[PATCH v1 00/12] iommufd: Repare for IOMMUFD_OBJ_HW_QUEUE

Nicolin Chen posted 12 patches 4 months ago
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h   | 11 ++--
drivers/iommu/iommufd/io_pagetable.h          |  2 +-
drivers/iommu/iommufd/iommufd_private.h       | 33 +++++++---
include/linux/iommu.h                         | 26 ++++----
include/linux/iommufd.h                       | 39 +++---------
.../arm/arm-smmu-v3/arm-smmu-v3-iommufd.c     | 47 +++++++-------
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c   |  3 +-
drivers/iommu/iommufd/device.c                |  3 +-
drivers/iommu/iommufd/driver.c                | 33 ----------
drivers/iommu/iommufd/eventq.c                | 14 ++---
drivers/iommu/iommufd/hw_pagetable.c          |  6 +-
drivers/iommu/iommufd/io_pagetable.c          |  3 +-
drivers/iommu/iommufd/iova_bitmap.c           |  1 -
drivers/iommu/iommufd/main.c                  | 62 +++++++++++++++++--
drivers/iommu/iommufd/pages.c                 |  9 ++-
drivers/iommu/iommufd/selftest.c              | 57 ++++++++---------
drivers/iommu/iommufd/viommu.c                | 46 +++++++++-----
17 files changed, 212 insertions(+), 183 deletions(-)
[PATCH v1 00/12] iommufd: Repare for IOMMUFD_OBJ_HW_QUEUE
Posted by Nicolin Chen 4 months ago
The new HW Queue object will require more interactions with IOMMU drivers,
with a few more for-driver APIs. This will complicate the driver-allocated
structure design like the viommu_alloc op: since the core structure is not
initialized during the driver allocation stage, a new for-driver API can't
reference any member in the core vIOMMU structure.

Make a preparatory series doing:
 - Cosmetic fixes and clean ups
 - Replace viommu_alloc design with get_viommu_size + viommu_init
 - Add a new iommufd_object_alloc_ucmd

Some of the patches are included from:
[PATCH v5 00/29] iommufd: Add vIOMMU infrastructure (Part-4 HW QUEUE)
https://lore.kernel.org/all/cover.1747537752.git.nicolinc@nvidia.com/

This is on Github:
https://github.com/nicolinc/iommufd/commits/iommufd_hw_queue-prep-v1

Thanks
Nicolin

Nicolin Chen (12):
  iommufd: Apply obvious cosmetic fixes
  iommufd: Drop unused ictx in struct iommufd_vdevice
  iommufd: Use enum iommu_viommu_type for type in struct iommufd_viommu
  iommufd: Use enum iommu_veventq_type for type in struct
    iommufd_veventq
  iommu: Introduce get_viommu_size and viommu_init ops
  iommufd/selftest: Implement mock_get_viommu_size and mock_viommu_init
  iommu/arm-smmu-v3: Implement arm_smmu_get_viommu_size and
    arm_vsmmu_init
  iommufd/viommu: Replace ops->viommu_alloc with ops->viommu_init
  iommu: Deprecate viommu_alloc op
  iommufd: Move _iommufd_object_alloc out of driver.c
  iommufd: Introduce iommufd_object_alloc_ucmd helper
  iommufd: Apply the new iommufd_object_alloc_ucmd helper

 drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h   | 11 ++--
 drivers/iommu/iommufd/io_pagetable.h          |  2 +-
 drivers/iommu/iommufd/iommufd_private.h       | 33 +++++++---
 include/linux/iommu.h                         | 26 ++++----
 include/linux/iommufd.h                       | 39 +++---------
 .../arm/arm-smmu-v3/arm-smmu-v3-iommufd.c     | 47 +++++++-------
 drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c   |  3 +-
 drivers/iommu/iommufd/device.c                |  3 +-
 drivers/iommu/iommufd/driver.c                | 33 ----------
 drivers/iommu/iommufd/eventq.c                | 14 ++---
 drivers/iommu/iommufd/hw_pagetable.c          |  6 +-
 drivers/iommu/iommufd/io_pagetable.c          |  3 +-
 drivers/iommu/iommufd/iova_bitmap.c           |  1 -
 drivers/iommu/iommufd/main.c                  | 62 +++++++++++++++++--
 drivers/iommu/iommufd/pages.c                 |  9 ++-
 drivers/iommu/iommufd/selftest.c              | 57 ++++++++---------
 drivers/iommu/iommufd/viommu.c                | 46 +++++++++-----
 17 files changed, 212 insertions(+), 183 deletions(-)

-- 
2.43.0
Re: [PATCH v1 00/12] iommufd: Repare for IOMMUFD_OBJ_HW_QUEUE
Posted by Nicolin Chen 4 months ago
On Mon, Jun 09, 2025 at 10:13:23AM -0700, Nicolin Chen wrote:
> The new HW Queue object will require more interactions with IOMMU drivers,
> with a few more for-driver APIs. This will complicate the driver-allocated
> structure design like the viommu_alloc op: since the core structure is not
> initialized during the driver allocation stage, a new for-driver API can't
> reference any member in the core vIOMMU structure.
> 
> Make a preparatory series doing:

So, Don pointed out that "Repare" is a typo here. All this series
doing is to "Prepare", as IOMMUFD_OBJ_HW_QUEUE hasn't been merged
yet.

Also the main goal of this series is to replace viommu_alloc with
get_viommu_size + viommu_init. The patch that introduces the two
new ops has the full details (though I should have some narrative
clearly show the idea in the cover letter too):

--------------------------------------------------------------------------
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:
    // my_viommu is successfully allocated
    my_viommu = iommufd_viommu_alloc(...);
    // This may crash if it reads viommu->ictx
    new = iommufd_new_viommu_helper(my_viommu->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.

This also adds a VIOMMU_STRUCT_SIZE macro, for drivers to use, which would
statically sanitize the driver structure.
--------------------------------------------------------------------------

Thanks.