From: Jan Beulich <jbeulich@suse.com>
To: "xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>
Cc: "Andrew Cooper" <andrew.cooper3@citrix.com>,
"Julien Grall" <julien@xen.org>,
"Stefano Stabellini" <sstabellini@kernel.org>,
"Anthony PERARD" <anthony.perard@vates.tech>,
"Michal Orzel" <michal.orzel@amd.com>,
"Roger Pau Monné" <roger@xenproject.org>,
"Teddy Astie" <teddy.astie@vates.tech>
Subject: [PATCH 02/13] x86/passthrough: don't blindly assume vCPU-s exist
Date: Thu, 26 Nov 2026 14:36:20 +0100 [thread overview]
Message-ID: <ebe22349-be46-4853-a142-ffc934c995ba@suse.com> (raw)
In-Reply-To: <1ea6d02b-8fba-4b1e-969c-033d6a7be233@suse.com>
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@amd.com>
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@suse.com>
---
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);
next prev parent reply other threads:[~2026-11-26 13:36 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 12:48 [PATCH 00/13] make better use of domain_vcpu() Jan Beulich
2026-11-26 13:35 ` [PATCH 01/13] x86/gdbsx: don't blindly assume vCPU 0 exists Jan Beulich
2026-11-26 13:36 ` Jan Beulich [this message]
2026-11-26 13:37 ` [PATCH 03/13] x86/altp2m: don't blindly assume vCPU-s exist Jan Beulich
2026-12-02 6:38 ` Stephen Cheng
2026-12-02 7:41 ` Jan Beulich
2026-11-26 13:37 ` [PATCH 04/13] domctl: use domain_vcpu() in XEN_DOMCTL_{g,s}etvcpucontext handling Jan Beulich
2026-11-26 13:38 ` [PATCH 05/13] vm-event: use domain_vcpu() in domctl handling Jan Beulich
2026-11-26 13:38 ` [PATCH 06/13] numa: use domain_vcpu() in domain_to_node() Jan Beulich
2026-11-26 13:39 ` [PATCH 07/13] x86/time: use domain_vcpu() in tsc_set_info() Jan Beulich
2026-11-26 13:39 ` [PATCH 08/13] x86/paging: use domain_vcpu() in paging_domctl() Jan Beulich
2026-11-26 13:40 ` [PATCH 09/13] x86/dm: use domain_vcpu() Jan Beulich
2026-11-26 13:41 ` [PATCH 10/13] x86/HVM/MTRR: " Jan Beulich
2026-11-26 13:41 ` [PATCH 11/13] x86/HVM: introduce hvm_load_vcpu_instance() Jan Beulich
2026-11-26 13:43 ` Jan Beulich
2026-11-26 13:42 ` [PATCH 12/13] x86/vPMU: use domain_vcpu() Jan Beulich
2026-11-26 13:42 ` [PATCH 13/13] x86/domctl: use domain_vcpu() to handle various sub-ops Jan Beulich
2026-12-02 6:32 ` [PATCH 00/13] make better use of domain_vcpu() Stephen Cheng
2026-12-02 7:34 ` Jan Beulich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ebe22349-be46-4853-a142-ffc934c995ba@suse.com \
--to=jbeulich@suse.com \
--cc=andrew.cooper3@citrix.com \
--cc=anthony.perard@vates.tech \
--cc=julien@xen.org \
--cc=michal.orzel@amd.com \
--cc=roger@xenproject.org \
--cc=sstabellini@kernel.org \
--cc=teddy.astie@vates.tech \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.