mirror of
git://git.yoctoproject.org/linux-yocto.git
synced 2025-07-06 05:45:29 +02:00
rcu: Eliminate lockless accesses to rcu_sync->gp_count
The rcu_sync structure's ->gp_count field is always accessed under the protection of that same structure's ->rss_lock field, with the exception of a pair of WARN_ON_ONCE() calls just prior to acquiring that lock in functions rcu_sync_exit() and rcu_sync_dtor(). These lockless accesses are unnecessary and impair KCSAN's ability to catch bugs that might be inserted via other lockless accesses. This commit therefore moves those WARN_ON_ONCE() calls under the lock. Signed-off-by: Oleg Nesterov <oleg@redhat.com> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
This commit is contained in:
parent
7f09e70f9e
commit
6f4cec22c3
|
@ -122,7 +122,7 @@ void rcu_sync_enter(struct rcu_sync *rsp)
|
||||||
* we are called at early boot time but this shouldn't happen.
|
* we are called at early boot time but this shouldn't happen.
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
WRITE_ONCE(rsp->gp_count, rsp->gp_count + 1);
|
rsp->gp_count++;
|
||||||
spin_unlock_irq(&rsp->rss_lock);
|
spin_unlock_irq(&rsp->rss_lock);
|
||||||
|
|
||||||
if (gp_state == GP_IDLE) {
|
if (gp_state == GP_IDLE) {
|
||||||
|
@ -151,15 +151,11 @@ void rcu_sync_enter(struct rcu_sync *rsp)
|
||||||
*/
|
*/
|
||||||
void rcu_sync_exit(struct rcu_sync *rsp)
|
void rcu_sync_exit(struct rcu_sync *rsp)
|
||||||
{
|
{
|
||||||
int gpc;
|
|
||||||
|
|
||||||
WARN_ON_ONCE(READ_ONCE(rsp->gp_state) == GP_IDLE);
|
WARN_ON_ONCE(READ_ONCE(rsp->gp_state) == GP_IDLE);
|
||||||
WARN_ON_ONCE(READ_ONCE(rsp->gp_count) == 0);
|
|
||||||
|
|
||||||
spin_lock_irq(&rsp->rss_lock);
|
spin_lock_irq(&rsp->rss_lock);
|
||||||
gpc = rsp->gp_count - 1;
|
WARN_ON_ONCE(rsp->gp_count == 0);
|
||||||
WRITE_ONCE(rsp->gp_count, gpc);
|
if (!--rsp->gp_count) {
|
||||||
if (!gpc) {
|
|
||||||
if (rsp->gp_state == GP_PASSED) {
|
if (rsp->gp_state == GP_PASSED) {
|
||||||
WRITE_ONCE(rsp->gp_state, GP_EXIT);
|
WRITE_ONCE(rsp->gp_state, GP_EXIT);
|
||||||
rcu_sync_call(rsp);
|
rcu_sync_call(rsp);
|
||||||
|
@ -178,10 +174,10 @@ void rcu_sync_dtor(struct rcu_sync *rsp)
|
||||||
{
|
{
|
||||||
int gp_state;
|
int gp_state;
|
||||||
|
|
||||||
WARN_ON_ONCE(READ_ONCE(rsp->gp_count));
|
|
||||||
WARN_ON_ONCE(READ_ONCE(rsp->gp_state) == GP_PASSED);
|
WARN_ON_ONCE(READ_ONCE(rsp->gp_state) == GP_PASSED);
|
||||||
|
|
||||||
spin_lock_irq(&rsp->rss_lock);
|
spin_lock_irq(&rsp->rss_lock);
|
||||||
|
WARN_ON_ONCE(rsp->gp_count);
|
||||||
if (rsp->gp_state == GP_REPLAY)
|
if (rsp->gp_state == GP_REPLAY)
|
||||||
WRITE_ONCE(rsp->gp_state, GP_EXIT);
|
WRITE_ONCE(rsp->gp_state, GP_EXIT);
|
||||||
gp_state = rsp->gp_state;
|
gp_state = rsp->gp_state;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user