Virtual NMI
v3 cover Virtual NMI
Currently, the Xen hypervisor delivers NMIs to the guests using the Event Injection mechanism. The Event Injection mechanism does not block the delivery of subsequent NMIs. So, the Xen Hypervisor tracks the NMI delivery and its completion (by intercepting the IRET instruction) before sending a new NMI.
With the 4th generation AMD EPYC, a hardware NMI virtualization support, Virtual NMI (VNMI), is introduced. The vNMI allows the hypervisor to inject the NMI into the guest w/o using Event Injection mechanism. No need to track the guest NMI and intercepting the IRET instruction.
NMI Virtualization support is indicated by CPUID Fn8000_000A_EDX[VNMI] = 1.[1]
NMI Virtualization is enabled by setting V_NMI_ENABLE (bit 26 in offset 60h of the VMCB). Enabling NMI Virtualization requires the NMI intercept bit to be set. An attempt to run a guest with V_NMI_ENABLE without the NMI intercept bit set results in #VMEXIT(INVALID) [1]
Three new bits are added to the VMCB field at offset 60h to provide NMI virtualization hardware support:
V_NMI(11): Indicates whether a virtual NMI is pending in the guest. The processor will clear V_NMI once it takes the virtual NMI. V_NMI_MASK(12): Indicates whether virtual NMIs are masked. The processor will set V_NMI_MASK once it takes the virtual NMI. V_NMI_MASK is cleared when the guest successfully completes an IRET instruction or #VMEXIT occurs while delivering the virtual NMI.V_NMI_ENABLE(26): Enables NMI virtualization. [1]
[1] https://docs.amd.com/v/u/en-US/24593_3.43
---
Changes in v3:
- Delete the introduced hvm_function_table::vNMI boolean and all the 3 vNMI hooks, hvm_function_table::is_vnmi_enabled, hvm_function_table::is_vnmi_masked and hvm_function_table::set_vnmi_pending.
- Use the HVM_INTR_SHADOW_NMI to indicate that the NMI is blocked rather than the usage of HVM_INTR_SHADOW_MOV_SS | HVM_INTR_SHADOW_STI.
- CI tests:
https://gitlab.com/xen-project/people/aabdelsa/xen/-/pipelines/2327265341
---
Changes in v2:
- Merge the patches for
"svm/vnmi: introduce the vnmi bit support in the cpuid feature set" and
"svm/vnmi: add the definitions for the svm vnmi management bits in the VMCB" into the one patch
"x86/svm: Add Enumerations for the SVM virtual NMI".
- Change the patch subject "svm/vnmi: Add support for the SVM Virtual NMI" to "x86/svm: Use virtual NMI when available"
- Move the print out of the VNMI capability to the patch "x86/svm: Use virtual NMI when available" when it is being used.
- Remove the hvm_intblk_vnmi enumeration that was introduced for the separate masked vNMI handling.
- Introduce the hvm_function_table's is_vnmi_enabled callback to allow for the SVM implementation to verify that the VNMI is enabled by checking the VMCB bits in addition to the CPUID reported support.
- Change the the name of the hvm_function_table's callback is_vnmi_pending to is_vnmi_masked.
- The svm_inject_nmi function gains a check for the distinct NMI injection handling when the VNMI is enabled.
- Simplify the check of AMD SVM Hardware support for the VNMI. The check cpu_has_svm_vnmi is performed unconditionally.
- Simplify the introduced changes diff for the vintr_t union for the VNMI bits support.
- Adopt the Xen formatting guidelines for the control structures.
- CI tests:
https://gitlab.com/xen-project/people/aabdelsa/xen/-/pipelines/2325298577
---
Abdelkareem Abdelsaamad (2):
x86/svm: Add Enumerations for the SVM virtual NMI x86/svm: Use the virtual NMI when available
xen/arch/x86/hvm/svm/intr.c | 9 +++++++++ xen/arch/x86/hvm/svm/svm.c | 5 ++++- xen/arch/x86/hvm/svm/vmcb.c | 2 ++ xen/arch/x86/hvm/svm/vmcb.h | 8 ++++++-- xen/arch/x86/include/asm/hvm/svm.h | 2 ++ 5 files changed, 23 insertions(+), 3 deletions(-)
Signature · 1 line
2.52.0
PATCH v3 1/2 x86/svm: Add Enumerations for the SVM virtual NMI
Introduce the cpuid bit for the SVM vNMI feature support for the x86\AMD platforms. The feature support is indicated by the CPUID Fn8000_000A_EDX[25] = 1.
Add defines for the three SVM's Virtual NMI (vNMI) managements bits in the VMCB structure's vintr_t:
vintr_t(11) - Virtual NMI is pending.vintr_t(12) - Virtual NMI is masked.vintr_t(26) - Enable NMI virtualization.
--- xen/arch/x86/hvm/svm/vmcb.h | 8 ++++++-- xen/arch/x86/include/asm/hvm/svm.h | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-)
xen/arch/x86/hvm/svm/vmcb.h +6 -2
@@ -336,13 +336,17 @@ typedef union u64 tpr: 8; u64 irq: 1; u64 vgif: 1; - u64 rsvd0: 6; + u64 rsvd0: 1; + u64 vnmi_pending: 1; + u64 vnmi_blocking:1; + u64:3 ; u64 prio: 4; u64 ign_tpr: 1; u64 rsvd1: 3; u64 intr_masking: 1; u64 vgif_enable: 1; - u64 rsvd2: 6; + u64 vnmi_enable: 1; + u64 rsvd2: 5; u64 vector: 8; u64 rsvd3: 24; } fields;
xen/arch/x86/include/asm/hvm/svm.h +2 -0
@@ -37,6 +37,7 @@ extern u32 svm_feature_flags;#define SVM_FEATURE_VGIF 16/* Virtual GIF */ #define SVM_FEATURE_SSS 19/* NPT Supervisor Shadow Stacks */ #define SVM_FEATURE_SPEC_CTRL 20/* MSR_SPEC_CTRL virtualisation */ +#define SVM_FEATURE_VNMI 25/* Virtual NMI */ #define SVM_FEATURE_BUS_LOCK 29/* Bus Lock Threshold */ static inline bool cpu_has_svm_feature (unsigned int feat)
@@ -57,6 +58,7 @@ static inline bool cpu_has_svm_feature(unsigned int feat)#define cpu_has_svm_vloadsave cpu_has_svm_feature(SVM_FEATURE_VLOADSAVE)#define cpu_has_svm_sss cpu_has_svm_feature(SVM_FEATURE_SSS)#define cpu_has_svm_spec_ctrl cpu_has_svm_feature(SVM_FEATURE_SPEC_CTRL) +#define cpu_has_svm_vnmi cpu_has_svm_feature(SVM_FEATURE_VNMI)#define cpu_has_svm_bus_lock cpu_has_svm_feature(SVM_FEATURE_BUS_LOCK)#define MSR_INTERCEPT_NONE 0
Signature · 1 line
2.52.0
Re: [PATCH v3 1/2] x86/svm: Add Enumerations for the SVM virtual NMI
Le 15/02/2026 à 19:24, Abdelkareem Abdelsaamad a écrit :
Quoted 54 lines
Introduce the cpuid bit for the SVM vNMI feature support for the x86\AMD platforms. The feature support is indicated by the CPUID Fn8000_000A_EDX[25] = 1.
Add defines for the three SVM's Virtual NMI (vNMI) managements bits in the VMCB structure's
vintr_t:
vintr_t(11)- Virtual NMI is pending.vintr_t(12)- Virtual NMI is masked.vintr_t(26)- Enable NMI virtualization.Signed-off-by Abdelkareem Abdelsaamad <[email protected]>--- xen/arch/x86/hvm/svm/vmcb.h | 8 ++++++-- xen/arch/x86/include/asm/hvm/svm.h | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-)xen/arch/x86/hvm/svm/vmcb.h +6
-2@@ -336,13 +336,17 @@ typedef union u64 tpr: 8; u64 irq: 1; u64 vgif: 1; - u64 rsvd0: 6; + u64 rsvd0: 1; + u64 vnmi_pending: 1; + u64 vnmi_blocking:1; + u64:3 ; u64 prio: 4; u64 ign_tpr: 1; u64 rsvd1: 3; u64 intr_masking: 1; u64 vgif_enable: 1; - u64 rsvd2: 6; + u64 vnmi_enable: 1; + u64 rsvd2: 5; u64 vector: 8; u64 rsvd3: 24; } fields;xen/arch/x86/include/asm/hvm/svm.h +1
-0@@ -37,6 +37,7 @@ extern u32 svm_feature_flags;#define SVM_FEATURE_VGIF 16/* Virtual GIF */ #define SVM_FEATURE_SSS 19/* NPT Supervisor Shadow Stacks */ #define SVM_FEATURE_SPEC_CTRL 20/* MSR_SPEC_CTRL virtualisation */ +#define SVM_FEATURE_VNMI 25/* Virtual NMI */ #define SVM_FEATURE_BUS_LOCK 29/* Bus Lock Threshold */ static inline bool cpu_has_svm_feature (unsigned int feat)
xen/arch/x86/include/asm/hvm/svm.h static inline bool cpu_has_svm_feature(unsigned int feat) · line 64
Quoted 7 lines
xen/arch/x86/include/asm/hvm/svm.h +1
-0@@ -57,6 +58,7 @@ static inline bool cpu_has_svm_feature(unsigned int feat)#define cpu_has_svm_vloadsave cpu_has_svm_feature(SVM_FEATURE_VLOADSAVE)#define cpu_has_svm_sss cpu_has_svm_feature(SVM_FEATURE_SSS)#define cpu_has_svm_spec_ctrl cpu_has_svm_feature(SVM_FEATURE_SPEC_CTRL) +#define cpu_has_svm_vnmi cpu_has_svm_feature(SVM_FEATURE_VNMI)#define cpu_has_svm_bus_lock cpu_has_svm_feature(SVM_FEATURE_BUS_LOCK)#define MSR_INTERCEPT_NONE 0
--
Teddy Astie | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
Re: [PATCH v3 1/2] x86/svm: Add Enumerations for the SVM virtual NMI
In reply to Abdelkareem Abdelsaamadxen/arch/x86/hvm/svm/vmcb.h typedef union · line 342
Quoted 11 lines · Abdelkareem Abdelsaamad
xen/arch/x86/hvm/svm/vmcb.h +4
-1@@ -336,13 +336,17 @@ typedef union u64 tpr: 8; u64 irq: 1; u64 vgif: 1; - u64 rsvd0: 6; + u64 rsvd0: 1; + u64 vnmi_pending: 1; + u64 vnmi_blocking:1; + u64:3 ;
Can we have a blank please ahead of the colon, to make it a little easier to actually notice?
Further for both rsvd0 and ...
xen/arch/x86/hvm/svm/vmcb.h typedef union · line 352
Quoted 11 lines
xen/arch/x86/hvm/svm/vmcb.h +2
-1u64 prio: 4; u64 ign_tpr: 1; u64 rsvd1: 3; u64 intr_masking: 1; u64 vgif_enable: 1; - u64 rsvd2: 6; + u64 vnmi_enable: 1; + u64 rsvd2: 5; u64 vector: 8; u64 rsvd3: 24; } fields;
... rsvd2 (i.e. the ones you touch anyway) I wonder if their identifiers couldn't be dropped at this occasion as well.
Jan
PATCH v3 2/2 x86/svm: Use the virtual NMI when available
In reply to Abdelkareem AbdelsaamadWith the Virtual NMI (vNMI), the pending NMI is simply stuffed into the VMCB and handed off to the hardware. There is no need for the artificial tracking of the NMI handling completion with the IRET instruction interception.
Adjust the svm_inject_nmi to rather inject the NMIs using the vNMI Hardware accelerated feature when the AMD platform support the vNMI.
Adjust the svm_get_interrupt_shadow to check if the vNMI is currently blocked by servicing another in-progress NMI.
--- xen/arch/x86/hvm/svm/intr.c | 9 +++++++++ xen/arch/x86/hvm/svm/svm.c | 5 ++++- xen/arch/x86/hvm/svm/vmcb.c | 2 ++ 3 files changed, 15 insertions(+), 1 deletion(-)
xen/arch/x86/hvm/svm/intr.c +9 -0
@@ -33,6 +33,15 @@ static void svm_inject_nmi(struct vcpu *v)u32 general1_intercepts =vmcb_get_general1_intercepts (vmcb);intinfo_t event; +if ( vmcb->_vintr.fields.vnmi_enable ) + { +if ( !vmcb->_vintr.fields.vnmi_pending && + !vmcb->_vintr.fields.vnmi_blocking ) + vmcb->_vintr.fields.vnmi_pending =1 ; + +return ; + } + event.raw =0 ; event.v = true; event.type =X86_ET_NMI ;
xen/arch/x86/hvm/svm/svm.c +4 -1
@@ -548,7 +548,9 @@ static unsigned cf_check int svm_get_interrupt_shadow(struct vcpu *v)if ( vmcb->int_stat.intr_shadow ) intr_shadow |=HVM_INTR_SHADOW_MOV_SS |HVM_INTR_SHADOW_STI ; -if (vmcb_get_general1_intercepts (vmcb) &GENERAL1_INTERCEPT_IRET ) +if ( vmcb->_vintr.fields.vnmi_enable + ? vmcb->_vintr.fields.vnmi_blocking + : (vmcb_get_general1_intercepts (vmcb) &GENERAL1_INTERCEPT_IRET ) ) intr_shadow |=HVM_INTR_SHADOW_NMI ;return intr_shadow;
@@ -2524,6 +2526,7 @@ const struct hvm_function_table * __init start_svm(void)P (cpu_has_tsc_ratio,"TSC Rate MSR" );P (cpu_has_svm_sss,"NPT Supervisor Shadow Stack" );P (cpu_has_svm_spec_ctrl,"MSR_SPEC_CTRL virtualisation" ); +P (cpu_has_svm_vnmi,"Virtual NMI" );P (cpu_has_svm_bus_lock,"Bus Lock Filter" );#undef P
xen/arch/x86/hvm/svm/vmcb.c +2 -0
@@ -184,6 +184,8 @@ static int construct_vmcb(struct vcpu *v)if ( default_xen_spec_ctrl ==SPEC_CTRL_STIBP ) v->arch.msrs->spec_ctrl.raw =SPEC_CTRL_STIBP ; + vmcb->_vintr.fields.vnmi_enable = cpu_has_svm_vnmi; +return 0 ; }
Signature · 1 line
2.52.0
Re: [PATCH v3 2/2] x86/svm: Use the virtual NMI when available
Le 15/02/2026 à 19:24, Abdelkareem Abdelsaamad a écrit :
Quoted 24 lines
With the Virtual NMI (vNMI), the pending NMI is simply stuffed into the VMCB and handed off to the hardware. There is no need for the artificial tracking of the NMI handling completion with the IRET instruction interception.
Adjust the
svm_inject_nmito rather inject the NMIs using the vNMI Hardware accelerated feature when the AMD platform support the vNMI.Adjust the
svm_get_interrupt_shadowto check if the vNMI is currently blocked by servicing another in-progress NMI.Signed-off-by Abdelkareem Abdelsaamad <[email protected]>--- xen/arch/x86/hvm/svm/intr.c | 9 +++++++++ xen/arch/x86/hvm/svm/svm.c | 5 ++++- xen/arch/x86/hvm/svm/vmcb.c | 2 ++ 3 files changed, 15 insertions(+), 1 deletion(-)xen/arch/x86/hvm/svm/intr.c +0
-0@@ -33,6 +33,15 @@ static void svm_inject_nmi(struct vcpu *v)u32 general1_intercepts =vmcb_get_general1_intercepts (vmcb);intinfo_t event;
xen/arch/x86/hvm/svm/intr.c static void svm_inject_nmi(struct vcpu *v) · line 44
Quoted 10 lines
xen/arch/x86/hvm/svm/intr.c +9
-0+if ( vmcb->_vintr.fields.vnmi_enable ) + { +if ( !vmcb->_vintr.fields.vnmi_pending && + !vmcb->_vintr.fields.vnmi_blocking ) + vmcb->_vintr.fields.vnmi_pending =1 ; + +return ; + } +
I think you need to update the clearbit for tpr (related to vintr) for the hardware to know that you modified the vnmi_pending bit.
This is done through vmcb_{get,set}_vintr in your case (this will also allow simplifying all the vmcb->_vintr).
You need to do something like
vintr_t intr = vmcb_get_vintr(vmcb);
...
if ( intr.fields.vnmi_enable )
{
if ( !intr.fields.vnmi_pending && !intr.vnmi_blocking )
{
intr.fields.vnmi_pending = 1;
vmcb_set_vintr(vmcb, intr); }
return;
}
Quoted 31 lines
xen/arch/x86/hvm/svm/intr.c +0
-0event.raw =0 ; event.v = true; event.type =X86_ET_NMI ;xen/arch/x86/hvm/svm/svm.c +4
-1@@ -548,7 +548,9 @@ static unsigned cf_check int svm_get_interrupt_shadow(struct vcpu *v)if ( vmcb->int_stat.intr_shadow ) intr_shadow |=HVM_INTR_SHADOW_MOV_SS |HVM_INTR_SHADOW_STI ; -if (vmcb_get_general1_intercepts (vmcb) &GENERAL1_INTERCEPT_IRET ) +if ( vmcb->_vintr.fields.vnmi_enable + ? vmcb->_vintr.fields.vnmi_blocking + : (vmcb_get_general1_intercepts (vmcb) &GENERAL1_INTERCEPT_IRET ) ) intr_shadow |=HVM_INTR_SHADOW_NMI ;return intr_shadow;@@ -2524,6 +2526,7 @@ const struct hvm_function_table * __init start_svm(void)P (cpu_has_tsc_ratio,"TSC Rate MSR" );P (cpu_has_svm_sss,"NPT Supervisor Shadow Stack" );P (cpu_has_svm_spec_ctrl,"MSR_SPEC_CTRL virtualisation" ); +P (cpu_has_svm_vnmi,"Virtual NMI" );P (cpu_has_svm_bus_lock,"Bus Lock Filter" );#undef Pxen/arch/x86/hvm/svm/vmcb.c +0
-0
xen/arch/x86/hvm/svm/vmcb.c static int construct_vmcb(struct vcpu *v) · line 191
Quoted 8 lines
xen/arch/x86/hvm/svm/vmcb.c +2
-0@@ -184,6 +184,8 @@ static int construct_vmcb(struct vcpu *v)if ( default_xen_spec_ctrl ==SPEC_CTRL_STIBP ) v->arch.msrs->spec_ctrl.raw =SPEC_CTRL_STIBP ; + vmcb->_vintr.fields.vnmi_enable = cpu_has_svm_vnmi; +return 0 ; }
Teddy
--
Teddy Astie | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
Re: [PATCH v3 2/2] x86/svm: Use the virtual NMI when available
Quoted 26 lines · Teddy Astie
Le 15/02/2026 à 19:24, Abdelkareem Abdelsaamad a écrit :
Quoted 25 lines
With the Virtual NMI (vNMI), the pending NMI is simply stuffed into the VMCB and handed off to the hardware. There is no need for the artificial tracking of the NMI handling completion with the IRET instruction interception.
Adjust the
svm_inject_nmito rather inject the NMIs using the vNMI Hardware accelerated feature when the AMD platform support the vNMI.Adjust the
svm_get_interrupt_shadowto check if the vNMI is currently blocked by servicing another in-progress NMI.Signed-off-by Abdelkareem Abdelsaamad <[email protected]>--- xen/arch/x86/hvm/svm/intr.c | 9 +++++++++ xen/arch/x86/hvm/svm/svm.c | 5 ++++- xen/arch/x86/hvm/svm/vmcb.c | 2 ++ 3 files changed, 15 insertions(+), 1 deletion(-)xen/arch/x86/hvm/svm/intr.c +0
-0@@ -33,6 +33,15 @@ static void svm_inject_nmi(struct vcpu *v)u32 general1_intercepts =vmcb_get_general1_intercepts (vmcb);intinfo_t event;
Quoted 11 lines
xen/arch/x86/hvm/svm/intr.c static void svm_inject_nmi(struct vcpu *v) · line 44
Quoted 9 lines
xen/arch/x86/hvm/svm/intr.c +9
-0+if ( vmcb->_vintr.fields.vnmi_enable ) + { +if ( !vmcb->_vintr.fields.vnmi_pending && + !vmcb->_vintr.fields.vnmi_blocking ) + vmcb->_vintr.fields.vnmi_pending =1 ; + +return ; + } +I think you need to update the clearbit for tpr (related to vintr) for the hardware to know that you modified the
vnmi_pendingbit.
What makes you think this? The APM states otherwise.
~Andrew
Re: [PATCH v3 2/2] x86/svm: Use the virtual NMI when available
Le 16/02/2026 à 11:16, Andrew Cooper a écrit :
Quoted 39 lines · Teddy Astie
Quoted 26 lines
Le 15/02/2026 à 19:24, Abdelkareem Abdelsaamad a écrit :
Quoted 25 lines
With the Virtual NMI (vNMI), the pending NMI is simply stuffed into the VMCB and handed off to the hardware. There is no need for the artificial tracking of the NMI handling completion with the IRET instruction interception.
Adjust the
svm_inject_nmito rather inject the NMIs using the vNMI Hardware accelerated feature when the AMD platform support the vNMI.Adjust the
svm_get_interrupt_shadowto check if the vNMI is currently blocked by servicing another in-progress NMI.Signed-off-by Abdelkareem Abdelsaamad <[email protected]>--- xen/arch/x86/hvm/svm/intr.c | 9 +++++++++ xen/arch/x86/hvm/svm/svm.c | 5 ++++- xen/arch/x86/hvm/svm/vmcb.c | 2 ++ 3 files changed, 15 insertions(+), 1 deletion(-)xen/arch/x86/hvm/svm/intr.c +0
-0@@ -33,6 +33,15 @@ static void svm_inject_nmi(struct vcpu *v)u32 general1_intercepts =vmcb_get_general1_intercepts (vmcb);intinfo_t event;Quoted 11 lines
xen/arch/x86/hvm/svm/intr.c static void svm_inject_nmi(struct vcpu *v) · line 44
Quoted 9 lines
xen/arch/x86/hvm/svm/intr.c +9
-0+if ( vmcb->_vintr.fields.vnmi_enable ) + { +if ( !vmcb->_vintr.fields.vnmi_pending && + !vmcb->_vintr.fields.vnmi_blocking ) + vmcb->_vintr.fields.vnmi_pending =1 ; + +return ; + } +I think you need to update the clearbit for tpr (related to vintr) for the hardware to know that you modified the
vnmi_pendingbit.
Quoted 2 lines
What makes you think this? The APM states otherwise.
The APM state doesn't appears to state regarding this; it's neither a part of the "VMCB Clear Field" layout part nor the the "explicitely not cached" list.
So I assume that it may be covered by the TPR clean-bit (which is the same part of vmcb); as it's actually unclear if hardware wants it or not.
Quoted 2 lines
~Andrew
Teddy
--
Teddy Astie | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
Re: [PATCH v3 2/2] x86/svm: Use the virtual NMI when available
Quoted 39 lines · Teddy Astie
Le 16/02/2026 à 11:16, Andrew Cooper a écrit :
Quoted 38 lines · Teddy Astie
Quoted 37 lines
Le 15/02/2026 à 19:24, Abdelkareem Abdelsaamad a écrit :
Quoted 24 lines
With the Virtual NMI (vNMI), the pending NMI is simply stuffed into the VMCB and handed off to the hardware. There is no need for the artificial tracking of the NMI handling completion with the IRET instruction interception.
Adjust the
svm_inject_nmito rather inject the NMIs using the vNMI Hardware accelerated feature when the AMD platform support the vNMI.Adjust the
svm_get_interrupt_shadowto check if the vNMI is currently blocked by servicing another in-progress NMI.Signed-off-by Abdelkareem Abdelsaamad <[email protected]>--- xen/arch/x86/hvm/svm/intr.c | 9 +++++++++ xen/arch/x86/hvm/svm/svm.c | 5 ++++- xen/arch/x86/hvm/svm/vmcb.c | 2 ++ 3 files changed, 15 insertions(+), 1 deletion(-)xen/arch/x86/hvm/svm/intr.c +0
-0@@ -33,6 +33,15 @@ static void svm_inject_nmi(struct vcpu *v)u32 general1_intercepts =vmcb_get_general1_intercepts (vmcb);intinfo_t event;xen/arch/x86/hvm/svm/intr.c static void svm_inject_nmi(struct vcpu *v) · line 44
Quoted 10 lines
xen/arch/x86/hvm/svm/intr.c +9
-0+if ( vmcb->_vintr.fields.vnmi_enable ) + { +if ( !vmcb->_vintr.fields.vnmi_pending && + !vmcb->_vintr.fields.vnmi_blocking ) + vmcb->_vintr.fields.vnmi_pending =1 ; + +return ; + } +I think you need to update the clearbit for tpr (related to vintr) for the hardware to know that you modified the
vnmi_pendingbit.
Quoted 3 lines
Quoted 2 lines
What makes you think this? The APM states otherwise.
The APM state doesn't appears to state regarding this;
The APM does state what is part of the TPR cleanbit, and vNMI is not amongst these.
Quoted 6 lines
it's neither a
part of the "VMCB Clear Field" layout part nor the the "explicitely not cached" list.So I assume that it may be covered by the TPR clean-bit (which is the same part of vmcb); as it's actually unclear if hardware wants it or not.
This is very different to your original feedback though.
It's fine for review feedback to be of the form "have you investigated the clean bits?", but if you're not sure, you must not phrase your feedback as an instruction to check the cleanbit.
~Andrew
Re: [PATCH v3 2/2] x86/svm: Use the virtual NMI when available
Le 16/02/2026 à 12:47, Andrew Cooper a écrit :
Quoted 40 lines · Teddy Astie
Quoted 39 lines
Le 16/02/2026 à 11:16, Andrew Cooper a écrit :
Quoted 38 lines · Teddy Astie
Quoted 37 lines
Le 15/02/2026 à 19:24, Abdelkareem Abdelsaamad a écrit :
Quoted 24 lines
With the Virtual NMI (vNMI), the pending NMI is simply stuffed into the VMCB and handed off to the hardware. There is no need for the artificial tracking of the NMI handling completion with the IRET instruction interception.
Adjust the
svm_inject_nmito rather inject the NMIs using the vNMI Hardware accelerated feature when the AMD platform support the vNMI.Adjust the
svm_get_interrupt_shadowto check if the vNMI is currently blocked by servicing another in-progress NMI.Signed-off-by Abdelkareem Abdelsaamad <[email protected]>--- xen/arch/x86/hvm/svm/intr.c | 9 +++++++++ xen/arch/x86/hvm/svm/svm.c | 5 ++++- xen/arch/x86/hvm/svm/vmcb.c | 2 ++ 3 files changed, 15 insertions(+), 1 deletion(-)xen/arch/x86/hvm/svm/intr.c +0
-0@@ -33,6 +33,15 @@ static void svm_inject_nmi(struct vcpu *v)u32 general1_intercepts =vmcb_get_general1_intercepts (vmcb);intinfo_t event;xen/arch/x86/hvm/svm/intr.c static void svm_inject_nmi(struct vcpu *v) · line 44
Quoted 10 lines
xen/arch/x86/hvm/svm/intr.c +9
-0+if ( vmcb->_vintr.fields.vnmi_enable ) + { +if ( !vmcb->_vintr.fields.vnmi_pending && + !vmcb->_vintr.fields.vnmi_blocking ) + vmcb->_vintr.fields.vnmi_pending =1 ; + +return ; + } +I think you need to update the clearbit for tpr (related to vintr) for the hardware to know that you modified the
vnmi_pendingbit.
Quoted 7 lines
Quoted 3 lines
Quoted 2 lines
What makes you think this? The APM states otherwise.
The APM state doesn't appears to state regarding this;
The APM does state what is part of the TPR cleanbit, and vNMI is not amongst these.
APM doesn't explicitly state that; though KVM assumes that it is and sets the cleanbits [1]. I think we want to have some clarifications from AMD on what's actually required here.
Quoted 4 lines
Quoted 4 lines
it's neither a
part of the "VMCB Clear Field" layout part nor the the "explicitely not cached" list.
Quoted 9 lines
Quoted 2 lines
So I assume that it may be covered by the TPR clean-bit (which is the same part of vmcb); as it's actually unclear if hardware wants it or not.
This is very different to your original feedback though.
It's fine for review feedback to be of the form "have you investigated the clean bits?", but if you're not sure, you must not phrase your feedback as an instruction to check the cleanbit.
Sorry, I may have been a bit too fast on that.
Quoted 2 lines
~Andrew
Teddy
--
Teddy Astie | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
Re: [PATCH v3 2/2] x86/svm: Use the virtual NMI when available
Quoted 47 lines · Teddy Astie
Le 16/02/2026 à 12:47, Andrew Cooper a écrit :
Quoted 40 lines · Teddy Astie
Quoted 39 lines
Le 16/02/2026 à 11:16, Andrew Cooper a écrit :
Quoted 38 lines · Teddy Astie
Quoted 37 lines
Le 15/02/2026 à 19:24, Abdelkareem Abdelsaamad a écrit :
Quoted 24 lines
With the Virtual NMI (vNMI), the pending NMI is simply stuffed into the VMCB and handed off to the hardware. There is no need for the artificial tracking of the NMI handling completion with the IRET instruction interception.
Adjust the
svm_inject_nmito rather inject the NMIs using the vNMI Hardware accelerated feature when the AMD platform support the vNMI.Adjust the
svm_get_interrupt_shadowto check if the vNMI is currently blocked by servicing another in-progress NMI.Signed-off-by Abdelkareem Abdelsaamad <[email protected]>--- xen/arch/x86/hvm/svm/intr.c | 9 +++++++++ xen/arch/x86/hvm/svm/svm.c | 5 ++++- xen/arch/x86/hvm/svm/vmcb.c | 2 ++ 3 files changed, 15 insertions(+), 1 deletion(-)xen/arch/x86/hvm/svm/intr.c +0
-0@@ -33,6 +33,15 @@ static void svm_inject_nmi(struct vcpu *v)u32 general1_intercepts =vmcb_get_general1_intercepts (vmcb);intinfo_t event;xen/arch/x86/hvm/svm/intr.c static void svm_inject_nmi(struct vcpu *v) · line 44
Quoted 10 lines
xen/arch/x86/hvm/svm/intr.c +9
-0+if ( vmcb->_vintr.fields.vnmi_enable ) + { +if ( !vmcb->_vintr.fields.vnmi_pending && + !vmcb->_vintr.fields.vnmi_blocking ) + vmcb->_vintr.fields.vnmi_pending =1 ; + +return ; + } +I think you need to update the clearbit for tpr (related to vintr) for the hardware to know that you modified the
vnmi_pendingbit.Quoted 6 lines
Quoted 3 lines
Quoted 2 lines
What makes you think this? The APM states otherwise.
The APM state doesn't appears to state regarding this;
The APM does state what is part of the TPR cleanbit, and vNMI is not amongst these.
Quoted 6 lines
APM doesn't explicitly state that; though KVM assumes that it is and sets the cleanbits [1]. I think we want to have some clarifications from AMD on what's actually required here.
I can see at least 2 bugs in that function. AMD tentatively say that vNMI is not subject to a cleanbit, but I'm waiting on some other clarifications.
~Andrew
Re: [PATCH v3 2/2] x86/svm: Use the virtual NMI when available
In reply to Abdelkareem AbdelsaamadQuoted 6 lines · Abdelkareem Abdelsaamad
xen/arch/x86/hvm/svm/intr.c +0
-0@@ -33,6 +33,15 @@ static void svm_inject_nmi(struct vcpu *v)u32 general1_intercepts =vmcb_get_general1_intercepts (vmcb);
xen/arch/x86/hvm/svm/intr.c static void svm_inject_nmi(struct vcpu *v) · line 43
Quoted 10 lines
xen/arch/x86/hvm/svm/intr.c +8
-0intinfo_t event; +if ( vmcb->_vintr.fields.vnmi_enable ) + { +if ( !vmcb->_vintr.fields.vnmi_pending && + !vmcb->_vintr.fields.vnmi_blocking ) + vmcb->_vintr.fields.vnmi_pending =1 ; + +return ; + }
So what happens to the NMI we're trying to inject when NMIs are currently blocked?
~Andrew
Re: Re: [PATCH v3 2/2] x86/svm: Use the virtual NMI when available
Quoted 2 lines · Andrew Cooper
So what happens to the NMI we're trying to inject when NMIs are currently blocked?
Ah, I see this...
The handling flow will eventually land on the function svm_enable_intr_window with HVM_INTR_SHADOW_NMI. The logic inside the function svm_enable_intr_window will drive it to create a vintr and set up the VMCB to intercept that created vintr. I see that the code logic in svm_enable_intr_window should be extended to skip creating such vintr and just return the same as the handling with Event injected NMI when the GENERAL1_INTERCEPT_IRET is already set.
Quoted 1 line
~Andrew
--Abdelkareem
Re: [PATCH v3 2/2] x86/svm: Use the virtual NMI when available
Quoted 6 lines · Abdelkareem Abdelsaamad
Quoted 2 lines · Andrew Cooper
So what happens to the NMI we're trying to inject when NMIs are currently blocked?
Ah, I see this...
The handling flow will eventually land on the functionsvm_enable_intr_windowwithHVM_INTR_SHADOW_NMI.
What happens is that you drop the NMI on the floor and discard it. Note how svm_inject_nmi() has no return value, and therefore must not fail.
It is buggy to check the blocked bit when injecting using this mechanism. The blocked bit roughly equates to "NMI in progress" in the guest, and it is explicitly possible to queue another NMI while the first is in progress.
Both pending and masked being set roughly means "One NMI in progress, and one queued", which is a perfectly fine state to be in.
~Andrew
Re: Re: Re: Re: [PATCH v3 2/2] x86/svm: Use the virtual NMI when available
Quoted 11 lines · Andrew Cooper
Quoted 6 lines · Abdelkareem Abdelsaamad
Quoted 2 lines · Andrew Cooper
So what happens to the NMI we're trying to inject when NMIs are currently blocked?
Ah, I see this...
The handling flow will eventually land on the functionsvm_enable_intr_windowwithHVM_INTR_SHADOW_NMI.What happens is that you drop the NMI on the floor and discard it. Note how
svm_inject_nmi()has no return value, and therefore must not fail.
Quoted 7 lines
It is buggy to check the blocked bit when injecting using this mechanism. The blocked bit roughly equates to "NMI in progress" in the guest, and it is explicitly possible to queue another NMI while the first is in progress.
Both pending and masked being set roughly means "One NMI in progress, and one queued", which is a perfectly fine state to be in.
Right, Actually, I see the changes in the svm_get_interrupt_shadow and the svm_enable_intr_window functions are not correct. There should not be changes in the two functions. The vNMI handling for multiple\concurrent NMIs should first set the vnmi_pending bit for the first NMI. The subsequent NMI should either see the vnmi_pending bit is still set, in which case, it should be just dropped, i.e, do nothing or it can see the vnmi_pending is cleared in which case the current vNMI might be is in progress or might be completed but the code should safely not consider the NMI as blocked, if the vnmi_blocking is set.
The confusion, I had, is due to looking at the KVM codebase. The upstream commit fa4c027a7956 ("KVM: x86: Add support for SVM's Virtual NMI") [1] that was later fixed with the fixing upstream commitb2ce89978889 ("KVM: SVM: vNMI pending bit is V_NMI_PENDING_MASK not V_NMI_BLOCKING_MASK") [2].
--Abdelkareem
[1]https://lore.kernel.org/r/[email protected] [2]https://lore.kernel.org/r/be4ca192eb0c1e69a210db3009ca984e6a54ae69.1684495380.git.maciej.szmigiero@oracle.com
Re: [PATCH v3 2/2] x86/svm: Use the virtual NMI when available
In reply to Abdelkareem Abdelsaamadxen/arch/x86/hvm/svm/intr.c static void svm_inject_nmi(struct vcpu *v) · line 40
Quoted 11 lines · Abdelkareem Abdelsaamad
xen/arch/x86/hvm/svm/intr.c +5
-0@@ -33,6 +33,15 @@ static void svm_inject_nmi(struct vcpu *v)u32 general1_intercepts =vmcb_get_general1_intercepts (vmcb);intinfo_t event; +if ( vmcb->_vintr.fields.vnmi_enable ) + { +if ( !vmcb->_vintr.fields.vnmi_pending && + !vmcb->_vintr.fields.vnmi_blocking ) + vmcb->_vintr.fields.vnmi_pending =1 ;
Nit: Off-by-1 indentation, while ...
xen/arch/x86/hvm/svm/intr.c static void svm_inject_nmi(struct vcpu *v) · line 42
Quoted 1 line
xen/arch/x86/hvm/svm/intr.c +1
-0+return ;
... interestingly this one's indented correctly.
Jan