Skip to contentSkip to conversation

xen/apic: refactor error_interrupt

RFC PATCH Superseded Tiejun Chen 3 participants 8 messages May 4, 2015 – May 5, 2015

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 xen/apic: refactor error_interrupt

Just make this readable while debug.

---
 xen/arch/x86/apic.c | 33 +++++++++++++++++++++------------
 1 file changed, 21 insertions(+), 12 deletions(-)
xen/arch/x86/apic.c +21 -12
index 3217bdf..0b21ed1 100644
@@ -1319,28 +1319,37 @@ out: ;
  * This interrupt should never happen with our APIC/SMP architecture
  */
 
+static const char *apic_fault_reasons[] =
+{
+    "Send CS error",
+    "Receive CS error",
+    "Send accept error",
+    "Receive accept error",
+    "Reserved",
+    "Send illegal vector",
+    "Received illegal vector",
+    "Illegal register address",
+};
+
+static const char *apic_get_fault_reason(u8 fault_reason)
+{
+    return apic_fault_reasons[fault_reason];
+}
+
 void error_interrupt(struct cpu_user_regs *regs)
 {
     unsigned long v, v1;
+    const char *reason;
 
     /* First tickle the hardware, only then report what went on. -- REW */
     v = apic_read(APIC_ESR);
     apic_write(APIC_ESR, 0);
     v1 = apic_read(APIC_ESR);
     ack_APIC_irq();
+    reason = apic_get_fault_reason(ffs(v1) - 1);
 
-    /* Here is what the APIC error bits mean:
-       0: Send CS error
-       1: Receive CS error
-       2: Send accept error
-       3: Receive accept error
-       4: Reserved
-       5: Send illegal vector
-       6: Received illegal vector
-       7: Illegal register address
-    */
-    printk (KERN_DEBUG "APIC error on CPU%d: %02lx(%02lx)\n",
-            smp_processor_id(), v , v1);
+    printk (KERN_DEBUG "APIC error on CPU%d: %02lx(%02lx):%s.\n",
+            smp_processor_id(), v , v1, reason);
 }
 
 /*
Signature · 1 line
1.8.3.2
#1 lore raw

xen/arch/x86/apic.c out: ; · line 1322

Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 04.05.15 at 04:03, <[email protected]> wrote:
xen/arch/x86/apic.c +1 -0
@@ -1319,28 +1319,37 @@ out: ;
  * This interrupt should never happen with our APIC/SMP architecture
  */
 
+static const char *apic_fault_reasons[] =

If at all, then this should be const. But...

Quoted 17 lines
xen/arch/x86/apic.c +16 -0
+{
+    "Send CS error",
+    "Receive CS error",
+    "Send accept error",
+    "Receive accept error",
+    "Reserved",
+    "Send illegal vector",
+    "Received illegal vector",
+    "Illegal register address",
+};
+
+static const char *apic_get_fault_reason(u8 fault_reason)
+{
+    return apic_fault_reasons[fault_reason];
+}
+
 void error_interrupt(struct cpu_user_regs *regs)

xen/arch/x86/apic.c out: ; · line 1349

Quoted 10 lines
xen/arch/x86/apic.c +2 -0
 {
     unsigned long v, v1;
+    const char *reason;
 
     /* First tickle the hardware, only then report what went on. -- REW */
     v = apic_read(APIC_ESR);
     apic_write(APIC_ESR, 0);
     v1 = apic_read(APIC_ESR);
     ack_APIC_irq();
+    reason = apic_get_fault_reason(ffs(v1) - 1);

... I'm not convinced - you're treating errors represented by lower bits "better" than higher ones. And if there are multiple errors, then spelling out one but not the other may end up being confusing. These errors should be rare enough to warrant manually looking up the individual bits' meanings.

Jan

Quoted 17 lines
xen/arch/x86/apic.c +2 -12
-    /* Here is what the APIC error bits mean:
-       0: Send CS error
-       1: Receive CS error
-       2: Send accept error
-       3: Receive accept error
-       4: Reserved
-       5: Send illegal vector
-       6: Received illegal vector
-       7: Illegal register address
-    */
-    printk (KERN_DEBUG "APIC error on CPU%d: %02lx(%02lx)\n",
-            smp_processor_id(), v , v1);
+    printk (KERN_DEBUG "APIC error on CPU%d: %02lx(%02lx):%s.\n",
+            smp_processor_id(), v , v1, reason);
 }
 
 /*
#3 lore raw
In reply to Tiejun Chen
Quoted 1 line · Tiejun Chen

Just make this readable while debug.

"debugging"

Quoted 2 lines

In principle, I fully agree with the change. (I had an item on my todo list to make a change like this anyway).

xen/arch/x86/apic.c out: ; · line 1322

Quoted 13 lines
---
 xen/arch/x86/apic.c | 33 +++++++++++++++++++++------------
 1 file changed, 21 insertions(+), 12 deletions(-)
xen/arch/x86/apic.c +1 -0
index 3217bdf..0b21ed1 100644
@@ -1319,28 +1319,37 @@ out: ;
  * This interrupt should never happen with our APIC/SMP architecture
  */
 
+static const char *apic_fault_reasons[] =

static const char * const

It might be better to have "esr" in the name to make it clear that these are string representations of the esr fields.

xen/arch/x86/apic.c out: ; · line 1328

