[PATCH v3 02/11] x86/irq: Define NMI source vectors

Jacob Pan posted 11 patches 1 year, 5 months ago
[PATCH v3 02/11] x86/irq: Define NMI source vectors
Posted by Jacob Pan 1 year, 5 months ago
When NMI-source reporting is supported, each logical processor maintains
a 16-bit NMI-source bitmap. It is up to the system software to assign NMI
sources for their matching vector (bit position) in the bitmap.

Notice that NMI source vector is in a different namespace than the IDT
vectors. Though they share the same programming interface/field in the
NMI originator.

This initial allocation of the NMI sources are limited to local NMIs in
that there is no external device NMI usage yet.

Signed-off-by: Jacob Pan <jacob.jun.pan@linux.intel.com>
---
 arch/x86/include/asm/irq_vectors.h | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/arch/x86/include/asm/irq_vectors.h b/arch/x86/include/asm/irq_vectors.h
index 13aea8fc3d45..e4cd33bc4fef 100644
--- a/arch/x86/include/asm/irq_vectors.h
+++ b/arch/x86/include/asm/irq_vectors.h
@@ -105,6 +105,34 @@
 
 #define NR_VECTORS			 256
 
+/*
+ * The NMI senders specify the NMI source vector as an 8bit integer in their
+ * vector field with NMI delivery mode. A local APIC receiving an NMI will
+ * set the corresponding bit in a 16bit bitmask, which is accumulated until
+ * the NMI is delivered.
+ * When a sender didn't specify an NMI source vector the source vector will
+ * be 0, which will result in bit 0 of the bitmask being set. For out of
+ * bounds vectors >= 16 bit 0 will also be set.
+ * When bit 0 is set, system software must invoke all registered NMI handlers
+ * as if NMI source feature is not enabled.
+ *
+ * Vector 2 is reserved for matching IDT NMI vector where it may be hardcoded
+ * by some external devices.
+ *
+ * The NMI source vectors are sorted by descending priority with the exceptions
+ * of 0 and 2.
+ */
+#define NMI_SOURCE_VEC_UNKNOWN		0
+#define NMI_SOURCE_VEC_IPI_REBOOT	1	/* Crash reboot */
+#define NMI_SOURCE_VEC_IDT_NMI		2	/* Match IDT NMI vector 2 */
+#define NMI_SOURCE_VEC_IPI_SMP_STOP	3	/* Panic stop CPU */
+#define NMI_SOURCE_VEC_IPI_BT		4	/* CPU backtrace */
+#define NMI_SOURCE_VEC_PMI		5	/* PerfMon counters */
+#define NMI_SOURCE_VEC_IPI_KGDB		6	/* KGDB */
+#define NMI_SOURCE_VEC_IPI_MCE		7	/* MCE injection */
+#define NMI_SOURCE_VEC_IPI_TEST		8	/* For remote and local IPIs */
+#define NR_NMI_SOURCE_VECTORS		9
+
 #ifdef CONFIG_X86_LOCAL_APIC
 #define FIRST_SYSTEM_VECTOR		POSTED_MSI_NOTIFICATION_VECTOR
 #else
-- 
2.25.1
Re: [PATCH v3 02/11] x86/irq: Define NMI source vectors
Posted by Xin Li 1 year, 5 months ago
On 6/28/2024 1:18 PM, Jacob Pan wrote:
> When NMI-source reporting is supported, each logical processor maintains
> a 16-bit NMI-source bitmap. It is up to the system software to assign NMI
> sources for their matching vector (bit position) in the bitmap.
> 
> Notice that NMI source vector is in a different namespace than the IDT
> vectors. Though they share the same programming interface/field in the
> NMI originator.
> 
> This initial allocation of the NMI sources are limited to local NMIs in
> that there is no external device NMI usage yet.
> 
> Signed-off-by: Jacob Pan <jacob.jun.pan@linux.intel.com>
> ---
>   arch/x86/include/asm/irq_vectors.h | 28 ++++++++++++++++++++++++++++
>   1 file changed, 28 insertions(+)
> 
> diff --git a/arch/x86/include/asm/irq_vectors.h b/arch/x86/include/asm/irq_vectors.h
> index 13aea8fc3d45..e4cd33bc4fef 100644
> --- a/arch/x86/include/asm/irq_vectors.h
> +++ b/arch/x86/include/asm/irq_vectors.h
> @@ -105,6 +105,34 @@
>   
>   #define NR_VECTORS			 256
>   
> +/*
> + * The NMI senders specify the NMI source vector as an 8bit integer in their

s/The NMI senders/NMI senders/

> + * vector field with NMI delivery mode. A local APIC receiving an NMI will
> + * set the corresponding bit in a 16bit bitmask, which is accumulated until
> + * the NMI is delivered.
> + * When a sender didn't specify an NMI source vector the source vector will
> + * be 0, which will result in bit 0 of the bitmask being set. For out of
> + * bounds vectors >= 16 bit 0 will also be set.
> + * When bit 0 is set, system software must invoke all registered NMI handlers
> + * as if NMI source feature is not enabled.

Add empty lines in the above paragraph.

> + *
> + * Vector 2 is reserved for matching IDT NMI vector where it may be hardcoded
> + * by some external devices.
> + *
> + * The NMI source vectors are sorted by descending priority with the exceptions
> + * of 0 and 2.
> + */
> +#define NMI_SOURCE_VEC_UNKNOWN		0
> +#define NMI_SOURCE_VEC_IPI_REBOOT	1	/* Crash reboot */
> +#define NMI_SOURCE_VEC_IDT_NMI		2	/* Match IDT NMI vector 2 */
> +#define NMI_SOURCE_VEC_IPI_SMP_STOP	3	/* Panic stop CPU */
> +#define NMI_SOURCE_VEC_IPI_BT		4	/* CPU backtrace */
> +#define NMI_SOURCE_VEC_PMI		5	/* PerfMon counters */
> +#define NMI_SOURCE_VEC_IPI_KGDB		6	/* KGDB */
> +#define NMI_SOURCE_VEC_IPI_MCE		7	/* MCE injection */
> +#define NMI_SOURCE_VEC_IPI_TEST		8	/* For remote and local IPIs */
> +#define NR_NMI_SOURCE_VECTORS		9

