PCI: s390: Handle ARI on bus without associated struct pci_dev
Niklas Schnelle
maintainerPATCH 1/1 PCI: s390: Handle ARI on bus without associated struct pci_dev
On s390 PCI busses are virtualized and the downstream ports are invisible to the OS and struct pci_bus::self is NULL. This associated struct pci_dev is however relied upon in pci_ari_enabled() to check whether ARI is enabled for the bus. ARI is therefor always detected as disabled.
At the same time firmware on s390 always enables and relies upon ARI thus causing a mismatch. Moreover with per-PCI function pass-through there may exist busses with no function with devfn 0. For example a SR-IOV capable device with two PFs may have separate function dependency link chains for each of the PFs and their child VFs. In this case the OS may only see the second PF and its child VFs on a bus without a devfn 0 function. A situation which is also not supported by the common pci_configure_ari() code.
Dispite simply being a mismatch this causes problems as some PCI devices present a different SR-IOV topology depending on PCI_SRIOV_CTRL_ARI.
A similar mismatch may occur with SR-IOV when virtfn_add_bus() creates new busses with no associated struct pci_dev. Here too pci_ari_enabled() on these busses would return false even if ARI is actually used.
Prevent both mismatches by moving the ari_enabled flag from struct pci_dev to struct pci_bus making it independent from struct pci_bus::
self. Let the bus inherit the ari_enabled state from its parent bus when there is no bridge device such that busses added by virtfn_add_bus() match their parent. For s390 set ari_enabled when the device supports ARI in the awareness that all PCIe ports on s390 systems are ARI capable.
--- arch/s390/pci/pci_bus.c | 12 ++++++++++++ drivers/pci/pci.c | 4 ++-- drivers/pci/probe.c | 1 + include/linux/pci.h | 4 ++-- 4 files changed, 17 insertions(+), 4 deletions(-)
arch/s390/pci/pci_bus.c +12 -0
@@ -278,6 +278,18 @@ void pcibios_bus_add_device(struct pci_dev *pdev) {struct zpci_dev *zdev =to_zpci (pdev); +/* +* On s390 PCI busses are virtualized and the bridge +* devices are invisible to the OS. Furthermore busses +* may exist without a devfn 0 function. Thus the normal +* ARI detection does not work. At the same time fw/hw +* has always enabled ARI when possible. Reflect the actual +* state by setting ari_enabled whenever a device on the bus +* supports it. +*/ +if (pci_find_ext_capability (pdev,PCI_EXT_CAP_ID_ARI )) + zdev->zbus->bus->ari_enabled =1 ; +/* * With pdev->no_vf_scan the common PCI probing code does not * perform PF/VF linking.
drivers/pci/pci.c +2 -2
@@ -3537,11 +3537,11 @@ void pci_configure_ari(struct pci_dev *dev)if (pci_find_ext_capability (dev,PCI_EXT_CAP_ID_ARI )) {pcie_capability_set_word (bridge,PCI_EXP_DEVCTL2 ,PCI_EXP_DEVCTL2_ARI ); - bridge->ari_enabled =1 ; + dev->bus->ari_enabled =1 ; }else {pcie_capability_clear_word (bridge,PCI_EXP_DEVCTL2 ,PCI_EXP_DEVCTL2_ARI ); - bridge->ari_enabled =0 ; + dev->bus->ari_enabled =0 ; } }
drivers/pci/probe.c +1 -0
@@ -1143,6 +1143,7 @@ static struct pci_bus *pci_alloc_child_bus(struct pci_bus *parent,if (!bridge) { child->dev.parent = parent->bridge; + child->ari_enabled = parent->ari_enabled; goto add_dev; }
include/linux/pci.h +2 -2
@@ -429,7 +429,6 @@ struct pci_dev { unsigned int irq_reroute_variant:2; /* Needs IRQ rerouting variant */ unsigned int msi_enabled:1; unsigned int msix_enabled:1; - unsigned int ari_enabled:1; /* ARI forwarding */ unsigned int ats_enabled:1; /* Address Translation Svc */ unsigned int pasid_enabled:1; /* Process Address Space ID */ unsigned int pri_enabled:1; /* Page Request Interface */
@@ -679,6 +678,7 @@ struct pci_bus {struct bin_attribute *legacy_mem;/* Legacy mem */ unsigned int is_added:1; unsigned int unsafe_warn:1; /* warned about RW1C config write */ + unsigned int ari_enabled:1; /* ARI forwarding enabled */ };#define to_pci_bus (n) container_of(n, struct pci_bus, dev)
@@ -2637,7 +2637,7 @@ static inline bool pci_is_dev_assigned(struct pci_dev *pdev)*/ static inline bool pci_ari_enabled (struct pci_bus *bus) { -return bus->self && bus->self->ari_enabled; +return bus->ari_enabled; }/**
---
base-commit: 8400291e289ee6b2bf9779ff1c83a291501f017b
change-id: 20240724-ari_no_bus_dev-52b2a27f3466
Best regards,
Signature · 1 line
Niklas Schnelle
Niklas Schnelle
maintainerQuoted 48 lines · Niklas Schnelle
On s390 PCI busses are virtualized and the downstream ports are invisible to the OS and struct
pci_bus::selfis NULL. This associated structpci_devis however relied upon inpci_ari_enabled()to check whether ARI is enabled for the bus. ARI is therefor always detected as disabled.At the same time firmware on s390 always enables and relies upon ARI thus causing a mismatch. Moreover with per-PCI function pass-through there may exist busses with no function with devfn 0. For example a SR-IOV capable device with two PFs may have separate function dependency link chains for each of the PFs and their child VFs. In this case the OS may only see the second PF and its child VFs on a bus without a devfn 0 function. A situation which is also not supported by the common
pci_configure_ari()code.Dispite simply being a mismatch this causes problems as some PCI devices present a different SR-IOV topology depending on
PCI_SRIOV_CTRL_ARI.A similar mismatch may occur with SR-IOV when
virtfn_add_bus()creates new busses with no associated structpci_dev. Here toopci_ari_enabled()on these busses would return false even if ARI is actually used.Prevent both mismatches by moving the
ari_enabledflag from structpci_devto structpci_busmaking it independent from structpci_bus::
self. Let the bus inherit theari_enabledstate from its parent bus when there is no bridge device such that busses added byvirtfn_add_bus()match their parent. For s390 setari_enabledwhen the device supports ARI in the awareness that all PCIe ports on s390 systems are ARI capable.Signed-off-by Niklas Schnelle <[email protected]>--- arch/s390/pci/pci_bus.c | 12 ++++++++++++ drivers/pci/pci.c | 4 ++-- drivers/pci/probe.c | 1 + include/linux/pci.h | 4 ++-- 4 files changed, 17 insertions(+), 4 deletions(-)arch/s390/pci/pci_bus.c +2
-0@@ -278,6 +278,18 @@ void pcibios_bus_add_device(struct pci_dev *pdev) {struct zpci_dev *zdev =to_zpci (pdev); +/* +* On s390 PCI busses are virtualized and the bridge
arch/s390/pci/pci_bus.c void pcibios_bus_add_device(struct pci_dev *pdev) · line 292
Quoted 10 lines
arch/s390/pci/pci_bus.c +10
-0+* devices are invisible to the OS. Furthermore busses +* may exist without a devfn 0 function. Thus the normal +* ARI detection does not work. At the same time fw/hw +* has always enabled ARI when possible. Reflect the actual +* state by setting ari_enabled whenever a device on the bus +* supports it. +*/ +if (pci_find_ext_capability (pdev,PCI_EXT_CAP_ID_ARI )) + zdev->zbus->bus->ari_enabled =1 ; +
@Bjorn unstead of adding the above code to s390 specific code an alternative I considered would be to modify pci_configure_ari() like below. I tested this as well but wasn't sure if it is too much churn especially the handling of the dev->devfn != 0 case. Then again it might be nice to have this in common code.
@@ -3523,12 +3524,18 @@ void pci_configure_ari(struct pci_dev *dev)
u32 cap;
struct pci_dev *bridge;- if (pcie_ari_disabled || !pci_is_pcie(dev) || dev->devfn)
+ if (pcie_ari_disabled || !pci_is_pcie(dev))
+ return;
+
+ if (dev->devfn && !hypervisor_isolated_pci_functions())
return;
bridge = dev->bus->self;
- if (!bridge)
+ if (!bridge) {
+ if (pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ARI))
+ dev->bus->ari_enabled = 1;
return;+ }
pcie_capability_read_dword(bridge, PCI_EXP_DEVCAP2, &cap);
if (!(cap & PCI_EXP_DEVCAP2_ARI))Quoted 72 lines · Niklas Schnelle
Quoted 48 lines · Niklas Schnelle
On s390 PCI busses are virtualized and the downstream ports are invisible to the OS and struct
pci_bus::selfis NULL. This associated structpci_devis however relied upon inpci_ari_enabled()to check whether ARI is enabled for the bus. ARI is therefor always detected as disabled.At the same time firmware on s390 always enables and relies upon ARI thus causing a mismatch. Moreover with per-PCI function pass-through there may exist busses with no function with devfn 0. For example a SR-IOV capable device with two PFs may have separate function dependency link chains for each of the PFs and their child VFs. In this case the OS may only see the second PF and its child VFs on a bus without a devfn 0 function. A situation which is also not supported by the common
pci_configure_ari()code.Dispite simply being a mismatch this causes problems as some PCI devices present a different SR-IOV topology depending on
PCI_SRIOV_CTRL_ARI.A similar mismatch may occur with SR-IOV when
virtfn_add_bus()creates new busses with no associated structpci_dev. Here toopci_ari_enabled()on these busses would return false even if ARI is actually used.Prevent both mismatches by moving the
ari_enabledflag from structpci_devto structpci_busmaking it independent from structpci_bus::
self. Let the bus inherit theari_enabledstate from its parent bus when there is no bridge device such that busses added byvirtfn_add_bus()match their parent. For s390 setari_enabledwhen the device supports ARI in the awareness that all PCIe ports on s390 systems are ARI capable.Signed-off-by Niklas Schnelle <[email protected]>--- arch/s390/pci/pci_bus.c | 12 ++++++++++++ drivers/pci/pci.c | 4 ++-- drivers/pci/probe.c | 1 + include/linux/pci.h | 4 ++-- 4 files changed, 17 insertions(+), 4 deletions(-)arch/s390/pci/pci_bus.c +2
-0@@ -278,6 +278,18 @@ void pcibios_bus_add_device(struct pci_dev *pdev) {struct zpci_dev *zdev =to_zpci (pdev); +/* +* On s390 PCI busses are virtualized and the bridge arch/s390/pci/pci_bus.c void pcibios_bus_add_device(struct pci_dev *pdev) · line 292
Quoted 10 lines
arch/s390/pci/pci_bus.c +10
-0+* devices are invisible to the OS. Furthermore busses +* may exist without a devfn 0 function. Thus the normal +* ARI detection does not work. At the same time fw/hw +* has always enabled ARI when possible. Reflect the actual +* state by setting ari_enabled whenever a device on the bus +* supports it. +*/ +if (pci_find_ext_capability (pdev,PCI_EXT_CAP_ID_ARI )) + zdev->zbus->bus->ari_enabled =1 ; +@Bjorn unstead of adding the above code to s390 specific code an alternative I considered would be to modify
pci_configure_ari()like below. I tested this as well but wasn't sure if it is too much churn especially the handling of thedev->devfn!= 0 case. Then again it might be nice to have this in common code.(quoted diff) +1
-1@@ -3523,12 +3524,18 @@ void pci_configure_ari(struct pci_dev *dev) u32 cap; struct pci_dev *bridge; - if (pcie_ari_disabled || !pci_is_pcie(dev) || dev->devfn) + if (pcie_ari_disabled || !pci_is_pcie(dev))
Review void pci_configure_ari(struct pci_dev *dev) · line 3536
Quoted 10 lines
(quoted diff) +6
-1+ return; + + if (dev->devfn && !hypervisor_isolated_pci_functions()) return; bridge = dev->bus->self; - if (!bridge) + if (!bridge) { + if (pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ARI)) + dev->bus->ari_enabled = 1;
In the generic case here, how do we know whether the invisible bridge leading here has ARI enabled? If that's known to always be the case for s390, I understand that, but I don't understand the other cases (jailhouse, passthrough, etc).
Quoted 6 lines
(quoted diff) +1
-0return; + } pcie_capability_read_dword(bridge, PCI_EXP_DEVCAP2, &cap); if (!(cap & PCI_EXP_DEVCAP2_ARI))
Niklas Schnelle
maintainerQuoted 32 lines · Bjorn Helgaas
Quoted 31 lines · Niklas Schnelle
Quoted 30 lines · Niklas Schnelle
On s390 PCI busses are virtualized and the downstream ports are invisible to the OS and struct
pci_bus::selfis NULL. This associated structpci_devis however relied upon inpci_ari_enabled()to check whether ARI is enabled for the bus. ARI is therefor always detected as disabled.At the same time firmware on s390 always enables and relies upon ARI thus causing a mismatch. Moreover with per-PCI function pass-through there may exist busses with no function with devfn 0. For example a SR-IOV capable device with two PFs may have separate function dependency link chains for each of the PFs and their child VFs. In this case the OS may only see the second PF and its child VFs on a bus without a devfn 0 function. A situation which is also not supported by the common
pci_configure_ari()code.Dispite simply being a mismatch this causes problems as some PCI devices present a different SR-IOV topology depending on
PCI_SRIOV_CTRL_ARI.A similar mismatch may occur with SR-IOV when
virtfn_add_bus()creates new busses with no associated structpci_dev. Here toopci_ari_enabled()on these busses would return false even if ARI is actually used.Prevent both mismatches by moving the
ari_enabledflag from structpci_devto structpci_busmaking it independent from structpci_bus::
self. Let the bus inherit theari_enabledstate from its parent bus when there is no bridge device such that busses added byvirtfn_add_bus()match their parent. For s390 setari_enabledwhen the device supports ARI in the awareness that all PCIe ports on s390 systems are ARI capable.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Signed-off-by Niklas Schnelle <[email protected]>---
---8<---
Quoted 11 lines
Quoted 11 lines
(quoted diff) +4
-1@@ -3523,12 +3524,18 @@ void pci_configure_ari(struct pci_dev *dev) u32 cap; struct pci_dev *bridge; - if (pcie_ari_disabled || !pci_is_pcie(dev) || dev->devfn) + if (pcie_ari_disabled || !pci_is_pcie(dev)) + return; + + if (dev->devfn && !hypervisor_isolated_pci_functions()) return;
Quoted 10 lines
Review void pci_configure_ari(struct pci_dev *dev) · line 3536
Quoted 5 lines
(quoted diff) +3
-1bridge = dev->bus->self; - if (!bridge) + if (!bridge) { + if (pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ARI)) + dev->bus->ari_enabled = 1;In the generic case here, how do we know whether the invisible bridge leading here has ARI enabled? If that's known to always be the case for s390, I understand that, but I don't understand the other cases (jailhouse, passthrough, etc).
Good point! Yes this is probably not correct if Jailhouse doesn't also guarantee ARI. I guess if we really want the generic solution, and I'm fine with an s390 specific one too, then we would need to add some indication that the invisible bridges support ARI. Honestly I'm not even entirely sure if the bridge is even NULL on jailhouse too. In QEMU/KVM for example I think everyone besides s390 emulates bridges.
Quoted 8 lines
Quoted 7 lines
(quoted diff) +1
-0return; + } pcie_capability_read_dword(bridge, PCI_EXP_DEVCAP2, &cap); if (!(cap & PCI_EXP_DEVCAP2_ARI))