Skip to content

Commit 3225f52

Browse files
committed
PCI/TSM: Establish Secure Sessions and Link Encryption
The PCIe 7.0 specification, section 11, defines the Trusted Execution Environment (TEE) Device Interface Security Protocol (TDISP). This protocol definition builds upon Component Measurement and Authentication (CMA), and link Integrity and Data Encryption (IDE). It adds support for assigning devices (PCI physical or virtual function) to a confidential VM such that the assigned device is enabled to access guest private memory protected by technologies like Intel TDX, AMD SEV-SNP, RISCV COVE, or ARM CCA. The "TSM" (TEE Security Manager) is a concept in the TDISP specification of an agent that mediates between a "DSM" (Device Security Manager) and system software in both a VMM and a confidential VM. A VMM uses TSM ABIs to setup link security and assign devices. A confidential VM uses TSM ABIs to transition an assigned device into the TDISP "RUN" state and validate its configuration. From a Linux perspective the TSM abstracts many of the details of TDISP, IDE, and CMA. Some of those details leak through at times, but for the most part TDISP is an internal implementation detail of the TSM. CONFIG_PCI_TSM adds an "authenticated" attribute and "tsm/" subdirectory to pci-sysfs. Consider that the TSM driver may itself be a PCI driver. Userspace can watch for the arrival of a "TSM" device, /sys/class/tsm/tsm0/uevent KOBJ_CHANGE, to know when the PCI core has initialized TSM services. The operations that can be executed against a PCI device are split into two mutually exclusive operation sets, "Link" and "Security" (struct pci_tsm_{link,security}_ops). The "Link" operations manage physical link security properties and communication with the device's Device Security Manager firmware. These are the host side operations in TDISP. The "Security" operations coordinate the security state of the assigned virtual device (TDI). These are the guest side operations in TDISP. Only "link" (Secure Session and physical Link Encryption) operations are defined at this stage. There are placeholders for the device security (Trusted Computing Base entry / exit) operations. The locking allows for multiple devices to be executing commands simultaneously, one outstanding command per-device and an rwsem synchronizes the implementation relative to TSM registration/unregistration events. Thanks to Wu Hao for his work on an early draft of this support. Cc: Lukas Wunner <lukas@wunner.de> Cc: Samuel Ortiz <sameo@rivosinc.com> Acked-by: Bjorn Helgaas <bhelgaas@google.com> Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com> Reviewed-by: Alexey Kardashevskiy <aik@amd.com> Co-developed-by: Xu Yilun <yilun.xu@linux.intel.com> Signed-off-by: Xu Yilun <yilun.xu@linux.intel.com> Link: https://patch.msgid.link/20251031212902.2256310-5-dan.j.williams@intel.com Signed-off-by: Dan Williams <dan.j.williams@intel.com>
1 parent 215afa8 commit 3225f52

18 files changed

Lines changed: 971 additions & 6 deletions

File tree

Documentation/ABI/testing/sysfs-bus-pci

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,3 +621,54 @@ Description:
621621
number extended capability. The file is read only and due to
622622
the possible sensitivity of accessible serial numbers, admin
623623
only.
624+
625+
What: /sys/bus/pci/devices/.../tsm/
626+
Contact: linux-coco@lists.linux.dev
627+
Description:
628+
This directory only appears if a physical device function
629+
supports authentication (PCIe CMA-SPDM), interface security
630+
(PCIe TDISP), and is accepted for secure operation by the
631+
platform TSM driver. This attribute directory appears
632+
dynamically after the platform TSM driver loads. So, only after
633+
the /sys/class/tsm/tsm0 device arrives can tools assume that
634+
devices without a tsm/ attribute directory will never have one;
635+
before that, the security capabilities of the device relative to
636+
the platform TSM are unknown. See
637+
Documentation/ABI/testing/sysfs-class-tsm.
638+
639+
What: /sys/bus/pci/devices/.../tsm/connect
640+
Contact: linux-coco@lists.linux.dev
641+
Description:
642+
(RW) Write the name of a TSM (TEE Security Manager) device from
643+
/sys/class/tsm to this file to establish a connection with the
644+
device. This typically includes an SPDM (DMTF Security
645+
Protocols and Data Models) session over PCIe DOE (Data Object
646+
Exchange) and may also include PCIe IDE (Integrity and Data
647+
Encryption) establishment. Reads from this attribute return the
648+
name of the connected TSM or the empty string if not
649+
connected. A TSM device signals its readiness to accept PCI
650+
connection via a KOBJ_CHANGE event.
651+
652+
What: /sys/bus/pci/devices/.../tsm/disconnect
653+
Contact: linux-coco@lists.linux.dev
654+
Description:
655+
(WO) Write the name of the TSM device that was specified
656+
to 'connect' to teardown the connection.
657+
658+
What: /sys/bus/pci/devices/.../authenticated
659+
Contact: linux-pci@vger.kernel.org
660+
Description:
661+
When the device's tsm/ directory is present device
662+
authentication (PCIe CMA-SPDM) and link encryption (PCIe IDE)
663+
are handled by the platform TSM (TEE Security Manager). When the
664+
tsm/ directory is not present this attribute reflects only the
665+
native CMA-SPDM authentication state with the kernel's
666+
certificate store.
667+
668+
If the attribute is not present, it indicates that
669+
authentication is unsupported by the device, or the TSM has no
670+
available authentication methods for the device.
671+
672+
When present and the tsm/ attribute directory is present, the
673+
authenticated attribute is an alias for the device 'connect'
674+
state. See the 'tsm/connect' attribute for more details.

