Skip to contentSkip to conversation

x86/apic: Avoid infinite loop in io_apic_level_ack_pending()

PATCH Superseded Jason Andryuk 2 participants 4 messages Sep 4, 2025 – Sep 8, 2025

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/apic: Avoid infinite loop in io_apic_level_ack_pending()

io_apic_level_ack_pending() will end up in an infinite loop if entry->pin == -1. entry does not change, so it will keep reading -1.

Switched to breaking out of the loop.

Fixes f821102450a1 ("x86: IRQ Migration logic enhancement.")

---
Noticed during code inspection.

---
 xen/arch/x86/io_apic.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/x86/io_apic.c +1 -1
index 17e6827f4b..b21f0515f5 100644
@@ -1715,7 +1715,7 @@ static bool io_apic_level_ack_pending(unsigned int irq)
 
         pin = entry->pin;
         if (pin == -1)
-            continue;
+            break;
         reg = io_apic_read(entry->apic, 0x10 + pin*2);
         /* Is the remote IRR bit set? */
         if (reg & IO_APIC_REDIR_REMOTE_IRR) {
Signature · 1 line
2.51.0
#1 lore raw
Quoted 9 lines · Jason Andryuk

io_apic_level_ack_pending() will end up in an infinite loop if entry->pin == -1. entry does not change, so it will keep reading -1.

Switched to breaking out of the loop.

Fixes f821102450a1 ("x86: IRQ Migration logic enhancement.")

---
Noticed during code inspection.

Well spotted, just that ...

xen/arch/x86/io_apic.c static bool io_apic_level_ack_pending(unsigned int irq) · line 1718

Quoted 8 lines
xen/arch/x86/io_apic.c +1 -1
@@ -1715,7 +1715,7 @@ static bool io_apic_level_ack_pending(unsigned int irq)
 
         pin = entry->pin;
         if (pin == -1)
-            continue;
+            break;

... we shouldn't terminate the loop here, but rather continue with the next entry in the list (if any). Hence presumably why "continue" was used, without achieving the intended effect.

Jan

#2 lore raw
Quoted 17 lines · Jan Beulich
Quoted 9 lines · Jason Andryuk

io_apic_level_ack_pending() will end up in an infinite loop if entry->pin == -1. entry does not change, so it will keep reading -1.

Switched to breaking out of the loop.

Fixes f821102450a1 ("x86: IRQ Migration logic enhancement.")

---
Noticed during code inspection.

Well spotted, just that ...

Quoted 4 lines
xen/arch/x86/io_apic.c +0 -0
@@ -1715,7 +1715,7 @@ static bool io_apic_level_ack_pending(unsigned int irq)
 
Quoted 8 lines

xen/arch/x86/io_apic.c static bool io_apic_level_ack_pending(unsigned int irq) · line 1718

Quoted 4 lines
xen/arch/x86/io_apic.c +1 -1
          pin = entry->pin;
          if (pin == -1)
-            continue;
+            break;

... we shouldn't terminate the loop here, but rather continue with the next entry in the list (if any). Hence presumably why "continue" was used, without achieving the intended effect.

Ok, makes sense. Though after the sending the patch, I was wondering if it was an unreachable condition, and we should not end up here with pin == -1.

Thanks,
Jason

#3 lore raw
Quoted 27 lines · Jason Andryuk
Quoted 17 lines · Jan Beulich
Quoted 9 lines · Jason Andryuk

io_apic_level_ack_pending() will end up in an infinite loop if entry->pin == -1. entry does not change, so it will keep reading -1.

Switched to breaking out of the loop.

Fixes f821102450a1 ("x86: IRQ Migration logic enhancement.")

---
Noticed during code inspection.

Well spotted, just that ...

Quoted 4 lines
xen/arch/x86/io_apic.c +0 -0
@@ -1715,7 +1715,7 @@ static bool io_apic_level_ack_pending(unsigned int irq)
 
Quoted 8 lines

xen/arch/x86/io_apic.c static bool io_apic_level_ack_pending(unsigned int irq) · line 1718

Quoted 4 lines
xen/arch/x86/io_apic.c +1 -1
          pin = entry->pin;
          if (pin == -1)
-            continue;
+            break;

... we shouldn't terminate the loop here, but rather continue with the next entry in the list (if any). Hence presumably why "continue" was used, without achieving the intended effect.

Quoted 3 lines

Ok, makes sense. Though after the sending the patch, I was wondering if it was an unreachable condition, and we should not end up here with pin == -1.

I can't exclude that, but other code (e.g. add_pin_to_irq()) also deal with this case.

Jan