drm/managed: Define drmm_mutex_init() as a macro to fix lockdep
Subsystems (2)
PATCH 1/1 drm/managed: Define drmm_mutex_init() as a macro to fix lockdep
drmm_mutex_init() needs to be defined as a macro if we want lockdep to classify locks properly. If we don't do that, all locks will be considered as belonging to the same lock class, leading to false positive deadlock reports.
--- drivers/gpu/drm/drm_managed.c | 26 -------------------------- include/drm/drm_managed.h | 30 +++++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 27 deletions(-)
drivers/gpu/drm/drm_managed.c +0 -26
@@ -263,29 +263,3 @@ void drmm_kfree(struct drm_device *dev, void *data)free_dr (dr_match); }EXPORT_SYMBOL (drmm_kfree); - -static void drmm_mutex_release (struct drm_device *dev,void *res) -{ -struct mutex *lock = res; - -mutex_destroy (lock); -} - -/** -* drmm_mutex_init - &drm_device-managed mutex_init() -* @dev: DRM device -* @lock: lock to be initialized -* -* Returns: -* 0 on success, or a negative errno code otherwise. -* -* This is a &drm_device-managed version of mutex_init(). The initialized -* lock is automatically destroyed on the final drm_dev_put(). -*/ -int drmm_mutex_init (struct drm_device *dev,struct mutex *lock) -{ -mutex_init (lock); - -return drmm_add_action_or_reset (dev, drmm_mutex_release, lock); -} -EXPORT_SYMBOL (drmm_mutex_init);
include/drm/drm_managed.h +29 -1
@@ -105,6 +105,34 @@ char *drmm_kstrdup(struct drm_device *dev, const char *s, gfp_t gfp);void drmm_kfree (struct drm_device *dev,void *data); -int drmm_mutex_init (struct drm_device *dev,struct mutex *lock); +/* Private function, don't use. */ +static inline void __drmm_mutex_release (struct drm_device *dev,void *res) +{ +struct mutex *lock = res; + +mutex_destroy (lock); +} + +/** +* drmm_mutex_init - &drm_device-managed mutex_init() +* @dev: DRM device +* @lock: lock to be initialized +* +* Returns: +* 0 on success, or a negative errno code otherwise. +* +* This is a &drm_device-managed version of mutex_init(). The initialized +* lock is automatically destroyed on the final drm_dev_put(). +* +* This needs to be defined as a macro to let lockdep classify locks +* properly. If we don't do that, all locks will be considered as +* belonging to the same lock class, leading to false positive lockdep +* reports. +*/ +#define drmm_mutex_init (dev, lock) \ + ({\ + mutex_init(lock); \ + drmm_add_action_or_reset(dev, __drmm_mutex_release, lock); \ + })#endif
Signature · 1 line
2.40.1
Quoted 8 lines · Boris Brezillon
drmm_mutex_init()needs to be defined as a macro if we want lockdep to classify locks properly. If we don't do that, all locks will be considered as belonging to the same lock class, leading to false positive deadlock reports.Signed-off-by Boris Brezillon <[email protected]>Reported-by Sarah Walker <[email protected]>
Yeah, we also encountered the same issue. Patch is here:
https://patchwork.freedesktop.org/patch/537605/?series=117891&rev=2
Quoted 82 lines
--- drivers/gpu/drm/drm_managed.c | 26 -------------------------- include/drm/drm_managed.h | 30 +++++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 27 deletions(-)drivers/gpu/drm/drm_managed.c +0
-26@@ -263,29 +263,3 @@ void drmm_kfree(struct drm_device *dev, void *data)free_dr (dr_match); }EXPORT_SYMBOL (drmm_kfree); - -static void drmm_mutex_release (struct drm_device *dev,void *res) -{ -struct mutex *lock = res; - -mutex_destroy (lock); -} - -/** -* drmm_mutex_init - &drm_device-managed mutex_init() -* @dev: DRM device -* @lock: lock to be initialized -* -* Returns: -* 0 on success, or a negative errno code otherwise. -* -* This is a &drm_device-managed version of mutex_init(). The initialized -* lock is automatically destroyed on the final drm_dev_put(). -*/ -int drmm_mutex_init (struct drm_device *dev,struct mutex *lock) -{ -mutex_init (lock); - -return drmm_add_action_or_reset (dev, drmm_mutex_release, lock); -} -EXPORT_SYMBOL (drmm_mutex_init);include/drm/drm_managed.h +29
-2@@ -105,6 +105,34 @@ char *drmm_kstrdup(struct drm_device *dev, const char *s, gfp_t gfp);void drmm_kfree (struct drm_device *dev,void *data); -int drmm_mutex_init (struct drm_device *dev,struct mutex *lock); +/* Private function, don't use. */ +static inline void __drmm_mutex_release (struct drm_device *dev,void *res) +{ +struct mutex *lock = res; + +mutex_destroy (lock); +} + +/** +* drmm_mutex_init - &drm_device-managed mutex_init() +* @dev: DRM device +* @lock: lock to be initialized +* +* Returns: +* 0 on success, or a negative errno code otherwise. +* +* This is a &drm_device-managed version of mutex_init(). The initialized +* lock is automatically destroyed on the final drm_dev_put(). +* +* This needs to be defined as a macro to let lockdep classify locks +* properly. If we don't do that, all locks will be considered as +* belonging to the same lock class, leading to false positive lockdep +* reports. +*/ +#define drmm_mutex_init (dev, lock) \ + ({\ + mutex_init(lock); \ + drmm_add_action_or_reset(dev, __drmm_mutex_release, lock); \ + })#endif --2.40.1
Quoted 8 lines · On Fri, 19 May 2023 10:05:27 +0100 Matthew Auld…
Quoted 6 lines · Boris Brezillon
drmm_mutex_init()needs to be defined as a macro if we want lockdep to classify locks properly. If we don't do that, all locks will be considered as belonging to the same lock class, leading to false positive deadlock reports.
Quoted 5 lines
Quoted 2 lines
Signed-off-by Boris Brezillon <[email protected]>Reported-by Sarah Walker <[email protected]>Yeah, we also encountered the same issue. Patch is here:
https://patchwork.freedesktop.org/patch/537605/?series=117891&rev=2
Cool! Added my R-b to this patch.
Hi
Quoted 7 lines · Boris Brezillon
drmm_mutex_init()needs to be defined as a macro if we want lockdep to classify locks properly. If we don't do that, all locks will be considered as belonging to the same lock class, leading to false positive deadlock reports.Signed-off-by Boris Brezillon <[email protected]>Reported-by Sarah Walker <[email protected]>
FYI: we have similar patch already posted:
https://lore.kernel.org/dri-devel/[email protected]/
Regards
Stanislaw
Quoted 82 lines
--- drivers/gpu/drm/drm_managed.c | 26 -------------------------- include/drm/drm_managed.h | 30 +++++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 27 deletions(-)drivers/gpu/drm/drm_managed.c +0
-26@@ -263,29 +263,3 @@ void drmm_kfree(struct drm_device *dev, void *data)free_dr (dr_match); }EXPORT_SYMBOL (drmm_kfree); - -static void drmm_mutex_release (struct drm_device *dev,void *res) -{ -struct mutex *lock = res; - -mutex_destroy (lock); -} - -/** -* drmm_mutex_init - &drm_device-managed mutex_init() -* @dev: DRM device -* @lock: lock to be initialized -* -* Returns: -* 0 on success, or a negative errno code otherwise. -* -* This is a &drm_device-managed version of mutex_init(). The initialized -* lock is automatically destroyed on the final drm_dev_put(). -*/ -int drmm_mutex_init (struct drm_device *dev,struct mutex *lock) -{ -mutex_init (lock); - -return drmm_add_action_or_reset (dev, drmm_mutex_release, lock); -} -EXPORT_SYMBOL (drmm_mutex_init);include/drm/drm_managed.h +29
-1@@ -105,6 +105,34 @@ char *drmm_kstrdup(struct drm_device *dev, const char *s, gfp_t gfp);void drmm_kfree (struct drm_device *dev,void *data); -int drmm_mutex_init (struct drm_device *dev,struct mutex *lock); +/* Private function, don't use. */ +static inline void __drmm_mutex_release (struct drm_device *dev,void *res) +{ +struct mutex *lock = res; + +mutex_destroy (lock); +} + +/** +* drmm_mutex_init - &drm_device-managed mutex_init() +* @dev: DRM device +* @lock: lock to be initialized +* +* Returns: +* 0 on success, or a negative errno code otherwise. +* +* This is a &drm_device-managed version of mutex_init(). The initialized +* lock is automatically destroyed on the final drm_dev_put(). +* +* This needs to be defined as a macro to let lockdep classify locks +* properly. If we don't do that, all locks will be considered as +* belonging to the same lock class, leading to false positive lockdep +* reports. +*/ +#define drmm_mutex_init (dev, lock) \ + ({\ + mutex_init(lock); \ + drmm_add_action_or_reset(dev, __drmm_mutex_release, lock); \ + })#endif Signature · 1 line
2.40.1