[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH v2 04/11] vpci/msix: add teardown cleanup
So that interrupts are properly freed. Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx> --- Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx> Cc: George Dunlap <George.Dunlap@xxxxxxxxxxxxx> Cc: Ian Jackson <ian.jackson@xxxxxxxxxxxxx> Cc: Jan Beulich <jbeulich@xxxxxxxx> Cc: Julien Grall <julien.grall@xxxxxxx> Cc: Konrad Rzeszutek Wilk <konrad.wilk@xxxxxxxxxx> Cc: Stefano Stabellini <sstabellini@xxxxxxxxxx> Cc: Tim Deegan <tim@xxxxxxx> Cc: Wei Liu <wei.liu2@xxxxxxxxxx> --- Changes since v1: - Shuffle order of the teardown function. - Free msix in the teardown function. --- xen/drivers/vpci/msix.c | 55 ++++++++++++++++++++++++++++++++++++----- xen/drivers/vpci/vpci.c | 1 - 2 files changed, 49 insertions(+), 7 deletions(-) diff --git a/xen/drivers/vpci/msix.c b/xen/drivers/vpci/msix.c index befc4192d9..4fd0b643df 100644 --- a/xen/drivers/vpci/msix.c +++ b/xen/drivers/vpci/msix.c @@ -436,11 +436,6 @@ static int init_msix(struct pci_dev *pdev) vpci_msix_arch_init_entry(&pdev->vpci->msix->entries[i]); } - rc = vpci_add_register(pdev->vpci, control_read, control_write, - msix_control_reg(msix_offset), 2, pdev->vpci->msix); - if ( rc ) - return rc; - write_lock(&d->arch.hvm_domain.msix_lock); if ( list_empty(&d->arch.hvm_domain.msix_tables) ) register_mmio_handler(d, &vpci_msix_table_ops); @@ -448,9 +443,57 @@ static int init_msix(struct pci_dev *pdev) list_add(&pdev->vpci->msix->next, &d->arch.hvm_domain.msix_tables); write_unlock(&d->arch.hvm_domain.msix_lock); + rc = vpci_add_register(pdev->vpci, control_read, control_write, + msix_control_reg(msix_offset), 2, pdev->vpci->msix); + if ( rc ) + /* The teardown function will free the msix struct. */ + return rc; + return 0; } -REGISTER_VPCI_INIT(init_msix, NULL, VPCI_PRIORITY_HIGH); + +static void teardown_msix(struct pci_dev *pdev) +{ + struct vpci_msix *msix = pdev->vpci->msix; + unsigned int i, pos; + uint16_t control; + + if ( !msix ) + return; + + write_lock(&pdev->domain->arch.hvm_domain.msix_lock); + list_del(&pdev->vpci->msix->next); + write_unlock(&pdev->domain->arch.hvm_domain.msix_lock); + + if ( !msix->enabled ) + goto out; + + /* Disable MSIX. */ + pos = pci_find_cap_offset(pdev->seg, pdev->bus, PCI_SLOT(pdev->devfn), + PCI_FUNC(pdev->devfn), PCI_CAP_ID_MSIX); + ASSERT(pos); + control = pci_conf_read16(pdev->seg, pdev->bus, PCI_SLOT(pdev->devfn), + PCI_FUNC(pdev->devfn), msix_control_reg(pos)); + pci_conf_write16(pdev->seg, pdev->bus, PCI_SLOT(pdev->devfn), + PCI_FUNC(pdev->devfn), msix_control_reg(pos), + (control & ~PCI_MSIX_FLAGS_ENABLE)); + + for ( i = 0; i < msix->max_entries; i++ ) + { + int rc = vpci_msix_arch_disable_entry(&msix->entries[i], pdev); + + if ( rc && rc != -ENOENT ) + gprintk(XENLOG_WARNING, + "%04x:%02x:%02x.%u: unable to disable MSIX entry %u: %d\n", + pdev->seg, pdev->bus, PCI_SLOT(pdev->devfn), + PCI_FUNC(pdev->devfn), i, rc); + } + +out: + xfree(msix); + pdev->vpci->msix = NULL; +} +REGISTER_VPCI_INIT(init_msix, teardown_msix, VPCI_PRIORITY_HIGH); /* * Local variables: diff --git a/xen/drivers/vpci/vpci.c b/xen/drivers/vpci/vpci.c index 41fd089904..67548c4f43 100644 --- a/xen/drivers/vpci/vpci.c +++ b/xen/drivers/vpci/vpci.c @@ -60,7 +60,6 @@ static void vpci_remove_device_locked(struct pci_dev *pdev) list_del(&r->node); xfree(r); } - xfree(pdev->vpci->msix); xfree(pdev->vpci->msi); xfree(pdev->vpci); pdev->vpci = NULL; -- 2.17.1 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |