Skip to content

Commit a4438f0

Browse files
committed
PCI/TSM: Report active IDE streams
Given that the platform TSM owns IDE Stream ID allocation, report the active streams via the TSM class device. Establish a symlink from the class device to the PCI endpoint device consuming the stream, named by the Stream ID. Acked-by: Bjorn Helgaas <bhelgaas@google.com> Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com> Reviewed-by: Alexey Kardashevskiy <aik@amd.com> Link: https://patch.msgid.link/20251031212902.2256310-10-dan.j.williams@intel.com Signed-off-by: Dan Williams <dan.j.williams@intel.com>
1 parent 9ddaf9c commit a4438f0

5 files changed

Lines changed: 47 additions & 0 deletions

File tree

Documentation/ABI/testing/sysfs-class-tsm

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,13 @@ Description:
77
signals when the PCI layer is able to support establishment of
88
link encryption and other device-security features coordinated
99
through a platform tsm.
10+
11+
What: /sys/class/tsm/tsmN/streamH.R.E
12+
Contact: linux-pci@vger.kernel.org
13+
Description:
14+
(RO) When a host bridge has established a secure connection via
15+
the platform TSM, symlink appears. The primary function of this
16+
is have a system global review of TSM resource consumption
17+
across host bridges. The link points to the endpoint PCI device
18+
and matches the same link published by the host bridge. See
19+
Documentation/ABI/testing/sysfs-devices-pci-host-bridge.

drivers/pci/ide.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <linux/pci_regs.h>
1212
#include <linux/slab.h>
1313
#include <linux/sysfs.h>
14+
#include <linux/tsm.h>
1415

1516
#include "pci.h"
1617

@@ -261,6 +262,9 @@ void pci_ide_stream_release(struct pci_ide *ide)
261262
if (ide->partner[PCI_IDE_EP].enable)
262263
pci_ide_stream_disable(pdev, ide);
263264

265+
if (ide->tsm_dev)
266+
tsm_ide_stream_unregister(ide);
267+
264268
if (ide->partner[PCI_IDE_RP].setup)
265269
pci_ide_stream_teardown(rp, ide);
266270

drivers/virt/coco/tsm-core.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
55

66
#include <linux/tsm.h>
7+
#include <linux/pci.h>
78
#include <linux/rwsem.h>
89
#include <linux/device.h>
910
#include <linux/module.h>
1011
#include <linux/cleanup.h>
1112
#include <linux/pci-tsm.h>
13+
#include <linux/pci-ide.h>
1214

1315
static struct class *tsm_class;
1416
static DECLARE_RWSEM(tsm_rwsem);
@@ -106,6 +108,32 @@ void tsm_unregister(struct tsm_dev *tsm_dev)
106108
}
107109
EXPORT_SYMBOL_GPL(tsm_unregister);
108110

111+
/* must be invoked between tsm_register / tsm_unregister */
112+
int tsm_ide_stream_register(struct pci_ide *ide)
113+
{
114+
struct pci_dev *pdev = ide->pdev;
115+
struct pci_tsm *tsm = pdev->tsm;
116+
struct tsm_dev *tsm_dev = tsm->tsm_dev;
117+
int rc;
118+
119+
rc = sysfs_create_link(&tsm_dev->dev.kobj, &pdev->dev.kobj, ide->name);
120+
if (rc)
121+
return rc;
122+
123+
ide->tsm_dev = tsm_dev;
124+
return 0;
125+
}
126+
EXPORT_SYMBOL_GPL(tsm_ide_stream_register);
127+
128+
void tsm_ide_stream_unregister(struct pci_ide *ide)
129+
{
130+
struct tsm_dev *tsm_dev = ide->tsm_dev;
131+
132+
ide->tsm_dev = NULL;
133+
sysfs_remove_link(&tsm_dev->dev.kobj, ide->name);
134+
}
135+
EXPORT_SYMBOL_GPL(tsm_ide_stream_unregister);
136+
109137
static void tsm_release(struct device *dev)
110138
{
111139
struct tsm_dev *tsm_dev = container_of(dev, typeof(*tsm_dev), dev);

include/linux/pci-ide.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ struct pci_ide_partner {
5050
* @host_bridge_stream: allocated from host bridge @ide_stream_ida pool
5151
* @stream_id: unique Stream ID (within Partner Port pairing)
5252
* @name: name of the established Selective IDE Stream in sysfs
53+
* @tsm_dev: For TSM established IDE, the TSM device context
5354
*
5455
* Negative @stream_id values indicate "uninitialized" on the
5556
* expectation that with TSM established IDE the TSM owns the stream_id
@@ -61,6 +62,7 @@ struct pci_ide {
6162
u8 host_bridge_stream;
6263
int stream_id;
6364
const char *name;
65+
struct tsm_dev *tsm_dev;
6466
};
6567

6668
void pci_ide_set_nr_streams(struct pci_host_bridge *hb, u16 nr);

include/linux/tsm.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,7 @@ int tsm_report_unregister(const struct tsm_report_ops *ops);
123123
struct tsm_dev *tsm_register(struct device *parent, struct pci_tsm_ops *ops);
124124
void tsm_unregister(struct tsm_dev *tsm_dev);
125125
struct tsm_dev *find_tsm_dev(int id);
126+
struct pci_ide;
127+
int tsm_ide_stream_register(struct pci_ide *ide);
128+
void tsm_ide_stream_unregister(struct pci_ide *ide);
126129
#endif /* __TSM_H */

0 commit comments

Comments
 (0)