Commit f67a3356 authored by Paul E. McKenney's avatar Paul E. McKenney

rcutorture: Abstract torture_shutdown_absorb()

Because handling races between rmmod and normal shutdown is not specific
to rcutorture, this commit renames rcutorture_shutdown_absorb() to
torture_shutdown_absorb() and pulls it out into then kernel/torture.c
module.  This implies pulling the fullstop mechanism into kernel/torture.c
as well.

The exporting of fullstop and fullstop_mutex is ugly and must die.
And it does in fact die in later commits that introduce higher-level
APIs that encapsulate both of these variables.
Signed-off-by: default avatarPaul E. McKenney <paulmck@linux.vnet.ibm.com>
Reviewed-by: Josh Triplett <josh@joshtriplett.org>`
parent c2884de3
...@@ -41,6 +41,18 @@ ...@@ -41,6 +41,18 @@
module_param(name, type, 0444); \ module_param(name, type, 0444); \
MODULE_PARM_DESC(name, msg); MODULE_PARM_DESC(name, msg);
/* Mediate rmmod and system shutdown. Concurrent rmmod & shutdown illegal! */
#define FULLSTOP_DONTSTOP 0 /* Normal operation. */
#define FULLSTOP_SHUTDOWN 1 /* System shutdown with rcutorture running. */
#define FULLSTOP_RMMOD 2 /* Normal rmmod of rcutorture. */
extern int fullstop;
/* Protect fullstop transitions and spawning of kthreads. */
extern struct mutex fullstop_mutex;
/* Common module parameters. */
extern char *torture_type;
extern bool verbose;
#define TORTURE_FLAG "-torture:" #define TORTURE_FLAG "-torture:"
#define TOROUT_STRING(s) \ #define TOROUT_STRING(s) \
pr_alert("%s" TORTURE_FLAG s "\n", torture_type) pr_alert("%s" TORTURE_FLAG s "\n", torture_type)
...@@ -57,4 +69,7 @@ struct torture_random_state { ...@@ -57,4 +69,7 @@ struct torture_random_state {
#define DEFINE_TORTURE_RANDOM(name) struct torture_random_state name = { 0, 0 } #define DEFINE_TORTURE_RANDOM(name) struct torture_random_state name = { 0, 0 }
unsigned long torture_random(struct torture_random_state *trsp); unsigned long torture_random(struct torture_random_state *trsp);
/* Shutdown task absorption, for when the tasks cannot safely be killed. */
void torture_shutdown_absorb(const char *title);
#endif /* __LINUX_TORTURE_H */ #endif /* __LINUX_TORTURE_H */
...@@ -91,11 +91,15 @@ torture_param(int, test_boost_interval, 7, ...@@ -91,11 +91,15 @@ torture_param(int, test_boost_interval, 7,
"Interval between boost tests, seconds."); "Interval between boost tests, seconds.");
torture_param(bool, test_no_idle_hz, true, torture_param(bool, test_no_idle_hz, true,
"Test support for tickless idle CPUs"); "Test support for tickless idle CPUs");
torture_param(bool, verbose, false, "Enable verbose debugging printk()s");
static char *torture_type = "rcu"; char *torture_type = "rcu";
EXPORT_SYMBOL_GPL(torture_type);
module_param(torture_type, charp, 0444); module_param(torture_type, charp, 0444);
MODULE_PARM_DESC(torture_type, "Type of RCU to torture (rcu, rcu_bh, ...)"); MODULE_PARM_DESC(torture_type, "Type of RCU to torture (rcu, rcu_bh, ...)");
bool verbose;
EXPORT_SYMBOL_GPL(verbose);
module_param(verbose, bool, 0444);
MODULE_PARM_DESC(verbose, "Enable verbose debugging printk()s");
static int nrealreaders; static int nrealreaders;
static struct task_struct *writer_task; static struct task_struct *writer_task;
...@@ -200,17 +204,6 @@ static atomic_t barrier_cbs_invoked; /* Barrier callbacks invoked. */ ...@@ -200,17 +204,6 @@ static atomic_t barrier_cbs_invoked; /* Barrier callbacks invoked. */
static wait_queue_head_t *barrier_cbs_wq; /* Coordinate barrier testing. */ static wait_queue_head_t *barrier_cbs_wq; /* Coordinate barrier testing. */
static DECLARE_WAIT_QUEUE_HEAD(barrier_wq); static DECLARE_WAIT_QUEUE_HEAD(barrier_wq);
/* Mediate rmmod and system shutdown. Concurrent rmmod & shutdown illegal! */
#define FULLSTOP_DONTSTOP 0 /* Normal operation. */
#define FULLSTOP_SHUTDOWN 1 /* System shutdown with rcutorture running. */
#define FULLSTOP_RMMOD 2 /* Normal rmmod of rcutorture. */
static int fullstop = FULLSTOP_RMMOD;
/*
* Protect fullstop transitions and spawning of kthreads.
*/
static DEFINE_MUTEX(fullstop_mutex);
/* Forward reference. */ /* Forward reference. */
static void rcu_torture_cleanup(void); static void rcu_torture_cleanup(void);
...@@ -231,20 +224,6 @@ rcutorture_shutdown_notify(struct notifier_block *unused1, ...@@ -231,20 +224,6 @@ rcutorture_shutdown_notify(struct notifier_block *unused1,
return NOTIFY_DONE; return NOTIFY_DONE;
} }
/*
* Absorb kthreads into a kernel function that won't return, so that
* they won't ever access module text or data again.
*/
static void rcutorture_shutdown_absorb(const char *title)
{
if (ACCESS_ONCE(fullstop) == FULLSTOP_SHUTDOWN) {
pr_notice(
"rcutorture thread %s parking due to system shutdown\n",
title);
schedule_timeout_uninterruptible(MAX_SCHEDULE_TIMEOUT);
}
}
/* /*
* Allocate an element from the rcu_tortures pool. * Allocate an element from the rcu_tortures pool.
*/ */
...@@ -286,7 +265,7 @@ rcu_stutter_wait(const char *title) ...@@ -286,7 +265,7 @@ rcu_stutter_wait(const char *title)
schedule_timeout_interruptible(1); schedule_timeout_interruptible(1);
else else
schedule_timeout_interruptible(round_jiffies_relative(HZ)); schedule_timeout_interruptible(round_jiffies_relative(HZ));
rcutorture_shutdown_absorb(title); torture_shutdown_absorb(title);
} }
} }
...@@ -681,7 +660,7 @@ checkwait: rcu_stutter_wait("rcu_torture_boost"); ...@@ -681,7 +660,7 @@ checkwait: rcu_stutter_wait("rcu_torture_boost");
/* Clean up and exit. */ /* Clean up and exit. */
VERBOSE_TOROUT_STRING("rcu_torture_boost task stopping"); VERBOSE_TOROUT_STRING("rcu_torture_boost task stopping");
rcutorture_shutdown_absorb("rcu_torture_boost"); torture_shutdown_absorb("rcu_torture_boost");
while (!kthread_should_stop() || rbi.inflight) while (!kthread_should_stop() || rbi.inflight)
schedule_timeout_uninterruptible(1); schedule_timeout_uninterruptible(1);
smp_mb(); /* order accesses to ->inflight before stack-frame death. */ smp_mb(); /* order accesses to ->inflight before stack-frame death. */
...@@ -717,7 +696,7 @@ rcu_torture_fqs(void *arg) ...@@ -717,7 +696,7 @@ rcu_torture_fqs(void *arg)
rcu_stutter_wait("rcu_torture_fqs"); rcu_stutter_wait("rcu_torture_fqs");
} while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP); } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
VERBOSE_TOROUT_STRING("rcu_torture_fqs task stopping"); VERBOSE_TOROUT_STRING("rcu_torture_fqs task stopping");
rcutorture_shutdown_absorb("rcu_torture_fqs"); torture_shutdown_absorb("rcu_torture_fqs");
while (!kthread_should_stop()) while (!kthread_should_stop())
schedule_timeout_uninterruptible(1); schedule_timeout_uninterruptible(1);
return 0; return 0;
...@@ -789,7 +768,7 @@ rcu_torture_writer(void *arg) ...@@ -789,7 +768,7 @@ rcu_torture_writer(void *arg)
rcu_stutter_wait("rcu_torture_writer"); rcu_stutter_wait("rcu_torture_writer");
} while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP); } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
VERBOSE_TOROUT_STRING("rcu_torture_writer task stopping"); VERBOSE_TOROUT_STRING("rcu_torture_writer task stopping");
rcutorture_shutdown_absorb("rcu_torture_writer"); torture_shutdown_absorb("rcu_torture_writer");
while (!kthread_should_stop()) while (!kthread_should_stop())
schedule_timeout_uninterruptible(1); schedule_timeout_uninterruptible(1);
return 0; return 0;
...@@ -827,7 +806,7 @@ rcu_torture_fakewriter(void *arg) ...@@ -827,7 +806,7 @@ rcu_torture_fakewriter(void *arg)
} while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP); } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
VERBOSE_TOROUT_STRING("rcu_torture_fakewriter task stopping"); VERBOSE_TOROUT_STRING("rcu_torture_fakewriter task stopping");
rcutorture_shutdown_absorb("rcu_torture_fakewriter"); torture_shutdown_absorb("rcu_torture_fakewriter");
while (!kthread_should_stop()) while (!kthread_should_stop())
schedule_timeout_uninterruptible(1); schedule_timeout_uninterruptible(1);
return 0; return 0;
...@@ -971,7 +950,7 @@ rcu_torture_reader(void *arg) ...@@ -971,7 +950,7 @@ rcu_torture_reader(void *arg)
rcu_stutter_wait("rcu_torture_reader"); rcu_stutter_wait("rcu_torture_reader");
} while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP); } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
VERBOSE_TOROUT_STRING("rcu_torture_reader task stopping"); VERBOSE_TOROUT_STRING("rcu_torture_reader task stopping");
rcutorture_shutdown_absorb("rcu_torture_reader"); torture_shutdown_absorb("rcu_torture_reader");
if (irqreader && cur_ops->irq_capable) if (irqreader && cur_ops->irq_capable)
del_timer_sync(&t); del_timer_sync(&t);
while (!kthread_should_stop()) while (!kthread_should_stop())
...@@ -1095,7 +1074,7 @@ rcu_torture_stats(void *arg) ...@@ -1095,7 +1074,7 @@ rcu_torture_stats(void *arg)
do { do {
schedule_timeout_interruptible(stat_interval * HZ); schedule_timeout_interruptible(stat_interval * HZ);
rcu_torture_stats_print(); rcu_torture_stats_print();
rcutorture_shutdown_absorb("rcu_torture_stats"); torture_shutdown_absorb("rcu_torture_stats");
} while (!kthread_should_stop()); } while (!kthread_should_stop());
VERBOSE_TOROUT_STRING("rcu_torture_stats task stopping"); VERBOSE_TOROUT_STRING("rcu_torture_stats task stopping");
return 0; return 0;
...@@ -1179,7 +1158,7 @@ rcu_torture_shuffle(void *arg) ...@@ -1179,7 +1158,7 @@ rcu_torture_shuffle(void *arg)
do { do {
schedule_timeout_interruptible(shuffle_interval * HZ); schedule_timeout_interruptible(shuffle_interval * HZ);
rcu_torture_shuffle_tasks(); rcu_torture_shuffle_tasks();
rcutorture_shutdown_absorb("rcu_torture_shuffle"); torture_shutdown_absorb("rcu_torture_shuffle");
} while (!kthread_should_stop()); } while (!kthread_should_stop());
VERBOSE_TOROUT_STRING("rcu_torture_shuffle task stopping"); VERBOSE_TOROUT_STRING("rcu_torture_shuffle task stopping");
return 0; return 0;
...@@ -1198,7 +1177,7 @@ rcu_torture_stutter(void *arg) ...@@ -1198,7 +1177,7 @@ rcu_torture_stutter(void *arg)
if (!kthread_should_stop()) if (!kthread_should_stop())
schedule_timeout_interruptible(stutter * HZ); schedule_timeout_interruptible(stutter * HZ);
stutter_pause_test = 0; stutter_pause_test = 0;
rcutorture_shutdown_absorb("rcu_torture_stutter"); torture_shutdown_absorb("rcu_torture_stutter");
} while (!kthread_should_stop()); } while (!kthread_should_stop());
VERBOSE_TOROUT_STRING("rcu_torture_stutter task stopping"); VERBOSE_TOROUT_STRING("rcu_torture_stutter task stopping");
return 0; return 0;
...@@ -1470,7 +1449,7 @@ static int rcu_torture_stall(void *args) ...@@ -1470,7 +1449,7 @@ static int rcu_torture_stall(void *args)
rcu_read_unlock(); rcu_read_unlock();
pr_alert("rcu_torture_stall end.\n"); pr_alert("rcu_torture_stall end.\n");
} }
rcutorture_shutdown_absorb("rcu_torture_stall"); torture_shutdown_absorb("rcu_torture_stall");
while (!kthread_should_stop()) while (!kthread_should_stop())
schedule_timeout_interruptible(10 * HZ); schedule_timeout_interruptible(10 * HZ);
return 0; return 0;
...@@ -1534,7 +1513,7 @@ static int rcu_torture_barrier_cbs(void *arg) ...@@ -1534,7 +1513,7 @@ static int rcu_torture_barrier_cbs(void *arg)
wake_up(&barrier_wq); wake_up(&barrier_wq);
} while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP); } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
VERBOSE_TOROUT_STRING("rcu_torture_barrier_cbs task stopping"); VERBOSE_TOROUT_STRING("rcu_torture_barrier_cbs task stopping");
rcutorture_shutdown_absorb("rcu_torture_barrier_cbs"); torture_shutdown_absorb("rcu_torture_barrier_cbs");
while (!kthread_should_stop()) while (!kthread_should_stop())
schedule_timeout_interruptible(1); schedule_timeout_interruptible(1);
cur_ops->cb_barrier(); cur_ops->cb_barrier();
...@@ -1571,7 +1550,7 @@ static int rcu_torture_barrier(void *arg) ...@@ -1571,7 +1550,7 @@ static int rcu_torture_barrier(void *arg)
schedule_timeout_interruptible(HZ / 10); schedule_timeout_interruptible(HZ / 10);
} while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP); } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
VERBOSE_TOROUT_STRING("rcu_torture_barrier task stopping"); VERBOSE_TOROUT_STRING("rcu_torture_barrier task stopping");
rcutorture_shutdown_absorb("rcu_torture_barrier"); torture_shutdown_absorb("rcu_torture_barrier");
while (!kthread_should_stop()) while (!kthread_should_stop())
schedule_timeout_interruptible(1); schedule_timeout_interruptible(1);
return 0; return 0;
......
...@@ -49,6 +49,11 @@ ...@@ -49,6 +49,11 @@
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
MODULE_AUTHOR("Paul E. McKenney <paulmck@us.ibm.com>"); MODULE_AUTHOR("Paul E. McKenney <paulmck@us.ibm.com>");
int fullstop = FULLSTOP_RMMOD;
EXPORT_SYMBOL_GPL(fullstop);
DEFINE_MUTEX(fullstop_mutex);
EXPORT_SYMBOL_GPL(fullstop_mutex);
#define TORTURE_RANDOM_MULT 39916801 /* prime */ #define TORTURE_RANDOM_MULT 39916801 /* prime */
#define TORTURE_RANDOM_ADD 479001701 /* prime */ #define TORTURE_RANDOM_ADD 479001701 /* prime */
#define TORTURE_RANDOM_REFRESH 10000 #define TORTURE_RANDOM_REFRESH 10000
...@@ -69,3 +74,18 @@ torture_random(struct torture_random_state *trsp) ...@@ -69,3 +74,18 @@ torture_random(struct torture_random_state *trsp)
return swahw32(trsp->trs_state); return swahw32(trsp->trs_state);
} }
EXPORT_SYMBOL_GPL(torture_random); EXPORT_SYMBOL_GPL(torture_random);
/*
* Absorb kthreads into a kernel function that won't return, so that
* they won't ever access module text or data again.
*/
void torture_shutdown_absorb(const char *title)
{
while (ACCESS_ONCE(fullstop) == FULLSTOP_SHUTDOWN) {
pr_notice(
"torture thread %s parking due to system shutdown\n",
title);
schedule_timeout_uninterruptible(MAX_SCHEDULE_TIMEOUT);
}
}
EXPORT_SYMBOL_GPL(torture_shutdown_absorb);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment