Commit 66b56562 authored by Christoffer Dall's avatar Christoffer Dall Committed by Paolo Bonzini

KVM: Move vcpu_load to arch-specific kvm_arch_vcpu_ioctl_set_guest_debug

Move vcpu_load() and vcpu_put() into the architecture specific
implementations of kvm_arch_vcpu_ioctl_set_guest_debug().
Reviewed-by: default avatarDavid Hildenbrand <david@redhat.com>
Signed-off-by: default avatarChristoffer Dall <christoffer.dall@linaro.org>
Reviewed-by: default avatarCornelia Huck <cohuck@redhat.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 1da5b61d
...@@ -361,10 +361,16 @@ int kvm_arch_vcpu_ioctl_translate(struct kvm_vcpu *vcpu, ...@@ -361,10 +361,16 @@ int kvm_arch_vcpu_ioctl_translate(struct kvm_vcpu *vcpu,
int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
struct kvm_guest_debug *dbg) struct kvm_guest_debug *dbg)
{ {
int ret = 0;
vcpu_load(vcpu);
trace_kvm_set_guest_debug(vcpu, dbg->control); trace_kvm_set_guest_debug(vcpu, dbg->control);
if (dbg->control & ~KVM_GUESTDBG_VALID_MASK) if (dbg->control & ~KVM_GUESTDBG_VALID_MASK) {
return -EINVAL; ret = -EINVAL;
goto out;
}
if (dbg->control & KVM_GUESTDBG_ENABLE) { if (dbg->control & KVM_GUESTDBG_ENABLE) {
vcpu->guest_debug = dbg->control; vcpu->guest_debug = dbg->control;
...@@ -378,7 +384,10 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, ...@@ -378,7 +384,10 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
/* If not enabled clear all flags */ /* If not enabled clear all flags */
vcpu->guest_debug = 0; vcpu->guest_debug = 0;
} }
return 0;
out:
vcpu_put(vcpu);
return ret;
} }
int kvm_arm_vcpu_arch_set_attr(struct kvm_vcpu *vcpu, int kvm_arm_vcpu_arch_set_attr(struct kvm_vcpu *vcpu,
......
...@@ -755,7 +755,9 @@ int kvm_arch_vcpu_ioctl_translate(struct kvm_vcpu *vcpu, ...@@ -755,7 +755,9 @@ int kvm_arch_vcpu_ioctl_translate(struct kvm_vcpu *vcpu,
int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
struct kvm_guest_debug *dbg) struct kvm_guest_debug *dbg)
{ {
vcpu_load(vcpu);
vcpu->guest_debug = dbg->control; vcpu->guest_debug = dbg->control;
vcpu_put(vcpu);
return 0; return 0;
} }
......
...@@ -2016,12 +2016,15 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, ...@@ -2016,12 +2016,15 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
{ {
struct debug_reg *dbg_reg; struct debug_reg *dbg_reg;
int n, b = 0, w = 0; int n, b = 0, w = 0;
int ret = 0;
vcpu_load(vcpu);
if (!(dbg->control & KVM_GUESTDBG_ENABLE)) { if (!(dbg->control & KVM_GUESTDBG_ENABLE)) {
vcpu->arch.dbg_reg.dbcr0 = 0; vcpu->arch.dbg_reg.dbcr0 = 0;
vcpu->guest_debug = 0; vcpu->guest_debug = 0;
kvm_guest_protect_msr(vcpu, MSR_DE, false); kvm_guest_protect_msr(vcpu, MSR_DE, false);
return 0; goto out;
} }
kvm_guest_protect_msr(vcpu, MSR_DE, true); kvm_guest_protect_msr(vcpu, MSR_DE, true);
...@@ -2053,8 +2056,9 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, ...@@ -2053,8 +2056,9 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
#endif #endif
if (!(vcpu->guest_debug & KVM_GUESTDBG_USE_HW_BP)) if (!(vcpu->guest_debug & KVM_GUESTDBG_USE_HW_BP))
return 0; goto out;
ret = -EINVAL;
for (n = 0; n < (KVMPPC_BOOKE_IAC_NUM + KVMPPC_BOOKE_DAC_NUM); n++) { for (n = 0; n < (KVMPPC_BOOKE_IAC_NUM + KVMPPC_BOOKE_DAC_NUM); n++) {
uint64_t addr = dbg->arch.bp[n].addr; uint64_t addr = dbg->arch.bp[n].addr;
uint32_t type = dbg->arch.bp[n].type; uint32_t type = dbg->arch.bp[n].type;
...@@ -2065,21 +2069,24 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, ...@@ -2065,21 +2069,24 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
if (type & ~(KVMPPC_DEBUG_WATCH_READ | if (type & ~(KVMPPC_DEBUG_WATCH_READ |
KVMPPC_DEBUG_WATCH_WRITE | KVMPPC_DEBUG_WATCH_WRITE |
KVMPPC_DEBUG_BREAKPOINT)) KVMPPC_DEBUG_BREAKPOINT))
return -EINVAL; goto out;
if (type & KVMPPC_DEBUG_BREAKPOINT) { if (type & KVMPPC_DEBUG_BREAKPOINT) {
/* Setting H/W breakpoint */ /* Setting H/W breakpoint */
if (kvmppc_booke_add_breakpoint(dbg_reg, addr, b++)) if (kvmppc_booke_add_breakpoint(dbg_reg, addr, b++))
return -EINVAL; goto out;
} else { } else {
/* Setting H/W watchpoint */ /* Setting H/W watchpoint */
if (kvmppc_booke_add_watchpoint(dbg_reg, addr, if (kvmppc_booke_add_watchpoint(dbg_reg, addr,
type, w++)) type, w++))
return -EINVAL; goto out;
} }
} }
return 0; ret = 0;
out:
vcpu_put(vcpu);
return ret;
} }
void kvmppc_booke_vcpu_load(struct kvm_vcpu *vcpu, int cpu) void kvmppc_booke_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
......
...@@ -2801,13 +2801,19 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, ...@@ -2801,13 +2801,19 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
{ {
int rc = 0; int rc = 0;
vcpu_load(vcpu);
vcpu->guest_debug = 0; vcpu->guest_debug = 0;
kvm_s390_clear_bp_data(vcpu); kvm_s390_clear_bp_data(vcpu);
if (dbg->control & ~VALID_GUESTDBG_FLAGS) if (dbg->control & ~VALID_GUESTDBG_FLAGS) {
return -EINVAL; rc = -EINVAL;
if (!sclp.has_gpere) goto out;
return -EINVAL; }
if (!sclp.has_gpere) {
rc = -EINVAL;
goto out;
}
if (dbg->control & KVM_GUESTDBG_ENABLE) { if (dbg->control & KVM_GUESTDBG_ENABLE) {
vcpu->guest_debug = dbg->control; vcpu->guest_debug = dbg->control;
...@@ -2827,6 +2833,8 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, ...@@ -2827,6 +2833,8 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
atomic_andnot(CPUSTAT_P, &vcpu->arch.sie_block->cpuflags); atomic_andnot(CPUSTAT_P, &vcpu->arch.sie_block->cpuflags);
} }
out:
vcpu_put(vcpu);
return rc; return rc;
} }
......
...@@ -7625,6 +7625,8 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, ...@@ -7625,6 +7625,8 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
unsigned long rflags; unsigned long rflags;
int i, r; int i, r;
vcpu_load(vcpu);
if (dbg->control & (KVM_GUESTDBG_INJECT_DB | KVM_GUESTDBG_INJECT_BP)) { if (dbg->control & (KVM_GUESTDBG_INJECT_DB | KVM_GUESTDBG_INJECT_BP)) {
r = -EBUSY; r = -EBUSY;
if (vcpu->arch.exception.pending) if (vcpu->arch.exception.pending)
...@@ -7670,7 +7672,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, ...@@ -7670,7 +7672,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
r = 0; r = 0;
out: out:
vcpu_put(vcpu);
return r; return r;
} }
......
...@@ -2673,9 +2673,7 @@ static long kvm_vcpu_ioctl(struct file *filp, ...@@ -2673,9 +2673,7 @@ static long kvm_vcpu_ioctl(struct file *filp,
r = -EFAULT; r = -EFAULT;
if (copy_from_user(&dbg, argp, sizeof(dbg))) if (copy_from_user(&dbg, argp, sizeof(dbg)))
goto out; goto out;
vcpu_load(vcpu);
r = kvm_arch_vcpu_ioctl_set_guest_debug(vcpu, &dbg); r = kvm_arch_vcpu_ioctl_set_guest_debug(vcpu, &dbg);
vcpu_put(vcpu);
break; break;
} }
case KVM_SET_SIGNAL_MASK: { case KVM_SET_SIGNAL_MASK: {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment