From: paulmck@kernel.org
To: rcu@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, kernel-team@fb.com,
mingo@kernel.org, jiangshanlai@gmail.com,
akpm@linux-foundation.org, mathieu.desnoyers@efficios.com,
josh@joshtriplett.org, tglx@linutronix.de, peterz@infradead.org,
rostedt@goodmis.org, dhowells@redhat.com, edumazet@google.com,
fweisbec@gmail.com, oleg@redhat.com, joel@joelfernandes.org,
Hou Tao <houtao1@huawei.com>,
"Paul E . McKenney" <paulmck@kernel.org>
Subject: [PATCH tip/core/rcu 23/28] locktorture: Invoke percpu_free_rwsem() to do percpu-rwsem cleanup
Date: Thu, 5 Nov 2020 15:47:14 -0800 [thread overview]
Message-ID: <20201105234719.23307-23-paulmck@kernel.org> (raw)
In-Reply-To: <20201105234658.GA23142@paulmck-ThinkPad-P72>
From: Hou Tao <houtao1@huawei.com>
When executing the LOCK06 locktorture scenario featuring percpu-rwsem,
the RCU callback rcu_sync_func() may still be pending after locktorture
module is removed. This can in turn lead to the following Oops:
BUG: unable to handle page fault for address: ffffffffc00eb920
#PF: supervisor read access in kernel mode
#PF: error_code(0x0000) - not-present page
PGD 6500a067 P4D 6500a067 PUD 6500c067 PMD 13a36c067 PTE 800000013691c163
Oops: 0000 [#1] PREEMPT SMP
CPU: 1 PID: 0 Comm: swapper/1 Not tainted 5.9.0-rc5+ #4
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996)
RIP: 0010:rcu_cblist_dequeue+0x12/0x30
Call Trace:
<IRQ>
rcu_core+0x1b1/0x860
__do_softirq+0xfe/0x326
asm_call_on_stack+0x12/0x20
</IRQ>
do_softirq_own_stack+0x5f/0x80
irq_exit_rcu+0xaf/0xc0
sysvec_apic_timer_interrupt+0x2e/0xb0
asm_sysvec_apic_timer_interrupt+0x12/0x20
This commit avoids tis problem by adding an exit hook in lock_torture_ops
and using it to call percpu_free_rwsem() for percpu rwsem torture during
the module-cleanup function, thus ensuring that rcu_sync_func() completes
before module exits.
It is also necessary to call the exit hook if lock_torture_init()
fails half-way, so this commit also adds an ->init_called field in
lock_torture_cxt to indicate that exit hook, if present, must be called.
Signed-off-by: Hou Tao <houtao1@huawei.com>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
---
kernel/locking/locktorture.c | 26 +++++++++++++++++++++-----
1 file changed, 21 insertions(+), 5 deletions(-)
diff --git a/kernel/locking/locktorture.c b/kernel/locking/locktorture.c
index 79fbd97..fd838ce 100644
--- a/kernel/locking/locktorture.c
+++ b/kernel/locking/locktorture.c
@@ -76,6 +76,7 @@ static void lock_torture_cleanup(void);
*/
struct lock_torture_ops {
void (*init)(void);
+ void (*exit)(void);
int (*writelock)(void);
void (*write_delay)(struct torture_random_state *trsp);
void (*task_boost)(struct torture_random_state *trsp);
@@ -92,12 +93,13 @@ struct lock_torture_cxt {
int nrealwriters_stress;
int nrealreaders_stress;
bool debug_lock;
+ bool init_called;
atomic_t n_lock_torture_errors;
struct lock_torture_ops *cur_ops;
struct lock_stress_stats *lwsa; /* writer statistics */
struct lock_stress_stats *lrsa; /* reader statistics */
};
-static struct lock_torture_cxt cxt = { 0, 0, false,
+static struct lock_torture_cxt cxt = { 0, 0, false, false,
ATOMIC_INIT(0),
NULL, NULL};
/*
@@ -573,6 +575,11 @@ static void torture_percpu_rwsem_init(void)
BUG_ON(percpu_init_rwsem(&pcpu_rwsem));
}
+static void torture_percpu_rwsem_exit(void)
+{
+ percpu_free_rwsem(&pcpu_rwsem);
+}
+
static int torture_percpu_rwsem_down_write(void) __acquires(pcpu_rwsem)
{
percpu_down_write(&pcpu_rwsem);
@@ -597,6 +604,7 @@ static void torture_percpu_rwsem_up_read(void) __releases(pcpu_rwsem)
static struct lock_torture_ops percpu_rwsem_lock_ops = {
.init = torture_percpu_rwsem_init,
+ .exit = torture_percpu_rwsem_exit,
.writelock = torture_percpu_rwsem_down_write,
.write_delay = torture_rwsem_write_delay,
.task_boost = torture_boost_dummy,
@@ -789,9 +797,10 @@ static void lock_torture_cleanup(void)
/*
* Indicates early cleanup, meaning that the test has not run,
- * such as when passing bogus args when loading the module. As
- * such, only perform the underlying torture-specific cleanups,
- * and avoid anything related to locktorture.
+ * such as when passing bogus args when loading the module.
+ * However cxt->cur_ops.init() may have been invoked, so beside
+ * perform the underlying torture-specific cleanups, cur_ops.exit()
+ * will be invoked if needed.
*/
if (!cxt.lwsa && !cxt.lrsa)
goto end;
@@ -831,6 +840,11 @@ static void lock_torture_cleanup(void)
cxt.lrsa = NULL;
end:
+ if (cxt.init_called) {
+ if (cxt.cur_ops->exit)
+ cxt.cur_ops->exit();
+ cxt.init_called = false;
+ }
torture_cleanup_end();
}
@@ -878,8 +892,10 @@ static int __init lock_torture_init(void)
goto unwind;
}
- if (cxt.cur_ops->init)
+ if (cxt.cur_ops->init) {
cxt.cur_ops->init();
+ cxt.init_called = true;
+ }
if (nwriters_stress >= 0)
cxt.nrealwriters_stress = nwriters_stress;
--
2.9.5
next prev parent reply other threads:[~2020-11-05 23:48 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-05 23:46 [PATCH tip/core/rcu 0/28] Torture-test updates for v5.11 Paul E. McKenney
2020-11-05 23:46 ` [PATCH tip/core/rcu 01/28] refscale: Bounds-check module parameters paulmck
2020-11-05 23:46 ` [PATCH tip/core/rcu 02/28] torture: Don't kill gdb sessions paulmck
2020-11-05 23:46 ` [PATCH tip/core/rcu 03/28] locktorture: Track time of last ->writeunlock() paulmck
2020-11-06 6:56 ` Davidlohr Bueso
2020-11-06 19:13 ` Paul E. McKenney
2020-11-05 23:46 ` [PATCH tip/core/rcu 04/28] torture: Periodically pause in stutter_wait() paulmck
2020-11-05 23:46 ` [PATCH tip/core/rcu 05/28] torture: Make torture_stutter() use hrtimer paulmck
2020-11-05 23:46 ` [PATCH tip/core/rcu 06/28] scftorture: Add an alternative IPI vector paulmck
2020-11-05 23:46 ` [PATCH tip/core/rcu 07/28] rcuscale: Add RCU Tasks Trace paulmck
2020-11-05 23:46 ` [PATCH tip/core/rcu 08/28] rcuscale: Avoid divide by zero paulmck
2020-11-05 23:47 ` [PATCH tip/core/rcu 09/28] torture: Exclude "NOHZ tick-stop error" from fatal errors paulmck
2020-11-05 23:47 ` [PATCH tip/core/rcu 10/28] rcuscale: Prevent hangs for invalid arguments paulmck
2020-11-05 23:47 ` [PATCH tip/core/rcu 11/28] refscale: " paulmck
2020-11-05 23:47 ` [PATCH tip/core/rcu 12/28] rcutorture: Adjust scenarios SRCU-t and SRCU-u to make kconfig happy paulmck
2020-11-05 23:47 ` [PATCH tip/core/rcu 13/28] locktorture: Ignore nreaders_stress if no readlock support paulmck
2020-11-05 23:47 ` [PATCH tip/core/rcu 14/28] locktorture: Prevent hangs for invalid arguments paulmck
2020-11-05 23:47 ` [PATCH tip/core/rcu 15/28] torture: Prevent jitter processes from delaying failed run paulmck
2020-11-05 23:47 ` [PATCH tip/core/rcu 16/28] rcutorture: Prevent hangs for invalid arguments paulmck
2020-11-05 23:47 ` [PATCH tip/core/rcu 17/28] torture: Force weak-hashed pointers on console log paulmck
2020-11-05 23:47 ` [PATCH tip/core/rcu 18/28] rcutorture: Make stutter_wait() caller restore priority paulmck
2020-11-05 23:47 ` [PATCH tip/core/rcu 19/28] torture: Accept time units on kvm.sh --duration argument paulmck
2020-11-05 23:47 ` [PATCH tip/core/rcu 20/28] rcutorture: Small code cleanups paulmck
2020-11-05 23:47 ` [PATCH tip/core/rcu 21/28] torture: Allow alternative forms of kvm.sh command-line arguments paulmck
2020-11-05 23:47 ` [PATCH tip/core/rcu 22/28] scftorture: Add full-test stutter capability paulmck
2020-11-05 23:47 ` paulmck [this message]
2020-11-05 23:47 ` [PATCH tip/core/rcu 24/28] rcutorture: Don't do need_resched() testing if ->sync is NULL paulmck
2020-11-05 23:47 ` [PATCH tip/core/rcu 25/28] rcutorture/nolibc: Fix a typo in header file paulmck
2020-11-05 23:47 ` [PATCH tip/core/rcu 26/28] torture: Make kvm-check-branches.sh use --allcpus paulmck
2020-11-05 23:47 ` [PATCH tip/core/rcu 27/28] tools/nolibc: Fix a spelling error in a comment paulmck
2020-11-05 23:47 ` [PATCH tip/core/rcu 28/28] tools/rcutorture: Fix BUG parsing of console.log paulmck
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201105234719.23307-23-paulmck@kernel.org \
--to=paulmck@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=dhowells@redhat.com \
--cc=edumazet@google.com \
--cc=fweisbec@gmail.com \
--cc=houtao1@huawei.com \
--cc=jiangshanlai@gmail.com \
--cc=joel@joelfernandes.org \
--cc=josh@joshtriplett.org \
--cc=kernel-team@fb.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=mingo@kernel.org \
--cc=oleg@redhat.com \
--cc=peterz@infradead.org \
--cc=rcu@vger.kernel.org \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox