Arch use of pci_dev_is_added()
Subsystems (4)
cover Arch use of pci_dev_is_added()
Hi Bjorn, Hi Michael,
In my proposal to make pci_dev_is_added() more regularly usable by arch code you mentioned[0] that you believe the uses in arch/powerpc are not necessary anymore. From code reading I agree and so does Oliver O'Halloran[1].
So as promised here is a patch removing them. I only compile tested this as I don't have access to a powerpc system.
I've also looked a bit more into our use in s390 and as dicussed previously I don't think we can cleanly get rid of the existing one in arch/s390/pci_sysfs.c:recover_store() because we need to distinguish an already removed pdev just by looking at the pdev itself.
As for new uses I think in the upcoming automatic recovery code we can rely on the fact that a removed device has pdev->driver == NULL and don't need pci_dev_is_added() but it would make things clearer. I also noticed that before commit 44bda4b7d26e9 ("PCI: Fix is_added/is_busmaster race condition") there was simply a pdev->is_added flag that was cleanly accessible by arch code. So I wanted to ask for your advice.
Thanks,
Niklas
[0] https://lore.kernel.org/lkml/20210825190444.GA3593752@bjorn-Precision-5520/
[1] https://lore.kernel.org/lkml/CAOSf1CFyuf9FaeSNparj+7W0mKTPvtcM8vxjHDSFsNDC6k_7xQ@mail.gmail.com/
Niklas Schnelle (1):
powerpc: Drop superfluous pci_dev_is_added() calls
arch/powerpc/platforms/powernv/pci-sriov.c | 6 ------ arch/powerpc/platforms/pseries/setup.c | 3 +-- 2 files changed, 1 insertion(+), 8 deletions(-)
Signature · 1 line
2.25.1
PATCH 1/1 powerpc: Drop superfluous pci_dev_is_added() calls
On powerpc, pci_dev_is_added() is called as part of SR-IOV fixups that are done under pcibios_add_device() which in turn is only called in pci_device_add() whih is called when a PCI device is scanned.
Now pci_dev_assign_added() is called in pci_bus_add_device() which is only called after scanning the device. Thus pci_dev_is_added() is always false and can be dropped.
--- arch/powerpc/platforms/powernv/pci-sriov.c | 6 ------ arch/powerpc/platforms/pseries/setup.c | 3 +-- 2 files changed, 1 insertion(+), 8 deletions(-)
arch/powerpc/platforms/powernv/pci-sriov.c +0 -6
@@ -9,9 +9,6 @@#include "pci.h" -/* for pci_dev_is_added() */ -#include "../../../../drivers/pci/pci.h" -/* * The majority of the complexity in supporting SR-IOV on PowerNV comes from * the need to put the MMIO space for each VF into a separate PE. Internally
@@ -228,9 +225,6 @@ static void pnv_pci_ioda_fixup_iov_resources(struct pci_dev *pdev)void pnv_pci_ioda_fixup_iov (struct pci_dev *pdev) { -if (WARN_ON (pci_dev_is_added (pdev))) -return ; -if (pdev->is_virtfn) {struct pnv_ioda_pe *pe =pnv_ioda_get_pe (pdev);
arch/powerpc/platforms/pseries/setup.c +1 -2
@@ -74,7 +74,6 @@#include <asm/hvconsole.h> #include "pseries.h" -#include "../../../../drivers/pci/pci.h" DEFINE_STATIC_KEY_FALSE (shared_processor);EXPORT_SYMBOL (shared_processor);
@@ -750,7 +749,7 @@ static void pseries_pci_fixup_iov_resources(struct pci_dev *pdev)const int *indexes;struct device_node *dn =pci_device_to_OF_node (pdev); -if (!pdev->is_physfn ||pci_dev_is_added (pdev)) +if (!pdev->is_physfn)return ;/*Firmware must support open sriov otherwise dont configure*/ indexes =of_get_property (dn,"ibm,open-sriov-vf-bar-info" ,NULL );
Signature · 1 line
2.25.1
Michael Ellerman
reviewerRe: [PATCH 1/1] powerpc: Drop superfluous pci_dev_is_added() calls
Quoted 3 lines · Niklas Schnelle
On powerpc,
pci_dev_is_added()is called as part of SR-IOV fixups that are done underpcibios_add_device()which in turn is only called inpci_device_add()whih is called when a PCI device is scanned.
Thanks for cleaning this up for us.
Quoted 3 lines
Now
pci_dev_assign_added()is called inpci_bus_add_device()which is only called after scanning the device. Thuspci_dev_is_added()is always false and can be dropped.
My only query is whether we can pin down when that changed.
Oliver said:
The use of pci_dev_is_added() in arch/powerpc was because in the past pci_bus_add_device() could be called before pci_device_add(). That was fixed a while ago so It should be safe to remove those calls now.
I trawled back through the history a bit but I can't remember/find which commit changed that, Oliver can you remember?
cheers
Quoted 47 lines
arch/powerpc/platforms/powernv/pci-sriov.c +0
-6@@ -9,9 +9,6 @@#include "pci.h" -/* for pci_dev_is_added() */ -#include "../../../../drivers/pci/pci.h" -/* * The majority of the complexity in supporting SR-IOV on PowerNV comes from * the need to put the MMIO space for each VF into a separate PE. Internally @@ -228,9 +225,6 @@ static void pnv_pci_ioda_fixup_iov_resources(struct pci_dev *pdev)void pnv_pci_ioda_fixup_iov (struct pci_dev *pdev) { -if (WARN_ON (pci_dev_is_added (pdev))) -return ; -if (pdev->is_virtfn) {struct pnv_ioda_pe *pe =pnv_ioda_get_pe (pdev);arch/powerpc/platforms/pseries/setup.c +1
-2@@ -74,7 +74,6 @@#include <asm/hvconsole.h> #include "pseries.h" -#include "../../../../drivers/pci/pci.h" DEFINE_STATIC_KEY_FALSE (shared_processor);EXPORT_SYMBOL (shared_processor);@@ -750,7 +749,7 @@ static void pseries_pci_fixup_iov_resources(struct pci_dev *pdev)const int *indexes;struct device_node *dn =pci_device_to_OF_node (pdev); -if (!pdev->is_physfn ||pci_dev_is_added (pdev)) +if (!pdev->is_physfn)return ;/*Firmware must support open sriov otherwise dont configure*/ indexes =of_get_property (dn,"ibm,open-sriov-vf-bar-info" ,NULL );Signature · 1 line
2.25.1
Oliver O'Halloran
Reviewed-byRe: [PATCH 1/1] powerpc: Drop superfluous pci_dev_is_added() calls
Quoted 14 lines · Michael Ellerman
Quoted 3 lines · Niklas Schnelle
On powerpc,
pci_dev_is_added()is called as part of SR-IOV fixups that are done underpcibios_add_device()which in turn is only called inpci_device_add()whih is called when a PCI device is scanned.Thanks for cleaning this up for us.
Quoted 3 lines
Now
pci_dev_assign_added()is called inpci_bus_add_device()which is only called after scanning the device. Thuspci_dev_is_added()is always false and can be dropped.My only query is whether we can pin down when that changed.
Quoted 8 lines
Oliver said:
The use of
pci_dev_is_added()inarch/powerpcwas because in the pastpci_bus_add_device()could be called beforepci_device_add(). That was fixed a while ago so It should be safe to remove those calls now.I trawled back through the history a bit but I can't remember/find which commit changed that, Oliver can you remember?
Yeah, on closer inspection that never happened. The re-ordering I was thinking of was when the boot-time BAR assignments were moved in 3f068aae7a95 so they'd always occur before pci_bus_add_device() was called. I think I got that change mixed up with commit 30d87ef8b38d ("powerpc/pci: Fix pcibios_setup_device() ordering") which moved some of what what pcibios_device_add() did into pcibios_bus_add_device() to harmonise the hot and coldplug paths.
As far as I can tell the pci_dev_is_added() check has been pointless since the code was added in 6e628c7d33d9 ("powerpc/powernv: Reserve additional space for IOV BAR according to the number of total_pe"). Even back then pci_device_add() was called first in both the normal and OF based PCI probing paths so there's no circumstance where that code would see the added flag set.
That patch was part of the PowerNV SRIOV support series which went through quite a few iterations. My best guess is that check might have been needed in an earlier version and was just carried forward until it got merged. I didn't dig too deeply into the history though.
Re: [PATCH 1/1] powerpc: Drop superfluous pci_dev_is_added() calls
In reply to Niklas SchnelleQuoted 9 lines · Niklas Schnelle
On powerpc,
pci_dev_is_added()is called as part of SR-IOV fixups that are done underpcibios_add_device()which in turn is only called inpci_device_add()whih is called when a PCI device is scanned.Now
pci_dev_assign_added()is called inpci_bus_add_device()which is only called after scanning the device. Thuspci_dev_is_added()is always false and can be dropped.Signed-off-by Niklas Schnelle <[email protected]>
This doesn't touch the PCI core, so maybe makes sense for you to take it, Michael? But let me know if you think otherwise.
Thanks a lot for cleaning this up, Niklas.
Quoted 53 lines
--- arch/powerpc/platforms/powernv/pci-sriov.c | 6 ------ arch/powerpc/platforms/pseries/setup.c | 3 +-- 2 files changed, 1 insertion(+), 8 deletions(-)arch/powerpc/platforms/powernv/pci-sriov.c +0
-6@@ -9,9 +9,6 @@#include "pci.h" -/* for pci_dev_is_added() */ -#include "../../../../drivers/pci/pci.h" -/* * The majority of the complexity in supporting SR-IOV on PowerNV comes from * the need to put the MMIO space for each VF into a separate PE. Internally @@ -228,9 +225,6 @@ static void pnv_pci_ioda_fixup_iov_resources(struct pci_dev *pdev)void pnv_pci_ioda_fixup_iov (struct pci_dev *pdev) { -if (WARN_ON (pci_dev_is_added (pdev))) -return ; -if (pdev->is_virtfn) {struct pnv_ioda_pe *pe =pnv_ioda_get_pe (pdev);arch/powerpc/platforms/pseries/setup.c +1
-2@@ -74,7 +74,6 @@#include <asm/hvconsole.h> #include "pseries.h" -#include "../../../../drivers/pci/pci.h" DEFINE_STATIC_KEY_FALSE (shared_processor);EXPORT_SYMBOL (shared_processor);@@ -750,7 +749,7 @@ static void pseries_pci_fixup_iov_resources(struct pci_dev *pdev)const int *indexes;struct device_node *dn =pci_device_to_OF_node (pdev); -if (!pdev->is_physfn ||pci_dev_is_added (pdev)) +if (!pdev->is_physfn)return ;/*Firmware must support open sriov otherwise dont configure*/ indexes =of_get_property (dn,"ibm,open-sriov-vf-bar-info" ,NULL );Signature · 1 line
2.25.1
Michael Ellerman
reviewerRe: [PATCH 1/1] powerpc: Drop superfluous pci_dev_is_added() calls
Quoted 9 lines · Bjorn Helgaas
Quoted 8 lines · Niklas Schnelle
On powerpc,
pci_dev_is_added()is called as part of SR-IOV fixups that are done underpcibios_add_device()which in turn is only called inpci_device_add()whih is called when a PCI device is scanned.Now
pci_dev_assign_added()is called inpci_bus_add_device()which is only called after scanning the device. Thuspci_dev_is_added()is always false and can be dropped.
Quoted 6 lines
Quoted 1 line
Signed-off-by Niklas Schnelle <[email protected]>Reviewed-by Bjorn Helgaas <[email protected]>This doesn't touch the PCI core, so maybe makes sense for you to take it, Michael? But let me know if you think otherwise.
Yeah I'm happy to take it, thanks.
cheers
Michael Ellerman
AppliedQuoted 8 lines · Niklas Schnelle
In my proposal to make
pci_dev_is_added()more regularly usable by arch code you mentioned[0] that you believe the uses inarch/powerpcare not necessary anymore. From code reading I agree and so does Oliver O'Halloran[1].So as promised here is a patch removing them. I only compile tested this as I don't have access to a powerpc system.
[...]
Applied to powerpc/next.
[1/1] powerpc: Drop superfluous pci_dev_is_added() calls
https://git.kernel.org/powerpc/c/452f145eca73945222923525a7eba59cf37909cc
cheers