[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH for-4.21 v3 1/2] x86/apic: Avoid infinite loop in io_apic_level_ack_pending()


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jason Andryuk <jason.andryuk@xxxxxxx>
  • Date: Wed, 15 Oct 2025 17:04:53 -0400
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0)
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=aaZUyhNxVa7d9OFxTEmdJIOr6CU9ub8d3ETcT6pczTw=; b=LlpxIn5PRkDLPdJoGtpDtrqTOKzbue/eWVAFGCyuUfYccSvJTXy9HwMIjYV0aYDoNi/xwmZTOmFu3Hd3ZOG3HAb1E1QHjxSbL/jG2z6fsGjL6CLOS1EUJ4W6WMLDEuhlHP0aiFlAUA5RpbxeX9d+a2qlztiJcGW4jXsxoe1b5A4JYBPtHD/vHAE73UF6brEx9qC85dj355LH8HJZK+RHEd2Jv/q/OU9/mPHQhyChlzdYqI5r00BqnlCUOSFksDHiXX8x3mLJAnO2ZLhxCSeJndz1E5RhqeuQyoAQsdpH4wRi3M6sDq0e7/3WYca4OT0/wDS2ByYVALpiuL6s7hxonQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Wc8GDV/hWjOVa0KuQckPjQXlPEn4RlN0kHqfuF6M4kXuSKyfpHtGOjUGPkDaEcOtfQ5azl+nKHwNPAhkwhVp9Haeb6Bo65Uphmo06iWg3E6GCSjGzma8uZt/soABp5m6dHdDBbkFXd9hFH3SbY1cYSyeRu/FyHCryuq2yISG2f10pyA7g98DGDIQVNwUQO1klH47Wkknu+KxdsJvEb9QWoM61rZbZil+u1JdgraDoGgqS2wZEe4pp+71LS3RdwNMIdghU1BSC++XKdBIpxeMb1zlHnR+fIzU++TiQs6p71gik8SrNE0jBHHUJvmvy7WxcO/wD1hi6D3QtGIIkYJNFw==
  • Cc: Jason Andryuk <jason.andryuk@xxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Oleksii Kurochko <oleksii.kurochko@xxxxxxxxx>
  • Delivery-date: Wed, 15 Oct 2025 21:05:23 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

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.

Convert to a proper for loop so that continue works.  Add a new helper,
next_entry(), to handle advancing to the next irq_pin_list entry.

Noticed during code inspection.  The infinite loop was not observed.

Fixes: f821102450a1 ("x86: IRQ Migration logic enhancement.")
Signed-off-by: Jason Andryuk <jason.andryuk@xxxxxxx>
Release-Acked-by: Oleksii Kurochko <oleksii.kurochko@xxxxxxxxx>
---
v3:
const on next_entry() parameter
Remove spaces inside for loop braces
Remove inner if (!entry) check
Expand commit message to state noticed during code inspection

v2:
continue (not break) for pin == -1.

I added the next_entry() helper since putting the expression in the for
loop is a little cluttered.  The helper can also be re-used for other
instances within the file.
---
 xen/arch/x86/io_apic.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/xen/arch/x86/io_apic.c b/xen/arch/x86/io_apic.c
index c384f10c1b..c35d611ecf 100644
--- a/xen/arch/x86/io_apic.c
+++ b/xen/arch/x86/io_apic.c
@@ -1586,20 +1586,24 @@ static int __init cf_check setup_ioapic_ack(const char 
*s)
 }
 custom_param("ioapic_ack", setup_ioapic_ack);
 
+static struct irq_pin_list *next_entry(const struct irq_pin_list *entry)
+{
+    if ( !entry->next )
+        return NULL;
+
+    return irq_2_pin + entry->next;
+}
+
 static bool io_apic_level_ack_pending(unsigned int irq)
 {
     struct irq_pin_list *entry;
     unsigned long flags;
 
     spin_lock_irqsave(&ioapic_lock, flags);
-    entry = &irq_2_pin[irq];
-    for (;;) {
+    for (entry = &irq_2_pin[irq]; entry; entry = next_entry(entry)) {
         unsigned int reg;
         int pin;
 
-        if (!entry)
-            break;
-
         pin = entry->pin;
         if (pin == -1)
             continue;
@@ -1609,9 +1613,6 @@ static bool io_apic_level_ack_pending(unsigned int irq)
             spin_unlock_irqrestore(&ioapic_lock, flags);
             return 1;
         }
-        if (!entry->next)
-            break;
-        entry = irq_2_pin + entry->next;
     }
     spin_unlock_irqrestore(&ioapic_lock, flags);
 
-- 
2.51.0




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.