@@ -1128,7 +1128,6 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
ret = 1;
run->exit_reason = KVM_EXIT_UNKNOWN;
- run->flags = 0;
while (ret > 0) {
/*
* Check conditions before entering the guest
@@ -186,7 +186,7 @@ static int kvm_handle_guest_debug(struct kvm_vcpu *vcpu)
run->exit_reason = KVM_EXIT_DEBUG;
run->debug.arch.hsr = lower_32_bits(esr);
run->debug.arch.hsr_high = upper_32_bits(esr);
- run->flags = KVM_DEBUG_ARCH_HSR_HIGH_VALID;
+ run->flags |= KVM_DEBUG_ARCH_HSR_HIGH_VALID;
switch (ESR_ELx_EC(esr)) {
case ESR_ELx_EC_WATCHPT_LOW:
@@ -1704,9 +1704,7 @@ static int kvmppc_handle_exit_hv(struct kvm_vcpu *vcpu,
/* Exit to guest with KVM_EXIT_NMI as exit reason */
run->exit_reason = KVM_EXIT_NMI;
run->hw.hardware_exit_reason = vcpu->arch.trap;
- /* Clear out the old NMI status from run->flags */
- run->flags &= ~KVM_RUN_PPC_NMI_DISP_MASK;
- /* Now set the NMI status */
+ /* Note, run->flags is cleared at the start of KVM_RUN. */
if (vcpu->arch.mce_evt.disposition == MCE_DISPOSITION_RECOVERED)
run->flags |= KVM_RUN_PPC_NMI_DISP_FULLY_RECOV;
else
@@ -11465,7 +11465,6 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
vcpu_load(vcpu);
kvm_sigset_activate(vcpu);
- kvm_run->flags = 0;
kvm_load_guest_fpu(vcpu);
kvm_vcpu_srcu_read_lock(vcpu);
@@ -4336,6 +4336,9 @@ static long kvm_vcpu_ioctl(struct file *filp,
put_pid(oldpid);
}
+
+ vcpu->run->flags = 0;
+
vcpu->wants_to_run = !READ_ONCE(vcpu->run->immediate_exit__unsafe);
r = kvm_arch_vcpu_ioctl_run(vcpu);
vcpu->wants_to_run = false;
Clear kvm_run.flags at the start of KVM_RUN for all architectures to minimize the probability of leaving a stale flag set. Signed-off-by: Sean Christopherson <seanjc@google.com> --- arch/arm64/kvm/arm.c | 1 - arch/arm64/kvm/handle_exit.c | 2 +- arch/powerpc/kvm/book3s_hv.c | 4 +--- arch/x86/kvm/x86.c | 1 - virt/kvm/kvm_main.c | 3 +++ 5 files changed, 5 insertions(+), 6 deletions(-)