Skip to content

Commit d537647

Browse files
committed
iommu: Rename ops->domain_alloc_user() to domain_alloc_paging_flags()
Now that the main domain allocating path is calling this function it doesn't make sense to leave it named _user. Change the name to alloc_paging_flags() to mirror the new iommu_paging_domain_alloc_flags() function. A driver should implement only one of ops->domain_alloc_paging() or ops->domain_alloc_paging_flags(). The former is a simpler interface with less boiler plate that the majority of drivers use. The latter is for drivers with a greater feature set (PASID, multiple page table support, advanced iommufd support, nesting, etc). Additional patches will be needed to achieve this. Link: https://patch.msgid.link/r/2-v1-c252ebdeb57b+329-iommu_paging_flags_jgg@nvidia.com Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
1 parent 64214c2 commit d537647

File tree

7 files changed

+32
-38
lines changed

7 files changed

+32
-38
lines changed

drivers/iommu/amd/iommu.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2407,9 +2407,8 @@ static struct iommu_domain *amd_iommu_domain_alloc(unsigned int type)
24072407
}
24082408

24092409
static struct iommu_domain *
2410-
amd_iommu_domain_alloc_user(struct device *dev, u32 flags,
2411-
struct iommu_domain *parent,
2412-
const struct iommu_user_data *user_data)
2410+
amd_iommu_domain_alloc_paging_flags(struct device *dev, u32 flags,
2411+
const struct iommu_user_data *user_data)
24132412

24142413
{
24152414
unsigned int type = IOMMU_DOMAIN_UNMANAGED;
@@ -2420,7 +2419,7 @@ amd_iommu_domain_alloc_user(struct device *dev, u32 flags,
24202419
if (dev)
24212420
iommu = get_amd_iommu_from_dev(dev);
24222421

2423-
if ((flags & ~supported_flags) || parent || user_data)
2422+
if ((flags & ~supported_flags) || user_data)
24242423
return ERR_PTR(-EOPNOTSUPP);
24252424

24262425
/* Allocate domain with v2 page table if IOMMU supports PASID. */
@@ -2884,7 +2883,7 @@ const struct iommu_ops amd_iommu_ops = {
28842883
.release_domain = &release_domain,
28852884
.identity_domain = &identity_domain.domain,
28862885
.domain_alloc = amd_iommu_domain_alloc,
2887-
.domain_alloc_user = amd_iommu_domain_alloc_user,
2886+
.domain_alloc_paging_flags = amd_iommu_domain_alloc_paging_flags,
28882887
.domain_alloc_sva = amd_iommu_domain_alloc_sva,
28892888
.probe_device = amd_iommu_probe_device,
28902889
.release_device = amd_iommu_release_device,

drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3132,9 +3132,8 @@ static struct iommu_domain arm_smmu_blocked_domain = {
31323132
};
31333133

31343134
static struct iommu_domain *
3135-
arm_smmu_domain_alloc_user(struct device *dev, u32 flags,
3136-
struct iommu_domain *parent,
3137-
const struct iommu_user_data *user_data)
3135+
arm_smmu_domain_alloc_paging_flags(struct device *dev, u32 flags,
3136+
const struct iommu_user_data *user_data)
31383137
{
31393138
struct arm_smmu_master *master = dev_iommu_priv_get(dev);
31403139
const u32 PAGING_FLAGS = IOMMU_HWPT_ALLOC_DIRTY_TRACKING |
@@ -3145,7 +3144,7 @@ arm_smmu_domain_alloc_user(struct device *dev, u32 flags,
31453144

31463145
if (flags & ~PAGING_FLAGS)
31473146
return ERR_PTR(-EOPNOTSUPP);
3148-
if (parent || user_data)
3147+
if (user_data)
31493148
return ERR_PTR(-EOPNOTSUPP);
31503149

31513150
if (flags & IOMMU_HWPT_ALLOC_PASID)
@@ -3546,7 +3545,7 @@ static struct iommu_ops arm_smmu_ops = {
35463545
.hw_info = arm_smmu_hw_info,
35473546
.domain_alloc_paging = arm_smmu_domain_alloc_paging,
35483547
.domain_alloc_sva = arm_smmu_sva_domain_alloc,
3549-
.domain_alloc_user = arm_smmu_domain_alloc_user,
3548+
.domain_alloc_paging_flags = arm_smmu_domain_alloc_paging_flags,
35503549
.probe_device = arm_smmu_probe_device,
35513550
.release_device = arm_smmu_release_device,
35523551
.device_group = arm_smmu_device_group,

drivers/iommu/intel/iommu.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3328,9 +3328,8 @@ static struct dmar_domain *paging_domain_alloc(struct device *dev, bool first_st
33283328
}
33293329

33303330
static struct iommu_domain *
3331-
intel_iommu_domain_alloc_user(struct device *dev, u32 flags,
3332-
struct iommu_domain *parent,
3333-
const struct iommu_user_data *user_data)
3331+
intel_iommu_domain_alloc_paging_flags(struct device *dev, u32 flags,
3332+
const struct iommu_user_data *user_data)
33343333
{
33353334
struct device_domain_info *info = dev_iommu_priv_get(dev);
33363335
bool dirty_tracking = flags & IOMMU_HWPT_ALLOC_DIRTY_TRACKING;
@@ -3340,9 +3339,6 @@ intel_iommu_domain_alloc_user(struct device *dev, u32 flags,
33403339
struct iommu_domain *domain;
33413340
bool first_stage;
33423341

3343-
if (parent)
3344-
return ERR_PTR(-EOPNOTSUPP);
3345-
33463342
if (flags &
33473343
(~(IOMMU_HWPT_ALLOC_NEST_PARENT | IOMMU_HWPT_ALLOC_DIRTY_TRACKING
33483344
| IOMMU_HWPT_FAULT_ID_VALID)))
@@ -4468,7 +4464,7 @@ const struct iommu_ops intel_iommu_ops = {
44684464
.identity_domain = &identity_domain,
44694465
.capable = intel_iommu_capable,
44704466
.hw_info = intel_iommu_hw_info,
4471-
.domain_alloc_user = intel_iommu_domain_alloc_user,
4467+
.domain_alloc_paging_flags = intel_iommu_domain_alloc_paging_flags,
44724468
.domain_alloc_sva = intel_svm_domain_alloc,
44734469
.domain_alloc_paging = intel_iommu_domain_alloc_paging,
44744470
.domain_alloc_nested = intel_iommu_domain_alloc_nested,

drivers/iommu/iommu.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1987,8 +1987,8 @@ __iommu_paging_domain_alloc_flags(struct device *dev, unsigned int type,
19871987

19881988
if (ops->domain_alloc_paging && !flags)
19891989
domain = ops->domain_alloc_paging(dev);
1990-
else if (ops->domain_alloc_user)
1991-
domain = ops->domain_alloc_user(dev, flags, NULL, NULL);
1990+
else if (ops->domain_alloc_paging_flags)
1991+
domain = ops->domain_alloc_paging_flags(dev, flags, NULL);
19921992
else if (ops->domain_alloc && !flags)
19931993
domain = ops->domain_alloc(IOMMU_DOMAIN_UNMANAGED);
19941994
else

drivers/iommu/iommufd/hw_pagetable.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ iommufd_hwpt_paging_alloc(struct iommufd_ctx *ictx, struct iommufd_ioas *ioas,
119119

120120
lockdep_assert_held(&ioas->mutex);
121121

122-
if ((flags || user_data) && !ops->domain_alloc_user)
122+
if ((flags || user_data) && !ops->domain_alloc_paging_flags)
123123
return ERR_PTR(-EOPNOTSUPP);
124124
if (flags & ~valid_flags)
125125
return ERR_PTR(-EOPNOTSUPP);
@@ -139,9 +139,9 @@ iommufd_hwpt_paging_alloc(struct iommufd_ctx *ictx, struct iommufd_ioas *ioas,
139139
hwpt_paging->ioas = ioas;
140140
hwpt_paging->nest_parent = flags & IOMMU_HWPT_ALLOC_NEST_PARENT;
141141

142-
if (ops->domain_alloc_user) {
143-
hwpt->domain = ops->domain_alloc_user(idev->dev, flags, NULL,
144-
user_data);
142+
if (ops->domain_alloc_paging_flags) {
143+
hwpt->domain = ops->domain_alloc_paging_flags(idev->dev, flags,
144+
user_data);
145145
if (IS_ERR(hwpt->domain)) {
146146
rc = PTR_ERR(hwpt->domain);
147147
hwpt->domain = NULL;

drivers/iommu/iommufd/selftest.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -379,9 +379,8 @@ mock_domain_alloc_nested(struct device *dev, struct iommu_domain *parent,
379379
}
380380

381381
static struct iommu_domain *
382-
mock_domain_alloc_user(struct device *dev, u32 flags,
383-
struct iommu_domain *parent,
384-
const struct iommu_user_data *user_data)
382+
mock_domain_alloc_paging_flags(struct device *dev, u32 flags,
383+
const struct iommu_user_data *user_data)
385384
{
386385
bool has_dirty_flag = flags & IOMMU_HWPT_ALLOC_DIRTY_TRACKING;
387386
const u32 PAGING_FLAGS = IOMMU_HWPT_ALLOC_DIRTY_TRACKING |
@@ -390,9 +389,6 @@ mock_domain_alloc_user(struct device *dev, u32 flags,
390389
MOCK_FLAGS_DEVICE_NO_DIRTY;
391390
struct iommu_domain *domain;
392391

393-
if (parent)
394-
return ERR_PTR(-EOPNOTSUPP);
395-
396392
if (user_data)
397393
return ERR_PTR(-EOPNOTSUPP);
398394
if ((flags & ~PAGING_FLAGS) || (has_dirty_flag && no_dirty_ops))
@@ -718,7 +714,7 @@ static const struct iommu_ops mock_ops = {
718714
.pgsize_bitmap = MOCK_IO_PAGE_SIZE,
719715
.hw_info = mock_domain_hw_info,
720716
.domain_alloc_paging = mock_domain_alloc_paging,
721-
.domain_alloc_user = mock_domain_alloc_user,
717+
.domain_alloc_paging_flags = mock_domain_alloc_paging_flags,
722718
.domain_alloc_nested = mock_domain_alloc_nested,
723719
.capable = mock_domain_capable,
724720
.device_group = generic_device_group,

include/linux/iommu.h

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -557,13 +557,17 @@ iommu_copy_struct_from_full_user_array(void *kdst, size_t kdst_entry_size,
557557
* @domain_alloc: allocate and return an iommu domain if success. Otherwise
558558
* NULL is returned. The domain is not fully initialized until
559559
* the caller iommu_domain_alloc() returns.
560-
* @domain_alloc_user: Allocate an iommu domain corresponding to the input
561-
* parameters as defined in include/uapi/linux/iommufd.h.
562-
* The @user_data can be optionally provided, the
563-
* new domain must support __IOMMU_DOMAIN_PAGING.
564-
* Upon failure, ERR_PTR must be returned.
560+
* @domain_alloc_paging_flags: Allocate an iommu domain corresponding to the
561+
* input parameters as defined in
562+
* include/uapi/linux/iommufd.h. The @user_data can be
563+
* optionally provided, the new domain must support
564+
* __IOMMU_DOMAIN_PAGING. Upon failure, ERR_PTR must be
565+
* returned.
565566
* @domain_alloc_paging: Allocate an iommu_domain that can be used for
566-
* UNMANAGED, DMA, and DMA_FQ domain types.
567+
* UNMANAGED, DMA, and DMA_FQ domain types. This is the
568+
* same as invoking domain_alloc_paging_flags() with
569+
* @flags=0, @user_data=NULL. A driver should implement
570+
* only one of the two ops.
567571
* @domain_alloc_sva: Allocate an iommu_domain for Shared Virtual Addressing.
568572
* @domain_alloc_nested: Allocate an iommu_domain for nested translation.
569573
* @probe_device: Add device to iommu driver handling
@@ -614,8 +618,8 @@ struct iommu_ops {
614618

615619
/* Domain allocation and freeing by the iommu driver */
616620
struct iommu_domain *(*domain_alloc)(unsigned iommu_domain_type);
617-
struct iommu_domain *(*domain_alloc_user)(
618-
struct device *dev, u32 flags, struct iommu_domain *parent,
621+
struct iommu_domain *(*domain_alloc_paging_flags)(
622+
struct device *dev, u32 flags,
619623
const struct iommu_user_data *user_data);
620624
struct iommu_domain *(*domain_alloc_paging)(struct device *dev);
621625
struct iommu_domain *(*domain_alloc_sva)(struct device *dev,

0 commit comments

Comments
 (0)