|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH 02/13] x86/passthrough: don't blindly assume vCPU-s exist
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);
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |