[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH v2 06/11] vpci/header: add teardown cleanup
In order to unmap the BARs 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: - Add comment regarding the fact that memory decoding is not disabled when removing a device. --- xen/drivers/vpci/header.c | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/xen/drivers/vpci/header.c b/xen/drivers/vpci/header.c index 4363270a55..17a9dbb0bf 100644 --- a/xen/drivers/vpci/header.c +++ b/xen/drivers/vpci/header.c @@ -131,12 +131,15 @@ bool vpci_process_pending(struct vcpu *v) if ( rc == -ERESTART ) return true; - spin_lock(&v->vpci.pdev->vpci_lock); - if ( v->vpci.pdev->vpci ) - /* Disable memory decoding unconditionally on failure. */ - modify_decoding(v->vpci.pdev, !rc && v->vpci.map, - !rc && v->vpci.rom_only); - spin_unlock(&v->vpci.pdev->vpci_lock); + if ( v->vpci.pdev ) + { + spin_lock(&v->vpci.pdev->vpci_lock); + if ( v->vpci.pdev->vpci ) + /* Disable memory decoding unconditionally on failure. */ + modify_decoding(v->vpci.pdev, !rc && v->vpci.map, + !rc && v->vpci.rom_only); + spin_unlock(&v->vpci.pdev->vpci_lock); + } rangeset_destroy(v->vpci.mem); v->vpci.mem = NULL; @@ -560,7 +563,25 @@ static int init_bars(struct pci_dev *pdev) return (cmd & PCI_COMMAND_MEMORY) ? modify_bars(pdev, true, false) : 0; } -REGISTER_VPCI_INIT(init_bars, NULL, VPCI_PRIORITY_MIDDLE); + +static void teardown_bars(struct pci_dev *pdev) +{ + uint16_t cmd = pci_conf_read16(pdev->seg, pdev->bus, PCI_SLOT(pdev->devfn), + PCI_FUNC(pdev->devfn), PCI_COMMAND); + + if ( cmd & PCI_COMMAND_MEMORY ) + { + /* Unmap all BARs from guest p2m. */ + modify_bars(pdev, false, false); + /* + * Since this operation is deferred at the point when it finishes the + * device might have been removed, so don't attempt to disable memory + * decoding afterwards. + */ + current->vpci.pdev = NULL; + } +} +REGISTER_VPCI_INIT(init_bars, teardown_bars, VPCI_PRIORITY_MIDDLE); /* * Local variables: -- 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 |