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

[PATCH 02/13] x86/passthrough: don't blindly assume vCPU-s exist


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Thu, 26 Nov 2026 14:36:20 +0100
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=google header.d=suse.com header.i="@suse.com" header.h="Content-Transfer-Encoding:Content-Type:In-Reply-To:Autocrypt:Cc:Content-Language:References:To:From:Subject:User-Agent:MIME-Version:Date:Message-ID"
  • Autocrypt: addr=jbeulich@xxxxxxxx; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8rnNg22uyfAgmBKNLpLgAGVRMZGaGoJObGf72s6TeIqKJo/LtggAS9qAUiuKVnygo 3wjfkS9A3DRO+SpU7JqWdsveeIQyeyEJ/8PTowmSQLakF+3fote9ybzd880fSmFuIEJldWxp Y2ggPGpiZXVsaWNoQHN1c2UuY29tPsJgBBMRAgAgBQJZN5xEAhsDBgsJCAcDAgQVAggDBBYC AwECHgECF4AACgkQoDSui/t3IH4J+wCfQ5jHdEjCRHj23O/5ttg9r9OIruwAn3103WUITZee e7Sbg12UgcQ5lv7SzsFNBFk3nEQQCACCuTjCjFOUdi5Nm244F+78kLghRcin/awv+IrTcIWF hUpSs1Y91iQQ7KItirz5uwCPlwejSJDQJLIS+QtJHaXDXeV6NI0Uef1hP20+y8qydDiVkv6l IreXjTb7DvksRgJNvCkWtYnlS3mYvQ9NzS9PhyALWbXnH6sIJd2O9lKS1Mrfq+y0IXCP10eS FFGg+Av3IQeFatkJAyju0PPthyTqxSI4lZYuJVPknzgaeuJv/2NccrPvmeDg6Coe7ZIeQ8Yj t0ARxu2xytAkkLCel1Lz1WLmwLstV30g80nkgZf/wr+/BXJW/oIvRlonUkxv+IbBM3dX2OV8 AmRv1ySWPTP7AAMFB/9PQK/VtlNUJvg8GXj9ootzrteGfVZVVT4XBJkfwBcpC/XcPzldjv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Roger Pau Monné <roger@xxxxxxxxxxxxxx>, Teddy Astie <teddy.astie@xxxxxxxxxx>
  • Delivery-date: Thu, 26 Nov 2026 13:36:24 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

First, pirq_guest_bind() really only needs a vCPU to establish IRQ
affinity, and it already has fallback logic which can be used if the vCPU
passed in is NULL. Have the caller pass in a (guaranteed non-NULL) domain
pointer, making the vCPU one optional.

Reported-by: Roger Pau Monné <roger.pau@xxxxxxx>

While altering pirq_guest_bind()'s signature also convert its boolean
parameter to bool.

Further, while generally hvm_girq_dest_2_vcpu_id() would return only IDs
of valid vCPU-s, for a single-vCPU guest it would return 0 no matter
whether that vCPU was created already. Use domain_vcpu() when consuming
the return value; subsequent code already deals with the pointer being
NULL.

Fixes: fbe487b996b5 ("PCI passthru: VT-d I/O hooks")
Fixes: 85715f4bc7c9 ("MSI 5/6: add MSI support to passthrough HVM domain")
Fixes:  ("")
Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
---
I'll fill the missing Fixes: when xenbits is willing to work again.

--- a/xen/arch/x86/irq.c
+++ b/xen/arch/x86/irq.c
@@ -1627,14 +1627,15 @@ int pirq_shared(struct domain *d, int pi
     return shared;
 }
 
-int pirq_guest_bind(struct vcpu *v, struct pirq *pirq, int will_share)
+int pirq_guest_bind(struct domain *d, const struct vcpu *v, struct pirq *pirq,
+                    bool will_share)
 {
     struct irq_desc         *desc;
     irq_guest_action_t *action, *newaction = NULL;
     unsigned int        max_nr_guests = will_share ? irq_max_guests : 1;
     int                 rc = 0;
 
-    WARN_ON(!rw_is_write_locked(&v->domain->event_lock));
+    WARN_ON(!rw_is_write_locked(&d->event_lock));
     BUG_ON(!local_irq_is_enabled());
 
  retry:
@@ -1651,7 +1652,7 @@ int pirq_guest_bind(struct vcpu *v, stru
         {
             printk(XENLOG_G_INFO
                    "Cannot bind IRQ%d to dom%d. In use by '%s'.\n",
-                   pirq->pirq, v->domain->domain_id, desc->action->name);
+                   pirq->pirq, d->domain_id, desc->action->name);
             rc = -EBUSY;
             goto unlock_out;
         }
@@ -1666,7 +1667,7 @@ int pirq_guest_bind(struct vcpu *v, stru
             xfree(newaction);
             printk(XENLOG_G_INFO
                    "Cannot bind IRQ%d to dom%d. Out of memory.\n",
-                   pirq->pirq, v->domain->domain_id);
+                   pirq->pirq, d->domain_id);
             return -ENOMEM;
         }
 
@@ -1690,7 +1691,7 @@ int pirq_guest_bind(struct vcpu *v, stru
         {
             const cpumask_t *affinity = NULL;
 
-            if ( !opt_noirqbalance )
+            if ( !opt_noirqbalance && v )
                 affinity = cpumask_of(v->processor);
             else if ( !cpumask_intersects(desc->affinity, &cpu_online_map) )
             {
@@ -1710,7 +1711,7 @@ int pirq_guest_bind(struct vcpu *v, stru
     else if ( !will_share || !action->shareable )
     {
         printk(XENLOG_G_INFO "Cannot bind IRQ%d to dom%d. %s.\n",
-               pirq->pirq, v->domain->domain_id,
+               pirq->pirq, d->domain_id,
                will_share ? "Others do not share"
                           : "Will not share with others");
         rc = -EBUSY;
@@ -1734,17 +1735,17 @@ int pirq_guest_bind(struct vcpu *v, stru
         printk(XENLOG_G_INFO
                "Cannot bind IRQ%d to %pd: already at max share %u"
                " (increase with irq-max-guests= option)\n",
-               pirq->pirq, v->domain, irq_max_guests);
+               pirq->pirq, d, irq_max_guests);
         rc = -EBUSY;
         goto unlock_out;
     }
 
-    action->guest[action->nr_guests++] = v->domain;
+    action->guest[action->nr_guests++] = d;
 
     if ( action->ack_type != ACKTYPE_NONE )
-        set_pirq_eoi(v->domain, pirq->pirq);
+        set_pirq_eoi(d, pirq->pirq);
     else
-        clear_pirq_eoi(v->domain, pirq->pirq);
+        clear_pirq_eoi(d, pirq->pirq);
 
  unlock_out:
     spin_unlock_irq(&desc->lock);
--- a/xen/common/event_channel.c
+++ b/xen/common/event_channel.c
@@ -718,7 +718,7 @@ static int evtchn_bind_pirq(evtchn_bind_
 
     info->evtchn = port;
     rc = (!is_hvm_domain(d)
-          ? pirq_guest_bind(v, info,
+          ? pirq_guest_bind(d, v, info,
                             !!(bind->flags & BIND_PIRQ__WILL_SHARE))
           : 0);
     if ( rc != 0 )
--- a/xen/drivers/passthrough/x86/hvm.c
+++ b/xen/drivers/passthrough/x86/hvm.c
@@ -315,7 +315,7 @@ int pt_irq_create_bind(
              */
             pirq_dpci->dom = d;
             /* bind after hvm_irq_dpci is setup to avoid race with irq 
handler*/
-            rc = pirq_guest_bind(d->vcpu[0], info, 0);
+            rc = pirq_guest_bind(d, d->vcpu[0], info, 0);
             if ( rc == 0 && pt_irq_bind->u.msi.gtable )
             {
                 rc = msixtbl_pt_register(d, info, pt_irq_bind->u.msi.gtable);
@@ -375,7 +375,7 @@ int pt_irq_create_bind(
         pirq_dpci->gmsi.dest_vcpu_id = dest_vcpu_id;
 
         pirq_dpci->gmsi.posted = false;
-        vcpu = (dest_vcpu_id >= 0) ? d->vcpu[dest_vcpu_id] : NULL;
+        vcpu = (dest_vcpu_id >= 0) ? domain_vcpu(d, dest_vcpu_id) : NULL;
         if ( iommu_intpost )
         {
             if ( delivery_mode == dest_LowestPrio )
@@ -527,7 +527,7 @@ int pt_irq_create_bind(
             }
 
             /* Deal with gsi for legacy devices */
-            rc = pirq_guest_bind(d->vcpu[0], info, share);
+            rc = pirq_guest_bind(d, d->vcpu[0], info, share);
             if ( unlikely(rc) )
             {
                 /*
--- a/xen/include/xen/irq.h
+++ b/xen/include/xen/irq.h
@@ -184,7 +184,8 @@ void pirq_cleanup_check(struct pirq *pir
 extern void pirq_guest_eoi(struct pirq *pirq);
 extern void desc_guest_eoi(struct irq_desc *desc, struct pirq *pirq);
 extern int pirq_guest_unmask(struct domain *d);
-extern int pirq_guest_bind(struct vcpu *v, struct pirq *pirq, int will_share);
+extern int pirq_guest_bind(struct domain *d, const struct vcpu *v,
+                           struct pirq *pirq, bool will_share);
 extern void pirq_guest_unbind(struct domain *d, struct pirq *pirq);
 extern void pirq_set_affinity(struct domain *d, int pirq,
                               const cpumask_t *mask);




 


Rackspace

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