Re: [PATCH v7 07/10] x86/nmi: Prepare for the new NMI-source vector encoding

From: Chao Gao
Date: Thu Jun 19 2025 - 03:45:11 EST


On Thu, Jun 12, 2025 at 02:48:46PM -0700, Sohil Mehta wrote:
>When using the send_IPI_* APIC calls, callers typically use NMI vector
>0x2 to trigger NMIs. The APIC APIs convert the NMI vector to the NMI
>delivery mode, which is eventually used to program the APIC.
>
>Before FRED, the hardware would ignore the vector used with NMI delivery
>mode. However, with NMI-source reporting, the vector information is
>relayed to the destination CPU, which sets the corresponding bit in the
>NMI-source bitmap. Unfortunately, the kernel now needs to maintain a new
>set of NMI vectors and differentiate them from the IDT vectors.
>
>Instead of creating a parallel set of send_NMI_* APIs to handle
>NMI-source vectors, enhance the existing send_IPI_* APIs with a new
>encoding scheme to handle the NMI delivery mode along with the
>NMI-source vector.
>
>NMI-source vectors would be encoded as:
> APIC_DM_NMI (0x400) | NMI_SOURCE_VECTOR (0x1-0xF)
>
>Also, introduce a helper to prepare the ICR value with the encoded
>delivery mode and vector. Update the guest paravirtual APIC code to use
>the new helper as well.
>
>While at it, rename APIC_DM_FIXED_MASK to the more appropriate
>APIC_DM_MASK.
>
>Suggested-by: Sean Christopherson <seanjc@xxxxxxxxxx>
>Co-developed-by: Xin Li (Intel) <xin@xxxxxxxxx>
>Signed-off-by: Xin Li (Intel) <xin@xxxxxxxxx>
>Signed-off-by: Sohil Mehta <sohil.mehta@xxxxxxxxx>

Reviewed-by: Chao Gao <chao.gao@xxxxxxxxx>

One nit below,

>--- a/arch/x86/kernel/apic/local.h
>+++ b/arch/x86/kernel/apic/local.h
>@@ -24,22 +24,24 @@ extern u32 x2apic_max_apicid;
>
> /* IPI */
>
>+u16 __prepare_ICR_DM_vector(u16 vector);
>+

This seems unnecessary. local.h already includes asm/apic.h, where the function
is defined.