Linux Confidential Computing Development
 help / color / mirror / Atom feed
From: Kameron Carr <kameroncarr@linux.microsoft.com>
To: "Aneesh Kumar K.V (Arm)" <aneesh.kumar@kernel.org>,
	linux-coco@lists.linux.dev, kvmarm@lists.linux.dev,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org
Cc: Alexey Kardashevskiy <aik@amd.com>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Dan Williams <dan.j.williams@intel.com>,
	Jason Gunthorpe <jgg@ziepe.ca>,
	Jonathan Cameron <jic23@kernel.org>,
	Marc Zyngier <maz@kernel.org>, Samuel Ortiz <sameo@rivosinc.com>,
	Steven Price <steven.price@arm.com>,
	Suzuki K Poulose <Suzuki.Poulose@arm.com>,
	Will Deacon <will@kernel.org>,
	Xu Yilun <yilun.xu@linux.intel.com>
Subject: Re: [RFC PATCH v4 07/11] coco: guest: arm64: Add guest APIs to read host-cached DA objects
Date: Tue, 18 Aug 2026 10:43:20 -0700	[thread overview]
Message-ID: <36877aa6-3f70-4da1-aecb-7209a33f8595@linux.microsoft.com> (raw)
In-Reply-To: <20260427082805.931832-8-aneesh.kumar@kernel.org>

On 4/27/2026 1:28 AM, Aneesh Kumar K.V (Arm) wrote:
> Introduce guest-side helpers to read host-cached DA objects
> (certificate, VCA, interface report, and measurements).
> 
> Add RHI_DA_OBJECT_SIZE and RHI_DA_OBJECT_READ definitions, then implement
> rhi_read_cached_object() that:
> - queries object size from host
> - validates size against MAX_CACHE_OBJ_SIZE
> - allocates a shared buffer
> - issues OBJECT_READ into shared memory
> - copies data into private memory and frees shared pages
> 
> Export the helper for later evidence-collection and verification code.
> 
> Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar@kernel.org>
> ---
>  arch/arm64/include/asm/rhi.h             |  8 +++
>  drivers/virt/coco/arm-cca-guest/rhi-da.c | 71 ++++++++++++++++++++++++
>  drivers/virt/coco/arm-cca-guest/rhi-da.h |  1 +
>  drivers/virt/coco/arm-cca-guest/rsi-da.h |  2 +
>  4 files changed, 82 insertions(+)
> 
> diff --git a/arch/arm64/include/asm/rhi.h b/arch/arm64/include/asm/rhi.h
> index 2b56a7760904..dc7a57370945 100644
> --- a/arch/arm64/include/asm/rhi.h
> +++ b/arch/arm64/include/asm/rhi.h
> @@ -48,6 +48,14 @@ unsigned long rhi_get_ipa_change_alignment(void);
>  				 RHI_DA_FEATURE_VDEV_SET_TDI_STATE)
>  #define RHI_DA_FEATURES			SMC_RHI_CALL(0x004B)
>  
> +#define RHI_DA_OBJECT_VCA			0x0
> +#define RHI_DA_OBJECT_CERTIFICATE		0x1
> +#define RHI_DA_OBJECT_MEASUREMENT		0x2
> +#define RHI_DA_OBJECT_INTERFACE_REPORT		0x3
> +#define RHI_DA_OBJECT_EXTENSION_EVIDENCE	0x4
> +#define RHI_DA_OBJECT_SIZE		SMC_RHI_CALL(0x004C)
> +#define RHI_DA_OBJECT_READ		SMC_RHI_CALL(0x004D)
> +
>  #define RHI_DA_VDEV_CONTINUE		SMC_RHI_CALL(0x0051)
>  
>  #define RHI_VDEV_MEASURE_HASH	0x0
> diff --git a/drivers/virt/coco/arm-cca-guest/rhi-da.c b/drivers/virt/coco/arm-cca-guest/rhi-da.c
> index d0f5ae320f83..73c599802a93 100644
> --- a/drivers/virt/coco/arm-cca-guest/rhi-da.c
> +++ b/drivers/virt/coco/arm-cca-guest/rhi-da.c
> @@ -3,6 +3,8 @@
>   * Copyright (C) 2026 ARM Ltd.
>   */
>  
> +#include <linux/string.h>
> +
>  #include "rsi-da.h"
>  #include "rhi-da.h"
>  
> @@ -283,3 +285,72 @@ int rhi_update_vdev_measurements_cache(struct pci_dev *pdev, const u8 *nonce)
>  		pci_err(pdev, "failed to get device measurement (%d)\n", ret);
>  	return ret;
>  }
> +
> +int rhi_read_cached_object(int vdev_id, int da_object_type, void **object, int *object_size)
> +{
> +	int ret;
> +	int data_size;
> +	void *data_buf_shared;
> +	struct page *shared_pages;
> +
> +	*object_size = 0;
> +	*object = NULL;
> +
> +	struct rsi_host_call *rhicall __free(kfree) =
> +		kmalloc(sizeof(struct rsi_host_call), GFP_KERNEL);

"Unused bits of the RsiHostCall structure SBZ"

It's best practice to use kzalloc for struct rsi_host_call.

> +	if (!rhicall)
> +		return -ENOMEM;
> +
> +	rhicall->imm = 0;
> +	rhicall->gprs[0] = RHI_DA_OBJECT_SIZE;
> +	rhicall->gprs[1] = vdev_id;
> +	rhicall->gprs[2] = da_object_type;
> +
> +	ret = rsi_host_call(rhicall);
> +	if (ret != RSI_SUCCESS)
> +		return -EIO;
> +
> +	if (rhicall->gprs[0] != RHI_DA_SUCCESS)
> +		return -EIO;
> +
> +	/* validate against the max cache object size used on host. */
> +	data_size = rhicall->gprs[1];
> +	if (data_size > MAX_CACHE_OBJ_SIZE || data_size == 0)
> +		return -EIO;

Consider making data_size and object_size size_t (unsigned long) to avoid
truncation and signed comparison.

For consistency with cca_verify_digests() and pci_tsm_evidence_object.len,
I would also change all the sizes in cca_collect_dev_evidence() to be
size_t.

> +	shared_pages = alloc_shared_pages(NUMA_NO_NODE, GFP_KERNEL, data_size);
> +	if (!shared_pages)
> +		return -ENOMEM;
> +
> +	data_buf_shared = page_address(shared_pages);
> +
> +	rhicall->imm = 0;
> +	rhicall->gprs[0] = RHI_DA_OBJECT_READ;
> +	rhicall->gprs[1] = vdev_id;
> +	rhicall->gprs[2] = da_object_type;
> +	rhicall->gprs[3] = virt_to_phys(data_buf_shared);
> +	rhicall->gprs[4] = data_size;
> +	rhicall->gprs[5] = 0; /* offset to read from */
> +	ret = rsi_host_call(rhicall);
> +	if (ret != RSI_SUCCESS || rhicall->gprs[0] != RHI_DA_SUCCESS) {
> +		free_shared_pages(shared_pages, data_size);
> +		return -EIO;
> +	}
> +
> +	if (data_size != rhicall->gprs[1]) {
> +		/* Short read */
> +		free_shared_pages(shared_pages, data_size);
> +		return -EIO;
> +	}
> +
> +	void *data_buf_private = kvmemdup(data_buf_shared,
> +					  data_size, GFP_KERNEL);
> +	/* free the shared pages irrespective of error condition */
> +	free_shared_pages(shared_pages, data_size);
> +	if (!data_buf_private)
> +		return -ENOMEM;
> +
> +	*object = data_buf_private;
> +	*object_size = data_size;
> +	return 0;
> +}
> diff --git a/drivers/virt/coco/arm-cca-guest/rhi-da.h b/drivers/virt/coco/arm-cca-guest/rhi-da.h
> index d32ccc48c0d0..f7655d7ecf18 100644
> --- a/drivers/virt/coco/arm-cca-guest/rhi-da.h
> +++ b/drivers/virt/coco/arm-cca-guest/rhi-da.h
> @@ -13,4 +13,5 @@ bool rhi_has_da_support(void);
>  int rhi_vdev_set_tdi_state(struct pci_dev *pdev, enum rhi_tdi_state target_state);
>  int rhi_update_vdev_interface_report_cache(struct pci_dev *pdev);
>  int rhi_update_vdev_measurements_cache(struct pci_dev *pdev, const u8 *nonce);
> +int rhi_read_cached_object(int vdev_id, int da_object_type, void **object, int *object_size);
>  #endif
> diff --git a/drivers/virt/coco/arm-cca-guest/rsi-da.h b/drivers/virt/coco/arm-cca-guest/rsi-da.h
> index 297cb800edc0..88067d2230ab 100644
> --- a/drivers/virt/coco/arm-cca-guest/rsi-da.h
> +++ b/drivers/virt/coco/arm-cca-guest/rsi-da.h
> @@ -10,6 +10,8 @@
>  #include <linux/pci-tsm.h>
>  #include <asm/rsi_smc.h>
>  
> +#define MAX_CACHE_OBJ_SIZE	SZ_16M

