Skip to content

Commit 651f733

Browse files
Xu Yilunjgunthorpe
authored andcommitted
iommufd/vdevice: Remove struct device reference from struct vdevice
Remove struct device *dev from struct vdevice. The dev pointer is the Plan B for vdevice to reference the physical device. As now vdev->idev is added without refcounting concern, just use vdev->idev->dev when needed. To avoid exposing struct iommufd_device in the public header, export a iommufd_vdevice_to_device() helper. Link: https://patch.msgid.link/r/[email protected] Reviewed-by: Jason Gunthorpe <[email protected]> Reviewed-by: Kevin Tian <[email protected]> Reviewed-by: Nicolin Chen <[email protected]> Co-developed-by: Nicolin Chen <[email protected]> Signed-off-by: Nicolin Chen <[email protected]> Tested-by: Nicolin Chen <[email protected]> Signed-off-by: Xu Yilun <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 850f14f commit 651f733

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1218,7 +1218,8 @@ static void tegra241_vintf_destroy_vsid(struct iommufd_vdevice *vdev)
12181218

12191219
static int tegra241_vintf_init_vsid(struct iommufd_vdevice *vdev)
12201220
{
1221-
struct arm_smmu_master *master = dev_iommu_priv_get(vdev->dev);
1221+
struct device *dev = iommufd_vdevice_to_device(vdev);
1222+
struct arm_smmu_master *master = dev_iommu_priv_get(dev);
12221223
struct tegra241_vintf *vintf = viommu_to_vintf(vdev->viommu);
12231224
struct tegra241_vintf_sid *vsid = vdev_to_vsid(vdev);
12241225
struct arm_smmu_stream *stream = &master->streams[0];

drivers/iommu/iommufd/driver.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ void _iommufd_destroy_mmap(struct iommufd_ctx *ictx,
8383
}
8484
EXPORT_SYMBOL_NS_GPL(_iommufd_destroy_mmap, "IOMMUFD");
8585

86+
struct device *iommufd_vdevice_to_device(struct iommufd_vdevice *vdev)
87+
{
88+
return vdev->idev->dev;
89+
}
90+
EXPORT_SYMBOL_NS_GPL(iommufd_vdevice_to_device, "IOMMUFD");
91+
8692
/* Caller should xa_lock(&viommu->vdevs) to protect the return value */
8793
struct device *iommufd_viommu_find_dev(struct iommufd_viommu *viommu,
8894
unsigned long vdev_id)
@@ -92,7 +98,7 @@ struct device *iommufd_viommu_find_dev(struct iommufd_viommu *viommu,
9298
lockdep_assert_held(&viommu->vdevs.xa_lock);
9399

94100
vdev = xa_load(&viommu->vdevs, vdev_id);
95-
return vdev ? vdev->dev : NULL;
101+
return vdev ? iommufd_vdevice_to_device(vdev) : NULL;
96102
}
97103
EXPORT_SYMBOL_NS_GPL(iommufd_viommu_find_dev, "IOMMUFD");
98104

@@ -109,7 +115,7 @@ int iommufd_viommu_get_vdev_id(struct iommufd_viommu *viommu,
109115

110116
xa_lock(&viommu->vdevs);
111117
xa_for_each(&viommu->vdevs, index, vdev) {
112-
if (vdev->dev == dev) {
118+
if (iommufd_vdevice_to_device(vdev) == dev) {
113119
*vdev_id = vdev->virt_id;
114120
rc = 0;
115121
break;

drivers/iommu/iommufd/viommu.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ void iommufd_vdevice_abort(struct iommufd_object *obj)
125125
xa_cmpxchg(&viommu->vdevs, vdev->virt_id, vdev, NULL, GFP_KERNEL);
126126
refcount_dec(&viommu->obj.users);
127127
idev->vdev = NULL;
128-
put_device(vdev->dev);
129128
}
130129

131130
void iommufd_vdevice_destroy(struct iommufd_object *obj)
@@ -203,8 +202,6 @@ int iommufd_vdevice_alloc_ioctl(struct iommufd_ucmd *ucmd)
203202
}
204203

205204
vdev->virt_id = virt_id;
206-
vdev->dev = idev->dev;
207-
get_device(idev->dev);
208205
vdev->viommu = viommu;
209206
refcount_inc(&viommu->obj.users);
210207
/*

include/linux/iommufd.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ struct iommufd_vdevice {
109109
struct iommufd_object obj;
110110
struct iommufd_viommu *viommu;
111111
struct iommufd_device *idev;
112-
struct device *dev;
113112

114113
/*
115114
* Virtual device ID per vIOMMU, e.g. vSID of ARM SMMUv3, vDeviceID of
@@ -261,6 +260,7 @@ int _iommufd_alloc_mmap(struct iommufd_ctx *ictx, struct iommufd_object *owner,
261260
unsigned long *offset);
262261
void _iommufd_destroy_mmap(struct iommufd_ctx *ictx,
263262
struct iommufd_object *owner, unsigned long offset);
263+
struct device *iommufd_vdevice_to_device(struct iommufd_vdevice *vdev);
264264
struct device *iommufd_viommu_find_dev(struct iommufd_viommu *viommu,
265265
unsigned long vdev_id);
266266
int iommufd_viommu_get_vdev_id(struct iommufd_viommu *viommu,
@@ -295,6 +295,12 @@ static inline void _iommufd_destroy_mmap(struct iommufd_ctx *ictx,
295295
{
296296
}
297297

298+
static inline struct device *
299+
iommufd_vdevice_to_device(struct iommufd_vdevice *vdev)
300+
{
301+
return NULL;
302+
}
303+
298304
static inline struct device *
299305
iommufd_viommu_find_dev(struct iommufd_viommu *viommu, unsigned long vdev_id)
300306
{

0 commit comments

Comments
 (0)