drm/fb-helper: Try to protect cleanup against delayed setup
Subsystems (2)
PATCH 1/1 drm/fb-helper: Try to protect cleanup against delayed setup
Some vague evidences suggests this can go wrong. Try to prevent it by holding the right mutex and clearing ->deferred_setup to make sure we later on don't accidentally try to re-register the fbdev when the driver thought it had it all cleaned up already.
v2: I realized that this is fundamentally butchered, and CI complained about lockdep splats. So limit the critical section again and just add a few notes what the proper fix is.
References: https://intel-gfx-ci.01.org/tree/linux-next/next-20201215/fi-byt-j1900/igt@[email protected]
--- drivers/gpu/drm/drm_fb_helper.c | 6 ++++++ drivers/gpu/drm/drm_fbdev_generic.c | 5 +++++ 2 files changed, 11 insertions(+)
drivers/gpu/drm/drm_fb_helper.c +6 -0
@@ -545,6 +545,9 @@ EXPORT_SYMBOL(drm_fb_helper_alloc_info);* A wrapper around unregister_framebuffer, to release the fb_info * framebuffer device. This must be called before releasing all resources for * @fb_helper by calling drm_fb_helper_fini(). +* +* Note that this is fundamentally racy on hotunload because it doen't handle +* open fbdev file descriptors at all. Use drm_fbdev_generic_setup() instead. */ void drm_fb_helper_unregister_info (struct drm_fb_helper *fb_helper) {
@@ -558,6 +561,9 @@ EXPORT_SYMBOL(drm_fb_helper_unregister_info);* @fb_helper: driver-allocated fbdev helper, can be NULL * * This cleans up all remaining resources associated with @fb_helper. +* +* Note that this is fundamentally racy on hotunload because it doen't handle +* open fbdev file descriptors at all. Use drm_fbdev_generic_setup() instead. */ void drm_fb_helper_fini (struct drm_fb_helper *fb_helper) {
drivers/gpu/drm/drm_fbdev_generic.c +5 -0
@@ -347,7 +347,12 @@ static void drm_fbdev_client_unregister(struct drm_client_dev *client) {struct drm_fb_helper *fb_helper =drm_fb_helper_from_client (client); +mutex_lock (&fb_helper->lock); + fb_helper->deferred_setup = false; +mutex_unlock (&fb_helper->lock); +if (fb_helper->info) { +/* drm_fbdev_fb_destroy() takes care of cleanup */ drm_fb_helper_unregister_info (fb_helper); }else {drm_client_release (&fb_helper->client);
Signature · 1 line
2.39.0
Thomas Zimmermann
maintainerHi
Am 17.02.23 um 20:47 schrieb Daniel Vetter:
Quoted 52 lines
Some vague evidences suggests this can go wrong. Try to prevent it by holding the right mutex and clearing ->deferred_setup to make sure we later on don't accidentally try to re-register the fbdev when the driver thought it had it all cleaned up already.
v2: I realized that this is fundamentally butchered, and CI complained about lockdep splats. So limit the critical section again and just add a few notes what the proper fix is.
References: https://intel-gfx-ci.01.org/tree/linux-next/next-20201215/fi-byt-j1900/igt@[email protected]
Signed-off-by Daniel Vetter <[email protected]>Cc Ville Syrjälä <[email protected]>Cc Chris Wilson <[email protected]>Cc Maarten Lankhorst <[email protected]>Cc Maxime Ripard <[email protected]>Cc Thomas Zimmermann <[email protected]>Cc David Airlie <[email protected]>Cc Daniel Vetter <[email protected]>--- drivers/gpu/drm/drm_fb_helper.c | 6 ++++++ drivers/gpu/drm/drm_fbdev_generic.c | 5 +++++ 2 files changed, 11 insertions(+)drivers/gpu/drm/drm_fb_helper.c +6
-0@@ -545,6 +545,9 @@ EXPORT_SYMBOL(drm_fb_helper_alloc_info);* A wrapper around unregister_framebuffer, to release the fb_info * framebuffer device. This must be called before releasing all resources for * @fb_helper by calling drm_fb_helper_fini(). +* +* Note that this is fundamentally racy on hotunload because it doen't handle +* open fbdev file descriptors at all. Use drm_fbdev_generic_setup() instead. */ void drm_fb_helper_unregister_info (struct drm_fb_helper *fb_helper) {@@ -558,6 +561,9 @@ EXPORT_SYMBOL(drm_fb_helper_unregister_info);* @fb_helper: driver-allocated fbdev helper, can be NULL * * This cleans up all remaining resources associated with @fb_helper. +* +* Note that this is fundamentally racy on hotunload because it doen't handle +* open fbdev file descriptors at all. Use drm_fbdev_generic_setup() instead. */ void drm_fb_helper_fini (struct drm_fb_helper *fb_helper) {drivers/gpu/drm/drm_fbdev_generic.c +0
-0
drivers/gpu/drm/drm_fbdev_generic.c static void drm_fbdev_client_unregister(struct drm_client_dev *client) · line 352
Quoted 6 lines
drivers/gpu/drm/drm_fbdev_generic.c +3
-0@@ -347,7 +347,12 @@ static void drm_fbdev_client_unregister(struct drm_client_dev *client) {struct drm_fb_helper *fb_helper =drm_fb_helper_from_client (client); +mutex_lock (&fb_helper->lock); + fb_helper->deferred_setup = false; +mutex_unlock (&fb_helper->lock);
The unregister code runs as part of the client cleanup. And the client also goes through a number of helpers that handle display hotplug and/or restore, which are affected by ->deferred_setup. But it's all mutually exclusive. AFAICT nothing runs parallel to the unregister code. See the use of dev->clientlist_mutex in drm_client.c. The patch is not necessary IMHO.
Best regards
Thomas
Quoted 6 lines
drivers/gpu/drm/drm_fbdev_generic.c +2
-0+if (fb_helper->info) { +/* drm_fbdev_fb_destroy() takes care of cleanup */ drm_fb_helper_unregister_info (fb_helper); }else {drm_client_release (&fb_helper->client);
Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Ivo Totev