[PATCH v4 34/34] KVM: x86/vmx: execute "int $2" for NMI reinjection when FRED is enabled

Xin Li posted 34 patches 3 years, 1 month ago
There is a newer version of this series
[PATCH v4 34/34] KVM: x86/vmx: execute "int $2" for NMI reinjection when FRED is enabled
Posted by Xin Li 3 years, 1 month ago
Execute "int $2" for NMI reinjection when FRED is enabled.

Tested-by: Shan Kang <shan.kang@intel.com>
Signed-off-by: Xin Li <xin3.li@intel.com>
---
 arch/x86/kvm/vmx/vmx.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index 30f854015c8c..b9644bd37672 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -7229,7 +7229,10 @@ static noinstr void vmx_vcpu_enter_exit(struct kvm_vcpu *vcpu,
 	if ((u16)vmx->exit_reason.basic == EXIT_REASON_EXCEPTION_NMI &&
 	    is_nmi(vmx_get_intr_info(vcpu))) {
 		kvm_before_interrupt(vcpu, KVM_HANDLING_NMI);
-		vmx_do_nmi_irqoff();
+		if (cpu_feature_enabled(X86_FEATURE_FRED))
+			asm volatile("int $2");
+		else
+			vmx_do_nmi_irqoff();
 		kvm_after_interrupt(vcpu);
 	}
 
-- 
2.34.1
Re: [PATCH v4 34/34] KVM: x86/vmx: execute "int $2" for NMI reinjection when FRED is enabled
Posted by Sean Christopherson 3 years, 1 month ago
On Wed, Mar 01, 2023, Xin Li wrote:
> Execute "int $2" for NMI reinjection when FRED is enabled.

This needs an explanation of _why_.  And as requested earlier[*], please avoid
"reinjection" in this context.

[*] https://lore.kernel.org/all/Y20f8v9ObO+IPwU+@google.com
RE: [PATCH v4 34/34] KVM: x86/vmx: execute "int $2" for NMI reinjection when FRED is enabled
Posted by Li, Xin3 3 years, 1 month ago
> > Execute "int $2" for NMI reinjection when FRED is enabled.
> 
> This needs an explanation of _why_.  And as requested earlier[*], please avoid
> "reinjection" in this context.

W/ FRED, we use ERETS to unblock NMI when returning from a NMI handler
(Setting bit 28 of CS).  And there are 2 approaches to do it:
1) "int $2", let the h/w do the job for us.
2) create a FRED stack frame, and then jump to fred_entrypoint_kernel
in arch/x86/entry/entry_64_fred.S.

I prefer "INT $2", what is your opinion?

> [*] https://lore.kernel.org/all/Y20f8v9ObO+IPwU+@google.com