]> xenbits.xensource.com Git - people/andrewcoop/xen.git/commitdiff
x86/irq: introduce APIC_VECTOR_VALID()
authorDenis Mukhin <dmukhin@ford.com>
Tue, 25 Mar 2025 08:22:59 +0000 (09:22 +0100)
committerJan Beulich <jbeulich@suse.com>
Tue, 25 Mar 2025 08:22:59 +0000 (09:22 +0100)
Add new macro APIC_VECTOR_VALID() to validate the interrupt vector
range as per [1]. This macro replaces hardcoded checks against the
open-coded value 16 in LAPIC and virtual LAPIC code and simplifies
the code a bit.

[1] Intel SDM volume 3A
    Chapter "ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER"
    Section "Valid Interrupt Vectors"

Signed-off-by: Denis Mukhin <dmukhin@ford.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
xen/arch/x86/cpu/mcheck/mce_intel.c
xen/arch/x86/hvm/vlapic.c
xen/arch/x86/include/asm/apicdef.h

index 07b50f8793b79085b269f878c10cd38c2809e08f..1e52b1ac25a4581588486aa819ec2770c1ec3863 100644 (file)
@@ -135,8 +135,7 @@ static void intel_init_thermal(struct cpuinfo_x86 *c)
      * BIOS has programmed on AP based on BSP's info we saved (since BIOS
      * is required to set the same value for all threads/cores).
      */
-    if ( (val & APIC_DM_MASK) != APIC_DM_FIXED
-         || (val & APIC_VECTOR_MASK) > 0xf )
+    if ( (val & APIC_DM_MASK) != APIC_DM_FIXED || APIC_VECTOR_VALID(val) )
         apic_write(APIC_LVTTHMR, val);
 
     if ( (msr_content & (1ULL<<3))
index 065b2aab5b20bdce63e4f4b2eef0f4a544f8afdb..993e972cd71e0f3bfbc3b2a5c5c88952ba18e6e3 100644 (file)
@@ -123,7 +123,7 @@ static void vlapic_error(struct vlapic *vlapic, unsigned int err_bit)
              * will end up back here.  Break the cycle by only injecting LVTERR
              * if it will succeed, and folding in RECVILL otherwise.
              */
-            if ( (lvterr & APIC_VECTOR_MASK) >= 16 )
+            if ( APIC_VECTOR_VALID(lvterr) )
                 inj = true;
             else
                 set_bit(ilog2(APIC_ESR_RECVILL), &vlapic->hw.pending_esr);
@@ -136,7 +136,7 @@ static void vlapic_error(struct vlapic *vlapic, unsigned int err_bit)
 
 bool vlapic_test_irq(const struct vlapic *vlapic, uint8_t vec)
 {
-    if ( unlikely(vec < 16) )
+    if ( unlikely(!APIC_VECTOR_VALID(vec)) )
         return false;
 
     if ( hvm_funcs.test_pir &&
@@ -150,7 +150,7 @@ void vlapic_set_irq(struct vlapic *vlapic, uint8_t vec, uint8_t trig)
 {
     struct vcpu *target = vlapic_vcpu(vlapic);
 
-    if ( unlikely(vec < 16) )
+    if ( unlikely(!APIC_VECTOR_VALID(vec)) )
     {
         vlapic_error(vlapic, ilog2(APIC_ESR_RECVILL));
         return;
@@ -523,7 +523,7 @@ void vlapic_ipi(
         struct vlapic *target = vlapic_lowest_prio(
             vlapic_domain(vlapic), vlapic, short_hand, dest, dest_mode);
 
-        if ( unlikely((icr_low & APIC_VECTOR_MASK) < 16) )
+        if ( unlikely(!APIC_VECTOR_VALID(icr_low)) )
             vlapic_error(vlapic, ilog2(APIC_ESR_SENDILL));
         else if ( target )
             vlapic_accept_irq(vlapic_vcpu(target), icr_low);
@@ -531,7 +531,7 @@ void vlapic_ipi(
     }
 
     case APIC_DM_FIXED:
-        if ( unlikely((icr_low & APIC_VECTOR_MASK) < 16) )
+        if ( unlikely(!APIC_VECTOR_VALID(icr_low)) )
         {
             vlapic_error(vlapic, ilog2(APIC_ESR_SENDILL));
             break;
index 49e29ec8015664f0ff191c3ede452f3e2dc65d72..63dab01dde62517b131bca923df3af12ff04e637 100644 (file)
@@ -78,6 +78,8 @@
 #define                        APIC_DM_STARTUP         0x00600
 #define                        APIC_DM_EXTINT          0x00700
 #define                        APIC_VECTOR_MASK        0x000FF
+#define                        APIC_VECTOR_VALID(x)    \
+                                       (((x) & APIC_VECTOR_MASK) >= 16)
 #define                APIC_ICR2       0x310
 #define                        GET_xAPIC_DEST_FIELD(x) (((x)>>24)&0xFF)
 #define                        SET_xAPIC_DEST_FIELD(x) ((x)<<24)