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

[PATCH] x86/irq: simplify loop in unmap_domain_pirq


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Roger Pau Monne <roger.pau@xxxxxxxxxx>
  • Date: Wed, 10 Feb 2021 10:22:11 +0100
  • 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=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1wJjk0FnZ0exCCqNZwfmwO0V8jY0khE99BEKiypY9VA=; b=hRd5vdqDMnSr6gM/QmC+e+UsCnQ9h5CeB4oy+Fk/ycE7Wk7wZtOopO57tCYI6mX7rEShOfrnwrm/o4RTb5rAGN9NFsuZQEJyyBXZ9bp7pQ2IIwf5EX5Bj566IeBjc8bSEj85/7KKjxH9g/oetqEyU7IQcNxeRjcPdjBalUIBFf9AUgHYne8dpMjJY0i1c5HH0XJtge1IlUXaXA9Vol5fKRHkp3Aay65CxaCTHRsy0JxhW/xPlMMuujDj1q1R5wKy6Q4GdUWPkrRpvUOLrhlMkkm487IBLlZVGOCJjulFXxNKyTsZ2iECFhPb+so6WjOQeG7/1p051LD6+LpRE22img==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nNIntsBgDH4EKwhfyZpjenesfEy5hPl6ko+m3TSJzLe9xudWeul1ApfHkQQEBIG1f8eFlzJiYZ5FyigSoNkOiQp3xMKY/AZfdfkvVgikLlU+DZtqcF8LPviXngIAZHEgNH83XiscTVuuXL6tMLFMACFSNiVjwcmds7lSnZDEC0ZFsAKn1zZVvDrbfHPyt0WpANflp17/pBkzuzeePLDIWVWo1tGn9Z4NwixLcnJ/j8rrqfXSIYcYzk4ARBRe741CiyslomqkQbIIgIMeUXBy2PRNvxXZr/w7E+LA7h5giXH5q1U9+VbfvJMdSmGVYypvEkgs6UmIxIfNHe8t0J1XJQ==
  • Authentication-results: esa5.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com
  • Cc: Roger Pau Monne <roger.pau@xxxxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>
  • Delivery-date: Wed, 10 Feb 2021 09:22:35 +0000
  • Ironport-sdr: Latd8G8zmysZV05HQOWBk5PU+Nggjef96NbFtl/NKZ2RwRtglodI+my9WoNndiPWILSnSOBv93 ZVuVEsfRmz1Vb4IFSPVdk7kl4WeR8U72pmFQOhzXI7MkCWIJrNNmAg6OYvq9BGsSoT1g6ZhDCp Jo4nDEBfmBKxdNyFn0+hMO1ulI80CiYqZGKFL6jimcXIjnnTionfiHiTQMCjXO6C4/LAzfXo4U 8naYdJj7WYd+ncyqmnxQR8HyT/bF9Fbjq2BxHgeT+uBqPgvZPomho9pYi53CdK7CM4BmewOjbU BPw=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

The for loop in unmap_domain_pirq is unnecessary complicated, with
several places where the index is incremented, and also different
exit conditions spread between the loop body.

Simplify it by looping over each possible PIRQ using the for loop
syntax, and remove all possible in-loop exit points.

No functional change intended.

Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
---
 xen/arch/x86/irq.c | 60 +++++++++++++---------------------------------
 1 file changed, 16 insertions(+), 44 deletions(-)

diff --git a/xen/arch/x86/irq.c b/xen/arch/x86/irq.c
index 032fe82167..856714b5bf 100644
--- a/xen/arch/x86/irq.c
+++ b/xen/arch/x86/irq.c
@@ -2305,7 +2305,6 @@ done:
 /* The pirq should have been unbound before this call. */
 int unmap_domain_pirq(struct domain *d, int pirq)
 {
-    unsigned long flags;
     struct irq_desc *desc;
     int irq, ret = 0, rc;
     unsigned int i, nr = 1;
@@ -2356,11 +2355,23 @@ int unmap_domain_pirq(struct domain *d, int pirq)
     if ( msi_desc != NULL )
         pci_disable_msi(msi_desc);
 
-    spin_lock_irqsave(&desc->lock, flags);
-
-    for ( i = 0; ; )
+    for ( i = 0; i < nr; i++, info = pirq_info(d, pirq + i) )
     {
+        unsigned long flags;
+
+        if ( !info || info->arch.irq <= 0 )
+        {
+            printk(XENLOG_G_ERR "dom%d: MSI pirq %d not mapped\n",
+                   d->domain_id, pirq + i);
+            continue;
+        }
+        irq = info->arch.irq;
+        desc = irq_to_desc(irq);
+
+        spin_lock_irqsave(&desc->lock, flags);
+
         BUG_ON(irq != domain_pirq_to_irq(d, pirq + i));
+        BUG_ON(desc->msi_desc != msi_desc + i);
 
         if ( !forced_unbind )
             clear_domain_irq_pirq(d, irq, info);
@@ -2378,45 +2389,6 @@ int unmap_domain_pirq(struct domain *d, int pirq)
             desc->msi_desc = NULL;
         }
 
-        if ( ++i == nr )
-            break;
-
-        spin_unlock_irqrestore(&desc->lock, flags);
-
-        if ( !forced_unbind )
-           cleanup_domain_irq_pirq(d, irq, info);
-
-        rc = irq_deny_access(d, irq);
-        if ( rc )
-        {
-            printk(XENLOG_G_ERR
-                   "dom%d: could not deny access to IRQ%d (pirq %d)\n",
-                   d->domain_id, irq, pirq + i);
-            ret = rc;
-        }
-
-        do {
-            info = pirq_info(d, pirq + i);
-            if ( info && (irq = info->arch.irq) > 0 )
-                break;
-            printk(XENLOG_G_ERR "dom%d: MSI pirq %d not mapped\n",
-                   d->domain_id, pirq + i);
-        } while ( ++i < nr );
-
-        if ( i == nr )
-        {
-            desc = NULL;
-            break;
-        }
-
-        desc = irq_to_desc(irq);
-        BUG_ON(desc->msi_desc != msi_desc + i);
-
-        spin_lock_irqsave(&desc->lock, flags);
-    }
-
-    if ( desc )
-    {
         spin_unlock_irqrestore(&desc->lock, flags);
 
         if ( !forced_unbind )
@@ -2427,7 +2399,7 @@ int unmap_domain_pirq(struct domain *d, int pirq)
         {
             printk(XENLOG_G_ERR
                    "dom%d: could not deny access to IRQ%d (pirq %d)\n",
-                   d->domain_id, irq, pirq + nr - 1);
+                   d->domain_id, irq, pirq + i);
             ret = rc;
         }
     }
-- 
2.29.2




 


Rackspace

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