Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Sean Christopherson" <seanjc@google.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v5 2/6] KVM: nVMX: Synthesize SHUTDOWN on RSM if L2 requires emulation
Date: Fri, 31 Jul 2026 17:49:39 +0000	[thread overview]
Message-ID: <20260731174940.54D371F00AC4@smtp.kernel.org> (raw)
In-Reply-To: <20260731173340.2644656-3-seanjc@google.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] The early return for `leave_smm` failure in `emulator_leave_smm` bypasses `kvm_leave_nested()`, leaving the vCPU in an inconsistent nested guest mode state.
--

--- Patch [2]: [PATCH v5 2/6] KVM: nVMX: Synthesize SHUTDOWN on RSM if L2 requires emulation ---
commit 4200f9610608af5b1ad7221b2b5cf164faad2906
Author: Sean Christopherson <seanjc@google.com>

KVM: nVMX: Synthesize SHUTDOWN on RSM if L2 requires emulation

This commit synthesizes SHUTDOWN for L1 if L2 requires unhandleable emulation
after loading guest state from SMRAM during RSM. This prevents a misbehaving
L1 from triggering a KVM warning and bugging the VM.

> diff --git a/arch/x86/kvm/smm.c b/arch/x86/kvm/smm.c
> index a446487bdd5cf..656a38dad7e7a 100644
> --- a/arch/x86/kvm/smm.c
> +++ b/arch/x86/kvm/smm.c
> @@ -649,6 +649,10 @@ int emulator_leave_smm(struct x86_emulate_ctxt *ctxt)
>  #endif
>  		ret = rsm_load_state_32(ctxt, &smram.smram32);
>  
> +	if (ret == X86EMUL_CONTINUE &&
> +	    kvm_x86_call(unhandleable_emulation_required)(vcpu))
> +		ret = X86EMUL_UNHANDLEABLE;
> +
>  	/*
>  	 * If RSM fails and triggers shutdown, architecturally the shutdown
>  	 * occurs *before* the transition to guest mode.  But due to KVM's

[Severity: High]
This isn't a bug introduced by this patch, but looking at the earlier call
to kvm_x86_call(leave_smm)() in emulator_leave_smm() in arch/x86/kvm/smm.c:

    if (kvm_x86_call(leave_smm)(vcpu, &smram))
        return X86EMUL_UNHANDLEABLE;

If this fails, it returns directly and bypasses the kvm_leave_nested()
cleanup at the bottom of the function.

Can this leave the vCPU in an inconsistent nested guest mode state?

For example, if an unprivileged L1 hypervisor maliciously modifies the SMRAM
state (like an invalid CR3) for an active nested VM, could
emulator_leave_smm() call svm_leave_smm() -> enter_svm_guest_mode() ->
enter_guest_mode(vcpu) and fail in nested_svm_load_cr3()?

If so, would it return an error without leaving guest mode, bypass the
kvm_leave_nested() cleanup, and synthesize a nested VM-Exit to L1 instead
of properly transitioning L1 to SHUTDOWN?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260731173340.2644656-1-seanjc@google.com?part=2

  reply	other threads:[~2026-07-31 17:49 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-31 17:33 [PATCH v5 0/6] KVM: nVMX: Synthesize SHUTDOWN on RSM with bad state Sean Christopherson
2026-07-31 17:33 ` [PATCH v5 1/6] KVM: x86: Extract VMX's unhandleable emulation check to common x86 Sean Christopherson
2026-07-31 17:33 ` [PATCH v5 2/6] KVM: nVMX: Synthesize SHUTDOWN on RSM if L2 requires emulation Sean Christopherson
2026-07-31 17:49   ` sashiko-bot [this message]
2026-07-31 17:33 ` [PATCH v5 3/6] KVM: x86: Rework kvm_x86_ops.vcpu_pre_run() into .vcpu_needs_initialization() Sean Christopherson
2026-07-31 17:33 ` [PATCH v5 4/6] KVM: selftests: Use port 0x80 in invalid nVMX guest state test Sean Christopherson
2026-07-31 17:33 ` [PATCH v5 5/6] KVM: selftests: Refactor invalid nVMX state test to prepare for RSM testcase Sean Christopherson
2026-07-31 17:33 ` [PATCH v5 6/6] KVM: selftests: Extend the invalid nVMX guest state test to cover RSM Sean Christopherson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260731174940.54D371F00AC4@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=seanjc@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox