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 V3 2/5] KVM: SVM: Inject #UD for STGI if EFER.SVME=0 and SVM Lock and DEV are not available
Date: Thu, 22 Jan 2026 04:57:51 +0000 [thread overview]
Message-ID: <20260122045755.205203-3-chengkev@google.com> (raw)
In-Reply-To: <20260122045755.205203-1-chengkev@google.com>
The AMD APM states that STGI causes a #UD if SVM is not enabled and
neither SVM Lock nor the device exclusion vector (DEV) are supported.
Support for DEV is part of the SKINIT architecture. Fix the STGI exit
handler by injecting #UD when these conditions are met.
Signed-off-by: Kevin Cheng <chengkev@google.com>
---
arch/x86/kvm/svm/nested.c | 9 +++++++--
arch/x86/kvm/svm/svm.c | 12 +++++++++++-
arch/x86/kvm/svm/svm.h | 1 +
3 files changed, 19 insertions(+), 3 deletions(-)
diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c
index ba0f11c68372b..60bb320c34bda 100644
--- a/arch/x86/kvm/svm/nested.c
+++ b/arch/x86/kvm/svm/nested.c
@@ -1466,9 +1466,9 @@ int nested_svm_exit_handled(struct vcpu_svm *svm)
return vmexit;
}
-int nested_svm_check_permissions(struct kvm_vcpu *vcpu)
+int __nested_svm_check_permissions(struct kvm_vcpu *vcpu, bool insn_allowed)
{
- if (!(vcpu->arch.efer & EFER_SVME) || !is_paging(vcpu)) {
+ if (!insn_allowed || !is_paging(vcpu)) {
kvm_queue_exception(vcpu, UD_VECTOR);
return 1;
}
@@ -1481,6 +1481,11 @@ int nested_svm_check_permissions(struct kvm_vcpu *vcpu)
return 0;
}
+int nested_svm_check_permissions(struct kvm_vcpu *vcpu)
+{
+ return __nested_svm_check_permissions(vcpu, vcpu->arch.efer & EFER_SVME);
+}
+
static bool nested_svm_is_exception_vmexit(struct kvm_vcpu *vcpu, u8 vector,
u32 error_code)
{
diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
index 7a854e81b6560..e6b1f8fa98a20 100644
--- a/arch/x86/kvm/svm/svm.c
+++ b/arch/x86/kvm/svm/svm.c
@@ -2283,9 +2283,19 @@ void svm_set_gif(struct vcpu_svm *svm, bool value)
static int stgi_interception(struct kvm_vcpu *vcpu)
{
+ bool insn_allowed;
int ret;
- if (nested_svm_check_permissions(vcpu))
+ /*
+ * According to the APM, STGI is allowed even with SVM disabled if SVM
+ * Lock or device exclusion vector (DEV) are supported. DEV is part of
+ * the SKINIT architecture.
+ */
+ insn_allowed = (vcpu->arch.efer & EFER_SVME) ||
+ guest_cpu_cap_has(vcpu, X86_FEATURE_SVML) ||
+ guest_cpu_cap_has(vcpu, X86_FEATURE_SKINIT);
+
+ if (__nested_svm_check_permissions(vcpu, insn_allowed))
return 1;
ret = kvm_skip_emulated_instruction(vcpu);
diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h
index 01be93a53d077..0ec09559767a3 100644
--- a/arch/x86/kvm/svm/svm.h
+++ b/arch/x86/kvm/svm/svm.h
@@ -769,6 +769,7 @@ static inline int nested_svm_simple_vmexit(struct vcpu_svm *svm, u32 exit_code)
}
int nested_svm_exit_handled(struct vcpu_svm *svm);
+int __nested_svm_check_permissions(struct kvm_vcpu *vcpu, bool insn_allowed);
int nested_svm_check_permissions(struct kvm_vcpu *vcpu);
int nested_svm_check_exception(struct vcpu_svm *svm, unsigned nr,
bool has_error_code, u32 error_code);
--
2.52.0.457.g6b5491de43-goog
next prev parent reply other threads:[~2026-01-22 4:58 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-22 4:57 [PATCH V3 0/5] Align SVM with APM defined behaviors Kevin Cheng
2026-01-22 4:57 ` [PATCH V3 1/5] KVM: SVM: Move STGI and CLGI intercept handling Kevin Cheng
2026-01-22 4:57 ` Kevin Cheng [this message]
2026-02-12 21:16 ` [PATCH V3 2/5] KVM: SVM: Inject #UD for STGI if EFER.SVME=0 and SVM Lock and DEV are not available Sean Christopherson
2026-02-12 21:18 ` Sean Christopherson
2026-02-12 21:57 ` Kevin Cheng
2026-02-13 15:06 ` Sean Christopherson
2026-01-22 4:57 ` [PATCH V3 3/5] KVM: SVM: Inject #UD for INVLPGA if EFER.SVME=0 Kevin Cheng
2026-01-22 4:57 ` [PATCH V3 4/5] KVM: SVM: Recalc instructions intercepts when EFER.SVME is toggled Kevin Cheng
2026-01-22 4:57 ` [PATCH V3 5/5] KVM: SVM: Raise #UD if VMMCALL instruction is not intercepted Kevin Cheng
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=20260122045755.205203-3-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®