Re: [RFC PATCH v1 32/38] coco: guest: arm64: Add support for guest initiated TDI bind/unbind

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 28 Jul 2025 19:22:09 +0530
"Aneesh Kumar K.V (Arm)" <aneesh.kumar@xxxxxxxxxx> wrote:

> Add RHI for VDEV_SET_TDI_STATE
> 
> Note: This is not part of RHI spec. This is a POC implementation
> and will be later switced to correct interface defined by RHI.
> 
> Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar@xxxxxxxxxx>

A few minor comments. 

Maybe we need some discussion of how this is used.

> diff --git a/arch/arm64/kernel/rhi.c b/arch/arm64/kernel/rhi.c
> new file mode 100644
> index 000000000000..3685b50c2e94
> --- /dev/null
> +++ b/arch/arm64/kernel/rhi.c
> @@ -0,0 +1,35 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Copyright (C) 2025 ARM Ltd.
> + */
> +
> +#include <asm/memory.h>
> +#include <asm/string.h>
> +#include <asm/rsi.h>
> +#include <asm/rhi.h>
> +
> +#include <linux/slab.h>
> +
> +long rhi_da_vdev_set_tdi_state(unsigned long guest_rid, unsigned long target_state)
> +{
> +	long ret;
> +	struct rsi_host_call *rhi_call;
> +
> +	rhi_call = kmalloc(sizeof(struct rsi_host_call), GFP_KERNEL);
	struct rsi_host_call *rhi_call __free(kfree) =
		kmalloc(sizeof(*rhi_call), GFP_KERNEL);

then direct returns on errors.

> +	if (!rhi_call)
> +		return -ENOMEM;
> +
> +	rhi_call->imm = 0;
> +	rhi_call->gprs[0] = RHI_DA_VDEV_SET_TDI_STATE;
> +	rhi_call->gprs[1] = guest_rid;
> +	rhi_call->gprs[2] = target_state;
> +
> +	ret = rsi_host_call(virt_to_phys(rhi_call));
> +	if (ret != RSI_SUCCESS)
> +		ret =  -EIO;
> +	else
> +		ret = rhi_call->gprs[0];
> +
> +	kfree(rhi_call);
> +	return ret;
> +}
> diff --git a/drivers/virt/coco/arm-cca-guest/arm-cca.c b/drivers/virt/coco/arm-cca-guest/arm-cca.c
> index 2c0190bcb2a9..de70fba09e92 100644
> --- a/drivers/virt/coco/arm-cca-guest/arm-cca.c
> +++ b/drivers/virt/coco/arm-cca-guest/arm-cca.c
> @@ -222,11 +222,20 @@ static void cca_tsm_pci_remove(struct pci_tsm *tsm)
>  
>  static int cca_tsm_lock(struct pci_dev *pdev)
>  {
> -	unsigned long ret;
> +	long ret;

Push this earlier. It doesn't do any harm that I can see and will reduce churn

> +	int vdev_id = (pci_domain_nr(pdev->bus) << 16) |
> +		PCI_DEVID(pdev->bus->number, pdev->devfn);
>  
> +	ret = rhi_da_vdev_set_tdi_state(vdev_id, RHI_DA_TDI_CONFIG_LOCKED);
> +	if (ret) {
> +		pci_err(pdev, "failed to TSM bind the device (%ld)\n", ret);
> +		return -EIO;
> +	}
> +
> +	/* This will be done by above rhi in later spec */
>  	ret = rsi_device_lock(pdev);
>  	if (ret) {
> -		pci_err(pdev, "failed to lock the device (%lu)\n", ret);
> +		pci_err(pdev, "failed to lock the device (%ld)\n", ret);
>  		return -EIO;
>  	}
>  	return 0;

>  
>  static const struct pci_tsm_ops cca_pci_ops = {
> diff --git a/drivers/virt/coco/arm-cca-host/arm-cca.c b/drivers/virt/coco/arm-cca-host/arm-cca.c
> index 0807fcf8d222..18d0a627baa4 100644
> --- a/drivers/virt/coco/arm-cca-host/arm-cca.c
> +++ b/drivers/virt/coco/arm-cca-host/arm-cca.c
> @@ -254,9 +254,13 @@ static struct pci_tdi *cca_tsm_bind(struct pci_dev *pdev, struct pci_dev *pf0_de
>  static void cca_tsm_unbind(struct pci_tdi *tdi)
>  {
>  	struct realm *realm = &tdi->kvm->arch.realm;
> -
> +	/*
> +	 * FIXME!!
> +	 * All the related DEV RIPAS regions should be unmapped by now.
> +	 * For now we handle them during stage2 teardown. There is no
> +	 * bound IPA address available here. Possibly dmabuf can help
> +	 */
>  	rme_unbind_vdev(realm, tdi->pdev, tdi->pdev->tsm->dsm_dev);
> -

Tidy up these whitespace changes.  Just adds noise.

>  	module_put(THIS_MODULE);
>  }
>  





[Index of Archives]     [DMA Engine]     [Linux Coverity]     [Linux USB]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Greybus]

  Powered by Linux