Skip to content

Commit 39e7234

Browse files
Waiman-LongPeter Zijlstra
authored andcommitted
locking/rwsem: Fix kernel crash when spinning on RWSEM_OWNER_UNKNOWN
The commit 91d2a81 ("locking/rwsem: Make handoff writer optimistically spin on owner") will allow a recently woken up waiting writer to spin on the owner. Unfortunately, if the owner happens to be RWSEM_OWNER_UNKNOWN, the code will incorrectly spin on it leading to a kernel crash. This is fixed by passing the proper non-spinnable bits to rwsem_spin_on_owner() so that RWSEM_OWNER_UNKNOWN will be treated as a non-spinnable target. Fixes: 91d2a81 ("locking/rwsem: Make handoff writer optimistically spin on owner") Reported-by: Christoph Hellwig <[email protected]> Signed-off-by: Waiman Long <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Tested-by: Christoph Hellwig <[email protected]> Cc: [email protected] Link: https://lkml.kernel.org/r/[email protected]
1 parent 51bfb1d commit 39e7234

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

kernel/locking/rwsem.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,8 +1226,8 @@ rwsem_down_write_slowpath(struct rw_semaphore *sem, int state)
12261226
* In this case, we attempt to acquire the lock again
12271227
* without sleeping.
12281228
*/
1229-
if ((wstate == WRITER_HANDOFF) &&
1230-
(rwsem_spin_on_owner(sem, 0) == OWNER_NULL))
1229+
if (wstate == WRITER_HANDOFF &&
1230+
rwsem_spin_on_owner(sem, RWSEM_NONSPINNABLE) == OWNER_NULL)
12311231
goto trylock_again;
12321232

12331233
/* Block until there are no active lockers. */

0 commit comments

Comments
 (0)