Documentation/driver-api/pci/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ The Linux PCI driver implementer's API guide
1010

1111
pci
1212
p2pdma
13+
tsm
1314

1415
.. only:: subproject and html
1516

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.. SPDX-License-Identifier: GPL-2.0
2+
.. include:: <isonum.txt>
3+
4+
========================================================
5+
PCI Trusted Execution Environment Security Manager (TSM)
6+
========================================================
7+
8+
Subsystem Interfaces
9+
====================
10+
11+
.. kernel-doc:: include/linux/pci-ide.h
12+
:internal:
13+
14+
.. kernel-doc:: drivers/pci/ide.c
15+
:export:
16+
17+
.. kernel-doc:: include/linux/pci-tsm.h
18+
:internal:
19+
20+
.. kernel-doc:: drivers/pci/tsm.c
21+
:export:

MAINTAINERS

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26118,8 +26118,10 @@ L: linux-coco@lists.linux.dev
2611826118
S: Maintained
2611926119
F: Documentation/ABI/testing/configfs-tsm-report
2612026120
F: Documentation/driver-api/coco/
26121+
F: Documentation/driver-api/pci/tsm.rst
26122+
F: drivers/pci/tsm.c
2612126123
F: drivers/virt/coco/guest/
26122-
F: include/linux/tsm*.h
26124+
F: include/linux/*tsm*.h
2612326125
F: samples/tsm-mr/
2612426126

2612526127
TRUSTED SERVICES TEE DRIVER

drivers/pci/Kconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,21 @@ config PCI_ATS
125125
config PCI_IDE
126126
bool
127127

128+
config PCI_TSM
129+
bool "PCI TSM: Device security protocol support"
130+
select PCI_IDE
131+
select PCI_DOE
132+
select TSM
133+
help
134+
The TEE (Trusted Execution Environment) Device Interface
135+
Security Protocol (TDISP) defines a "TSM" as a platform agent
136+
that manages device authentication, link encryption, link
137+
integrity protection, and assignment of PCI device functions
138+
(virtual or physical) to confidential computing VMs that can
139+
access (DMA) guest private memory.
140+
141+
Enable a platform TSM driver to use this capability.
142+
128143
config PCI_DOE
129144
bool "Enable PCI Data Object Exchange (DOE) support"
130145
help

drivers/pci/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ obj-$(CONFIG_XEN_PCIDEV_FRONTEND) += xen-pcifront.o
3535
obj-$(CONFIG_VGA_ARB) += vgaarb.o
3636
obj-$(CONFIG_PCI_DOE) += doe.o
3737
obj-$(CONFIG_PCI_IDE) += ide.o
38+
obj-$(CONFIG_PCI_TSM) += tsm.o
3839
obj-$(CONFIG_PCI_DYNAMIC_OF_NODES) += of_property.o
3940
obj-$(CONFIG_PCI_NPEM) += npem.o
4041
obj-$(CONFIG_PCIE_TPH) += tph.o

drivers/pci/doe.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424

2525
#include "pci.h"
2626

27-
#define PCI_DOE_FEATURE_DISCOVERY 0
28-
2927
/* Timeout of 1 second from 6.30.2 Operation, PCI Spec r6.0 */
3028
#define PCI_DOE_TIMEOUT HZ
3129
#define PCI_DOE_POLL_INTERVAL (PCI_DOE_TIMEOUT / 128)

drivers/pci/pci-sysfs.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1868,6 +1868,10 @@ const struct attribute_group *pci_dev_attr_groups[] = {
18681868
#endif
18691869
#ifdef CONFIG_PCI_DOE
18701870
&pci_doe_sysfs_group,
1871+
#endif
1872+
#ifdef CONFIG_PCI_TSM
1873+
&pci_tsm_auth_attr_group,
1874+
&pci_tsm_attr_group,
18711875
#endif
18721876
NULL,
18731877
};

drivers/pci/pci.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,16 @@ void pci_ide_init(struct pci_dev *dev);
619619
static inline void pci_ide_init(struct pci_dev *dev) { }
620620
#endif
621621

622+
#ifdef CONFIG_PCI_TSM
623+
void pci_tsm_init(struct pci_dev *pdev);
624+
void pci_tsm_destroy(struct pci_dev *pdev);
625+
extern const struct attribute_group pci_tsm_attr_group;
626+
extern const struct attribute_group pci_tsm_auth_attr_group;
627+
#else
628+
static inline void pci_tsm_init(struct pci_dev *pdev) { }
629+
static inline void pci_tsm_destroy(struct pci_dev *pdev) { }
630+
#endif
631+
622632
/**
623633
* pci_dev_set_io_state - Set the new error state if possible.
624634
*

drivers/pci/probe.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2763,6 +2763,9 @@ void pci_device_add(struct pci_dev *dev, struct pci_bus *bus)
27632763
ret = device_add(&dev->dev);
27642764
WARN_ON(ret < 0);
27652765

2766+
/* Establish pdev->tsm for newly added (e.g. new SR-IOV VFs) */
2767+
pci_tsm_init(dev);
2768+
27662769
pci_npem_create(dev);
27672770

27682771
pci_doe_sysfs_init(dev);

0 commit comments

Comments
 (0)