Why is the limit 16 MiB? I don't see that limitation in the RHI spec.
Does the limit come from PCI TSM?

Regards,
Kameron

> +
>  struct cca_guest_dsc {
>  	struct pci_tsm_devsec pci;
>  };


  reply	other threads:[~2026-08-18 17:43 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-27  8:27 [RFC PATCH v4 00/11] coco/TSM: Arm CCA guest TDISP lock/accept flow with verification and DMA enable Aneesh Kumar K.V (Arm)
2026-04-27  8:27 ` [RFC PATCH v4 01/11] coco: guest: arm64: Guest TSM callback and realm device lock support Aneesh Kumar K.V (Arm)
2026-04-27  8:27 ` [RFC PATCH v4 02/11] coco: guest: arm64: Fix a typo in the ARM_CCA_GUEST Kconfig help string ("and" -> "an") Aneesh Kumar K.V (Arm)
2026-04-27  8:27 ` [RFC PATCH v4 03/11] coco: guest: arm64: Add Realm Host Interface and guest DA helper Aneesh Kumar K.V (Arm)
2026-04-27  8:27 ` [RFC PATCH v4 04/11] coco: guest: arm64: Support guest-initiated TDI lock/unlock transitions Aneesh Kumar K.V (Arm)
2026-04-27  8:27 ` [RFC PATCH v4 05/11] coco: guest: arm64: Refresh interface-report cache during device lock Aneesh Kumar K.V (Arm)
2026-04-27  8:28 ` [RFC PATCH v4 06/11] coco: guest: arm64: Add measurement refresh via RHI_DA_VDEV_GET_MEASUREMENTS Aneesh Kumar K.V (Arm)
2026-04-27  8:28 ` [RFC PATCH v4 07/11] coco: guest: arm64: Add guest APIs to read host-cached DA objects Aneesh Kumar K.V (Arm)
2026-08-18 17:43   ` Kameron Carr [this message]
2026-04-27  8:28 ` [RFC PATCH v4 08/11] coco: guest: arm64: Verify DA evidence with RSI_VDEV_GET_INFO digests Aneesh Kumar K.V (Arm)
2026-04-27  8:28 ` [RFC PATCH v4 09/11] coco: guest: arm64: Hook TSM accept to Realm TDISP RUN transition Aneesh Kumar K.V (Arm)
2026-04-27  8:28 ` [RFC PATCH v4 10/11] coco: arm64: dma: Update force_dma_unencrypted for accepted devices Aneesh Kumar K.V (Arm)
2026-04-27  8:28 ` [RFC PATCH v4 11/11] coco: guest: arm64: Enable vdev DMA after attestation 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=36877aa6-3f70-4da1-aecb-7209a33f8595@linux.microsoft.com \
    --to=kameroncarr@linux.microsoft.com \
    --cc=Suzuki.Poulose@arm.com \
    --cc=aik@amd.com \
    --cc=aneesh.kumar@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=dan.j.williams@intel.com \
    --cc=jgg@ziepe.ca \
    --cc=jic23@kernel.org \
    --cc=kvmarm@lists.linux.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-coco@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maz@kernel.org \
    --cc=sameo@rivosinc.com \
    --cc=steven.price@arm.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox