Skip to content

Commit bd7a282

Browse files
committed
iommufd: Add iommufd_ctx to iommufd_put_object()
Will be used in the next patch. Link: https://lore.kernel.org/r/1-v2-ca9e00171c5b+123-iommufd_syz4_jgg@nvidia.com/ Reviewed-by: Kevin Tian <kevin.tian@intel.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
1 parent 9859418 commit bd7a282

File tree

6 files changed

+36
-35
lines changed

6 files changed

+36
-35
lines changed

drivers/iommu/iommufd/device.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ iommufd_device_auto_get_domain(struct iommufd_device *idev,
571571
continue;
572572
destroy_hwpt = (*do_attach)(idev, hwpt);
573573
if (IS_ERR(destroy_hwpt)) {
574-
iommufd_put_object(&hwpt->obj);
574+
iommufd_put_object(idev->ictx, &hwpt->obj);
575575
/*
576576
* -EINVAL means the domain is incompatible with the
577577
* device. Other error codes should propagate to
@@ -583,7 +583,7 @@ iommufd_device_auto_get_domain(struct iommufd_device *idev,
583583
goto out_unlock;
584584
}
585585
*pt_id = hwpt->obj.id;
586-
iommufd_put_object(&hwpt->obj);
586+
iommufd_put_object(idev->ictx, &hwpt->obj);
587587
goto out_unlock;
588588
}
589589

@@ -652,15 +652,15 @@ static int iommufd_device_change_pt(struct iommufd_device *idev, u32 *pt_id,
652652
destroy_hwpt = ERR_PTR(-EINVAL);
653653
goto out_put_pt_obj;
654654
}
655-
iommufd_put_object(pt_obj);
655+
iommufd_put_object(idev->ictx, pt_obj);
656656

657657
/* This destruction has to be after we unlock everything */
658658
if (destroy_hwpt)
659659
iommufd_hw_pagetable_put(idev->ictx, destroy_hwpt);
660660
return 0;
661661

662662
out_put_pt_obj:
663-
iommufd_put_object(pt_obj);
663+
iommufd_put_object(idev->ictx, pt_obj);
664664
return PTR_ERR(destroy_hwpt);
665665
}
666666

@@ -792,7 +792,7 @@ static int iommufd_access_change_ioas_id(struct iommufd_access *access, u32 id)
792792
if (IS_ERR(ioas))
793793
return PTR_ERR(ioas);
794794
rc = iommufd_access_change_ioas(access, ioas);
795-
iommufd_put_object(&ioas->obj);
795+
iommufd_put_object(access->ictx, &ioas->obj);
796796
return rc;
797797
}
798798

@@ -941,7 +941,7 @@ void iommufd_access_notify_unmap(struct io_pagetable *iopt, unsigned long iova,
941941

942942
access->ops->unmap(access->data, iova, length);
943943

944-
iommufd_put_object(&access->obj);
944+
iommufd_put_object(access->ictx, &access->obj);
945945
xa_lock(&ioas->iopt.access_list);
946946
}
947947
xa_unlock(&ioas->iopt.access_list);
@@ -1243,6 +1243,6 @@ int iommufd_get_hw_info(struct iommufd_ucmd *ucmd)
12431243
out_free:
12441244
kfree(data);
12451245
out_put:
1246-
iommufd_put_object(&idev->obj);
1246+
iommufd_put_object(ucmd->ictx, &idev->obj);
12471247
return rc;
12481248
}

drivers/iommu/iommufd/hw_pagetable.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,9 @@ int iommufd_hwpt_alloc(struct iommufd_ucmd *ucmd)
318318
if (ioas)
319319
mutex_unlock(&ioas->mutex);
320320
out_put_pt:
321-
iommufd_put_object(pt_obj);
321+
iommufd_put_object(ucmd->ictx, pt_obj);
322322
out_put_idev:
323-
iommufd_put_object(&idev->obj);
323+
iommufd_put_object(ucmd->ictx, &idev->obj);
324324
return rc;
325325
}
326326