Fix alignment.

> +
>   #ifdef CONFIG_X86_LOCAL_APIC
>   #define FIRST_SYSTEM_VECTOR		POSTED_MSI_NOTIFICATION_VECTOR
>   #else
Re: [PATCH v3 02/11] x86/irq: Define NMI source vectors
Posted by Jacob Pan 1 year, 5 months ago
On Sat, 29 Jun 2024 11:32:10 -0700, Xin Li <xin@zytor.com> wrote:

> On 6/28/2024 1:18 PM, Jacob Pan wrote:
> > When NMI-source reporting is supported, each logical processor maintains
> > a 16-bit NMI-source bitmap. It is up to the system software to assign
> > NMI sources for their matching vector (bit position) in the bitmap.
> > 
> > Notice that NMI source vector is in a different namespace than the IDT
> > vectors. Though they share the same programming interface/field in the
> > NMI originator.
> > 
> > This initial allocation of the NMI sources are limited to local NMIs in
> > that there is no external device NMI usage yet.
> > 
> > Signed-off-by: Jacob Pan <jacob.jun.pan@linux.intel.com>
> > ---
> >   arch/x86/include/asm/irq_vectors.h | 28 ++++++++++++++++++++++++++++
> >   1 file changed, 28 insertions(+)
> > 
> > diff --git a/arch/x86/include/asm/irq_vectors.h
> > b/arch/x86/include/asm/irq_vectors.h index 13aea8fc3d45..e4cd33bc4fef
> > 100644 --- a/arch/x86/include/asm/irq_vectors.h
> > +++ b/arch/x86/include/asm/irq_vectors.h
> > @@ -105,6 +105,34 @@
> >   
> >   #define NR_VECTORS			 256
> >   
> > +/*
> > + * The NMI senders specify the NMI source vector as an 8bit integer in
> > their  
> 
> s/The NMI senders/NMI senders/
will do

> > + * vector field with NMI delivery mode. A local APIC receiving an NMI
> > will
> > + * set the corresponding bit in a 16bit bitmask, which is accumulated
> > until
> > + * the NMI is delivered.
> > + * When a sender didn't specify an NMI source vector the source vector
> > will
> > + * be 0, which will result in bit 0 of the bitmask being set. For out
> > of
> > + * bounds vectors >= 16 bit 0 will also be set.
> > + * When bit 0 is set, system software must invoke all registered NMI
> > handlers
> > + * as if NMI source feature is not enabled.  
> 
> Add empty lines in the above paragraph.
sounds good.

> > + *
> > + * Vector 2 is reserved for matching IDT NMI vector where it may be
> > hardcoded
> > + * by some external devices.
> > + *
> > + * The NMI source vectors are sorted by descending priority with the
> > exceptions
> > + * of 0 and 2.
> > + */
> > +#define NMI_SOURCE_VEC_UNKNOWN		0
> > +#define NMI_SOURCE_VEC_IPI_REBOOT	1	/* Crash reboot */
> > +#define NMI_SOURCE_VEC_IDT_NMI		2	/* Match IDT
> > NMI vector 2 */ +#define NMI_SOURCE_VEC_IPI_SMP_STOP	3	/*
> > Panic stop CPU */ +#define NMI_SOURCE_VEC_IPI_BT
> > 4	/* CPU backtrace */ +#define NMI_SOURCE_VEC_PMI
> > 5	/* PerfMon counters */ +#define NMI_SOURCE_VEC_IPI_KGDB
> > 	6	/* KGDB */ +#define NMI_SOURCE_VEC_IPI_MCE
> > 	7	/* MCE injection */ +#define
> > NMI_SOURCE_VEC_IPI_TEST		8	/* For remote and local
> > IPIs */ +#define NR_NMI_SOURCE_VECTORS		9  
> 
> Fix alignment.
Do you see alignment problem after the patch is applied? Alignment looks
good with vi, emacs, etc. passed checkpatch --strict.

> > +
> >   #ifdef CONFIG_X86_LOCAL_APIC
> >   #define FIRST_SYSTEM_VECTOR
> > POSTED_MSI_NOTIFICATION_VECTOR #else  
> 


Thanks,

Jacob