mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yeoreum Yun <yeoreum.yun@arm.com>
To: linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org,
	 linux-security-module@vger.kernel.org,
	linux-doc@vger.kernel.org,  linux-kselftest@vger.kernel.org,
	linux-acpi@vger.kernel.org,  acpica-devel@lists.linux.dev
Cc: Catalin Marinas <catalin.marinas@arm.com>,
	 Will Deacon <will@kernel.org>, Jason Gunthorpe <jgg@ziepe.ca>,
	 Suzuki Poulose <suzuki.poulose@arm.com>,
	 Steven Price <steven.price@arm.com>,
	Sami Mujawar <sami.mujawar@arm.com>,
	 thuth@redhat.com, "Rafael J. Wysocki" <rafael@kernel.org>,
	 Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>,
	 Pawel Chmielewski <pawel.chmielewski@intel.com>,
	 Jiri Pirko <jiri@resnulli.us>, Jonathan Corbet <corbet@lwn.net>,
	 Shuah Khan <shuah@kernel.org>, Len Brown <lenb@kernel.org>,
	 Shuah Khan <skhan@linuxfoundation.org>,
	 Randy Dunlap <rdunlap@infradead.org>,
	Mark Brown <broonie@kernel.org>
Subject: [PATCH RFC v3 1/8] arm64: rsi: Add helpers for Arm CCA measurement register operations
Date: Fri, 27 Nov 2026 15:32:56 +0000	[thread overview]
Message-ID: <20261127-arm_cca_mr-v3-1-df3230afce8f@arm.com> (raw)
In-Reply-To: <20261127-arm_cca_mr-v3-0-df3230afce8f@arm.com>

From: Sami Mujawar <sami.mujawar@arm.com>

Add static inline helper functions to support reading the Realm
Initial Measurement (RIM) and reading/extending the Realm
Extensible Measurement (REM) registers.

The indices of the Arm CCA measurement registers, as defined by
the Realm Management Monitor specification, are as follows:
    Index    Register
    0        RIM
    1 - 4    REM[0 - 3]

The rsi_measurement_extend() function allows extending REM[0–3]
registers with a caller-provided digest (up to 64 bytes).
Index 0 (RIM) is read-only and cannot be extended.

The rsi_measurement_read() function allows reading measurement
values from RIM (index 0) or REM[0–3] (indices 1–4). The returned
digest is expected to be 64 bytes.

Signed-off-by: Sami Mujawar <sami.mujawar@arm.com>
---
 include/linux/arm-rsi-cmds.h | 118 ++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 117 insertions(+), 1 deletion(-)

diff --git a/include/linux/arm-rsi-cmds.h b/include/linux/arm-rsi-cmds.h
index 3f7a6a833993b..188e5dc7eb587 100644
--- a/include/linux/arm-rsi-cmds.h
+++ b/include/linux/arm-rsi-cmds.h
@@ -1,6 +1,6 @@
 /* SPDX-License-Identifier: GPL-2.0-only */
 /*
- * Copyright (C) 2023 ARM Ltd.
+ * Copyright (C) 2023 - 2025 ARM Ltd.
  */
 
 #ifndef __LINUX_ARM_RSI_CMDS_H_
@@ -9,6 +9,7 @@
 #include <linux/arm-smccc-rsi.h>
 #include <linux/jump_label.h>
 #include <linux/string.h>
+#include <crypto/sha2.h>
 #include <asm/memory.h>
 
 #ifdef CONFIG_ARM_RMM_RSI
@@ -36,6 +37,26 @@ static inline bool is_realm_world(void) { return false; }
 #define RSI_GRANULE_SHIFT		12
 #define RSI_GRANULE_SIZE		(_AC(1, UL) << RSI_GRANULE_SHIFT)
 
+/*
+ * Maximum measurement data size in bytes.
+ * According to the RMM Specification, the width of the RmmRealmMeasurement type
+ * is 512 bits.
+ */
+#define RSI_MAX_MEASUREMENT_DATA_SIZE_BYTES  64
+
+/*
+ * Indices for the Realm Initial Measurement register (RIM) and the Realm
+ * Extensible Measurement registers (REMs).
+ * According to the RMM Specification, Realm attributes of a Realm include
+ * an array of measurement values. The first entry in this array is a RIM.
+ * The remaining entries in this array are REMs.
+ */
+#define RSI_INDEX_RIM		0
+#define RSI_INDEX_REM0		1
+#define RSI_INDEX_REM1		2
+#define RSI_INDEX_REM2		3
+#define RSI_INDEX_REM3		4
+
 enum ripas {
 	RSI_RIPAS_EMPTY = 0,
 	RSI_RIPAS_RAM = 1,
@@ -236,4 +257,99 @@ static inline unsigned long rsi_attestation_token_continue(phys_addr_t granule,
 	return res.a0;
 }
 
+#define RSI_MAX_DIGEST_SIZE	SHA512_DIGEST_SIZE
+
+struct rsi_measurement_extend_args {
+	unsigned long fid;
+	unsigned long idx;
+	unsigned long size;
+	u8	      digest[SHA512_DIGEST_SIZE];
+};
+
+/**
+ * rsi_measurement_extend - Extend the measurement value to the Realm Extensible
+ * Measurement (REM).
+ *
+ * @idx:		Index of the REM register.
+ *				Where:
+ *				Index	Register
+ *				1 - 4	REM[0-3]
+ * @digest:		The digest data to be extended.
+ * @digest_size:	Size of the digest data in bytes.
+ *
+ * Returns:
+ *  On success, returns RSI_SUCCESS.
+ *  Otherwise, -EINVAL
+ */
+static inline unsigned long rsi_measurement_extend(u32 idx,
+						   const u8 *digest,
+						   unsigned long digest_size)
+{
+	union {
+		struct arm_smccc_1_2_regs regs;
+		struct rsi_measurement_extend_args extend;
+	} args = { 0 };
+
+	/*
+	 * Index 0 is for RIM (which is Read Only), while
+	 * REM[0-3] are indexed from 1 - 4.
+	 * The digest size can be at the most 64 bytes.
+	 */
+	if (!digest || idx < RSI_INDEX_REM0 || idx > RSI_INDEX_REM3 ||
+	    digest_size == 0 || digest_size > RSI_MAX_MEASUREMENT_DATA_SIZE_BYTES)
+		return -EINVAL;
+
+	args.extend.fid = SMC_RSI_MEASUREMENT_EXTEND;
+	args.extend.idx = idx;
+	args.extend.size = digest_size;
+	memcpy(&args.extend.digest, digest, digest_size);
+	arm_smccc_1_2_smc(&args.regs, &args.regs);
+
+	if (args.regs.a0 != RSI_SUCCESS)
+		return -EINVAL;
+
+	return RSI_SUCCESS;
+}
+
+/**
+ * rsi_measurement_read - Read the measurement value from the Realm Initial
+ * Measurement (RIM) or the Realm Extensible Measurement (REM) register.
+ *
+ * @idx:		Index of the RIM or REM register.
+ *				Where:
+ *				Index	Register
+ *				0	RIM
+ *				1 - 4	REM[0-3]
+ * @digest:			The digest data to be returned.
+ * @digest_size:	Size of the digest data buffer in bytes.
+ *
+ * Returns:
+ *  On success, returns RSI_SUCCESS.
+ *  Otherwise, -EINVAL
+ */
+static inline unsigned long rsi_measurement_read(u32 idx,
+						 u8 *digest,
+						 unsigned long digest_size)
+{
+	struct arm_smccc_1_2_regs regs = { 0 };
+
+	/*
+	 * The digest size can be at the most 64 bytes, if less then 64 bytes
+	 * it is zero padded.
+	 */
+	if (!digest || idx > RSI_INDEX_REM3 ||
+	    digest_size == 0 || digest_size > RSI_MAX_MEASUREMENT_DATA_SIZE_BYTES)
+		return -EINVAL;
+
+	regs.a0 = SMC_RSI_MEASUREMENT_READ;
+	regs.a1 = idx;
+	arm_smccc_1_2_smc(&regs, &regs);
+
+	if (regs.a0 != RSI_SUCCESS)
+		return -EINVAL;
+
+	memcpy(digest, &regs.a1, digest_size);
+	return regs.a0;
+}
+
 #endif /* __LINUX_ARM_RSI_CMDS_H_ */

-- 
2.43.0


  reply	other threads:[~2026-11-27 15:33 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27 15:32 [PATCH RFC v3 0/8] attestation: provider: add CCA Realm Guest provider Yeoreum Yun
2026-11-27 15:32 ` Yeoreum Yun [this message]
2026-11-27 15:32 ` [PATCH RFC v3 2/8] arm64: rsi: Add realm hash algorithm defines Yeoreum Yun
2026-11-27 15:32 ` [PATCH RFC v3 3/8] arm64: acpi: Enable ACPI CCEL support Yeoreum Yun
2026-11-27 16:28   ` Suzuki K Poulose
2026-11-27 18:12     ` Yeoreum Yun
2026-11-27 15:32 ` [PATCH RFC v3 4/8] acpi: add CCtype value macros for CCEL table Yeoreum Yun
2026-11-27 15:33 ` [PATCH RFC v3 5/8] Documentation/ctlv: introduce ctlv-attestation-cca-guest family Yeoreum Yun
2026-11-27 15:33 ` [PATCH RFC v3 6/8] ctlv: add auto-generated files for ctlv-attestation-cca-guest Yeoreum Yun
2026-11-27 15:33 ` [PATCH RFC v3 7/8] attestation: providers: introduce CCA Guest attestation provider Yeoreum Yun
2026-11-27 17:07   ` Jason Gunthorpe
2026-11-27 18:24     ` Yeoreum Yun
2026-11-27 18:35       ` Jason Gunthorpe
2026-11-27 19:11         ` Yeoreum Yun
2026-11-27 19:13           ` Yeoreum Yun
2026-11-27 19:18           ` Jason Gunthorpe
2026-11-27 19:40             ` Yeoreum Yun
2026-11-27 18:27     ` Yeoreum Yun
2026-11-27 18:36       ` Jason Gunthorpe
2026-11-27 15:33 ` [PATCH RFC v3 8/8] selftest: attestation: add cca_guest_attestation_test selftest Yeoreum Yun
2026-11-27 17:09   ` Jason Gunthorpe

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=20261127-arm_cca_mr-v3-1-df3230afce8f@arm.com \
    --to=yeoreum.yun@arm.com \
    --cc=acpica-devel@lists.linux.dev \
    --cc=broonie@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=corbet@lwn.net \
    --cc=jgg@ziepe.ca \
    --cc=jiri@resnulli.us \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=maciej.wieczor-retman@intel.com \
    --cc=pawel.chmielewski@intel.com \
    --cc=rafael@kernel.org \
    --cc=rdunlap@infradead.org \
    --cc=sami.mujawar@arm.com \
    --cc=shuah@kernel.org \
    --cc=skhan@linuxfoundation.org \
    --cc=steven.price@arm.com \
    --cc=suzuki.poulose@arm.com \
    --cc=thuth@redhat.com \
    --cc=will@kernel.org \
    /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®