@@ -345,7 +345,7 @@ int iommufd_hwpt_set_dirty_tracking(struct iommufd_ucmd *ucmd)
345345
rc = iopt_set_dirty_tracking(&ioas->iopt, hwpt_paging->common.domain,
346346
enable);
347347

348-
iommufd_put_object(&hwpt_paging->common.obj);
348+
iommufd_put_object(ucmd->ictx, &hwpt_paging->common.obj);
349349
return rc;
350350
}
351351

@@ -368,6 +368,6 @@ int iommufd_hwpt_get_dirty_bitmap(struct iommufd_ucmd *ucmd)
368368
rc = iopt_read_and_clear_dirty_data(
369369
&ioas->iopt, hwpt_paging->common.domain, cmd->flags, cmd);
370370

371-
iommufd_put_object(&hwpt_paging->common.obj);
371+
iommufd_put_object(ucmd->ictx, &hwpt_paging->common.obj);
372372
return rc;
373373
}

drivers/iommu/iommufd/ioas.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ int iommufd_ioas_iova_ranges(struct iommufd_ucmd *ucmd)
105105
rc = -EMSGSIZE;
106106
out_put:
107107
up_read(&ioas->iopt.iova_rwsem);
108-
iommufd_put_object(&ioas->obj);
108+
iommufd_put_object(ucmd->ictx, &ioas->obj);
109109
return rc;
110110
}
111111

@@ -175,7 +175,7 @@ int iommufd_ioas_allow_iovas(struct iommufd_ucmd *ucmd)
175175
interval_tree_remove(node, &allowed_iova);
176176
kfree(container_of(node, struct iopt_allowed, node));
177177
}
178-
iommufd_put_object(&ioas->obj);
178+
iommufd_put_object(ucmd->ictx, &ioas->obj);
179179
return rc;
180180
}
181181

@@ -228,7 +228,7 @@ int iommufd_ioas_map(struct iommufd_ucmd *ucmd)
228228
cmd->iova = iova;
229229
rc = iommufd_ucmd_respond(ucmd, sizeof(*cmd));
230230
out_put:
231-
iommufd_put_object(&ioas->obj);
231+
iommufd_put_object(ucmd->ictx, &ioas->obj);
232232
return rc;
233233
}
234234

@@ -258,7 +258,7 @@ int iommufd_ioas_copy(struct iommufd_ucmd *ucmd)
258258
return PTR_ERR(src_ioas);
259259
rc = iopt_get_pages(&src_ioas->iopt, cmd->src_iova, cmd->length,
260260
&pages_list);
261-
iommufd_put_object(&src_ioas->obj);
261+
iommufd_put_object(ucmd->ictx, &src_ioas->obj);
262262
if (rc)
263263
return rc;
264264

@@ -279,7 +279,7 @@ int iommufd_ioas_copy(struct iommufd_ucmd *ucmd)
279279
cmd->dst_iova = iova;
280280
rc = iommufd_ucmd_respond(ucmd, sizeof(*cmd));
281281
out_put_dst:
282-
iommufd_put_object(&dst_ioas->obj);
282+
iommufd_put_object(ucmd->ictx, &dst_ioas->obj);
283283
out_pages:
284284
iopt_free_pages_list(&pages_list);
285285
return rc;
@@ -315,7 +315,7 @@ int iommufd_ioas_unmap(struct iommufd_ucmd *ucmd)
315315
rc = iommufd_ucmd_respond(ucmd, sizeof(*cmd));
316316

317317
out_put:
318-
iommufd_put_object(&ioas->obj);
318+
iommufd_put_object(ucmd->ictx, &ioas->obj);
319319
return rc;
320320
}
321321

@@ -393,6 +393,6 @@ int iommufd_ioas_option(struct iommufd_ucmd *ucmd)
393393
rc = -EOPNOTSUPP;
394394
}
395395

396-
iommufd_put_object(&ioas->obj);
396+
iommufd_put_object(ucmd->ictx, &ioas->obj);
397397
return rc;
398398
}

drivers/iommu/iommufd/iommufd_private.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ static inline bool iommufd_lock_obj(struct iommufd_object *obj)
154154

