Commit 7975b722 authored by Yi Liu's avatar Yi Liu Committed by Jason Gunthorpe

iommufd: Use the domain_alloc_user() op for domain allocation

Make IOMMUFD use iommu_domain_alloc_user() by default for iommu_domain
creation. IOMMUFD needs to support iommu_domain allocation with parameters
from userspace in nested support, and a driver is expected to implement
everything under this op.

If the iommu driver doesn't provide domain_alloc_user callback then
IOMMUFD falls back to use iommu_domain_alloc() with an UNMANAGED type if
possible.

Link: https://lore.kernel.org/r/20230928071528.26258-3-yi.l.liu@intel.comSuggested-by: default avatarJason Gunthorpe <jgg@nvidia.com>
Reviewed-by: default avatarLu Baolu <baolu.lu@linux.intel.com>
Reviewed-by: default avatarKevin Tian <kevin.tian@intel.com>
Co-developed-by: default avatarNicolin Chen <nicolinc@nvidia.com>
Signed-off-by: default avatarNicolin Chen <nicolinc@nvidia.com>
Signed-off-by: default avatarYi Liu <yi.l.liu@intel.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@nvidia.com>
parent 909f4abd
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include <linux/iommu.h> #include <linux/iommu.h>
#include <uapi/linux/iommufd.h> #include <uapi/linux/iommufd.h>
#include "../iommu-priv.h"
#include "iommufd_private.h" #include "iommufd_private.h"
void iommufd_hw_pagetable_destroy(struct iommufd_object *obj) void iommufd_hw_pagetable_destroy(struct iommufd_object *obj)
...@@ -74,6 +75,7 @@ struct iommufd_hw_pagetable * ...@@ -74,6 +75,7 @@ struct iommufd_hw_pagetable *
iommufd_hw_pagetable_alloc(struct iommufd_ctx *ictx, struct iommufd_ioas *ioas, iommufd_hw_pagetable_alloc(struct iommufd_ctx *ictx, struct iommufd_ioas *ioas,
struct iommufd_device *idev, bool immediate_attach) struct iommufd_device *idev, bool immediate_attach)
{ {
const struct iommu_ops *ops = dev_iommu_ops(idev->dev);
struct iommufd_hw_pagetable *hwpt; struct iommufd_hw_pagetable *hwpt;
int rc; int rc;
...@@ -88,10 +90,19 @@ iommufd_hw_pagetable_alloc(struct iommufd_ctx *ictx, struct iommufd_ioas *ioas, ...@@ -88,10 +90,19 @@ iommufd_hw_pagetable_alloc(struct iommufd_ctx *ictx, struct iommufd_ioas *ioas,
refcount_inc(&ioas->obj.users); refcount_inc(&ioas->obj.users);
hwpt->ioas = ioas; hwpt->ioas = ioas;
hwpt->domain = iommu_domain_alloc(idev->dev->bus); if (ops->domain_alloc_user) {
if (!hwpt->domain) { hwpt->domain = ops->domain_alloc_user(idev->dev, 0);
rc = -ENOMEM; if (IS_ERR(hwpt->domain)) {
goto out_abort; rc = PTR_ERR(hwpt->domain);
hwpt->domain = NULL;
goto out_abort;
}
} else {
hwpt->domain = iommu_domain_alloc(idev->dev->bus);
if (!hwpt->domain) {
rc = -ENOMEM;
goto out_abort;
}
} }
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment