Skip to content

Commit 64e6fc2

Browse files
committed
Merge tag 'for-linus-iommufd' of git://git.kernel.org/pub/scm/linux/kernel/git/jgg/iommufd
Pull more iommufd updates from Jason Gunthorpe: "Change the driver callback op domain_alloc_user() into two ops: domain_alloc_paging_flags() and domain_alloc_nesting() that better describe what the ops are expected to do. There will be per-driver cleanup based on this going into the next cycle via the driver trees" * tag 'for-linus-iommufd' of git://git.kernel.org/pub/scm/linux/kernel/git/jgg/iommufd: iommu: Rename ops->domain_alloc_user() to domain_alloc_paging_flags() iommu: Add ops->domain_alloc_nested()
2 parents 9ad55a6 + d537647 commit 64e6fc2

File tree

9 files changed

+57
-55
lines changed

9 files changed

+57
-55
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: 4 additions & 11 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,13 +3339,6 @@ intel_iommu_domain_alloc_user(struct device *dev, u32 flags,
33403339
struct iommu_domain *domain;
33413340
bool first_stage;
33423341

3343-
/* Must be NESTING domain */
3344-
if (parent) {
3345-
if (!nested_supported(iommu) || flags)
3346-
return ERR_PTR(-EOPNOTSUPP);
3347-
return intel_nested_domain_alloc(parent, user_data);
3348-
}
3349-
33503342
if (flags &
33513343
(~(IOMMU_HWPT_ALLOC_NEST_PARENT | IOMMU_HWPT_ALLOC_DIRTY_TRACKING
33523344
| IOMMU_HWPT_FAULT_ID_VALID)))
@@ -4472,9 +4464,10 @@ const struct iommu_ops intel_iommu_ops = {
44724464
.identity_domain = &identity_domain,
44734465
.capable = intel_iommu_capable,
44744466
.hw_info = intel_iommu_hw_info,
4475-
.domain_alloc_user = intel_iommu_domain_alloc_user,
4467+
.domain_alloc_paging_flags = intel_iommu_domain_alloc_paging_flags,
44764468
.domain_alloc_sva = intel_svm_domain_alloc,
44774469
.domain_alloc_paging = intel_iommu_domain_alloc_paging,
4470+
.domain_alloc_nested = intel_iommu_domain_alloc_nested,
44784471
.probe_device = intel_iommu_probe_device,
44794472
.release_device = intel_iommu_release_device,
44804473
.get_resv_regions = intel_iommu_get_resv_regions,

drivers/iommu/intel/iommu.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,8 +1265,10 @@ int __domain_setup_first_level(struct intel_iommu *iommu,
12651265
int dmar_ir_support(void);
12661266

12671267
void iommu_flush_write_buffer(struct intel_iommu *iommu);
1268-
struct iommu_domain *intel_nested_domain_alloc(struct iommu_domain *parent,
1269-
const struct iommu_user_data *user_data);
1268+
struct iommu_domain *
1269+
intel_iommu_domain_alloc_nested(struct device *dev, struct iommu_domain *parent,
1270+
u32 flags,
1271+
const struct iommu_user_data *user_data);
12701272
struct device *device_rbtree_find(struct intel_iommu *iommu, u16 rid);
12711273

12721274
enum cache_tag_type {

drivers/iommu/intel/nested.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,21 @@ static const struct iommu_domain_ops intel_nested_domain_ops = {
186186
.cache_invalidate_user = intel_nested_cache_invalidate_user,
187187
};
188188

189-
struct iommu_domain *intel_nested_domain_alloc(struct iommu_domain *parent,
190-
const struct iommu_user_data *user_data)
189+
struct iommu_domain *
190+
intel_iommu_domain_alloc_nested(struct device *dev, struct iommu_domain *parent,
191+
u32 flags,
192+
const struct iommu_user_data *user_data)
191193
{
194+
struct device_domain_info *info = dev_iommu_priv_get(dev);
192195
struct dmar_domain *s2_domain = to_dmar_domain(parent);
196+
struct intel_iommu *iommu = info->iommu;
193197
struct iommu_hwpt_vtd_s1 vtd;
194198
struct dmar_domain *domain;
195199
int ret;
196200

201+
if (!nested_supported(iommu) || flags)
202+
return ERR_PTR(-EOPNOTSUPP);
203+
197204
/* Must be nested domain */
198205
if (user_data->type != IOMMU_HWPT_DATA_VTD_S1)
199206
return ERR_PTR(-EOPNOTSUPP);

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: 8 additions & 8 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;
@@ -227,7 +227,7 @@ iommufd_hwpt_nested_alloc(struct iommufd_ctx *ictx,
227227
int rc;
228228

229229
if ((flags & ~IOMMU_HWPT_FAULT_ID_VALID) ||
230-
!user_data->len || !ops->domain_alloc_user)
230+
!user_data->len || !ops->domain_alloc_nested)
231231
return ERR_PTR(-EOPNOTSUPP);
232232
if (parent->auto_domain || !parent->nest_parent ||
233233
parent->common.domain->owner != ops)
@@ -242,9 +242,9 @@ iommufd_hwpt_nested_alloc(struct iommufd_ctx *ictx,
242242
refcount_inc(&parent->common.obj.users);
243243
hwpt_nested->parent = parent;
244244

245-
hwpt->domain = ops->domain_alloc_user(idev->dev,
246-
flags & ~IOMMU_HWPT_FAULT_ID_VALID,
247-
parent->common.domain, user_data);
245+
hwpt->domain = ops->domain_alloc_nested(
246+
idev->dev, parent->common.domain,
247+
flags & ~IOMMU_HWPT_FAULT_ID_VALID, user_data);
248248
if (IS_ERR(hwpt->domain)) {
249249
rc = PTR_ERR(hwpt->domain);
250250
hwpt->domain = NULL;

drivers/iommu/iommufd/selftest.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,8 @@ __mock_domain_alloc_nested(const struct iommu_user_data *user_data)
356356
}
357357

358358
static struct iommu_domain *
359-
mock_domain_alloc_nested(struct iommu_domain *parent, u32 flags,
360-
const struct iommu_user_data *user_data)
359+
mock_domain_alloc_nested(struct device *dev, struct iommu_domain *parent,
360+
u32 flags, const struct iommu_user_data *user_data)
361361
{
362362
struct mock_iommu_domain_nested *mock_nested;
363363
struct mock_iommu_domain *mock_parent;
@@ -379,9 +379,8 @@ mock_domain_alloc_nested(struct iommu_domain *parent, u32 flags,
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 mock_domain_alloc_nested(parent, flags, user_data);
395-
396392
if (user_data)
397393
return ERR_PTR(-EOPNOTSUPP);
398394
if ((flags & ~PAGING_FLAGS) || (has_dirty_flag && no_dirty_ops))
@@ -718,7 +714,8 @@ 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,
718+
.domain_alloc_nested = mock_domain_alloc_nested,
722719
.capable = mock_domain_capable,
723720
.device_group = generic_device_group,
724721
.probe_device = mock_probe_device,

include/linux/iommu.h

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -557,17 +557,19 @@ 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-
* Upon success, if the @user_data is valid and the @parent
563-
* points to a kernel-managed domain, the new domain must be
564-
* IOMMU_DOMAIN_NESTED type; otherwise, the @parent must be
565-
* NULL while the @user_data can be optionally provided, the
566-
* new domain must support __IOMMU_DOMAIN_PAGING.
567-
* 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.
568566
* @domain_alloc_paging: Allocate an iommu_domain that can be used for
569-
* 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.
570571
* @domain_alloc_sva: Allocate an iommu_domain for Shared Virtual Addressing.
572+
* @domain_alloc_nested: Allocate an iommu_domain for nested translation.
571573
* @probe_device: Add device to iommu driver handling
572574
* @release_device: Remove device from iommu driver handling
573575
* @probe_finalize: Do final setup work after the device is added to an IOMMU
@@ -616,12 +618,15 @@ struct iommu_ops {
616618

617619
/* Domain allocation and freeing by the iommu driver */
618620
struct iommu_domain *(*domain_alloc)(unsigned iommu_domain_type);
619-
struct iommu_domain *(*domain_alloc_user)(
620-
struct device *dev, u32 flags, struct iommu_domain *parent,
621+
struct iommu_domain *(*domain_alloc_paging_flags)(
622+
struct device *dev, u32 flags,
621623
const struct iommu_user_data *user_data);
622624
struct iommu_domain *(*domain_alloc_paging)(struct device *dev);
623625
struct iommu_domain *(*domain_alloc_sva)(struct device *dev,
624626
struct mm_struct *mm);
627+
struct iommu_domain *(*domain_alloc_nested)(
628+
struct device *dev, struct iommu_domain *parent, u32 flags,
629+
const struct iommu_user_data *user_data);
625630

626631
struct iommu_device *(*probe_device)(struct device *dev);
627632
void (*release_device)(struct device *dev);

0 commit comments

Comments
 (0)