* [PATCH v1 01/10] PCI/TSM: Report active IDE streams per host bridge
2026-11-23 8:33 [PATCH v1 00/10] PCI/TSM: Support guest TSM drivers Aneesh Kumar K.V (Arm)
@ 2026-11-23 8:33 ` Aneesh Kumar K.V (Arm)
2026-11-23 8:33 ` [PATCH v1 02/10] coco: tsm: Register the TSM class before device drivers Aneesh Kumar K.V (Arm)
` (9 subsequent siblings)
10 siblings, 0 replies; 18+ messages in thread
From: Aneesh Kumar K.V (Arm) @ 2026-11-23 8:33 UTC (permalink / raw)
To: linux-coco
Cc: Aneesh Kumar K.V (Arm), Dan Williams, Leon Romanovsky,
Bjorn Helgaas, Jason Gunthorpe, Jonathan Cameron, Xu Yilun,
Alexey Kardashevskiy, Greg Kroah-Hartman, Rafael J . Wysocki,
Steven Price, Suzuki K Poulose, Lukas Wunner, Ashish Kalra,
Tom Lendacky, Herbert Xu, driver-core, linux-pci, kvm, patches,
Dan Williams
From: Dan Williams <dan.j.williams@intel.com>
The first attempt at an ABI for this failed to account for naming
collisions across host bridges:
Commit a4438f06b1db ("PCI/TSM: Report active IDE streams")
Revive this ABI with a per host bridge link that appears at first stream
creation for a given host bridge and disappears after the last stream is
removed.
For systems with many host bridge objects it allows:
ls /sys/class/tsm/tsmN/pci*/stream*
...to find all the host bridges with active streams without first iterating
over all host bridges. Yilun notes that is handy to have this short cut [1]
and from an administrator perspective it helps with inventory for
constrained stream resources.
Link: http://lore.kernel.org/aXLtILY85oMU5qlb@yilunxu-OptiPlex-7050 [1]
Reviewed-by: Xu Yilun <yilun.xu@linux.intel.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar@kernel.org>
---
Documentation/ABI/testing/sysfs-class-tsm | 13 ++++
drivers/pci/ide.c | 4 +
drivers/virt/coco/tsm-core.c | 95 +++++++++++++++++++++++
include/linux/pci-ide.h | 2 +
include/linux/tsm.h | 4 +
5 files changed, 118 insertions(+)
diff --git a/Documentation/ABI/testing/sysfs-class-tsm b/Documentation/ABI/testing/sysfs-class-tsm
index 2949468deaf7..1ddb8f357961 100644
--- a/Documentation/ABI/testing/sysfs-class-tsm
+++ b/Documentation/ABI/testing/sysfs-class-tsm
@@ -7,3 +7,16 @@ Description:
signals when the PCI layer is able to support establishment of
link encryption and other device-security features coordinated
through a platform tsm.
+
+What: /sys/class/tsm/tsmN/pciDDDD:BB
+Contact: linux-pci@vger.kernel.org
+Description:
+ (RO) When a PCIe host bridge has established a secure connection
+ via a TSM to an endpoint, this symlink appears. It facilitates a
+ TSM instance scoped view of PCIe Link Encryption and Secure
+ Session resource consumption across host bridges. The symlink
+ appears when a host bridge has 1 or more IDE streams established
+ with this TSM, and disappears when that number returns to 0. See
+ Documentation/ABI/testing/sysfs-devices-pci-host-bridge for the
+ description of the pciDDDD:BB/streamH.R.E symlink and the
+ pciDDDD:BB/available_secure_streams attribute.
diff --git a/drivers/pci/ide.c b/drivers/pci/ide.c
index beb67b8fb5c5..19f61f957fb4 100644
--- a/drivers/pci/ide.c
+++ b/drivers/pci/ide.c
@@ -11,6 +11,7 @@
#include <linux/pci_regs.h>
#include <linux/slab.h>
#include <linux/sysfs.h>
+#include <linux/tsm.h>
#include "pci.h"
@@ -370,6 +371,9 @@ void pci_ide_stream_release(struct pci_ide *ide)
if (ide->partner[PCI_IDE_EP].enable)
pci_ide_stream_disable(pdev, ide);
+ if (ide->tsm_dev)
+ tsm_ide_stream_unregister(ide);
+
if (ide->partner[PCI_IDE_RP].setup)
pci_ide_stream_teardown(rp, ide);
diff --git a/drivers/virt/coco/tsm-core.c b/drivers/virt/coco/tsm-core.c
index 696c1abfece7..f07e68dcf6e1 100644
--- a/drivers/virt/coco/tsm-core.c
+++ b/drivers/virt/coco/tsm-core.c
@@ -4,11 +4,13 @@
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/tsm.h>
+#include <linux/pci.h>
#include <linux/device.h>
#include <linux/module.h>
#include <linux/cleanup.h>
#include <linux/jiffies.h>
#include <linux/pci-tsm.h>
+#include <linux/pci-ide.h>
#include <linux/pid.h>
#include <linux/sched.h>
@@ -273,6 +275,98 @@ int tsm_unregister(struct tsm_dev *tsm_dev)
}
EXPORT_SYMBOL_GPL(tsm_unregister);
+static DEFINE_XARRAY(tsm_ide_streams);
+static DEFINE_MUTEX(tsm_ide_streams_lock);
+
+/* tracker for the bridge symlink when the bridge has any streams */
+struct tsm_ide_stream {
+ struct tsm_dev *tsm_dev;
+ struct pci_host_bridge *bridge;
+ struct kref kref;
+};
+
+static struct tsm_ide_stream *create_streams(struct tsm_dev *tsm_dev,
+ struct pci_host_bridge *bridge)
+{
+ int rc;
+
+ struct tsm_ide_stream *streams __free(kfree) = kzalloc_obj(*streams);
+ if (!streams)
+ return NULL;
+
+ streams->tsm_dev = tsm_dev;
+ streams->bridge = bridge;
+ kref_init(&streams->kref);
+ rc = xa_insert(&tsm_ide_streams, (unsigned long)bridge, streams,
+ GFP_KERNEL);
+ if (rc)
+ return NULL;
+
+ rc = sysfs_create_link(&tsm_dev->dev.kobj, &bridge->dev.kobj,
+ dev_name(&bridge->dev));
+ if (rc) {
+ xa_erase(&tsm_ide_streams, (unsigned long)bridge);
+ return NULL;
+ }
+
+ return no_free_ptr(streams);
+}
+
+int tsm_ide_stream_register(struct pci_ide *ide, struct tsm_dev *tsm_dev)
+{
+ struct tsm_ide_stream *streams;
+ struct pci_dev *pdev = ide->pdev;
+ struct pci_host_bridge *bridge = pci_find_host_bridge(pdev->bus);
+
+ guard(mutex)(&tsm_ide_streams_lock);
+ streams = xa_load(&tsm_ide_streams, (unsigned long)bridge);
+ if (streams)
+ kref_get(&streams->kref);
+ else
+ streams = create_streams(tsm_dev, bridge);
+
+ if (!streams)
+ return -ENOMEM;
+
+ ide->tsm_dev = tsm_dev;
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(tsm_ide_stream_register);
+
+static void destroy_streams(struct kref *kref)
+{
+ struct tsm_ide_stream *streams =
+ container_of(kref, struct tsm_ide_stream, kref);
+ struct tsm_dev *tsm_dev = streams->tsm_dev;
+ struct pci_host_bridge *bridge = streams->bridge;
+
+ lockdep_assert_held(&tsm_ide_streams_lock);
+ sysfs_remove_link(&tsm_dev->dev.kobj, dev_name(&bridge->dev));
+ xa_erase(&tsm_ide_streams, (unsigned long)bridge);
+ kfree(streams);
+}
+
+void tsm_ide_stream_unregister(struct pci_ide *ide)
+{
+ struct tsm_ide_stream *streams;
+ struct tsm_dev *tsm_dev = ide->tsm_dev;
+ struct pci_dev *pdev = ide->pdev;
+ struct pci_host_bridge *bridge = pci_find_host_bridge(pdev->bus);
+
+ guard(mutex)(&tsm_ide_streams_lock);
+ streams = xa_load(&tsm_ide_streams, (unsigned long)bridge);
+ /* catch API abuse */
+ if (dev_WARN_ONCE(&tsm_dev->dev,
+ !streams || streams->tsm_dev != tsm_dev,
+ "no IDE streams associated with %s\n",
+ dev_name(&bridge->dev)))
+ return;
+ kref_put(&streams->kref, destroy_streams);
+ ide->tsm_dev = NULL;
+}
+EXPORT_SYMBOL_GPL(tsm_ide_stream_unregister);
+
static void tsm_release(struct device *dev)
{
struct tsm_dev *tsm_dev = container_of(dev, typeof(*tsm_dev), dev);
@@ -290,6 +384,7 @@ module_init(tsm_init)
static void __exit tsm_exit(void)
{
class_unregister(&tsm_class);
+ xa_destroy(&tsm_ide_streams);
}
module_exit(tsm_exit)
diff --git a/include/linux/pci-ide.h b/include/linux/pci-ide.h
index ae07d9f699c0..381a1bf22a95 100644
--- a/include/linux/pci-ide.h
+++ b/include/linux/pci-ide.h
@@ -82,6 +82,7 @@ struct pci_ide_regs {
* @host_bridge_stream: allocated from host bridge @ide_stream_ida pool
* @stream_id: unique Stream ID (within Partner Port pairing)
* @name: name of the established Selective IDE Stream in sysfs
+ * @tsm_dev: For TSM established IDE, the TSM device context
*
* Negative @stream_id values indicate "uninitialized" on the
* expectation that with TSM established IDE the TSM owns the stream_id
@@ -93,6 +94,7 @@ struct pci_ide {
u8 host_bridge_stream;
int stream_id;
const char *name;
+ struct tsm_dev *tsm_dev;
};
/*
diff --git a/include/linux/tsm.h b/include/linux/tsm.h
index 0996b888df21..866a71478d3c 100644
--- a/include/linux/tsm.h
+++ b/include/linux/tsm.h
@@ -162,4 +162,8 @@ tsm_viommu_get_ops(struct tsm_dev *tsm_dev, struct device *dev,
return NULL;
}
#endif
+
+struct pci_ide;
+int tsm_ide_stream_register(struct pci_ide *ide, struct tsm_dev *tsm_dev);
+void tsm_ide_stream_unregister(struct pci_ide *ide);
#endif /* __TSM_H */
--
2.43.0
^ permalink raw reply related [flat|nested] 18+ messages in thread* [PATCH v1 02/10] coco: tsm: Register the TSM class before device drivers
2026-11-23 8:33 [PATCH v1 00/10] PCI/TSM: Support guest TSM drivers Aneesh Kumar K.V (Arm)
2026-11-23 8:33 ` [PATCH v1 01/10] PCI/TSM: Report active IDE streams per host bridge Aneesh Kumar K.V (Arm)
@ 2026-11-23 8:33 ` Aneesh Kumar K.V (Arm)
2026-11-23 8:33 ` [PATCH v1 03/10] PCI/TSM: Let TSM drivers discover the CMA DOE mailbox Aneesh Kumar K.V (Arm)
` (8 subsequent siblings)
10 siblings, 0 replies; 18+ messages in thread
From: Aneesh Kumar K.V (Arm) @ 2026-11-23 8:33 UTC (permalink / raw)
To: linux-coco
Cc: Aneesh Kumar K.V (Arm), Dan Williams, Leon Romanovsky,
Bjorn Helgaas, Jason Gunthorpe, Jonathan Cameron, Xu Yilun,
Alexey Kardashevskiy, Greg Kroah-Hartman, Rafael J . Wysocki,
Steven Price, Suzuki K Poulose, Lukas Wunner, Ashish Kalra,
Tom Lendacky, Herbert Xu, driver-core, linux-pci, kvm, patches
Register the built-in TSM class with subsys_initcall() so it exists
before a platform TSM driver probes, independently of object link order.
CONFIG_TSM is boolean; remove the unused module exit path.
Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar@kernel.org>
---
drivers/virt/coco/tsm-core.c | 9 +--------
1 file changed, 1 insertion(+), 8 deletions(-)
diff --git a/drivers/virt/coco/tsm-core.c b/drivers/virt/coco/tsm-core.c
index f07e68dcf6e1..31ef48203eac 100644
--- a/drivers/virt/coco/tsm-core.c
+++ b/drivers/virt/coco/tsm-core.c
@@ -379,14 +379,7 @@ static int __init tsm_init(void)
{
return class_register(&tsm_class);
}
-module_init(tsm_init)
-
-static void __exit tsm_exit(void)
-{
- class_unregister(&tsm_class);
- xa_destroy(&tsm_ide_streams);
-}
-module_exit(tsm_exit)
+subsys_initcall(tsm_init)
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("TEE Security Manager Class Device");
--
2.43.0
^ permalink raw reply related [flat|nested] 18+ messages in thread* [PATCH v1 03/10] PCI/TSM: Let TSM drivers discover the CMA DOE mailbox
2026-11-23 8:33 [PATCH v1 00/10] PCI/TSM: Support guest TSM drivers Aneesh Kumar K.V (Arm)
2026-11-23 8:33 ` [PATCH v1 01/10] PCI/TSM: Report active IDE streams per host bridge Aneesh Kumar K.V (Arm)
2026-11-23 8:33 ` [PATCH v1 02/10] coco: tsm: Register the TSM class before device drivers Aneesh Kumar K.V (Arm)
@ 2026-11-23 8:33 ` Aneesh Kumar K.V (Arm)
2026-11-23 8:33 ` [PATCH v1 04/10] PCI/TSM: Defer TSM vDEVICE allocation until device setup completes Aneesh Kumar K.V (Arm)
` (7 subsequent siblings)
10 siblings, 0 replies; 18+ messages in thread
From: Aneesh Kumar K.V (Arm) @ 2026-11-23 8:33 UTC (permalink / raw)
To: linux-coco
Cc: Aneesh Kumar K.V (Arm), Dan Williams, Leon Romanovsky,
Bjorn Helgaas, Jason Gunthorpe, Jonathan Cameron, Xu Yilun,
Alexey Kardashevskiy, Greg Kroah-Hartman, Rafael J . Wysocki,
Steven Price, Suzuki K Poulose, Lukas Wunner, Ashish Kalra,
Tom Lendacky, Herbert Xu, driver-core, linux-pci, kvm, patches
Move CMA DOE discovery out of pci_tsm_pf0_constructor(). An external
Endpoint requires a mailbox, while an RcIEP can use device assignment
without DOE. Let each TSM driver enforce its own requirement.
Keep SEV-TIO requiring a CMA mailbox and reject devices without one. A
later patch adds the CCA host driver's mailbox checks, allowing RcIEPs
to operate without DOE.
Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar@kernel.org>
---
drivers/crypto/ccp/sev-dev-tsm.c | 7 ++++++
drivers/pci/tsm.c | 39 ++++++++++++++++----------------
include/linux/pci-tsm.h | 4 ++--
3 files changed, 29 insertions(+), 21 deletions(-)
diff --git a/drivers/crypto/ccp/sev-dev-tsm.c b/drivers/crypto/ccp/sev-dev-tsm.c
index 5c61ce74ee0f..af22f36a2318 100644
--- a/drivers/crypto/ccp/sev-dev-tsm.c
+++ b/drivers/crypto/ccp/sev-dev-tsm.c
@@ -213,6 +213,13 @@ static struct pci_tsm *tio_pf0_probe(struct pci_dev *pdev, struct sev_device *se
if (!dsm)
return NULL;
+ dsm->tsm.doe_mb = pci_find_doe_mailbox(pdev, PCI_VENDOR_ID_PCI_SIG,
+ PCI_DOE_FEATURE_CMA);
+ if (!dsm->tsm.doe_mb) {
+ pci_warn(pdev, "TSM init failure, no CMA mailbox\n");
+ return NULL;
+ }
+
rc = pci_tsm_pf0_constructor(pdev, &dsm->tsm, sev->tsmdev);
if (rc)
return NULL;
diff --git a/drivers/pci/tsm.c b/drivers/pci/tsm.c
index 5ff1265714aa..2be92bde8780 100644
--- a/drivers/pci/tsm.c
+++ b/drivers/pci/tsm.c
@@ -714,30 +714,31 @@ EXPORT_SYMBOL_GPL(pci_tsm_link_constructor);
/**
* pci_tsm_pf0_constructor() - common 'struct pci_tsm_pf0' (DSM) initialization
* @pdev: Physical Function 0 PCI device (as indicated by is_pci_tsm_pf0())
- * @tsm: context to initialize
+ * @pf0: PF0 state to initialize
* @tsm_dev: Platform TEE Security Manager, initiator of security operations
*/
-int pci_tsm_pf0_constructor(struct pci_dev *pdev, struct pci_tsm_pf0 *tsm,
+int pci_tsm_pf0_constructor(struct pci_dev *pdev, struct pci_tsm_pf0 *pf0,
struct tsm_dev *tsm_dev)
{
- mutex_init(&tsm->lock);
- init_completion(&tsm->dsm_context_drain_complete);
- tsm->dsm_context_users = 0;
- tsm->removing = false;
- tsm->doe_mb = pci_find_doe_mailbox(pdev, PCI_VENDOR_ID_PCI_SIG,
- PCI_DOE_FEATURE_CMA);
- if (!tsm->doe_mb) {
- pci_warn(pdev, "TSM init failure, no CMA mailbox\n");
- return -ENODEV;
- }
+ mutex_init(&pf0->lock);
+ init_completion(&pf0->dsm_context_drain_complete);
+ pf0->dsm_context_users = 0;
+ pf0->removing = false;
+ /*
+ * Note, low-level TSM driver responsible for determining if it wants to
+ * proceed with a device that has no DOE mailbox. TSM may have an
+ * alternate method for coordinating TDISP.
+ */
+ if (!pf0->doe_mb)
+ pci_dbg(pdev, "No DOE mailbox for Component Measurement and Authentication\n");
- return pci_tsm_link_constructor(pdev, &tsm->base_tsm, tsm_dev);
+ return pci_tsm_link_constructor(pdev, &pf0->base_tsm, tsm_dev);
}
EXPORT_SYMBOL_GPL(pci_tsm_pf0_constructor);
-void pci_tsm_pf0_destructor(struct pci_tsm_pf0 *pf0_tsm)
+void pci_tsm_pf0_destructor(struct pci_tsm_pf0 *pf0)
{
- mutex_destroy(&pf0_tsm->lock);
+ mutex_destroy(&pf0->lock);
}
EXPORT_SYMBOL_GPL(pci_tsm_pf0_destructor);
@@ -954,16 +955,16 @@ void pci_tsm_unregister(struct tsm_dev *tsm_dev)
int pci_tsm_doe_transfer(struct pci_dev *pdev, u8 type, const void *req,
size_t req_sz, void *resp, size_t resp_sz)
{
- struct pci_tsm_pf0 *tsm;
+ struct pci_tsm_pf0 *pf0;
if (!pdev->tsm || !is_pci_tsm_pf0(pdev))
return -ENXIO;
- tsm = to_pci_tsm_pf0(pdev->tsm);
- if (!tsm->doe_mb)
+ pf0 = to_pci_tsm_pf0(pdev->tsm);
+ if (!pf0->doe_mb)
return -ENXIO;
- return pci_doe(tsm->doe_mb, PCI_VENDOR_ID_PCI_SIG, type, req, req_sz,
+ return pci_doe(pf0->doe_mb, PCI_VENDOR_ID_PCI_SIG, type, req, req_sz,
resp, resp_sz);
}
EXPORT_SYMBOL_GPL(pci_tsm_doe_transfer);
diff --git a/include/linux/pci-tsm.h b/include/linux/pci-tsm.h
index 68ebe774121b..7e91c15ffe3b 100644
--- a/include/linux/pci-tsm.h
+++ b/include/linux/pci-tsm.h
@@ -160,9 +160,9 @@ int pci_tsm_register(struct tsm_dev *tsm_dev);
void pci_tsm_unregister(struct tsm_dev *tsm_dev);
int pci_tsm_link_constructor(struct pci_dev *pdev, struct pci_tsm *tsm,
struct tsm_dev *tsm_dev);
-int pci_tsm_pf0_constructor(struct pci_dev *pdev, struct pci_tsm_pf0 *tsm,
+int pci_tsm_pf0_constructor(struct pci_dev *pdev, struct pci_tsm_pf0 *pf0,
struct tsm_dev *tsm_dev);
-void pci_tsm_pf0_destructor(struct pci_tsm_pf0 *tsm);
+void pci_tsm_pf0_destructor(struct pci_tsm_pf0 *pf0);
int pci_tsm_doe_transfer(struct pci_dev *pdev, u8 type, const void *req,
size_t req_sz, void *resp, size_t resp_sz);
bool pci_tsm_is_configured(struct pci_dev *pdev);
--
2.43.0
^ permalink raw reply related [flat|nested] 18+ messages in thread* [PATCH v1 04/10] PCI/TSM: Defer TSM vDEVICE allocation until device setup completes
2026-11-23 8:33 [PATCH v1 00/10] PCI/TSM: Support guest TSM drivers Aneesh Kumar K.V (Arm)
` (2 preceding siblings ...)
2026-11-23 8:33 ` [PATCH v1 03/10] PCI/TSM: Let TSM drivers discover the CMA DOE mailbox Aneesh Kumar K.V (Arm)
@ 2026-11-23 8:33 ` Aneesh Kumar K.V (Arm)
2026-11-23 8:33 ` [PATCH v1 05/10] PCI/TSM: Add association locking helpers for evidence acceptance Aneesh Kumar K.V (Arm)
` (6 subsequent siblings)
10 siblings, 0 replies; 18+ messages in thread
From: Aneesh Kumar K.V (Arm) @ 2026-11-23 8:33 UTC (permalink / raw)
To: linux-coco
Cc: Aneesh Kumar K.V (Arm), Dan Williams, Leon Romanovsky,
Bjorn Helgaas, Jason Gunthorpe, Jonathan Cameron, Xu Yilun,
Alexey Kardashevskiy, Greg Kroah-Hartman, Rafael J . Wysocki,
Steven Price, Suzuki K Poulose, Lukas Wunner, Ashish Kalra,
Tom Lendacky, Herbert Xu, driver-core, linux-pci, kvm, patches
A successful connect does not necessarily complete the checks and setup
needed to assign a device to a confidential guest. Authentication and
userspace evidence acceptance may still be required.
Add pci_tsm_pf0::ready and pci_tsm_set_ready(). While ready is false,
pci_tsm_context_get() returns -EACCES, preventing TSM virtual device
(vDEVICE) allocation.
Initialize ready to true to preserve existing TSM driver behavior. A
follow-up CCA patch will clear ready during connect and set it after
evidence-accept completes the required device setup.
Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar@kernel.org>
---
drivers/pci/tsm.c | 31 ++++++++++++++++++++++++++++++-
include/linux/pci-tsm.h | 10 ++++++++++
2 files changed, 40 insertions(+), 1 deletion(-)
diff --git a/drivers/pci/tsm.c b/drivers/pci/tsm.c
index 2be92bde8780..4dafc5dc6fe3 100644
--- a/drivers/pci/tsm.c
+++ b/drivers/pci/tsm.c
@@ -27,7 +27,8 @@
* Provide a read/write lock against the init / exit of pdev tsm
* capabilities and arrival/departure of a TSM instance
*/
-static DECLARE_RWSEM(pci_tsm_rwsem);
+DECLARE_RWSEM(pci_tsm_rwsem);
+EXPORT_SYMBOL_GPL(pci_tsm_rwsem);
/*
* Count of TSMs registered that support physical link operations vs device
@@ -293,6 +294,26 @@ static bool is_devsec_tsm(struct tsm_dev *tsm_dev)
return tsm_dev && tsm_dev->pci_ops && tsm_dev->pci_ops->devsec_ops.lock;
}
+/**
+ * pci_tsm_set_ready() - Set when PF0 permits device assignment
+ * @ready: whether the device is ready for assignment
+ *
+ * pci_tsm_context_get() rejects requests with -EACCES while pf0->ready
+ * is false. A TSM driver can clear it during connect and set it after
+ * completing authentication, evidence acceptance and device setup.
+ *
+ * Hold pci_tsm_rwsem for write and pf0->lock through device setup and
+ * this update. pci_tsm_context_get() checks ready under pf0->lock, so
+ * device assignment cannot proceed before setup completes.
+ */
+void pci_tsm_set_ready(struct pci_tsm_pf0 *pf0, bool ready)
+{
+ lockdep_assert_held_write(&pci_tsm_rwsem);
+ lockdep_assert_held(&pf0->lock);
+ pf0->ready = ready;
+}
+EXPORT_SYMBOL_GPL(pci_tsm_set_ready);
+
static ssize_t connect_store(struct device *dev, struct device_attribute *attr,
const char *buf, size_t len)
{
@@ -393,6 +414,12 @@ struct pci_tsm_context *pci_tsm_context_get(struct pci_dev *pdev,
goto out_unlock_mutex;
}
+ if (!pf0->ready) {
+ kfree(context);
+ context = ERR_PTR(-EACCES);
+ goto out_unlock_mutex;
+ }
+
if (!pf0->dsm_context_users)
reinit_completion(&pf0->dsm_context_drain_complete);
@@ -724,6 +751,8 @@ int pci_tsm_pf0_constructor(struct pci_dev *pdev, struct pci_tsm_pf0 *pf0,
init_completion(&pf0->dsm_context_drain_complete);
pf0->dsm_context_users = 0;
pf0->removing = false;
+ /* Default to ready for TSM drivers that complete setup during connect. */
+ pf0->ready = true;
/*
* Note, low-level TSM driver responsible for determining if it wants to
* proceed with a device that has no DOE mailbox. TSM may have an
diff --git a/include/linux/pci-tsm.h b/include/linux/pci-tsm.h
index 7e91c15ffe3b..9c5f0b6c0f6d 100644
--- a/include/linux/pci-tsm.h
+++ b/include/linux/pci-tsm.h
@@ -4,6 +4,7 @@
#include <linux/completion.h>
#include <linux/mutex.h>
#include <linux/pci.h>
+#include <linux/rwsem.h>
#include <uapi/linux/iommufd.h>
struct iommufd_viommu_ops;
@@ -111,6 +112,7 @@ struct pci_tsm {
* blocks link disconnect
* @dsm_context_drain_complete: completed when the last context is released
* @removing: reject new contexts while the DSM is being removed
+ * @ready: TSM driver has completed the checks and setup needed for assignment
* @doe_mb: PCIe Data Object Exchange mailbox
*/
struct pci_tsm_pf0 {
@@ -119,6 +121,7 @@ struct pci_tsm_pf0 {
unsigned int dsm_context_users;
struct completion dsm_context_drain_complete;
bool removing;
+ bool ready;
struct pci_doe_mb *doe_mb;
};
@@ -156,6 +159,7 @@ static inline bool is_pci_tsm_pf0(struct pci_dev *pdev)
}
#ifdef CONFIG_PCI_TSM
+void pci_tsm_set_ready(struct pci_tsm_pf0 *pf0, bool ready);
int pci_tsm_register(struct tsm_dev *tsm_dev);
void pci_tsm_unregister(struct tsm_dev *tsm_dev);
int pci_tsm_link_constructor(struct pci_dev *pdev, struct pci_tsm *tsm,
@@ -175,6 +179,10 @@ bool pci_tsm_context_match_device(struct pci_tsm_context *context,
struct pci_dev *pdev);
struct tsm_dev *pci_tsm_get_device(struct pci_dev *pdev);
#else
+static inline void pci_tsm_set_ready(struct pci_tsm_pf0 *pf0, bool ready)
+{
+}
+
static inline int pci_tsm_register(struct tsm_dev *tsm_dev)
{
return 0;
@@ -222,4 +230,6 @@ pci_tsm_context_match_device(struct pci_tsm_context *context,
return false;
}
#endif
+extern struct rw_semaphore pci_tsm_rwsem;
+
#endif /*__PCI_TSM_H */
--
2.43.0
^ permalink raw reply related [flat|nested] 18+ messages in thread* [PATCH v1 05/10] PCI/TSM: Add association locking helpers for evidence acceptance
2026-11-23 8:33 [PATCH v1 00/10] PCI/TSM: Support guest TSM drivers Aneesh Kumar K.V (Arm)
` (3 preceding siblings ...)
2026-11-23 8:33 ` [PATCH v1 04/10] PCI/TSM: Defer TSM vDEVICE allocation until device setup completes Aneesh Kumar K.V (Arm)
@ 2026-11-23 8:33 ` Aneesh Kumar K.V (Arm)
2026-11-23 8:33 ` [PATCH v1 06/10] PCI/TSM: Notify TSM drivers before waiting for TSM user references Aneesh Kumar K.V (Arm)
` (5 subsequent siblings)
10 siblings, 0 replies; 18+ messages in thread
From: Aneesh Kumar K.V (Arm) @ 2026-11-23 8:33 UTC (permalink / raw)
To: linux-coco
Cc: Aneesh Kumar K.V (Arm), Dan Williams, Leon Romanovsky,
Bjorn Helgaas, Jason Gunthorpe, Jonathan Cameron, Xu Yilun,
Alexey Kardashevskiy, Greg Kroah-Hartman, Rafael J . Wysocki,
Steven Price, Suzuki K Poulose, Lukas Wunner, Ashish Kalra,
Tom Lendacky, Herbert Xu, driver-core, linux-pci, kvm, patches
Later attestation patches let userspace finish device setup through
evidence-accept after host sysfs connect or guest sysfs lock returns.
Those commands use a saved struct pci_tsm and must prevent disconnect or
guest unlock from changing pci_dev::tsm or freeing the saved structure
while setup is in progress.
Add pci_tsm_trylock_association() to acquire pci_tsm_rwsem for write and
check that pci_dev::tsm still points to the saved structure. For a TSM
implementing devsec_ops, first take device::mutex to prevent driver
attachment during MMIO validation and device acceptance. This matches
the device-mutex-before-rwsem order used by PCI DMA preparation.
Neither lock acquisition waits. Host disconnect holds pci_tsm_rwsem for
write; guest unlock holds device::mutex and the rwsem. Both unregister
attestation, which takes ctlv::registration_lock for write to wait for
running CTLV ioctls. The evidence-accept ioctl holds that lock for read
when calling this helper, so waiting for disconnect or unlock would
deadlock. Return ERR_PTR(-EAGAIN) on contention and ERR_PTR(-ENODEV) if
the saved pointer no longer matches.
Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar@kernel.org>
---
drivers/pci/tsm.c | 66 +++++++++++++++++++++++++++++++++++++++++
include/linux/pci-tsm.h | 17 +++++++++++
2 files changed, 83 insertions(+)
diff --git a/drivers/pci/tsm.c b/drivers/pci/tsm.c
index 4dafc5dc6fe3..56b6c812a8f9 100644
--- a/drivers/pci/tsm.c
+++ b/drivers/pci/tsm.c
@@ -294,6 +294,72 @@ static bool is_devsec_tsm(struct tsm_dev *tsm_dev)
return tsm_dev && tsm_dev->pci_ops && tsm_dev->pci_ops->devsec_ops.lock;
}
+/**
+ * pci_tsm_trylock_association() - Lock and check a PCI function's TSM state
+ * @tsm: struct pci_tsm kept allocated by the caller throughout the operation
+ *
+ * For a TSM implementing devsec_ops, first trylock tsm->pdev->dev.mutex to
+ * prevent PCI driver attachment during MMIO validation and device setup.
+ * Then acquire pci_tsm_rwsem for write before checking that tsm->pdev->tsm
+ * still points to @tsm. A TSM implementing link_ops only needs the rwsem.
+ *
+ * Host disconnect holds pci_tsm_rwsem for write; guest unlock also
+ * holds pdev->dev.mutex. Both unregister attestation, which waits for
+ * running CTLV ioctls by taking ctlv::registration_lock for write.
+ *
+ * evidence-accept holds that registration lock for read when calling
+ * this helper. It must return -EAGAIN rather than wait for the locks
+ * held by disconnect or unlock, otherwise neither call can finish.
+ *
+ * Return: @tsm with the locks held, ERR_PTR(-EAGAIN) on lock contention, or
+ * ERR_PTR(-ENODEV) if tsm->pdev->tsm no longer points to @tsm.
+ */
+struct pci_tsm *pci_tsm_trylock_association(struct pci_tsm *tsm)
+{
+ struct pci_dev *pdev = tsm->pdev;
+ bool devsec = is_devsec_tsm(tsm->tsm_dev);
+
+ if (devsec && !device_trylock(&pdev->dev))
+ return ERR_PTR(-EAGAIN);
+
+ if (!down_write_trylock(&pci_tsm_rwsem)) {
+ if (devsec)
+ device_unlock(&pdev->dev);
+
+ return ERR_PTR(-EAGAIN);
+ }
+
+ if (pdev->tsm != tsm) {
+ up_write(&pci_tsm_rwsem);
+
+ if (devsec)
+ device_unlock(&pdev->dev);
+
+ return ERR_PTR(-ENODEV);
+ }
+
+ return tsm;
+}
+EXPORT_SYMBOL_GPL(pci_tsm_trylock_association);
+
+/**
+ * pci_tsm_unlock_association() - Release locks protecting a PCI function's TSM state
+ * @tsm: struct pci_tsm returned by a successful pci_tsm_trylock_association()
+ *
+ */
+void pci_tsm_unlock_association(struct pci_tsm *tsm)
+{
+ struct pci_dev *pdev = tsm->pdev;
+ bool devsec = is_devsec_tsm(tsm->tsm_dev);
+
+ lockdep_assert_held_write(&pci_tsm_rwsem);
+ up_write(&pci_tsm_rwsem);
+
+ if (devsec)
+ device_unlock(&pdev->dev);
+}
+EXPORT_SYMBOL_GPL(pci_tsm_unlock_association);
+
/**
* pci_tsm_set_ready() - Set when PF0 permits device assignment
* @ready: whether the device is ready for assignment
diff --git a/include/linux/pci-tsm.h b/include/linux/pci-tsm.h
index 9c5f0b6c0f6d..d93d1c30d734 100644
--- a/include/linux/pci-tsm.h
+++ b/include/linux/pci-tsm.h
@@ -1,6 +1,7 @@
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef __PCI_TSM_H
#define __PCI_TSM_H
+#include <linux/cleanup.h>
#include <linux/completion.h>
#include <linux/mutex.h>
#include <linux/pci.h>
@@ -159,6 +160,8 @@ static inline bool is_pci_tsm_pf0(struct pci_dev *pdev)
}
#ifdef CONFIG_PCI_TSM
+struct pci_tsm *pci_tsm_trylock_association(struct pci_tsm *tsm);
+void pci_tsm_unlock_association(struct pci_tsm *tsm);
void pci_tsm_set_ready(struct pci_tsm_pf0 *pf0, bool ready);
int pci_tsm_register(struct tsm_dev *tsm_dev);
void pci_tsm_unregister(struct tsm_dev *tsm_dev);
@@ -179,6 +182,15 @@ bool pci_tsm_context_match_device(struct pci_tsm_context *context,
struct pci_dev *pdev);
struct tsm_dev *pci_tsm_get_device(struct pci_dev *pdev);
#else
+static inline struct pci_tsm *pci_tsm_trylock_association(struct pci_tsm *tsm)
+{
+ return ERR_PTR(-ENODEV);
+}
+
+static inline void pci_tsm_unlock_association(struct pci_tsm *tsm)
+{
+}
+
static inline void pci_tsm_set_ready(struct pci_tsm_pf0 *pf0, bool ready)
{
}
@@ -230,6 +242,11 @@ pci_tsm_context_match_device(struct pci_tsm_context *context,
return false;
}
#endif
+
+DEFINE_FREE(pci_tsm_unlock, struct pci_tsm *,
+ if (!IS_ERR_OR_NULL(_T))
+ pci_tsm_unlock_association(_T))
+
extern struct rw_semaphore pci_tsm_rwsem;
#endif /*__PCI_TSM_H */
--
2.43.0
^ permalink raw reply related [flat|nested] 18+ messages in thread* [PATCH v1 06/10] PCI/TSM: Notify TSM drivers before waiting for TSM user references
2026-11-23 8:33 [PATCH v1 00/10] PCI/TSM: Support guest TSM drivers Aneesh Kumar K.V (Arm)
` (4 preceding siblings ...)
2026-11-23 8:33 ` [PATCH v1 05/10] PCI/TSM: Add association locking helpers for evidence acceptance Aneesh Kumar K.V (Arm)
@ 2026-11-23 8:33 ` Aneesh Kumar K.V (Arm)
2026-11-23 8:33 ` [PATCH v1 07/10] device core: Add helpers to record confidential device acceptance Aneesh Kumar K.V (Arm)
` (4 subsequent siblings)
10 siblings, 0 replies; 18+ messages in thread
From: Aneesh Kumar K.V (Arm) @ 2026-11-23 8:33 UTC (permalink / raw)
To: linux-coco
Cc: Aneesh Kumar K.V (Arm), Dan Williams, Leon Romanovsky,
Bjorn Helgaas, Jason Gunthorpe, Jonathan Cameron, Xu Yilun,
Alexey Kardashevskiy, Greg Kroah-Hartman, Rafael J . Wysocki,
Steven Price, Suzuki K Poulose, Lukas Wunner, Ashish Kalra,
Tom Lendacky, Herbert Xu, driver-core, linux-pci, kvm, patches
Call the optional prepare_remove callback from tsm_unregister() before
waiting for TSM user references. Host PF0 callbacks run with
pci_tsm_rwsem held for write, followed by pci_tsm_pf0::lock. Guest
device-security callbacks take device::mutex before pci_tsm_rwsem for
write, matching PCI DMA preparation.
Later CCA patches use this callback to reject new host physical device
(PDEV) operations and guest evidence requests before unregister waits
for existing users. The guest DMA patch also uses this ordering to
reject DMA-enable requests while permitting DMA disable.
Also invoke prepare_remove() from pci_tsm_destroy() before waiting for
existing struct pci_tsm_context objects to be released. Sysfs disconnect
continues to return -EBUSY while those objects remain.
Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar@kernel.org>
---
drivers/pci/tsm.c | 50 +++++++++++++++++++++++++++++++++---
drivers/virt/coco/tsm-core.c | 2 ++
include/linux/pci-tsm.h | 10 ++++++++
3 files changed, 59 insertions(+), 3 deletions(-)
diff --git a/drivers/pci/tsm.c b/drivers/pci/tsm.c
index 56b6c812a8f9..f04498265383 100644
--- a/drivers/pci/tsm.c
+++ b/drivers/pci/tsm.c
@@ -906,6 +906,21 @@ static void __pci_tsm_destroy(struct pci_dev *pdev, struct tsm_dev *tsm_dev)
}
}
+static void pci_tsm_prepare_remove(struct pci_dev *pdev)
+{
+ struct pci_tsm_pf0 *pf0 = to_pci_tsm_pf0(pdev->tsm);
+ const struct pci_tsm_ops *ops = pdev->tsm->tsm_dev->pci_ops;
+
+ lockdep_assert_held_write(&pci_tsm_rwsem);
+ guard(mutex)(&pf0->lock);
+ if (pf0->removing)
+ return;
+
+ pf0->removing = true;
+ if (ops->prepare_remove)
+ ops->prepare_remove(pdev);
+}
+
void pci_tsm_destroy(struct pci_dev *pdev)
{
struct tsm_dev *tsm_dev = NULL;
@@ -916,9 +931,7 @@ void pci_tsm_destroy(struct pci_dev *pdev)
is_pci_tsm_pf0(pdev)) {
struct pci_tsm_pf0 *pf0 = to_pci_tsm_pf0(pdev->tsm);
- mutex_lock(&pf0->lock);
- pf0->removing = true;
- mutex_unlock(&pf0->lock);
+ pci_tsm_prepare_remove(pdev);
if (pf0->dsm_context_users) {
struct completion *drain_complete;
@@ -1034,6 +1047,37 @@ void pci_tsm_init(struct pci_dev *pdev)
up_read(&pci_tsm_rwsem);
}
+/* Reject new device operations before tsm_unregister() waits for users. */
+void pci_tsm_prepare_unregister(struct tsm_dev *tsm_dev)
+{
+ const struct pci_tsm_ops *ops = tsm_dev->pci_ops;
+ struct pci_dev *pdev = NULL;
+
+ if (is_devsec_tsm(tsm_dev)) {
+ if (!ops->prepare_remove)
+ return;
+
+ for_each_pci_dev(pdev) {
+ guard(device)(&pdev->dev);
+ guard(rwsem_write)(&pci_tsm_rwsem);
+
+ if (pdev->tsm && pdev->tsm->tsm_dev == tsm_dev)
+ ops->prepare_remove(pdev);
+ }
+
+ return;
+ }
+
+ guard(rwsem_write)(&pci_tsm_rwsem);
+ for_each_pci_dev(pdev) {
+ if (!pdev->tsm || pdev->tsm->tsm_dev != tsm_dev)
+ continue;
+
+ if (is_pci_tsm_pf0(pdev))
+ pci_tsm_prepare_remove(pdev);
+ }
+}
+
void pci_tsm_unregister(struct tsm_dev *tsm_dev)
{
struct pci_dev *pdev = NULL;
diff --git a/drivers/virt/coco/tsm-core.c b/drivers/virt/coco/tsm-core.c
index 31ef48203eac..ba9183783dd1 100644
--- a/drivers/virt/coco/tsm-core.c
+++ b/drivers/virt/coco/tsm-core.c
@@ -260,6 +260,8 @@ int tsm_unregister(struct tsm_dev *tsm_dev)
}
tsm_dev->unregistering = true;
+ if (IS_ENABLED(CONFIG_PCI_TSM) && tsm_dev->pci_ops)
+ pci_tsm_prepare_unregister(tsm_dev);
device_del(&tsm_dev->dev);
/* No new user references can be acquired while the write lock is held. */
diff --git a/include/linux/pci-tsm.h b/include/linux/pci-tsm.h
index d93d1c30d734..75df64a2e97d 100644
--- a/include/linux/pci-tsm.h
+++ b/include/linux/pci-tsm.h
@@ -25,6 +25,8 @@ struct tsm_dev;
* @viommu_get_ops: Return operations for a supported TSM-owned vIOMMU type,
* or NULL if unsupported
* @owner: Module providing the vIOMMU operations, if built as a module
+ * @prepare_remove: Optional, reject new device operations before TSM unregister
+ * waits for users, or before forced PF0 removal.
*
* The vIOMMU owner holds a TSM user reference, a device reference and a
* backend module reference before querying @viommu_get_ops, releasing them
@@ -36,11 +38,14 @@ struct tsm_dev;
*
* @viommu_get_ops runs with the backend module pinned. The PCI/TSM
* association is checked during acquisition under pci_tsm_rwsem.
+ * @prepare_remove runs under pci_tsm_rwsem for write, with pci_tsm_pf0::lock
+ * for link devices or device::mutex for device-security operations.
*/
struct pci_tsm_ops {
struct module *owner;
const struct iommufd_viommu_ops *(*viommu_get_ops)(
struct device *dev, enum iommu_viommu_type type);
+ void (*prepare_remove)(struct pci_dev *pdev);
/*
* struct pci_tsm_link_ops - Manage physical link and the TSM/DSM session
@@ -165,6 +170,7 @@ void pci_tsm_unlock_association(struct pci_tsm *tsm);
void pci_tsm_set_ready(struct pci_tsm_pf0 *pf0, bool ready);
int pci_tsm_register(struct tsm_dev *tsm_dev);
void pci_tsm_unregister(struct tsm_dev *tsm_dev);
+void pci_tsm_prepare_unregister(struct tsm_dev *tsm_dev);
int pci_tsm_link_constructor(struct pci_dev *pdev, struct pci_tsm *tsm,
struct tsm_dev *tsm_dev);
int pci_tsm_pf0_constructor(struct pci_dev *pdev, struct pci_tsm_pf0 *pf0,
@@ -203,6 +209,10 @@ static inline void pci_tsm_unregister(struct tsm_dev *tsm_dev)
{
}
+static inline void pci_tsm_prepare_unregister(struct tsm_dev *tsm_dev)
+{
+}
+
static inline bool pci_tsm_is_configured(struct pci_dev *pdev)
{
return false;
--
2.43.0
^ permalink raw reply related [flat|nested] 18+ messages in thread* [PATCH v1 07/10] device core: Add helpers to record confidential device acceptance
2026-11-23 8:33 [PATCH v1 00/10] PCI/TSM: Support guest TSM drivers Aneesh Kumar K.V (Arm)
` (5 preceding siblings ...)
2026-11-23 8:33 ` [PATCH v1 06/10] PCI/TSM: Notify TSM drivers before waiting for TSM user references Aneesh Kumar K.V (Arm)
@ 2026-11-23 8:33 ` Aneesh Kumar K.V (Arm)
2026-11-23 8:42 ` Greg Kroah-Hartman
2026-11-23 8:33 ` [PATCH v1 08/10] PCI/TSM: Add sysfs lock and unlock for guest-assigned devices Aneesh Kumar K.V (Arm)
` (3 subsequent siblings)
10 siblings, 1 reply; 18+ messages in thread
From: Aneesh Kumar K.V (Arm) @ 2026-11-23 8:33 UTC (permalink / raw)
To: linux-coco
Cc: Aneesh Kumar K.V (Arm), Dan Williams, Leon Romanovsky,
Bjorn Helgaas, Jason Gunthorpe, Jonathan Cameron, Xu Yilun,
Alexey Kardashevskiy, Greg Kroah-Hartman, Rafael J . Wysocki,
Steven Price, Suzuki K Poulose, Lukas Wunner, Ashish Kalra,
Tom Lendacky, Herbert Xu, driver-core, linux-pci, kvm, patches
Add a flag to record whether a device is accepted for private memory
access, with helpers to set, clear and read it. Setting or clearing the
flag requires device::mutex and fails with -EBUSY if a driver is
attached.
Follow-up patches will have TSM drivers mark devices accepted after
verification and setup. PCI DMA setup will check this state before
allowing the device to access private memory.
Based on the original patch from Dan Williams <djbw@kernel.org>.
Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar@kernel.org>
---
MAINTAINERS | 1 +
drivers/base/Kconfig | 4 +++
drivers/base/Makefile | 1 +
drivers/base/base.h | 9 ++++++
drivers/base/coco.c | 68 ++++++++++++++++++++++++++++++++++++++++++
include/linux/device.h | 22 ++++++++++++++
6 files changed, 105 insertions(+)
create mode 100644 drivers/base/coco.c
diff --git a/MAINTAINERS b/MAINTAINERS
index a3ee234d79ae..142ba5af8798 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -28553,6 +28553,7 @@ T: git git://git.kernel.org/pub/scm/linux/kernel/git/tsm/linux.git
F: Documentation/ABI/testing/configfs-tsm-report
F: Documentation/driver-api/coco/
F: Documentation/driver-api/pci/tsm.rst
+F: drivers/base/coco.c
F: drivers/pci/tsm.c
F: drivers/virt/coco/guest/
F: drivers/virt/coco/tsm-core.c
diff --git a/drivers/base/Kconfig b/drivers/base/Kconfig
index a9acf4575f4f..be8d1484f210 100644
--- a/drivers/base/Kconfig
+++ b/drivers/base/Kconfig
@@ -242,4 +242,8 @@ config FW_DEVLINK_SYNC_STATE_TIMEOUT
command line option on every system/board your kernel is expected to
work on.
+config CONFIDENTIAL_DEVICES
+ depends on ARCH_HAS_CC_PLATFORM
+ bool
+
endmenu
diff --git a/drivers/base/Makefile b/drivers/base/Makefile
index 435710f643a5..8f5725e3e670 100644
--- a/drivers/base/Makefile
+++ b/drivers/base/Makefile
@@ -26,6 +26,7 @@ obj-$(CONFIG_DEV_COREDUMP) += devcoredump.o
obj-$(CONFIG_GENERIC_MSI_IRQ) += platform-msi.o
obj-$(CONFIG_GENERIC_ARCH_TOPOLOGY) += arch_topology.o
obj-$(CONFIG_ACPI) += physical_location.o
+obj-$(CONFIG_CONFIDENTIAL_DEVICES) += coco.o
obj-y += test/
diff --git a/drivers/base/base.h b/drivers/base/base.h
index 866b2beb6baa..97a9fcb10c97 100644
--- a/drivers/base/base.h
+++ b/drivers/base/base.h
@@ -108,8 +108,13 @@ struct driver_private {
* @dead: This device is currently either in the process of or has been
* removed from the system. Any asynchronous events scheduled for this
* device should exit without taking any action.
+ * @cc_accepted: Device accepted for private memory access. Bus code checks
+ * this state before enabling DMA during driver attachment.
*
* Nothing outside of the driver core should ever touch these fields.
+ *
+ * All bitfield flags are manipulated under device_lock() to avoid
+ * read-modify-write collisions.
*/
struct device_private {
struct klist klist_children;
@@ -122,6 +127,10 @@ struct device_private {
char *deferred_probe_reason;
struct device *device;
u8 dead:1;
+#ifdef CONFIG_CONFIDENTIAL_DEVICES
+ u8 cc_accepted:1;
+#endif
+
};
#define to_device_private_parent(obj) \
container_of(obj, struct device_private, knode_parent)
diff --git a/drivers/base/coco.c b/drivers/base/coco.c
new file mode 100644
index 000000000000..3e00bb37556e
--- /dev/null
+++ b/drivers/base/coco.c
@@ -0,0 +1,68 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (C) 2026 Intel Corporation */
+#include <linux/device.h>
+#include <linux/export.h>
+#include <linux/lockdep.h>
+#include "base.h"
+
+/*
+ * The device_cc_*() helpers record whether a device has been accepted for
+ * private memory access. Recording acceptance does not enable DMA. Bus code
+ * can check this state before enabling DMA during driver attachment.
+ */
+
+/**
+ * device_cc_accept() - Record acceptance for private memory access
+ * @dev: device to accept
+ *
+ * Call after the required verification and device setup have succeeded.
+ * This helper only records acceptance; it does not enable DMA.
+ *
+ * Context: The caller must hold dev->mutex. No driver may be attached.
+ * Return: 0 on success, or -EBUSY if a driver is attached.
+ */
+int device_cc_accept(struct device *dev)
+{
+ lockdep_assert_held(&dev->mutex);
+
+ if (dev->driver)
+ return -EBUSY;
+
+ dev->p->cc_accepted = 1;
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(device_cc_accept);
+
+/**
+ * device_cc_reject() - Clear acceptance for private memory access
+ * @dev: device whose acceptance state is cleared
+ *
+ * This helper only clears the recorded state; it does not disable DMA.
+ *
+ * Context: The caller must hold dev->mutex. No driver may be attached.
+ * Return: 0 on success, or -EBUSY if a driver is attached.
+ */
+int device_cc_reject(struct device *dev)
+{
+ lockdep_assert_held(&dev->mutex);
+
+ if (dev->driver)
+ return -EBUSY;
+
+ dev->p->cc_accepted = 0;
+
+ return 0;
+}
+
+/**
+ * device_cc_accepted() - Read the recorded acceptance state
+ * @dev: device to check
+ *
+ * Context: The caller must hold dev->mutex to serialize with state changes.
+ * Return: true if the device is accepted for private memory access.
+ */
+bool device_cc_accepted(struct device *dev)
+{
+ return dev->p->cc_accepted;
+}
diff --git a/include/linux/device.h b/include/linux/device.h
index 429e39f647cf..cf872935adae 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -1396,6 +1396,28 @@ static inline bool device_link_test(const struct device_link *link, u32 flags)
return !!(link->flags & flags);
}
+/* Confidential Device state helpers */
+#ifdef CONFIG_CONFIDENTIAL_DEVICES
+int device_cc_accept(struct device *dev);
+int device_cc_reject(struct device *dev);
+bool device_cc_accepted(struct device *dev);
+#else
+static inline int device_cc_accept(struct device *dev)
+{
+ lockdep_assert_held(&dev->mutex);
+ return 0;
+}
+static inline int device_cc_reject(struct device *dev)
+{
+ lockdep_assert_held(&dev->mutex);
+ return 0;
+}
+static inline bool device_cc_accepted(struct device *dev)
+{
+ return false;
+}
+#endif /* CONFIG_CONFIDENTIAL_DEVICES */
+
/* Create alias, so I can be autoloaded. */
#define MODULE_ALIAS_CHARDEV(major,minor) \
MODULE_ALIAS("char-major-" __stringify(major) "-" __stringify(minor))
--
2.43.0
^ permalink raw reply related [flat|nested] 18+ messages in thread* Re: [PATCH v1 07/10] device core: Add helpers to record confidential device acceptance
2026-11-23 8:33 ` [PATCH v1 07/10] device core: Add helpers to record confidential device acceptance Aneesh Kumar K.V (Arm)
@ 2026-11-23 8:42 ` Greg Kroah-Hartman
0 siblings, 0 replies; 18+ messages in thread
From: Greg Kroah-Hartman @ 2026-11-23 8:42 UTC (permalink / raw)
To: Aneesh Kumar K.V (Arm)
Cc: linux-coco, Dan Williams, Leon Romanovsky, Bjorn Helgaas,
Jason Gunthorpe, Jonathan Cameron, Xu Yilun, Alexey Kardashevskiy,
Rafael J . Wysocki, Steven Price, Suzuki K Poulose, Lukas Wunner,
Ashish Kalra, Tom Lendacky, Herbert Xu, driver-core, linux-pci,
kvm, patches
On Mon, Nov 23, 2026 at 02:03:34PM +0530, Aneesh Kumar K.V (Arm) wrote:
> Add a flag to record whether a device is accepted for private memory
> access, with helpers to set, clear and read it. Setting or clearing the
> flag requires device::mutex and fails with -EBUSY if a driver is
> attached.
>
> Follow-up patches will have TSM drivers mark devices accepted after
> verification and setup. PCI DMA setup will check this state before
> allowing the device to access private memory.
>
> Based on the original patch from Dan Williams <djbw@kernel.org>.
> Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar@kernel.org>
> ---
> MAINTAINERS | 1 +
> drivers/base/Kconfig | 4 +++
> drivers/base/Makefile | 1 +
> drivers/base/base.h | 9 ++++++
> drivers/base/coco.c | 68 ++++++++++++++++++++++++++++++++++++++++++
> include/linux/device.h | 22 ++++++++++++++
> 6 files changed, 105 insertions(+)
> create mode 100644 drivers/base/coco.c
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index a3ee234d79ae..142ba5af8798 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -28553,6 +28553,7 @@ T: git git://git.kernel.org/pub/scm/linux/kernel/git/tsm/linux.git
> F: Documentation/ABI/testing/configfs-tsm-report
> F: Documentation/driver-api/coco/
> F: Documentation/driver-api/pci/tsm.rst
> +F: drivers/base/coco.c
> F: drivers/pci/tsm.c
> F: drivers/virt/coco/guest/
> F: drivers/virt/coco/tsm-core.c
> diff --git a/drivers/base/Kconfig b/drivers/base/Kconfig
> index a9acf4575f4f..be8d1484f210 100644
> --- a/drivers/base/Kconfig
> +++ b/drivers/base/Kconfig
> @@ -242,4 +242,8 @@ config FW_DEVLINK_SYNC_STATE_TIMEOUT
> command line option on every system/board your kernel is expected to
> work on.
>
> +config CONFIDENTIAL_DEVICES
> + depends on ARCH_HAS_CC_PLATFORM
> + bool
> +
> endmenu
> diff --git a/drivers/base/Makefile b/drivers/base/Makefile
> index 435710f643a5..8f5725e3e670 100644
> --- a/drivers/base/Makefile
> +++ b/drivers/base/Makefile
> @@ -26,6 +26,7 @@ obj-$(CONFIG_DEV_COREDUMP) += devcoredump.o
> obj-$(CONFIG_GENERIC_MSI_IRQ) += platform-msi.o
> obj-$(CONFIG_GENERIC_ARCH_TOPOLOGY) += arch_topology.o
> obj-$(CONFIG_ACPI) += physical_location.o
> +obj-$(CONFIG_CONFIDENTIAL_DEVICES) += coco.o
>
> obj-y += test/
>
> diff --git a/drivers/base/base.h b/drivers/base/base.h
> index 866b2beb6baa..97a9fcb10c97 100644
> --- a/drivers/base/base.h
> +++ b/drivers/base/base.h
> @@ -108,8 +108,13 @@ struct driver_private {
> * @dead: This device is currently either in the process of or has been
> * removed from the system. Any asynchronous events scheduled for this
> * device should exit without taking any action.
> + * @cc_accepted: Device accepted for private memory access. Bus code checks
> + * this state before enabling DMA during driver attachment.
No, please do not do this, make this a "state" like the trusted device
series does.
> *
> * Nothing outside of the driver core should ever touch these fields.
> + *
> + * All bitfield flags are manipulated under device_lock() to avoid
> + * read-modify-write collisions.
Why is this added now?
> */
> struct device_private {
> struct klist klist_children;
> @@ -122,6 +127,10 @@ struct device_private {
> char *deferred_probe_reason;
> struct device *device;
> u8 dead:1;
> +#ifdef CONFIG_CONFIDENTIAL_DEVICES
> + u8 cc_accepted:1;
It's a bitfield, just always use it. But again, this isn't going to be
needed.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH v1 08/10] PCI/TSM: Add sysfs lock and unlock for guest-assigned devices
2026-11-23 8:33 [PATCH v1 00/10] PCI/TSM: Support guest TSM drivers Aneesh Kumar K.V (Arm)
` (6 preceding siblings ...)
2026-11-23 8:33 ` [PATCH v1 07/10] device core: Add helpers to record confidential device acceptance Aneesh Kumar K.V (Arm)
@ 2026-11-23 8:33 ` Aneesh Kumar K.V (Arm)
2026-11-23 8:33 ` [PATCH v1 09/10] PCI/TSM: Build encrypted MMIO descriptors from a supplied report Aneesh Kumar K.V (Arm)
` (2 subsequent siblings)
10 siblings, 0 replies; 18+ messages in thread
From: Aneesh Kumar K.V (Arm) @ 2026-11-23 8:33 UTC (permalink / raw)
To: linux-coco
Cc: Aneesh Kumar K.V (Arm), Dan Williams, Leon Romanovsky,
Bjorn Helgaas, Jason Gunthorpe, Jonathan Cameron, Xu Yilun,
Alexey Kardashevskiy, Greg Kroah-Hartman, Rafael J . Wysocki,
Steven Price, Suzuki K Poulose, Lukas Wunner, Ashish Kalra,
Tom Lendacky, Herbert Xu, driver-core, linux-pci, kvm, patches
A confidential guest needs to lock a PCI device before collecting and
verifying evidence about it. Userspace also needs a way to unlock the
device after use or when verification fails.
Add tsm/lock and tsm/unlock sysfs attributes for TSM drivers
implementing devsec_ops. Writing a TSM device name to tsm/lock calls its
lock callback. Unlock calls the matching driver's unlock callback
Take device::mutex to prevent driver attachment, then pci_tsm_rwsem
for write to protect pci_dev::tsm during either operation. This order
matches PCI DMA preparation, which runs with the device mutex held.
Return -EBUSY if a PCI driver is already attached. Also call unlock
during PCI device removal or TSM unregister, using the same lock order.
Guest TSM unregister processes one PCI device at a time and releases
both locks before moving to the next device.
Require ARCH_HAS_CC_PLATFORM and select CONFIDENTIAL_DEVICES so
pci_tsm_unlock() clears the device's accepted state.
Expose the TSM class device's pci_mode attribute so userspace can
distinguish host link TSM from guest device-security TSM. Evidence
retrieval and acceptance are handled separately through the attestation
subsystem.
Based on the original Device Security LOCK patch from
Dan Williams <djbw@kernel.org>, adapted to the current PCI/TSM structures
and locking rules.
Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar@kernel.org>
---
Documentation/ABI/testing/sysfs-bus-pci | 35 ++-
Documentation/ABI/testing/sysfs-class-tsm | 19 ++
Documentation/driver-api/pci/tsm.rst | 47 ++++
drivers/pci/Kconfig | 2 +
drivers/pci/tsm.c | 247 ++++++++++++++++++++--
drivers/virt/coco/tsm-core.c | 48 ++++-
include/linux/pci-tsm.h | 21 +-
7 files changed, 401 insertions(+), 18 deletions(-)
diff --git a/Documentation/ABI/testing/sysfs-bus-pci b/Documentation/ABI/testing/sysfs-bus-pci
index ab9083f3b0d3..0b13c6c53964 100644
--- a/Documentation/ABI/testing/sysfs-bus-pci
+++ b/Documentation/ABI/testing/sysfs-bus-pci
@@ -653,14 +653,17 @@ Description:
Encryption) establishment. Reads from this attribute return the
name of the connected TSM or the empty string if not
connected. A TSM device signals its readiness to accept PCI
- connection via a KOBJ_CHANGE event.
+ connection via a KOBJ_CHANGE event. This is a "link" TSM
+ attribute, see Documentation/ABI/testing/sysfs-class-tsm.
What: /sys/bus/pci/devices/.../tsm/disconnect
Contact: linux-coco@lists.linux.dev
Description:
(WO) Write the name of the TSM device that was specified
to 'connect' to teardown the connection.
- The write fails with EBUSY if the TSM is in use.
+ The write fails with EBUSY if the TSM is in use. This is a
+ "link" TSM attribute, see
+ Documentation/ABI/testing/sysfs-class-tsm.
What: /sys/bus/pci/devices/.../tsm/dsm
Contact: linux-coco@lists.linux.dev
@@ -695,3 +698,31 @@ Description:
When present and the tsm/ attribute directory is present, the
authenticated attribute is an alias for the device 'connect'
state. See the 'tsm/connect' attribute for more details.
+ This is a "link" TSM attribute, see
+ Documentation/ABI/testing/sysfs-class-tsm.
+
+What: /sys/bus/pci/devices/.../tsm/lock
+Contact: linux-coco@lists.linux.dev
+Description:
+ (RW) Write the name of a TSM (TEE Security Manager) device
+ instance to this file to request that the platform transition
+ the PCIe device configuration to the TDISP LOCKED state. This
+ puts the device in a state where security sensitive
+ configuration settings cannot be changed without transitioning
+ the device to the PCIe TDISP ERROR state. Reads from this attribute
+ return the name of the TSM device instance that has arranged for
+ the device to be locked, or the empty string if not locked. A
+ TSM class device signals its readiness for lock requests via a
+ KOBJ_CHANGE event. Writes fail with EBUSY if this device is
+ bound to a driver. This is a "devsec" TSM attribute, see
+ Documentation/ABI/testing/sysfs-class-tsm. See
+ Documentation/driver-api/pci/tsm.rst for more details.
+
+What: /sys/bus/pci/devices/.../tsm/unlock
+Contact: linux-coco@lists.linux.dev
+Description:
+ (WO) Write the name of the TSM device that was specified to
+ 'lock' to unlock the device configuration and release the TSM's
+ per-device state. Writes fail with EBUSY if this device is bound
+ to a driver. This is a "devsec" TSM
+ attribute, see Documentation/ABI/testing/sysfs-class-tsm.
diff --git a/Documentation/ABI/testing/sysfs-class-tsm b/Documentation/ABI/testing/sysfs-class-tsm
index 1ddb8f357961..76704501f082 100644
--- a/Documentation/ABI/testing/sysfs-class-tsm
+++ b/Documentation/ABI/testing/sysfs-class-tsm
@@ -20,3 +20,22 @@ Description:
Documentation/ABI/testing/sysfs-devices-pci-host-bridge for the
description of the pciDDDD:BB/streamH.R.E symlink and the
pciDDDD:BB/available_secure_streams attribute.
+
+What: /sys/class/tsm/tsmN/pci_mode
+Contact: linux-coco@lists.linux.dev
+Description:
+ (RO) A TSM with PCIe TDISP capability can be in one of two
+ modes.
+
+ "link": typically for a hypervisor (VMM) to authenticate,
+ establish a secure session, and setup link
+ encryption.
+
+ "devsec": typically for a confidential guest (TVM) to
+ transition assigned devices through the TDISP
+ state machine UNLOCKED->LOCKED->RUN.
+
+ See the "tsm/" entries in
+ Documentation/ABI/testing/sysfs-bus-pci for the available PCI
+ device attributes when a TSM with the given "pci_mode" is
+ registered.
diff --git a/Documentation/driver-api/pci/tsm.rst b/Documentation/driver-api/pci/tsm.rst
index 232b92bec93f..c9eec7b88144 100644
--- a/Documentation/driver-api/pci/tsm.rst
+++ b/Documentation/driver-api/pci/tsm.rst
@@ -5,6 +5,53 @@
PCI Trusted Execution Environment Security Manager (TSM)
========================================================
+Overview
+========
+
+A "TSM", as detailed by PCIe r7.0 section 11 "TEE Device Interface
+Security Protocol (TDISP)", is an entity within the platform's Trusted
+Computing Base (TCB) that enforces security policies on the host. It
+serves to mitigate a threat model where devices may be under the control
+of an adversary. The adversarial threats are:
+
+- Identity: Device may be mimicking a legitimate device identity / firmware
+- Physical: link may be under observation, or control (reorder / drop data)
+- Virtual: Device MMIO presented to a guest may not actually map the
+ device, device DMA may be redirected.
+
+Linux exposes a TSM class device and PCI sysfs attributes for the
+operations supported by its TSM driver. A host uses ``tsm/connect`` and
+``tsm/disconnect`` to request or release the TSM's connection to a device.
+A confidential guest uses ``tsm/lock`` and ``tsm/unlock`` to lock or unlock
+an assigned device's security-sensitive configuration.
+
+Successful connect or lock does not necessarily mean that userspace has
+verified the device or that it is ready for use. Userspace retrieves
+evidence through the attestation subsystem and verifies it before
+requesting device use through ``evidence-accept``.
+
+Device Interface LOCK
+=====================
+The lock operation facilitated by tsm/lock (see
+Documentation/ABI/testing/sysfs-bus-pci) places the device in a mode
+where any security sensitive changes to the device configuration results
+in the device transitioning to the ERROR state. Userspace retrieves
+evidence about the locked configuration through the attestation subsystem
+and verifies it before requesting device use.
+The relying party is responsible for verifying not only the evidence but
+that the device is trusted to maintain those attested values while
+locked. Accepting the locked configuration also asserts that device is
+trusted to cease TCB interactions (send T=1 DMA / accept T=1 MMIO TLPs)
+when it is subsequently unlocked. The TSM is responsible for enforcing
+that the device is not unlocked within the interval between evidence
+collection and acceptance, by correlating the evidence from LOCK to the
+subsequent RUN request.
+
+While the PCIe specification allows for the device to operate outside
+the TCB when locked, depending on the TSM architecture implementation,
+T=0 DMA from the device may be blocked until the device is next
+unlocked.
+
Subsystem Interfaces
====================
diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig
index 0c7408509ba2..f7b7a6e269a2 100644
--- a/drivers/pci/Kconfig
+++ b/drivers/pci/Kconfig
@@ -126,6 +126,8 @@ config PCI_IDE
config PCI_TSM
bool "PCI TSM: Device security protocol support"
+ depends on ARCH_HAS_CC_PLATFORM
+ select CONFIDENTIAL_DEVICES
select PCI_IDE
select PCI_DOE
select TSM
diff --git a/drivers/pci/tsm.c b/drivers/pci/tsm.c
index f04498265383..2fbd146db387 100644
--- a/drivers/pci/tsm.c
+++ b/drivers/pci/tsm.c
@@ -9,6 +9,7 @@
#define dev_fmt(fmt) "PCI/TSM: " fmt
#include <linux/bitfield.h>
+#include <linux/ioport.h>
#include <linux/iommufd.h>
#include <linux/jiffies.h>
#include <linux/module.h>
@@ -88,6 +89,25 @@ static struct pci_tsm_pf0 *to_pci_tsm_pf0(struct pci_tsm *tsm)
return container_of(pf0->tsm, struct pci_tsm_pf0, base_tsm);
}
+static inline bool is_devsec(struct pci_dev *pdev)
+{
+ return pdev->tsm && pdev->tsm->dsm_dev == NULL;
+}
+
+/* 'struct pci_tsm_devsec' wraps 'struct pci_tsm' when ->dsm_dev == NULL */
+struct pci_tsm_devsec *to_pci_tsm_devsec(struct pci_tsm *tsm)
+{
+ struct pci_dev *pdev = tsm->pdev;
+
+ if (!is_devsec(pdev) || !has_tee(pdev)) {
+ pci_WARN_ONCE(pdev, 1, "invalid context object\n");
+ return NULL;
+ }
+
+ return container_of(tsm, struct pci_tsm_devsec, base_tsm);
+}
+EXPORT_SYMBOL_GPL(to_pci_tsm_devsec);
+
static void tsm_remove(struct pci_tsm *tsm)
{
struct pci_dev *pdev;
@@ -630,6 +650,128 @@ static ssize_t dsm_show(struct device *dev, struct device_attribute *attr,
}
static DEVICE_ATTR_RO(dsm);
+/**
+ * pci_tsm_unlock() - Transition TDI from LOCKED/RUN to UNLOCKED
+ * @pdev: TDI device to unlock
+ *
+ * Returns void, requires all callers to have satisfied dependencies like making
+ * sure the device is locked and detached from its driver.
+ */
+static void pci_tsm_unlock(struct pci_dev *pdev)
+{
+ lockdep_assert_held_write(&pci_tsm_rwsem);
+ device_lock_assert(&pdev->dev);
+
+ if (dev_WARN_ONCE(&pdev->dev, pdev->dev.driver,
+ "unlock attempted on driver attached device\n"))
+ return;
+
+ device_cc_reject(&pdev->dev);
+ to_pci_tsm_ops(pdev->tsm)->unlock(pdev->tsm);
+ pdev->tsm = NULL;
+}
+
+static int pci_tsm_lock(struct pci_dev *pdev, struct tsm_dev *tsm_dev)
+{
+ const struct pci_tsm_ops *ops = tsm_dev->pci_ops;
+ struct pci_tsm *tsm;
+
+ device_lock_assert(&pdev->dev);
+ lockdep_assert_held_write(&pci_tsm_rwsem);
+
+ if (pdev->dev.driver)
+ return -EBUSY;
+
+ tsm = ops->lock(tsm_dev, pdev);
+ if (IS_ERR(tsm))
+ return PTR_ERR(tsm);
+
+ pdev->tsm = tsm;
+ return 0;
+}
+
+static ssize_t lock_store(struct device *dev, struct device_attribute *attr,
+ const char *buf, size_t len)
+{
+ struct pci_dev *pdev = to_pci_dev(dev);
+ int rc, id;
+
+ rc = sscanf(buf, "tsm%d\n", &id);
+ if (rc != 1)
+ return -EINVAL;
+
+ ACQUIRE(device_intr, dev_lock)(&pdev->dev);
+ if ((rc = ACQUIRE_ERR(device_intr, &dev_lock)))
+ return rc;
+
+ ACQUIRE(rwsem_write_kill, lock)(&pci_tsm_rwsem);
+ if ((rc = ACQUIRE_ERR(rwsem_write_kill, &lock)))
+ return rc;
+
+ if (pdev->tsm)
+ return -EBUSY;
+
+ struct tsm_dev *tsm_dev __free(put_tsm_dev) = find_tsm_dev(id);
+ if (!is_devsec_tsm(tsm_dev))
+ return -ENXIO;
+
+ rc = pci_tsm_lock(pdev, tsm_dev);
+ if (rc)
+ return rc;
+
+ return len;
+}
+
+static ssize_t lock_show(struct device *dev, struct device_attribute *attr,
+ char *buf)
+{
+ struct pci_dev *pdev = to_pci_dev(dev);
+ struct tsm_dev *tsm_dev;
+ int rc;
+
+ ACQUIRE(rwsem_read_intr, lock)(&pci_tsm_rwsem);
+ if ((rc = ACQUIRE_ERR(rwsem_read_intr, &lock)))
+ return rc;
+
+ if (!pdev->tsm)
+ return sysfs_emit(buf, "\n");
+
+ tsm_dev = pdev->tsm->tsm_dev;
+ return sysfs_emit(buf, "%s\n", dev_name(&tsm_dev->dev));
+}
+static DEVICE_ATTR_RW(lock);
+
+static ssize_t unlock_store(struct device *dev, struct device_attribute *attr,
+ const char *buf, size_t len)
+{
+ struct pci_dev *pdev = to_pci_dev(dev);
+ struct tsm_dev *tsm_dev;
+ int rc;
+
+ ACQUIRE(device_intr, dev_lock)(&pdev->dev);
+ if ((rc = ACQUIRE_ERR(device_intr, &dev_lock)))
+ return rc;
+
+ ACQUIRE(rwsem_write_kill, lock)(&pci_tsm_rwsem);
+ if ((rc = ACQUIRE_ERR(rwsem_write_kill, &lock)))
+ return rc;
+
+ if (!pdev->tsm)
+ return -EINVAL;
+
+ tsm_dev = pdev->tsm->tsm_dev;
+ if (!sysfs_streq(buf, dev_name(&tsm_dev->dev)))
+ return -EINVAL;
+
+ if (pdev->dev.driver)
+ return -EBUSY;
+
+ pci_tsm_unlock(pdev);
+
+ return len;
+}
+static DEVICE_ATTR_WO(unlock);
+
/* The 'authenticated' attribute is exclusive to the presence of a 'link' TSM */
static bool pci_tsm_link_group_visible(struct kobject *kobj)
{
@@ -655,6 +797,13 @@ static bool pci_tsm_link_group_visible(struct kobject *kobj)
}
DEFINE_SIMPLE_SYSFS_GROUP_VISIBLE(pci_tsm_link);
+static bool pci_tsm_devsec_group_visible(struct kobject *kobj)
+{
+ struct pci_dev *pdev = to_pci_dev(kobj_to_dev(kobj));
+
+ return pci_tsm_devsec_count && has_tee(pdev);
+}
+
/*
* 'link' and 'devsec' TSMs share the same 'tsm/' sysfs group, so the TSM type
* specific attributes need individual visibility checks.
@@ -679,12 +828,19 @@ static umode_t pci_tsm_attr_visible(struct kobject *kobj,
}
}
+ if (pci_tsm_devsec_group_visible(kobj)) {
+ if (attr == &dev_attr_lock.attr ||
+ attr == &dev_attr_unlock.attr)
+ return attr->mode;
+ }
+
return 0;
}
static bool pci_tsm_group_visible(struct kobject *kobj)
{
- return pci_tsm_link_group_visible(kobj);
+ return pci_tsm_link_group_visible(kobj) ||
+ pci_tsm_devsec_group_visible(kobj);
}
DEFINE_SYSFS_GROUP_VISIBLE(pci_tsm);
@@ -692,6 +848,8 @@ static struct attribute *pci_tsm_attrs[] = {
&dev_attr_connect.attr,
&dev_attr_disconnect.attr,
&dev_attr_dsm.attr,
+ &dev_attr_lock.attr,
+ &dev_attr_unlock.attr,
NULL
};
@@ -804,6 +962,28 @@ int pci_tsm_link_constructor(struct pci_dev *pdev, struct pci_tsm *tsm,
}
EXPORT_SYMBOL_GPL(pci_tsm_link_constructor);
+/**
+ * pci_tsm_devsec_constructor() - devsec TSM context initialization
+ * @pdev: The PCI device
+ * @devsec: Device-security state to initialize
+ * @tsm_dev: Platform TEE Security Manager, initiator of security operations
+ */
+int pci_tsm_devsec_constructor(struct pci_dev *pdev, struct pci_tsm_devsec *devsec,
+ struct tsm_dev *tsm_dev)
+{
+ struct pci_tsm *pci_tsm = &devsec->base_tsm;
+
+ if (!is_devsec_tsm(tsm_dev))
+ return -EINVAL;
+
+ pci_tsm->dsm_dev = NULL;
+ pci_tsm->pdev = pdev;
+ pci_tsm->tsm_dev = tsm_dev;
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(pci_tsm_devsec_constructor);
+
/**
* pci_tsm_pf0_constructor() - common 'struct pci_tsm_pf0' (DSM) initialization
* @pdev: Physical Function 0 PCI device (as indicated by is_pci_tsm_pf0())
@@ -837,6 +1017,13 @@ void pci_tsm_pf0_destructor(struct pci_tsm_pf0 *pf0)
}
EXPORT_SYMBOL_GPL(pci_tsm_pf0_destructor);
+static void devsec_sysfs_enable(struct pci_dev *pdev)
+{
+ pci_dbg(pdev, "TEE I/O Device capability detected (TDISP)\n");
+
+ sysfs_update_group(&pdev->dev.kobj, &pci_tsm_attr_group);
+}
+
int pci_tsm_register(struct tsm_dev *tsm_dev)
{
struct pci_dev *pdev = NULL;
@@ -858,8 +1045,10 @@ int pci_tsm_register(struct tsm_dev *tsm_dev)
for_each_pci_dev(pdev)
if (is_pci_tsm_pf0(pdev))
link_sysfs_enable(pdev);
- } else if (is_devsec_tsm(tsm_dev)) {
- pci_tsm_devsec_count++;
+ } else if (is_devsec_tsm(tsm_dev) && pci_tsm_devsec_count++ == 0) {
+ for_each_pci_dev(pdev)
+ if (has_tee(pdev))
+ devsec_sysfs_enable(pdev);
}
return 0;
@@ -888,6 +1077,9 @@ static void __pci_tsm_destroy(struct pci_dev *pdev, struct tsm_dev *tsm_dev)
if (is_link_tsm(tsm_dev) && is_pci_tsm_pf0(pdev) && !pci_tsm_link_count)
link_sysfs_disable(pdev);
+ if (is_devsec_tsm(tsm_dev) && !pci_tsm_devsec_count)
+ sysfs_update_group(&pdev->dev.kobj, &pci_tsm_attr_group);
+
/* Nothing else to do if this device never attached to the departing TSM */
if (!tsm)
return;
@@ -898,11 +1090,19 @@ static void __pci_tsm_destroy(struct pci_dev *pdev, struct tsm_dev *tsm_dev)
else if (tsm_dev != tsm->tsm_dev)
return;
- if (is_link_tsm(tsm_dev) && is_pci_tsm_pf0(pdev)) {
- if (pci_tsm_disconnect(pdev))
- pci_warn(pdev, "TSM connection is still in use\n");
- } else {
- tsm_remove(pdev->tsm);
+ /* Disconnect DSMs, unlock assigned TDIs, or clean up subfunctions. */
+ if (is_link_tsm(tsm_dev)) {
+ if (is_pci_tsm_pf0(pdev)) {
+ if (pci_tsm_disconnect(pdev))
+ pci_warn(pdev, "TSM connection is still in use\n");
+ } else {
+ tsm_remove(pdev->tsm);
+ }
+ }
+
+ if (is_devsec_tsm(tsm_dev) && has_tee(pdev)) {
+ device_lock_assert(&pdev->dev);
+ pci_tsm_unlock(pdev);
}
}
@@ -926,7 +1126,17 @@ void pci_tsm_destroy(struct pci_dev *pdev)
struct tsm_dev *tsm_dev = NULL;
bool registration_locked = false;
- down_write(&pci_tsm_rwsem);
+ /* Guest cleanup takes the device mutex before the PCI/TSM writer. */
+ scoped_guard(device, &pdev->dev) {
+ down_write(&pci_tsm_rwsem);
+ if (pdev->tsm && is_devsec_tsm(pdev->tsm->tsm_dev)) {
+ __pci_tsm_destroy(pdev, NULL);
+ up_write(&pci_tsm_rwsem);
+ return;
+ }
+ }
+
+ /* Host cleanup must not retain the device mutex while waiting for users. */
if (pdev->tsm && is_link_tsm(pdev->tsm->tsm_dev) &&
is_pci_tsm_pf0(pdev)) {
struct pci_tsm_pf0 *pf0 = to_pci_tsm_pf0(pdev->tsm);
@@ -1082,11 +1292,22 @@ void pci_tsm_unregister(struct tsm_dev *tsm_dev)
{
struct pci_dev *pdev = NULL;
+ if (is_devsec_tsm(tsm_dev)) {
+ scoped_guard(rwsem_write, &pci_tsm_rwsem)
+ pci_tsm_devsec_count--;
+
+ for_each_pci_dev_reverse(pdev) {
+ guard(device)(&pdev->dev);
+ guard(rwsem_write)(&pci_tsm_rwsem);
+
+ __pci_tsm_destroy(pdev, tsm_dev);
+ }
+
+ return;
+ }
+
guard(rwsem_write)(&pci_tsm_rwsem);
- if (is_link_tsm(tsm_dev))
- pci_tsm_link_count--;
- if (is_devsec_tsm(tsm_dev))
- pci_tsm_devsec_count--;
+ pci_tsm_link_count--;
for_each_pci_dev_reverse(pdev)
__pci_tsm_destroy(pdev, tsm_dev);
}
diff --git a/drivers/virt/coco/tsm-core.c b/drivers/virt/coco/tsm-core.c
index ba9183783dd1..b7a0e85bbad7 100644
--- a/drivers/virt/coco/tsm-core.c
+++ b/drivers/virt/coco/tsm-core.c
@@ -10,10 +10,11 @@
#include <linux/cleanup.h>
#include <linux/jiffies.h>
#include <linux/pci-tsm.h>
-#include <linux/pci-ide.h>
#include <linux/pid.h>
#include <linux/sched.h>
+#include <linux/pci-ide.h>
+
/* The caller must hold a tsm_get_device() reference for the entire use. */
const struct iommufd_viommu_ops *tsm_viommu_get_ops(struct tsm_dev *tsm_dev,
struct device *dev, enum iommu_viommu_type type)
@@ -25,10 +26,53 @@ const struct iommufd_viommu_ops *tsm_viommu_get_ops(struct tsm_dev *tsm_dev,
}
EXPORT_SYMBOL_GPL(tsm_viommu_get_ops);
+static ssize_t pci_mode_show(struct device *dev, struct device_attribute *attr,
+ char *buf)
+{
+ struct tsm_dev *tsm_dev = container_of(dev, struct tsm_dev, dev);
+ const struct pci_tsm_ops *ops = tsm_dev->pci_ops;
+
+ if (ops->connect)
+ return sysfs_emit(buf, "link\n");
+
+ if (ops->lock)
+ return sysfs_emit(buf, "devsec\n");
+
+ return sysfs_emit(buf, "none\n");
+}
+static DEVICE_ATTR_RO(pci_mode);
+
+static umode_t tsm_pci_visible(struct kobject *kobj, struct attribute *attr, int n)
+{
+ struct device *dev = container_of(kobj, struct device, kobj);
+ struct tsm_dev *tsm_dev = container_of(dev, struct tsm_dev, dev);
+
+ if (tsm_dev->pci_ops)
+ return attr->mode;
+
+ return 0;
+}
+
+static struct attribute *tsm_pci_attrs[] = {
+ &dev_attr_pci_mode.attr,
+ NULL
+};
+
+static const struct attribute_group tsm_pci_group = {
+ .attrs = tsm_pci_attrs,
+ .is_visible = tsm_pci_visible,
+};
+
+static const struct attribute_group *tsm_pci_groups[] = {
+ &tsm_pci_group,
+ NULL
+};
+
static void tsm_release(struct device *);
static const struct class tsm_class = {
.name = "tsm",
- .dev_release = tsm_release
+ .dev_release = tsm_release,
+ .dev_groups = tsm_pci_groups,
};
static DEFINE_IDA(tsm_ida);
diff --git a/include/linux/pci-tsm.h b/include/linux/pci-tsm.h
index 75df64a2e97d..c43aa3e85bb0 100644
--- a/include/linux/pci-tsm.h
+++ b/include/linux/pci-tsm.h
@@ -78,7 +78,8 @@ struct pci_tsm_ops {
* @unlock: destroy TSM context and return device to UNLOCKED state
*
* Context: @lock and @unlock run under pci_tsm_rwsem held for write to
- * sync with TSM unregistration and each other
+ * sync with TSM unregistration and each other. All operations run under
+ * the device lock for mutual exclusion with driver attach and detach.
*/
struct_group_tagged(pci_tsm_devsec_ops, devsec_ops,
struct pci_tsm *(*lock)(struct tsm_dev *tsm_dev,
@@ -103,6 +104,13 @@ struct pci_tsm_ops {
* sub-function (SR-IOV virtual function, or non-function0
* multifunction-device), or a downstream endpoint (PCIe upstream switch-port as
* DSM).
+ *
+ * For devsec operations it serves to indicate that the function / TDI has been
+ * locked to a given TSM.
+ *
+ * The common expectation is that there is only ever one TSM, but this is not
+ * enforced. The implementation only enforces that a device can be "connected"
+ * to a TSM instance or "locked" to a different TSM.
*/
struct pci_tsm {
struct pci_dev *pdev;
@@ -131,6 +139,14 @@ struct pci_tsm_pf0 {
struct pci_doe_mb *doe_mb;
};
+/**
+ * struct pci_tsm_devsec - context for tracking private/accepted PCI resources
+ * @base_tsm: generic core "tsm" context
+ */
+struct pci_tsm_devsec {
+ struct pci_tsm base_tsm;
+};
+
/* physical function0 and capable of 'connect' */
static inline bool is_pci_tsm_pf0(struct pci_dev *pdev)
{
@@ -175,6 +191,8 @@ int pci_tsm_link_constructor(struct pci_dev *pdev, struct pci_tsm *tsm,
struct tsm_dev *tsm_dev);
int pci_tsm_pf0_constructor(struct pci_dev *pdev, struct pci_tsm_pf0 *pf0,
struct tsm_dev *tsm_dev);
+int pci_tsm_devsec_constructor(struct pci_dev *pdev, struct pci_tsm_devsec *devsec,
+ struct tsm_dev *tsm_dev);
void pci_tsm_pf0_destructor(struct pci_tsm_pf0 *pf0);
int pci_tsm_doe_transfer(struct pci_dev *pdev, u8 type, const void *req,
size_t req_sz, void *resp, size_t resp_sz);
@@ -187,6 +205,7 @@ struct pci_dev *pci_tsm_context_dsm_dev(struct pci_tsm_context *context);
bool pci_tsm_context_match_device(struct pci_tsm_context *context,
struct pci_dev *pdev);
struct tsm_dev *pci_tsm_get_device(struct pci_dev *pdev);
+struct pci_tsm_devsec *to_pci_tsm_devsec(struct pci_tsm *tsm);
#else
static inline struct pci_tsm *pci_tsm_trylock_association(struct pci_tsm *tsm)
{
--
2.43.0
^ permalink raw reply related [flat|nested] 18+ messages in thread* [PATCH v1 09/10] PCI/TSM: Build encrypted MMIO descriptors from a supplied report
2026-11-23 8:33 [PATCH v1 00/10] PCI/TSM: Support guest TSM drivers Aneesh Kumar K.V (Arm)
` (7 preceding siblings ...)
2026-11-23 8:33 ` [PATCH v1 08/10] PCI/TSM: Add sysfs lock and unlock for guest-assigned devices Aneesh Kumar K.V (Arm)
@ 2026-11-23 8:33 ` Aneesh Kumar K.V (Arm)
2026-11-23 8:33 ` [PATCH v1 10/10] PCI/TSM: Configure accepted device DMA during driver attachment Aneesh Kumar K.V (Arm)
2026-11-23 8:40 ` [PATCH v1 00/10] PCI/TSM: Support guest TSM drivers Greg Kroah-Hartman
10 siblings, 0 replies; 18+ messages in thread
From: Aneesh Kumar K.V (Arm) @ 2026-11-23 8:33 UTC (permalink / raw)
To: linux-coco
Cc: Aneesh Kumar K.V (Arm), Dan Williams, Leon Romanovsky,
Bjorn Helgaas, Jason Gunthorpe, Jonathan Cameron, Xu Yilun,
Alexey Kardashevskiy, Greg Kroah-Hartman, Rafael J . Wysocki,
Steven Price, Suzuki K Poulose, Lukas Wunner, Ashish Kalra,
Tom Lendacky, Herbert Xu, driver-core, linux-pci, kvm, patches
The TDISP Device Interface Report describes a device interface's
configuration, including its MMIO ranges and their attributes. Each MMIO
range identifies its BAR, starting physical address and size.
The device adds the MMIO Reporting Offset (MRO) to the physical
addresses included in the report. When the MRO is a multiple of the BAR
size, masking the reported address by the BAR size recovers the offset
within that BAR. Combining this offset with the guest's PCI resource
start gives the corresponding guest physical address.
TSM drivers need to parse these reports and identify the MMIO ranges
requiring private mappings. Provide common PCI/TSM helpers so each
driver does not have to implement the same parsing and resource setup.
Add pci_tsm_mmio_alloc_report() to parse a caller-supplied report.
Record each range's guest physical address and retain its reported
address for firmware mapping validation. Skip non-TEE and currently
unsupported MSI-X ranges.
Add helpers to register the ranges in iomem with IORES_DESC_ENCRYPTED,
Setup requires device::mutex and rejects devices with a PCI driver
attached.
A later guest attestation patch uses these helpers during
evidence-accept. The caller remains responsible for verifying the report
and validating the MMIO mappings before allowing device use.
Based on the original patch from Dan Williams <djbw@kernel.org>
Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar@kernel.org>
---
drivers/pci/tsm.c | 227 ++++++++++++++++++++++++++++++++++++++++
include/linux/ioport.h | 1 +
include/linux/pci-tsm.h | 35 +++++++
3 files changed, 263 insertions(+)
diff --git a/drivers/pci/tsm.c b/drivers/pci/tsm.c
index 2fbd146db387..c21066e55d3b 100644
--- a/drivers/pci/tsm.c
+++ b/drivers/pci/tsm.c
@@ -21,6 +21,7 @@
#include <linux/slab.h>
#include <linux/sysfs.h>
#include <linux/tsm.h>
+#include <linux/unaligned.h>
#include <linux/xarray.h>
#include "pci.h"
@@ -650,6 +651,232 @@ static ssize_t dsm_show(struct device *dev, struct device_attribute *attr,
}
static DEVICE_ATTR_RO(dsm);
+static void mmio_teardown(struct pci_tsm_mmio *mmio, int nr)
+{
+ while (nr--)
+ remove_resource(pci_tsm_mmio_resource(mmio, nr));
+}
+
+/**
+ * pci_tsm_mmio_setup() - mark device MMIO as encrypted in iomem
+ * @pdev: device owner of MMIO resources
+ * @mmio: container of an array of resources to mark encrypted
+ */
+int pci_tsm_mmio_setup(struct pci_dev *pdev, struct pci_tsm_mmio *mmio)
+{
+ int i;
+
+ device_lock_assert(&pdev->dev);
+ if (pdev->dev.driver)
+ return -EBUSY;
+
+ for (i = 0; i < mmio->nr; i++) {
+ struct resource *res = pci_tsm_mmio_resource(mmio, i);
+ int j;
+
+ if (resource_size(res) == 0 || !res->end)
+ break;
+
+ /* Only require the caller to set the range, init remainder */
+ *res = DEFINE_RES_NAMED_DESC(res->start, resource_size(res),
+ "PCI MMIO Encrypted",
+ IORESOURCE_MEM,
+ IORES_DESC_ENCRYPTED);
+
+ for (j = 0; j < PCI_NUM_RESOURCES; j++)
+ if (resource_contains(pci_resource_n(pdev, j), res))
+ break;
+
+ /* Request is outside of device MMIO */
+ if (j >= PCI_NUM_RESOURCES)
+ break;
+
+ if (insert_resource(&iomem_resource, res) != 0)
+ break;
+ }
+
+ if (i >= mmio->nr)
+ return 0;
+
+ mmio_teardown(mmio, i);
+
+ return -EINVAL;
+}
+EXPORT_SYMBOL_GPL(pci_tsm_mmio_setup);
+
+void pci_tsm_mmio_teardown(struct pci_tsm_mmio *mmio)
+{
+ mmio_teardown(mmio, mmio->nr);
+}
+EXPORT_SYMBOL_GPL(pci_tsm_mmio_teardown);
+
+/*
+ * PCIe ECN TEE Device Interface Security Protocol (TDISP)
+ *
+ * Device Interface Report data object layout as defined by PCIe r7.0 section
+ * 11.3.11
+ */
+#define PCI_TSM_DEVIF_REPORT_MMIO_ATTR_MSIX_TABLE BIT(0)
+#define PCI_TSM_DEVIF_REPORT_MMIO_ATTR_MSIX_PBA BIT(1)
+#define PCI_TSM_DEVIF_REPORT_MMIO_ATTR_IS_NON_TEE BIT(2)
+#define PCI_TSM_DEVIF_REPORT_MMIO_ATTR_IS_UPDATABLE BIT(3)
+#define PCI_TSM_DEVIF_REPORT_MMIO_ATTR_RANGE_ID GENMASK(31, 16)
+
+/* An interface report 'pfn' is 4K in size */
+struct pci_tsm_devif_mmio {
+ __le64 pfn;
+ __le32 nr_pfns;
+ __le32 attributes;
+};
+
+struct pci_tsm_devif_report {
+ __le16 interface_info;
+ __le16 reserved;
+ __le16 msi_x_message_control;
+ __le16 lnr_control;
+ __le32 tph_control;
+ __le32 mmio_range_count;
+ struct pci_tsm_devif_mmio mmio[];
+};
+
+/**
+ * pci_tsm_mmio_alloc_report() - allocate encrypted MMIO range descriptor
+ * @pdev: device owner of MMIO ranges
+ * @report_data: TDISP Device Interface (DevIf) Report blob
+ * @report_sz: DevIf Report size
+ *
+ * Return: the encrypted MMIO range descriptor on success, NULL on failure
+ *
+ * The caller keeps pdev->tsm valid throughout this call.
+ */
+struct pci_tsm_mmio *pci_tsm_mmio_alloc_report(struct pci_dev *pdev,
+ const void *report_data, size_t report_sz)
+{
+ struct pci_tsm *tsm = pdev->tsm;
+ struct tsm_dev *tsm_dev = tsm->tsm_dev;
+ u64 last_reporting_end;
+ const struct pci_tsm_devif_report *report;
+ u32 mmio_range_count;
+ int last_bar = -1;
+ int i;
+
+ if (report_sz < sizeof(struct pci_tsm_devif_report))
+ return NULL;
+
+ if (dev_WARN_ONCE(&tsm_dev->dev, !IS_ALIGNED((unsigned long) report_data, 8),
+ "misaligned report data\n"))
+ return NULL;
+
+ report = report_data;
+ mmio_range_count = __le32_to_cpu(report->mmio_range_count);
+
+ /* check that the report object is self-consistent on mmio entries */
+ if (report_sz < struct_size(report, mmio, mmio_range_count))
+ return NULL;
+
+ /* create pci_tsm_mmio descriptors from the report data */
+ struct pci_tsm_mmio *mmio __free(kfree) =
+ kzalloc(struct_size(mmio, mmio, mmio_range_count), GFP_KERNEL);
+ if (!mmio)
+ return NULL;
+
+ for (i = 0; i < mmio_range_count; i++) {
+ u64 range_off;
+ struct range range;
+ const struct pci_tsm_devif_mmio *mmio_data = &report->mmio[i];
+ struct pci_tsm_mmio_entry *entry;
+ /* report values in are in terms of 4K pages */
+ u64 tsm_offset = __le64_to_cpu(mmio_data->pfn) * SZ_4K;
+ u64 size = (u64)__le32_to_cpu(mmio_data->nr_pfns) * SZ_4K;
+ u32 attr = __le32_to_cpu(mmio_data->attributes);
+ int bar = FIELD_GET(PCI_TSM_DEVIF_REPORT_MMIO_ATTR_RANGE_ID,
+ attr);
+
+ if (bar >= PCI_STD_NUM_BARS ||
+ !(pci_resource_flags(pdev, bar) & IORESOURCE_MEM)) {
+ pci_dbg(pdev, "Invalid reporting bar ID %d\n", bar);
+ return NULL;
+ }
+
+ if (last_bar > bar) {
+ pci_dbg(pdev, "Reporting bar ID not in ascending order\n");
+ return NULL;
+ }
+
+ if (last_bar < bar) {
+ /* transition to a new bar */
+ last_bar = bar;
+ } else if (tsm_offset < last_reporting_end) {
+ pci_dbg(pdev, "Reporting ranges within BAR not in ascending order\n");
+ return NULL;
+ }
+
+ last_reporting_end = tsm_offset + size;
+ if (last_reporting_end < tsm_offset) {
+ pci_dbg(pdev, "Reporting range overflow\n");
+ return NULL;
+ }
+
+ range_off = tsm_offset & (pci_resource_len(pdev, bar) - 1);
+
+ if (pci_resource_len(pdev, bar) < range_off + size) {
+ pci_dbg(pdev, "Reporting range larger than BAR size\n");
+ return NULL;
+ }
+
+ range.start = pci_resource_start(pdev, bar) + range_off;
+ range.end = range.start + size - 1;
+
+ if (FIELD_GET(PCI_TSM_DEVIF_REPORT_MMIO_ATTR_IS_NON_TEE,
+ attr)) {
+ pci_dbg(pdev, "Skipping non-TEE range, BAR%d %pra\n",
+ bar, &range);
+ continue;
+ }
+
+ /* Currently not supported */
+ if (FIELD_GET(PCI_TSM_DEVIF_REPORT_MMIO_ATTR_MSIX_TABLE,
+ attr) ||
+ FIELD_GET(PCI_TSM_DEVIF_REPORT_MMIO_ATTR_MSIX_PBA, attr)) {
+ pci_dbg(pdev, "Skipping MSIX range BAR%d %pra\n", bar,
+ &range);
+ continue;
+ }
+
+ /* Update __counted_by(nr) before accessing the new entry. */
+ mmio->nr++;
+ entry = pci_tsm_mmio_entry(mmio, mmio->nr - 1);
+ entry->res.start = range.start;
+ entry->res.end = range.end;
+ entry->tsm_offset = tsm_offset;
+ }
+
+ return_ptr(mmio);
+}
+EXPORT_SYMBOL_GPL(pci_tsm_mmio_alloc_report);
+
+/**
+ * pci_tsm_mmio_free() - free a pci_tsm_mmio instance
+ * @pdev: device owner of MMIO ranges
+ * @mmio: instance to free
+ *
+ * Returns 0 if @mmio was idle on entry, -EBUSY otherwise
+ */
+int pci_tsm_mmio_free(struct pci_dev *pdev, struct pci_tsm_mmio *mmio)
+{
+ for (int i = 0; i < mmio->nr; i++) {
+ struct resource *res = pci_tsm_mmio_resource(mmio, i);
+
+ if (dev_WARN_ONCE(&pdev->dev, resource_assigned(res),
+ "MMIO resource still assigned %pr\n", res))
+ return -EBUSY;
+ }
+
+ kfree(mmio);
+ return 0;
+}
+EXPORT_SYMBOL_GPL(pci_tsm_mmio_free);
+
/**
* pci_tsm_unlock() - Transition TDI from LOCKED/RUN to UNLOCKED
* @pdev: TDI device to unlock
diff --git a/include/linux/ioport.h b/include/linux/ioport.h
index f7930b3dfd0a..e8a9fd653620 100644
--- a/include/linux/ioport.h
+++ b/include/linux/ioport.h
@@ -144,6 +144,7 @@ enum {
IORES_DESC_RESERVED = 7,
IORES_DESC_SOFT_RESERVED = 8,
IORES_DESC_CXL = 9,
+ IORES_DESC_ENCRYPTED = 10,
};
/*
diff --git a/include/linux/pci-tsm.h b/include/linux/pci-tsm.h
index c43aa3e85bb0..aef6cfb87082 100644
--- a/include/linux/pci-tsm.h
+++ b/include/linux/pci-tsm.h
@@ -139,12 +139,42 @@ struct pci_tsm_pf0 {
struct pci_doe_mb *doe_mb;
};
+/**
+ * struct pci_tsm_mmio_entry - an encrypted MMIO range
+ * @res: MMIO address range (typically Guest Physical Address, GPA)
+ * @tsm_offset: Host Physical Address, HPA obfuscation offset added by the TSM.
+ * Translates report addresses to GPA.
+ */
+struct pci_tsm_mmio_entry {
+ struct resource res;
+ u64 tsm_offset;
+};
+
+struct pci_tsm_mmio {
+ int nr;
+ struct pci_tsm_mmio_entry mmio[] __counted_by(nr);
+};
+
+static inline struct pci_tsm_mmio_entry *
+pci_tsm_mmio_entry(struct pci_tsm_mmio *mmio, int idx)
+{
+ return &mmio->mmio[idx];
+}
+
+static inline struct resource *pci_tsm_mmio_resource(struct pci_tsm_mmio *mmio,
+ int idx)
+{
+ return &mmio->mmio[idx].res;
+}
+
/**
* struct pci_tsm_devsec - context for tracking private/accepted PCI resources
* @base_tsm: generic core "tsm" context
+ * @mmio: encrypted MMIO resources for this assigned device
*/
struct pci_tsm_devsec {
struct pci_tsm base_tsm;
+ struct pci_tsm_mmio *mmio;
};
/* physical function0 and capable of 'connect' */
@@ -206,6 +236,11 @@ bool pci_tsm_context_match_device(struct pci_tsm_context *context,
struct pci_dev *pdev);
struct tsm_dev *pci_tsm_get_device(struct pci_dev *pdev);
struct pci_tsm_devsec *to_pci_tsm_devsec(struct pci_tsm *tsm);
+int pci_tsm_mmio_setup(struct pci_dev *pdev, struct pci_tsm_mmio *mmio);
+void pci_tsm_mmio_teardown(struct pci_tsm_mmio *mmio);
+struct pci_tsm_mmio *pci_tsm_mmio_alloc_report(struct pci_dev *pdev,
+ const void *report_data, size_t report_sz);
+int pci_tsm_mmio_free(struct pci_dev *pdev, struct pci_tsm_mmio *mmio);
#else
static inline struct pci_tsm *pci_tsm_trylock_association(struct pci_tsm *tsm)
{
--
2.43.0
^ permalink raw reply related [flat|nested] 18+ messages in thread* [PATCH v1 10/10] PCI/TSM: Configure accepted device DMA during driver attachment
2026-11-23 8:33 [PATCH v1 00/10] PCI/TSM: Support guest TSM drivers Aneesh Kumar K.V (Arm)
` (8 preceding siblings ...)
2026-11-23 8:33 ` [PATCH v1 09/10] PCI/TSM: Build encrypted MMIO descriptors from a supplied report Aneesh Kumar K.V (Arm)
@ 2026-11-23 8:33 ` Aneesh Kumar K.V (Arm)
2026-11-23 8:40 ` [PATCH v1 00/10] PCI/TSM: Support guest TSM drivers Greg Kroah-Hartman
10 siblings, 0 replies; 18+ messages in thread
From: Aneesh Kumar K.V (Arm) @ 2026-11-23 8:33 UTC (permalink / raw)
To: linux-coco
Cc: Aneesh Kumar K.V (Arm), Dan Williams, Leon Romanovsky,
Bjorn Helgaas, Jason Gunthorpe, Jonathan Cameron, Xu Yilun,
Alexey Kardashevskiy, Greg Kroah-Hartman, Rafael J . Wysocki,
Steven Price, Suzuki K Poulose, Lukas Wunner, Ashish Kalra,
Tom Lendacky, Herbert Xu, driver-core, linux-pci, kvm, patches
Device acceptance and DMA enablement are separate operations. An
accepted device may still need TSM-specific setup before it can perform
DMA.
Add dma_enable and dma_disable callbacks for device-security TSMs. For
TSMs implementing these callbacks, require the device to be accepted
before configuring DMA. Reject drivers setting driver_managed_dma, which
are not supported by this patch.
Take a TSM user reference before DMA configuration and retain it until
DMA cleanup finishes. This also references the TSM device and its driver
module, so tsm_unregister() waits for cleanup and the callback code
remains available. Record whether DMA setup holds this reference in
pci_dev::tsm_dma_pinned.
Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar@kernel.org>
---
drivers/pci/pci-driver.c | 31 +++++++++++++-
drivers/pci/tsm.c | 89 ++++++++++++++++++++++++++++++++++++++++
include/linux/pci-tsm.h | 35 ++++++++++++++--
include/linux/pci.h | 1 +
4 files changed, 152 insertions(+), 4 deletions(-)
diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index 7efe808cdf0c..edabdf30b289 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -5,6 +5,7 @@
*/
#include <linux/pci.h>
+#include <linux/pci-tsm.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/device.h>
@@ -1732,9 +1733,14 @@ static int pci_bus_num_vf(struct device *dev)
static int pci_dma_configure(struct device *dev)
{
const struct device_driver *drv = READ_ONCE(dev->driver);
+ bool use_default_domain = drv && !to_pci_driver(drv)->driver_managed_dma;
struct device *bridge;
int ret = 0;
+ ret = pci_tsm_dma_prepare(to_pci_dev(dev));
+ if (ret)
+ return ret;
+
bridge = pci_get_host_bridge_device(to_pci_dev(dev));
if (IS_ENABLED(CONFIG_OF) && bridge->parent &&
@@ -1757,12 +1763,34 @@ static int pci_dma_configure(struct device *dev)
pci_put_host_bridge_device(bridge);
/* @drv may not be valid when we're called from the IOMMU layer */
- if (!ret && drv && !to_pci_driver(drv)->driver_managed_dma) {
+ if (!ret && use_default_domain) {
ret = iommu_device_use_default_domain(dev);
if (ret)
+ goto err_arch;
+ }
+
+ if (ret)
+ goto err_arch;
+
+ if (drv) {
+ ret = pci_tsm_dma_enable(to_pci_dev(dev));
+ if (ret) {
+ /* Driver core does not call dma_cleanup on this failure. */
+ pci_tsm_dma_cleanup(to_pci_dev(dev));
+ if (use_default_domain)
+ iommu_device_unuse_default_domain(dev);
+
arch_teardown_dma_ops(dev);
+ return ret;
+ }
}
+ return 0;
+
+err_arch:
+ pci_tsm_dma_cleanup(to_pci_dev(dev));
+
+ arch_teardown_dma_ops(dev);
return ret;
}
@@ -1770,6 +1798,7 @@ static void pci_dma_cleanup(struct device *dev)
{
struct pci_driver *driver = to_pci_driver(dev->driver);
+ pci_tsm_dma_cleanup(to_pci_dev(dev));
if (!driver->driver_managed_dma)
iommu_device_unuse_default_domain(dev);
}
diff --git a/drivers/pci/tsm.c b/drivers/pci/tsm.c
index c21066e55d3b..6464670dde08 100644
--- a/drivers/pci/tsm.c
+++ b/drivers/pci/tsm.c
@@ -315,6 +315,92 @@ static bool is_devsec_tsm(struct tsm_dev *tsm_dev)
return tsm_dev && tsm_dev->pci_ops && tsm_dev->pci_ops->devsec_ops.lock;
}
+/*
+ * Driver core already holds pdev->dev.mutex. Guest PCI/TSM operations take
+ * that mutex before pci_tsm_rwsem, so the read acquisition can wait here.
+ * The device mutex and refusal to unlock a driver-attached device keep
+ * pdev->tsm unchanged through DMA configuration and driver attachment.
+ */
+int pci_tsm_dma_prepare(struct pci_dev *pdev)
+{
+ const struct pci_tsm_ops *ops;
+ struct pci_tsm *tsm;
+ int ret = 0;
+
+ device_lock_assert(&pdev->dev);
+ if (!pdev->dev.driver)
+ return 0;
+
+ down_read(&pci_tsm_rwsem);
+
+ tsm = pdev->tsm;
+ if (!tsm || !is_devsec_tsm(tsm->tsm_dev))
+ goto out;
+
+ ops = to_pci_tsm_ops(tsm);
+ if (!ops->dma_enable)
+ goto out;
+
+ /* driver_managed_dma is unsupported. */
+ if (to_pci_driver(pdev->dev.driver)->driver_managed_dma) {
+ ret = -EOPNOTSUPP;
+ goto out;
+ }
+
+ if (!device_cc_accepted(&pdev->dev)) {
+ ret = -EACCES;
+ goto out;
+ }
+
+ /*
+ * pdev->tsm does not hold a TSM user reference. Take one so
+ * tsm_unregister() waits until pci_tsm_dma_cleanup() finishes
+ * calling dma_disable(). tsm_get() also references the TSM device
+ * and module containing the callbacks.
+ *
+ * tsm_dma_pinned records whether DMA setup holds this reference;
+ * pdev->tsm can also be set when no PCI driver is attached.
+ */
+ if (IS_ERR(tsm_get(tsm->tsm_dev))) {
+ ret = -ENODEV;
+ goto out;
+ }
+
+ pdev->tsm_dma_pinned = true;
+out:
+ up_read(&pci_tsm_rwsem);
+ return ret;
+}
+
+int pci_tsm_dma_enable(struct pci_dev *pdev)
+{
+ device_lock_assert(&pdev->dev);
+ if (!pdev->tsm_dma_pinned)
+ return 0;
+
+ return to_pci_tsm_ops(pdev->tsm)->dma_enable(pdev);
+}
+
+void pci_tsm_dma_cleanup(struct pci_dev *pdev)
+{
+ const struct pci_tsm_ops *ops;
+ struct tsm_dev *tsm_dev;
+ int ret;
+
+ device_lock_assert(&pdev->dev);
+ if (!pdev->tsm_dma_pinned)
+ return;
+
+ ops = to_pci_tsm_ops(pdev->tsm);
+ tsm_dev = pdev->tsm->tsm_dev;
+ ret = ops->dma_disable(pdev);
+ if (ret)
+ /* TODO: Prevent DMA to private memory before releasing the TSM reference. */
+ pci_err(pdev, "Failed to revoke confidential DMA (%d)\n", ret);
+ pdev->tsm_dma_pinned = false;
+ tsm_put_device(tsm_dev);
+}
+
/**
* pci_tsm_trylock_association() - Lock and check a PCI function's TSM state
* @tsm: struct pci_tsm kept allocated by the caller throughout the operation
@@ -1265,6 +1351,9 @@ int pci_tsm_register(struct tsm_dev *tsm_dev)
if (is_link_tsm(tsm_dev) && is_devsec_tsm(tsm_dev))
return -EINVAL;
+ if (!!tsm_dev->pci_ops->dma_enable != !!tsm_dev->pci_ops->dma_disable)
+ return -EINVAL;
+
guard(rwsem_write)(&pci_tsm_rwsem);
/* On first enable, update sysfs groups */
diff --git a/include/linux/pci-tsm.h b/include/linux/pci-tsm.h
index aef6cfb87082..4da2a24cc0fe 100644
--- a/include/linux/pci-tsm.h
+++ b/include/linux/pci-tsm.h
@@ -24,7 +24,7 @@ struct tsm_dev;
* operations).
* @viommu_get_ops: Return operations for a supported TSM-owned vIOMMU type,
* or NULL if unsupported
- * @owner: Module providing the vIOMMU operations, if built as a module
+ * @owner: Module providing the vIOMMU or DMA operations, if built as a module
* @prepare_remove: Optional, reject new device operations before TSM unregister
* waits for users, or before forced PF0 removal.
*
@@ -76,15 +76,22 @@ struct pci_tsm_ops {
* pci_tsm') for follow-on security state transitions from the
* LOCKED state
* @unlock: destroy TSM context and return device to UNLOCKED state
+ * @dma_enable: enable DMA after PCI DMA configuration, before probe
+ * @dma_disable: disable DMA on driver detach or DMA/probe failure
*
* Context: @lock and @unlock run under pci_tsm_rwsem held for write to
* sync with TSM unregistration and each other. All operations run under
- * the device lock for mutual exclusion with driver attach and detach.
+ * device::mutex for mutual exclusion with driver attach and detach.
+ * @dma_enable and @dma_disable run under device::mutex with the TSM user
+ * reference held, without pci_tsm_rwsem. They must not acquire
+ * pci_tsm_rwsem or attestation_dev::lock.
*/
struct_group_tagged(pci_tsm_devsec_ops, devsec_ops,
struct pci_tsm *(*lock)(struct tsm_dev *tsm_dev,
struct pci_dev *pdev);
void (*unlock)(struct pci_tsm *tsm);
+ int (*dma_enable)(struct pci_dev *pdev);
+ int (*dma_disable)(struct pci_dev *pdev);
);
};
@@ -177,6 +184,7 @@ struct pci_tsm_devsec {
struct pci_tsm_mmio *mmio;
};
+#ifdef CONFIG_PCI_TSM
/* physical function0 and capable of 'connect' */
static inline bool is_pci_tsm_pf0(struct pci_dev *pdev)
{
@@ -210,7 +218,9 @@ static inline bool is_pci_tsm_pf0(struct pci_dev *pdev)
return PCI_FUNC(pdev->devfn) == 0;
}
-#ifdef CONFIG_PCI_TSM
+int pci_tsm_dma_prepare(struct pci_dev *pdev);
+int pci_tsm_dma_enable(struct pci_dev *pdev);
+void pci_tsm_dma_cleanup(struct pci_dev *pdev);
struct pci_tsm *pci_tsm_trylock_association(struct pci_tsm *tsm);
void pci_tsm_unlock_association(struct pci_tsm *tsm);
void pci_tsm_set_ready(struct pci_tsm_pf0 *pf0, bool ready);
@@ -242,6 +252,25 @@ struct pci_tsm_mmio *pci_tsm_mmio_alloc_report(struct pci_dev *pdev,
const void *report_data, size_t report_sz);
int pci_tsm_mmio_free(struct pci_dev *pdev, struct pci_tsm_mmio *mmio);
#else
+static inline bool is_pci_tsm_pf0(struct pci_dev *pdev)
+{
+ return false;
+}
+
+static inline int pci_tsm_dma_prepare(struct pci_dev *pdev)
+{
+ return 0;
+}
+
+static inline int pci_tsm_dma_enable(struct pci_dev *pdev)
+{
+ return 0;
+}
+
+static inline void pci_tsm_dma_cleanup(struct pci_dev *pdev)
+{
+}
+
static inline struct pci_tsm *pci_tsm_trylock_association(struct pci_tsm *tsm)
{
return ERR_PTR(-ENODEV);
diff --git a/include/linux/pci.h b/include/linux/pci.h
index aa3765a20a96..487ef6c5dea6 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -581,6 +581,7 @@ struct pci_dev {
#endif
#ifdef CONFIG_PCI_TSM
struct pci_tsm *tsm; /* TSM operation state */
+ bool tsm_dma_pinned; /* DMA binding holds a TSM user reference */
#endif
u16 acs_cap; /* ACS Capability offset */
u16 acs_capabilities; /* ACS Capabilities */
--
2.43.0
^ permalink raw reply related [flat|nested] 18+ messages in thread* Re: [PATCH v1 00/10] PCI/TSM: Support guest TSM drivers
2026-11-23 8:33 [PATCH v1 00/10] PCI/TSM: Support guest TSM drivers Aneesh Kumar K.V (Arm)
` (9 preceding siblings ...)
2026-11-23 8:33 ` [PATCH v1 10/10] PCI/TSM: Configure accepted device DMA during driver attachment Aneesh Kumar K.V (Arm)
@ 2026-11-23 8:40 ` Greg Kroah-Hartman
2026-11-23 9:06 ` Leon Romanovsky
10 siblings, 1 reply; 18+ messages in thread
From: Greg Kroah-Hartman @ 2026-11-23 8:40 UTC (permalink / raw)
To: Aneesh Kumar K.V (Arm)
Cc: linux-coco, Dan Williams, Leon Romanovsky, Bjorn Helgaas,
Jason Gunthorpe, Jonathan Cameron, Xu Yilun, Alexey Kardashevskiy,
Rafael J . Wysocki, Steven Price, Suzuki K Poulose, Lukas Wunner,
Ashish Kalra, Tom Lendacky, Herbert Xu, driver-core, linux-pci,
kvm, patches
On Mon, Nov 23, 2026 at 02:03:27PM +0530, Aneesh Kumar K.V (Arm) wrote:
> This series adds the PCI/TSM support needed by a TEE Security Manager
> (TSM) driver in a confidential guest. It adds device lock/unlock,
> helpers for recording device acceptance and parsing MMIO reports, and
> DMA callbacks used during PCI driver attachment. The guest TSM driver and
> attestation commands using these interfaces are in follow-up series.
>
> This series is based on Dan Williams' "[PATCH v2 00/19] PCI/TSM: TEE I/O
> infrastructure" posting [1], particularly the guest LOCK/UNLOCK, ACCEPT
> and MMIO report work [2-4]. It retains device_cc_accepted() and the
> confidential-device acceptance model from that posting, with changes
> adapted to the current PCI/TSM structures and reference APIs. Dan's
> device-core acceptance helper and per-host-bridge IDE stream reporting
> patch are also included.
>
> This series does not adopt the Device Trust changes from Dan's "Device
> Evidence and Trust for PCI Security Protocol (TDISP)" [5]. That work is
> being developed separately in Leon Romanovsky's "driver core: Authorize
> device trust before driver binding" series, [6]. Confidential-device
> acceptance is kept separate from that driver-binding trust policy.
But it should not, as you are making driver core changes that will
mirror the same thing that that patchset is attempting to do. Please
work together on this.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 18+ messages in thread* Re: [PATCH v1 00/10] PCI/TSM: Support guest TSM drivers
2026-11-23 8:40 ` [PATCH v1 00/10] PCI/TSM: Support guest TSM drivers Greg Kroah-Hartman
@ 2026-11-23 9:06 ` Leon Romanovsky
2026-11-23 9:43 ` Aneesh Kumar K.V
0 siblings, 1 reply; 18+ messages in thread
From: Leon Romanovsky @ 2026-11-23 9:06 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: Aneesh Kumar K.V (Arm), linux-coco, Dan Williams, Bjorn Helgaas,
Jason Gunthorpe, Jonathan Cameron, Xu Yilun, Alexey Kardashevskiy,
Rafael J . Wysocki, Steven Price, Suzuki K Poulose, Lukas Wunner,
Ashish Kalra, Tom Lendacky, Herbert Xu, driver-core, linux-pci,
kvm, patches
On Mon, Nov 23, 2026 at 09:40:55AM +0100, Greg Kroah-Hartman wrote:
> On Mon, Nov 23, 2026 at 02:03:27PM +0530, Aneesh Kumar K.V (Arm) wrote:
> > This series adds the PCI/TSM support needed by a TEE Security Manager
> > (TSM) driver in a confidential guest. It adds device lock/unlock,
> > helpers for recording device acceptance and parsing MMIO reports, and
> > DMA callbacks used during PCI driver attachment. The guest TSM driver and
> > attestation commands using these interfaces are in follow-up series.
> >
> > This series is based on Dan Williams' "[PATCH v2 00/19] PCI/TSM: TEE I/O
> > infrastructure" posting [1], particularly the guest LOCK/UNLOCK, ACCEPT
> > and MMIO report work [2-4]. It retains device_cc_accepted() and the
> > confidential-device acceptance model from that posting, with changes
> > adapted to the current PCI/TSM structures and reference APIs. Dan's
> > device-core acceptance helper and per-host-bridge IDE stream reporting
> > patch are also included.
> >
> > This series does not adopt the Device Trust changes from Dan's "Device
> > Evidence and Trust for PCI Security Protocol (TDISP)" [5]. That work is
> > being developed separately in Leon Romanovsky's "driver core: Authorize
> > device trust before driver binding" series, [6]. Confidential-device
> > acceptance is kept separate from that driver-binding trust policy.
>
> But it should not, as you are making driver core changes that will
> mirror the same thing that that patchset is attempting to do. Please
> work together on this.
+10000000,
Greg,
This series came as a surprise to me given the fact that device trust
series is exactly for that - allow confidential computing.
Adversarial is equal to the "cc_accepted".
Thanks
>
> thanks,
>
> greg k-h
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v1 00/10] PCI/TSM: Support guest TSM drivers
2026-11-23 9:06 ` Leon Romanovsky
@ 2026-11-23 9:43 ` Aneesh Kumar K.V
2026-11-23 11:58 ` Leon Romanovsky
0 siblings, 1 reply; 18+ messages in thread
From: Aneesh Kumar K.V @ 2026-11-23 9:43 UTC (permalink / raw)
To: Leon Romanovsky, Greg Kroah-Hartman
Cc: linux-coco, Dan Williams, Bjorn Helgaas, Jason Gunthorpe,
Jonathan Cameron, Xu Yilun, Alexey Kardashevskiy,
Rafael J . Wysocki, Steven Price, Suzuki K Poulose, Lukas Wunner,
Ashish Kalra, Tom Lendacky, Herbert Xu, driver-core, linux-pci,
kvm, patches
Leon Romanovsky <leon@kernel.org> writes:
> On Mon, Nov 23, 2026 at 09:40:55AM +0100, Greg Kroah-Hartman wrote:
>> On Mon, Nov 23, 2026 at 02:03:27PM +0530, Aneesh Kumar K.V (Arm) wrote:
>> > This series adds the PCI/TSM support needed by a TEE Security Manager
>> > (TSM) driver in a confidential guest. It adds device lock/unlock,
>> > helpers for recording device acceptance and parsing MMIO reports, and
>> > DMA callbacks used during PCI driver attachment. The guest TSM driver and
>> > attestation commands using these interfaces are in follow-up series.
>> >
>> > This series is based on Dan Williams' "[PATCH v2 00/19] PCI/TSM: TEE I/O
>> > infrastructure" posting [1], particularly the guest LOCK/UNLOCK, ACCEPT
>> > and MMIO report work [2-4]. It retains device_cc_accepted() and the
>> > confidential-device acceptance model from that posting, with changes
>> > adapted to the current PCI/TSM structures and reference APIs. Dan's
>> > device-core acceptance helper and per-host-bridge IDE stream reporting
>> > patch are also included.
>> >
>> > This series does not adopt the Device Trust changes from Dan's "Device
>> > Evidence and Trust for PCI Security Protocol (TDISP)" [5]. That work is
>> > being developed separately in Leon Romanovsky's "driver core: Authorize
>> > device trust before driver binding" series, [6]. Confidential-device
>> > acceptance is kept separate from that driver-binding trust policy.
>>
>> But it should not, as you are making driver core changes that will
>> mirror the same thing that that patchset is attempting to do. Please
>> work together on this.
>
> +10000000,
>
> Greg,
>
> This series came as a surprise to me given the fact that device trust
> series is exactly for that - allow confidential computing.
>
> Adversarial is equal to the "cc_accepted".
I think the confusion stems from this thread:
https://lore.kernel.org/all/yq5amrr8yldi.fsf@kernel.org
Based on that discussion, I understood TRUST and eligibility for private
DMA to be complementary attributes. Device acceptance determines whether
a device may access private memory, while trust determines whether the
core must enforce additional restrictions. I understood that supporting
an accepted but adversarial device would require either a private IOTLB
to restrict its access or an IOMMU.
Therefore, with this series, a request to enable private memory DMA is
handled as follows:
if (!device_cc_accepted(&pdev->dev)) {
ret = -EACCES;
goto out;
}
/* Adversarial devices are unsupported for confidential DMA. */
if (device_is_adversarial(&pdev->dev)) {
ret = -EOPNOTSUPP;
goto out;
}
-aneesh
^ permalink raw reply [flat|nested] 18+ messages in thread* Re: [PATCH v1 00/10] PCI/TSM: Support guest TSM drivers
2026-11-23 9:43 ` Aneesh Kumar K.V
@ 2026-11-23 11:58 ` Leon Romanovsky
2026-11-23 13:24 ` Aneesh Kumar K.V
0 siblings, 1 reply; 18+ messages in thread
From: Leon Romanovsky @ 2026-11-23 11:58 UTC (permalink / raw)
To: Aneesh Kumar K.V
Cc: Greg Kroah-Hartman, linux-coco, Dan Williams, Bjorn Helgaas,
Jason Gunthorpe, Jonathan Cameron, Xu Yilun, Alexey Kardashevskiy,
Rafael J . Wysocki, Steven Price, Suzuki K Poulose, Lukas Wunner,
Ashish Kalra, Tom Lendacky, Herbert Xu, driver-core, linux-pci,
kvm, patches
On Mon, Nov 23, 2026 at 03:13:13PM +0530, Aneesh Kumar K.V wrote:
> Leon Romanovsky <leon@kernel.org> writes:
>
> > On Mon, Nov 23, 2026 at 09:40:55AM +0100, Greg Kroah-Hartman wrote:
> >> On Mon, Nov 23, 2026 at 02:03:27PM +0530, Aneesh Kumar K.V (Arm) wrote:
> >> > This series adds the PCI/TSM support needed by a TEE Security Manager
> >> > (TSM) driver in a confidential guest. It adds device lock/unlock,
> >> > helpers for recording device acceptance and parsing MMIO reports, and
> >> > DMA callbacks used during PCI driver attachment. The guest TSM driver and
> >> > attestation commands using these interfaces are in follow-up series.
> >> >
> >> > This series is based on Dan Williams' "[PATCH v2 00/19] PCI/TSM: TEE I/O
> >> > infrastructure" posting [1], particularly the guest LOCK/UNLOCK, ACCEPT
> >> > and MMIO report work [2-4]. It retains device_cc_accepted() and the
> >> > confidential-device acceptance model from that posting, with changes
> >> > adapted to the current PCI/TSM structures and reference APIs. Dan's
> >> > device-core acceptance helper and per-host-bridge IDE stream reporting
> >> > patch are also included.
> >> >
> >> > This series does not adopt the Device Trust changes from Dan's "Device
> >> > Evidence and Trust for PCI Security Protocol (TDISP)" [5]. That work is
> >> > being developed separately in Leon Romanovsky's "driver core: Authorize
> >> > device trust before driver binding" series, [6]. Confidential-device
> >> > acceptance is kept separate from that driver-binding trust policy.
> >>
> >> But it should not, as you are making driver core changes that will
> >> mirror the same thing that that patchset is attempting to do. Please
> >> work together on this.
> >
> > +10000000,
> >
> > Greg,
> >
> > This series came as a surprise to me given the fact that device trust
> > series is exactly for that - allow confidential computing.
> >
> > Adversarial is equal to the "cc_accepted".
>
> I think the confusion stems from this thread:
>
> https://lore.kernel.org/all/yq5amrr8yldi.fsf@kernel.org
>
> Based on that discussion, I understood TRUST and eligibility for private
> DMA to be complementary attributes. Device acceptance determines whether
> a device may access private memory, while trust determines whether the
> core must enforce additional restrictions. I understood that supporting
> an accepted but adversarial device would require either a private IOTLB
> to restrict its access or an IOMMU.
I reached a completely different conclusion from that discussion.
Device trust does little beyond preventing driver binding and recording the
trust decision in "struct device". The missing piece, which I would expect
you to address, is ensuring that the IOMMU and private DMA are configured
only after the trust level has been decided or as part of that decision,
rather than beforehand, as they are today.
Thanks
>
> Therefore, with this series, a request to enable private memory DMA is
> handled as follows:
>
> if (!device_cc_accepted(&pdev->dev)) {
> ret = -EACCES;
> goto out;
> }
>
> /* Adversarial devices are unsupported for confidential DMA. */
> if (device_is_adversarial(&pdev->dev)) {
> ret = -EOPNOTSUPP;
> goto out;
> }
The snippet above clearly shows why it is a good idea to wait until support
for device trust levels is accepted. An adversarial device is untrusted
from the PCI perspective and must have private DMA and a separate IOMMU
group.
Thanks
>
>
> -aneesh
>
^ permalink raw reply [flat|nested] 18+ messages in thread* Re: [PATCH v1 00/10] PCI/TSM: Support guest TSM drivers
2026-11-23 11:58 ` Leon Romanovsky
@ 2026-11-23 13:24 ` Aneesh Kumar K.V
2026-11-23 13:56 ` Leon Romanovsky
0 siblings, 1 reply; 18+ messages in thread
From: Aneesh Kumar K.V @ 2026-11-23 13:24 UTC (permalink / raw)
To: Leon Romanovsky
Cc: Greg Kroah-Hartman, linux-coco, Dan Williams, Bjorn Helgaas,
Jason Gunthorpe, Jonathan Cameron, Xu Yilun, Alexey Kardashevskiy,
Rafael J . Wysocki, Steven Price, Suzuki K Poulose, Lukas Wunner,
Ashish Kalra, Tom Lendacky, Herbert Xu, driver-core, linux-pci,
kvm, patches
Leon Romanovsky <leon@kernel.org> writes:
> On Mon, Nov 23, 2026 at 03:13:13PM +0530, Aneesh Kumar K.V wrote:
>> Leon Romanovsky <leon@kernel.org> writes:
>>
>> > On Mon, Nov 23, 2026 at 09:40:55AM +0100, Greg Kroah-Hartman wrote:
>> >> On Mon, Nov 23, 2026 at 02:03:27PM +0530, Aneesh Kumar K.V (Arm) wrote:
>> >> > This series adds the PCI/TSM support needed by a TEE Security Manager
>> >> > (TSM) driver in a confidential guest. It adds device lock/unlock,
>> >> > helpers for recording device acceptance and parsing MMIO reports, and
>> >> > DMA callbacks used during PCI driver attachment. The guest TSM driver and
>> >> > attestation commands using these interfaces are in follow-up series.
>> >> >
>> >> > This series is based on Dan Williams' "[PATCH v2 00/19] PCI/TSM: TEE I/O
>> >> > infrastructure" posting [1], particularly the guest LOCK/UNLOCK, ACCEPT
>> >> > and MMIO report work [2-4]. It retains device_cc_accepted() and the
>> >> > confidential-device acceptance model from that posting, with changes
>> >> > adapted to the current PCI/TSM structures and reference APIs. Dan's
>> >> > device-core acceptance helper and per-host-bridge IDE stream reporting
>> >> > patch are also included.
>> >> >
>> >> > This series does not adopt the Device Trust changes from Dan's "Device
>> >> > Evidence and Trust for PCI Security Protocol (TDISP)" [5]. That work is
>> >> > being developed separately in Leon Romanovsky's "driver core: Authorize
>> >> > device trust before driver binding" series, [6]. Confidential-device
>> >> > acceptance is kept separate from that driver-binding trust policy.
>> >>
>> >> But it should not, as you are making driver core changes that will
>> >> mirror the same thing that that patchset is attempting to do. Please
>> >> work together on this.
>> >
>> > +10000000,
>> >
>> > Greg,
>> >
>> > This series came as a surprise to me given the fact that device trust
>> > series is exactly for that - allow confidential computing.
>> >
>> > Adversarial is equal to the "cc_accepted".
>>
>> I think the confusion stems from this thread:
>>
>> https://lore.kernel.org/all/yq5amrr8yldi.fsf@kernel.org
>>
>> Based on that discussion, I understood TRUST and eligibility for private
>> DMA to be complementary attributes. Device acceptance determines whether
>> a device may access private memory, while trust determines whether the
>> core must enforce additional restrictions. I understood that supporting
>> an accepted but adversarial device would require either a private IOTLB
>> to restrict its access or an IOMMU.
>
> I reached a completely different conclusion from that discussion.
>
> Device trust does little beyond preventing driver binding and recording the
> trust decision in "struct device". The missing piece, which I would expect
> you to address, is ensuring that the IOMMU and private DMA are configured
> only after the trust level has been decided or as part of that decision,
> rather than beforehand, as they are today.
>
I agree that the trust decision must precede DMA configuration and
driver probe. My integration tree shared in the cover letter already
includes your trust framework, with PCI/TSM DMA setup following that
decision.
What I am still trying to understand is how you view the DMA allocation
and mapping paths determining whether a device can access private
memory. Paths such as force_dma_unencrypted() and SWIOTLB receive a
struct device pointer and need to decide whether to use private memory
or shared buffers.
We could move cc_accepted into struct pci_tsm_devsec, outside driver
core. How would you expect the generic DMA code to obtain that
information? Adding another flag to struct device would effectively
recreate the state we are trying to remove.
This goes back to my question here:
https://lore.kernel.org/all/yq5amrr8yldi.fsf@kernel.org/
If we remove device_cc_accepted(), what should those callers use
instead? How do you see your trust framework supporting that decision?
-aneesh
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v1 00/10] PCI/TSM: Support guest TSM drivers
2026-11-23 13:24 ` Aneesh Kumar K.V
@ 2026-11-23 13:56 ` Leon Romanovsky
0 siblings, 0 replies; 18+ messages in thread
From: Leon Romanovsky @ 2026-11-23 13:56 UTC (permalink / raw)
To: Aneesh Kumar K.V
Cc: Greg Kroah-Hartman, linux-coco, Dan Williams, Bjorn Helgaas,
Jason Gunthorpe, Jonathan Cameron, Xu Yilun, Alexey Kardashevskiy,
Rafael J . Wysocki, Steven Price, Suzuki K Poulose, Lukas Wunner,
Ashish Kalra, Tom Lendacky, Herbert Xu, driver-core, linux-pci,
kvm, patches
On Mon, Nov 23, 2026 at 06:54:31PM +0530, Aneesh Kumar K.V wrote:
> Leon Romanovsky <leon@kernel.org> writes:
>
> > On Mon, Nov 23, 2026 at 03:13:13PM +0530, Aneesh Kumar K.V wrote:
> >> Leon Romanovsky <leon@kernel.org> writes:
> >>
> >> > On Mon, Nov 23, 2026 at 09:40:55AM +0100, Greg Kroah-Hartman wrote:
> >> >> On Mon, Nov 23, 2026 at 02:03:27PM +0530, Aneesh Kumar K.V (Arm) wrote:
> >> >> > This series adds the PCI/TSM support needed by a TEE Security Manager
> >> >> > (TSM) driver in a confidential guest. It adds device lock/unlock,
> >> >> > helpers for recording device acceptance and parsing MMIO reports, and
> >> >> > DMA callbacks used during PCI driver attachment. The guest TSM driver and
> >> >> > attestation commands using these interfaces are in follow-up series.
> >> >> >
> >> >> > This series is based on Dan Williams' "[PATCH v2 00/19] PCI/TSM: TEE I/O
> >> >> > infrastructure" posting [1], particularly the guest LOCK/UNLOCK, ACCEPT
> >> >> > and MMIO report work [2-4]. It retains device_cc_accepted() and the
> >> >> > confidential-device acceptance model from that posting, with changes
> >> >> > adapted to the current PCI/TSM structures and reference APIs. Dan's
> >> >> > device-core acceptance helper and per-host-bridge IDE stream reporting
> >> >> > patch are also included.
> >> >> >
> >> >> > This series does not adopt the Device Trust changes from Dan's "Device
> >> >> > Evidence and Trust for PCI Security Protocol (TDISP)" [5]. That work is
> >> >> > being developed separately in Leon Romanovsky's "driver core: Authorize
> >> >> > device trust before driver binding" series, [6]. Confidential-device
> >> >> > acceptance is kept separate from that driver-binding trust policy.
> >> >>
> >> >> But it should not, as you are making driver core changes that will
> >> >> mirror the same thing that that patchset is attempting to do. Please
> >> >> work together on this.
> >> >
> >> > +10000000,
> >> >
> >> > Greg,
> >> >
> >> > This series came as a surprise to me given the fact that device trust
> >> > series is exactly for that - allow confidential computing.
> >> >
> >> > Adversarial is equal to the "cc_accepted".
> >>
> >> I think the confusion stems from this thread:
> >>
> >> https://lore.kernel.org/all/yq5amrr8yldi.fsf@kernel.org
> >>
> >> Based on that discussion, I understood TRUST and eligibility for private
> >> DMA to be complementary attributes. Device acceptance determines whether
> >> a device may access private memory, while trust determines whether the
> >> core must enforce additional restrictions. I understood that supporting
> >> an accepted but adversarial device would require either a private IOTLB
> >> to restrict its access or an IOMMU.
> >
> > I reached a completely different conclusion from that discussion.
> >
> > Device trust does little beyond preventing driver binding and recording the
> > trust decision in "struct device". The missing piece, which I would expect
> > you to address, is ensuring that the IOMMU and private DMA are configured
> > only after the trust level has been decided or as part of that decision,
> > rather than beforehand, as they are today.
> >
>
>
> I agree that the trust decision must precede DMA configuration and
> driver probe. My integration tree shared in the cover letter already
> includes your trust framework, with PCI/TSM DMA setup following that
> decision.
>
> What I am still trying to understand is how you view the DMA allocation
> and mapping paths determining whether a device can access private
> memory. Paths such as force_dma_unencrypted() and SWIOTLB receive a
> struct device pointer and need to decide whether to use private memory
> or shared buffers.
After the IOMMU cleanup, I expect we’ll be able to create a cyclic
trust-level state machine that lets us reset the trust level when a
driver is unbound. We can then add internal states to the trust-level
FSM, which DMA/SWIOTLB can check.
In theory, we could make this final improvement before the IOMMU cleanup.
However, the risk of creating a mess is higher than if we follow a
straightforward, sequential engineering approach.
Thanks
>
> We could move cc_accepted into struct pci_tsm_devsec, outside driver
> core. How would you expect the generic DMA code to obtain that
> information? Adding another flag to struct device would effectively
> recreate the state we are trying to remove.
>
> This goes back to my question here:
> https://lore.kernel.org/all/yq5amrr8yldi.fsf@kernel.org/
>
> If we remove device_cc_accepted(), what should those callers use
> instead? How do you see your trust framework supporting that decision?
>
> -aneesh
>
>
^ permalink raw reply [flat|nested] 18+ messages in thread