Skip to content

Commit 249872f

Browse files
committed
Merge tag 'tsm-for-6.19' of git://git.kernel.org/pub/scm/linux/kernel/git/devsec/tsm
Pull PCIe Link Encryption and Device Authentication from Dan Williams: "New PCI infrastructure and one architecture implementation for PCIe link encryption establishment via platform firmware services. This work is the result of multiple vendors coming to consensus on some core infrastructure (thanks Alexey, Yilun, and Aneesh!), and three vendor implementations, although only one is included in this pull. The PCI core changes have an ack from Bjorn, the crypto/ccp/ changes have an ack from Tom, and the iommu/amd/ changes have an ack from Joerg. PCIe link encryption is made possible by the soup of acronyms mentioned in the shortlog below. Link Integrity and Data Encryption (IDE) is a protocol for installing keys in the transmitter and receiver at each end of a link. That protocol is transported over Data Object Exchange (DOE) mailboxes using PCI configuration requests. The aspect that makes this a "platform firmware service" is that the key provisioning and protocol is coordinated through a Trusted Execution Envrionment (TEE) Security Manager (TSM). That is either firmware running in a coprocessor (AMD SEV-TIO), or quasi-hypervisor software (Intel TDX Connect / ARM CCA) running in a protected CPU mode. Now, the only reason to ask a TSM to run this protocol and install the keys rather than have a Linux driver do the same is so that later, a confidential VM can ask the TSM directly "can you certify this device?". That precludes host Linux from provisioning its own keys, because host Linux is outside the trust domain for the VM. It also turns out that all architectures, save for one, do not publish a mechanism for an OS to establish keys in the root port. So "TSM-established link encryption" is the only cross-architecture path for this capability for the foreseeable future. This unblocks the other arch implementations to follow in v6.20/v7.0, once they clear some other dependencies, and it unblocks the next phase of work to implement the end-to-end flow of confidential device assignment. The PCIe specification calls this end-to-end flow Trusted Execution Environment (TEE) Device Interface Security Protocol (TDISP). In the meantime, Linux gets a link encryption facility which has practical benefits along the same lines as memory encryption. It authenticates devices via certificates and may protect against interposer attacks trying to capture clear-text PCIe traffic. Summary: - Introduce the PCI/TSM core for the coordination of device authentication, link encryption and establishment (IDE), and later management of the device security operational states (TDISP). Notify the new TSM core layer of PCI device arrival and departure - Add a low level TSM driver for the link encryption establishment capabilities of the AMD SEV-TIO architecture - Add a library of helpers TSM drivers to use for IDE establishment and the DOE transport - Add skeleton support for 'bind' and 'guest_request' operations in support of TDISP" * tag 'tsm-for-6.19' of git://git.kernel.org/pub/scm/linux/kernel/git/devsec/tsm: (23 commits) crypto/ccp: Fix CONFIG_PCI=n build virt: Fix Kconfig warning when selecting TSM without VIRT_DRIVERS crypto/ccp: Implement SEV-TIO PCIe IDE (phase1) iommu/amd: Report SEV-TIO support psp-sev: Assign numbers to all status codes and add new ccp: Make snp_reclaim_pages and __sev_do_cmd_locked public PCI/TSM: Add 'dsm' and 'bound' attributes for dependent functions PCI/TSM: Add pci_tsm_guest_req() for managing TDIs PCI/TSM: Add pci_tsm_bind() helper for instantiating TDIs PCI/IDE: Initialize an ID for all IDE streams PCI/IDE: Add Address Association Register setup for downstream MMIO resource: Introduce resource_assigned() for discerning active resources PCI/TSM: Drop stub for pci_tsm_doe_transfer() drivers/virt: Drop VIRT_DRIVERS build dependency PCI/TSM: Report active IDE streams PCI/IDE: Report available IDE streams PCI/IDE: Add IDE establishment helpers PCI: Establish document for PCI host bridge sysfs attributes PCI: Add PCIe Device 3 Extended Capability enumeration PCI/TSM: Establish Secure Sessions and Link Encryption ...
2 parents fbff949 + 7dfbe9a commit 249872f

43 files changed

