PCI/TSM: Finalize "Link" TSM infrastructure
Subsystems (2)
v2 cover PCI/TSM: Finalize "Link" TSM infrastructure
Changes since v1 [1]:
- Fix build error reported for the commits in linux-next ([email protected])
- Clarify how TSM drivers can accept / modify default the @mem_assoc and @pref_assoc settings (Jonathan)
- Drop the pci_tsm_doe_transfer() stub (Yilun)
- Simple cleanups of reserve_stream_idx() and reserve_stream_id() (Jonathan)
- Rename alloc_stream_id() to request_stream_id() (Jonathan)
- Simplify conditional in pci_tsm_bind() (Jonathan)
- Reflow whitespace and spelling fixes (Jonathan)
[1]: http://lore.kernel.org/[email protected]
Now that the base series has settled [2], here is a collection of topics to finish off the "Link" side of the PCI/TSM core. Recall that "Link" refers to all the physical device security aspects of TEE Device Interface Security Protocol (TDISP) managed by the host kernel / VMM.
[2]: http://lore.kernel.org/[email protected]
Add support for Address Association registers that helps root port hardware pick the Selective IDE Stream to use for a downstream memory transaction.
Add support for devices that expect to have all Stream IDs on the device configured to unique values even if the given stream is not in use.
Add an operation for requesting a device enter the LOCKED TDISP state (pci_tsm_bind())). This has no user outside of test code in the staging tree [3] for now, but examples exist in the SEV-TIO and ARM CCA RFC branches.
Add an operation for marshaling TDISP collateral and TDISP state change requests from confidential guests to the platform TSM (pci_tsm_guest_req()). This too has no consumer in the staging branch outside of the samples/devsec/ test module, but is used in the vendor RFC branches that will soon be incorporated into the staging branch.
These patches have previously appeared in the tsm.git#staging branch [4] for integration testing.
[3]: https://git.kernel.org/pub/scm/linux/kernel/git/devsec/tsm.git/tree/samples/devsec/link_tsm.c?h=staging#n306
[4]: https://git.kernel.org/pub/scm/linux/kernel/git/devsec/tsm.git/log/?h=staging
Dan Williams (7):
drivers/virt: Drop VIRT_DRIVERS build dependency PCI/TSM: Drop stub for pci_tsm_doe_transfer()
resource: Introduce resource_assigned() for discerning active
resources
PCI/IDE: Initialize an ID for all IDE streams
PCI/TSM: Add pci_tsm_bind() helper for instantiating TDIs PCI/TSM: Add pci_tsm_guest_req() for managing TDIs PCI/TSM: Add 'dsm' and 'bound' attributes for dependent functions
Xu Yilun (1):
PCI/IDE: Add Address Association Register setup for downstream MMIO
drivers/Makefile | 2 +- Documentation/ABI/testing/sysfs-bus-pci | 30 +++ drivers/pci/pci.h | 2 + include/linux/ioport.h | 9 + include/linux/pci-ide.h | 38 +++ include/linux/pci-tsm.h | 92 +++++++- include/linux/pci.h | 6 + drivers/pci/ide.c | 244 ++++++++++++++++++- drivers/pci/remove.c | 1 + drivers/pci/tsm.c | 299 ++++++++++++++++++++++-- 10 files changed, 689 insertions(+), 34 deletions(-)
base-commit: a4438f06b1db15ce3d831ce82b8767665638aa2a
Signature · 1 line
2.51.1
PATCH v2 1/8 drivers/virt: Drop VIRT_DRIVERS build dependency
All of the objects in drivers/virt/ have their own configuration symbols to gate compilation. I.e. nothing gets added to the kernel with CONFIG_VIRT_DRIVERS=y in isolation.
Unconditionally descend into drivers/virt/ so that consumers do not need to add an additional CONFIG_VIRT_DRIVERS dependency.
Fix warnings of the form:
Kconfig warnings: (for reference only)
WARNING: unmet direct dependencies detected for TSM Depends on [n]: VIRT_DRIVERS [=n]
Selected by [y]:
- PCI_TSM [=y] && PCI [=y]
...where PCI_TSM selects CONFIG_TSM, but fails to select CONFIG_VIRT_DRIVERS.
--- drivers/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/Makefile +1 -1
@@ -160,7 +160,7 @@ obj-$(CONFIG_RPMSG) += rpmsg/ obj-$(CONFIG_SOUNDWIRE) += soundwire/ # Virtualization drivers -obj-$(CONFIG_VIRT_DRIVERS) += virt/ +obj-y += virt/ obj-$(CONFIG_HYPERV) += hv/ obj-$(CONFIG_PM_DEVFREQ) += devfreq/
Signature · 1 line
2.51.1
Re: [PATCH v2 1/8] drivers/virt: Drop VIRT_DRIVERS build dependency
Quoted 15 lines · On Wed, 12 Nov 2025 18:14:39 -0800 Dan Williams <[email protected]>…
All of the objects in
drivers/virt/have their own configuration symbols to gate compilation. I.e. nothing gets added to the kernel withCONFIG_VIRT_DRIVERS=yin isolation.Unconditionally descend into
drivers/virt/so that consumers do not need to add an additionalCONFIG_VIRT_DRIVERSdependency.Fix warnings of the form:
Kconfigwarnings: (for reference only)
WARNING: unmet direct dependencies detected for TSM Depends on [n]:VIRT_DRIVERS[=n]
Selected by [y]:
-PCI_TSM[=y] && PCI [=y]
Quoted 6 lines
...where
PCI_TSMselectsCONFIG_TSM, but fails to selectCONFIG_VIRT_DRIVERS.Reported-by kernel test robot <[email protected]>Signed-off-by Dan Williams <[email protected]>
Seems reasonable to me.
Re: [PATCH v2 1/8] drivers/virt: Drop VIRT_DRIVERS build dependency
In reply to Dan WilliamsHi Dan,
Quoted 7 lines · Dan Williams
All of the objects in
drivers/virt/have their own configuration symbols to gate compilation. I.e. nothing gets added to the kernel withCONFIG_VIRT_DRIVERS=yin isolation.Unconditionally descend into
drivers/virt/so that consumers do not need to add an additionalCONFIG_VIRT_DRIVERSdependency.
Quoted 7 lines
Fix warnings of the form:
Kconfigwarnings: (for reference only)
WARNING: unmet direct dependencies detected for TSM Depends on [n]:VIRT_DRIVERS[=n]
Selected by [y]:
-PCI_TSM[=y] && PCI [=y]
I can still trigger this warning on next-20251202, which contains this change as commit 110c155e8a68 ("drivers/virt: Drop VIRT_DRIVERS build dependency").
$ git merge-base --is-ancestor 110c155e8a684d8b2423a72cfde147903881f765 HEAD
echo $status
0$ make -skj"$(nproc)" ARCH=arm64 CROSS_COMPILE=aarch64-linux- clean defconfig
$ scripts/config -e PCI_TSM
$ make -skj"$(nproc)" ARCH=arm64 CROSS_COMPILE=aarch64-linux- olddefconfig
WARNING: unmet direct dependencies detected for TSM
Depends on [n]: VIRT_DRIVERS [=n]
Selected by [y]:
- PCI_TSM [=y] && PCI [=y]I would think you would need something like this avoid the problem but I am not sure if it would be acceptable, hence just the report.
Cheers,
Nathan
drivers/virt/Kconfig +2 -2
@@ -47,6 +47,6 @@ source "drivers/virt/nitro_enclaves/Kconfig" source "drivers/virt/acrn/Kconfig" -source "drivers/virt/coco/Kconfig" - endif + +source "drivers/virt/coco/Kconfig"
drivers/virt/coco/Kconfig +2 -0
@@ -3,6 +3,7 @@ # Confidential computing related collateral # +if VIRT_DRIVERS source "drivers/virt/coco/efi_secret/Kconfig" source "drivers/virt/coco/pkvm-guest/Kconfig"
@@ -14,6 +15,7 @@ source "drivers/virt/coco/tdx-guest/Kconfig" source "drivers/virt/coco/arm-cca-guest/Kconfig" source "drivers/virt/coco/guest/Kconfig" +endif config TSM bool
Re: [PATCH v2 1/8] drivers/virt: Drop VIRT_DRIVERS build dependency
Quoted 30 lines · Nathan Chancellor
Hi Dan,
Quoted 7 lines · Dan Williams
All of the objects in
drivers/virt/have their own configuration symbols to gate compilation. I.e. nothing gets added to the kernel withCONFIG_VIRT_DRIVERS=yin isolation.Unconditionally descend into
drivers/virt/so that consumers do not need to add an additionalCONFIG_VIRT_DRIVERSdependency.Quoted 7 lines
Fix warnings of the form:
Kconfigwarnings: (for reference only)
WARNING: unmet direct dependencies detected for TSM Depends on [n]:VIRT_DRIVERS[=n]
Selected by [y]:
-PCI_TSM[=y] && PCI [=y]I can still trigger this warning on next-20251202, which contains this change as commit
110c155e8a68("drivers/virt: DropVIRT_DRIVERSbuild dependency").$ git merge-base --is-ancestor 110c155e8a684d8b2423a72cfde147903881f765 HEAD echo $status 0$ make -skj"$(nproc)" ARCH=arm64 CROSS_COMPILE=aarch64-linux- clean defconfig$ scripts/config -e PCI_TSM
Quoted 8 lines
$ make -skj"$(nproc)" ARCH=arm64 CROSS_COMPILE=aarch64-linux- olddefconfig WARNING: unmet direct dependencies detected for TSM Depends on [n]: VIRT_DRIVERS [=n] Selected by [y]: - PCI_TSM [=y] && PCI [=y]I would think you would need something like this avoid the problem but I am not sure if it would be acceptable, hence just the report.
Oh, yes, thanks for that. It turns out I fixed the compilation problem associated with this report [1].
ld: drivers/pci/ide.o: in function `pci_ide_stream_release':
ide.c:(.text+0xffb): undefined reference to `tsm_ide_stream_unregister'
ld: drivers/pci/tsm.o: in function `connect_store':
tsm.c:(.text+0x1d42): undefined reference to `find_tsm_dev'
I missed that the report I ended up quoting [2] was only about the Kconfig problem not the build error.
[1]: http://lore.kernel.org/[email protected]
[2]: http://lore.kernel.org/[email protected]
Quoted 29 lines
Cheers,
Nathandrivers/virt/Kconfig +2
-2@@ -47,6 +47,6 @@ source "drivers/virt/nitro_enclaves/Kconfig" source "drivers/virt/acrn/Kconfig" -source "drivers/virt/coco/Kconfig" - endif + +source "drivers/virt/coco/Kconfig"drivers/virt/coco/Kconfig +1
-0@@ -3,6 +3,7 @@ # Confidential computing related collateral # +if VIRT_DRIVERS source "drivers/virt/coco/efi_secret/Kconfig" source "drivers/virt/coco/pkvm-guest/Kconfig"
drivers/virt/coco/Kconfig source "drivers/virt/coco/tdx-guest/Kconfig" · line 21
Quoted 7 lines
drivers/virt/coco/Kconfig +1
-0@@ -14,6 +15,7 @@ source "drivers/virt/coco/tdx-guest/Kconfig" source "drivers/virt/coco/arm-cca-guest/Kconfig" source "drivers/virt/coco/guest/Kconfig" +endif config TSM bool
Yes, I think that looks right to me as core infrastructure pieces are not user selectable like the leaf drivers.
For now I will note the mixup in the pull request and would be happy to take an incremental patch fixing this up.
PATCH v2 2/8 PCI/TSM: Drop stub for pci_tsm_doe_transfer()
In reply to Dan WilliamsJust like pci_tsm_pf0_{con,de}structor(), in the CONFIG_PCI_TSM=n case there should be no callers of pci_tsm_doe_transfer().
--- include/linux/pci-tsm.h | 6 ------ 1 file changed, 6 deletions(-)
include/linux/pci-tsm.h +0 -6
@@ -147,11 +147,5 @@ static inline int pci_tsm_register(struct tsm_dev *tsm_dev)static inline void pci_tsm_unregister (struct tsm_dev *tsm_dev) { } -static inline int pci_tsm_doe_transfer (struct pci_dev *pdev,u8 type, -const void *req,size_t req_sz, -void *resp,size_t resp_sz) -{ -return -ENXIO ; -}#endif #endif /*__PCI_TSM_H */
Signature · 1 line
2.51.1
Re: [PATCH v2 2/8] PCI/TSM: Drop stub for pci_tsm_doe_transfer()
Quoted 6 lines · On Wed, 12 Nov 2025 18:14:40 -0800 Dan Williams <[email protected]>…
Just like pci_tsm_pf0_{con,de}structor(), in the
CONFIG_PCI_TSM=ncase there should be no callers ofpci_tsm_doe_transfer().Reported-by Xu Yilun <[email protected]>Signed-off-by Dan Williams <[email protected]>
PATCH v2 3/8 resource: Introduce resource_assigned() for discerning active resources
In reply to Dan WilliamsA PCI bridge resource lifecycle involves both a "request" and "assign" phase. At any point in time that resource may not yet be assigned, or may have failed to assign (because it does not fit).
There are multiple conventions to determine when assignment has not
completed: IORESOURCE_UNSET, IORESOURCE_DISABLED, and checking whether the resource is parented.
In code paths that are known to not be racing assignment, e.g. post subsys_initcall(), the most reliable method to judge that a bridge resource is assigned is to check the resource is parented [1].
Introduce a resource_assigned() helper for this purpose.
--- include/linux/ioport.h | 9 +++++++++ 1 file changed, 9 insertions(+)
include/linux/ioport.h +9 -0
@@ -334,6 +334,15 @@ static inline bool resource_union(const struct resource *r1, const struct resourreturn true; } +/* +* Check if this resource is added to a resource tree or detached. Caller is +* responsible for not racing assignment. +*/ +static inline bool resource_assigned (struct resource *res) +{ +return res->parent; +} +int find_resource_space (struct resource *root,struct resource *new,resource_size_t size,struct resource_constraint *constraint);
Signature · 1 line
2.51.1
Re: [PATCH v2 3/8] resource: Introduce resource_assigned() for discerning active resources
Quoted 12 lines · On Wed, 12 Nov 2025 18:14:41 -0800 Dan Williams <[email protected]>…
A PCI bridge resource lifecycle involves both a "request" and "assign" phase. At any point in time that resource may not yet be assigned, or may have failed to assign (because it does not fit).
There are multiple conventions to determine when assignment has not
completed:IORESOURCE_UNSET,IORESOURCE_DISABLED, and checking whether the resource is parented.In code paths that are known to not be racing assignment, e.g. post
subsys_initcall(), the most reliable method to judge that a bridge resource is assigned is to check the resource is parented [1].
Quoted 6 lines
Introduce a
resource_assigned()helper for this purpose.Suggested-by Ilpo Järvinen <[email protected]>Cc Bjorn Helgaas <[email protected]>Signed-off-by Dan Williams <[email protected]>
Given you replied (and I'm happy to accept that reply) to the doc formatting comment I had on v1. This LGTM
Nice to have a follow up series applying this more widely if anyone has time. Lots of them in pci/setup-bus.c for instance.
One of those is doing an assignment check but maybe isn't good to change as it is
if (res->parent)
return res->parent;
Others all look like low hanging fruit for the readability improvement this brings.
Quoted 24 lines
--- include/linux/ioport.h | 9 +++++++++ 1 file changed, 9 insertions(+)include/linux/ioport.h +9
-0@@ -334,6 +334,15 @@ static inline bool resource_union(const struct resource *r1, const struct resourreturn true; } +/* +* Check if this resource is added to a resource tree or detached. Caller is +* responsible for not racing assignment. +*/ +static inline bool resource_assigned (struct resource *res) +{ +return res->parent; +} +int find_resource_space (struct resource *root,struct resource *new,resource_size_t size,struct resource_constraint *constraint);
PATCH v2 4/8 PCI/IDE: Add Address Association Register setup for downstream MMIO
In reply to Dan WilliamsFrom: Xu Yilun <[email protected]>
The address ranges for downstream Address Association Registers need to cover memory addresses for all functions (PFs/VFs/downstream devices) managed by a Device Security Manager (DSM). The proposed solution is get the memory (32-bit only) range and prefetchable-memory (64-bit capable) range from the immediate ancestor downstream port (either the direct-attach RP or deepest switch port when switch attached).
Similar to RID association, address associations will be set by default if hardware sets 'Number of Address Association Register Blocks' in the 'Selective IDE Stream Capability Register' to a non-zero value. TSM drivers can opt-out of the settings by zero'ing out unwanted / unsupported address ranges. E.g. TDX Connect only supports prefetachable (64-bit capable) memory ranges for the Address Association setting.
If the immediate downstream port provides both a memory range and prefetchable-memory range, but the IDE partner port only provides 1 Address Association Register block then the TSM driver can pick which range to associate, or let the PCI core prioritize memory.
Note, the Address Association Register setup for upstream requests is still uncertain so is not included.
--- include/linux/pci-ide.h | 32 +++++++++++ include/linux/pci.h | 5 ++ drivers/pci/ide.c | 115 ++++++++++++++++++++++++++++++++++++---- 3 files changed, 143 insertions(+), 9 deletions(-)
include/linux/pci-ide.h +32 -0
@@ -28,21 +28,53 @@ enum pci_ide_partner_select {* @rid_start: Partner Port Requester ID range start * @rid_end: Partner Port Requester ID range end * @stream_index: Selective IDE Stream Register Block selection +* @mem_assoc: PCI bus memory address association for targeting peer partner +* @pref_assoc: PCI bus prefetchable memory address association for +* targeting peer partner * @default_stream: Endpoint uses this stream for all upstream TLPs regardless of * address and RID association registers * @setup: flag to track whether to run pci_ide_stream_teardown() for this * partner slot * @enable: flag whether to run pci_ide_stream_disable() for this partner slot +* +* By default, pci_ide_stream_alloc() initializes @mem_assoc and @pref_assoc +* with the immediate ancestor downstream port memory ranges (i.e. Type 1 +* Configuration Space Header values). Caller may zero size ({0, -1}) the range +* to drop it from consideration at pci_ide_stream_setup() time. */ struct pci_ide_partner {u16 rid_start;u16 rid_end;u8 stream_index; +struct pci_bus_region mem_assoc; +struct pci_bus_region pref_assoc;unsigned int default_stream:1 ;unsigned int setup:1 ;unsigned int enable:1 ; }; +/** +* struct pci_ide_regs - Hardware register association settings for Selective +* IDE Streams +* @rid1: IDE RID Association Register 1 +* @rid2: IDE RID Association Register 2 +* @addr: Up to two address association blocks (IDE Address Association Register +* 1 through 3) for MMIO and prefetchable MMIO +* @nr_addr: Number of address association blocks initialized +* +* See pci_ide_stream_to_regs() +*/ +struct pci_ide_regs { +u32 rid1; +u32 rid2; +struct { +u32 assoc1; +u32 assoc2; +u32 assoc3; + } addr[2 ]; +int nr_addr; +}; +/** * struct pci_ide - PCIe Selective IDE Stream descriptor * @pdev: PCIe Endpoint in the pci_ide_partner pair
include/linux/pci.h +5 -0
@@ -870,6 +870,11 @@ struct pci_bus_region {pci_bus_addr_t end; }; +static inline pci_bus_addr_t pci_bus_region_size (const struct pci_bus_region *region) +{ +return region->end - region->start +1 ; +} +struct pci_dynids {spinlock_t lock;/* Protects list, index */ struct list_head list;/* For IDs added at runtime */
drivers/pci/ide.c +106 -9
172 lines not on this page · raw message
Signature · 1 line
2.51.1
Re: [PATCH v2 4/8] PCI/IDE: Add Address Association Register setup for downstream MMIO
Quoted 24 lines · On Wed, 12 Nov 2025 18:14:42 -0800 Dan Williams <[email protected]>…
From: Xu Yilun <[email protected]>
The address ranges for downstream Address Association Registers need to cover memory addresses for all functions (PFs/VFs/downstream devices) managed by a Device Security Manager (DSM). The proposed solution is get the memory (32-bit only) range and prefetchable-memory (64-bit capable) range from the immediate ancestor downstream port (either the direct-attach RP or deepest switch port when switch attached).
Similar to RID association, address associations will be set by default if hardware sets 'Number of Address Association Register Blocks' in the 'Selective IDE Stream Capability Register' to a non-zero value. TSM drivers can opt-out of the settings by zero'ing out unwanted / unsupported address ranges. E.g. TDX Connect only supports prefetachable (64-bit capable) memory ranges for the Address Association setting.
If the immediate downstream port provides both a memory range and prefetchable-memory range, but the IDE partner port only provides 1 Address Association Register block then the TSM driver can pick which range to associate, or let the PCI core prioritize memory.
Note, the Address Association Register setup for upstream requests is still uncertain so is not included.
Quoted 7 lines
Co-developed-by Aneesh Kumar K.V <[email protected]>Signed-off-by Aneesh Kumar K.V <[email protected]>Co-developed-by Arto Merilainen <[email protected]>Signed-off-by Arto Merilainen <[email protected]>Signed-off-by Xu Yilun <[email protected]>Co-developed-by Dan Williams <[email protected]>Signed-off-by Dan Williams <[email protected]>
This addressed only comment I was expecting to result in changes in v1, so
kernel test robot
build botRe: [PATCH v2 4/8] PCI/IDE: Add Address Association Register setup for downstream MMIO
In reply to Dan Williamskernel test robot noticed the following build errors:
Hi Dan,
kernel test robot noticed the following build errors:
[auto build test ERROR on a4438f06b1db15ce3d831ce82b8767665638aa2a]
url: https://github.com/intel-lab-lkp/linux/commits/Dan-Williams/drivers-virt-Drop-VIRT_DRIVERS-build-dependency/20251113-102117 base: a4438f06b1db15ce3d831ce82b8767665638aa2a patch link: https://lore.kernel.org/r/20251113021446.436830-5-dan.j.williams%40intel.com patch subject: [PATCH v2 4/8] PCI/IDE: Add Address Association Register setup for downstream MMIO config: i386-randconfig-012-20251114 (https://download.01.org/0day-ci/archive/20251114/[email protected]/config) compiler: gcc-14 (Debian 14.2.0-19) 14.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251114/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
In file included from <command-line>:
drivers/pci/ide.c: In function 'mem_assoc_to_regs.constprop':
>> include/linux/compiler_types.h:597:45: error: call to '__compiletime_assert_537' declared with attribute error: FIELD_GET: type of reg too small for mask
597 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^
include/linux/compiler_types.h:578:25: note: in definition of macro '__compiletime_assert'
578 | prefix ## suffix(); \
| ^~~~~~
include/linux/compiler_types.h:597:9: note: in expansion of macro '_compiletime_assert'
597 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^~~~~~~~~~~~~~~~~~~
include/linux/build_bug.h:39:37: note: in expansion of macro 'compiletime_assert'
39 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
| ^~~~~~~~~~~~~~~~~~
include/linux/bitfield.h:72:17: note: in expansion of macro 'BUILD_BUG_ON_MSG'
72 | BUILD_BUG_ON_MSG(__bf_cast_unsigned(_mask, _mask) > \
| ^~~~~~~~~~~~~~~~
include/linux/bitfield.h:155:17: note: in expansion of macro '__BF_FIELD_CHECK'
155 | __BF_FIELD_CHECK(_mask, _reg, 0U, "FIELD_GET: "); \
| ^~~~~~~~~~~~~~~~
drivers/pci/ide.c:425:34: note: in expansion of macro 'FIELD_GET'
425 | regs->addr[idx].assoc2 = FIELD_GET(SEL_ADDR_UPPER, region->end);
| ^~~~~~~~~vim +/__compiletime_assert_537 +597 include/linux/compiler_types.h
eb5c2d4b45e3d2 Will Deacon 2020-07-21 583 eb5c2d4b45e3d2 Will Deacon 2020-07-21 584 #define _compiletime_assert(condition, msg, prefix, suffix) \ eb5c2d4b45e3d2 Will Deacon 2020-07-21 585 __compiletime_assert(condition, msg, prefix, suffix) eb5c2d4b45e3d2 Will Deacon 2020-07-21 586 eb5c2d4b45e3d2 Will Deacon 2020-07-21 587 /** eb5c2d4b45e3d2 Will Deacon 2020-07-21 588 * compiletime_assert - break build and emit msg if condition is false eb5c2d4b45e3d2 Will Deacon 2020-07-21 589 * @condition: a compile-time constant condition to check eb5c2d4b45e3d2 Will Deacon 2020-07-21 590 * @msg: a message to emit if condition is false eb5c2d4b45e3d2 Will Deacon 2020-07-21 591 * eb5c2d4b45e3d2 Will Deacon 2020-07-21 592 * In tradition of POSIX assert, this macro will break the build if the eb5c2d4b45e3d2 Will Deacon 2020-07-21 593 * supplied condition is *false*, emitting the supplied error message if the eb5c2d4b45e3d2 Will Deacon 2020-07-21 594 * compiler has support to do so. eb5c2d4b45e3d2 Will Deacon 2020-07-21 595 */ eb5c2d4b45e3d2 Will Deacon 2020-07-21 596 #define compiletime_assert(condition, msg) \
eb5c2d4b45e3d2 Will Deacon 2020-07-21 @597 _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)eb5c2d4b45e3d2 Will Deacon 2020-07-21 598
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
PATCH v3 4/8 PCI/IDE: Add Address Association Register setup for downstream MMIO
In reply to Dan WilliamsFrom: Xu Yilun <[email protected]>
The address ranges for downstream Address Association Registers need to cover memory addresses for all functions (PFs/VFs/downstream devices) managed by a Device Security Manager (DSM). The proposed solution is get the memory (32-bit only) range and prefetchable-memory (64-bit capable) range from the immediate ancestor downstream port (either the direct-attach RP or deepest switch port when switch attached).
Similar to RID association, address associations will be set by default if hardware sets 'Number of Address Association Register Blocks' in the 'Selective IDE Stream Capability Register' to a non-zero value. TSM drivers can opt-out of the settings by zero'ing out unwanted / unsupported address ranges. E.g. TDX Connect only supports prefetachable (64-bit capable) memory ranges for the Address Association setting.
If the immediate downstream port provides both a memory range and prefetchable-memory range, but the IDE partner port only provides 1 Address Association Register block then the TSM driver can pick which range to associate, or let the PCI core prioritize memory.
Note, the Address Association Register setup for upstream requests is still uncertain so is not included.
---
Changes since v2:
Fix a build error when pci_bus_addr_t is a 32-bit value (0day)
include/linux/pci-ide.h | 32 +++++++++++ include/linux/pci.h | 5 ++ drivers/pci/ide.c | 117 ++++++++++++++++++++++++++++++++++++---- 3 files changed, 145 insertions(+), 9 deletions(-)
include/linux/pci-ide.h +32 -0
@@ -28,21 +28,53 @@ enum pci_ide_partner_select {* @rid_start: Partner Port Requester ID range start * @rid_end: Partner Port Requester ID range end * @stream_index: Selective IDE Stream Register Block selection +* @mem_assoc: PCI bus memory address association for targeting peer partner +* @pref_assoc: PCI bus prefetchable memory address association for +* targeting peer partner * @default_stream: Endpoint uses this stream for all upstream TLPs regardless of * address and RID association registers * @setup: flag to track whether to run pci_ide_stream_teardown() for this * partner slot * @enable: flag whether to run pci_ide_stream_disable() for this partner slot +* +* By default, pci_ide_stream_alloc() initializes @mem_assoc and @pref_assoc +* with the immediate ancestor downstream port memory ranges (i.e. Type 1 +* Configuration Space Header values). Caller may zero size ({0, -1}) the range +* to drop it from consideration at pci_ide_stream_setup() time. */ struct pci_ide_partner {u16 rid_start;u16 rid_end;u8 stream_index; +struct pci_bus_region mem_assoc; +struct pci_bus_region pref_assoc;unsigned int default_stream:1 ;unsigned int setup:1 ;unsigned int enable:1 ; }; +/** +* struct pci_ide_regs - Hardware register association settings for Selective +* IDE Streams +* @rid1: IDE RID Association Register 1 +* @rid2: IDE RID Association Register 2 +* @addr: Up to two address association blocks (IDE Address Association Register +* 1 through 3) for MMIO and prefetchable MMIO +* @nr_addr: Number of address association blocks initialized +* +* See pci_ide_stream_to_regs() +*/ +struct pci_ide_regs { +u32 rid1; +u32 rid2; +struct { +u32 assoc1; +u32 assoc2; +u32 assoc3; + } addr[2 ]; +int nr_addr; +}; +/** * struct pci_ide - PCIe Selective IDE Stream descriptor * @pdev: PCIe Endpoint in the pci_ide_partner pair
include/linux/pci.h +5 -0
@@ -870,6 +870,11 @@ struct pci_bus_region {pci_bus_addr_t end; }; +static inline pci_bus_addr_t pci_bus_region_size (const struct pci_bus_region *region) +{ +return region->end - region->start +1 ; +} +struct pci_dynids {spinlock_t lock;/* Protects list, index */ struct list_head list;/* For IDs added at runtime */
drivers/pci/ide.c +108 -9
174 lines not on this page · raw message
base-commit: a4438f06b1db15ce3d831ce82b8767665638aa2a
prerequisite-patch-id: b494ce8950cbed66695e82312da2670630e370a3
prerequisite-patch-id: 0dc62753148ccead5e13d13a344a73aafcf6b1a7
prerequisite-patch-id: d73d8429dc29238718ade8fc48f0cb96fc777d0d
Signature · 1 line
2.51.1
kernel test robot
build botRe: [PATCH v2 4/8] PCI/IDE: Add Address Association Register setup for downstream MMIO
In reply to Dan Williamskernel test robot noticed the following build errors:
Hi Dan,
kernel test robot noticed the following build errors:
[auto build test ERROR on a4438f06b1db15ce3d831ce82b8767665638aa2a]
url: https://github.com/intel-lab-lkp/linux/commits/Dan-Williams/drivers-virt-Drop-VIRT_DRIVERS-build-dependency/20251114-130410 base: a4438f06b1db15ce3d831ce82b8767665638aa2a patch link: https://lore.kernel.org/r/20251113021446.436830-5-dan.j.williams%40intel.com patch subject: [PATCH v2 4/8] PCI/IDE: Add Address Association Register setup for downstream MMIO config: openrisc-allyesconfig (https://download.01.org/0day-ci/archive/20251119/[email protected]/config) compiler: or1k-linux-gcc (GCC) 15.1.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251119/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
In file included from <command-line>:
In function 'mem_assoc_to_regs',
inlined from 'pci_ide_stream_to_regs' at drivers/pci/ide.c:453:3, inlined from 'pci_ide_stream_setup' at drivers/pci/ide.c:485:2:
>> include/linux/compiler_types.h:597:45: error: call to '__compiletime_assert_416' declared with attribute error: FIELD_GET: type of reg too small for mask
597 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^
include/linux/compiler_types.h:578:25: note: in definition of macro '__compiletime_assert'
578 | prefix ## suffix(); \
| ^~~~~~
include/linux/compiler_types.h:597:9: note: in expansion of macro '_compiletime_assert'
597 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^~~~~~~~~~~~~~~~~~~
include/linux/build_bug.h:39:37: note: in expansion of macro 'compiletime_assert'
39 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
| ^~~~~~~~~~~~~~~~~~
include/linux/bitfield.h:72:17: note: in expansion of macro 'BUILD_BUG_ON_MSG'
72 | BUILD_BUG_ON_MSG(__bf_cast_unsigned(_mask, _mask) > \
| ^~~~~~~~~~~~~~~~
include/linux/bitfield.h:155:17: note: in expansion of macro '__BF_FIELD_CHECK'
155 | __BF_FIELD_CHECK(_mask, _reg, 0U, "FIELD_GET: "); \
| ^~~~~~~~~~~~~~~~
drivers/pci/ide.c:425:34: note: in expansion of macro 'FIELD_GET'
425 | regs->addr[idx].assoc2 = FIELD_GET(SEL_ADDR_UPPER, region->end);
| ^~~~~~~~~
In function 'mem_assoc_to_regs',
inlined from 'pci_ide_stream_to_regs' at drivers/pci/ide.c:459:3,
inlined from 'pci_ide_stream_setup' at drivers/pci/ide.c:485:2:
>> include/linux/compiler_types.h:597:45: error: call to '__compiletime_assert_416' declared with attribute error: FIELD_GET: type of reg too small for mask
597 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^
include/linux/compiler_types.h:578:25: note: in definition of macro '__compiletime_assert'
578 | prefix ## suffix(); \
| ^~~~~~
include/linux/compiler_types.h:597:9: note: in expansion of macro '_compiletime_assert'
597 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^~~~~~~~~~~~~~~~~~~
include/linux/build_bug.h:39:37: note: in expansion of macro 'compiletime_assert'
39 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
| ^~~~~~~~~~~~~~~~~~
include/linux/bitfield.h:72:17: note: in expansion of macro 'BUILD_BUG_ON_MSG'
72 | BUILD_BUG_ON_MSG(__bf_cast_unsigned(_mask, _mask) > \
| ^~~~~~~~~~~~~~~~
include/linux/bitfield.h:155:17: note: in expansion of macro '__BF_FIELD_CHECK'
155 | __BF_FIELD_CHECK(_mask, _reg, 0U, "FIELD_GET: "); \
| ^~~~~~~~~~~~~~~~
drivers/pci/ide.c:425:34: note: in expansion of macro 'FIELD_GET'
425 | regs->addr[idx].assoc2 = FIELD_GET(SEL_ADDR_UPPER, region->end);
| ^~~~~~~~~vim +/__compiletime_assert_416 +597 include/linux/compiler_types.h
eb5c2d4b45e3d2 Will Deacon 2020-07-21 583 eb5c2d4b45e3d2 Will Deacon 2020-07-21 584 #define _compiletime_assert(condition, msg, prefix, suffix) \ eb5c2d4b45e3d2 Will Deacon 2020-07-21 585 __compiletime_assert(condition, msg, prefix, suffix) eb5c2d4b45e3d2 Will Deacon 2020-07-21 586 eb5c2d4b45e3d2 Will Deacon 2020-07-21 587 /** eb5c2d4b45e3d2 Will Deacon 2020-07-21 588 * compiletime_assert - break build and emit msg if condition is false eb5c2d4b45e3d2 Will Deacon 2020-07-21 589 * @condition: a compile-time constant condition to check eb5c2d4b45e3d2 Will Deacon 2020-07-21 590 * @msg: a message to emit if condition is false eb5c2d4b45e3d2 Will Deacon 2020-07-21 591 * eb5c2d4b45e3d2 Will Deacon 2020-07-21 592 * In tradition of POSIX assert, this macro will break the build if the eb5c2d4b45e3d2 Will Deacon 2020-07-21 593 * supplied condition is *false*, emitting the supplied error message if the eb5c2d4b45e3d2 Will Deacon 2020-07-21 594 * compiler has support to do so. eb5c2d4b45e3d2 Will Deacon 2020-07-21 595 */ eb5c2d4b45e3d2 Will Deacon 2020-07-21 596 #define compiletime_assert(condition, msg) \
eb5c2d4b45e3d2 Will Deacon 2020-07-21 @597 _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)eb5c2d4b45e3d2 Will Deacon 2020-07-21 598
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
PATCH v2 5/8 PCI/IDE: Initialize an ID for all IDE streams
In reply to Dan WilliamsThe PCIe spec defines two types of streams - selective and link. Each stream has an ID from the same bucket so a stream ID does not tell the type. The spec defines an "enable" bit for every stream and required stream IDs to be unique among all enabled stream but there is no such requirement for disabled streams.
However, when IDE_KM is programming keys, an IDE-capable device needs to know the type of stream being programmed to write it directly to the hardware as keys are relatively large, possibly many of them and devices often struggle with keeping around rather big data not being used.
Walk through all streams on a device and initialise the IDs to some unique number, both link and selective.
The weakest part of this proposal is the host bridge ide_stream_ids_ida. Technically, a Stream ID only needs to be unique within a given partner pair. However, with "anonymous" / unassigned streams there is no convenient place to track the available ids. Proceed with an ida in the host bridge for now, but consider moving this tracking to be an ide_stream_ids_ida per device.
--- drivers/pci/pci.h | 2 + include/linux/pci-ide.h | 6 ++ include/linux/pci.h | 1 + drivers/pci/ide.c | 129 ++++++++++++++++++++++++++++++++++++++++ drivers/pci/remove.c | 1 + 5 files changed, 139 insertions(+)
drivers/pci/pci.h +2 -0
@@ -616,10 +616,12 @@ static inline void pci_doe_sysfs_teardown(struct pci_dev *pdev) { }#ifdef CONFIG_PCI_IDE void pci_ide_init (struct pci_dev *dev);void pci_ide_init_host_bridge (struct pci_host_bridge *hb); +void pci_ide_destroy (struct pci_dev *dev);extern const struct attribute_group pci_ide_attr_group;#else static inline void pci_ide_init (struct pci_dev *dev) { }static inline void pci_ide_init_host_bridge (struct pci_host_bridge *hb) { } +static inline void pci_ide_destroy (struct pci_dev *dev) { }#endif #ifdef CONFIG_PCI_TSM
include/linux/pci-ide.h +6 -0
@@ -97,6 +97,12 @@ struct pci_ide {struct tsm_dev *tsm_dev; }; +/* +* Some devices need help with aliased stream-ids even for idle streams. Use +* this id as the "never enabled" place holder. +*/ +#define PCI_IDE_RESERVED_STREAM_ID 255 +void pci_ide_set_nr_streams (struct pci_host_bridge *hb,u16 nr);struct pci_ide_partner *pci_ide_to_settings (struct pci_dev *pdev,struct pci_ide *ide);
include/linux/pci.h +1 -0
@@ -619,6 +619,7 @@ struct pci_host_bridge {#ifdef CONFIG_PCI_IDE u16 nr_ide_streams;/* Max streams possibly active in @ide_stream_ida */ struct ida ide_stream_ida; +struct ida ide_stream_ids_ida;/* track unique ids per domain */ #endif u8 (*swizzle_irq)(struct pci_dev *,u8 *);/* Platform IRQ swizzler */ int (*map_irq)(const struct pci_dev *,u8 ,u8 );
drivers/pci/ide.c +129 -0
188 lines not on this page · raw message
drivers/pci/remove.c +1 -0
@@ -70,6 +70,7 @@ static void pci_destroy_dev(struct pci_dev *dev)up_write (&pci_bus_sem);pci_doe_destroy (dev); +pci_ide_destroy (dev);pcie_aspm_exit_link_state (dev);pci_bridge_d3_update (dev);pci_pwrctrl_unregister (&dev->dev);
Signature · 1 line
2.51.1
Re: [PATCH v2 5/8] PCI/IDE: Initialize an ID for all IDE streams
Quoted 22 lines · On Wed, 12 Nov 2025 18:14:43 -0800 Dan Williams <[email protected]>…
The PCIe spec defines two types of streams - selective and link. Each stream has an ID from the same bucket so a stream ID does not tell the type. The spec defines an "enable" bit for every stream and required stream IDs to be unique among all enabled stream but there is no such requirement for disabled streams.
However, when
IDE_KMis programming keys, an IDE-capable device needs to know the type of stream being programmed to write it directly to the hardware as keys are relatively large, possibly many of them and devices often struggle with keeping around rather big data not being used.Walk through all streams on a device and initialise the IDs to some unique number, both link and selective.
The weakest part of this proposal is the host bridge
ide_stream_ids_ida. Technically, a Stream ID only needs to be unique within a given partner pair. However, with "anonymous" / unassigned streams there is no convenient place to track the available ids. Proceed with an ida in the host bridge for now, but consider moving this tracking to be anide_stream_ids_idaper device.
Quoted 3 lines
Co-developed-by Alexey Kardashevskiy <[email protected]>Signed-off-by Alexey Kardashevskiy <[email protected]>Signed-off-by Dan Williams <[email protected]>
Re: [PATCH v2 5/8] PCI/IDE: Initialize an ID for all IDE streams
In reply to Dan WilliamsQuoted 8 lines
drivers/pci/ide.c +4
-0@@ -98,6 +141,51 @@ void pci_ide_init(struct pci_dev *pdev) } nr_ide_mem = nr_assoc; + +/* +* Claim Stream IDs and Selective Stream blocks that are already +* active on the device
drivers/pci/ide.c void pci_ide_init(struct pci_dev *pdev) · line 157
Quoted 10 lines
drivers/pci/ide.c +10
-0+*/ +pci_read_config_dword (pdev, pos +PCI_IDE_SEL_CTL , &val); + id =FIELD_GET (PCI_IDE_SEL_CTL_ID , val); +if ((val &PCI_IDE_SEL_CTL_EN ) && + !claim_stream (hb, id, pdev, i)) +return ; + } + +/* Reserve link stream-ids that are already active on the device */ +for (u16 i =0 ; i < nr_link_ide; ++i) {
^
i++. Since i++ is used in previous patch, better keep all loops aligned.
Quoted 8 lines
drivers/pci/ide.c +8
-0+int pos = ide_cap +PCI_IDE_LINK_STREAM_0 + i *PCI_IDE_LINK_BLOCK_SIZE ; +u8 id; + +pci_read_config_dword (pdev, pos +PCI_IDE_LINK_CTL_0 , &val); + id =FIELD_GET (PCI_IDE_LINK_CTL_ID , val); +if ((val &PCI_IDE_LINK_CTL_EN ) && + !claim_stream (hb, id,NULL ,-1 )) +return ;
drivers/pci/ide.c void pci_ide_init(struct pci_dev *pdev) · line 175
Quoted 10 lines
drivers/pci/ide.c +10
-0+ } + +for (u16 i =0 ; i < nr_streams; i++) { +int pos =__sel_ide_offset (ide_cap, nr_link_ide, i, nr_ide_mem); + +pci_read_config_dword (pdev, pos +PCI_IDE_SEL_CAP , &val); +if (val &PCI_IDE_SEL_CTL_EN ) +continue ; + val &= ~PCI_IDE_SEL_CTL_ID ; + val |=FIELD_PREP (PCI_IDE_SEL_CTL_ID ,PCI_IDE_RESERVED_STREAM_ID );
FIELD_MODIFY could save a line.
drivers/pci/ide.c void pci_ide_init(struct pci_dev *pdev) · line 179
Quoted 4 lines
drivers/pci/ide.c +4
-0+pci_write_config_dword (pdev, pos +PCI_IDE_SEL_CTL , val); + } + +for (u16 i =0 ; i < nr_link_ide; ++i) {
ditto
drivers/pci/ide.c void pci_ide_init(struct pci_dev *pdev) · line 187
Quoted 8 lines
drivers/pci/ide.c +8
-0+int pos = ide_cap +PCI_IDE_LINK_STREAM_0 + + i *PCI_IDE_LINK_BLOCK_SIZE ; + +pci_read_config_dword (pdev, pos, &val); +if (val &PCI_IDE_LINK_CTL_EN ) +continue ; + val &= ~PCI_IDE_LINK_CTL_ID ; + val |=FIELD_PREP (PCI_IDE_LINK_CTL_ID ,PCI_IDE_RESERVED_STREAM_ID );
ditto
PATCH v2 6/8 PCI/TSM: Add pci_tsm_bind() helper for instantiating TDIs
In reply to Dan WilliamsAfter a PCIe device has established a secure link and session between a TEE Security Manager (TSM) and its local Device Security Manager (DSM), the device or its subfunctions are candidates to be bound to a private memory context, a TVM. A PCIe device function interface assigned to a TVM is a TEE Device Interface (TDI).
The pci_tsm_bind() requests the low-level TSM driver to associate the device with private MMIO and private IOMMU context resources of a given TVM represented by a @kvm argument. A device in the bound state corresponds to the TDISP protocol LOCKED state and awaits validation by the TVM. It is a 'struct pci_tsm_link_ops' operation because, similar to IDE establishment, it involves host side resource establishment and context setup on behalf of the guest. It is also expected to be performed lazily to allow for operation of the device in non-confidential "shared" context for pre-lock configuration.
--- include/linux/pci-tsm.h | 34 +++++++++++++ drivers/pci/tsm.c | 109 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 142 insertions(+), 1 deletion(-)
include/linux/pci-tsm.h +34 -0
@@ -6,6 +6,8 @@struct pci_tsm ;struct tsm_dev ; +struct kvm ; +enum pci_tsm_req_scope ;/* * struct pci_tsm_ops - manage confidential links and security state
@@ -29,12 +31,16 @@ struct pci_tsm_ops {* @connect: establish / validate a secure connection (e.g. IDE) * with the device * @disconnect: teardown the secure link +* @bind: bind a TDI in preparation for it to be accepted by a TVM +* @unbind: remove a TDI from secure operation with a TVM * * Context: @probe, @remove, @connect, and @disconnect run under * pci_tsm_rwsem held for write to sync with TSM unregistration and * mutual exclusion of @connect and @disconnect. @connect and * @disconnect additionally run under the DSM lock (struct * pci_tsm_pf0::lock) as well as @probe and @remove of the subfunctions. +* @bind and @unbind run under pci_tsm_rwsem held for read and the DSM +* lock. */ struct_group_tagged (pci_tsm_link_ops, link_ops, struct pci_tsm *(*probe)(struct tsm_dev *tsm_dev,
@@ -42,6 +48,9 @@ struct pci_tsm_ops {void (*remove)(struct pci_tsm *tsm);int (*connect)(struct pci_dev *pdev);void (*disconnect)(struct pci_dev *pdev); +struct pci_tdi *(*bind)(struct pci_dev *pdev, +struct kvm *kvm,u32 tdi_id); +void (*unbind)(struct pci_tdi *tdi); );/*
@@ -61,12 +70,25 @@ struct pci_tsm_ops { ); }; +/** +* struct pci_tdi - Core TEE I/O Device Interface (TDI) context +* @pdev: host side representation of guest-side TDI +* @kvm: TEE VM context of bound TDI +* @tdi_id: Identifier (virtual BDF) for the TDI as referenced by the TSM and DSM +*/ +struct pci_tdi { +struct pci_dev *pdev; +struct kvm *kvm; +u32 tdi_id; +}; +/** * struct pci_tsm - Core TSM context for a given PCIe endpoint * @pdev: Back ref to device function, distinguishes type of pci_tsm context * @dsm_dev: PCI Device Security Manager for link operations on @pdev * @tsm_dev: PCI TEE Security Manager device for Link Confidentiality or Device * Function Security operations +* @tdi: TDI context established by the @bind link operation * * This structure is wrapped by low level TSM driver data and returned by * probe()/lock(), it is freed by the corresponding remove()/unlock().
@@ -82,6 +104,7 @@ struct pci_tsm {struct pci_dev *pdev;struct pci_dev *dsm_dev;struct tsm_dev *tsm_dev; +struct pci_tdi *tdi; };/**
@@ -139,6 +162,10 @@ int pci_tsm_pf0_constructor(struct pci_dev *pdev, struct pci_tsm_pf0 *tsm,void pci_tsm_pf0_destructor (struct pci_tsm_pf0 *tsm);int pci_tsm_doe_transfer (struct pci_dev *pdev,u8 type,const void *req,size_t req_sz,void *resp,size_t resp_sz); +int pci_tsm_bind (struct pci_dev *pdev,struct kvm *kvm,u32 tdi_id); +void pci_tsm_unbind (struct pci_dev *pdev); +void pci_tsm_tdi_constructor (struct pci_dev *pdev,struct pci_tdi *tdi, +struct kvm *kvm,u32 tdi_id);#else static inline int pci_tsm_register (struct tsm_dev *tsm_dev) {
@@ -147,5 +174,12 @@ static inline int pci_tsm_register(struct tsm_dev *tsm_dev)static inline void pci_tsm_unregister (struct tsm_dev *tsm_dev) { } +static inline int pci_tsm_bind (struct pci_dev *pdev,struct kvm *kvm,u64 tdi_id) +{ +return -ENXIO ; +} +static inline void pci_tsm_unbind (struct pci_dev *pdev) +{ +}#endif #endif /*__PCI_TSM_H */
drivers/pci/tsm.c +108 -1
133 lines not on this page · raw message
Signature · 1 line
2.51.1
Re: [PATCH v2 6/8] PCI/TSM: Add pci_tsm_bind() helper for instantiating TDIs
Quoted 16 lines · On Wed, 12 Nov 2025 18:14:44 -0800 Dan Williams <[email protected]>…
After a PCIe device has established a secure link and session between a TEE Security Manager (TSM) and its local Device Security Manager (DSM), the device or its subfunctions are candidates to be bound to a private memory context, a TVM. A PCIe device function interface assigned to a TVM is a TEE Device Interface (TDI).
The
pci_tsm_bind()requests the low-level TSM driver to associate the device with private MMIO and private IOMMU context resources of a given TVM represented by a @kvm argument. A device in the bound state corresponds to the TDISP protocol LOCKED state and awaits validation by the TVM. It is a 'structpci_tsm_link_ops' operation because, similar to IDE establishment, it involves host side resource establishment and context setup on behalf of the guest. It is also expected to be performed lazily to allow for operation of the device in non-confidential "shared" context for pre-lock configuration.
Quoted 3 lines
Co-developed-by Xu Yilun <[email protected]>Signed-off-by Xu Yilun <[email protected]>Signed-off-by Dan Williams <[email protected]>
LGTM to me so
though I would like to here from Aneesh on whether the v1 discussion answered all questions expressed.
Re: [PATCH v2 6/8] PCI/TSM: Add pci_tsm_bind() helper for instantiating TDIs
Quoted 19 lines · Jonathan Cameron
Quoted 16 lines · On Wed, 12 Nov 2025 18:14:44 -0800 Dan Williams <[email protected]>…
After a PCIe device has established a secure link and session between a TEE Security Manager (TSM) and its local Device Security Manager (DSM), the device or its subfunctions are candidates to be bound to a private memory context, a TVM. A PCIe device function interface assigned to a TVM is a TEE Device Interface (TDI).
The
pci_tsm_bind()requests the low-level TSM driver to associate the device with private MMIO and private IOMMU context resources of a given TVM represented by a @kvm argument. A device in the bound state corresponds to the TDISP protocol LOCKED state and awaits validation by the TVM. It is a 'structpci_tsm_link_ops' operation because, similar to IDE establishment, it involves host side resource establishment and context setup on behalf of the guest. It is also expected to be performed lazily to allow for operation of the device in non-confidential "shared" context for pre-lock configuration.
Quoted 7 lines
Quoted 3 lines
Co-developed-by Xu Yilun <[email protected]>Signed-off-by Xu Yilun <[email protected]>Signed-off-by Dan Williams <[email protected]>LGTM to me so
Reviewed-by Jonathan Cameron <[email protected]>though I would like to here from Aneesh on whether the v1 discussion answered all questions expressed.
I did follow up with him on the last CCC call and setting tsm->tdi in the TSM driver as needed is the going forward plan.
Thanks for taking a look at these.
Re: [PATCH v2 6/8] PCI/TSM: Add pci_tsm_bind() helper for instantiating TDIs
In reply to Dan Williamsinclude/linux/pci-tsm.h static inline int pci_tsm_register(struct tsm_dev *tsm_dev) · line 177
Quoted 12 lines
include/linux/pci-tsm.h +5
-0+int pci_tsm_bind (struct pci_dev *pdev,struct kvm *kvm,u32 tdi_id); +void pci_tsm_unbind (struct pci_dev *pdev); +void pci_tsm_tdi_constructor (struct pci_dev *pdev,struct pci_tdi *tdi, +struct kvm *kvm,u32 tdi_id);#else static inline int pci_tsm_register (struct tsm_dev *tsm_dev) {@@ -147,5 +174,12 @@ static inline int pci_tsm_register(struct tsm_dev *tsm_dev)static inline void pci_tsm_unregister (struct tsm_dev *tsm_dev) { } +static inline int pci_tsm_bind (struct pci_dev *pdev,struct kvm *kvm,u64 tdi_id)
^
s/u64/u32
PATCH v2 7/8 PCI/TSM: Add pci_tsm_guest_req() for managing TDIs
In reply to Dan WilliamsA PCIe device function interface assigned to a TVM is a TEE Device Interface (TDI). A TDI instantiated by pci_tsm_bind() needs additional steps taken by the TVM to be accepted into the TVM's Trusted Compute Boundary (TCB) and transitioned to the RUN state.
pci_tsm_guest_req() is a channel for the guest to request TDISP collateral, like Device Interface Reports, and effect TDISP state changes, like LOCKED->RUN transititions. Similar to IDE establishment and pci_tsm_bind(), these are long running operations involving SPDM message passing via the DOE mailbox.
The path for a TVM to invoke pci_tsm_guest_req() is:
* TSM triggers exit via guest-to-host-interface ABI (implementation specific)
* VMM invokes handler (KVM handle_exit() -> userspace io)
* handler issues request (userspace io handler -> ioctl() -> pci_tsm_guest_req())
* handler supplies response
* VMM posts response, notifies/re-enters TVM
This path is purely a transport for messages from TVM to platform TSM. By design the host kernel does not and must not care about the content of these messages. I.e. the host kernel is not in the TCB of the TVM.
As this is an opaque passthrough interface, similar to fwctl, the kernel requires that implementations stay within the bounds defined by 'enum pci_tsm_req_scope'. Violation of those expectations likely has market and regulatory consequences. Out of scope requests are blocked by default.
--- include/linux/pci-tsm.h | 62 +++++++++++++++++++++++++++++++++++++++-- drivers/pci/tsm.c | 60 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 120 insertions(+), 2 deletions(-)
include/linux/pci-tsm.h +60 -2
@@ -3,6 +3,7 @@#define __PCI_TSM_H#include <linux/mutex.h> #include <linux/pci.h> +#include <linux/sockptr.h> struct pci_tsm ;struct tsm_dev ;
@@ -33,14 +34,15 @@ struct pci_tsm_ops {* @disconnect: teardown the secure link * @bind: bind a TDI in preparation for it to be accepted by a TVM * @unbind: remove a TDI from secure operation with a TVM +* @guest_req: marshal TVM information and state change requests * * Context: @probe, @remove, @connect, and @disconnect run under * pci_tsm_rwsem held for write to sync with TSM unregistration and * mutual exclusion of @connect and @disconnect. @connect and * @disconnect additionally run under the DSM lock (struct * pci_tsm_pf0::lock) as well as @probe and @remove of the subfunctions. -* @bind and @unbind run under pci_tsm_rwsem held for read and the DSM -* lock. +* @bind, @unbind, and @guest_req run under pci_tsm_rwsem held for read +* and the DSM lock. */ struct_group_tagged (pci_tsm_link_ops, link_ops, struct pci_tsm *(*probe)(struct tsm_dev *tsm_dev,
@@ -51,6 +53,11 @@ struct pci_tsm_ops {struct pci_tdi *(*bind)(struct pci_dev *pdev,struct kvm *kvm,u32 tdi_id);void (*unbind)(struct pci_tdi *tdi); +ssize_t (*guest_req)(struct pci_tdi *tdi, +enum pci_tsm_req_scope scope, +sockptr_t req_in,size_t in_len, +sockptr_t req_out,size_t out_len, +u64 *tsm_code); );/*
@@ -152,6 +159,46 @@ static inline bool is_pci_tsm_pf0(struct pci_dev *pdev)return PCI_FUNC (pdev->devfn) ==0 ; } +/** +* enum pci_tsm_req_scope - Scope of guest requests to be validated by TSM +* +* Guest requests are a transport for a TVM to communicate with a TSM + DSM for +* a given TDI. A TSM driver is responsible for maintaining the kernel security +* model and limit commands that may affect the host, or are otherwise outside +* the typical TDISP operational model. +*/ +enum pci_tsm_req_scope { +/** +* @PCI_TSM_REQ_INFO: Read-only, without side effects, request for +* typical TDISP collateral information like Device Interface Reports. +* No device secrets are permitted, and no device state is changed. +*/ +PCI_TSM_REQ_INFO =0 , +/** +* @PCI_TSM_REQ_STATE_CHANGE: Request to change the TDISP state from +* UNLOCKED->LOCKED, LOCKED->RUN, or other architecture specific state +* changes to support those transitions for a TDI. No other (unrelated +* to TDISP) device / host state, configuration, or data change is +* permitted. +*/ +PCI_TSM_REQ_STATE_CHANGE =1 , +/** +* @PCI_TSM_REQ_DEBUG_READ: Read-only request for debug information +* +* A method to facilitate TVM information retrieval outside of typical +* TDISP operational requirements. No device secrets are permitted. +*/ +PCI_TSM_REQ_DEBUG_READ =2 , +/** +* @PCI_TSM_REQ_DEBUG_WRITE: Device state changes for debug purposes +* +* The request may affect the operational state of the device outside of +* the TDISP operational model. If allowed, requires CAP_SYS_RAW_IO, and +* will taint the kernel. +*/ +PCI_TSM_REQ_DEBUG_WRITE =3 , +}; +#ifdef CONFIG_PCI_TSM int pci_tsm_register (struct tsm_dev *tsm_dev);void pci_tsm_unregister (struct tsm_dev *tsm_dev);
@@ -166,6 +213,9 @@ int pci_tsm_bind(struct pci_dev *pdev, struct kvm *kvm, u32 tdi_id);void pci_tsm_unbind (struct pci_dev *pdev);void pci_tsm_tdi_constructor (struct pci_dev *pdev,struct pci_tdi *tdi,struct kvm *kvm,u32 tdi_id); +ssize_t pci_tsm_guest_req (struct pci_dev *pdev,enum pci_tsm_req_scope scope, +sockptr_t req_in,size_t in_len,sockptr_t req_out, +size_t out_len,u64 *tsm_code);#else static inline int pci_tsm_register (struct tsm_dev *tsm_dev) {
@@ -181,5 +231,13 @@ static inline int pci_tsm_bind(struct pci_dev *pdev, struct kvm *kvm, u64 tdi_idstatic inline void pci_tsm_unbind (struct pci_dev *pdev) { } +static inline ssize_t pci_tsm_guest_req (struct pci_dev *pdev, +enum pci_tsm_req_scope scope, +sockptr_t req_in,size_t in_len, +sockptr_t req_out,size_t out_len, +u64 *tsm_code) +{ +return -ENXIO ; +}#endif #endif /*__PCI_TSM_H */
drivers/pci/tsm.c +60 -0
66 lines not on this page · raw message
Signature · 1 line
2.51.1
Re: [PATCH v2 7/8] PCI/TSM: Add pci_tsm_guest_req() for managing TDIs
Quoted 23 lines · On Wed, 12 Nov 2025 18:14:45 -0800 Dan Williams <[email protected]>…
A PCIe device function interface assigned to a TVM is a TEE Device Interface (TDI). A TDI instantiated by
pci_tsm_bind()needs additional steps taken by the TVM to be accepted into the TVM's Trusted Compute Boundary (TCB) and transitioned to the RUN state.
pci_tsm_guest_req()is a channel for the guest to request TDISP collateral, like Device Interface Reports, and effect TDISP state changes, likeLOCKED->RUNtransititions. Similar to IDE establishment andpci_tsm_bind(), these are long running operations involving SPDM message passing via the DOE mailbox.The path for a TVM to invoke
pci_tsm_guest_req()is:
* TSM triggers exit via guest-to-host-interface ABI (implementation specific)
* VMM invokes handler (KVMhandle_exit()-> userspace io)
* handler issues request (userspace io handler ->ioctl()->pci_tsm_guest_req())
* handler supplies response
* VMM posts response, notifies/re-enters TVMThis path is purely a transport for messages from TVM to platform TSM. By design the host kernel does not and must not care about the content of these messages. I.e. the host kernel is not in the TCB of the TVM.
Quoted 8 lines
As this is an opaque passthrough interface, similar to fwctl, the kernel requires that implementations stay within the bounds defined by 'enum
pci_tsm_req_scope'. Violation of those expectations likely has market and regulatory consequences. Out of scope requests are blocked by default.Co-developed-by Xu Yilun <[email protected]>Signed-off-by Xu Yilun <[email protected]>Signed-off-by Dan Williams <[email protected]>
Re: [PATCH v2 7/8] PCI/TSM: Add pci_tsm_guest_req() for managing TDIs
In reply to Dan WilliamsQuoted 8 lines · Dan Williams
A PCIe device function interface assigned to a TVM is a TEE Device Interface (TDI). A TDI instantiated by
pci_tsm_bind()needs additional steps taken by the TVM to be accepted into the TVM's Trusted Compute Boundary (TCB) and transitioned to the RUN state.
pci_tsm_guest_req()is a channel for the guest to request TDISP collateral, like Device Interface Reports, and effect TDISP state changes, likeLOCKED->RUNtransititions. Similar to IDE establishment andpci_tsm_bind(),
^
transition
[...]
drivers/pci/tsm.c int pci_tsm_bind(struct pci_dev *pdev, struct kvm *kvm, u32 tdi_id) · line 391
Quoted 11 lines
drivers/pci/tsm.c +11
-0+ssize_t pci_tsm_guest_req (struct pci_dev *pdev,enum pci_tsm_req_scope scope, +sockptr_t req_in,size_t in_len,sockptr_t req_out, +size_t out_len,u64 *tsm_code) +{ +struct pci_tsm_pf0 *tsm_pf0; +struct pci_tdi *tdi; +int rc; + +/* Forbid requests that are not directly related to TDISP operations */ +if (scope >PCI_TSM_REQ_STATE_CHANGE ) +return -EINVAL ;
So we are not ready for PCI_TSM_REQ_DEBUG_READ/WRITE, is it?
Others look good to me.
PATCH v2 8/8 PCI/TSM: Add 'dsm' and 'bound' attributes for dependent functions
In reply to Dan WilliamsPCI/TSM sysfs for physical function 0 devices, i.e. the "DSM" (Device Security Manager), contains the 'connect' and 'disconnect' attributes. After a successful 'connect' operation the DSM, its dependent functions (SR-IOV virtual functions, non-zero multi-functions, or downstream endpoints of a switch DSM) are candidates for being transitioned into a TDISP (TEE Device Interface Security Protocol) operational state, via pci_tsm_bind(). At present sysfs is blind to which devices are capable of TDISP operation and it is ambiguous which functions are serviced by which DSMs.
Add a 'dsm' attribute to identify a function's DSM device, and add a 'bound' attribute to identify when a function has entered a TDISP operational state.
--- Documentation/ABI/testing/sysfs-bus-pci | 30 ++++++ drivers/pci/tsm.c | 130 ++++++++++++++++++++---- 2 files changed, 140 insertions(+), 20 deletions(-)
Documentation/ABI/testing/sysfs-bus-pci +30 -0
@@ -655,6 +655,36 @@ Description: (WO) Write the name of the TSM device that was specified to 'connect' to teardown the connection. +What: /sys/bus/pci/devices/.../tsm/dsm +Contact: [email protected] +Description: (RO) Return PCI device name of this device's DSM (Device + Security Manager). When a device is in the connected state it + indicates that the platform TSM (TEE Security Manager) has made + a secure-session connection with a device's DSM. A DSM is always + physical function 0 and when the device supports TDISP (TEE + Device Interface Security Protocol) its managed functions also + populate this tsm/dsm attribute. The managed functions of a DSM + are SR-IOV (Single Root I/O Virtualization) virtual functions, + non-zero functions of a multi-function device, or downstream + endpoints depending on whether the DSM is an SR-IOV physical + function, function0 of a multi-function device, or an upstream + PCIe switch port. This is a "link" TSM attribute, see + Documentation/ABI/testing/sysfs-class-tsm. + +What: /sys/bus/pci/devices/.../tsm/bound +Contact: [email protected] +Description: (RO) Return the device name of the TSM when the device is in a + TDISP (TEE Device Interface Security Protocol) operational state + (LOCKED, RUN, or ERROR, not UNLOCKED). Bound devices consume + platform TSM resources and depend on the device's configuration + (e.g. BME (Bus Master Enable) and MSE (Memory Space Enable) + among other settings) to remain stable for the duration of the + bound state. This attribute is only visible for devices that + support TDISP operation, and it is only populated after + successful connect and TSM bind. The TSM bind operation is + initiated by VFIO/IOMMUFD. This is a "link" TSM attribute, see + Documentation/ABI/testing/sysfs-class-tsm. + What: /sys/bus/pci/devices/.../authenticated Contact: [email protected] Description:
drivers/pci/tsm.c +110 -20
190 lines not on this page · raw message
Signature · 1 line
2.51.1
Re: [PATCH v2 8/8] PCI/TSM: Add 'dsm' and 'bound' attributes for dependent functions
Quoted 14 lines · Dan Williams
PCI/TSM sysfs for physical function 0 devices, i.e. the "DSM" (Device Security Manager), contains the 'connect' and 'disconnect' attributes. After a successful 'connect' operation the DSM, its dependent functions (SR-IOV virtual functions, non-zero multi-functions, or downstream endpoints of a switch DSM) are candidates for being transitioned into a TDISP (TEE Device Interface Security Protocol) operational state, via
pci_tsm_bind(). At present sysfs is blind to which devices are capable of TDISP operation and it is ambiguous which functions are serviced by which DSMs.Add a 'dsm' attribute to identify a function's DSM device, and add a 'bound' attribute to identify when a function has entered a TDISP operational state.
Quoted 8 lines
Cc Bjorn Helgaas <[email protected]>Cc Lukas Wunner <[email protected]>Cc Samuel Ortiz <[email protected]>Cc Alexey Kardashevskiy <[email protected]>Cc Xu Yilun <[email protected]>Cc Suzuki K Poulose <[email protected]>Cc "Aneesh Kumar K.V" <[email protected]>Signed-off-by Dan Williams <[email protected]>