[Devel] [PATCH 04/11] KVM: nSVM: Report NMIs as allowed when in L2 and Exit-on-NMI is set

Alexander Mikhalitsyn alexander.mikhalitsyn at virtuozzo.com
Thu Jun 23 12:55:16 MSK 2022


From: Paolo Bonzini <pbonzini at redhat.com>

Report NMIs as allowed when the vCPU is in L2 and L2 is being run with
Exit-on-NMI enabled, as NMIs are always unblocked from L1's perspective
in this case.

Signed-off-by: Paolo Bonzini <pbonzini at redhat.com>
(cherry picked from commit bbdad0b5a708ddb37a9f051504c2133fa92df97a)

nested_exit_on_nmi was absent, so, let it be in arch/x86/kvm/svm.c

https://jira.sw.ru/browse/PSBM-139278

Signed-off-by: Alexander Mikhalitsyn <alexander.mikhalitsyn at virtuozzo.com>
---
 arch/x86/kvm/svm.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index 7bd91caeb812..bed737e4df17 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -4967,11 +4967,20 @@ out:
 	return ret;
 }
 
+static inline bool nested_exit_on_nmi(struct vcpu_svm *svm)
+{
+	return (svm->nested.intercept & (1ULL << INTERCEPT_NMI));
+}
+
 static int svm_nmi_allowed(struct kvm_vcpu *vcpu)
 {
 	struct vcpu_svm *svm = to_svm(vcpu);
 	struct vmcb *vmcb = svm->vmcb;
 	int ret;
+
+	if (is_guest_mode(vcpu) && nested_exit_on_nmi(svm))
+		return 1;
+
 	ret = !(vmcb->control.int_state & SVM_INTERRUPT_SHADOW_MASK) &&
 	      !(svm->vcpu.arch.hflags & HF_NMI_MASK);
 	ret = ret && gif_set(svm) && nested_svm_nmi(svm);
-- 
2.36.1



More information about the Devel mailing list