[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250616124347.GV1174925@nvidia.com>
Date: Mon, 16 Jun 2025 09:43:47 -0300
From: Jason Gunthorpe <jgg@...dia.com>
To: Nicolin Chen <nicolinc@...dia.com>
Cc: kevin.tian@...el.com, will@...nel.org, robin.murphy@....com,
joro@...tes.org, praan@...gle.com, yi.l.liu@...el.com,
peterz@...radead.org, jsnitsel@...hat.com,
linux-arm-kernel@...ts.infradead.org, iommu@...ts.linux.dev,
linux-kernel@...r.kernel.org, patches@...ts.linux.dev,
baolu.lu@...ux.intel.com
Subject: Re: [PATCH v2 06/14] iommu: Introduce get_viommu_size and
viommu_init ops
On Fri, Jun 13, 2025 at 11:35:18PM -0700, Nicolin Chen wrote:
> So far, a vIOMMU object has been allocated by IOMMU driver and initialized
> with the driver-level structure, before it returns to the iommufd core for
> core-level structure initialization. It has been requiring iommufd core to
> expose some core structure/helpers in its driver.c file, which result in a
> size increase of this driver module.
>
> Meanwhile, IOMMU drivers are now requiring more vIOMMU-base structures for
> some advanced feature, such as the existing vDEVICE and a future HW_QUEUE.
> Initializing a core-structure later than driver-structure gives for-driver
> helpers some trouble, when they are used by IOMMU driver assuming that the
> new structure (including core) are fully initialized, for example:
>
> core: viommu = ops->viommu_alloc();
> driver: // my_viommu is successfully allocated
> driver: my_viommu = iommufd_viommu_alloc(...);
> driver: // This may crash if it reads viommu->ictx
> driver: new = iommufd_new_viommu_helper(my_viommu->core ...);
> core: viommu->ictx = ucmd->ictx;
> core: ...
>
> To ease such a condition, allow the IOMMU driver to report the size of its
> vIOMMU structure, let the core allocate a vIOMMU object and initialize the
> core-level structure first, and then hand it over the driver to initialize
> its driver-level structure.
>
> Thus, this requires two new iommu ops, get_viommu_size and viommu_init, so
> iommufd core can communicate with drivers to replace the viommu_alloc op:
>
> core: viommu = ops->get_viommu_size();
> driver: return VIOMMU_STRUCT_SIZE();
> core: viommu->ictx = ucmd->ictx; // and others
> core: rc = ops->viommu_init();
> driver: // This is safe now as viommu->ictx is inited
> driver: new = iommufd_new_viommu_helper(my_viommu->core ...);
> core: ...
>
> This also adds a VIOMMU_STRUCT_SIZE macro, for drivers to use, which would
> statically sanitize the driver structure.
>
> Suggested-by: Jason Gunthorpe <jgg@...dia.com>
> Signed-off-by: Nicolin Chen <nicolinc@...dia.com>
> ---
> include/linux/iommu.h | 15 +++++++++++++++
> include/linux/iommufd.h | 6 ++++++
> 2 files changed, 21 insertions(+)
Reviewed-by: Jason Gunthorpe <jgg@...dia.com>
Jason
Powered by blists - more mailing lists