Linux Confidential Computing Development
 help / color / mirror / Atom feed
From: Baolu Lu <baolu.lu@linux.intel.com>
To: "Aneesh Kumar K.V (Arm)" <aneesh.kumar@kernel.org>,
	linux-coco@lists.linux.dev
Cc: baolu.lu@linux.intel.com, Alex Williamson <alex@shazbot.org>,
	Alexey Kardashevskiy <aik@amd.com>,
	Bjorn Helgaas <bhelgaas@google.com>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Jacob Pan <jacob.pan@linux.microsoft.com>,
	Jason Gunthorpe <jgg@ziepe.ca>, Joerg Roedel <joro@8bytes.org>,
	Jonathan Cameron <jic23@kernel.org>,
	Jonathan Hunter <jonathanh@nvidia.com>,
	Kevin Tian <kevin.tian@intel.com>,
	Krishna Reddy <vdumpa@nvidia.com>, Lukas Wunner <lukas@wunner.de>,
	Nicolin Chen <nicolinc@nvidia.com>,
	Robin Murphy <robin.murphy@arm.com>,
	Samuel Ortiz <sameo@rivosinc.com>,
	Shameer Kolothum <shameerali.kolothum.thodi@huawei.com>,
	Steven Price <steven.price@arm.com>,
	Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>,
	Suzuki K Poulose <suzuki.poulose@arm.com>,
	Thierry Reding <thierry.reding@kernel.org>,
	Vasant Hegde <vasant.hegde@amd.com>,
	Will Deacon <will@kernel.org>,
	Xu Yilun <yilun.xu@linux.intel.com>,
	Ashish Kalra <ashish.kalra@amd.com>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	iommu@lists.linux.dev,
	Jonathan Cameron <jonathan.cameron@huawei.com>,
	Tom Lendacky <thomas.lendacky@amd.com>,
	kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-pci@vger.kernel.org, linux-tegra@vger.kernel.org,
	patches@lists.linux.dev
Subject: Re: [PATCH v9 09/13] iommufd/viommu: Select vIOMMU operations before allocation
Date: Fri, 20 Nov 2026 12:44:10 +0800	[thread overview]
Message-ID: <2e8a853f-9e7b-4cce-b578-2dac0c564eb5@linux.intel.com> (raw)
In-Reply-To: <20261116081935.85372-10-aneesh.kumar@kernel.org>

On 11/16/2026 4:19 PM, Aneesh Kumar K.V (Arm) wrote:
> Physical IOMMU drivers currently provide the vIOMMU size and
> initialization callbacks through iommu_ops. The initialization callback
> then selects and installs the corresponding iommufd_viommu_ops.
> 
> Add iommu_ops::get_viommu_ops() to select the operations from the
> physical device and requested vIOMMU type before allocation. Move the
> size and initialization callbacks into iommufd_viommu_ops. The core can
> then validate the selected operations, allocate the driver structure,
> initialize it, and install the operations.
> 
> Convert AMD, Arm SMMUv3, Tegra CMDQV, and the selftest backend to the
> new interface.
> 
> The current code requires a valid parent HWPT before calling
> viommu_init(), which selects the vIOMMU operations. A later patch adds
> an operations flag indicating that a vIOMMU type does not require a
> parent HWPT. Selecting the operations earlier allows the core to check
> that flag before deciding whether to look up and validate a parent HWPT.
> 
> Temporarily disable AMD vIOMMU allocation by returning NULL from
> amd_iommufd_get_viommu_ops() while the vIOMMU interfaces are being
> updated.
> 
> Cc: Joerg Roedel <joro@8bytes.org>
> Cc: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
> Cc: Vasant Hegde <vasant.hegde@amd.com>
> Cc: Will Deacon <will@kernel.org>
> Cc: Robin Murphy <robin.murphy@arm.com>
> Cc: Thierry Reding <thierry.reding@kernel.org>
> Cc: Krishna Reddy <vdumpa@nvidia.com>
> Cc: Jonathan Hunter <jonathanh@nvidia.com>
> Cc: Jason Gunthorpe <jgg@ziepe.ca>
> Cc: Kevin Tian <kevin.tian@intel.com>
> Cc: linux-arm-kernel@lists.infradead.org
> Cc: linux-tegra@vger.kernel.org
> Cc: iommu@lists.linux.dev
> Based on original patch by Jason Gunthorpe <jgg@nvidia.com>
> Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar@kernel.org>
> ---
>   drivers/iommu/amd/iommu.c                     |  3 +-
>   drivers/iommu/amd/iommufd.c                   | 18 ++++++---
>   drivers/iommu/amd/iommufd.h                   | 11 ++++--
>   drivers/iommu/amd/nested.c                    |  4 +-
>   .../arm/arm-smmu-v3/arm-smmu-v3-iommufd.c     | 37 +++++++++++--------
>   drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c   |  7 ++--
>   drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h   | 16 ++++----
>   .../iommu/arm/arm-smmu-v3/tegra241-cmdqv.c    | 24 ++++++++----
>   drivers/iommu/iommufd/selftest.c              | 31 +++++++++++-----
>   drivers/iommu/iommufd/viommu.c                | 32 ++++++++--------
>   include/linux/iommu.h                         | 20 +++-------
>   include/linux/iommufd.h                       | 14 +++++++
>   12 files changed, 129 insertions(+), 88 deletions(-)
> 

[...]

> diff --git a/drivers/iommu/iommufd/viommu.c b/drivers/iommu/iommufd/viommu.c
> index 0d162a3fdc98..2eba1562a704 100644
> --- a/drivers/iommu/iommufd/viommu.c
> +++ b/drivers/iommu/iommufd/viommu.c
> @@ -33,7 +33,7 @@ int iommufd_viommu_alloc_ioctl(struct iommufd_ucmd *ucmd)
>   	struct iommufd_viommu *viommu;
>   	struct iommufd_device *idev;
>   	struct iommu_device *iommu_dev;
> -	const struct iommu_ops *ops;
> +	const struct iommufd_viommu_ops *ops;
>   	size_t viommu_size;
>   	int rc;
>   
> @@ -49,23 +49,25 @@ int iommufd_viommu_alloc_ioctl(struct iommufd_ucmd *ucmd)
>   		rc = -EOPNOTSUPP;
>   		goto out_put_idev;
>   	}
> -	ops = iommu_dev->ops;
> -	if (!ops->get_viommu_size || !ops->viommu_init) {
> +	if (!iommu_dev->ops->get_viommu_ops) {
>   		rc = -EOPNOTSUPP;
>   		goto out_put_idev;
>   	}
> -
> -	viommu_size = ops->get_viommu_size(idev->dev, cmd->type);
> -	if (!viommu_size) {
> +	ops = iommu_dev->ops->get_viommu_ops(idev->dev, cmd->type);
> +	if (!ops) {
>   		rc = -EOPNOTSUPP;
>   		goto out_put_idev;
>   	}
> -
>   	/*
> -	 * It is a driver bug for providing a viommu_size smaller than the core
> -	 * vIOMMU structure size
> +	 * It is a driver bug to omit the required operations or provide a size
> +	 * smaller than the core vIOMMU structure.
>   	 */
> -	if (WARN_ON_ONCE(viommu_size < sizeof(*viommu))) {
> +	if (WARN_ON_ONCE(!ops->get_viommu_size || !ops->viommu_init)) {
> +		rc = -EOPNOTSUPP;
> +		goto out_put_idev;
> +	}
> +	viommu_size = ops->get_viommu_size(idev->dev, cmd->type);
> +	if (!viommu_size || WARN_ON_ONCE(viommu_size < sizeof(*viommu))) {
>   		rc = -EOPNOTSUPP;
>   		goto out_put_idev;
>   	}
> @@ -104,16 +106,12 @@ int iommufd_viommu_alloc_ioctl(struct iommufd_ucmd *ucmd)
>   	 */
>   	viommu->iommu_dev = iommu_dev;
>   
> -	rc = ops->viommu_init(viommu, hwpt_paging->common.domain,
> +	rc = ops->viommu_init(viommu, idev->dev,
> +			      hwpt_paging->common.domain,
>   			      user_data.len ? &user_data : NULL);
>   	if (rc)
>   		goto out_put_hwpt;
> -
> -	/* It is a driver bug that viommu->ops isn't filled */
> -	if (WARN_ON_ONCE(!viommu->ops)) {
> -		rc = -EOPNOTSUPP;
> -		goto out_put_hwpt;
> -	}
> +	viommu->ops = ops;
>   
>   	cmd->out_viommu_id = viommu->obj.id;
>   	rc = iommufd_ucmd_respond(ucmd, sizeof(*cmd));
> diff --git a/include/linux/iommu.h b/include/linux/iommu.h
> index ef5043752a36..f27064917df7 100644
> --- a/include/linux/iommu.h
> +++ b/include/linux/iommu.h
> @@ -46,6 +46,7 @@ struct iommu_dma_msi_cookie;
>   struct iommu_fault_param;
>   struct iommufd_ctx;
>   struct iommufd_viommu;
> +struct iommufd_viommu_ops;
>   struct msi_desc;
>   struct msi_msg;
>   
> @@ -669,16 +670,8 @@ __iommu_copy_struct_to_user(const struct iommu_user_data *dst_data,
>    *		- IOMMU_DOMAIN_DMA: must use a dma domain
>    *		- 0: use the default setting
>    * @default_domain_ops: the default ops for domains
> - * @get_viommu_size: Get the size of a driver-level vIOMMU structure for a given
> - *                   @dev corresponding to @viommu_type. Driver should return 0
> - *                   if vIOMMU isn't supported accordingly. It is required for
> - *                   driver to use the VIOMMU_STRUCT_SIZE macro to sanitize the
> - *                   driver-level vIOMMU structure related to the core one
> - * @viommu_init: Init the driver-level struct of an iommufd_viommu on a physical
> - *               IOMMU instance @viommu->iommu_dev, as the set of virtualization
> - *               resources shared/passed to user space IOMMU instance. Associate
> - *               it with a nesting @parent_domain. It is required for driver to
> - *               set @viommu->ops pointing to its own viommu_ops
> + * @get_viommu_ops: Return the vIOMMU operations supported by @dev for a type.
> + *                  Return NULL if the type is unsupported.
>    * @owner: Driver module providing these ops
>    * @identity_domain: An always available, always attachable identity
>    *                   translation.
> @@ -729,11 +722,8 @@ struct iommu_ops {
>   
>   	int (*def_domain_type)(struct device *dev);
>   
> -	size_t (*get_viommu_size)(struct device *dev,
> -				  enum iommu_viommu_type viommu_type);
> -	int (*viommu_init)(struct iommufd_viommu *viommu,
> -			   struct iommu_domain *parent_domain,
> -			   const struct iommu_user_data *user_data);
> +	const struct iommufd_viommu_ops *(*get_viommu_ops)(
> +		struct device *dev, enum iommu_viommu_type viommu_type);
>   
>   	const struct iommu_domain_ops *default_domain_ops;
>   	struct module *owner;
> diff --git a/include/linux/iommufd.h b/include/linux/iommufd.h
> index d1fd7888fc91..5f5c67b24134 100644
> --- a/include/linux/iommufd.h
> +++ b/include/linux/iommufd.h
> @@ -148,6 +148,15 @@ struct iommufd_hw_queue {
>   
>   /**
>    * struct iommufd_viommu_ops - vIOMMU specific operations
> + * @get_viommu_size: Get the size of a driver-level vIOMMU structure for a given
> + *                   @dev corresponding to @viommu_type. Driver should return 0
> + *                   if vIOMMU isn't supported accordingly. It is required for
> + *                   driver to use the VIOMMU_STRUCT_SIZE macro to sanitize the
> + *                   driver-level vIOMMU structure related to the core one
> + * @viommu_init: Init the driver-level struct of an iommufd_viommu on a physical
> + *               IOMMU instance @viommu->iommu_dev, as the set of virtualization
> + *               resources shared/passed to user space IOMMU instance. Associate
> + *               it with a nesting @parent_domain.
>    * @destroy: Clean up all driver-specific parts of an iommufd_viommu. The memory
>    *           of the vIOMMU will be free-ed by iommufd core after calling this op
>    * @alloc_domain_nested: Allocate a IOMMU_DOMAIN_NESTED on a vIOMMU that holds a
> @@ -190,6 +199,11 @@ struct iommufd_hw_queue {
>    *                      does, it should set it to the @hw_queue->destroy pointer
>    */
>   struct iommufd_viommu_ops {
> +	size_t (*get_viommu_size)(struct device *dev,
> +		enum iommu_viommu_type type);
> +	int (*viommu_init)(struct iommufd_viommu *viommu, struct device *dev,
> +		struct iommu_domain *parent_domain,
> +		const struct iommu_user_data *user_data);
>   	void (*destroy)(struct iommufd_viommu *viommu);
>   	struct iommu_domain *(*alloc_domain_nested)(
>   		struct iommufd_viommu *viommu, u32 flags,

For changes in iommufd/viommu common code,

Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com>

  reply	other threads:[~2026-11-20  4:44 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16  8:19 [PATCH v9 00/13] iommufd: TSM-backed virtual IOMMUs for confidential guests Aneesh Kumar K.V (Arm)
2026-11-16  8:19 ` [PATCH v9 01/13] virt: coco: tsm: Require PCI operations when registering a TSM Aneesh Kumar K.V (Arm)
2026-11-19  7:18   ` Baolu Lu
2026-11-16  8:19 ` [PATCH v9 02/13] virt: coco: tsm: Remove the device from lookup before PCI teardown Aneesh Kumar K.V (Arm)
2026-11-18  6:43   ` Xu Yilun
2026-11-16  8:19 ` [PATCH v9 03/13] virt: coco: tsm: Complete PCI registration before publishing the device Aneesh Kumar K.V (Arm)
2026-11-18  7:11   ` Xu Yilun
2026-11-16  8:19 ` [PATCH v9 04/13] iommufd/device: Associate KVM file pointer with iommufd_device Aneesh Kumar K.V (Arm)
2026-11-19  8:13   ` Baolu Lu
2026-11-16  8:19 ` [PATCH v9 05/13] iommufd/viommu: Keep a reference to the KVM file Aneesh Kumar K.V (Arm)
2026-11-19  8:20   ` Baolu Lu
2026-11-16  8:19 ` [PATCH v9 06/13] iommufd: Add a vDEVICE operation ioctl framework Aneesh Kumar K.V (Arm)
2026-11-20  1:17   ` Baolu Lu
2026-11-16  8:19 ` [PATCH v9 07/13] PCI/TSM: Remove the legacy guest request interface Aneesh Kumar K.V (Arm)
2026-11-20  1:37   ` Baolu Lu
2026-11-16  8:19 ` [PATCH v9 08/13] PCI/TSM: Keep connections active while device contexts exist Aneesh Kumar K.V (Arm)
2026-11-20  2:58   ` Baolu Lu
2026-11-16  8:19 ` [PATCH v9 09/13] iommufd/viommu: Select vIOMMU operations before allocation Aneesh Kumar K.V (Arm)
2026-11-20  4:44   ` Baolu Lu [this message]
2026-11-16  8:19 ` [PATCH v9 10/13] iommufd/viommu: Allow PCI TSM backends to provide vIOMMU operations Aneesh Kumar K.V (Arm)
2026-11-19 19:50   ` Jacob Pan
2026-11-16  8:19 ` [PATCH v9 11/13] iommufd/viommu: Allow vIOMMUs without a parent HWPT Aneesh Kumar K.V (Arm)
2026-11-16  8:19 ` [PATCH v9 12/13] PCI/TSM: Wait for device contexts before removing a DSM Aneesh Kumar K.V (Arm)
2026-11-16  8:19 ` [PATCH v9 13/13] PCI/TSM: Wait for users during unregister 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=2e8a853f-9e7b-4cce-b578-2dac0c564eb5@linux.intel.com \
    --to=baolu.lu@linux.intel.com \
    --cc=aik@amd.com \
    --cc=alex@shazbot.org \
    --cc=aneesh.kumar@kernel.org \
    --cc=ashish.kalra@amd.com \
    --cc=bhelgaas@google.com \
    --cc=catalin.marinas@arm.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=iommu@lists.linux.dev \
    --cc=jacob.pan@linux.microsoft.com \
    --cc=jgg@ziepe.ca \
    --cc=jic23@kernel.org \
    --cc=jonathan.cameron@huawei.com \
    --cc=jonathanh@nvidia.com \
    --cc=joro@8bytes.org \
    --cc=kevin.tian@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-coco@lists.linux.dev \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=lukas@wunner.de \
    --cc=nicolinc@nvidia.com \
    --cc=patches@lists.linux.dev \
    --cc=robin.murphy@arm.com \
    --cc=sameo@rivosinc.com \
    --cc=shameerali.kolothum.thodi@huawei.com \
    --cc=steven.price@arm.com \
    --cc=suravee.suthikulpanit@amd.com \
    --cc=suzuki.poulose@arm.com \
    --cc=thierry.reding@kernel.org \
    --cc=thomas.lendacky@amd.com \
    --cc=vasant.hegde@amd.com \
    --cc=vdumpa@nvidia.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