public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Paul E. McKenney" <paulmck@kernel.org>
To: rcu@vger.kernel.org, Joel Fernandes <joelagnelf@nvidia.com>
Cc: linux-kernel@vger.kernel.org, kernel-team@meta.com,
	rostedt@goodmis.org, "Paul E. McKenney" <paulmck@kernel.org>,
	kernel test robot <oliver.sang@intel.com>
Subject: [PATCH v2 09/12] rcutorture: Check for ->up_read() without matching ->down_read()
Date: Mon, 31 Mar 2025 14:03:11 -0700	[thread overview]
Message-ID: <20250331210314.590622-9-paulmck@kernel.org> (raw)
In-Reply-To: <eea8d42f-6d2d-485b-9bb9-4eb77a0e1f95@paulmck-laptop>

This commit creates counters in the rcu_torture_one_read_state_updown
structure that check for a call to ->up_read() that lacks a matching
call to ->down_read().

While in the area, add end-of-run cleanup code that prevents calls to
rcu_torture_updown_hrt() from happening after the test has moved on.  Yes,
the srcu_barrier() at the end of the test will wait for them, but this
could result in confusing states, statistics, and diagnostic information.
So explicitly wait for them before we get to the end-of-test output.

[ paulmck: Apply kernel test robot feedback. ]

Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
Tested-by: kernel test robot <oliver.sang@intel.com>
---
 kernel/rcu/rcutorture.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
index d2728e95a69b1..079e164c85a16 100644
--- a/kernel/rcu/rcutorture.c
+++ b/kernel/rcu/rcutorture.c
@@ -2439,6 +2439,8 @@ struct rcu_torture_one_read_state_updown {
 	struct hrtimer rtorsu_hrt;
 	bool rtorsu_inuse;
 	unsigned long rtorsu_j;
+	unsigned long rtorsu_ndowns;
+	unsigned long rtorsu_nups;
 	struct torture_random_state rtorsu_trs;
 	struct rcu_torture_one_read_state rtorsu_rtors;
 };
@@ -2453,6 +2455,8 @@ static enum hrtimer_restart rcu_torture_updown_hrt(struct hrtimer *hrtp)
 
 	rtorsup = container_of(hrtp, struct rcu_torture_one_read_state_updown, rtorsu_hrt);
 	rcu_torture_one_read_end(&rtorsup->rtorsu_rtors, &rtorsup->rtorsu_trs, -1);
+	WARN_ONCE(rtorsup->rtorsu_nups >= rtorsup->rtorsu_ndowns, "%s: Up without matching down #%zu.\n", __func__, rtorsup - updownreaders);
+	rtorsup->rtorsu_nups++;
 	smp_store_release(&rtorsup->rtorsu_inuse, false);
 	return HRTIMER_NORESTART;
 }
@@ -2498,8 +2502,12 @@ static void rcu_torture_updown_cleanup(void)
 	for (rtorsup = updownreaders; rtorsup < &updownreaders[n_up_down]; rtorsup++) {
 		if (!smp_load_acquire(&rtorsup->rtorsu_inuse))
 			continue;
-		if (!hrtimer_cancel(&rtorsup->rtorsu_hrt))
-			WARN_ON_ONCE(rtorsup->rtorsu_inuse);
+		if (hrtimer_cancel(&rtorsup->rtorsu_hrt) || WARN_ON_ONCE(rtorsup->rtorsu_inuse)) {
+			rcu_torture_one_read_end(&rtorsup->rtorsu_rtors, &rtorsup->rtorsu_trs, -1);
+			WARN_ONCE(rtorsup->rtorsu_nups >= rtorsup->rtorsu_ndowns, "%s: Up without matching down #%zu.\n", __func__, rtorsup - updownreaders);
+			rtorsup->rtorsu_nups++;
+			smp_store_release(&rtorsup->rtorsu_inuse, false);
+		}
 
 	}
 	kfree(updownreaders);
