[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <BN9PR11MB52769429DBEC752093C89E678C7DA@BN9PR11MB5276.namprd11.prod.outlook.com>
Date: Thu, 19 Jun 2025 05:42:21 +0000
From: "Tian, Kevin" <kevin.tian@...el.com>
To: Nicolin Chen <nicolinc@...dia.com>, "jgg@...dia.com" <jgg@...dia.com>
CC: "will@...nel.org" <will@...nel.org>, "robin.murphy@....com"
<robin.murphy@....com>, "joro@...tes.org" <joro@...tes.org>,
"praan@...gle.com" <praan@...gle.com>, "Liu, Yi L" <yi.l.liu@...el.com>,
"peterz@...radead.org" <peterz@...radead.org>, "jsnitsel@...hat.com"
<jsnitsel@...hat.com>, "linux-arm-kernel@...ts.infradead.org"
<linux-arm-kernel@...ts.infradead.org>, "iommu@...ts.linux.dev"
<iommu@...ts.linux.dev>, "linux-kernel@...r.kernel.org"
<linux-kernel@...r.kernel.org>, "patches@...ts.linux.dev"
<patches@...ts.linux.dev>, "baolu.lu@...ux.intel.com"
<baolu.lu@...ux.intel.com>
Subject: RE: [PATCH v2 06/14] iommu: Introduce get_viommu_size and viommu_init
ops
> From: Nicolin Chen <nicolinc@...dia.com>
> Sent: Saturday, June 14, 2025 2:35 PM
>
> 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>
Reviewed-by: Kevin Tian <kevin.tian@...el.com>
Powered by blists - more mailing lists