Skip to content

Commit 4522ad7

Browse files
sgruszkajlawryno
authored andcommitted
accel/ivpu: Do not access HW registers after unbind
We should not access hardware after we unbind from the bus. Use drm_dev_enter() / drm_dev_exit() to mark code sections where hardware is accessed (and not already protected by other locks) and drm_dev_unplug() to mark device is gone. Fixes: 35b1376 ("accel/ivpu: Introduce a new DRM driver for Intel VPU") Signed-off-by: Stanislaw Gruszka <[email protected]> Reviewed-by: Jeffrey Hugo <[email protected]> Signed-off-by: Jacek Lawrynowicz <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 1a70ca8 commit 4522ad7

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

drivers/accel/ivpu/ivpu_drv.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include <linux/pci.h>
99

1010
#include <drm/drm_accel.h>
11-
#include <drm/drm_drv.h>
1211
#include <drm/drm_file.h>
1312
#include <drm/drm_gem.h>
1413
#include <drm/drm_ioctl.h>
@@ -118,6 +117,10 @@ static int ivpu_get_param_ioctl(struct drm_device *dev, void *data, struct drm_f
118117
struct pci_dev *pdev = to_pci_dev(vdev->drm.dev);
119118
struct drm_ivpu_param *args = data;
120119
int ret = 0;
120+
int idx;
121+
122+
if (!drm_dev_enter(dev, &idx))
123+
return -ENODEV;
121124

122125
switch (args->param) {
123126
case DRM_IVPU_PARAM_DEVICE_ID:
@@ -171,6 +174,7 @@ static int ivpu_get_param_ioctl(struct drm_device *dev, void *data, struct drm_f
171174
break;
172175
}
173176

177+
drm_dev_exit(idx);
174178
return ret;
175179
}
176180

@@ -622,7 +626,7 @@ static void ivpu_remove(struct pci_dev *pdev)
622626
{
623627
struct ivpu_device *vdev = pci_get_drvdata(pdev);
624628

625-
drm_dev_unregister(&vdev->drm);
629+
drm_dev_unplug(&vdev->drm);
626630
ivpu_dev_fini(vdev);
627631
}
628632

drivers/accel/ivpu/ivpu_drv.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#define __IVPU_DRV_H__
88

99
#include <drm/drm_device.h>
10+
#include <drm/drm_drv.h>
1011
#include <drm/drm_managed.h>
1112
#include <drm/drm_mm.h>
1213
#include <drm/drm_print.h>

drivers/accel/ivpu/ivpu_job.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -489,12 +489,12 @@ ivpu_job_prepare_bos_for_submit(struct drm_file *file, struct ivpu_job *job, u32
489489

490490
int ivpu_submit_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
491491
{
492-
int ret = 0;
493492
struct ivpu_file_priv *file_priv = file->driver_priv;
494493
struct ivpu_device *vdev = file_priv->vdev;
495494
struct drm_ivpu_submit *params = data;
496495
struct ivpu_job *job;
497496
u32 *buf_handles;
497+
int idx, ret;
498498

499499
if (params->engine > DRM_IVPU_ENGINE_COPY)
500500
return -EINVAL;
@@ -523,14 +523,19 @@ int ivpu_submit_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
523523
goto free_handles;
524524
}
525525

526+
if (!drm_dev_enter(&vdev->drm, &idx)) {
527+
ret = -ENODEV;
528+
goto free_handles;
529+
}
530+
526531
ivpu_dbg(vdev, JOB, "Submit ioctl: ctx %u buf_count %u\n",
527532
file_priv->ctx.id, params->buffer_count);
528533

529534
job = ivpu_create_job(file_priv, params->engine, params->buffer_count);
530535
if (!job) {
531536
ivpu_err(vdev, "Failed to create job\n");
532537
ret = -ENOMEM;
533-
goto free_handles;
538+
goto dev_exit;
534539
}
535540

536541
ret = ivpu_job_prepare_bos_for_submit(file, job, buf_handles, params->buffer_count,
@@ -548,6 +553,8 @@ int ivpu_submit_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
548553

549554
job_put:
550555
job_put(job);
556+
dev_exit:
557+
drm_dev_exit(idx);
551558
free_handles:
552559
kfree(buf_handles);
553560

0 commit comments

Comments
 (0)