Skip to content

Commit 57f6020

Browse files
committed
rcutorture: Properly synchronize with OOM notifier
The current rcutorture forward-progress code assumes that it is the only cause of out-of-memory (OOM) events. For script-based rcutorture testing, this assumption is in fact correct. However, testing based on modprobe/rmmod might well encounter external OOM events, which could happen at any time. This commit therefore properly synchronizes the interaction between rcutorture's forward-progress testing and its OOM notifier by adding a global mutex. Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
1 parent c8fa637 commit 57f6020

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

kernel/rcu/rcutorture.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1796,6 +1796,7 @@ struct rcu_fwd {
17961796
unsigned long rcu_launder_gp_seq_start;
17971797
};
17981798

1799+
static DEFINE_MUTEX(rcu_fwd_mutex);
17991800
static struct rcu_fwd *rcu_fwds;
18001801
static bool rcu_fwd_emergency_stop;
18011802

@@ -2062,8 +2063,14 @@ static void rcu_torture_fwd_prog_cr(struct rcu_fwd *rfp)
20622063
static int rcutorture_oom_notify(struct notifier_block *self,
20632064
unsigned long notused, void *nfreed)
20642065
{
2065-
struct rcu_fwd *rfp = rcu_fwds;
2066+
struct rcu_fwd *rfp;
20662067

2068+
mutex_lock(&rcu_fwd_mutex);
2069+
rfp = rcu_fwds;
2070+
if (!rfp) {
2071+
mutex_unlock(&rcu_fwd_mutex);
2072+
return NOTIFY_OK;
2073+
}
20672074
WARN(1, "%s invoked upon OOM during forward-progress testing.\n",
20682075
__func__);
20692076
rcu_torture_fwd_cb_hist(rfp);
@@ -2081,6 +2088,7 @@ static int rcutorture_oom_notify(struct notifier_block *self,
20812088
smp_mb(); /* Frees before return to avoid redoing OOM. */
20822089
(*(unsigned long *)nfreed)++; /* Forward progress CBs freed! */
20832090
pr_info("%s returning after OOM processing.\n", __func__);
2091+
mutex_unlock(&rcu_fwd_mutex);
20842092
return NOTIFY_OK;
20852093
}
20862094

@@ -2148,7 +2156,9 @@ static int __init rcu_torture_fwd_prog_init(void)
21482156
return -ENOMEM;
21492157
spin_lock_init(&rfp->rcu_fwd_lock);
21502158
rfp->rcu_fwd_cb_tail = &rfp->rcu_fwd_cb_head;
2159+
mutex_lock(&rcu_fwd_mutex);
21512160
rcu_fwds = rfp;
2161+
mutex_unlock(&rcu_fwd_mutex);
21522162
return torture_create_kthread(rcu_torture_fwd_prog, rfp, fwd_prog_task);
21532163
}
21542164

@@ -2158,7 +2168,9 @@ static void rcu_torture_fwd_prog_cleanup(void)
21582168

21592169
torture_stop_kthread(rcu_torture_fwd_prog, fwd_prog_task);
21602170
rfp = rcu_fwds;
2171+
mutex_lock(&rcu_fwd_mutex);
21612172
rcu_fwds = NULL;
2173+
mutex_unlock(&rcu_fwd_mutex);
21622174
kfree(rfp);
21632175
}
21642176

0 commit comments

Comments
 (0)