[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [PATCH v10 05/17] vpci: add hooks for PCI device assign/de-assign
On Thu, Oct 12, 2023 at 10:09:15PM +0000, Volodymyr Babchuk wrote: > From: Oleksandr Andrushchenko <oleksandr_andrushchenko@xxxxxxxx> > > When a PCI device gets assigned/de-assigned we need to > initialize/de-initialize vPCI state for the device. > > Also, rename vpci_add_handlers() to vpci_assign_device() and > vpci_remove_device() to vpci_deassign_device() to better reflect role > of the functions. > > Signed-off-by: Oleksandr Andrushchenko <oleksandr_andrushchenko@xxxxxxxx> > Signed-off-by: Volodymyr Babchuk <volodymyr_babchuk@xxxxxxxx> > --- > > In v10: > - removed HAS_VPCI_GUEST_SUPPORT checks > - HAS_VPCI_GUEST_SUPPORT config option (in Kconfig) as it is not used > anywhere > In v9: > - removed previous vpci_[de]assign_device function and renamed > existing handlers > - dropped attempts to handle errors in assign_device() function > - do not call vpci_assign_device for dom_io > - use d instead of pdev->domain > - use IS_ENABLED macro > In v8: > - removed vpci_deassign_device > In v6: > - do not pass struct domain to vpci_{assign|deassign}_device as > pdev->domain can be used > - do not leave the device assigned (pdev->domain == new domain) in case > vpci_assign_device fails: try to de-assign and if this also fails, then > crash the domain > In v5: > - do not split code into run_vpci_init > - do not check for is_system_domain in vpci_{de}assign_device > - do not use vpci_remove_device_handlers_locked and re-allocate > pdev->vpci completely > - make vpci_deassign_device void > In v4: > - de-assign vPCI from the previous domain on device assignment > - do not remove handlers in vpci_assign_device as those must not > exist at that point > In v3: > - remove toolstack roll-back description from the commit message > as error are to be handled with proper cleanup in Xen itself > - remove __must_check > - remove redundant rc check while assigning devices > - fix redundant CONFIG_HAS_VPCI check for CONFIG_HAS_VPCI_GUEST_SUPPORT > - use REGISTER_VPCI_INIT machinery to run required steps on device > init/assign: add run_vpci_init helper > In v2: > - define CONFIG_HAS_VPCI_GUEST_SUPPORT so dead code is not compiled > for x86 > In v1: > - constify struct pci_dev where possible > - do not open code is_system_domain() > - extended the commit message > --- > xen/drivers/passthrough/pci.c | 20 ++++++++++++++++---- > xen/drivers/vpci/header.c | 2 +- > xen/drivers/vpci/vpci.c | 6 +++--- > xen/include/xen/vpci.h | 10 +++++----- > 4 files changed, 25 insertions(+), 13 deletions(-) > > diff --git a/xen/drivers/passthrough/pci.c b/xen/drivers/passthrough/pci.c > index 182da45acb..b7926a291c 100644 > --- a/xen/drivers/passthrough/pci.c > +++ b/xen/drivers/passthrough/pci.c > @@ -755,7 +755,7 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn, > * For devices not discovered by Xen during boot, add vPCI handlers > * when Dom0 first informs Xen about such devices. > */ > - ret = vpci_add_handlers(pdev); > + ret = vpci_assign_device(pdev); > if ( ret ) > { > list_del(&pdev->domain_list); > @@ -769,7 +769,7 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn, > if ( ret ) > { > write_lock(&hardware_domain->pci_lock); > - vpci_remove_device(pdev); > + vpci_deassign_device(pdev); > list_del(&pdev->domain_list); > write_unlock(&hardware_domain->pci_lock); > pdev->domain = NULL; > @@ -817,7 +817,7 @@ int pci_remove_device(u16 seg, u8 bus, u8 devfn) > list_for_each_entry ( pdev, &pseg->alldevs_list, alldevs_list ) > if ( pdev->bus == bus && pdev->devfn == devfn ) > { > - vpci_remove_device(pdev); > + vpci_deassign_device(pdev); > pci_cleanup_msi(pdev); > ret = iommu_remove_device(pdev); > if ( pdev->domain ) > @@ -875,6 +875,10 @@ static int deassign_device(struct domain *d, uint16_t > seg, uint8_t bus, > goto out; > } > > + write_lock(&d->pci_lock); > + vpci_deassign_device(pdev); > + write_unlock(&d->pci_lock); > + > devfn = pdev->devfn; > ret = iommu_call(hd->platform_ops, reassign_device, d, target, devfn, > pci_to_dev(pdev)); In deassign_device() you are missing a call to vpci_assign_device() in order to setup the vPCI handlers for the target domain (not for dom_io, but possibly for hardware_domain if it's PVH-like). If the call to reassign_device is successful you need to call vpci_assign_device(). The rest LGTM. Thanks, Roger.
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |