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

Message ID 20230302052511.1918-35-xin3.li@intel.com
State New
Headers
Series x86: enable FRED for x86-64 |

Commit Message

Li, Xin3 March 2, 2023, 5:25 a.m. UTC
  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(-)
  

Comments

Sean Christopherson March 6, 2023, 6:11 p.m. UTC | #1
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
  
Li, Xin3 March 6, 2023, 6:56 p.m. UTC | #2
> > 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
  

Patch

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);
 	}