[RFC PATCH v1 37/38] coco: guest: arm64: Add support for fetching device measurements

Aneesh Kumar K.V (Arm)
2025-07-28T13:56:17Z

Fetch device measurements using RSI_RDEV_GET_MEASUREMENTS.

Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar@kernel.org>
---
arch/arm64/include/asm/rsi_cmds.h | 11 +++++++
arch/arm64/include/asm/rsi_smc.h | 16 ++++++++++
drivers/virt/coco/arm-cca-guest/rsi-da.c | 39 ++++++++++++++++++++++++
drivers/virt/coco/arm-cca-guest/rsi-da.h | 2 ++
4 files changed, 68 insertions(+)

diff --git a/arch/arm64/include/asm/rsi_cmds.h b/arch/arm64/include/asm/rsi_cmds.h
index 3463d571d7db..42b998f44a0e 100644
--- a/arch/arm64/include/asm/rsi_cmds.h
+++ b/arch/arm64/include/asm/rsi_cmds.h
@@ -265,4 +265,15 @@ static inline unsigned long __rsi_rdev_stop(unsigned long vdev_id, unsigned long
return res.a0;
}

+static inline unsigned long __rsi_rdev_get_measurements(unsigned long vdev_id,
+ unsigned long inst_id,
+ phys_addr_t meas)
+{
+ struct arm_smccc_res res;
+
+ arm_smccc_1_1_invoke(SMC_RSI_RDEV_GET_MEASUREMENTS, vdev_id, inst_id, meas, &res);
+
+ return res.a0;
+}
+
#endif /* __ASM_RSI_CMDS_H */
diff --git a/arch/arm64/include/asm/rsi_smc.h b/arch/arm64/include/asm/rsi_smc.h
index f6aa647239c0..f051db54cdc3 100644
--- a/arch/arm64/include/asm/rsi_smc.h
+++ b/arch/arm64/include/asm/rsi_smc.h
@@ -202,6 +202,22 @@ struct rsi_host_call {

#define SMC_RSI_RDEV_GET_INTERFACE_REPORT SMC_RSI_FID(0x1a6)

+#define RSI_DEV_MEASURE_ALL BIT(0)
+#define RSI_DEV_MEASURE_SIGNED BIT(1)
+#define RSI_DEV_MEASURE_RAW BIT(2)
+
+struct rsi_device_measurements_params {
+ union {
+ struct {
+ u64 flags;
+ u8 indices[32];
+ u8 nounce[32];
+ };
+ u8 padding[0x100];
+ };
+};
+
+#define SMC_RSI_RDEV_GET_MEASUREMENTS SMC_RSI_FID(0x1a7)
#define SMC_RSI_RDEV_LOCK SMC_RSI_FID(0x1a9)
#define SMC_RSI_RDEV_START SMC_RSI_FID(0x1aa)
#define SMC_RSI_RDEV_STOP SMC_RSI_FID(0x1ab)
diff --git a/drivers/virt/coco/arm-cca-guest/rsi-da.c b/drivers/virt/coco/arm-cca-guest/rsi-da.c
index 64034d220e02..6222b10964ee 100644
--- a/drivers/virt/coco/arm-cca-guest/rsi-da.c
+++ b/drivers/virt/coco/arm-cca-guest/rsi-da.c
@@ -166,10 +166,31 @@ static long rhi_get_report(int vdev_id, int da_object_type, void **report, int *
return ret;
}

+static inline unsigned long
+rsi_rdev_get_measurements(struct pci_dev *pdev, unsigned long vdev_id,
+ unsigned long inst_id, phys_addr_t meas)
+{
+ unsigned long ret;
+
+ ret = __rsi_rdev_get_measurements(vdev_id, inst_id, meas);
+ if (ret != RSI_SUCCESS)
+ return ret;
+
+ do {
+ ret = rsi_rdev_continue(vdev_id, inst_id);
+ } while (ret == RSI_INCOMPLETE);
+ if (ret != RSI_SUCCESS) {
+ pci_err(pdev, "failed to communicate with the device (%lu)\n", ret);
+ return ret;
+ }
+ return RSI_SUCCESS;
+}
+
int rsi_device_lock(struct pci_dev *pdev)
{
unsigned long ret;
unsigned long tdisp_version;
+ struct rsi_device_measurements_params *rsi_dev_meas;
struct cca_guest_dsc *dsm = to_cca_guest_dsc(pdev);
int vdev_id = (pci_domain_nr(pdev->bus) << 16) |
PCI_DEVID(pdev->bus->number, pdev->devfn);
@@ -198,6 +219,17 @@ int rsi_device_lock(struct pci_dev *pdev)
return -EOPNOTSUPP;
}

+ rsi_dev_meas = (struct rsi_device_measurements_params *)__get_free_page(GFP_KERNEL);
+ rsi_dev_meas->flags = RSI_DEV_MEASURE_ALL;
+ ret = rsi_rdev_get_measurements(pdev, vdev_id, dsm->instance_id,
+ virt_to_phys(rsi_dev_meas));
+
+ free_page((unsigned long)rsi_dev_meas);
+ if (ret != RSI_SUCCESS) {
+ pci_err(pdev, "failed to get device measurement (%lu)\n", ret);
+ return -EIO;
+ }
+
/* Now make a host call to copy the interface report to guest. */
ret = rhi_get_report(vdev_id, RHI_DA_OBJECT_INTERFACE_REPORT,
&dsm->interface_report, &dsm->interface_report_size);
@@ -213,6 +245,13 @@ int rsi_device_lock(struct pci_dev *pdev)
return -EIO;
}

+ ret = rhi_get_report(vdev_id, RHI_DA_OBJECT_MEASUREMENT,
+ &dsm->measurements, &dsm->measurements_size);
+ if (ret) {
+ pci_err(pdev, "failed to get device certificate from the host (%lu)\n", ret);
+ return -EIO;
+ }
+
return ret;
}
static inline unsigned long rsi_rdev_start(struct pci_dev *pdev,
diff --git a/drivers/virt/coco/arm-cca-guest/rsi-da.h b/drivers/virt/coco/arm-cca-guest/rsi-da.h
index 71ee1edb832e..f26156d9be81 100644
--- a/drivers/virt/coco/arm-cca-guest/rsi-da.h
+++ b/drivers/virt/coco/arm-cca-guest/rsi-da.h
@@ -40,6 +40,8 @@ struct cca_guest_dsc {
int interface_report_size;
void *certificate;
int certificate_size;
+ void *measurements;
+ int measurements_size;
};

static inline struct cca_guest_dsc *to_cca_guest_dsc(struct pci_dev *pdev)
--
2.43.0