]> git.baikalelectronics.ru Git - kernel.git/commitdiff
KVM: nSVM: Transparently handle L1 -> L2 NMI re-injection
authorMaciej S. Szmigiero <maciej.szmigiero@oracle.com>
Sun, 1 May 2022 22:07:34 +0000 (00:07 +0200)
committerPaolo Bonzini <pbonzini@redhat.com>
Wed, 8 Jun 2022 08:47:03 +0000 (04:47 -0400)
A NMI that L1 wants to inject into its L2 should be directly re-injected,
without causing L0 side effects like engaging NMI blocking for L1.

It's also worth noting that in this case it is L1 responsibility
to track the NMI window status for its L2 guest.

Signed-off-by: Maciej S. Szmigiero <maciej.szmigiero@oracle.com>
Message-Id: <f894d13501cd48157b3069a4b4c7369575ddb60e.1651440202.git.maciej.szmigiero@oracle.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/svm/nested.c
arch/x86/kvm/svm/svm.c
arch/x86/kvm/svm/svm.h

index 0d25dea407965674f3e0bfb2d5b0ba5453e703fd..688f86b9202a70cb66cc81068f0061f1bf708824 100644 (file)
@@ -623,6 +623,16 @@ static inline bool is_evtinj_soft(u32 evtinj)
        return type == SVM_EVTINJ_TYPE_EXEPT && kvm_exception_is_soft(vector);
 }
 
+static bool is_evtinj_nmi(u32 evtinj)
+{
+       u32 type = evtinj & SVM_EVTINJ_TYPE_MASK;
+
+       if (!(evtinj & SVM_EVTINJ_VALID))
+               return false;
+
+       return type == SVM_EVTINJ_TYPE_NMI;
+}
+
 static void nested_vmcb02_prepare_control(struct vcpu_svm *svm,
                                          unsigned long vmcb12_rip)
 {
@@ -691,6 +701,7 @@ static void nested_vmcb02_prepare_control(struct vcpu_svm *svm,
        else if (boot_cpu_has(X86_FEATURE_NRIPS))
                vmcb02->control.next_rip    = vmcb12_rip;
 
+       svm->nmi_l1_to_l2 = is_evtinj_nmi(vmcb02->control.event_inj);
        if (is_evtinj_soft(vmcb02->control.event_inj)) {
                svm->soft_int_injected = true;
                svm->soft_int_csbase = svm->vmcb->save.cs.base;
@@ -873,6 +884,7 @@ int nested_svm_vmrun(struct kvm_vcpu *vcpu)
 
 out_exit_err:
        svm->nested.nested_run_pending = 0;
+       svm->nmi_l1_to_l2 = false;
        svm->soft_int_injected = false;
 
        svm->vmcb->control.exit_code    = SVM_EXIT_ERR;
index 0f4d38e5ceab94946646f9e5c035d43a43a1b707..5fda7e7102f207ac2c9295eb24020525a4ae469f 100644 (file)
@@ -3429,6 +3429,10 @@ static void svm_inject_nmi(struct kvm_vcpu *vcpu)
        struct vcpu_svm *svm = to_svm(vcpu);
 
        svm->vmcb->control.event_inj = SVM_EVTINJ_VALID | SVM_EVTINJ_TYPE_NMI;
+
+       if (svm->nmi_l1_to_l2)
+               return;
+
        vcpu->arch.hflags |= HF_NMI_MASK;
        if (!sev_es_guest(vcpu->kvm))
                svm_set_intercept(svm, INTERCEPT_IRET);
@@ -3769,8 +3773,10 @@ static void svm_complete_interrupts(struct kvm_vcpu *vcpu)
        u8 vector;
        int type;
        u32 exitintinfo = svm->vmcb->control.exit_int_info;
+       bool nmi_l1_to_l2 = svm->nmi_l1_to_l2;
        bool soft_int_injected = svm->soft_int_injected;
 
+       svm->nmi_l1_to_l2 = false;
        svm->soft_int_injected = false;
 
        /*
@@ -3802,6 +3808,7 @@ static void svm_complete_interrupts(struct kvm_vcpu *vcpu)
        switch (type) {
        case SVM_EXITINTINFO_TYPE_NMI:
                vcpu->arch.nmi_injected = true;
+               svm->nmi_l1_to_l2 = nmi_l1_to_l2;
                break;
        case SVM_EXITINTINFO_TYPE_EXEPT:
                /*
index f0b6111ee5b15ad8065f876f275e0cdc5352d6d5..24b5c73a8c87990cae86e7d09571d74b0f43f57b 100644 (file)
@@ -229,6 +229,7 @@ struct vcpu_svm {
 
        bool nmi_singlestep;
        u64 nmi_singlestep_guest_rflags;
+       bool nmi_l1_to_l2;
 
        unsigned long soft_int_csbase;
        unsigned long soft_int_old_rip;