155155
struct iommufd_object *iommufd_get_object(struct iommufd_ctx *ictx, u32 id,
156156
enum iommufd_object_type type);
157-
static inline void iommufd_put_object(struct iommufd_object *obj)
157+
static inline void iommufd_put_object(struct iommufd_ctx *ictx,
158+
struct iommufd_object *obj)
158159
{
159160
refcount_dec(&obj->users);
160161
up_read(&obj->destroy_rwsem);

drivers/iommu/iommufd/selftest.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ void iommufd_test_syz_conv_iova_id(struct iommufd_ucmd *ucmd,
8686
if (IS_ERR(ioas))
8787
return;
8888
*iova = iommufd_test_syz_conv_iova(&ioas->iopt, iova);
89-
iommufd_put_object(&ioas->obj);
89+
iommufd_put_object(ucmd->ictx, &ioas->obj);
9090
}
9191

9292
struct mock_iommu_domain {
@@ -500,7 +500,7 @@ get_md_pagetable(struct iommufd_ucmd *ucmd, u32 mockpt_id,
500500
return hwpt;
501501
if (hwpt->domain->type != IOMMU_DOMAIN_UNMANAGED ||
502502
hwpt->domain->ops != mock_ops.default_domain_ops) {
503-
iommufd_put_object(&hwpt->obj);
503+
iommufd_put_object(ucmd->ictx, &hwpt->obj);
504504
return ERR_PTR(-EINVAL);
505505
}
506506
*mock = container_of(hwpt->domain, struct mock_iommu_domain, domain);
@@ -518,7 +518,7 @@ get_md_pagetable_nested(struct iommufd_ucmd *ucmd, u32 mockpt_id,
518518
return hwpt;
519519
if (hwpt->domain->type != IOMMU_DOMAIN_NESTED ||
520520
hwpt->domain->ops != &domain_nested_ops) {
521-
iommufd_put_object(&hwpt->obj);
521+
iommufd_put_object(ucmd->ictx, &hwpt->obj);
522522
return ERR_PTR(-EINVAL);
523523
}
524524
*mock_nested = container_of(hwpt->domain,
@@ -681,7 +681,7 @@ static int iommufd_test_mock_domain_replace(struct iommufd_ucmd *ucmd,
681681
rc = iommufd_ucmd_respond(ucmd, sizeof(*cmd));
682682

683683
out_dev_obj:
684-
iommufd_put_object(dev_obj);
684+
iommufd_put_object(ucmd->ictx, dev_obj);
685685
return rc;
686686
}
687687

@@ -699,7 +699,7 @@ static int iommufd_test_add_reserved(struct iommufd_ucmd *ucmd,
699699
down_write(&ioas->iopt.iova_rwsem);
700700
rc = iopt_reserve_iova(&ioas->iopt, start, start + length - 1, NULL);
701701
up_write(&ioas->iopt.iova_rwsem);
702-
iommufd_put_object(&ioas->obj);
702+
iommufd_put_object(ucmd->ictx, &ioas->obj);
703703
return rc;
704704
}
705705

@@ -754,7 +754,7 @@ static int iommufd_test_md_check_pa(struct iommufd_ucmd *ucmd,
754754
rc = 0;
755755

756756
out_put:
757-
iommufd_put_object(&hwpt->obj);
757+
iommufd_put_object(ucmd->ictx, &hwpt->obj);
758758
return rc;
759759
}
760760

@@ -1233,7 +1233,7 @@ static int iommufd_test_dirty(struct iommufd_ucmd *ucmd, unsigned int mockpt_id,
12331233
out_free:
12341234
kvfree(tmp);
12351235
out_put:
1236-
iommufd_put_object(&hwpt->obj);
1236+
iommufd_put_object(ucmd->ictx, &hwpt->obj);
12371237
return rc;
12381238
}
12391239

drivers/iommu/iommufd/vfio_compat.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ int iommufd_vfio_compat_ioas_get_id(struct iommufd_ctx *ictx, u32 *out_ioas_id)
4141
if (IS_ERR(ioas))
4242
return PTR_ERR(ioas);
4343
*out_ioas_id = ioas->obj.id;
44-
iommufd_put_object(&ioas->obj);
44+
iommufd_put_object(ictx, &ioas->obj);
4545
return 0;
4646
}
4747
EXPORT_SYMBOL_NS_GPL(iommufd_vfio_compat_ioas_get_id, IOMMUFD_VFIO);
@@ -98,7 +98,7 @@ int iommufd_vfio_compat_ioas_create(struct iommufd_ctx *ictx)
9898

9999
if (ictx->vfio_ioas && iommufd_lock_obj(&ictx->vfio_ioas->obj)) {
100100
ret = 0;
101-
iommufd_put_object(&ictx->vfio_ioas->obj);
101+
iommufd_put_object(ictx, &ictx->vfio_ioas->obj);
102102
goto out_abort;
103103
}
104104
ictx->vfio_ioas = ioas;
@@ -133,7 +133,7 @@ int iommufd_vfio_ioas(struct iommufd_ucmd *ucmd)
133133
if (IS_ERR(ioas))
134134
return PTR_ERR(ioas);
135135
cmd->ioas_id = ioas->obj.id;
136-
iommufd_put_object(&ioas->obj);
136+
iommufd_put_object(ucmd->ictx, &ioas->obj);
137137
return iommufd_ucmd_respond(ucmd, sizeof(*cmd));
138138

139139
case IOMMU_VFIO_IOAS_SET:
@@ -143,7 +143,7 @@ int iommufd_vfio_ioas(struct iommufd_ucmd *ucmd)
143143
xa_lock(&ucmd->ictx->objects);
144144
ucmd->ictx->vfio_ioas = ioas;
145145
xa_unlock(&ucmd->ictx->objects);
146-
iommufd_put_object(&ioas->obj);
146+
iommufd_put_object(ucmd->ictx, &ioas->obj);
147147
return 0;
148148

149149
case IOMMU_VFIO_IOAS_CLEAR:
@@ -190,7 +190,7 @@ static int iommufd_vfio_map_dma(struct iommufd_ctx *ictx, unsigned int cmd,
190190
iova = map.iova;
191191
rc = iopt_map_user_pages(ictx, &ioas->iopt, &iova, u64_to_user_ptr(map.vaddr),
192192
map.size, iommu_prot, 0);
193-
iommufd_put_object(&ioas->obj);
193+
iommufd_put_object(ictx, &ioas->obj);
194194
return rc;
195195
}
196196

@@ -249,7 +249,7 @@ static int iommufd_vfio_unmap_dma(struct iommufd_ctx *ictx, unsigned int cmd,
249249
rc = -EFAULT;
250250

251251
err_put:
252-
iommufd_put_object(&ioas->obj);
252+
iommufd_put_object(ictx, &ioas->obj);
253253
return rc;
254254
}
255255

@@ -272,7 +272,7 @@ static int iommufd_vfio_cc_iommu(struct iommufd_ctx *ictx)
272272
}
273273
mutex_unlock(&ioas->mutex);
274274

275-
iommufd_put_object(&ioas->obj);
275+
iommufd_put_object(ictx, &ioas->obj);
276276
return rc;
277277
}
278278

@@ -349,7 +349,7 @@ static int iommufd_vfio_set_iommu(struct iommufd_ctx *ictx, unsigned long type)
349349
*/
350350
if (type == VFIO_TYPE1_IOMMU)
351351
rc = iopt_disable_large_pages(&ioas->iopt);
352-
iommufd_put_object(&ioas->obj);
352+
iommufd_put_object(ictx, &ioas->obj);
353353
return rc;
354354
}
355355

@@ -511,7 +511,7 @@ static int iommufd_vfio_iommu_get_info(struct iommufd_ctx *ictx,
511511

512512
out_put:
513513
up_read(&ioas->iopt.iova_rwsem);
514-
iommufd_put_object(&ioas->obj);
514+
iommufd_put_object(ictx, &ioas->obj);
515515
return rc;
516516
}
517517

0 commit comments

Comments
 (0)