Skip to content

Commit 977625a

Browse files
nhaehnleingomolnar
authored andcommitted
locking/mutex: Initialize mutex_waiter::ww_ctx with poison when debugging
Help catch cases where mutex_lock is used directly on w/w mutexes, which otherwise result in the w/w tasks reading uninitialized data. Signed-off-by: Nicolai Hähnle <Nicolai.Haehnle@amd.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Chris Wilson <chris@chris-wilson.co.uk> Cc: Daniel Vetter <daniel@ffwll.ch> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Maarten Lankhorst <dev@mblankhorst.nl> Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: dri-devel@lists.freedesktop.org Link: http://lkml.kernel.org/r/1482346000-9927-12-git-send-email-nhaehnle@gmail.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent c516df9 commit 977625a

2 files changed

Lines changed: 5 additions & 0 deletions

File tree

‎include/linux/poison.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
/********** kernel/mutexes **********/
8181
#define MUTEX_DEBUG_INIT 0x11
8282
#define MUTEX_DEBUG_FREE 0x22
83+
#define MUTEX_POISON_WW_CTX ((void *) 0x500 + POISON_POINTER_DELTA)
8384

8485
/********** lib/flex_array.c **********/
8586
#define FLEX_ARRAY_FREE 0x6c /* for use-after-free poisoning */

‎kernel/locking/mutex.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,10 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
785785
if (!use_ww_ctx) {
786786
/* add waiting tasks to the end of the waitqueue (FIFO): */
787787
list_add_tail(&waiter.list, &lock->wait_list);
788+
789+
#ifdef CONFIG_DEBUG_MUTEXES
790+
waiter.ww_ctx = MUTEX_POISON_WW_CTX;
791+
#endif
788792
} else {
789793
/* Add in stamp order, waking up waiters that must back off. */
790794
ret = __ww_mutex_add_waiter(&waiter, lock, ww_ctx);

0 commit comments

Comments
 (0)