Lines changed: 4326 additions & 52 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Documentation/ABI/testing/sysfs-bus-pci

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,3 +621,84 @@ 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/.../tsm/dsm
659+
Contact: linux-coco@lists.linux.dev
660+
Description: (RO) Return PCI device name of this device's DSM (Device
661+
Security Manager). When a device is in the connected state it
662+
indicates that the platform TSM (TEE Security Manager) has made
663+
a secure-session connection with a device's DSM. A DSM is always
664+
physical function 0 and when the device supports TDISP (TEE
665+
Device Interface Security Protocol) its managed functions also
666+
populate this tsm/dsm attribute. The managed functions of a DSM
667+
are SR-IOV (Single Root I/O Virtualization) virtual functions,
668+
non-zero functions of a multi-function device, or downstream
669+
endpoints depending on whether the DSM is an SR-IOV physical
670+
function, function0 of a multi-function device, or an upstream
671+
PCIe switch port. This is a "link" TSM attribute, see
672+
Documentation/ABI/testing/sysfs-class-tsm.
673+
674+
What: /sys/bus/pci/devices/.../tsm/bound
675+
Contact: linux-coco@lists.linux.dev
676+
Description: (RO) Return the device name of the TSM when the device is in a
677+
TDISP (TEE Device Interface Security Protocol) operational state
678+
(LOCKED, RUN, or ERROR, not UNLOCKED). Bound devices consume
679+
platform TSM resources and depend on the device's configuration
680+
(e.g. BME (Bus Master Enable) and MSE (Memory Space Enable)
681+
among other settings) to remain stable for the duration of the
682+
bound state. This attribute is only visible for devices that
683+
support TDISP operation, and it is only populated after
684+
successful connect and TSM bind. The TSM bind operation is
685+
initiated by VFIO/IOMMUFD. This is a "link" TSM attribute, see
686+
Documentation/ABI/testing/sysfs-class-tsm.
687+
688+
What: /sys/bus/pci/devices/.../authenticated
689+
Contact: linux-pci@vger.kernel.org
690+
Description:
691+
When the device's tsm/ directory is present device
692+
authentication (PCIe CMA-SPDM) and link encryption (PCIe IDE)
693+
are handled by the platform TSM (TEE Security Manager). When the
694+
tsm/ directory is not present this attribute reflects only the
695+
native CMA-SPDM authentication state with the kernel's
696+
certificate store.
697+
698+
If the attribute is not present, it indicates that
699+
authentication is unsupported by the device, or the TSM has no
700+
available authentication methods for the device.
701+
702+
When present and the tsm/ attribute directory is present, the
703+
authenticated attribute is an alias for the device 'connect'
704+
state. See the 'tsm/connect' attribute for more details.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
What: /sys/class/tsm/tsmN
2+
Contact: linux-coco@lists.linux.dev
3+
Description:
4+
"tsmN" is a device that represents the generic attributes of a
5+
platform TEE Security Manager. It is typically a child of a
6+
platform enumerated TSM device. /sys/class/tsm/tsmN/uevent
7+
signals when the PCI layer is able to support establishment of
8+
link encryption and other device-security features coordinated
9+
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.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
What: /sys/devices/pciDDDD:BB
2+
/sys/devices/.../pciDDDD:BB
3+
Contact: linux-pci@vger.kernel.org
4+
Description:
5+
A PCI host bridge device parents a PCI bus device topology. PCI
6+
controllers may also parent host bridges. The DDDD:BB format
7+
conveys the PCI domain (ACPI segment) number and root bus number
8+
(in hexadecimal) of the host bridge. Note that the domain number
9+
may be larger than the 16-bits that the "DDDD" format implies
10+
for emulated host-bridges.
11+
12+
What: pciDDDD:BB/firmware_node
13+
Contact: linux-pci@vger.kernel.org
14+
Description:
15+
(RO) Symlink to the platform firmware device object "companion"
16+
of the host bridge. For example, an ACPI device with an _HID of
17+
PNP0A08 (/sys/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0A08:00). See
18+
/sys/devices/pciDDDD:BB entry for details about the DDDD:BB
19+
format.
20+
21+
What: pciDDDD:BB/streamH.R.E
22+
Contact: linux-pci@vger.kernel.org
23+
Description:
24+
(RO) When a platform has established a secure connection, PCIe
25+
IDE, between two Partner Ports, this symlink appears. A stream
26+
consumes a Stream ID slot in each of the Host bridge (H), Root
27+
Port (R) and Endpoint (E). The link points to the Endpoint PCI
28+
device in the Selective IDE Stream pairing. Specifically, "R"
29+
and "E" represent the assigned Selective IDE Stream Register
30+
Block in the Root Port and Endpoint, and "H" represents a
31+
platform specific pool of stream resources shared by the Root
32+
Ports in a host bridge. See /sys/devices/pciDDDD:BB entry for
33+
details about the DDDD:BB format.
34+
35+
What: pciDDDD:BB/available_secure_streams
36+
Contact: linux-pci@vger.kernel.org
37+
Description:
38+
(RO) When a host bridge has Root Ports that support PCIe IDE
39+
(link encryption and integrity protection) there may be a
40+
limited number of Selective IDE Streams that can be used for
41+
establishing new end-to-end secure links. This attribute
42+
decrements upon secure link setup, and increments upon secure
43+
link teardown. The in-use stream count is determined by counting
44+
stream symlinks. See /sys/devices/pciDDDD:BB entry for details
45+
about the DDDD:BB format.

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: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20093,6 +20093,7 @@ Q: https://patchwork.kernel.org/project/linux-pci/list/
2009320093
B: https://bugzilla.kernel.org
2009420094
C: irc://irc.oftc.net/linux-pci
2009520095
T: git git://git.kernel.org/pub/scm/linux/kernel/git/pci/pci.git
20096+
F: Documentation/ABI/testing/sysfs-devices-pci-host-bridge
2009620097
F: Documentation/PCI/
2009720098
F: Documentation/devicetree/bindings/pci/
2009820099
F: arch/x86/kernel/early-quirks.c
@@ -26392,14 +26393,16 @@ M: David Lechner <dlechner@baylibre.com>
2639226393
S: Maintained
2639326394
F: Documentation/devicetree/bindings/trigger-source/*
2639426395

26395-
TRUSTED SECURITY MODULE (TSM) INFRASTRUCTURE
26396+
TRUSTED EXECUTION ENVIRONMENT SECURITY MANAGER (TSM)
2639626397
M: Dan Williams <dan.j.williams@intel.com>
2639726398
L: linux-coco@lists.linux.dev
2639826399
S: Maintained
2639926400
F: Documentation/ABI/testing/configfs-tsm-report
2640026401
F: Documentation/driver-api/coco/
26402+
F: Documentation/driver-api/pci/tsm.rst
26403+
F: drivers/pci/tsm.c
2640126404
F: drivers/virt/coco/guest/
26402-
F: include/linux/tsm*.h
26405+
F: include/linux/*tsm*.h
2640326406
F: samples/tsm-mr/
2640426407

2640526408
TRUSTED SERVICES TEE DRIVER

drivers/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ obj-$(CONFIG_RPMSG) += rpmsg/
160160
obj-$(CONFIG_SOUNDWIRE) += soundwire/
161161

162162
# Virtualization drivers
163-
obj-$(CONFIG_VIRT_DRIVERS) += virt/
163+
obj-y += virt/
164164
obj-$(CONFIG_HYPERV) += hv/
165165

166166
obj-$(CONFIG_PM_DEVFREQ) += devfreq/

drivers/base/bus.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,19 @@ static struct device *next_device(struct klist_iter *i)
334334
return dev;
335335
}
336336

337+
static struct device *prev_device(struct klist_iter *i)
338+
{
339+
struct klist_node *n = klist_prev(i);
340+
struct device *dev = NULL;
341+
struct device_private *dev_prv;
342+
343+
if (n) {
344+
dev_prv = to_device_private_bus(n);
345+
dev = dev_prv->device;
346+
}
347+
return dev;
348+
}
349+
337350
/**
338351
* bus_for_each_dev - device iterator.
339352
* @bus: bus type.
@@ -414,6 +427,31 @@ struct device *bus_find_device(const struct bus_type *bus,
414427
}
415428
EXPORT_SYMBOL_GPL(bus_find_device);
416429

430+
struct device *bus_find_device_reverse(const struct bus_type *bus,
431+
struct device *start, const void *data,
432+
device_match_t match)
433+
{
434+
struct subsys_private *sp = bus_to_subsys(bus);
435+
struct klist_iter i;
436+
struct device *dev;
437+
438+
if (!sp)
439+
return NULL;
440+
441+
klist_iter_init_node(&sp->klist_devices, &i,
442+
(start ? &start->p->knode_bus : NULL));
443+
while ((dev = prev_device(&i))) {
444+
if (match(dev, data)) {
445+
get_device(dev);
446+
break;
447+
}
448+
}
449+
klist_iter_exit(&i);
450+
subsys_put(sp);
451+
return dev;
452+
}
453+
EXPORT_SYMBOL_GPL(bus_find_device_reverse);
454+
417455
static struct device_driver *next_driver(struct klist_iter *i)
418456
{
419457
struct klist_node *n = klist_next(i);

drivers/crypto/ccp/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ config CRYPTO_DEV_SP_PSP
3939
bool "Platform Security Processor (PSP) device"
4040
default y
4141
depends on CRYPTO_DEV_CCP_DD && X86_64 && AMD_IOMMU
42+
select PCI_TSM if PCI
4243
help
4344
Provide support for the AMD Platform Security Processor (PSP).
4445
The PSP is a dedicated processor that provides support for key

drivers/crypto/ccp/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ ccp-$(CONFIG_CRYPTO_DEV_SP_PSP) += psp-dev.o \
1616
hsti.o \
1717
sfs.o
1818

19+
ifeq ($(CONFIG_PCI_TSM),y)
20+
ccp-$(CONFIG_CRYPTO_DEV_SP_PSP) += sev-dev-tsm.o sev-dev-tio.o
21+
endif
22+
1923
obj-$(CONFIG_CRYPTO_DEV_CCP_CRYPTO) += ccp-crypto.o
2024
ccp-crypto-objs := ccp-crypto-main.o \
2125
ccp-crypto-aes.o \

0 commit comments

Comments
 (0)