IOMMU group creation for pseries hotplug, and powernv VFs
Subsystems (3)
Oliver O'Halloran
reviewerA couple of extra patches on top of Shawn's existing re-ordering patch. This seems to fix the problem Alexey noted with Shawn's change causing VFs to lose their IOMMU group. I've tried pretty hard to make this a minimal fix it's still a bit large.
If mpe is happy to take this as a fix for 5.4 then I'll leave it, otherwise we might want to look at different approaches.
Oliver O'Halloran
reviewerPATCH 1/3 powernv/iov: Ensure the pdn for VFs always contains a valid PE number
On PowerNV we use the pcibios_sriov_enable() hook to do two things:
1. Create a pci_dn structure for each of the VFs, and
2. Configure the PHB's internal BARs that map MMIO ranges to PEs so that each VF has it's own PE. Note that the PE also determines the IOMMU table the HW uses for the device.
Currently we do not set the pe_number field of the pci_dn immediately after assigning the PE number for the VF that it represents. Instead, we do that in a fixup (see pnv_pci_dma_dev_setup) which is run inside the pcibios_add_device() hook which is run prior to adding the device to the bus.
On PowerNV we add the device to it's IOMMU group using a bus notifier and in order for this to work the PE number needs to be known when the bus notifier is run. This works today since the PE number is set in the fixup which runs before adding the device to the bus. However, if we want to move the fixup to a later stage this will break.
We can fix this by setting the pdn->pe_number inside of pcibios_sriov_enable(). There's no good to avoid this since we already have all the required information at that point, so... do that. Moving this earlier does cause two problems:
1. We trip the WARN_ON() in the fixup code, and
2. The EEH core will clear pdn->pe_number while recovering VFs.
The only justification for either of these is a comment in eeh_rmv_device() suggesting that pdn->pe_number *must* be set to IODA_INVALID_PE in order for the VF to be scanned. However, this comment appears to have no basis in reality so just delete it.
---
Can't get rid of the fixup entirely since we need it to set the ioda_pe->pdev back-pointer. I'll look at killing that another time.
--- arch/powerpc/kernel/eeh_driver.c | 6 ------ arch/powerpc/platforms/powernv/pci-ioda.c | 19 +++++++++++++++---- arch/powerpc/platforms/powernv/pci.c | 4 ---- 3 files changed, 15 insertions(+), 14 deletions(-)
arch/powerpc/kernel/eeh_driver.c +0 -6
@@ -541,12 +541,6 @@ static void eeh_rmv_device(struct eeh_dev *edev, void *userdata)pci_iov_remove_virtfn (edev->physfn, pdn->vf_index); edev->pdev =NULL ; - -/* -* We have to set the VF PE number to invalid one, which is -* required to plug the VF successfully. -*/ - pdn->pe_number =IODA_INVALID_PE ;#endif if (rmv_data)list_add (&edev->rmv_entry, &rmv_data->removed_vf_list);
arch/powerpc/platforms/powernv/pci-ioda.c +15 -4
@@ -1558,6 +1558,10 @@ static void pnv_ioda_setup_vf_PE(struct pci_dev *pdev, u16 num_vfs)/* Reserve PE for each VF */ for (vf_index =0 ; vf_index < num_vfs; vf_index++) { +int vf_devfn =pci_iov_virtfn_devfn (pdev, vf_index); +int vf_bus =pci_iov_virtfn_bus (pdev, vf_index); +struct pci_dn *vf_pdn; +if (pdn->m64_single_mode) pe_num = pdn->pe_num_map[vf_index];else
@@ -1570,13 +1574,11 @@ static void pnv_ioda_setup_vf_PE(struct pci_dev *pdev, u16 num_vfs) pe->pbus =NULL ; pe->parent_dev = pdev; pe->mve_number =-1 ; - pe->rid = (pci_iov_virtfn_bus (pdev, vf_index) <<8 ) | -pci_iov_virtfn_devfn (pdev, vf_index); + pe->rid = (vf_bus <<8 ) | vf_devfn;pe_info (pe,"VF %04d:%02d:%02d.%d associated with PE#%x\n" , hose->global_number, pdev->bus->number, -PCI_SLOT (pci_iov_virtfn_devfn (pdev, vf_index)), -PCI_FUNC (pci_iov_virtfn_devfn (pdev, vf_index)), pe_num); +PCI_SLOT (vf_devfn),PCI_FUNC (vf_devfn), pe_num);if (pnv_ioda_configure_pe (phb, pe)) {/* XXX What do we do here ? */
@@ -1590,6 +1592,15 @@ static void pnv_ioda_setup_vf_PE(struct pci_dev *pdev, u16 num_vfs)list_add_tail (&pe->list, &phb->ioda.pe_list);mutex_unlock (&phb->ioda.pe_list_mutex); +/* associate this pe to it's pdn */ +list_for_each_entry (vf_pdn, &pdn->parent->child_list, list) { +if (vf_pdn->busno == vf_bus && + vf_pdn->devfn == vf_devfn) { + vf_pdn->pe_number = pe_num; +break ; + } + } +pnv_pci_ioda2_setup_dma_pe (phb, pe);#ifdef CONFIG_IOMMU_API iommu_register_group(&pe->table_group,
arch/powerpc/platforms/powernv/pci.c +0 -4
@@ -816,16 +816,12 @@ void pnv_pci_dma_dev_setup(struct pci_dev *pdev)struct pnv_phb *phb = hose->private_data;#ifdef CONFIG_PCI_IOV struct pnv_ioda_pe *pe; -struct pci_dn *pdn;/* Fix the VF pdn PE number */ if (pdev->is_virtfn) { - pdn =pci_get_pdn (pdev); -WARN_ON (pdn->pe_number !=IODA_INVALID_PE );list_for_each_entry (pe, &phb->ioda.pe_list, list) {if (pe->rid == ((pdev->bus->number <<8 ) | (pdev->devfn &0xff ))) { - pdn->pe_number = pe->pe_number; pe->pdev = pdev;break ; }
Signature · 1 line
2.9.5
Oliver O'Halloran
reviewerPATCH 2/3 powerpc/pci: Fix pcibios_setup_device() ordering
In reply to Oliver O'HalloranFrom: Shawn Anastasio <[email protected]>
Move PCI device setup from pcibios_add_device() and pcibios_fixup_bus() to pcibios_bus_add_device(). This ensures that platform-specific DMA and IOMMU setup occurs after the device has been registered in sysfs, which is a requirement for IOMMU group assignment to work
This fixes IOMMU group assignment for hotplugged devices on pseries, where the existing behavior results in IOMMU assignment before registration.
Thanks to Lukas Wunner <[email protected]> for the suggestion.
--- arch/powerpc/kernel/pci-common.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-)
arch/powerpc/kernel/pci-common.c +9 -16
@@ -261,12 +261,6 @@ int pcibios_sriov_disable(struct pci_dev *pdev)#endif /* CONFIG_PCI_IOV */ -void pcibios_bus_add_device (struct pci_dev *pdev) -{ -if (ppc_md.pcibios_bus_add_device) - ppc_md.pcibios_bus_add_device (pdev); -} -static resource_size_t pcibios_io_size (const struct pci_controller *hose) {#ifdef CONFIG_PPC64
@@ -987,15 +981,17 @@ static void pcibios_setup_device(struct pci_dev *dev) ppc_md.pci_irq_fixup (dev); } -int pcibios_add_device (struct pci_dev *dev) +void pcibios_bus_add_device (struct pci_dev *pdev) { -/* -* We can only call pcibios_setup_device() after bus setup is complete, -* since some of the platform specific DMA setup code depends on it. -*/ -if (dev->bus->is_added) -pcibios_setup_device (dev); +/* Perform platform-specific device setup */ +pcibios_setup_device (pdev); + +if (ppc_md.pcibios_bus_add_device) + ppc_md.pcibios_bus_add_device (pdev); +} +int pcibios_add_device (struct pci_dev *dev) +{#ifdef CONFIG_PCI_IOV if (ppc_md.pcibios_fixup_sriov) ppc_md.pcibios_fixup_sriov (dev);
@@ -1037,9 +1033,6 @@ void pcibios_fixup_bus(struct pci_bus *bus)/* Now fixup the bus bus */ pcibios_setup_bus_self (bus); - -/* Now fixup devices on that bus */ -pcibios_setup_bus_devices (bus); }EXPORT_SYMBOL (pcibios_fixup_bus);
Signature · 1 line
2.9.5
Oliver O'Halloran
reviewerPATCH 3/3 powerpc/pci: Remove pcibios_setup_bus_devices()
In reply to Oliver O'HalloranWith the previous patch applied pcibios_setup_device() will always be run when pcibios_bus_add_device() is called. There are several code paths where pcibios_setup_bus_device() is still called (the PowerPC specific PCI hotplug support is one) so with just the previous patch applied the setup can be run multiple times on a device, once before the device is added to the bus and once after.
There's no need to run the setup in the early case any more so just remove it entirely.
--- arch/powerpc/include/asm/pci.h | 1 - arch/powerpc/kernel/pci-common.c | 25 ------------------------- arch/powerpc/kernel/pci-hotplug.c | 1 - arch/powerpc/kernel/pci_of_scan.c | 1 - 4 files changed, 28 deletions(-)
arch/powerpc/include/asm/pci.h +0 -1
@@ -113,7 +113,6 @@ extern pgprot_t pci_phys_mem_access_prot(struct file *file, pgprot_t prot);extern resource_size_t pcibios_io_space_offset (struct pci_controller *hose); -extern void pcibios_setup_bus_devices (struct pci_bus *bus);extern void pcibios_setup_bus_self (struct pci_bus *bus);extern void pcibios_setup_phb_io_space (struct pci_controller *hose);extern void pcibios_scan_phb (struct pci_controller *hose);
arch/powerpc/kernel/pci-common.c +0 -25
@@ -1000,24 +1000,6 @@ int pcibios_add_device(struct pci_dev *dev)return 0 ; } -void pcibios_setup_bus_devices (struct pci_bus *bus) -{ -struct pci_dev *dev; - -pr_debug ("PCI: Fixup bus devices %d (%s)\n" , - bus->number, bus->self ?pci_name (bus->self) :"PHB" ); - -list_for_each_entry (dev, &bus->devices, bus_list) { -/* Cardbus can call us to add new devices to a bus, so ignore -* those who are already fully discovered -*/ -if (pci_dev_is_added (dev)) -continue ; - -pcibios_setup_device (dev); - } -} -void pcibios_set_master (struct pci_dev *dev) {/* No special bus mastering setup handling */
@@ -1036,13 +1018,6 @@ void pcibios_fixup_bus(struct pci_bus *bus) }EXPORT_SYMBOL (pcibios_fixup_bus); -void pci_fixup_cardbus (struct pci_bus *bus) -{ -/* Now fixup devices on that bus */ -pcibios_setup_bus_devices (bus); -} - -static int skip_isa_ioresource_align (struct pci_dev *dev) { if (pci_has_flag(PCI_CAN_SKIP_ISA_ALIGN) &&
arch/powerpc/kernel/pci-hotplug.c +0 -1
@@ -134,7 +134,6 @@ void pci_hp_add_devices(struct pci_bus *bus)*/ slotno =PCI_SLOT (PCI_DN (dn->child)->devfn);pci_scan_slot (bus,PCI_DEVFN (slotno,0 )); -pcibios_setup_bus_devices (bus); max = bus->busn_res.start;/* * Scan bridges that are already configured. We don't touch
arch/powerpc/kernel/pci_of_scan.c +0 -1
@@ -414,7 +414,6 @@ static void __of_scan_bus(struct device_node *node, struct pci_bus *bus,*/ if (!rescan_existing)pcibios_setup_bus_self (bus); -pcibios_setup_bus_devices (bus);/* Now scan child busses */ for_each_pci_bridge (dev, bus)
Signature · 1 line
2.9.5
Re: [PATCH 1/3] powernv/iov: Ensure the pdn for VFs always contains a valid PE number
In reply to Oliver O'HalloranOn Mon, Sep 30, 2019 at 12:08:46PM +1000, Oliver O'Halloran wrote:
This is all powerpc, so I assume Michael will handle this. Just random things I noticed; ignore if they don't make sense:
Quoted 5 lines
On PowerNV we use the
pcibios_sriov_enable()hook to do two things:1. Create a
pci_dnstructure for each of the VFs, and
2. Configure the PHB's internal BARs that map MMIO ranges to PEs so that each VF has it's own PE. Note that the PE also determines
s/it's/its/
Quoted 9 lines
the IOMMU table the HW uses for the device.
Currently we do not set the
pe_numberfield of thepci_dnimmediately after assigning the PE number for the VF that it represents. Instead, we do that in a fixup (seepnv_pci_dma_dev_setup) which is run inside thepcibios_add_device()hook which is run prior to adding the device to the bus.On PowerNV we add the device to it's IOMMU group using a bus notifier and
s/it's/its/
Quoted 7 lines
in order for this to work the PE number needs to be known when the bus notifier is run. This works today since the PE number is set in the fixup which runs before adding the device to the bus. However, if we want to move the fixup to a later stage this will break.
We can fix this by setting the
pdn->pe_numberinside ofpcibios_sriov_enable(). There's no good to avoid this since we already have
s/no good/no good reason/ ?
Not quite sure what "this" refers to ... "no good reason to avoid setting pdn->pe_number in pcibios_sriov_enable()"? The double negative makes it a little hard to parse.
Quoted 54 lines
all the required information at that point, so... do that. Moving this earlier does cause two problems:
1. We trip the
WARN_ON()in the fixup code, and
2. The EEH core will clearpdn->pe_numberwhile recovering VFs.The only justification for either of these is a comment in
eeh_rmv_device()suggesting thatpdn->pe_number*must* be set toIODA_INVALID_PEin order for the VF to be scanned. However, this comment appears to have no basis in reality so just delete it.Signed-off-by Oliver O'Halloran <[email protected]>---
Can't get rid of the fixup entirely since we need it to set theioda_pe->pdevback-pointer. I'll look at killing that another time.--- arch/powerpc/kernel/eeh_driver.c | 6 ------ arch/powerpc/platforms/powernv/pci-ioda.c | 19 +++++++++++++++---- arch/powerpc/platforms/powernv/pci.c | 4 ---- 3 files changed, 15 insertions(+), 14 deletions(-)arch/powerpc/kernel/eeh_driver.c +0
-6@@ -541,12 +541,6 @@ static void eeh_rmv_device(struct eeh_dev *edev, void *userdata)pci_iov_remove_virtfn (edev->physfn, pdn->vf_index); edev->pdev =NULL ; - -/* -* We have to set the VF PE number to invalid one, which is -* required to plug the VF successfully. -*/ - pdn->pe_number =IODA_INVALID_PE ;#endif if (rmv_data)list_add (&edev->rmv_entry, &rmv_data->removed_vf_list);arch/powerpc/platforms/powernv/pci-ioda.c +4
-0@@ -1558,6 +1558,10 @@ static void pnv_ioda_setup_vf_PE(struct pci_dev *pdev, u16 num_vfs)/* Reserve PE for each VF */ for (vf_index =0 ; vf_index < num_vfs; vf_index++) { +int vf_devfn =pci_iov_virtfn_devfn (pdev, vf_index); +int vf_bus =pci_iov_virtfn_bus (pdev, vf_index); +struct pci_dn *vf_pdn; +if (pdn->m64_single_mode) pe_num = pdn->pe_num_map[vf_index];else
arch/powerpc/platforms/powernv/pci-ioda.c static void pnv_ioda_setup_vf_PE(struct pci_dev *pdev, u16 num_vfs) · line 1579
Quoted 8 lines
arch/powerpc/platforms/powernv/pci-ioda.c +1
-2@@ -1570,13 +1574,11 @@ static void pnv_ioda_setup_vf_PE(struct pci_dev *pdev, u16 num_vfs) pe->pbus =NULL ; pe->parent_dev = pdev; pe->mve_number =-1 ; - pe->rid = (pci_iov_virtfn_bus (pdev, vf_index) <<8 ) | -pci_iov_virtfn_devfn (pdev, vf_index); + pe->rid = (vf_bus <<8 ) | vf_devfn; pe_info(pe, "VF %04d:%02d:%02d.%d associated with PE#%x\n",
Not related to *this* patch, but this looks like maybe it's supposed to match the pci_name(), e.g., "%04x:%02x:%02x.%d" from pci_setup_device()? If so, the "%04d:%02d:%02d" here will be confusing since the decimal & hex won't always match.
arch/powerpc/platforms/powernv/pci-ioda.c static void pnv_ioda_setup_vf_PE(struct pci_dev *pdev, u16 num_vfs) · line 1580
Quoted 1 line
arch/powerpc/platforms/powernv/pci-ioda.c +0
-0hose->global_number, pdev->bus->number,
Consider pci_domain_nr(bus) instead of hose->global_number? It would be nice if you had the pci_dev * for each VF so you could just use pci_name(vf) instead of all this domain/bus/PCI_SLOT/FUNC.
Quoted 46 lines
arch/powerpc/platforms/powernv/pci-ioda.c +10
-2-PCI_SLOT (pci_iov_virtfn_devfn (pdev, vf_index)), - PCI_FUNC(pci_iov_virtfn_devfn(pdev, vf_index)), pe_num); + PCI_SLOT(vf_devfn), PCI_FUNC(vf_devfn), pe_num);if (pnv_ioda_configure_pe (phb, pe)) {/* XXX What do we do here ? */ @@ -1590,6 +1592,15 @@ static void pnv_ioda_setup_vf_PE(struct pci_dev *pdev, u16 num_vfs)list_add_tail (&pe->list, &phb->ioda.pe_list);mutex_unlock (&phb->ioda.pe_list_mutex); +/* associate this pe to it's pdn */ +list_for_each_entry (vf_pdn, &pdn->parent->child_list, list) { +if (vf_pdn->busno == vf_bus && + vf_pdn->devfn == vf_devfn) { + vf_pdn->pe_number = pe_num; +break ; + } + } +pnv_pci_ioda2_setup_dma_pe (phb, pe);#ifdef CONFIG_IOMMU_API iommu_register_group(&pe->table_group,arch/powerpc/platforms/powernv/pci.c +0
-4@@ -816,16 +816,12 @@ void pnv_pci_dma_dev_setup(struct pci_dev *pdev)struct pnv_phb *phb = hose->private_data;#ifdef CONFIG_PCI_IOV struct pnv_ioda_pe *pe; -struct pci_dn *pdn;/* Fix the VF pdn PE number */ if (pdev->is_virtfn) { - pdn =pci_get_pdn (pdev); -WARN_ON (pdn->pe_number !=IODA_INVALID_PE );list_for_each_entry (pe, &phb->ioda.pe_list, list) {if (pe->rid == ((pdev->bus->number <<8 ) | (pdev->devfn &0xff ))) { - pdn->pe_number = pe->pe_number; pe->pdev = pdev;break ; }Signature · 1 line
2.9.5
Oliver O'Halloran
reviewerRe: [PATCH 1/3] powernv/iov: Ensure the pdn for VFs always contains a valid PE number
Quoted 31 lines · Bjorn Helgaas
On Mon, Sep 30, 2019 at 12:08:46PM +1000, Oliver O'Halloran wrote:
This is all powerpc, so I assume Michael will handle this. Just random things I noticed; ignore if they don't make sense:
Quoted 5 lines
On PowerNV we use the
pcibios_sriov_enable()hook to do two things:1. Create a
pci_dnstructure for each of the VFs, and
2. Configure the PHB's internal BARs that map MMIO ranges to PEs so that each VF has it's own PE. Note that the PE also determiness/it's/its/
Quoted 9 lines
the IOMMU table the HW uses for the device.
Currently we do not set the
pe_numberfield of thepci_dnimmediately after assigning the PE number for the VF that it represents. Instead, we do that in a fixup (seepnv_pci_dma_dev_setup) which is run inside thepcibios_add_device()hook which is run prior to adding the device to the bus.On PowerNV we add the device to it's IOMMU group using a bus notifier and
s/it's/its/
Quoted 5 lines
in order for this to work the PE number needs to be known when the bus notifier is run. This works today since the PE number is set in the fixup which runs before adding the device to the bus. However, if we want to move the fixup to a later stage this will break.
Quoted 8 lines
Quoted 2 lines
We can fix this by setting the
pdn->pe_numberinside ofpcibios_sriov_enable(). There's no good to avoid this since we already haves/no good/no good reason/ ?
Not quite sure what "this" refers to ... "no good reason to avoid setting
pdn->pe_numberinpcibios_sriov_enable()"? The double negative makes it a little hard to parse.
I agree it's a bit vague, I'll re-word it.
Quoted 61 lines
Quoted 61 lines
all the required information at that point, so... do that. Moving this earlier does cause two problems:
1. We trip the
WARN_ON()in the fixup code, and
2. The EEH core will clearpdn->pe_numberwhile recovering VFs.The only justification for either of these is a comment in
eeh_rmv_device()suggesting thatpdn->pe_number*must* be set toIODA_INVALID_PEin order for the VF to be scanned. However, this comment appears to have no basis in reality so just delete it.Signed-off-by Oliver O'Halloran <[email protected]>---
Can't get rid of the fixup entirely since we need it to set theioda_pe->pdevback-pointer. I'll look at killing that another time.--- arch/powerpc/kernel/eeh_driver.c | 6 ------ arch/powerpc/platforms/powernv/pci-ioda.c | 19 +++++++++++++++---- arch/powerpc/platforms/powernv/pci.c | 4 ---- 3 files changed, 15 insertions(+), 14 deletions(-)arch/powerpc/kernel/eeh_driver.c +0
-6@@ -541,12 +541,6 @@ static void eeh_rmv_device(struct eeh_dev *edev, void *userdata)pci_iov_remove_virtfn (edev->physfn, pdn->vf_index); edev->pdev =NULL ; - -/* -* We have to set the VF PE number to invalid one, which is -* required to plug the VF successfully. -*/ - pdn->pe_number =IODA_INVALID_PE ;#endif if (rmv_data)list_add (&edev->rmv_entry, &rmv_data->removed_vf_list);arch/powerpc/platforms/powernv/pci-ioda.c +5
-2@@ -1558,6 +1558,10 @@ static void pnv_ioda_setup_vf_PE(struct pci_dev *pdev, u16 num_vfs)/* Reserve PE for each VF */ for (vf_index =0 ; vf_index < num_vfs; vf_index++) { +int vf_devfn =pci_iov_virtfn_devfn (pdev, vf_index); +int vf_bus =pci_iov_virtfn_bus (pdev, vf_index); +struct pci_dn *vf_pdn; +if (pdn->m64_single_mode) pe_num = pdn->pe_num_map[vf_index];else @@ -1570,13 +1574,11 @@ static void pnv_ioda_setup_vf_PE(struct pci_dev *pdev, u16 num_vfs) pe->pbus =NULL ; pe->parent_dev = pdev; pe->mve_number =-1 ; - pe->rid = (pci_iov_virtfn_bus (pdev, vf_index) <<8 ) | -pci_iov_virtfn_devfn (pdev, vf_index); + pe->rid = (vf_bus <<8 ) | vf_devfn;
Quoted 6 lines
arch/powerpc/platforms/powernv/pci-ioda.c static void pnv_ioda_setup_vf_PE(struct pci_dev *pdev, u16 num_vfs) · line 1579
Quoted 1 line
arch/powerpc/platforms/powernv/pci-ioda.c +0
-0pe_info(pe, "VF %04d:%02d:%02d.%d associated with PE#%x\n",Not related to *this* patch, but this looks like maybe it's supposed to match the
pci_name(), e.g., "%04x:%02x:%02x.%d" frompci_setup_device()? If so, the "%04d:%02d:%02d" here will be confusing since the decimal & hex won't always match.
That looks plain wrong. I'll send a separate patch to fix it.
Quoted 5 lines
arch/powerpc/platforms/powernv/pci-ioda.c static void pnv_ioda_setup_vf_PE(struct pci_dev *pdev, u16 num_vfs) · line 1580
Quoted 1 line
arch/powerpc/platforms/powernv/pci-ioda.c +0
-0hose->global_number, pdev->bus->number,Consider
pci_domain_nr(bus)instead ofhose->global_number? It would be nice if you had thepci_dev* for each VF so you could just usepci_name(vf)instead of all this domain/bus/PCI_SLOT/FUNC.
Unfortunately, we don't have pci_devs for the VFs when pcibios_sriov_enable() is called. On powernv (and pseries) we only permit config accesses to a BDF when a pci_dn exists for that BDF because the platform code assumes that one will exist. As a result we can't scan the VFs until after pcibios_sriov_enable() is called since that's where pci_dn's are created for the VFs. I'm working on removing the use of pci_dn from powernv entirely though. Once that's done we should revisit whether any of this infrastructure is necessary...
Oliver
Re: [PATCH 1/3] powernv/iov: Ensure the pdn for VFs always contains a valid PE number
In reply to Oliver O'HalloranQuoted 27 lines · Oliver O'Halloran
On PowerNV we use the
pcibios_sriov_enable()hook to do two things:1. Create a
pci_dnstructure for each of the VFs, and
2. Configure the PHB's internal BARs that map MMIO ranges to PEs so that each VF has it's own PE. Note that the PE also determines the IOMMU table the HW uses for the device.Currently we do not set the
pe_numberfield of thepci_dnimmediately after assigning the PE number for the VF that it represents. Instead, we do that in a fixup (seepnv_pci_dma_dev_setup) which is run inside thepcibios_add_device()hook which is run prior to adding the device to the bus.On PowerNV we add the device to it's IOMMU group using a bus notifier and in order for this to work the PE number needs to be known when the bus notifier is run. This works today since the PE number is set in the fixup which runs before adding the device to the bus. However, if we want to move the fixup to a later stage this will break.
We can fix this by setting the
pdn->pe_numberinside ofpcibios_sriov_enable(). There's no good to avoid this since we already have all the required information at that point, so... do that. Moving this earlier does cause two problems:1. We trip the
WARN_ON()in the fixup code, and
2. The EEH core will clearpdn->pe_numberwhile recovering VFs.
Quoted 6 lines
The only justification for either of these is a comment in
eeh_rmv_device()suggesting thatpdn->pe_number*must* be set toIODA_INVALID_PEin order for the VF to be scanned. However, this comment appears to have no basis in reality so just delete it.Signed-off-by Oliver O'Halloran <[email protected]>
Quoted 95 lines
---
Can't get rid of the fixup entirely since we need it to set theioda_pe->pdevback-pointer. I'll look at killing that another time.--- arch/powerpc/kernel/eeh_driver.c | 6 ------ arch/powerpc/platforms/powernv/pci-ioda.c | 19 +++++++++++++++---- arch/powerpc/platforms/powernv/pci.c | 4 ---- 3 files changed, 15 insertions(+), 14 deletions(-)arch/powerpc/kernel/eeh_driver.c +0
-6@@ -541,12 +541,6 @@ static void eeh_rmv_device(struct eeh_dev *edev, void *userdata)pci_iov_remove_virtfn (edev->physfn, pdn->vf_index); edev->pdev =NULL ; - -/* -* We have to set the VF PE number to invalid one, which is -* required to plug the VF successfully. -*/ - pdn->pe_number =IODA_INVALID_PE ;#endif if (rmv_data)list_add (&edev->rmv_entry, &rmv_data->removed_vf_list);arch/powerpc/platforms/powernv/pci-ioda.c +15
-4@@ -1558,6 +1558,10 @@ static void pnv_ioda_setup_vf_PE(struct pci_dev *pdev, u16 num_vfs)/* Reserve PE for each VF */ for (vf_index =0 ; vf_index < num_vfs; vf_index++) { +int vf_devfn =pci_iov_virtfn_devfn (pdev, vf_index); +int vf_bus =pci_iov_virtfn_bus (pdev, vf_index); +struct pci_dn *vf_pdn; +if (pdn->m64_single_mode) pe_num = pdn->pe_num_map[vf_index];else @@ -1570,13 +1574,11 @@ static void pnv_ioda_setup_vf_PE(struct pci_dev *pdev, u16 num_vfs) pe->pbus =NULL ; pe->parent_dev = pdev; pe->mve_number =-1 ; - pe->rid = (pci_iov_virtfn_bus (pdev, vf_index) <<8 ) | -pci_iov_virtfn_devfn (pdev, vf_index); + pe->rid = (vf_bus <<8 ) | vf_devfn;pe_info (pe,"VF %04d:%02d:%02d.%d associated with PE#%x\n" , hose->global_number, pdev->bus->number, -PCI_SLOT (pci_iov_virtfn_devfn (pdev, vf_index)), -PCI_FUNC (pci_iov_virtfn_devfn (pdev, vf_index)), pe_num); +PCI_SLOT (vf_devfn),PCI_FUNC (vf_devfn), pe_num);if (pnv_ioda_configure_pe (phb, pe)) {/* XXX What do we do here ? */ @@ -1590,6 +1592,15 @@ static void pnv_ioda_setup_vf_PE(struct pci_dev *pdev, u16 num_vfs)list_add_tail (&pe->list, &phb->ioda.pe_list);mutex_unlock (&phb->ioda.pe_list_mutex); +/* associate this pe to it's pdn */ +list_for_each_entry (vf_pdn, &pdn->parent->child_list, list) { +if (vf_pdn->busno == vf_bus && + vf_pdn->devfn == vf_devfn) { + vf_pdn->pe_number = pe_num; +break ; + } + } +pnv_pci_ioda2_setup_dma_pe (phb, pe);#ifdef CONFIG_IOMMU_API iommu_register_group(&pe->table_group,arch/powerpc/platforms/powernv/pci.c +0
-4@@ -816,16 +816,12 @@ void pnv_pci_dma_dev_setup(struct pci_dev *pdev)struct pnv_phb *phb = hose->private_data;#ifdef CONFIG_PCI_IOV struct pnv_ioda_pe *pe; -struct pci_dn *pdn;/* Fix the VF pdn PE number */ if (pdev->is_virtfn) { - pdn =pci_get_pdn (pdev); -WARN_ON (pdn->pe_number !=IODA_INVALID_PE );list_for_each_entry (pe, &phb->ioda.pe_list, list) {if (pe->rid == ((pdev->bus->number <<8 ) | (pdev->devfn &0xff ))) { - pdn->pe_number = pe->pe_number; pe->pdev = pdev;break ; }
Signature · 1 line
Alexey
Re: [PATCH 2/3] powerpc/pci: Fix pcibios_setup_device() ordering
In reply to Oliver O'HalloranQuoted 7 lines · Oliver O'Halloran
From: Shawn Anastasio <[email protected]>
Move PCI device setup from
pcibios_add_device()andpcibios_fixup_bus()topcibios_bus_add_device(). This ensures that platform-specific DMA and IOMMU setup occurs after the device has been registered in sysfs, which is a requirement for IOMMU group assignment to work
Quoted 6 lines
This fixes IOMMU group assignment for hotplugged devices on pseries, where the existing behavior results in IOMMU assignment before registration.
Thanks to Lukas Wunner <[email protected]> for the suggestion.
Signed-off-by Shawn Anastasio <[email protected]>
Quoted 57 lines
--- arch/powerpc/kernel/pci-common.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-)arch/powerpc/kernel/pci-common.c +9
-16@@ -261,12 +261,6 @@ int pcibios_sriov_disable(struct pci_dev *pdev)#endif /* CONFIG_PCI_IOV */ -void pcibios_bus_add_device (struct pci_dev *pdev) -{ -if (ppc_md.pcibios_bus_add_device) - ppc_md.pcibios_bus_add_device (pdev); -} -static resource_size_t pcibios_io_size (const struct pci_controller *hose) {#ifdef CONFIG_PPC64 @@ -987,15 +981,17 @@ static void pcibios_setup_device(struct pci_dev *dev) ppc_md.pci_irq_fixup (dev); } -int pcibios_add_device (struct pci_dev *dev) +void pcibios_bus_add_device (struct pci_dev *pdev) { -/* -* We can only call pcibios_setup_device() after bus setup is complete, -* since some of the platform specific DMA setup code depends on it. -*/ -if (dev->bus->is_added) -pcibios_setup_device (dev); +/* Perform platform-specific device setup */ +pcibios_setup_device (pdev); + +if (ppc_md.pcibios_bus_add_device) + ppc_md.pcibios_bus_add_device (pdev); +} +int pcibios_add_device (struct pci_dev *dev) +{#ifdef CONFIG_PCI_IOV if (ppc_md.pcibios_fixup_sriov) ppc_md.pcibios_fixup_sriov (dev);@@ -1037,9 +1033,6 @@ void pcibios_fixup_bus(struct pci_bus *bus)/* Now fixup the bus bus */ pcibios_setup_bus_self (bus); - -/* Now fixup devices on that bus */ -pcibios_setup_bus_devices (bus); }EXPORT_SYMBOL (pcibios_fixup_bus);
Signature · 1 line
Alexey
Re: [PATCH 3/3] powerpc/pci: Remove pcibios_setup_bus_devices()
In reply to Oliver O'HalloranQuoted 11 lines · Oliver O'Halloran
With the previous patch applied
pcibios_setup_device()will always be run whenpcibios_bus_add_device()is called. There are several code paths wherepcibios_setup_bus_device()is still called (the PowerPC specific PCI hotplug support is one) so with just the previous patch applied the setup can be run multiple times on a device, once before the device is added to the bus and once after.There's no need to run the setup in the early case any more so just remove it entirely.
Signed-off-by Oliver O'Halloran <[email protected]>
Quoted 87 lines
--- arch/powerpc/include/asm/pci.h | 1 - arch/powerpc/kernel/pci-common.c | 25 ------------------------- arch/powerpc/kernel/pci-hotplug.c | 1 - arch/powerpc/kernel/pci_of_scan.c | 1 - 4 files changed, 28 deletions(-)arch/powerpc/include/asm/pci.h +0
-1@@ -113,7 +113,6 @@ extern pgprot_t pci_phys_mem_access_prot(struct file *file, pgprot_t prot);extern resource_size_t pcibios_io_space_offset (struct pci_controller *hose); -extern void pcibios_setup_bus_devices (struct pci_bus *bus);extern void pcibios_setup_bus_self (struct pci_bus *bus);extern void pcibios_setup_phb_io_space (struct pci_controller *hose);extern void pcibios_scan_phb (struct pci_controller *hose);arch/powerpc/kernel/pci-common.c +0
-25@@ -1000,24 +1000,6 @@ int pcibios_add_device(struct pci_dev *dev)return 0 ; } -void pcibios_setup_bus_devices (struct pci_bus *bus) -{ -struct pci_dev *dev; - -pr_debug ("PCI: Fixup bus devices %d (%s)\n" , - bus->number, bus->self ?pci_name (bus->self) :"PHB" ); - -list_for_each_entry (dev, &bus->devices, bus_list) { -/* Cardbus can call us to add new devices to a bus, so ignore -* those who are already fully discovered -*/ -if (pci_dev_is_added (dev)) -continue ; - -pcibios_setup_device (dev); - } -} -void pcibios_set_master (struct pci_dev *dev) {/* No special bus mastering setup handling */ @@ -1036,13 +1018,6 @@ void pcibios_fixup_bus(struct pci_bus *bus) }EXPORT_SYMBOL (pcibios_fixup_bus); -void pci_fixup_cardbus (struct pci_bus *bus) -{ -/* Now fixup devices on that bus */ -pcibios_setup_bus_devices (bus); -} - -static int skip_isa_ioresource_align (struct pci_dev *dev) { if (pci_has_flag(PCI_CAN_SKIP_ISA_ALIGN) &&arch/powerpc/kernel/pci-hotplug.c +0
-1@@ -134,7 +134,6 @@ void pci_hp_add_devices(struct pci_bus *bus)*/ slotno =PCI_SLOT (PCI_DN (dn->child)->devfn);pci_scan_slot (bus,PCI_DEVFN (slotno,0 )); -pcibios_setup_bus_devices (bus); max = bus->busn_res.start;/* * Scan bridges that are already configured. We don't touch arch/powerpc/kernel/pci_of_scan.c +0
-1@@ -414,7 +414,6 @@ static void __of_scan_bus(struct device_node *node, struct pci_bus *bus,*/ if (!rescan_existing)pcibios_setup_bus_self (bus); -pcibios_setup_bus_devices (bus);/* Now scan child busses */ for_each_pci_bridge (dev, bus)
Signature · 1 line
Alexey
Shawn Anastasio
Reviewed-byQuoted 8 lines · Oliver O'Halloran
A couple of extra patches on top of Shawn's existing re-ordering patch. This seems to fix the problem Alexey noted with Shawn's change causing VFs to lose their IOMMU group. I've tried pretty hard to make this a minimal fix it's still a bit large.
If mpe is happy to take this as a fix for 5.4 then I'll leave it, otherwise we might want to look at different approaches.
Thanks for fixing this Oliver!
Michael Ellerman
reviewerRe: [PATCH 1/3] powernv/iov: Ensure the pdn for VFs always contains a valid PE number
In reply to Oliver O'HalloranQuoted 33 lines · Oliver O'Halloran
Quoted 32 lines · Bjorn Helgaas
On Mon, Sep 30, 2019 at 12:08:46PM +1000, Oliver O'Halloran wrote:
This is all powerpc, so I assume Michael will handle this. Just random things I noticed; ignore if they don't make sense:Quoted 5 lines
On PowerNV we use the
pcibios_sriov_enable()hook to do two things:1. Create a
pci_dnstructure for each of the VFs, and
2. Configure the PHB's internal BARs that map MMIO ranges to PEs so that each VF has it's own PE. Note that the PE also determiness/it's/its/
Quoted 9 lines
the IOMMU table the HW uses for the device.
Currently we do not set the
pe_numberfield of thepci_dnimmediately after assigning the PE number for the VF that it represents. Instead, we do that in a fixup (seepnv_pci_dma_dev_setup) which is run inside thepcibios_add_device()hook which is run prior to adding the device to the bus.On PowerNV we add the device to it's IOMMU group using a bus notifier and
s/it's/its/
Quoted 7 lines
in order for this to work the PE number needs to be known when the bus notifier is run. This works today since the PE number is set in the fixup which runs before adding the device to the bus. However, if we want to move the fixup to a later stage this will break.
We can fix this by setting the
pdn->pe_numberinside ofpcibios_sriov_enable(). There's no good to avoid this since we already have
Quoted 7 lines
Quoted 5 lines
s/no good/no good reason/ ?
Not quite sure what "this" refers to ... "no good reason to avoid setting
pdn->pe_numberinpcibios_sriov_enable()"? The double negative makes it a little hard to parse.I agree it's a bit vague, I'll re-word it.
So I'm expecting a v2?
cheers