Skip to content

Commit 7975b72

Browse files
yiliu1765jgunthorpe
authored andcommitted
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.com Suggested-by: Jason Gunthorpe <jgg@nvidia.com> Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com> Reviewed-by: Kevin Tian <kevin.tian@intel.com> Co-developed-by: Nicolin Chen <nicolinc@nvidia.com> Signed-off-by: Nicolin Chen <nicolinc@nvidia.com> Signed-off-by: Yi Liu <yi.l.liu@intel.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
1 parent 909f4ab commit 7975b72

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

drivers/iommu/iommufd/hw_pagetable.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <linux/iommu.h>
66
#include <uapi/linux/iommufd.h>
77

8+
#include "../iommu-priv.h"
89
#include "iommufd_private.h"
910

1011
void iommufd_hw_pagetable_destroy(struct iommufd_object *obj)
@@ -74,6 +75,7 @@ struct iommufd_hw_pagetable *
7475
iommufd_hw_pagetable_alloc(struct iommufd_ctx *ictx, struct iommufd_ioas *ioas,
7576
struct iommufd_device *idev, bool immediate_attach)
7677
{
78+
const struct iommu_ops *ops = dev_iommu_ops(idev->dev);
7779
struct iommufd_hw_pagetable *hwpt;
7880
int rc;
7981

@@ -88,10 +90,19 @@ iommufd_hw_pagetable_alloc(struct iommufd_ctx *ictx, struct iommufd_ioas *ioas,
8890
refcount_inc(&ioas->obj.users);
8991
hwpt->ioas = ioas;
9092

91-
hwpt->domain = iommu_domain_alloc(idev->dev->bus);
92-
if (!hwpt->domain) {
93-
rc = -ENOMEM;
94-
goto out_abort;
93+
if (ops->domain_alloc_user) {
94+
hwpt->domain = ops->domain_alloc_user(idev->dev, 0);
95+
if (IS_ERR(hwpt->domain)) {
96+
rc = PTR_ERR(hwpt->domain);
97+
hwpt->domain = NULL;
98+
goto out_abort;
99+
}
100+
} else {
101+
hwpt->domain = iommu_domain_alloc(idev->dev->bus);
102+
if (!hwpt->domain) {
103+
rc = -ENOMEM;
104+
goto out_abort;
105+
}
95106
}
96107

97108
/*

0 commit comments

Comments
 (0)