@@ -599,6 +599,13 @@ int pcibios_device_add(struct pci_dev *pdev)
continue;
pci_claim_resource(pdev, i);
}
+ /*
+ * The below is the s390 equivalent of pci_configure_ari()
+ * which we can't use directly because the bridge devices
+ * are hidden in firmware.
+ */
+ if (!pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_ARI))
+ zdev->zbus->bus->ari_enabled = 0;
return 0;
}
@@ -208,6 +208,16 @@ static int zpci_bus_create_pci_bus(struct zpci_bus *zbus, struct zpci_dev *fr, s
return -EFAULT;
}
+ /*
+ * 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.
+ */
+ bus->ari_enabled = 1;
zbus->bus = bus;
return 0;
@@ -3571,11 +3571,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;
}
}
@@ -1198,6 +1198,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;
}
@@ -439,7 +439,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 */
@@ -684,6 +683,7 @@ struct pci_bus {
unsigned int is_added:1;
unsigned int unsafe_warn:1; /* warned about RW1C config write */
unsigned int flit_mode:1; /* Link in Flit mode */
+ unsigned int ari_enabled:1; /* ARI forwarding enabled */
};
#define to_pci_bus(n) container_of(n, struct pci_bus, dev)
@@ -2663,7 +2663,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;
}
/**
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. Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com> --- Changes in v3: - Move setting of ari_enabled on s390 to bus creation and clear it in pcibios_add_device() if the capability is not available. - Rebase on v6.15-rc2 - Link to v2: https://lore.kernel.org/r/20240918-ari_no_bus_dev-v2-1-83cfa991082f@linux.ibm.com Changes in v2: - Rebased on v6.11 - Link to v1: https://lore.kernel.org/r/20240730-ari_no_bus_dev-v1-1-7de17676f9fe@linux.ibm.com --- arch/s390/pci/pci.c | 7 +++++++ arch/s390/pci/pci_bus.c | 10 ++++++++++ drivers/pci/pci.c | 4 ++-- drivers/pci/probe.c | 1 + include/linux/pci.h | 4 ++-- 5 files changed, 22 insertions(+), 4 deletions(-) --- base-commit: 8ffd015db85fea3e15a77027fda6c02ced4d2444 change-id: 20240724-ari_no_bus_dev-52b2a27f3466 Best regards,