@@ -2515,11 +2523,14 @@ static void rcu_torture_updown_one(struct rcu_torture_one_read_state_updown *rto
 
 	init_rcu_torture_one_read_state(&rtorsup->rtorsu_rtors, &rtorsup->rtorsu_trs);
 	rawidx = cur_ops->down_read();
+	rtorsup->rtorsu_ndowns++;
 	idx = (rawidx << RCUTORTURE_RDR_SHIFT_1) & RCUTORTURE_RDR_MASK_1;
 	rtorsup->rtorsu_rtors.readstate = idx | RCUTORTURE_RDR_UPDOWN;
 	rtorsup->rtorsu_rtors.rtrsp++;
 	if (!rcu_torture_one_read_start(&rtorsup->rtorsu_rtors, &rtorsup->rtorsu_trs, -1)) {
 		cur_ops->up_read(rawidx);
+		rtorsup->rtorsu_nups++;
+		WARN_ONCE(rtorsup->rtorsu_nups >= rtorsup->rtorsu_ndowns, "%s: Up without matching down #%zu.\n", __func__, rtorsup - updownreaders);
 		schedule_timeout_idle(HZ);
 		return;
 	}
-- 
2.40.1


  parent reply	other threads:[~2025-03-31 21:03 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-31 21:02 [PATCH v2 0/12] Paul E. McKenney
2025-03-31 21:03 ` [PATCH v2 01/12] rcutorture: Make srcu_lockdep.sh check kernel Kconfig Paul E. McKenney
2025-03-31 21:03 ` [PATCH v2 02/12] rcutorture: Make srcu_lockdep.sh check reader-conflict handling Paul E. McKenney
2025-03-31 21:03 ` [PATCH v2 03/12] rcutorture: Split out beginning and end from rcu_torture_one_read() Paul E. McKenney
2025-03-31 21:03 ` [PATCH v2 04/12] rcutorture: Make torture.sh --do-rt use CONFIG_PREEMPT_RT Paul E. McKenney
2025-04-02  7:42   ` Sebastian Andrzej Siewior
2025-04-02 18:51     ` Paul E. McKenney
2025-04-07 19:12   ` [PATCH v3 4/12] " Paul E. McKenney
2025-04-08 14:29     ` [v3,4/12] " Joel Fernandes
2025-04-08 16:20       ` Paul E. McKenney
2025-03-31 21:03 ` [PATCH v2 05/12] rcutorture: Add tests for SRCU up/down reader primitives Paul E. McKenney
2025-04-08 20:18   ` [v2,05/12] " Joel Fernandes
2025-04-08 20:58     ` Paul E. McKenney
2025-04-08 22:05       ` Joel Fernandes
2025-04-08 22:21         ` Paul E. McKenney
2025-04-15 17:16   ` [PATCH v2 05/12] " Joel Fernandes
2025-04-15 17:59     ` Paul E. McKenney
2025-04-15 21:15       ` Paul E. McKenney
2025-04-16  1:14         ` Joel Fernandes
2025-04-16  3:55           ` Paul E. McKenney
2025-03-31 21:03 ` [PATCH v2 06/12] rcutorture: Pull rcu_torture_updown() loop body into new function Paul E. McKenney
2025-03-31 21:03 ` [PATCH v2 07/12] rcutorture: Comment invocations of tick_dep_set_task() Paul E. McKenney
2025-03-31 21:03 ` [PATCH v2 08/12] rcutorture: Complain if an ->up_read() is delayed more than 10 seconds Paul E. McKenney
2025-03-31 21:03 ` Paul E. McKenney [this message]
2025-03-31 21:03 ` [PATCH v2 10/12] checkpatch: Deprecate srcu_read_lock_lite() and srcu_read_unlock_lite() Paul E. McKenney
2025-04-01  6:53   ` Joe Perches
2025-04-01 14:05     ` Paul E. McKenney
2025-04-02  3:48       ` Joe Perches
2025-04-02  4:23         ` Paul E. McKenney
2025-04-02  4:49           ` Joe Perches
2025-04-02 14:12             ` Paul E. McKenney
2025-03-31 21:03 ` [PATCH v2 11/12] torture: Add --do-{,no-}normal to torture.sh Paul E. McKenney
2025-03-31 21:03 ` [PATCH v2 12/12] torture: Add testing of RCU's Rust bindings " Paul E. McKenney
2025-04-02 14:45 ` [PATCH v2 0/12] Joel Fernandes

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=20250331210314.590622-9-paulmck@kernel.org \
    --to=paulmck@kernel.org \
    --cc=joelagnelf@nvidia.com \
    --cc=kernel-team@meta.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oliver.sang@intel.com \
    --cc=rcu@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    /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