0003-lockdep-assert-none-held.patch 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. From 144ec5e1ce3bd238723a259c09f635b84fda423e Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Christian=20K=C3=B6nig?= <christian.koenig@amd.com>
  3. Date: Fri, 15 Jan 2021 14:32:39 +0100
  4. Subject: [PATCH] lockdep: add lockdep_assert_none_held_once() macro
  5. [ Upstream commit 7621350c6bb20fb6ab7eb988833ab96eac3dcbef ]
  6. DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT can't be used when we hold locks
  7. since we are basically waiting for userspace to do something.
  8. Holding a lock while doing so can trivial deadlock with page faults
  9. etc...
  10. So make lockdep complain when a driver tries to do this.
  11. v2: Add lockdep_assert_none_held() macro.
  12. v3: Add might_sleep() and also use lockdep_assert_none_held() in the
  13. IOCTL path.
  14. Signed-off-by: Christian König <christian.koenig@amd.com>
  15. Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
  16. Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
  17. Link: https://patchwork.freedesktop.org/patch/414944/
  18. Stable-dep-of: 3c43177ffb54 ("drm/syncobj: call drm_syncobj_fence_add_wait when WAIT_AVAILABLE flag is set")
  19. Signed-off-by: Sasha Levin <sashal@kernel.org>
  20. ---
  21. include/linux/lockdep.h | 5 +++++
  22. 1 file changed, 5 insertions(+)
  23. diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h
  24. index 2c2586312b44..3eca9f91b9a5 100644
  25. --- a/include/linux/lockdep.h
  26. +++ b/include/linux/lockdep.h
  27. @@ -321,6 +321,10 @@ extern void lock_unpin_lock(struct lockdep_map *lock, struct pin_cookie);
  28. WARN_ON_ONCE(debug_locks && !lockdep_is_held(l)); \
  29. } while (0)
  30. +#define lockdep_assert_none_held_once() do { \
  31. + WARN_ON_ONCE(debug_locks && current->lockdep_depth); \
  32. + } while (0)
  33. +
  34. #define lockdep_recursing(tsk) ((tsk)->lockdep_recursion)
  35. #define lockdep_pin_lock(l) lock_pin_lock(&(l)->dep_map)
  36. @@ -394,6 +398,7 @@ static inline void lockdep_unregister_key(struct lock_class_key *key)
  37. #define lockdep_assert_held_write(l) do { (void)(l); } while (0)
  38. #define lockdep_assert_held_read(l) do { (void)(l); } while (0)
  39. #define lockdep_assert_held_once(l) do { (void)(l); } while (0)
  40. +#define lockdep_assert_none_held_once() do { } while (0)
  41. #define lockdep_recursing(tsk) (0)
  42. --
  43. 2.55.0