Messages in this thread Patch in this message | | | Date | Mon, 3 Oct 2022 21:44:53 +0000 | Subject | [RFC PATCH 03/11] kernel/locking: Add p->blocked_on wrapper | From | "Connor O'Brien" <> |
| |
From: Valentin Schneider <valentin.schneider@arm.com>
This lets us assert p->blocked_lock is held whenever we access p->blocked_on.
XXX: just make a pointer return, so we can also check at get's.
Signed-off-by: Valentin Schneider <valentin.schneider@arm.com> [fix conflicts] Signed-off-by: Connor O'Brien <connoro@google.com> --- include/linux/sched.h | 7 +++++++ kernel/locking/mutex.c | 6 +++--- 2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/include/linux/sched.h b/include/linux/sched.h index bd995e66d7d6..379e4c052644 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -2201,6 +2201,13 @@ static inline int rwlock_needbreak(rwlock_t *lock) #endif } +static inline void set_task_blocked_on(struct task_struct *p, struct mutex *m) +{ + lockdep_assert_held(&p->blocked_lock); + + p->blocked_on = m; +} + static __always_inline bool need_resched(void) { return unlikely(tif_need_resched()); diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c index f05cd2d216c7..7800380219db 100644 --- a/kernel/locking/mutex.c +++ b/kernel/locking/mutex.c @@ -645,7 +645,7 @@ __mutex_lock_common(struct mutex *lock, unsigned int state, unsigned int subclas goto err_early_kill; } - current->blocked_on = lock; + set_task_blocked_on(current, lock); set_current_state(state); trace_contention_begin(lock, LCB_F_MUTEX); for (;;) { @@ -686,7 +686,7 @@ __mutex_lock_common(struct mutex *lock, unsigned int state, unsigned int subclas /* * Gets reset by ttwu_runnable(). */ - current->blocked_on = lock; + set_task_blocked_on(current, lock); set_current_state(state); /* * Here we order against unlock; we must either see it change @@ -720,7 +720,7 @@ __mutex_lock_common(struct mutex *lock, unsigned int state, unsigned int subclas } __mutex_remove_waiter(lock, &waiter); - current->blocked_on = NULL; + set_task_blocked_on(current, NULL); debug_mutex_free_waiter(&waiter); -- 2.38.0.rc1.362.ged0d419d3c-goog
| |