* [PATCH 2/3] lockdep: add might_lock_nested()
[not found] <20191104173720.2696-1-daniel.vetter@ffwll.ch>
@ 2019-11-04 17:37 ` Daniel Vetter
2019-11-04 17:37 ` [PATCH 3/3] drm/i915: use might_lock_nested in get_pages annotation Daniel Vetter
1 sibling, 0 replies; 3+ messages in thread
From: Daniel Vetter @ 2019-11-04 17:37 UTC (permalink / raw)
To: Intel Graphics Development
Cc: Daniel Vetter, Peter Zijlstra, Daniel Vetter, Ingo Molnar,
Will Deacon, linux-kernel
Necessary to annotate functions where we might acquire a
mutex_lock_nested() or similar. Needed by i915.
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Will Deacon <will@kernel.org>
Cc: linux-kernel@vger.kernel.org
---
include/linux/lockdep.h | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h
index e0eca94e58c8..c4155436e6fc 100644
--- a/include/linux/lockdep.h
+++ b/include/linux/lockdep.h
@@ -628,6 +628,13 @@ do { \
lock_acquire(&(lock)->dep_map, 0, 0, 1, 1, NULL, _THIS_IP_); \
lock_release(&(lock)->dep_map, 0, _THIS_IP_); \
} while (0)
+# define might_lock_nested(lock, subclass) \
+do { \
+ typecheck(struct lockdep_map *, &(lock)->dep_map); \
+ lock_acquire(&(lock)->dep_map, subclass, 0, 1, 1, NULL, \
+ _THIS_IP_); \
+ lock_release(&(lock)->dep_map, 0, _THIS_IP_); \
+} while (0)
#define lockdep_assert_irqs_enabled() do { \
WARN_ONCE(debug_locks && !current->lockdep_recursion && \
@@ -650,6 +657,7 @@ do { \
#else
# define might_lock(lock) do { } while (0)
# define might_lock_read(lock) do { } while (0)
+# define might_lock_nested(lock, subclass) do { } while (0)
# define lockdep_assert_irqs_enabled() do { } while (0)
# define lockdep_assert_irqs_disabled() do { } while (0)
# define lockdep_assert_in_irq() do { } while (0)
--
2.24.0.rc2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 3/3] drm/i915: use might_lock_nested in get_pages annotation
[not found] <20191104173720.2696-1-daniel.vetter@ffwll.ch>
2019-11-04 17:37 ` [PATCH 2/3] lockdep: add might_lock_nested() Daniel Vetter
@ 2019-11-04 17:37 ` Daniel Vetter
2019-11-05 9:02 ` [Intel-gfx] " Joonas Lahtinen
1 sibling, 1 reply; 3+ messages in thread
From: Daniel Vetter @ 2019-11-04 17:37 UTC (permalink / raw)
To: Intel Graphics Development
Cc: Daniel Vetter, Daniel Vetter, Peter Zijlstra, Ingo Molnar,
Will Deacon, linux-kernel
So strictly speaking the existing annotation is also ok, because we
have a chain of
obj->mm.lock#I915_MM_GET_PAGES -> fs_reclaim -> obj->mm.lock
(the shrinker cannot get at an object while we're in get_pages, hence
this is safe). But it's confusing, so try to take the right subclass
of the lock.
This does a bit reduce our lockdep based checking, but then it's also
less fragile, in case we ever change the nesting around.
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Will Deacon <will@kernel.org>
Cc: linux-kernel@vger.kernel.org
---
drivers/gpu/drm/i915/gem/i915_gem_object.h | 36 +++++++++++-----------
1 file changed, 18 insertions(+), 18 deletions(-)
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_object.h b/drivers/gpu/drm/i915/gem/i915_gem_object.h
index edaf7126a84d..e5750d506cc9 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_object.h
+++ b/drivers/gpu/drm/i915/gem/i915_gem_object.h
@@ -271,10 +271,27 @@ void __i915_gem_object_set_pages(struct drm_i915_gem_object *obj,
int ____i915_gem_object_get_pages(struct drm_i915_gem_object *obj);
int __i915_gem_object_get_pages(struct drm_i915_gem_object *obj);
+enum i915_mm_subclass { /* lockdep subclass for obj->mm.lock/struct_mutex */
+ I915_MM_NORMAL = 0,
+ /*
+ * Only used by struct_mutex, when called "recursively" from
+ * direct-reclaim-esque. Safe because there is only every one
+ * struct_mutex in the entire system.
+ */
+ I915_MM_SHRINKER = 1,
+ /*
+ * Used for obj->mm.lock when allocating pages. Safe because the object
+ * isn't yet on any LRU, and therefore the shrinker can't deadlock on
+ * it. As soon as the object has pages, obj->mm.lock nests within
+ * fs_reclaim.
+ */
+ I915_MM_GET_PAGES = 1,
+};
+
static inline int __must_check
i915_gem_object_pin_pages(struct drm_i915_gem_object *obj)
{
- might_lock(&obj->mm.lock);
+ might_lock_nested(&obj->mm.lock, I915_MM_GET_PAGES);
if (atomic_inc_not_zero(&obj->mm.pages_pin_count))
return 0;
@@ -317,23 +334,6 @@ i915_gem_object_unpin_pages(struct drm_i915_gem_object *obj)
__i915_gem_object_unpin_pages(obj);
}
-enum i915_mm_subclass { /* lockdep subclass for obj->mm.lock/struct_mutex */
- I915_MM_NORMAL = 0,
- /*
- * Only used by struct_mutex, when called "recursively" from
- * direct-reclaim-esque. Safe because there is only every one
- * struct_mutex in the entire system.
- */
- I915_MM_SHRINKER = 1,
- /*
- * Used for obj->mm.lock when allocating pages. Safe because the object
- * isn't yet on any LRU, and therefore the shrinker can't deadlock on
- * it. As soon as the object has pages, obj->mm.lock nests within
- * fs_reclaim.
- */
- I915_MM_GET_PAGES = 1,
-};
-
int __i915_gem_object_put_pages(struct drm_i915_gem_object *obj);
void i915_gem_object_truncate(struct drm_i915_gem_object *obj);
void i915_gem_object_writeback(struct drm_i915_gem_object *obj);
--
2.24.0.rc2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Intel-gfx] [PATCH 3/3] drm/i915: use might_lock_nested in get_pages annotation
2019-11-04 17:37 ` [PATCH 3/3] drm/i915: use might_lock_nested in get_pages annotation Daniel Vetter
@ 2019-11-05 9:02 ` Joonas Lahtinen
0 siblings, 0 replies; 3+ messages in thread
From: Joonas Lahtinen @ 2019-11-05 9:02 UTC (permalink / raw)
To: Daniel Vetter, Intel Graphics Development
Cc: Peter Zijlstra, Daniel Vetter, linux-kernel, Ingo Molnar,
Daniel Vetter, Will Deacon
Quoting Daniel Vetter (2019-11-04 19:37:20)
> So strictly speaking the existing annotation is also ok, because we
> have a chain of
>
> obj->mm.lock#I915_MM_GET_PAGES -> fs_reclaim -> obj->mm.lock
>
> (the shrinker cannot get at an object while we're in get_pages, hence
> this is safe). But it's confusing, so try to take the right subclass
> of the lock.
>
> This does a bit reduce our lockdep based checking, but then it's also
> less fragile, in case we ever change the nesting around.
>
> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: Will Deacon <will@kernel.org>
> Cc: linux-kernel@vger.kernel.org
Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Regards, Joonas
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-11-05 9:02 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <20191104173720.2696-1-daniel.vetter@ffwll.ch>
2019-11-04 17:37 ` [PATCH 2/3] lockdep: add might_lock_nested() Daniel Vetter
2019-11-04 17:37 ` [PATCH 3/3] drm/i915: use might_lock_nested in get_pages annotation Daniel Vetter
2019-11-05 9:02 ` [Intel-gfx] " Joonas Lahtinen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).