From: "Noralf Trønnes" <noralf-L59+Z2yzLopAfugRpC6u6w@public.gmane.org>
To: dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org
Cc: David1.Zhou-5C7GfCeVMHo@public.gmane.org,
Andrey.Grodzovsky-5C7GfCeVMHo@public.gmane.org,
oleksandr_andrushchenko-uRwfk40T5oI@public.gmane.org,
daniel.vetter-/w4YWyX8dFk@public.gmane.org,
intel-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org,
amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org,
"Noralf Trønnes" <noralf-L59+Z2yzLopAfugRpC6u6w@public.gmane.org>,
alexander.deucher-5C7GfCeVMHo@public.gmane.org,
airlied-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org,
sean-p7yTbzM4H96eqtR555YLDQ@public.gmane.org,
christian.koenig-5C7GfCeVMHo@public.gmane.org
Subject: [PATCH v2 1/2] drm: Fix drm_release() and device unplug
Date: Fri, 8 Feb 2019 15:01:02 +0100 [thread overview]
Message-ID: <20190208140103.28919-2-noralf@tronnes.org> (raw)
In-Reply-To: <20190208140103.28919-1-noralf-L59+Z2yzLopAfugRpC6u6w@public.gmane.org>
If userspace has open fd(s) when drm_dev_unplug() is run, it will result
in drm_dev_unregister() being called twice. First in drm_dev_unplug() and
then later in drm_release() through the call to drm_put_dev().
Since userspace already holds a ref on drm_device through the drm_minor,
it's not necessary to add extra ref counting based on no open file
handles. Instead just drm_dev_put() unconditionally in drm_dev_unplug().
We now have this:
- Userpace holds a ref on drm_device as long as there's open fd(s)
- The driver holds a ref on drm_device as long as it's bound to the
struct device
When both sides are done with drm_device, it is released.
Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
Reviewed-by: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Reviewed-by: Sean Paul <sean@poorly.run>
---
drivers/gpu/drm/drm_drv.c | 6 +-----
drivers/gpu/drm/drm_file.c | 6 ++----
2 files changed, 3 insertions(+), 9 deletions(-)
diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
index 381581b01d48..05bbc2b622fc 100644
--- a/drivers/gpu/drm/drm_drv.c
+++ b/drivers/gpu/drm/drm_drv.c
@@ -376,11 +376,7 @@ void drm_dev_unplug(struct drm_device *dev)
synchronize_srcu(&drm_unplug_srcu);
drm_dev_unregister(dev);
-
- mutex_lock(&drm_global_mutex);
- if (dev->open_count == 0)
- drm_dev_put(dev);
- mutex_unlock(&drm_global_mutex);
+ drm_dev_put(dev);
}
EXPORT_SYMBOL(drm_dev_unplug);
diff --git a/drivers/gpu/drm/drm_file.c b/drivers/gpu/drm/drm_file.c
index 46f48f245eb5..3f20f598cd7c 100644
--- a/drivers/gpu/drm/drm_file.c
+++ b/drivers/gpu/drm/drm_file.c
@@ -479,11 +479,9 @@ int drm_release(struct inode *inode, struct file *filp)
drm_file_free(file_priv);
- if (!--dev->open_count) {
+ if (!--dev->open_count)
drm_lastclose(dev);
- if (drm_dev_is_unplugged(dev))
- drm_put_dev(dev);
- }
+
mutex_unlock(&drm_global_mutex);
drm_minor_release(minor);
--
2.20.1
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
next prev parent reply other threads:[~2019-02-08 14:01 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-08 14:01 [PATCH v2 0/2] drm/drv: Rework drm_dev_unplug() (was: Remove drm_dev_unplug()) Noralf Trønnes
[not found] ` <20190208140103.28919-1-noralf-L59+Z2yzLopAfugRpC6u6w@public.gmane.org>
2019-02-08 14:01 ` Noralf Trønnes [this message]
2019-02-08 14:01 ` [PATCH v2 2/2] drm/drv: drm_dev_unplug(): Move out drm_dev_put() call Noralf Trønnes
2019-02-08 14:36 ` Oleksandr Andrushchenko
[not found] ` <20190208140103.28919-3-noralf-L59+Z2yzLopAfugRpC6u6w@public.gmane.org>
2019-02-11 8:28 ` Daniel Vetter
2019-02-08 15:54 ` ✓ Fi.CI.BAT: success for drm/drv: Rework drm_dev_unplug() (was: Remove drm_dev_unplug()) Patchwork
2019-02-08 18:45 ` ✓ Fi.CI.IGT: " Patchwork
2019-02-21 11:31 ` [PATCH v2 0/2] " Noralf Trønnes
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190208140103.28919-2-noralf@tronnes.org \
--to=noralf-l59+z2yzlopafugrpc6u6w@public.gmane.org \
--cc=Andrey.Grodzovsky-5C7GfCeVMHo@public.gmane.org \
--cc=David1.Zhou-5C7GfCeVMHo@public.gmane.org \
--cc=airlied-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
--cc=alexander.deucher-5C7GfCeVMHo@public.gmane.org \
--cc=amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
--cc=christian.koenig-5C7GfCeVMHo@public.gmane.org \
--cc=daniel.vetter-/w4YWyX8dFk@public.gmane.org \
--cc=dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
--cc=intel-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
--cc=oleksandr_andrushchenko-uRwfk40T5oI@public.gmane.org \
--cc=sean-p7yTbzM4H96eqtR555YLDQ@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox