Skip to contentSkip to conversation

x86/ioapic: fix clear_IO_APIC_pin when using interrupt remapping

PATCH In review Roger Pau Monne 3 participants 6 messages Nov 10, 2019 – Nov 12, 2019

lore
Share & tools
lore
#0 lore raw

v2 cover x86/ioapic: fix clear_IO_APIC_pin when using interrupt remapping

Hello,

Current code in clear_IO_APIC_pin doesn't properly deal with IO-APIC entries already configured to point to entries in the iommu interrupt remapping table, fix this.

Roger Pau Monne (2):
x86/ioapic: remove usage of TRUE and FALSE in clear_IO_APIC_pin x86/ioapic: fix clear_IO_APIC_pin write of raw entries

 xen/arch/x86/io_apic.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
Signature · 7 lines
2.23.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw

PATCH v2 1/2 x86/ioapic: remove usage of TRUE and FALSE in clear_IO_APIC_pin

And instead use proper booleans. No functional change intended.

---
Cc: Juergen Gross <[email protected]>

---
 xen/arch/x86/io_apic.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
xen/arch/x86/io_apic.c +6 -6
index 37eabc16c9..b9c66acdb3 100644
@@ -502,7 +502,7 @@ static void clear_IO_APIC_pin(unsigned int apic, unsigned int pin)
     struct IO_APIC_route_entry entry;
 
     /* Check delivery_mode to be sure we're not clearing an SMI pin */
-    entry = __ioapic_read_entry(apic, pin, FALSE);
+    entry = __ioapic_read_entry(apic, pin, false);
     if (entry.delivery_mode == dest_SMI)
         return;
 
@@ -512,15 +512,15 @@ static void clear_IO_APIC_pin(unsigned int apic, unsigned int pin)
      */
     if (!entry.mask) {
         entry.mask = 1;
-        __ioapic_write_entry(apic, pin, FALSE, entry);
+        __ioapic_write_entry(apic, pin, false, entry);
     }
-    entry = __ioapic_read_entry(apic, pin, TRUE);
+    entry = __ioapic_read_entry(apic, pin, true);
 
     if (entry.irr) {
         /* Make sure the trigger mode is set to level. */
         if (!entry.trigger) {
             entry.trigger = 1;
-            __ioapic_write_entry(apic, pin, TRUE, entry);
+            __ioapic_write_entry(apic, pin, true, entry);
         }
         __io_apic_eoi(apic, entry.vector, pin);
     }
@@ -530,9 +530,9 @@ static void clear_IO_APIC_pin(unsigned int apic, unsigned int pin)
      */
     memset(&entry, 0, sizeof(entry));
     entry.mask = 1;
-    __ioapic_write_entry(apic, pin, TRUE, entry);
+    __ioapic_write_entry(apic, pin, true, entry);
 
-    entry = __ioapic_read_entry(apic, pin, TRUE);
+    entry = __ioapic_read_entry(apic, pin, true);
     if (entry.irr)
         printk(KERN_ERR "IO-APIC%02x-%u: Unable to reset IRR\n",
                IO_APIC_ID(apic), pin);
Signature · 7 lines
2.23.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#2 lore raw

PATCH v2 2/2 x86/ioapic: fix clear_IO_APIC_pin write of raw entries

In reply to Roger Pau Monne

clear_IO_APIC_pin can be called after the iommu has been enabled, and using raw reads and writes to modify IO-APIC entries that have been setup to use interrupt remapping can lead to issues as some of the fields have different meaning when the IO-APIC entry is setup to point to an interrupt remapping table entry.

The following ASSERT in AMD IOMMU code triggers afterwards as a result of the raw changes to IO-APIC entries performed by clear_IO_APIC_pin.

(XEN) [   10.082154] ENABLING IO-APIC IRQs
(XEN) [   10.087789]  -> Using new ACK method
(XEN) [   10.093738] Assertion 'get_rte_index(rte) == offset' failed at iommu_intr.c:328

Fix this by making sure that modifications to entries are performed in non raw mode.

---
Cc: Juergen Gross <[email protected]>
---
Changes since v1:
- Do not change all instances of raw reads.
- Fix commit message

---
 xen/arch/x86/io_apic.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
xen/arch/x86/io_apic.c +3 -2
index b9c66acdb3..732b57995c 100644
@@ -519,8 +519,9 @@ static void clear_IO_APIC_pin(unsigned int apic, unsigned int pin)
     if (entry.irr) {
         /* Make sure the trigger mode is set to level. */
         if (!entry.trigger) {
+            entry = __ioapic_read_entry(apic, pin, false);
             entry.trigger = 1;
-            __ioapic_write_entry(apic, pin, true, entry);
+            __ioapic_write_entry(apic, pin, false, entry);
         }
         __io_apic_eoi(apic, entry.vector, pin);
     }
@@ -530,7 +531,7 @@ static void clear_IO_APIC_pin(unsigned int apic, unsigned int pin)
      */
     memset(&entry, 0, sizeof(entry));
     entry.mask = 1;
-    __ioapic_write_entry(apic, pin, true, entry);
+    __ioapic_write_entry(apic, pin, false, entry);
 
     entry = __ioapic_read_entry(apic, pin, true);
     if (entry.irr)
Signature · 7 lines
2.23.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v2 2/2
#3 lore raw

Re: [Xen-devel] [PATCH for-4.13 v2 2/2] x86/ioapic: fix clear_IO_APIC_pin write of raw entries

Quoted 9 lines · Roger Pau Monne

clear_IO_APIC_pin can be called after the iommu has been enabled, and using raw reads and writes to modify IO-APIC entries that have been setup to use interrupt remapping can lead to issues as some of the fields have different meaning when the IO-APIC entry is setup to point to an interrupt remapping table entry.

The following ASSERT in AMD IOMMU code triggers afterwards as a result of the raw changes to IO-APIC entries performed by clear_IO_APIC_pin.

Quoted 6 lines
(XEN) [   10.082154] ENABLING IO-APIC IRQs
(XEN) [   10.087789]  -> Using new ACK method
(XEN) [   10.093738] Assertion 'get_rte_index(rte) == offset' failed at iommu_intr.c:328

Fix this by making sure that modifications to entries are performed in non raw mode.

... when fields are affected which may either have changed meaning with interrupt remapping, or which may need mirroring into IRTEs.

Quoted 2 lines

With the above addition (or something substantially similar)

Of course the adjustment is easy enough to do while committing.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#4 lore raw

Re: [Xen-devel] [PATCH for-4.13 v2 2/2] x86/ioapic: fix clear_IO_APIC_pin write of raw entries

Quoted 20 lines · Jan Beulich
Quoted 9 lines · Roger Pau Monne

clear_IO_APIC_pin can be called after the iommu has been enabled, and using raw reads and writes to modify IO-APIC entries that have been setup to use interrupt remapping can lead to issues as some of the fields have different meaning when the IO-APIC entry is setup to point to an interrupt remapping table entry.

The following ASSERT in AMD IOMMU code triggers afterwards as a result of the raw changes to IO-APIC entries performed by clear_IO_APIC_pin.

Quoted 6 lines
(XEN) [   10.082154] ENABLING IO-APIC IRQs
(XEN) [   10.087789]  -> Using new ACK method
(XEN) [   10.093738] Assertion 'get_rte_index(rte) == offset' failed at iommu_intr.c:328

Fix this by making sure that modifications to entries are performed in non raw mode.

... when fields are affected which may either have changed meaning with interrupt remapping, or which may need mirroring into IRTEs.

Quoted 6 lines
Quoted 2 lines

With the above addition (or something substantially similar)

Of course the adjustment is easy enough to do while committing.

The adjustment LGTM, please do it at commit time unless there's something else that requires a resend of the series.

Thanks, Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#5 lore raw
In reply to Roger Pau Monne
Quoted 6 lines · Roger Pau Monne

Hello,

Current code in clear_IO_APIC_pin doesn't properly deal with IO-APIC entries already configured to point to entries in the iommu interrupt remapping table, fix this.

Quoted 7 lines

Roger Pau Monne (2):
x86/ioapic: remove usage of TRUE and FALSE in clear_IO_APIC_pin x86/ioapic: fix clear_IO_APIC_pin write of raw entries

  xen/arch/x86/io_apic.c | 13 +++++++------
  1 file changed, 7 insertions(+), 6 deletions(-)

For the series:

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel