Skip to content

Commit 952041a

Browse files
Peter ZijlstraIngo Molnar
authored andcommitted
tty/ldsem, locking/rwsem: Add missing ACQUIRE to read_failed sleep loop
While reviewing rwsem down_slowpath, Will noticed ldsem had a copy of a bug we just found for rwsem. X = 0; CPU0 CPU1 rwsem_down_read() for (;;) { set_current_state(TASK_UNINTERRUPTIBLE); X = 1; rwsem_up_write(); rwsem_mark_wake() atomic_long_add(adjustment, &sem->count); smp_store_release(&waiter->task, NULL); if (!waiter.task) break; ... } r = X; Allows 'r == 0'. Reported-by: Will Deacon <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Acked-by: Will Deacon <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Peter Hurley <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Fixes: 4898e64 ("tty: Add timed, writer-prioritized rw semaphore") Signed-off-by: Ingo Molnar <[email protected]>
1 parent 99143f8 commit 952041a

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

drivers/tty/tty_ldsem.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ static void __ldsem_wake_readers(struct ld_semaphore *sem)
9393

9494
list_for_each_entry_safe(waiter, next, &sem->read_wait, list) {
9595
tsk = waiter->task;
96-
smp_mb();
97-
waiter->task = NULL;
96+
smp_store_release(&waiter->task, NULL);
9897
wake_up_process(tsk);
9998
put_task_struct(tsk);
10099
}
@@ -194,7 +193,7 @@ down_read_failed(struct ld_semaphore *sem, long count, long timeout)
194193
for (;;) {
195194
set_current_state(TASK_UNINTERRUPTIBLE);
196195

197-
if (!waiter.task)
196+
if (!smp_load_acquire(&waiter.task))
198197
break;
199198
if (!timeout)
200199
break;

0 commit comments

Comments
 (0)