diff -r 1020c52c58c1 -r 1c4d731a68ef linux-2.6-xen-sparse/drivers/xen/pciback/pciback.h --- a/linux-2.6-xen-sparse/drivers/xen/pciback/pciback.h Sat Apr 22 09:41:53 2006 +++ b/linux-2.6-xen-sparse/drivers/xen/pciback/pciback.h Tue Apr 25 16:58:33 2006 @@ -11,12 +11,17 @@ #include #include #include +#include +#include #include struct pci_dev_entry { struct list_head list; struct pci_dev *dev; }; + +#define _PDEVF_op_active (0) +#define PDEVF_op_active (1<<(_PDEVF_op_active)) struct pciback_device { void *pci_dev_data; @@ -30,6 +35,10 @@ int evtchn_irq; struct xen_pci_sharedinfo *sh_info; + + unsigned long flags; + + struct work_struct op_work; }; struct pciback_dev_data { @@ -70,6 +79,7 @@ /* Handles events from front-end */ irqreturn_t pciback_handle_event(int irq, void *dev_id, struct pt_regs *regs); +void pciback_do_op(void *data); int pciback_xenbus_register(void); void pciback_xenbus_unregister(void); diff -r 1020c52c58c1 -r 1c4d731a68ef linux-2.6-xen-sparse/drivers/xen/pciback/pciback_ops.c --- a/linux-2.6-xen-sparse/drivers/xen/pciback/pciback_ops.c Sat Apr 22 09:41:53 2006 +++ b/linux-2.6-xen-sparse/drivers/xen/pciback/pciback_ops.c Tue Apr 25 16:58:33 2006 @@ -40,17 +40,24 @@ pciback_config_reset(dev); } -irqreturn_t pciback_handle_event(int irq, void *dev_id, struct pt_regs *regs) +static inline void test_and_schedule_op(struct pciback_device *pdev) { - struct pciback_device *pdev = dev_id; + /* Check that frontend is requesting an operation and that we are not + * already processing a request */ + if (test_bit(_XEN_PCIF_active, (unsigned long *)&pdev->sh_info->flags) + && !test_and_set_bit(_PDEVF_op_active, &pdev->flags)) + schedule_work(&pdev->op_work); +} + +/* Performing the configuration space reads/writes must not be done in atomic + * context because some of the pci_* functions can sleep (mostly due to ACPI + * use of semaphores). This function is intended to be called from a work + * queue in process context taking a struct pciback_device as a parameter */ +void pciback_do_op(void *data) +{ + 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,10 +72,25 @@ else op->err = XEN_PCI_ERR_not_implemented; + /* 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); - out: + /* Mark that we're done */ + wmb(); + clear_bit(_PDEVF_op_active, &pdev->flags); + + /* Check to see if the driver domain tried to start another request + * in between clearing _XEN_PCIF_active and clearing _PDEVF_op_active */ + test_and_schedule_op(pdev); +} + +irqreturn_t pciback_handle_event(int irq, void *dev_id, struct pt_regs *regs) +{ + struct pciback_device *pdev = dev_id; + + test_and_schedule_op(pdev); + return IRQ_HANDLED; } diff -r 1020c52c58c1 -r 1c4d731a68ef linux-2.6-xen-sparse/drivers/xen/pciback/xenbus.c --- a/linux-2.6-xen-sparse/drivers/xen/pciback/xenbus.c Sat Apr 22 09:41:53 2006 +++ b/linux-2.6-xen-sparse/drivers/xen/pciback/xenbus.c Tue Apr 25 16:58:33 2006 @@ -30,6 +30,8 @@ pdev->evtchn_irq = INVALID_EVTCHN_IRQ; pdev->be_watching = 0; + INIT_WORK(&pdev->op_work, pciback_do_op, pdev); + if (pciback_init_devices(pdev)) { kfree(pdev); pdev = NULL; @@ -46,6 +48,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);