KVM: x86: Syzkaller nested_run_pending defense
Sean Christopherson
maintainercover KVM: x86: Syzkaller nested_run_pending defense
Defeat syzkaller once and for all when it comes to nested_run_pending (yeah, those words won't come back to haunt me), by treating nested_run_pending as "untrusted" for the purposes of WARNs if userspace gains control of the vCPU. I.e. don't WARN if userspace _may_ have stuffed vCPU state to force an impossible VM-Exit.
We've reached the point where the signal:noise ratio for nested_run_pending WARNs when syzkaller is fuzzing nVMX/nSVM is awful, and playing whack-a-mole with syzkaller is doing more harm that good at this point. While it's possible syzkaller could find an actual KVM bug by stuffing vCPU state, if the _only_ symptom is the nested_run_pending WARN, then in theory the bug should also be hittable by stuffing L2 state prior to nested VM-Enter.
Sean Christopherson (1):
KVM: x86: Suppress WARNs on nested_run_pending after userspace exit
Yosry Ahmed (1):
KVM: x86: Move nested_run_pending to kvm_vcpu_arch
arch/x86/include/asm/kvm_host.h | 15 ++++++++++ arch/x86/kvm/svm/nested.c | 23 ++++++++------- arch/x86/kvm/svm/svm.c | 16 +++++------ arch/x86/kvm/svm/svm.h | 4 --- arch/x86/kvm/vmx/nested.c | 50 +++++++++++++++++---------------- arch/x86/kvm/vmx/vmx.c | 16 +++++------ arch/x86/kvm/vmx/vmx.h | 3 -- arch/x86/kvm/x86.c | 7 +++++ arch/x86/kvm/x86.h | 10 +++++++ 9 files changed, 87 insertions(+), 57 deletions(-)
base-commit: 5128b972fb2801ad9aca54d990a75611ab5283a9
Signature · 1 line
2.53.0.473.g4a7958ca14-goog
Sean Christopherson
maintainerPATCH 1/2 KVM: x86: Move nested_run_pending to kvm_vcpu_arch
From: Yosry Ahmed <[email protected]>
Move nested_run_pending field present in both svm_nested_state and nested_vmx to the common kvm_vcpu_arch. This allows for common code to use without plumbing it through per-vendor helpers.
nested_run_pending remains zero-initialized, as the entire kvm_vcpu struct is, and all further accesses are done through vcpu->arch instead of svm->nested or vmx->nested.
No functional change intended.
--- arch/x86/include/asm/kvm_host.h | 9 +++++++ arch/x86/kvm/svm/nested.c | 18 ++++++------- arch/x86/kvm/svm/svm.c | 16 ++++++------ arch/x86/kvm/svm/svm.h | 4 --- arch/x86/kvm/vmx/nested.c | 46 ++++++++++++++++----------------- arch/x86/kvm/vmx/vmx.c | 16 ++++++------ arch/x86/kvm/vmx/vmx.h | 3 --- 7 files changed, 57 insertions(+), 55 deletions(-)
arch/x86/include/asm/kvm_host.h +9 -0
@@ -1099,6 +1099,15 @@ struct kvm_vcpu_arch {*/ bool pdptrs_from_userspace; +/* +* Set if an emulated nested VM-Enter to L2 is pending completion. KVM +* must not synthesize a VM-Exit to L1 before entering L2, as VM-Exits +* can only occur at instruction boundaries. The only exception is +* VMX's "notify" exits, which exist in large part to break the CPU out +* of infinite ucode loops, but can corrupt vCPU state in the process! +*/ +bool nested_run_pending; +#if IS_ENABLED (CONFIG_HYPERV )hpa_t hv_root_tdp;#endif
arch/x86/kvm/svm/nested.c +9 -9
@@ -914,7 +914,7 @@ static void nested_vmcb02_prepare_control(struct vcpu_svm *svm)* the CPU and/or KVM and should be used regardless of L1's support. */ if (guest_cpu_cap_has (vcpu,X86_FEATURE_NRIPS ) || - !svm->nested.nested_run_pending) + !vcpu->arch.nested_run_pending) vmcb02->control.next_rip = vmcb12_ctrl->next_rip; svm->nmi_l1_to_l2 =is_evtinj_nmi (vmcb02->control.event_inj);
@@ -926,7 +926,7 @@ static void nested_vmcb02_prepare_control(struct vcpu_svm *svm)if (is_evtinj_soft (vmcb02->control.event_inj)) { svm->soft_int_injected = true;if (guest_cpu_cap_has (vcpu,X86_FEATURE_NRIPS ) || - !svm->nested.nested_run_pending) + !vcpu->arch.nested_run_pending) svm->soft_int_next_rip = vmcb12_ctrl->next_rip; }
@@ -1131,11 +1131,11 @@ int nested_svm_vmrun(struct kvm_vcpu *vcpu)if (!npt_enabled) vmcb01->save.cr3 =kvm_read_cr3 (vcpu); - svm->nested.nested_run_pending =1 ; + vcpu->arch.nested_run_pending =1 ;if (enter_svm_guest_mode (vcpu, vmcb12_gpa, true) || !nested_svm_merge_msrpm (vcpu)) { - svm->nested.nested_run_pending =0 ; + vcpu->arch.nested_run_pending =0 ; svm->nmi_l1_to_l2 = false; svm->soft_int_injected = false;
@@ -1277,7 +1277,7 @@ void nested_svm_vmexit(struct vcpu_svm *svm)/* Exit Guest-Mode */ leave_guest_mode (vcpu); svm->nested.vmcb12_gpa =0 ; -WARN_ON_ONCE (svm->nested.nested_run_pending); +WARN_ON_ONCE (vcpu->arch.nested_run_pending);kvm_clear_request (KVM_REQ_GET_NESTED_STATE_PAGES , vcpu);
@@ -1487,7 +1487,7 @@ void svm_leave_nested(struct kvm_vcpu *vcpu)struct vcpu_svm *svm =to_svm (vcpu);if (is_guest_mode (vcpu)) { - svm->nested.nested_run_pending =0 ; + vcpu->arch.nested_run_pending =0 ; svm->nested.vmcb12_gpa =INVALID_GPA ;leave_guest_mode (vcpu);
@@ -1672,7 +1672,7 @@ static int svm_check_nested_events(struct kvm_vcpu *vcpu)* previously injected event, the pending exception occurred while said * event was being delivered and thus needs to be handled. */ -bool block_nested_exceptions = svm->nested.nested_run_pending; +bool block_nested_exceptions = vcpu->arch.nested_run_pending;/* * New events (not exceptions) are only recognized at instruction * boundaries. If an event needs reinjection, then KVM is handling a
@@ -1847,7 +1847,7 @@ static int svm_get_nested_state(struct kvm_vcpu *vcpu, kvm_state.size +=KVM_STATE_NESTED_SVM_VMCB_SIZE ; kvm_state.flags |=KVM_STATE_NESTED_GUEST_MODE ; -if (svm->nested.nested_run_pending) +if (vcpu->arch.nested_run_pending) kvm_state.flags |=KVM_STATE_NESTED_RUN_PENDING ; }
@@ -1984,7 +1984,7 @@ static int svm_set_nested_state(struct kvm_vcpu *vcpu,svm_set_gif (svm, !!(kvm_state->flags &KVM_STATE_NESTED_GIF_SET )); - svm->nested.nested_run_pending = + vcpu->arch.nested_run_pending = !!(kvm_state->flags &KVM_STATE_NESTED_RUN_PENDING ); svm->nested.vmcb12_gpa = kvm_state->hdr.svm.vmcb_pa;
arch/x86/kvm/svm/svm.c +8 -8
@@ -3831,7 +3831,7 @@ static void svm_fixup_nested_rips(struct kvm_vcpu *vcpu) {struct vcpu_svm *svm =to_svm (vcpu); -if (!is_guest_mode (vcpu) || !svm->nested.nested_run_pending) +if (!is_guest_mode (vcpu) || !vcpu->arch.nested_run_pending)return ;/*
@@ -3979,7 +3979,7 @@ bool svm_nmi_blocked(struct kvm_vcpu *vcpu)static int svm_nmi_allowed (struct kvm_vcpu *vcpu,bool for_injection) {struct vcpu_svm *svm =to_svm (vcpu); -if (svm->nested.nested_run_pending) +if (vcpu->arch.nested_run_pending)return -EBUSY ;if (svm_nmi_blocked (vcpu))
@@ -4021,7 +4021,7 @@ static int svm_interrupt_allowed(struct kvm_vcpu *vcpu, bool for_injection) {struct vcpu_svm *svm =to_svm (vcpu); -if (svm->nested.nested_run_pending) +if (vcpu->arch.nested_run_pending)return -EBUSY ;if (svm_interrupt_blocked (vcpu))
@@ -4244,7 +4244,7 @@ static void svm_complete_soft_interrupt(struct kvm_vcpu *vcpu, u8 vector,* the soft int and will reinject it via the standard injection flow, * and so KVM needs to grab the state from the pending nested VMRUN. */ -if (is_guest_mode (vcpu) && svm->nested.nested_run_pending) +if (is_guest_mode (vcpu) && vcpu->arch.nested_run_pending)svm_set_nested_run_soft_int_state (vcpu);/*
@@ -4547,11 +4547,11 @@ static __no_kcsan fastpath_t svm_vcpu_run(struct kvm_vcpu *vcpu, u64 run_flags)nested_sync_control_from_vmcb02 (svm);/* Track VMRUNs that have made past consistency checking */ -if (svm->nested.nested_run_pending && +if (vcpu->arch.nested_run_pending && !svm_is_vmrun_failure (svm->vmcb->control.exit_code)) ++vcpu->stat.nested_run; - svm->nested.nested_run_pending =0 ; + vcpu->arch.nested_run_pending =0 ; } svm->vmcb->control.tlb_ctl =TLB_CONTROL_DO_NOTHING ;
@@ -4920,7 +4920,7 @@ bool svm_smi_blocked(struct kvm_vcpu *vcpu)static int svm_smi_allowed (struct kvm_vcpu *vcpu,bool for_injection) {struct vcpu_svm *svm =to_svm (vcpu); -if (svm->nested.nested_run_pending) +if (vcpu->arch.nested_run_pending)return -EBUSY ;if (svm_smi_blocked (vcpu))
@@ -5035,7 +5035,7 @@ static int svm_leave_smm(struct kvm_vcpu *vcpu, const union kvm_smram *smram)if (ret) goto unmap_save; - svm->nested.nested_run_pending =1 ; + vcpu->arch.nested_run_pending =1 ; unmap_save:kvm_vcpu_unmap (vcpu, &map_save);
arch/x86/kvm/svm/svm.h +0 -4
@@ -215,10 +215,6 @@ struct svm_nested_state {*/ void *msrpm; -/* A VMRUN has started but has not yet been performed, so -* we cannot inject a nested vmexit yet. */ -bool nested_run_pending; -/* cache for control fields of the guest */ struct vmcb_ctrl_area_cached ctl;
arch/x86/kvm/vmx/nested.c +23 -23
175 lines not on this page · raw message
arch/x86/kvm/vmx/vmx.c +8 -8
@@ -5170,7 +5170,7 @@ bool vmx_nmi_blocked(struct kvm_vcpu *vcpu)int vmx_nmi_allowed (struct kvm_vcpu *vcpu,bool for_injection) { -if (to_vmx (vcpu)->nested.nested_run_pending) +if (vcpu->arch.nested_run_pending)return -EBUSY ;/* An NMI must not be injected into L2 if it's supposed to VM-Exit. */
@@ -5197,7 +5197,7 @@ bool vmx_interrupt_blocked(struct kvm_vcpu *vcpu)int vmx_interrupt_allowed (struct kvm_vcpu *vcpu,bool for_injection) { -if (to_vmx (vcpu)->nested.nested_run_pending) +if (vcpu->arch.nested_run_pending)return -EBUSY ;/*
@@ -6009,7 +6009,7 @@ static bool vmx_unhandleable_emulation_required(struct kvm_vcpu *vcpu)* only reachable if userspace modifies L2 guest state after KVM has * performed the nested VM-Enter consistency checks. */ -if (vmx->nested.nested_run_pending) +if (vcpu->arch.nested_run_pending)return true;/*
@@ -6693,7 +6693,7 @@ static int __vmx_handle_exit(struct kvm_vcpu *vcpu, fastpath_t exit_fastpath)* invalid guest state should never happen as that means KVM knowingly * allowed a nested VM-Enter with an invalid vmcs12. More below. */ -if (KVM_BUG_ON (vmx->nested.nested_run_pending, vcpu->kvm)) +if (KVM_BUG_ON (vcpu->arch.nested_run_pending, vcpu->kvm))return -EIO ;if (is_guest_mode (vcpu)) {
@@ -7621,11 +7621,11 @@ fastpath_t vmx_vcpu_run(struct kvm_vcpu *vcpu, u64 run_flags)* Track VMLAUNCH/VMRESUME that have made past guest state * checking. */ -if (vmx->nested.nested_run_pending && +if (vcpu->arch.nested_run_pending && !vmx_get_exit_reason (vcpu).failed_vmentry) ++vcpu->stat.nested_run; - vmx->nested.nested_run_pending =0 ; + vcpu->arch.nested_run_pending =0 ; }if (unlikely (vmx->fail))
@@ -8382,7 +8382,7 @@ void vmx_setup_mce(struct kvm_vcpu *vcpu)int vmx_smi_allowed (struct kvm_vcpu *vcpu,bool for_injection) {/* we need a nested vmexit to enter SMM, postpone if run is pending */ -if (to_vmx (vcpu)->nested.nested_run_pending) +if (vcpu->arch.nested_run_pending)return -EBUSY ;return !is_smm (vcpu); }
@@ -8423,7 +8423,7 @@ int vmx_leave_smm(struct kvm_vcpu *vcpu, const union kvm_smram *smram)if (ret)return ret; - vmx->nested.nested_run_pending =1 ; + vcpu->arch.nested_run_pending =1 ; vmx->nested.smm.guest_mode = false; }return 0 ;
arch/x86/kvm/vmx/vmx.h +0 -3
@@ -138,9 +138,6 @@ struct nested_vmx {*/ bool enlightened_vmcs_enabled; -/* L2 must run next, and mustn't decide to exit to L1. */ -bool nested_run_pending; -/* Pending MTF VM-exit into L1. */ bool mtf_pending;
Signature · 1 line
2.53.0.473.g4a7958ca14-goog
Sean Christopherson
maintainerPATCH 2/2 KVM: x86: Suppress WARNs on nested_run_pending after userspace exit
In reply to Sean ChristophersonTo end an ongoing game of whack-a-mole between KVM and syzkaller, WARN on illegally cancelling a pending nested VM-Enter if and only if userspace has NOT gained control of the vCPU since the nested run was initiated. As proven time and time again by syzkaller, userspace can clobber vCPU state so as to force a VM-Exit that violates KVM's architectural modelling of VMRUN/VMLAUNCH/VMRESUME.
To detect that userspace has gained control, while minimizing the risk of operating on stale data, convert nested_run_pending from a pure boolean to a tri-state of sorts, where '0' is still "not pending", '1' is "pending", and '2' is "pending but untrusted". Then on KVM_RUN, if the flag is in the "trusted pending" state, move it to "untrusted pending".
--- arch/x86/include/asm/kvm_host.h | 8 +++++++- arch/x86/kvm/svm/nested.c | 11 +++++++---- arch/x86/kvm/svm/svm.c | 2 +- arch/x86/kvm/vmx/nested.c | 12 +++++++----- arch/x86/kvm/vmx/vmx.c | 2 +- arch/x86/kvm/x86.c | 7 +++++++ arch/x86/kvm/x86.h | 10 ++++++++++ 7 files changed, 40 insertions(+), 12 deletions(-)
arch/x86/include/asm/kvm_host.h +7 -1
@@ -1105,8 +1105,14 @@ struct kvm_vcpu_arch {* can only occur at instruction boundaries. The only exception is * VMX's "notify" exits, which exist in large part to break the CPU out * of infinite ucode loops, but can corrupt vCPU state in the process! +* +* For all intents and purposes, this is a boolean, but it's tracked as +* a u8 so that KVM can detect when userspace may have stuffed vCPU +* state and generated an architecturally-impossible VM-Exit. */ -bool nested_run_pending; +#define KVM_NESTED_RUN_PENDING 1 +#define KVM_NESTED_RUN_PENDING_UNTRUSTED 2 +u8 nested_run_pending;#if IS_ENABLED (CONFIG_HYPERV )hpa_t hv_root_tdp;
arch/x86/kvm/svm/nested.c +7 -4
@@ -1131,7 +1131,7 @@ int nested_svm_vmrun(struct kvm_vcpu *vcpu)if (!npt_enabled) vmcb01->save.cr3 =kvm_read_cr3 (vcpu); - vcpu->arch.nested_run_pending =1 ; + vcpu->arch.nested_run_pending =KVM_NESTED_RUN_PENDING ;if (enter_svm_guest_mode (vcpu, vmcb12_gpa, true) || !nested_svm_merge_msrpm (vcpu)) {
@@ -1277,7 +1277,8 @@ void nested_svm_vmexit(struct vcpu_svm *svm)/* Exit Guest-Mode */ leave_guest_mode (vcpu); svm->nested.vmcb12_gpa =0 ; -WARN_ON_ONCE (vcpu->arch.nested_run_pending); + +kvm_warn_on_nested_run_pending (vcpu);kvm_clear_request (KVM_REQ_GET_NESTED_STATE_PAGES , vcpu);
@@ -1984,8 +1985,10 @@ static int svm_set_nested_state(struct kvm_vcpu *vcpu,svm_set_gif (svm, !!(kvm_state->flags &KVM_STATE_NESTED_GIF_SET )); - vcpu->arch.nested_run_pending = - !!(kvm_state->flags &KVM_STATE_NESTED_RUN_PENDING ); +if (kvm_state->flags &KVM_STATE_NESTED_RUN_PENDING ) + vcpu->arch.nested_run_pending =KVM_NESTED_RUN_PENDING_UNTRUSTED ; +else + vcpu->arch.nested_run_pending =0 ; svm->nested.vmcb12_gpa = kvm_state->hdr.svm.vmcb_pa;
arch/x86/kvm/svm/svm.c +1 -1
@@ -5035,7 +5035,7 @@ static int svm_leave_smm(struct kvm_vcpu *vcpu, const union kvm_smram *smram)if (ret) goto unmap_save; - vcpu->arch.nested_run_pending =1 ; + vcpu->arch.nested_run_pending =KVM_NESTED_RUN_PENDING ; unmap_save:kvm_vcpu_unmap (vcpu, &map_save);
arch/x86/kvm/vmx/nested.c +7 -5
@@ -3844,7 +3844,7 @@ static int nested_vmx_run(struct kvm_vcpu *vcpu, bool launch)* We're finally done with prerequisite checking, and can start with * the nested entry. */ - vcpu->arch.nested_run_pending =1 ; + vcpu->arch.nested_run_pending =KVM_NESTED_RUN_PENDING ; vmx->nested.has_preemption_timer_deadline = false; status =nested_vmx_enter_non_root_mode (vcpu, true);if (unlikely (status !=NVMX_VMENTRY_SUCCESS ))
@@ -5056,7 +5056,7 @@ void __nested_vmx_vmexit(struct kvm_vcpu *vcpu, u32 vm_exit_reason, vmx->nested.mtf_pending = false;/* trying to cancel vmlaunch/vmresume is a bug */ -WARN_ON_ONCE (vcpu->arch.nested_run_pending); +kvm_warn_on_nested_run_pending (vcpu);#ifdef CONFIG_KVM_HYPERV if (kvm_check_request (KVM_REQ_GET_NESTED_STATE_PAGES , vcpu)) {
@@ -6679,7 +6679,7 @@ bool nested_vmx_reflect_vmexit(struct kvm_vcpu *vcpu)unsigned long exit_qual;u32 exit_intr_info; -WARN_ON_ONCE (vcpu->arch.nested_run_pending); +kvm_warn_on_nested_run_pending (vcpu);/* * Late nested VM-Fail shares the same flow as nested VM-Exit since KVM
@@ -6987,8 +6987,10 @@ static int vmx_set_nested_state(struct kvm_vcpu *vcpu,if (!(kvm_state->flags &KVM_STATE_NESTED_GUEST_MODE ))return 0 ; - vcpu->arch.nested_run_pending = - !!(kvm_state->flags &KVM_STATE_NESTED_RUN_PENDING ); +if (kvm_state->flags &KVM_STATE_NESTED_RUN_PENDING ) + vcpu->arch.nested_run_pending =KVM_NESTED_RUN_PENDING_UNTRUSTED ; +else + vcpu->arch.nested_run_pending =0 ; vmx->nested.mtf_pending = !!(kvm_state->flags &KVM_STATE_NESTED_MTF_PENDING );
arch/x86/kvm/vmx/vmx.c +1 -1
@@ -8423,7 +8423,7 @@ int vmx_leave_smm(struct kvm_vcpu *vcpu, const union kvm_smram *smram)if (ret)return ret; - vcpu->arch.nested_run_pending =1 ; + vcpu->arch.nested_run_pending =KVM_NESTED_RUN_PENDING ; vmx->nested.smm.guest_mode = false; }return 0 ;
arch/x86/kvm/x86.c +7 -0
@@ -12090,6 +12090,13 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)if (r <=0 ) goto out; +/* +* If userspace may have modified vCPU state, mark nested_run_pending +* as "untrusted" to avoid triggering false-positive WARNs. +*/ +if (vcpu->arch.nested_run_pending ==KVM_NESTED_RUN_PENDING ) + vcpu->arch.nested_run_pending =KVM_NESTED_RUN_PENDING_UNTRUSTED ; + r =vcpu_run (vcpu); out:
arch/x86/kvm/x86.h +10 -0
@@ -188,6 +188,16 @@ static inline bool kvm_can_set_cpuid_and_feature_msrs(struct kvm_vcpu *vcpu)return vcpu->arch.last_vmentry_cpu ==-1 && !is_guest_mode (vcpu); } +/* +* WARN if a nested VM-Enter is pending completion, and userspace hasn't gained +* control since the nested VM-Enter was initiated (in which case, userspace +* may have modified vCPU state to induce an architecturally invalid VM-Exit). +*/ +static inline void kvm_warn_on_nested_run_pending (struct kvm_vcpu *vcpu) +{ +WARN_ON_ONCE (vcpu->arch.nested_run_pending ==KVM_NESTED_RUN_PENDING ); +} +static inline void kvm_set_mp_state (struct kvm_vcpu *vcpu,int mp_state) { vcpu->arch.mp_state = mp_state;
Signature · 1 line
2.53.0.473.g4a7958ca14-goog
Re: [PATCH 2/2] KVM: x86: Suppress WARNs on nested_run_pending after userspace exit
Quoted 5 lines
arch/x86/kvm/x86.c +0
-0
arch/x86/kvm/x86.c int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) · line 12099
Quoted 10 lines
arch/x86/kvm/x86.c +7
-0@@ -12090,6 +12090,13 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)if (r <=0 ) goto out; +/* +* If userspace may have modified vCPU state, mark nested_run_pending +* as "untrusted" to avoid triggering false-positive WARNs. +*/ +if (vcpu->arch.nested_run_pending ==KVM_NESTED_RUN_PENDING ) + vcpu->arch.nested_run_pending =KVM_NESTED_RUN_PENDING_UNTRUSTED ; +
Why not inside kvm_x86_vcpu_pre_run()?
Sean Christopherson
maintainerRe: [PATCH 2/2] KVM: x86: Suppress WARNs on nested_run_pending after userspace exit
Quoted 8 lines · Yosry Ahmed
Quoted 8 lines
arch/x86/kvm/x86.c +0
-0@@ -12090,6 +12090,13 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)if (r <=0 ) goto out;
Quoted 9 lines
arch/x86/kvm/x86.c int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) · line 12099
Quoted 7 lines
arch/x86/kvm/x86.c +7
-0+/* +* If userspace may have modified vCPU state, mark nested_run_pending +* as "untrusted" to avoid triggering false-positive WARNs. +*/ +if (vcpu->arch.nested_run_pending ==KVM_NESTED_RUN_PENDING ) + vcpu->arch.nested_run_pending =KVM_NESTED_RUN_PENDING_UNTRUSTED ; +Why not inside
kvm_x86_vcpu_pre_run()?
That, is a very good question. /facepalm
Yosry Ahmed
Reviewed-byRe: [PATCH 2/2] KVM: x86: Suppress WARNs on nested_run_pending after userspace exit
Quoted 20 lines · Sean Christopherson
Quoted 8 lines · Yosry Ahmed
Quoted 8 lines
arch/x86/kvm/x86.c +0
-0@@ -12090,6 +12090,13 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)if (r <=0 ) goto out;Quoted 9 lines
arch/x86/kvm/x86.c int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) · line 12099
Quoted 7 lines
arch/x86/kvm/x86.c +7
-0+/* +* If userspace may have modified vCPU state, mark nested_run_pending +* as "untrusted" to avoid triggering false-positive WARNs. +*/ +if (vcpu->arch.nested_run_pending ==KVM_NESTED_RUN_PENDING ) + vcpu->arch.nested_run_pending =KVM_NESTED_RUN_PENDING_UNTRUSTED ; +Why not inside
kvm_x86_vcpu_pre_run()?
Quoted 1 line
That, is a very good question. /facepalm
After moving it to kvm_x86_vcpu_pre_run(), feel free to add:
Sean Christopherson
maintainerRe: [PATCH 2/2] KVM: x86: Suppress WARNs on nested_run_pending after userspace exit
Quoted 21 lines · Yosry Ahmed
Quoted 20 lines · Sean Christopherson
Quoted 17 lines · Yosry Ahmed
Quoted 5 lines
arch/x86/kvm/x86.c +0
-0arch/x86/kvm/x86.c int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) · line 12099
Quoted 10 lines
arch/x86/kvm/x86.c +7
-0@@ -12090,6 +12090,13 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)if (r <=0 ) goto out; +/* +* If userspace may have modified vCPU state, mark nested_run_pending +* as "untrusted" to avoid triggering false-positive WARNs. +*/ +if (vcpu->arch.nested_run_pending ==KVM_NESTED_RUN_PENDING ) + vcpu->arch.nested_run_pending =KVM_NESTED_RUN_PENDING_UNTRUSTED ; +Why not inside
kvm_x86_vcpu_pre_run()?
Quoted 1 line
Quoted 1 line
That, is a very good question. /facepalm
Oh, I know why I put it here. I didn't want to change nested_run_pending if kvm_x86_vcpu_pre_run() rejected KVM_RUN. But looking at this again, it doesn't actually matter because for the "untrusted" state to matter, KVM must get past kvm_x86_vcpu_pre_run() at some point.