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

Re: [PATCH v2] x86/apic: Avoid infinite loop in io_apic_level_ack_pending()


  • To: Jason Andryuk <jason.andryuk@xxxxxxx>
  • From: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Date: Tue, 14 Oct 2025 09:37:09 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • 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=HQCtHzzmgtwKLjdWm+SaTOHdwOObZCpRVv65PCf6QTQ=; b=Xj4o6crxHART2kdysjkjU9DbY+mkDy7cZHDSjoTDmH/KU6qNt+T/iBEB2bdyYFEnhVacLkOSskvFjjvSzxQ9LuFY80xaelBdC5zoP8kEYMsUMCvfMKS5DkDJWRe/Fb2BrYbNEd22e2MEUykTP/TBZfcWg23YItqJ1G+X3XiGWp+j7e6gZrNEv1bp1kaSyx8ZFTq1X0wK9ODHcciNMr++kS2d0mpcUXmV575ZOV+TqIUKGZoEb9bD+qRrA8erKIQGsL9+dY7DryYnbJbKqU9HtEG0vMd1KVVWsYF7/TDGqRLjm9IKQhXCK46q82dhpvKwQYDZjcpMx1UKC+HikLO0RA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=jI8wp+AtInsUqvFqL4OjzDOGfId/evGKgPAkuLAGqz+3o04qSqFZ0nh9WScXRq5QYyZ2NnMbAvw7+EVYPOaUgOtt6qVipk/jpOUj0DbEQ/R7VlZ2D4i0UWk+Rr3JhQ4q0CvFFxMsyli05kzhYOEaA+gl2bDcGqx0+0Z3JwcXklEbrEWbYNEoss+J6H4bwHwdlFLhU1TwKmexQ19nlaLFzYB2Z1h1TLqhZNNszfNnlcsumpiQqA2Ic10iyaLv9ZT3HftMMZlc2UrN9awvaWyGSjwgFp6qn1vIHUFGsPOtcik1aOCqTM39R4clZouTWd/7MkiJCdbvP1Zo1avO1Ic/vQ==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: xen-devel@xxxxxxxxxxxxxxxxxxxx, Oleksii Kurochko <oleksii.kurochko@xxxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Delivery-date: Tue, 14 Oct 2025 07:37:39 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On Mon, Oct 13, 2025 at 05:11:06PM -0400, Jason Andryuk wrote:
> 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.

Do you know how you end up with an entry with pin == -1 on the
irq_pin_list? Are there systems with gaps in the GSI space between
IO-APICs?  So far everything I saw had the IO-APIC in contiguous GSI
space.

> 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.
> 
> Fixes: f821102450a1 ("x86: IRQ Migration logic enhancement.")
> Signed-off-by: Jason Andryuk <jason.andryuk@xxxxxxx>
> ---
> 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 | 14 +++++++++-----
>  1 file changed, 9 insertions(+), 5 deletions(-)
> 
> diff --git a/xen/arch/x86/io_apic.c b/xen/arch/x86/io_apic.c
> index c384f10c1b..7b58345c96 100644
> --- a/xen/arch/x86/io_apic.c
> +++ b/xen/arch/x86/io_apic.c
> @@ -1586,14 +1586,21 @@ 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(struct irq_pin_list *entry)

I think you can make the entry parameter const?

> +{
> +    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) ) {

I'm not sure where we stand regarding coding style here, but it looks
you either want to remove the space between parentheses (my
preference), or place the opening for braces on a newline.  I would
possibly do:

for (entry = &irq_2_pin[irq]; entry; entry = next_entry(entry)) {
...

As I think it fits better given the small change and the surrounding
coding style.

>          unsigned int reg;
>          int pin;

Below here you can remove the:

        if (!entry)
            break;

Chunk, as the for loop already checks for this condition.

Otherwise looks good, I think we should consider for 4.21 inclusion.

Thanks, Roger.



 


Rackspace

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