From 0e474135ce7b8e885e32d0c3adc49b96bad17cd7 Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Sat, 12 Aug 2023 17:10:42 -0400 Subject: bcachefs: six locks: Guard against wakee exiting in __six_lock_wakeup() Signed-off-by: Kent Overstreet --- fs/bcachefs/six.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/fs/bcachefs/six.c b/fs/bcachefs/six.c index b6ca53c85249..14cffa68d722 100644 --- a/fs/bcachefs/six.c +++ b/fs/bcachefs/six.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -223,7 +224,12 @@ again: if (ret <= 0) goto unlock; - task = w->task; + /* + * Similar to percpu_rwsem_wake_function(), we need to guard + * against the wakee noticing w->lock_acquired, returning, and + * then exiting before we do the wakeup: + */ + task = get_task_struct(w->task); __list_del(w->list.prev, w->list.next); /* * The release barrier here ensures the ordering of the @@ -234,6 +240,7 @@ again: */ smp_store_release(&w->lock_acquired, true); wake_up_process(task); + put_task_struct(task); } six_clear_bitmask(lock, SIX_LOCK_WAITING_read << lock_type); -- cgit v1.2.3