From: Kevin Cheng <chengkev@google.com>
To: seanjc@google.com, pbonzini@redhat.com
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
yosry.ahmed@linux.dev, Kevin Cheng <chengkev@google.com>
Subject: [PATCH 1/2] KVM: SVM: Generate #UD for certain instructions when SVME.EFER is disabled
Date: Tue, 6 Jan 2026 04:12:49 +0000 [thread overview]
Message-ID: <20260106041250.2125920-2-chengkev@google.com> (raw)
In-Reply-To: <20260106041250.2125920-1-chengkev@google.com>
The AMD APM states that VMRUN, VMLOAD, VMSAVE, CLGI, VMMCALL, and
INVLPGA instructions should generate a #UD when EFER.SVME is cleared.
Currently, when VMLOAD, VMSAVE, or CLGI are executed in L1 with
EFER.SVME cleared, no #UD is generated in certain cases. This is because
the intercepts for these instructions are cleared based on whether or
not vls or vgif is enabled. The #UD fails to be generated when the
intercepts are absent.
INVLPGA is always intercepted, but there is no call to
nested_svm_check_permissions() which is responsible for checking
EFER.SVME and queuing the #UD exception.
Fix the missing #UD generation by ensuring that all relevant
instructions have intercepts set when SVME.EFER is disabled and that the
exit handlers contain the necessary checks.
VMMCALL is special because KVM's ABI is that VMCALL/VMMCALL are always
supported for L1 and never fault.
Signed-off-by: Kevin Cheng <chengkev@google.com>
---
arch/x86/kvm/svm/svm.c | 27 +++++++++++++++++++++++++--
1 file changed, 25 insertions(+), 2 deletions(-)
diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
index 24d59ccfa40d9..fc1b8707bb00c 100644
--- a/arch/x86/kvm/svm/svm.c
+++ b/arch/x86/kvm/svm/svm.c
@@ -228,6 +228,14 @@ int svm_set_efer(struct kvm_vcpu *vcpu, u64 efer)
if (!is_smm(vcpu))
svm_free_nested(svm);
+ /*
+ * If EFER.SVME is being cleared, we must intercept these
+ * instructions to ensure #UD is generated.
+ */
+ svm_set_intercept(svm, INTERCEPT_CLGI);
+ svm_set_intercept(svm, INTERCEPT_VMSAVE);
+ svm_set_intercept(svm, INTERCEPT_VMLOAD);
+ svm->vmcb->control.virt_ext &= ~VIRTUAL_VMLOAD_VMSAVE_ENABLE_MASK;
} else {
int ret = svm_allocate_nested(svm);
@@ -242,6 +250,15 @@ int svm_set_efer(struct kvm_vcpu *vcpu, u64 efer)
*/
if (svm_gp_erratum_intercept && !sev_guest(vcpu->kvm))
set_exception_intercept(svm, GP_VECTOR);
+
+ if (vgif)
+ svm_clr_intercept(svm, INTERCEPT_CLGI);
+
+ if (vls) {
+ svm_clr_intercept(svm, INTERCEPT_VMSAVE);
+ svm_clr_intercept(svm, INTERCEPT_VMLOAD);
+ svm->vmcb->control.virt_ext |= VIRTUAL_VMLOAD_VMSAVE_ENABLE_MASK;
+ }
}
}
@@ -2291,8 +2308,14 @@ static int clgi_interception(struct kvm_vcpu *vcpu)
static int invlpga_interception(struct kvm_vcpu *vcpu)
{
- gva_t gva = kvm_rax_read(vcpu);
- u32 asid = kvm_rcx_read(vcpu);
+ gva_t gva;
+ u32 asid;
+
+ if (nested_svm_check_permissions(vcpu))
+ return 1;
+
+ gva = kvm_rax_read(vcpu);
+ asid = kvm_rcx_read(vcpu);
/* FIXME: Handle an address size prefix. */
if (!is_long_mode(vcpu))
--
2.52.0.351.gbe84eed79e-goog
next prev parent reply other threads:[~2026-01-06 4:12 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-06 4:12 [PATCH 0/2] KVM: SVM: Align SVM with APM defined behaviors Kevin Cheng
2026-01-06 4:12 ` Kevin Cheng [this message]
2026-01-06 18:21 ` [PATCH 1/2] KVM: SVM: Generate #UD for certain instructions when SVME.EFER is disabled Sean Christopherson
2026-01-06 20:38 ` Andrew Cooper
2026-01-06 23:42 ` Yosry Ahmed
2026-01-06 23:48 ` Sean Christopherson
2026-01-07 0:04 ` Yosry Ahmed
2026-01-06 4:12 ` [PATCH 2/2] KVM: SVM: Raise #UD if VMMCALL instruction is not intercepted Kevin Cheng
2026-01-06 18:29 ` Sean Christopherson
2026-01-06 18:52 ` Andrew Cooper
2026-01-06 18:57 ` Sean Christopherson
2026-01-06 20:40 ` Andrew Cooper
2026-01-06 23:31 ` Yosry Ahmed
2026-01-06 23:38 ` Sean Christopherson
2026-01-07 0:02 ` 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=20260106041250.2125920-2-chengkev@google.com \
--to=chengkev@google.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=yosry.ahmed@linux.dev \
/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®