Re: [PATCH 12/14] xen: events: remove use of nr_irqs as upperbound on number of pirqs

From: Ian Campbell
Date: Thu Mar 10 2011 - 03:57:42 EST


On Thu, 2011-03-10 at 05:33 +0000, Konrad Rzeszutek Wilk wrote:
> > int xen_irq_from_pirq(unsigned pirq)
> > {
> > - return pirq_to_irq[pirq];
> > + int irq;
> > +
> > + struct irq_info *info;
> > +
> > + spin_lock(&irq_mapping_update_lock);
> > +
> > + list_for_each_entry(info, &xen_irq_list_head, list) {
> > + if (info == NULL || info->type != IRQT_PIRQ)
> > + continue;
> > + irq = info->irq;
> > + if (info->u.pirq.pirq == pirq)
> > + goto out;
> > + }
> > + irq = -1;
> > +out:
> > + spin_lock(&irq_mapping_update_lock);
> > +
> > + return -1;
>
> Shouldn't this be:
>
> return irq

Yes. The impact of not doing so is that xen_hvm_setup_msi_irqs would
allocate a fresh PIRQ each time an MSI was reused, instead of resuing
the old one -- i.e. it's a leak. I retested PVHVM PCI hotplug with the
following patch.

> How come you are using the spin_lock here, but not
> in other places when iterating over the xen_irq_list_head?

Those other places already hold the lock in their caller (or are known
to be single threaded -- e.g. resume). Callers of xen_irq_from_pirq do
not hold the lock.

Ian.

8<------------------------