From: Yosry Ahmed <yosry.ahmed@linux.dev>
To: Sean Christopherson <seanjc@google.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
Yosry Ahmed <yosry.ahmed@linux.dev>
Subject: [PATCH 2/3] KVM: nSVM: Do not track EFER.SVME toggling in guest mode
Date: Fri, 30 Jan 2026 02:07:34 +0000 [thread overview]
Message-ID: <20260130020735.2517101-3-yosry.ahmed@linux.dev> (raw)
In-Reply-To: <20260130020735.2517101-1-yosry.ahmed@linux.dev>
KVM tracks when EFER.SVME is set and cleared to initialize and tear down
nested state. However, it doesn't differentiate if EFER.SVME is getting
toggled in L1 or L2+. Toggling EFER.SVME in L2+ is inconsequential from
KVM's perspective, as the vCPU is still obviously using nested.
This causes a problem if L2 sets then clears EFER.SVME without L1
interception, as KVM exits guest mode and tears down nested state while
L2 is running, executing L1 without injecting a proper #VMEXIT.
Technically, it's not a bug as the APM states that an L1 hypervisor
should intercept EFER writes:
The effect of turning off EFER.SVME while a guest is running is
undefined; therefore, the VMM should always prevent guests from
writing EFER.
However, it would be nice if KVM handled it more gracefully.
Signed-off-by: Yosry Ahmed <yosry.ahmed@linux.dev>
---
arch/x86/kvm/svm/svm.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
index 4575a6a7d6c4e..eaf0f8053fbfb 100644
--- a/arch/x86/kvm/svm/svm.c
+++ b/arch/x86/kvm/svm/svm.c
@@ -208,6 +208,13 @@ static int svm_set_efer_svme(struct kvm_vcpu *vcpu, u64 old_efer, u64 new_efer)
if ((old_efer & EFER_SVME) == (new_efer & EFER_SVME))
return 0;
+ /*
+ * An L2 guest setting or clearing EFER_SVME does not change whether or
+ * not the vCPU can use nested from KVM's perspective.
+ */
+ if (is_guest_mode(vcpu))
+ return 0;
+
if (new_efer & EFER_SVME) {
r = svm_allocate_nested(svm);
if (r)
--
2.53.0.rc1.225.gd81095ad13-goog
next prev parent reply other threads:[~2026-01-30 2:08 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-30 2:07 [PATCH 0/3] KVM: nSVM: Stop tracking EFER.SVME " Yosry Ahmed
2026-01-30 2:07 ` [PATCH 1/3] KVM: SVM: Refactor EFER.SVME switching logic out of svm_set_efer() Yosry Ahmed
2026-02-04 18:49 ` Sean Christopherson
2026-01-30 2:07 ` Yosry Ahmed [this message]
2026-02-04 21:15 ` [PATCH 2/3] KVM: nSVM: Do not track EFER.SVME toggling in guest mode Sean Christopherson
2026-02-04 23:30 ` Yosry Ahmed
2026-02-05 2:10 ` Sean Christopherson
2026-01-30 2:07 ` [PATCH 3/3] KVM: selftests: Add a test for L2 toggling EFER.SVME Yosry Ahmed
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=20260130020735.2517101-3-yosry.ahmed@linux.dev \
--to=yosry.ahmed@linux.dev \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--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
all inboxes | Powered by JetHome®