Thread (149 messages) 149 messages, 7 authors, 2025-05-12

Re: [PATCH v2 10/19] iommufd/viommu: Add vdev_id helpers for IOMMU drivers

From: Nicolin Chen <hidden>
Date: 2024-10-05 05:19:56
Also in: linux-iommu, linux-kselftest, lkml

On Wed, Sep 11, 2024 at 08:17:22PM -0700, Nicolin Chen wrote:
On Wed, Sep 11, 2024 at 08:11:03PM -0300, Jason Gunthorpe wrote:
quoted
On Thu, Sep 05, 2024 at 10:53:31AM -0700, Nicolin Chen wrote:
quoted
On Thu, Sep 05, 2024 at 01:14:15PM -0300, Jason Gunthorpe wrote:
quoted
On Tue, Aug 27, 2024 at 09:59:47AM -0700, Nicolin Chen wrote:
quoted
Driver can call the iommufd_viommu_find_device() to find a device pointer
using its per-viommu virtual ID. The returned device must be protected by
the pair of iommufd_viommu_lock/unlock_vdev_id() function.

Put these three functions into a new viommu_api file, to build it with the
IOMMUFD_DRIVER config.

Signed-off-by: Nicolin Chen <redacted>
---
 drivers/iommu/iommufd/Makefile     |  2 +-
 drivers/iommu/iommufd/viommu_api.c | 39 ++++++++++++++++++++++++++++++
 include/linux/iommufd.h            | 16 ++++++++++++
 3 files changed, 56 insertions(+), 1 deletion(-)
 create mode 100644 drivers/iommu/iommufd/viommu_api.c
I still think this is better to just share the struct content with the
driver, eventually we want to do this anyhow as the driver will
want to use container_of() techniques to reach its private data.
In my mind, exposing everything to the driver is something that
we have to (for driver-managed structures) v.s. we want to...
Even in that case, a driver actually only need to know the size
of the core structure, without touching what's inside(?).

I am a bit worried that drivers would abuse the content in the
core-level structure.. Providing a set of API would encourage
them to keep the core structure intact, hopefully..
This is always a tension in the kernel. If the core apis can be nice
and tidy then it is a reasonable direction

But here I think we've cross some threshold where the APIs are
complex, want to be inlined and really we just want to expose data not
APIs to drivers.
OK. I'll think of a rework. And might need another justification
for a DEFAULT type of vIOMMU object to fit in.
I tried exposing the struct iommufd_viommu to drivers, and was
able to drop a couple of helpers, except these two:

struct device *vdev_to_dev(struct iommufd_vdevice *vdev)
{
	return vdev ? vdev->idev->dev : NULL;
} // Without it, we need to expose struct iommufd_device.

struct iommu_domain *
iommufd_viommu_to_parent_domain(struct iommufd_viommu *viommu)
{
	if (!viommu || !viommu->hwpt)
		return NULL;
	return viommu->hwpt->common.domain;
} // Without it, we need to expose struct iommufd_hwpt_page.

Thanks
Nicolin
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help