Message ID | 20250211025828.3072076-9-binbin.wu@linux.intel.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | KVM: TDX: TDX interrupts | expand |
>+static void tdx_complete_interrupts(struct kvm_vcpu *vcpu) >+{ >+ /* Avoid costly SEAMCALL if no NMI was injected. */ >+ if (vcpu->arch.nmi_injected) { >+ /* >+ * No need to request KVM_REQ_EVENT because PEND_NMI is still >+ * set if NMI re-injection needed. No other event types need >+ * to be handled because TDX doesn't support injection of >+ * exception, SMI or interrupt (via event injection). >+ */ >+ vcpu->arch.nmi_injected = td_management_read8(to_tdx(vcpu), >+ TD_VCPU_PEND_NMI); >+ } Why does KVM care whether/when an NMI is injected by the TDX module? I think we can simply set nmi_injected to false unconditionally here, or even in tdx_inject_nmi(). From KVM's perspective, NMI injection is complete right after writing to PEND_NMI. It is the TDX module that should inject the NMI at the right time and do the re-injection. >+} >+
On 2/13/2025 4:20 PM, Chao Gao wrote: >> +static void tdx_complete_interrupts(struct kvm_vcpu *vcpu) >> +{ >> + /* Avoid costly SEAMCALL if no NMI was injected. */ >> + if (vcpu->arch.nmi_injected) { >> + /* >> + * No need to request KVM_REQ_EVENT because PEND_NMI is still >> + * set if NMI re-injection needed. No other event types need >> + * to be handled because TDX doesn't support injection of >> + * exception, SMI or interrupt (via event injection). >> + */ >> + vcpu->arch.nmi_injected = td_management_read8(to_tdx(vcpu), >> + TD_VCPU_PEND_NMI); >> + } > Why does KVM care whether/when an NMI is injected by the TDX module? > > I think we can simply set nmi_injected to false unconditionally here, or even in > tdx_inject_nmi(). From KVM's perspective, NMI injection is complete right after > writing to PEND_NMI. It is the TDX module that should inject the NMI at the > right time and do the re-injection. Yes, it can/should be cleared unconditionally here. Previously (v19 and before), nmi_injected will impact the limit of pending nmi. Now, we don't care the limit of pending nmi because more pending NMIs will be collapsed to the one pending in the TDX module. Will update it. Thanks! > > >> +} >> +
diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c index ba9038ac5bf7..9737574b8049 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -803,6 +803,21 @@ int tdx_vcpu_pre_run(struct kvm_vcpu *vcpu) return 1; } +static void tdx_complete_interrupts(struct kvm_vcpu *vcpu) +{ + /* Avoid costly SEAMCALL if no NMI was injected. */ + if (vcpu->arch.nmi_injected) { + /* + * No need to request KVM_REQ_EVENT because PEND_NMI is still + * set if NMI re-injection needed. No other event types need + * to be handled because TDX doesn't support injection of + * exception, SMI or interrupt (via event injection). + */ + vcpu->arch.nmi_injected = td_management_read8(to_tdx(vcpu), + TD_VCPU_PEND_NMI); + } +} + struct tdx_uret_msr { u32 msr; unsigned int slot; @@ -985,6 +1000,8 @@ fastpath_t tdx_vcpu_run(struct kvm_vcpu *vcpu, bool force_immediate_exit) if (unlikely(tdx_failed_vmentry(vcpu))) return EXIT_FASTPATH_NONE; + tdx_complete_interrupts(vcpu); + return tdx_exit_handlers_fastpath(vcpu); }