[PATCH 2/2] locking/rwsem: add preempt_disable/enable for spin region

From: Yanfei Xu
Date: Mon Sep 27 2021 - 12:40:04 EST


The rwsem_optimistic_spin() invokes the rwsem_spin_on_owner() with
preemption disabled, but rwsem_down_write_slowpath() doesn't. Because
the spin region should not be preempted, add preempt_disable/enable()
in rwsem_spin_on_owner().

Signed-off-by: Yanfei Xu <yanfei.xu@xxxxxxxxxxxxx>
---
kernel/locking/rwsem.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/kernel/locking/rwsem.c b/kernel/locking/rwsem.c
index 2907f9d8e4a6..db3a6a06a9c8 100644
--- a/kernel/locking/rwsem.c
+++ b/kernel/locking/rwsem.c
@@ -674,6 +674,7 @@ rwsem_spin_on_owner(struct rw_semaphore *sem)
if (state != OWNER_WRITER)
return state;

+ preempt_disable();
rcu_read_lock();
for (;;) {
/*
@@ -704,6 +705,7 @@ rwsem_spin_on_owner(struct rw_semaphore *sem)
cpu_relax();
}
rcu_read_unlock();
+ preempt_enable();

return state;
}
--
2.27.0