Skip to content

Commit ab7e5e3

Browse files
jgunthorpeAlex Williamson
authored andcommitted
vfio/platform: Use open_device() instead of open coding a refcnt scheme
Platform simply wants to run some code when the device is first opened/last closed. Use the core framework and locking for this. Aside from removing a bit of code this narrows the locking scope from a global lock. Reviewed-by: Cornelia Huck <cohuck@redhat.com> Reviewed-by: Eric Auger <eric.auger@redhat.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Signed-off-by: Yishai Hadas <yishaih@nvidia.com> Link: https://lore.kernel.org/r/7-v4-9ea22c5e6afb+1adf-vfio_reflck_jgg@nvidia.com Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
1 parent da119f3 commit ab7e5e3

2 files changed

Lines changed: 32 additions & 48 deletions

File tree

drivers/vfio/platform/vfio_platform_common.c

Lines changed: 32 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -218,74 +218,59 @@ static int vfio_platform_call_reset(struct vfio_platform_device *vdev,
218218
return -EINVAL;
219219
}
220220

221-
static void vfio_platform_release(struct vfio_device *core_vdev)
221+
static void vfio_platform_close_device(struct vfio_device *core_vdev)
222222
{
223223
struct vfio_platform_device *vdev =
224224
container_of(core_vdev, struct vfio_platform_device, vdev);
225+
const char *extra_dbg = NULL;
226+
int ret;
225227

226-
mutex_lock(&driver_lock);
227-
228-
if (!(--vdev->refcnt)) {
229-
const char *extra_dbg = NULL;
230-
int ret;
231-
232-
ret = vfio_platform_call_reset(vdev, &extra_dbg);
233-
if (ret && vdev->reset_required) {
234-
dev_warn(vdev->device, "reset driver is required and reset call failed in release (%d) %s\n",
235-
ret, extra_dbg ? extra_dbg : "");
236-
WARN_ON(1);
237-
}
238-
pm_runtime_put(vdev->device);
239-
vfio_platform_regions_cleanup(vdev);
240-
vfio_platform_irq_cleanup(vdev);
228+
ret = vfio_platform_call_reset(vdev, &extra_dbg);
229+
if (WARN_ON(ret && vdev->reset_required)) {
230+
dev_warn(
231+
vdev->device,
232+
"reset driver is required and reset call failed in release (%d) %s\n",
233+
ret, extra_dbg ? extra_dbg : "");
241234
}
242-
243-
mutex_unlock(&driver_lock);
235+
pm_runtime_put(vdev->device);
236+
vfio_platform_regions_cleanup(vdev);
237+
vfio_platform_irq_cleanup(vdev);
244238
}
245239

246-
static int vfio_platform_open(struct vfio_device *core_vdev)
240+
static int vfio_platform_open_device(struct vfio_device *core_vdev)
247241
{
248242
struct vfio_platform_device *vdev =
249243
container_of(core_vdev, struct vfio_platform_device, vdev);
244+
const char *extra_dbg = NULL;
250245
int ret;
251246

252-
mutex_lock(&driver_lock);
253-
254-
if (!vdev->refcnt) {
255-
const char *extra_dbg = NULL;
256-
257-
ret = vfio_platform_regions_init(vdev);
258-
if (ret)
259-
goto err_reg;
247+
ret = vfio_platform_regions_init(vdev);
248+
if (ret)
249+
return ret;
260250

261-
ret = vfio_platform_irq_init(vdev);
262-
if (ret)
263-
goto err_irq;
251+
ret = vfio_platform_irq_init(vdev);
252+
if (ret)
253+
goto err_irq;
264254

265-
ret = pm_runtime_get_sync(vdev->device);
266-
if (ret < 0)
267-
goto err_rst;
255+
ret = pm_runtime_get_sync(vdev->device);
256+
if (ret < 0)
257+
goto err_rst;
268258

269-
ret = vfio_platform_call_reset(vdev, &extra_dbg);
270-
if (ret && vdev->reset_required) {
271-
dev_warn(vdev->device, "reset driver is required and reset call failed in open (%d) %s\n",
272-
ret, extra_dbg ? extra_dbg : "");
273-
goto err_rst;
274-
}
259+
ret = vfio_platform_call_reset(vdev, &extra_dbg);
260+
if (ret && vdev->reset_required) {
261+
dev_warn(
262+
vdev->device,
263+
"reset driver is required and reset call failed in open (%d) %s\n",
264+
ret, extra_dbg ? extra_dbg : "");
265+
goto err_rst;
275266
}
276-
277-
vdev->refcnt++;
278-
279-
mutex_unlock(&driver_lock);
280267
return 0;
281268

282269
err_rst:
283270
pm_runtime_put(vdev->device);
284271
vfio_platform_irq_cleanup(vdev);
285272
err_irq:
286273
vfio_platform_regions_cleanup(vdev);
287-
err_reg:
288-
mutex_unlock(&driver_lock);
289274
return ret;
290275
}
291276

@@ -616,8 +601,8 @@ static int vfio_platform_mmap(struct vfio_device *core_vdev, struct vm_area_stru
616601

617602
static const struct vfio_device_ops vfio_platform_ops = {
618603
.name = "vfio-platform",
619-
.open = vfio_platform_open,
620-
.release = vfio_platform_release,
604+
.open_device = vfio_platform_open_device,
605+
.close_device = vfio_platform_close_device,
621606
.ioctl = vfio_platform_ioctl,
622607
.read = vfio_platform_read,
623608
.write = vfio_platform_write,

drivers/vfio/platform/vfio_platform_private.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ struct vfio_platform_device {
4848
u32 num_regions;
4949
struct vfio_platform_irq *irqs;
5050
u32 num_irqs;
51-
int refcnt;
5251
struct mutex igate;
5352
const char *compat;
5453
const char *acpihid;

0 commit comments

Comments
 (0)