diff -r c783f340bef8 -r f4e09625f1dd linux-2.6-xen-sparse/drivers/xen/pciback/pciback_ops.c --- a/linux-2.6-xen-sparse/drivers/xen/pciback/pciback_ops.c Tue Apr 11 08:58:04 2006 +++ b/linux-2.6-xen-sparse/drivers/xen/pciback/pciback_ops.c Tue Apr 11 17:40:03 2006 @@ -36,21 +36,13 @@ dev->is_busmaster = 0; } } - - pciback_config_reset(dev); } -irqreturn_t pciback_handle_event(int irq, void *dev_id, struct pt_regs *regs) +void pciback_do_op(void *data) { - struct pciback_device *pdev = dev_id; + struct pciback_device *pdev = data; struct pci_dev *dev; struct xen_pci_op *op = &pdev->sh_info->op; - - if (unlikely(!test_bit(_XEN_PCIF_active, - (unsigned long *)&pdev->sh_info->flags))) { - pr_debug("pciback: interrupt, but no active operation\n"); - goto out; - } dev = pciback_get_pci_dev(pdev, op->domain, op->bus, op->devfn); @@ -65,9 +57,31 @@ else op->err = XEN_PCI_ERR_not_implemented; + /* Mark that we're done */ + atomic_inc(&pdev->in_use); + + /* Tell the driver domain that we're done */ wmb(); clear_bit(_XEN_PCIF_active, (unsigned long *)&pdev->sh_info->flags); notify_remote_via_irq(pdev->evtchn_irq); +} + +irqreturn_t pciback_handle_event(int irq, void *dev_id, struct pt_regs *regs) +{ + struct pciback_device *pdev = dev_id; + + if (unlikely(!test_bit(_XEN_PCIF_active, + (unsigned long *)&pdev->sh_info->flags))) { + pr_debug("pciback: interrupt, but no active operation\n"); + goto out; + } + + /* Make sure driver domain doesn't trigger another interrupt while + * we're still processing the last one */ + if (atomic_dec_and_test(&pdev->in_use)) + schedule_work(&pdev->op_work); + else + atomic_inc(&pdev->in_use); out: return IRQ_HANDLED; diff -r c783f340bef8 -r f4e09625f1dd linux-2.6-xen-sparse/drivers/xen/pciback/xenbus.c --- a/linux-2.6-xen-sparse/drivers/xen/pciback/xenbus.c Tue Apr 11 08:58:04 2006 +++ b/linux-2.6-xen-sparse/drivers/xen/pciback/xenbus.c Tue Apr 11 17:40:03 2006 @@ -30,6 +30,9 @@ pdev->evtchn_irq = INVALID_EVTCHN_IRQ; pdev->be_watching = 0; + atomic_set(&pdev->in_use, 1); + INIT_WORK(&pdev->op_work, pciback_do_op, pdev); + if (pciback_init_devices(pdev)) { kfree(pdev); pdev = NULL; @@ -46,6 +49,11 @@ /* Ensure the guest can't trigger our handler before removing devices */ if (pdev->evtchn_irq != INVALID_EVTCHN_IRQ) unbind_from_irqhandler(pdev->evtchn_irq, pdev); + + /* If the driver domain started an op, make sure we complete it or + * delete it before releasing the shared memory */ + cancel_delayed_work(&pdev->op_work); + flush_scheduled_work(); if (pdev->sh_info) xenbus_unmap_ring_vfree(pdev->xdev, pdev->sh_info);