From: Jiri Pirko <jiri@resnulli.us>
To: linux-coco@lists.linux.dev
Cc: linux-kernel@vger.kernel.org, linux-api@vger.kernel.org,
x86@kernel.org, kvm@vger.kernel.org, linux-doc@vger.kernel.org,
jgg@ziepe.ca, david.quigley@intel.com, lukas@wunner.de,
ksinyuk@kernel.org, rodrigo.vivi@intel.com,
cedric.xing@intel.com, sameo@meta.com, drdeeglaze@gmail.com,
James.Bottomley@HansenPartnership.com, aik@amd.com,
jpiotrowski@nvidia.com, qinkun@google.com, pgonda@google.com,
jic23@kernel.org, alistair.francis@wdc.com, ankita@nvidia.com,
suzuki.poulose@arm.com, kas@kernel.org,
rick.p.edgecombe@intel.com, elena.reshetova@intel.com,
dave.hansen@linux.intel.com,
sathyanarayanan.kuppuswamy@linux.intel.com, peter.fang@intel.com,
jarkko@kernel.org, zohar@linux.ibm.com, yeoreum.yun@arm.com,
aneesh.kumar@kernel.org, dave.jiang@intel.com,
nik.borisov@suse.com, sergii.dmytruk@3mdeb.com
Subject: [PATCH RFC v2 4/9] attestation: Prepare measurement registers
Date: Fri, 13 Nov 2026 17:08:33 +0100 [thread overview]
Message-ID: <20261113160838.2512652-5-jiri@resnulli.us> (raw)
In-Reply-To: <20261113160838.2512652-1-jiri@resnulli.us>
From: Jiri Pirko <jiri@nvidia.com>
Add the fixed MRs from the provider descriptor, their lookup and MR
extension, which advances an instance-wide MR generation.
The MR objects can be compile-checked here. CONFIG_ATTESTATION remains
unwired until the CTLV operation handlers complete the module.
Assisted-by: Cursor: GPT-5.6 Sol
Assisted-by: Cursor: Claude Opus 5.5
Signed-off-by: Jiri Pirko <jiri@nvidia.com>
---
RFC->RFCv2:
- kept the MR state in struct attestation_dev, which providers embed
- dropped the MR journal and its notifications
- counted MR changes in a plain MR generation
- retitled from "Prepare measurement register journal"
- used the helpers generated for the rewritten spec
- let an extend carry values for some of an MR's banks
- always provided mr-read with MRs
---
drivers/attestation/Makefile | 2 +-
drivers/attestation/core/core.c | 71 +++++++++++++++++++++++++++++
drivers/attestation/core/internal.h | 13 ++++++
drivers/attestation/core/mr.c | 64 ++++++++++++++++++++++++++
include/linux/attestation.h | 5 +-
5 files changed, 153 insertions(+), 2 deletions(-)
create mode 100644 drivers/attestation/core/mr.c
diff --git a/drivers/attestation/Makefile b/drivers/attestation/Makefile
index 8a75558a7013..28036586f5d8 100644
--- a/drivers/attestation/Makefile
+++ b/drivers/attestation/Makefile
@@ -1,4 +1,4 @@
# SPDX-License-Identifier: GPL-2.0
obj-$(CONFIG_ATTESTATION) += attestation.o
-attestation-y := core/core.o
+attestation-y := core/core.o core/mr.o
diff --git a/drivers/attestation/core/core.c b/drivers/attestation/core/core.c
index 587a0a9616b6..24abe0923306 100644
--- a/drivers/attestation/core/core.c
+++ b/drivers/attestation/core/core.c
@@ -213,6 +213,12 @@ bool attestation_registered(struct attestation_dev *att)
return registered;
}
+void attestation_mr_changed(struct attestation_dev *att)
+{
+ lockdep_assert_held(&att->lock);
+ att->mr_generation++;
+}
+
void attestation_stop(struct attestation_dev *att)
{
lockdep_assert_held(&att->lock);
@@ -221,6 +227,38 @@ void attestation_stop(struct attestation_dev *att)
xa_unlock(&attestation_instances);
}
+static struct attestation_mr *attestation_mr_alloc(struct attestation_dev *att,
+ const struct attestation_mr_props *props)
+{
+ struct attestation_mr *mr;
+ int ret;
+
+ ret = attestation_mr_props_validate(att->provider, props);
+ if (ret)
+ return ERR_PTR(ret);
+ if (xa_load(&att->mrs, props->id))
+ return ERR_PTR(-EEXIST);
+ mr = kzalloc_obj(*mr, GFP_KERNEL);
+ if (!mr)
+ return ERR_PTR(-ENOMEM);
+ mr->props = props;
+ ret = xa_insert(&att->mrs, props->id, mr, GFP_KERNEL);
+ if (ret) {
+ kfree(mr);
+ return ERR_PTR(ret);
+ }
+ return mr;
+}
+
+struct attestation_mr *attestation_mr_lookup_live(struct attestation_dev *att, unsigned int mr_id)
+{
+ struct attestation_mr *mr;
+
+ lockdep_assert_held(&att->lock);
+ mr = xa_load(&att->mrs, mr_id);
+ return mr ? mr : ERR_PTR(-ENOENT);
+}
+
/**
* attestation_evidence_write - Write an evidence object to its blob.
* @object: the requested object
@@ -252,11 +290,41 @@ void attestation_provide_ops(struct attestation_dev *att)
ctlv_attestation_evidence_get_provide(ctlv);
ctlv_attestation_evidence_get_enable(ctlv);
}
+
+ if (provider->mrs_count) {
+ ctlv_attestation_mr_get_provide(ctlv);
+ ctlv_attestation_mr_read_provide(ctlv);
+ if (provider->mr_extend)
+ ctlv_attestation_mr_extend_provide(ctlv);
+ }
+}
+
+static int attestation_mrs_create(struct attestation_dev *att)
+{
+ const struct attestation_provider *provider = att->provider;
+ size_t index;
+
+ for (index = 0; index < provider->mrs_count; index++) {
+ struct attestation_mr *mr;
+
+ mr = attestation_mr_alloc(att, &provider->mrs[index]);
+ if (IS_ERR(mr))
+ return PTR_ERR(mr);
+ }
+ return 0;
}
/* Runs from the release, so it must not reach the provider's module. */
static void attestation_state_free(struct attestation_dev *att)
{
+ struct attestation_mr *mr;
+ unsigned long index;
+
+ xa_for_each(&att->mrs, index, mr) {
+ xa_erase(&att->mrs, index);
+ kfree(mr);
+ }
+ xa_destroy(&att->mrs);
mutex_destroy(&att->lock);
}
@@ -338,11 +406,14 @@ struct attestation_dev *_attestation_alloc(struct device *parent,
return ERR_PTR(-ENOMEM);
att->provider = provider;
mutex_init(&att->lock);
+ xa_init(&att->mrs);
/* From here on, the release frees whatever was set up. */
ret = ctlv_device_init(&att->node, &attestation_class, parent, &att->ctlv);
if (!ret)
ret = ctlv_init(&att->ctlv, &att->node.dev, family, &attestation_ctlv_hooks);
+ if (!ret)
+ ret = attestation_mrs_create(att);
if (ret) {
put_device(&att->node.dev);
return ERR_PTR(ret);
diff --git a/drivers/attestation/core/internal.h b/drivers/attestation/core/internal.h
index f42bc3cd9a35..19c2ade5e6db 100644
--- a/drivers/attestation/core/internal.h
+++ b/drivers/attestation/core/internal.h
@@ -11,11 +11,24 @@
#define ATTESTATION_REGISTERED XA_MARK_1
+struct attestation_mr {
+ const struct attestation_mr_props *props;
+};
+
bool attestation_registered(struct attestation_dev *att);
void attestation_stop(struct attestation_dev *att);
+void attestation_mr_changed(struct attestation_dev *att);
int attestation_provider_validate(const struct attestation_provider *provider,
const struct ctlv_family *family);
void attestation_provide_ops(struct attestation_dev *att);
+struct attestation_mr *attestation_mr_lookup_live(struct attestation_dev *att, unsigned int mr_id);
+int attestation_mr_values_validate(const struct attestation_mr_props *props,
+ const struct attestation_digest_set *values, bool all_banks);
+int attestation_mr_extend_locked(struct attestation_dev *att, struct attestation_mr *mr,
+ const struct attestation_digest_set *values);
+
+int attestation_mr_props_encode(struct ctlv_cursor *reply, const struct attestation_mr *mr);
+
#endif /* _ATTESTATION_INTERNAL_H */
diff --git a/drivers/attestation/core/mr.c b/drivers/attestation/core/mr.c
new file mode 100644
index 000000000000..44a8c06df0c6
--- /dev/null
+++ b/drivers/attestation/core/mr.c
@@ -0,0 +1,64 @@
+// SPDX-License-Identifier: GPL-2.0-only
+#include <linux/device.h>
+#include <linux/errno.h>
+#include <linux/limits.h>
+
+#include "internal.h"
+
+/* @values follow the banks' order, so each bank comes once at most. */
+int attestation_mr_values_validate(const struct attestation_mr_props *props,
+ const struct attestation_digest_set *values, bool all_banks)
+{
+ size_t bank = 0, index;
+
+ if (!values || !values->values || !values->values_count ||
+ (all_banks && values->values_count != props->algorithms_count))
+ return -EINVAL;
+ for (index = 0; index < values->values_count; index++, bank++) {
+ while (bank < props->algorithms_count &&
+ props->algorithms[bank] != values->values[index].algorithm)
+ bank++;
+ if (bank == props->algorithms_count)
+ return -EINVAL;
+ }
+ return 0;
+}
+
+int attestation_mr_extend_locked(struct attestation_dev *att, struct attestation_mr *mr,
+ const struct attestation_digest_set *values)
+{
+ int ret;
+
+ lockdep_assert_held(&att->lock);
+ if (att->mr_generation == UINT_MAX) {
+ dev_warn(att->node.dev.parent,
+ "attestation instance %u stopped: mr generation exhausted\n",
+ att->index);
+ attestation_stop(att);
+ return -EOVERFLOW;
+ }
+ ret = att->provider->mr_extend(att, mr->props->id, values);
+ if (ret)
+ return ret;
+ attestation_mr_changed(att);
+ return 0;
+}
+
+int attestation_mr_props_encode(struct ctlv_cursor *reply, const struct attestation_mr *mr)
+{
+ u64 caps = 0;
+ size_t index;
+ bool ok = true;
+
+ ok &= ctlv_attestation_mr_get_items_id_put(reply, mr->props->id);
+ ok &= ctlv_attestation_mr_desc_name_put(reply, mr->props->name);
+ for (index = 0; index < mr->props->algorithms_count; index++)
+ ok &= ctlv_attestation_mr_desc_supported_hash_algorithms_put(
+ reply, mr->props->algorithms[index]);
+ if (mr->props->has_register_index)
+ ok &= ctlv_attestation_mr_desc_register_index_put(reply, mr->props->register_index);
+ if (mr->props->extendable)
+ caps |= CTLV_ATTESTATION_MR_CAPS_EXTEND;
+ ok &= ctlv_attestation_mr_desc_caps_put(reply, caps);
+ return ok ? 0 : -EMSGSIZE;
+}
diff --git a/include/linux/attestation.h b/include/linux/attestation.h
index 29bb776bfb41..7745938092c7 100644
--- a/include/linux/attestation.h
+++ b/include/linux/attestation.h
@@ -9,6 +9,7 @@
#include <linux/device.h>
#include <linux/mutex.h>
#include <linux/types.h>
+#include <linux/xarray.h>
#include <uapi/ctlv/ctlv_attestation_gen.h>
#include <uapi/linux/hash_info.h>
@@ -200,9 +201,11 @@ struct attestation_dev {
const struct attestation_provider *provider;
unsigned int index;
- /* Mutable instance state. */
+ /* Mutable instance and MR state. */
struct mutex lock;
+ unsigned int mr_generation;
+ struct xarray mrs;
};
/* What a CTLV callback of a family inheriting ctlv-attestation was handed. */
--
2.56.0
next prev parent reply other threads:[~2026-11-13 16:08 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-13 16:08 [PATCH RFC v2 0/9] attestation: Add a common subsystem and TDX support Jiri Pirko
2026-11-13 16:08 ` [PATCH RFC v2 1/9] attestation: Add the base family specification and generated files Jiri Pirko
2026-11-13 16:08 ` [PATCH RFC v2 2/9] Documentation: attestation: Add userspace ABI Jiri Pirko
2026-11-13 16:08 ` [PATCH RFC v2 3/9] attestation: Prepare provider and instance core Jiri Pirko
2026-11-13 16:08 ` Jiri Pirko [this message]
2026-11-13 16:08 ` [PATCH RFC v2 5/9] attestation: Add CTLV operation handling Jiri Pirko
2026-11-13 16:08 ` [PATCH RFC v2 6/9] Documentation: attestation: Describe how to write a provider Jiri Pirko
2026-11-13 16:08 ` [PATCH RFC v2 7/9] tdx-guest: Expose the native attestation service API Jiri Pirko
2026-11-13 16:08 ` [PATCH RFC v2 8/9] attestation: Add the TDX family specification and generated files Jiri Pirko
2026-11-13 16:08 ` [PATCH RFC v2 9/9] attestation: Add the TDX family implementation Jiri Pirko
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=20261113160838.2512652-5-jiri@resnulli.us \
--to=jiri@resnulli.us \
--cc=James.Bottomley@HansenPartnership.com \
--cc=aik@amd.com \
--cc=alistair.francis@wdc.com \
--cc=aneesh.kumar@kernel.org \
--cc=ankita@nvidia.com \
--cc=cedric.xing@intel.com \
--cc=dave.hansen@linux.intel.com \
--cc=dave.jiang@intel.com \
--cc=david.quigley@intel.com \
--cc=drdeeglaze@gmail.com \
--cc=elena.reshetova@intel.com \
--cc=jarkko@kernel.org \
--cc=jgg@ziepe.ca \
--cc=jic23@kernel.org \
--cc=jpiotrowski@nvidia.com \
--cc=kas@kernel.org \
--cc=ksinyuk@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=linux-api@vger.kernel.org \
--cc=linux-coco@lists.linux.dev \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lukas@wunner.de \
--cc=nik.borisov@suse.com \
--cc=peter.fang@intel.com \
--cc=pgonda@google.com \
--cc=qinkun@google.com \
--cc=rick.p.edgecombe@intel.com \
--cc=rodrigo.vivi@intel.com \
--cc=sameo@meta.com \
--cc=sathyanarayanan.kuppuswamy@linux.intel.com \
--cc=sergii.dmytruk@3mdeb.com \
--cc=suzuki.poulose@arm.com \
--cc=x86@kernel.org \
--cc=yeoreum.yun@arm.com \
--cc=zohar@linux.ibm.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®