Alexey Kardashevskiy wrote: > On 6/12/24 09:24, Dan Williams wrote: > > The limited number of link-encryption (IDE) streams that a given set of > > host-bridges supports is a platform specific detail. Provide > > pci_set_nr_ide_streams() as a generic facility for either platform TSM > > drivers, or in the future PCI core native IDE, to report the number > > available streams. After invoking pci_set_nr_ide_streams() an > > "available_secure_streams" attribute appears in PCI Host Bridge sysfs to > > convey how many streams are available for IDE establishment. > > > > Cc: Bjorn Helgaas <bhelgaas@xxxxxxxxxx> > > Cc: Lukas Wunner <lukas@xxxxxxxxx> > > Cc: Samuel Ortiz <sameo@xxxxxxxxxxxx> > > Cc: Alexey Kardashevskiy <aik@xxxxxxx> > > Cc: Xu Yilun <yilun.xu@xxxxxxxxxxxxxxx> > > Signed-off-by: Dan Williams <dan.j.williams@xxxxxxxxx> > > --- > > .../ABI/testing/sysfs-devices-pci-host-bridge | 11 +++++ > > drivers/pci/ide.c | 46 ++++++++++++++++++++ > > drivers/pci/pci.h | 3 + > > drivers/pci/probe.c | 11 ++++- > > include/linux/pci.h | 9 ++++ > > 5 files changed, 79 insertions(+), 1 deletion(-) > > > > diff --git a/Documentation/ABI/testing/sysfs-devices-pci-host-bridge b/Documentation/ABI/testing/sysfs-devices-pci-host-bridge > > index 15dafb46b176..1a3249f20e48 100644 > > --- a/Documentation/ABI/testing/sysfs-devices-pci-host-bridge > > +++ b/Documentation/ABI/testing/sysfs-devices-pci-host-bridge > > @@ -26,3 +26,14 @@ Description: > > streams can be returned to the available secure streams pool by > > invoking the tsm/disconnect flow. The link points to the > > endpoint PCI device at domain:DDDDD bus:BB device:DD function:F. > > + > > +What: pciDDDDD:BB/available_secure_streams > > +Date: December, 2024 > > +Contact: linux-pci@xxxxxxxxxxxxxxx > > +Description: > > + (RO) When a host-bridge has root ports that support PCIe IDE > > + (link encryption and integrity protection) there may be a > > + limited number of streams that can be used for establishing new > > + secure links. This attribute decrements upon secure link setup, > > + and increments upon secure link teardown. The in-use stream > > + count is determined by counting stream symlinks. > > diff --git a/drivers/pci/ide.c b/drivers/pci/ide.c > > index c37f35f0d2c0..0abc19b341ab 100644 > > --- a/drivers/pci/ide.c > > +++ b/drivers/pci/ide.c > > @@ -75,8 +75,54 @@ void pci_ide_init(struct pci_dev *pdev) > > pdev->nr_ide_mem = nr_ide_mem; > > } > > > > +static ssize_t available_secure_streams_show(struct device *dev, > > + struct device_attribute *attr, > > + char *buf) > > +{ > > + struct pci_host_bridge *hb = to_pci_host_bridge(dev); > > + int avail; > > + > > + if (hb->nr_ide_streams < 0) > > + return -ENXIO; > > + > > + avail = hb->nr_ide_streams - > > + bitmap_weight(hb->ide_stream_ids, PCI_IDE_SEL_CTL_ID_MAX + 1); > > + return sysfs_emit(buf, "%d\n", avail); > > +} > > +static DEVICE_ATTR_RO(available_secure_streams); > > + > > +static struct attribute *pci_ide_attrs[] = { > > + &dev_attr_available_secure_streams.attr, > > + NULL, > > +}; > > + > > +static umode_t pci_ide_attr_visible(struct kobject *kobj, struct attribute *a, int n) > > +{ > > + struct device *dev = kobj_to_dev(kobj); > > + struct pci_host_bridge *hb = to_pci_host_bridge(dev); > > + > > + if (a == &dev_attr_available_secure_streams.attr) > > + if (hb->nr_ide_streams < 0) > > + return 0; > > + > > + return a->mode; > > +} > > + > > +struct attribute_group pci_ide_attr_group = { > > + .attrs = pci_ide_attrs, > > + .is_visible = pci_ide_attr_visible, > > +}; > > + > > +void pci_set_nr_ide_streams(struct pci_host_bridge *hb, int nr) > > +{ > > + hb->nr_ide_streams = nr; > > + sysfs_update_group(&hb->dev.kobj, &pci_ide_attr_group); > > +} > > +EXPORT_SYMBOL_NS_GPL(pci_set_nr_ide_streams, PCI_IDE); > > PCI_IDE needs quotes but somehow it was compiling for months until I > rebased onto v6.14. Oh, interesting, will fix that up when sending v2 based on v6.14-rc. > Hm. Also probably all exports should be PCI_IDE NS, > or none. Thanks, I will add a comment for why this one is namespaced and the others are not. I am also renaming it to pci_ide_init_nr_streams() to reflect this detail: /** * pci_init_nr_ide_streams() - size the pool of IDE Stream resources * @hb: host bridge boundary for the stream pool * @nr: number of streams * * Enable IDE Stream establishment by setting the number of stream * resources available at the host bridge. Platform init code must set * this before the first pci_ide_stream_alloc() call. * * The "PCI_IDE" symbol namespace is required because this is typically * a detail that is settled in early PCI init, i.e. only an expert or * test module should consume this export. */