Quoted 6 lines
xen/arch/x86/apic.c +6 -0
+{
+    "Send CS error",
+    "Receive CS error",
+    "Send accept error",
+    "Receive accept error",
+    "Reserved",

"Redirectable IPI"

This field is not reserved on all processors which can run Xen.

xen/arch/x86/apic.c out: ; · line 1336

Quoted 8 lines
xen/arch/x86/apic.c +8 -0
+    "Send illegal vector",
+    "Received illegal vector",
+    "Illegal register address",
+};
+
+static const char *apic_get_fault_reason(u8 fault_reason)
+{
+    return apic_fault_reasons[fault_reason];

This can easily overflow the array. I don't see much value in the wrapper.

xen/arch/x86/apic.c out: ; · line 1341

Quoted 5 lines
xen/arch/x86/apic.c +2 -0
+}
+
 void error_interrupt(struct cpu_user_regs *regs)
 {
     unsigned long v, v1;

These can be unsigned int rather than unsigned long, saving a bit of space.

xen/arch/x86/apic.c out: ; · line 1349

Quoted 8 lines
xen/arch/x86/apic.c +2 -0
+    const char *reason;
 
     /* First tickle the hardware, only then report what went on. -- REW */
     v = apic_read(APIC_ESR);
     apic_write(APIC_ESR, 0);
     v1 = apic_read(APIC_ESR);
     ack_APIC_irq();
+    reason = apic_get_fault_reason(ffs(v1) - 1);

All but the bottom byte of v1 is reserved, and not guaranteed to be read as 0.

Also, more than a single error can be latched at once, which this code discards.

Quoted 4 lines
xen/arch/x86/apic.c +0 -3
-    /* Here is what the APIC error bits mean:
-       0: Send CS error
-       1: Receive CS error

xen/arch/x86/apic.c out: ; · line 1351

Quoted 10 lines
xen/arch/x86/apic.c +1 -9
-       2: Send accept error
-       3: Receive accept error
-       4: Reserved
-       5: Send illegal vector
-       6: Received illegal vector
-       7: Illegal register address
-    */
-    printk (KERN_DEBUG "APIC error on CPU%d: %02lx(%02lx)\n",
-            smp_processor_id(), v , v1);
+    printk (KERN_DEBUG "APIC error on CPU%d: %02lx(%02lx):%s.\n",

Please can we avoid adding redundant punctuation to error messages. The full stop serves no semantic purpose.

Also, please correct %d to %u as smp_processor_id() is an unsigned integer.

xen/arch/x86/apic.c out: ; · line 1352

Quoted 1 line
xen/arch/x86/apic.c +1 -0
+            smp_processor_id(), v , v1, reason);

A better approach might be:

printk(KERN_DEBUG "APIC error on CPU%u: %02lx(%02lx)", ...) for ( i = (1<<7); i; i >>= 1 )
if ( v1 & i )

    printk(", %s", apic_fault_reasons[i]);

printk("\n");

Which will decode all set bits, and guarantee not to access outside the bounds of apic_fault_reasons.

~Andrew

#2 lore raw
In reply to Jan Beulich
Quoted 32 lines · Jan Beulich

xen/arch/x86/apic.c out: ; · line 1322

Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 04.05.15 at 04:03, <[email protected]> wrote:
xen/arch/x86/apic.c +1 -0
@@ -1319,28 +1319,37 @@ out: ;
   * This interrupt should never happen with our APIC/SMP architecture
   */
 
+static const char *apic_fault_reasons[] =

If at all, then this should be const. But...

Quoted 21 lines
xen/arch/x86/apic.c +17 -0
+{
+    "Send CS error",
+    "Receive CS error",
+    "Send accept error",
+    "Receive accept error",
+    "Reserved",
+    "Send illegal vector",
+    "Received illegal vector",
+    "Illegal register address",
+};
+
+static const char *apic_get_fault_reason(u8 fault_reason)
+{
+    return apic_fault_reasons[fault_reason];
+}
+
  void error_interrupt(struct cpu_user_regs *regs)
  {
      unsigned long v, v1;
+    const char *reason;
 
Quoted 10 lines

xen/arch/x86/apic.c out: ; · line 1349

Quoted 6 lines
xen/arch/x86/apic.c +1 -0
      /* First tickle the hardware, only then report what went on. -- REW */
      v = apic_read(APIC_ESR);
      apic_write(APIC_ESR, 0);
      v1 = apic_read(APIC_ESR);
      ack_APIC_irq();
+    reason = apic_get_fault_reason(ffs(v1) - 1);

... I'm not convinced - you're treating errors represented by lower bits "better" than higher ones. And if there are multiple errors, then spelling out one but not the other may end up being confusing.

I just think APIC shouldn't record these multiple errors at the same time because these kinds of errors seem be exclusive... But I don't find this is described in SDM so I think you're right.

Fortunately, looks Andrew guides me a approach to cover this point, so just let me go there.

Thanks
Tiejun

Quoted 26 lines

These errors should be rare enough to warrant manually looking up the individual bits' meanings.

Jan

Quoted 17 lines
xen/arch/x86/apic.c +2 -12
-    /* Here is what the APIC error bits mean:
-       0: Send CS error
-       1: Receive CS error
-       2: Send accept error
-       3: Receive accept error
-       4: Reserved
-       5: Send illegal vector
-       6: Received illegal vector
-       7: Illegal register address
-    */
-    printk (KERN_DEBUG "APIC error on CPU%d: %02lx(%02lx)\n",
-            smp_processor_id(), v , v1);
+    printk (KERN_DEBUG "APIC error on CPU%d: %02lx(%02lx):%s.\n",
+            smp_processor_id(), v , v1, reason);
  }
 
  /*
#4 lore raw
In reply to Andrew Cooper
Quoted 4 lines · Andrew Cooper
Quoted 1 line · Tiejun Chen

Just make this readable while debug.

"debugging"

Fixed.

Quoted 19 lines
Quoted 3 lines

In principle, I fully agree with the change. (I had an item on my todo list to make a change like this anyway).

Quoted 12 lines
---
  xen/arch/x86/apic.c | 33 +++++++++++++++++++++------------
  1 file changed, 21 insertions(+), 12 deletions(-)
xen/arch/x86/apic.c +0 -0
index 3217bdf..0b21ed1 100644
@@ -1319,28 +1319,37 @@ out: ;
   * This interrupt should never happen with our APIC/SMP architecture
   */
 
Quoted 6 lines

xen/arch/x86/apic.c out: ; · line 1322

Quoted 1 line
xen/arch/x86/apic.c +1 -0
+static const char *apic_fault_reasons[] =

static const char * const

It might be better to have "esr" in the name to make it clear that these are string representations of the esr fields.

Sure.

Quoted 11 lines

xen/arch/x86/apic.c out: ; · line 1328

Quoted 7 lines
xen/arch/x86/apic.c +6 -0
+{
+    "Send CS error",
+    "Receive CS error",
+    "Send accept error",
+    "Receive accept error",
+    "Reserved",

"Redirectable IPI"

This field is not reserved on all processors which can run Xen.

Changed.

Quoted 11 lines

xen/arch/x86/apic.c out: ; · line 1336

Quoted 9 lines
xen/arch/x86/apic.c +8 -0
+    "Send illegal vector",
+    "Received illegal vector",
+    "Illegal register address",
+};
+
+static const char *apic_get_fault_reason(u8 fault_reason)
+{
+    return apic_fault_reasons[fault_reason];

This can easily overflow the array. I don't see much value in the wrapper.

Right.

Quoted 8 lines

xen/arch/x86/apic.c out: ; · line 1341

Quoted 6 lines
xen/arch/x86/apic.c +2 -0
+}
+
  void error_interrupt(struct cpu_user_regs *regs)
  {
      unsigned long v, v1;

These can be unsigned int rather than unsigned long, saving a bit of space.

Okay.

Quoted 36 lines

xen/arch/x86/apic.c out: ; · line 1349

Quoted 9 lines
xen/arch/x86/apic.c +2 -0
+    const char *reason;
 
      /* First tickle the hardware, only then report what went on. -- REW */
      v = apic_read(APIC_ESR);
      apic_write(APIC_ESR, 0);
      v1 = apic_read(APIC_ESR);
      ack_APIC_irq();
+    reason = apic_get_fault_reason(ffs(v1) - 1);

All but the bottom byte of v1 is reserved, and not guaranteed to be read as 0.

Also, more than a single error can be latched at once, which this code discards.

Quoted 4 lines
xen/arch/x86/apic.c +0 -3
-    /* Here is what the APIC error bits mean:
-       0: Send CS error
-       1: Receive CS error

xen/arch/x86/apic.c out: ; · line 1350

Quoted 10 lines
xen/arch/x86/apic.c +1 -9
-       2: Send accept error
-       3: Receive accept error
-       4: Reserved
-       5: Send illegal vector
-       6: Received illegal vector
-       7: Illegal register address
-    */
-    printk (KERN_DEBUG "APIC error on CPU%d: %02lx(%02lx)\n",
-            smp_processor_id(), v , v1);
+    printk (KERN_DEBUG "APIC error on CPU%d: %02lx(%02lx):%s.\n",

Please can we avoid adding redundant punctuation to error messages. The full stop serves no semantic purpose.

Also, please correct %d to %u as smp_processor_id() is an unsigned integer.

Quoted 8 lines

xen/arch/x86/apic.c out: ; · line 1351

Quoted 1 line
xen/arch/x86/apic.c +1 -0
+            smp_processor_id(), v , v1, reason);

A better approach might be:

printk(KERN_DEBUG "APIC error on CPU%u: %02lx(%02lx)", ...) for ( i = (1<<7); i; i >>= 1 )
if ( v1 & i )

     printk(", %s", apic_fault_reasons[i]);

I guess this should be apic_fault_reasons[ffs(i) - 1].

Quoted 5 lines

printk("\n");

Which will decode all set bits, and guarantee not to access outside the bounds of apic_fault_reasons.

Thanks you for all comments. So overall, what about this?

xen/arch/x86/apic.c +18 -12
index 3217bdf..87684a2 100644
@@ -1319,9 +1319,21 @@ out: ;
  * This interrupt should never happen with our APIC/SMP architecture
  */
 
+static const char * const fault_reasons_from_esr[] =
+{
+    "Send CS error",
+    "Receive CS error",
+    "Send accept error",
+    "Receive accept error",
+    "Redirectable IPI",
+    "Send illegal vector",
+    "Received illegal vector",
+    "Illegal register address",
+};
+
 void error_interrupt(struct cpu_user_regs *regs)
 {
-    unsigned long v, v1;
+    unsigned int v, v1, i;
 
     /* First tickle the hardware, only then report what went on. -- REW */
     v = apic_read(APIC_ESR);
@@ -1329,18 +1341,12 @@ void error_interrupt(struct cpu_user_regs *regs)
     v1 = apic_read(APIC_ESR);
     ack_APIC_irq();
 
-    /* Here is what the APIC error bits mean:
-       0: Send CS error
-       1: Receive CS error
-       2: Send accept error
-       3: Receive accept error
-       4: Reserved
-       5: Send illegal vector
-       6: Received illegal vector
-       7: Illegal register address
-    */
-    printk (KERN_DEBUG "APIC error on CPU%d: %02lx(%02lx)\n",
+    printk (KERN_DEBUG "APIC error on CPU%u: %02x(%02x)",
             smp_processor_id(), v , v1);
+    for (i = (1<<7); i; i >>= 1)
+        if(v1 & i)
+            printk (KERN_DEBUG ", %s", fault_reasons_from_esr[ffs(i) - 1]);
+    printk (KERN_DEBUG ".\n");
 }
 
 /*

Thanks
Tiejun

#5 lore raw
Quoted 9 lines · Tiejun
Quoted 7 lines

A better approach might be:

printk(KERN_DEBUG "APIC error on CPU%u: %02lx(%02lx)", ...) for ( i = (1<<7); i; i >>= 1 )
if ( v1 & i )

     printk(", %s", apic_fault_reasons[i]);

I guess this should be apic_fault_reasons[ffs(i) - 1].

Indeed.

Quoted 8 lines
Quoted 6 lines

printk("\n");

Which will decode all set bits, and guarantee not to access outside the bounds of apic_fault_reasons.

Thanks you for all comments. So overall, what about this?

Much better. A few further comments.

xen/arch/x86/apic.c out: ; · line 1322

Quoted 10 lines
xen/arch/x86/apic.c +1 -0
index 3217bdf..87684a2 100644
@@ -1319,9 +1319,21 @@ out: ;
  * This interrupt should never happen with our APIC/SMP architecture
  */
 
+static const char * const fault_reasons_from_esr[] =

It is not too important, but I was thinking of something rather shorter as a name. "esr_fields[]" perhaps ?

Quoted 25 lines
xen/arch/x86/apic.c +12 -1
+{
+    "Send CS error",
+    "Receive CS error",
+    "Send accept error",
+    "Receive accept error",
+    "Redirectable IPI",
+    "Send illegal vector",
+    "Received illegal vector",
+    "Illegal register address",
+};
+
 void error_interrupt(struct cpu_user_regs *regs)
 {
-    unsigned long v, v1;
+    unsigned int v, v1, i;
 
     /* First tickle the hardware, only then report what went on. --

REW */

     v = apic_read(APIC_ESR);
xen/arch/x86/apic.c +0 -2
@@ -1329,18 +1341,12 @@ void error_interrupt(struct cpu_user_regs *regs)
     v1 = apic_read(APIC_ESR);
     ack_APIC_irq();
 
-    /* Here is what the APIC error bits mean:
-       0: Send CS error

xen/arch/x86/apic.c void error_interrupt(struct cpu_user_regs *regs) · line 1344

Quoted 10 lines
xen/arch/x86/apic.c +1 -9
-       1: Receive CS error
-       2: Send accept error
-       3: Receive accept error
-       4: Reserved
-       5: Send illegal vector
-       6: Received illegal vector
-       7: Illegal register address
-    */
-    printk (KERN_DEBUG "APIC error on CPU%d: %02lx(%02lx)\n",
+    printk (KERN_DEBUG "APIC error on CPU%u: %02x(%02x)",

While at this, please apply Xen style to all changed lines. In particular, drop the space between printk and its opening bracket. Swap KERN_ for XENLOG_

xen/arch/x86/apic.c void error_interrupt(struct cpu_user_regs *regs) · line 1346

Quoted 2 lines
xen/arch/x86/apic.c +1 -0
             smp_processor_id(), v , v1);
+    for (i = (1<<7); i; i >>= 1)

Spaces inside the brackets.

xen/arch/x86/apic.c void error_interrupt(struct cpu_user_regs *regs) · line 1347

Quoted 1 line
xen/arch/x86/apic.c +1 -0
+        if(v1 & i)

And here.

xen/arch/x86/apic.c void error_interrupt(struct cpu_user_regs *regs) · line 1344

Quoted 2 lines
xen/arch/x86/apic.c +1 -1
+            printk (KERN_DEBUG ", %s", fault_reasons_from_esr[ffs(i)
- 1]);

The code here now looks correct, but it is unlikely that the compiler would be able to simplify the ffs() call.

An alternate approach would be:

int i;
for ( i = 7; i >= 0; --i )

    if ( v1 & (1 << i) )
         printk(... , fault_reasons_from_esr[i])

xen/arch/x86/apic.c void error_interrupt(struct cpu_user_regs *regs) · line 1349

Quoted 1 line
xen/arch/x86/apic.c +1 -0
+    printk (KERN_DEBUG ".\n");

Please do not put full stops on messages like this. It serves no useful purpose, but wasted space in the console ring and wasted time when pushed over a serial console.

~Andrew

#6 lore raw
Quoted 33 lines · Andrew Cooper
Quoted 9 lines · Tiejun
Quoted 7 lines

A better approach might be:

printk(KERN_DEBUG "APIC error on CPU%u: %02lx(%02lx)", ...) for ( i = (1<<7); i; i >>= 1 )

    if ( v1 & i )
      printk(", %s", apic_fault_reasons[i]);

I guess this should be apic_fault_reasons[ffs(i) - 1].

Indeed.

Quoted 8 lines
Quoted 6 lines

printk("\n");

Which will decode all set bits, and guarantee not to access outside the bounds of apic_fault_reasons.

Thanks you for all comments. So overall, what about this?

Much better. A few further comments.

Quoted 9 lines
xen/arch/x86/apic.c +0 -0
index 3217bdf..87684a2 100644
@@ -1319,9 +1319,21 @@ out: ;
   * This interrupt should never happen with our APIC/SMP architecture
   */
 
Quoted 4 lines

xen/arch/x86/apic.c out: ; · line 1322

Quoted 1 line
xen/arch/x86/apic.c +1 -0
+static const char * const fault_reasons_from_esr[] =

It is not too important, but I was thinking of something rather shorter as a name. "esr_fields[]" perhaps ?

Looks good.

Quoted 24 lines
Quoted 24 lines
xen/arch/x86/apic.c +12 -1
+{
+    "Send CS error",
+    "Receive CS error",
+    "Send accept error",
+    "Receive accept error",
+    "Redirectable IPI",
+    "Send illegal vector",
+    "Received illegal vector",
+    "Illegal register address",
+};
+
  void error_interrupt(struct cpu_user_regs *regs)
  {
-    unsigned long v, v1;
+    unsigned int v, v1, i;
 
      /* First tickle the hardware, only then report what went on. --

REW */

      v = apic_read(APIC_ESR);
xen/arch/x86/apic.c +0 -0
@@ -1329,18 +1341,12 @@ void error_interrupt(struct cpu_user_regs *regs)
      v1 = apic_read(APIC_ESR);
      ack_APIC_irq();
 
Quoted 15 lines

xen/arch/x86/apic.c void error_interrupt(struct cpu_user_regs *regs) · line 1344

Quoted 12 lines
xen/arch/x86/apic.c +1 -11
-    /* Here is what the APIC error bits mean:
-       0: Send CS error
-       1: Receive CS error
-       2: Send accept error
-       3: Receive accept error
-       4: Reserved
-       5: Send illegal vector
-       6: Received illegal vector
-       7: Illegal register address
-    */
-    printk (KERN_DEBUG "APIC error on CPU%d: %02lx(%02lx)\n",
+    printk (KERN_DEBUG "APIC error on CPU%u: %02x(%02x)",

While at this, please apply Xen style to all changed lines. In particular, drop the space between printk and its opening bracket. Swap

Okay. And actually we should clean this whole file completely since this is backported from Linux...

Quoted 1 line

KERN_ for XENLOG_

Sure.

Quoted 16 lines

xen/arch/x86/apic.c void error_interrupt(struct cpu_user_regs *regs) · line 1346

Quoted 3 lines
xen/arch/x86/apic.c +1 -0
              smp_processor_id(), v , v1);
+    for (i = (1<<7); i; i >>= 1)

Spaces inside the brackets.

xen/arch/x86/apic.c void error_interrupt(struct cpu_user_regs *regs) · line 1347

Quoted 1 line
xen/arch/x86/apic.c +1 -0
+        if(v1 & i)

And here.

xen/arch/x86/apic.c void error_interrupt(struct cpu_user_regs *regs) · line 1344

Quoted 2 lines
xen/arch/x86/apic.c +1 -1
+            printk (KERN_DEBUG ", %s", fault_reasons_from_esr[ffs(i)
- 1]);

The code here now looks correct, but it is unlikely that the compiler would be able to simplify the ffs() call.

Quoted 6 lines

An alternate approach would be:

int i;
for ( i = 7; i >= 0; --i )

     if ( v1 & (1 << i) )
          printk(... , fault_reasons_from_esr[i])

Then,

- printk (KERN_DEBUG "APIC error on CPU%d: %02lx(%02lx)\n",
+ printk(XENLOG_DEBUG "APIC error on CPU%u: %02x(%02x)",

             smp_processor_id(), v , v1);

+ for ( i = 7; i >= 0; --i )
+ if ( v1 & (1 << i) )
+ printk(XENLOG_DEBUG ", %s", esr_fields[i]);

Quoted 6 lines

xen/arch/x86/apic.c void error_interrupt(struct cpu_user_regs *regs) · line 1349

Quoted 2 lines
xen/arch/x86/apic.c +1 -0
+    printk (KERN_DEBUG ".\n");

Please do not put full stops on messages like this. It serves no useful purpose, but wasted space in the console ring and wasted time when pushed over a serial console.

Are you saying this?

printk(XENLOG_DEBUG "\n");

Thanks
Tiejun

#7 lore raw
Quoted 83 lines · Tiejun
Quoted 34 lines · Andrew Cooper
Quoted 9 lines · Tiejun
Quoted 7 lines

A better approach might be:

printk(KERN_DEBUG "APIC error on CPU%u: %02lx(%02lx)", ...) for ( i = (1<<7); i; i >>= 1 )

    if ( v1 & i )
      printk(", %s", apic_fault_reasons[i]);

I guess this should be apic_fault_reasons[ffs(i) - 1].

Indeed.

Quoted 9 lines
Quoted 7 lines

printk("\n");

Which will decode all set bits, and guarantee not to access outside the
bounds of apic_fault_reasons.

Thanks you for all comments. So overall, what about this?

Much better. A few further comments.

Quoted 9 lines
xen/arch/x86/apic.c +0 -0
index 3217bdf..87684a2 100644
@@ -1319,9 +1319,21 @@ out: ;
   * This interrupt should never happen with our APIC/SMP architecture
   */
 
Quoted 4 lines

xen/arch/x86/apic.c out: ; · line 1322

Quoted 1 line
xen/arch/x86/apic.c +1 -0
+static const char * const fault_reasons_from_esr[] =

It is not too important, but I was thinking of something rather shorter as a name. "esr_fields[]" perhaps ?

Looks good.

Quoted 25 lines
Quoted 25 lines
xen/arch/x86/apic.c +12 -1
+{
+    "Send CS error",
+    "Receive CS error",
+    "Send accept error",
+    "Receive accept error",
+    "Redirectable IPI",
+    "Send illegal vector",
+    "Received illegal vector",
+    "Illegal register address",
+};
+
  void error_interrupt(struct cpu_user_regs *regs)
  {
-    unsigned long v, v1;
+    unsigned int v, v1, i;
 
      /* First tickle the hardware, only then report what went on. --

REW */

      v = apic_read(APIC_ESR);
xen/arch/x86/apic.c +0 -0
@@ -1329,18 +1341,12 @@ void error_interrupt(struct cpu_user_regs
 *regs)
      v1 = apic_read(APIC_ESR);
      ack_APIC_irq();
 
Quoted 15 lines

xen/arch/x86/apic.c void error_interrupt(struct cpu_user_regs *regs) · line 1344

Quoted 12 lines
xen/arch/x86/apic.c +1 -11
-    /* Here is what the APIC error bits mean:
-       0: Send CS error
-       1: Receive CS error
-       2: Send accept error
-       3: Receive accept error
-       4: Reserved
-       5: Send illegal vector
-       6: Received illegal vector
-       7: Illegal register address
-    */
-    printk (KERN_DEBUG "APIC error on CPU%d: %02lx(%02lx)\n",
+    printk (KERN_DEBUG "APIC error on CPU%u: %02x(%02x)",

While at this, please apply Xen style to all changed lines. In particular, drop the space between printk and its opening bracket. Swap

Quoted 2 lines

Okay. And actually we should clean this whole file completely since this is backported from Linux...

Not worth changing for the sake of changing, but where we are already altering code we attempt to make it consistent.

Quoted 40 lines
Quoted 2 lines

KERN_ for XENLOG_

Sure.

Quoted 16 lines

xen/arch/x86/apic.c void error_interrupt(struct cpu_user_regs *regs) · line 1346

Quoted 3 lines
xen/arch/x86/apic.c +1 -0
              smp_processor_id(), v , v1);
+    for (i = (1<<7); i; i >>= 1)

Spaces inside the brackets.

xen/arch/x86/apic.c void error_interrupt(struct cpu_user_regs *regs) · line 1347

Quoted 1 line
xen/arch/x86/apic.c +1 -0
+        if(v1 & i)

And here.

xen/arch/x86/apic.c void error_interrupt(struct cpu_user_regs · line 1345

Quoted 2 lines
xen/arch/x86/apic.c +1 -1
+            printk (KERN_DEBUG ", %s", fault_reasons_from_esr[ffs(i)
- 1]);

The code here now looks correct, but it is unlikely that the compiler would be able to simplify the ffs() call.

Quoted 6 lines

An alternate approach would be:

int i;
for ( i = 7; i >= 0; --i )

     if ( v1 & (1 << i) )
          printk(... , fault_reasons_from_esr[i])

Then,

(quoted diff) +4 -1
-    printk (KERN_DEBUG "APIC error on CPU%d: %02lx(%02lx)\n",
+    printk(XENLOG_DEBUG "APIC error on CPU%u: %02x(%02x)",
             smp_processor_id(), v , v1);
+    for ( i = 7; i >= 0; --i )
+        if ( v1 & (1 << i) )
+            printk(XENLOG_DEBUG ", %s", esr_fields[i]);
Quoted 4 lines
Quoted 3 lines
xen/arch/x86/apic.c +1 -0
+    printk (KERN_DEBUG ".\n");
Quoted 7 lines
Quoted 3 lines

Please do not put full stops on messages like this. It serves no useful purpose, but wasted space in the console ring and wasted time when pushed over a serial console.

Are you saying this?

printk(XENLOG_DEBUG "\n");

Yes, although you also need to drop the XENLOG_DEBUG from this and the printk() inside the loop, as they are not printks from the start of a line.

so,
for ( i = 7; i >= 0; --i )

    if ( v1 & (1 << i) )
        printk(", %s", esr_fields[i]);

printk("\n");

~Andrew