From: "Aneesh Kumar K.V (Arm)" <aneesh.kumar@kernel.org>
To: linux-coco@lists.linux.dev
Cc: "Aneesh Kumar K.V (Arm)" <aneesh.kumar@kernel.org>,
Jiri Pirko <jiri@resnulli.us>, Kevin Tian <kevin.tian@intel.com>,
Alexey Kardashevskiy <aik@amd.com>,
Xu Yilun <yilun.xu@linux.intel.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Steven Price <steven.price@arm.com>,
Kiryl Shutsemau <kas@kernel.org>,
Rick Edgecombe <rick.p.edgecombe@intel.com>,
Dave Hansen <dave.hansen@linux.intel.com>,
Jonathan Cameron <jic23@kernel.org>,
Jason Gunthorpe <jgg@nvidia.com>,
Bjorn Helgaas <bhelgaas@google.com>,
Ashish Kalra <ashish.kalra@amd.com>,
Tom Lendacky <thomas.lendacky@amd.com>,
John Allen <john.allen@amd.com>, Will Deacon <will@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
patches@lists.linux.dev
Subject: [RFC PATCH v1 07/11] attestation: Add attestation helpers for PCI/TSM integration
Date: Wed, 28 Oct 2026 20:56:14 +0530 [thread overview]
Message-ID: <20261028152618.1356860-8-aneesh.kumar@kernel.org> (raw)
In-Reply-To: <20261028152618.1356860-1-aneesh.kumar@kernel.org>
Add helpers that let the following PCI/TSM patch coordinate device state
changes with attestation state.
PCI child-family operations use ctlv_attestation_op_pre() to acquire the
attestation lock before invoking the backend. They need to validate the
requested device generation before changing state and invalidating
previous evidence.
The existing attestation_state_changed() takes the attestation lock itself.
Factor out a locked variant so those operations can report a state
change without acquiring the same mutex again.
Also expose helpers to check for device-generation overflow, read the
current device generation, and acquire the instance mutex for notifications
outside CTLV dispatch.
Cc: Jiri Pirko <jiri@resnulli.us>
Cc: Jonathan Cameron <jic23@kernel.org>
Cc: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar@kernel.org>
---
drivers/attestation/core/core.c | 40 +++++++++++++++++++++++++---
include/linux/attestation.h | 47 +++++++++++++++++++++++++++++++++
2 files changed, 84 insertions(+), 3 deletions(-)
diff --git a/drivers/attestation/core/core.c b/drivers/attestation/core/core.c
index 914f29693aee..e35c45bc715d 100644
--- a/drivers/attestation/core/core.c
+++ b/drivers/attestation/core/core.c
@@ -430,14 +430,13 @@ void attestation_mr_destroy(struct attestation_mr *mr)
}
EXPORT_SYMBOL_NS_GPL(attestation_mr_destroy, "ATTESTATION");
-void attestation_state_changed(struct attestation *att)
+void attestation_state_changed_locked(struct attestation *att)
{
struct attestation_event_batch events = {};
bool evidence;
int ret;
- guard(mutex)
- (&att->lock);
+ lockdep_assert_held(&att->lock);
if (!attestation_registered(att))
return;
evidence = att->evidence_generation > att->evidence_floor || att->verdict_recorded;
@@ -458,8 +457,43 @@ void attestation_state_changed(struct attestation *att)
attestation_evidence_event_emit(&events, att);
attestation_events_abort(&events);
}
+EXPORT_SYMBOL_NS_GPL(attestation_state_changed_locked, "ATTESTATION");
+
+void attestation_state_changed(struct attestation *att)
+{
+ guard(mutex)(&att->lock);
+ attestation_state_changed_locked(att);
+}
EXPORT_SYMBOL_NS_GPL(attestation_state_changed, "ATTESTATION");
+void attestation_lock(struct attestation *att)
+{
+ mutex_lock(&att->lock);
+}
+EXPORT_SYMBOL_NS_GPL(attestation_lock, "ATTESTATION");
+
+void attestation_unlock(struct attestation *att)
+{
+ mutex_unlock(&att->lock);
+}
+EXPORT_SYMBOL_NS_GPL(attestation_unlock, "ATTESTATION");
+
+int attestation_state_change_prepare(struct attestation *att)
+{
+ lockdep_assert_held(&att->lock);
+ if (!attestation_registered(att))
+ return -ENODEV;
+ return attestation_preflight(att, true, false, false);
+}
+EXPORT_SYMBOL_NS_GPL(attestation_state_change_prepare, "ATTESTATION");
+
+unsigned int attestation_get_device_generation(struct attestation *att)
+{
+ lockdep_assert_held(&att->lock);
+ return att->device_generation;
+}
+EXPORT_SYMBOL_NS_GPL(attestation_get_device_generation, "ATTESTATION");
+
static unsigned int attestation_provider_features(const struct attestation_provider *provider)
{
unsigned int features = 0;
diff --git a/include/linux/attestation.h b/include/linux/attestation.h
index 09ebd2af3a1e..0dae626b2e0e 100644
--- a/include/linux/attestation.h
+++ b/include/linux/attestation.h
@@ -299,6 +299,53 @@ void attestation_mr_destroy(struct attestation_mr *mr);
*/
void attestation_state_changed(struct attestation *att);
+/**
+ * attestation_lock - Lock the attestation instance.
+ * @att: attestation instance
+ *
+ * CTLV operations already hold this mutex. Other callers must follow the
+ * same lock order as the provider's CTLV pre-hook.
+ * Do not call while holding an attestation instance mutex.
+ */
+void attestation_lock(struct attestation *att);
+
+/**
+ * attestation_unlock - Release the attestation instance mutex.
+ * @att: attestation instance locked by attestation_lock()
+ */
+void attestation_unlock(struct attestation *att);
+
+/**
+ * attestation_state_change_prepare - Check whether device state can change.
+ * @att: attestation instance
+ *
+ * Call with the instance mutex held, before changing device state.
+ *
+ * Return: 0 on success, -ENODEV if the instance is no longer registered,
+ * or -EOVERFLOW if the device generation cannot be incremented.
+ */
+int attestation_state_change_prepare(struct attestation *att);
+
+/**
+ * attestation_state_changed_locked - Report a device state change.
+ * @att: attestation instance
+ *
+ * Call with the instance mutex held.
+ *
+ * Advance the device generation, invalidate previous evidence and acceptance
+ * verdicts, and emit state-change events. Invalidation still occurs if
+ * allocating the events fails.
+ */
+void attestation_state_changed_locked(struct attestation *att);
+
+/**
+ * attestation_get_device_generation - Read the device generation.
+ * @att: attestation instance
+ *
+ * The caller must hold the instance mutex.
+ */
+unsigned int attestation_get_device_generation(struct attestation *att);
+
/**
* attestation_features_set_locked - Set enabled features with the mutex held.
* @att: attestation instance
--
2.43.0
next prev parent reply other threads:[~2026-10-28 15:27 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-28 15:26 [RFC PATCH v1 00/11] PCI/TSM: Add CTLV attestation Aneesh Kumar K.V (Arm)
2026-10-28 15:26 ` [RFC PATCH v1 01/11] attestation: Restrict inherited operations per instance Aneesh Kumar K.V (Arm)
2026-10-28 15:26 ` [RFC PATCH v1 02/11] attestation: Filter evidence objects " Aneesh Kumar K.V (Arm)
2026-10-28 15:26 ` [RFC PATCH v1 03/11] attestation: Enter secure operation when evidence is accepted Aneesh Kumar K.V (Arm)
2026-10-28 15:26 ` [RFC PATCH v1 04/11] attestation: Bind object selection to accepted evidence snapshots Aneesh Kumar K.V (Arm)
2026-10-28 15:26 ` [RFC PATCH v1 05/11] attestation: Make the evidence-get challenge attribute optional Aneesh Kumar K.V (Arm)
2026-10-28 15:26 ` [RFC PATCH v1 06/11] PCI/TSM: Describe the PCI attestation control family Aneesh Kumar K.V (Arm)
2026-10-28 15:26 ` Aneesh Kumar K.V (Arm) [this message]
2026-10-28 15:26 ` [RFC PATCH v1 08/11] PCI/TSM: Bind CTLV attestation to connected and locked contexts Aneesh Kumar K.V (Arm)
2026-10-28 22:56 ` Dave Jiang
2026-10-29 5:30 ` Aneesh Kumar K.V
2026-10-29 12:41 ` Jason Gunthorpe
2026-10-28 15:26 ` [RFC PATCH v1 09/11] crypto/ccp: Defer SEV-TIO link setup until evidence acceptance Aneesh Kumar K.V (Arm)
2026-10-28 15:26 ` [RFC PATCH v1 10/11] virt: coco: arm-cca-host: Publish slot zero and establish streams after acceptance Aneesh Kumar K.V (Arm)
2026-10-28 15:26 ` [RFC PATCH v1 11/11] virt: coco: arm-cca-guest: Refresh selected evidence against trusted digests Aneesh Kumar K.V (Arm)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261028152618.1356860-8-aneesh.kumar@kernel.org \
--to=aneesh.kumar@kernel.org \
--cc=aik@amd.com \
--cc=ashish.kalra@amd.com \
--cc=bhelgaas@google.com \
--cc=catalin.marinas@arm.com \
--cc=dave.hansen@linux.intel.com \
--cc=jgg@nvidia.com \
--cc=jic23@kernel.org \
--cc=jiri@resnulli.us \
--cc=john.allen@amd.com \
--cc=kas@kernel.org \
--cc=kevin.tian@intel.com \
--cc=linux-coco@lists.linux.dev \
--cc=mark.rutland@arm.com \
--cc=patches@lists.linux.dev \
--cc=rick.p.edgecombe@intel.com \
--cc=steven.price@arm.com \
--cc=suzuki.poulose@arm.com \
--cc=thomas.lendacky@amd.com \
--cc=will@kernel.org \
--cc=yilun.xu@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.