[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20260122045755.205203-3-chengkev@google.com>
Date: Thu, 22 Jan 2026 04:57:51 +0000
From: Kevin Cheng <chengkev@...gle.com>
To: seanjc@...gle.com, pbonzini@...hat.com
Cc: kvm@...r.kernel.org, linux-kernel@...r.kernel.org, yosry.ahmed@...ux.dev,
Kevin Cheng <chengkev@...gle.com>
Subject: [PATCH V3 2/5] KVM: SVM: Inject #UD for STGI if EFER.SVME=0 and SVM
Lock and DEV are not available
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@...gle.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
Powered by blists - more mailing lists