Linux RCU subsystem development
 help / color / mirror / Atom feed
* [PATCH v2 08/14] rcuscale: Rename kfree_rcu() to kfree_rcu_mightsleep()
       [not found] <20230315181902.4177819-1-joel@joelfernandes.org>
@ 2023-03-15 18:18 ` Joel Fernandes (Google)
  2023-03-15 18:18 ` [PATCH v2 09/14] torture: Enable clocksource watchdog with "tsc=watchdog" Joel Fernandes (Google)
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 6+ messages in thread
From: Joel Fernandes (Google) @ 2023-03-15 18:18 UTC (permalink / raw)
  To: Davidlohr Bueso, Paul E. McKenney, Josh Triplett,
	Frederic Weisbecker, Neeraj Upadhyay, Steven Rostedt,
	Mathieu Desnoyers, Lai Jiangshan, Joel Fernandes
  Cc: Uladzislau Rezki (Sony), linux-kernel, rcu

From: "Uladzislau Rezki (Sony)" <urezki@gmail.com>

The kfree_rcu() and kvfree_rcu() macros' single-argument forms are
deprecated.  Therefore switch to the new kfree_rcu_mightsleep() and
kvfree_rcu_mightsleep() variants. The goal is to avoid accidental use
of the single-argument forms, which can introduce functionality bugs in
atomic contexts and latency bugs in non-atomic contexts.

Signed-off-by: Uladzislau Rezki (Sony) <urezki@gmail.com>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
Signed-off-by: Joel Fernandes (Google) <joel@joelfernandes.org>
---
 kernel/rcu/rcuscale.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/rcu/rcuscale.c b/kernel/rcu/rcuscale.c
index 91fb5905a008..98b75995b680 100644
--- a/kernel/rcu/rcuscale.c
+++ b/kernel/rcu/rcuscale.c
@@ -716,7 +716,7 @@ kfree_scale_thread(void *arg)
 			// is tested.
 			if ((kfree_rcu_test_single && !kfree_rcu_test_double) ||
 					(kfree_rcu_test_both && torture_random(&tr) & 0x800))
-				kfree_rcu(alloc_ptr);
+				kfree_rcu_mightsleep(alloc_ptr);
 			else
 				kfree_rcu(alloc_ptr, rh);
 		}
-- 
2.40.0.rc1.284.g88254d51c5-goog


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 09/14] torture: Enable clocksource watchdog with "tsc=watchdog"
       [not found] <20230315181902.4177819-1-joel@joelfernandes.org>
  2023-03-15 18:18 ` [PATCH v2 08/14] rcuscale: Rename kfree_rcu() to kfree_rcu_mightsleep() Joel Fernandes (Google)
@ 2023-03-15 18:18 ` Joel Fernandes (Google)
  2023-03-15 18:18 ` [PATCH v2 10/14] rcutorture: Create nocb kthreads only when testing rcu in CONFIG_RCU_NOCB_CPU=y kernels Joel Fernandes (Google)
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 6+ messages in thread
From: Joel Fernandes (Google) @ 2023-03-15 18:18 UTC (permalink / raw)
  To: Paul E. McKenney, Josh Triplett, Steven Rostedt,
	Mathieu Desnoyers, Lai Jiangshan, Shuah Khan
  Cc: Joel Fernandes, rcu, linux-kselftest, linux-kernel

From: "Paul E. McKenney" <paulmck@kernel.org>

This commit tests the "tsc=watchdog" kernel boot parameter when running
the clocksourcewd torture tests.

Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
Signed-off-by: Joel Fernandes (Google) <joel@joelfernandes.org>
---
 tools/testing/selftests/rcutorture/bin/torture.sh | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/rcutorture/bin/torture.sh b/tools/testing/selftests/rcutorture/bin/torture.sh
index 130d0de4c3bb..5a2ae2264403 100755
--- a/tools/testing/selftests/rcutorture/bin/torture.sh
+++ b/tools/testing/selftests/rcutorture/bin/torture.sh
@@ -497,16 +497,16 @@ fi
 
 if test "$do_clocksourcewd" = "yes"
 then
-	torture_bootargs="rcupdate.rcu_cpu_stall_suppress_at_boot=1 torture.disable_onoff_at_boot rcupdate.rcu_task_stall_timeout=30000"
+	torture_bootargs="rcupdate.rcu_cpu_stall_suppress_at_boot=1 torture.disable_onoff_at_boot rcupdate.rcu_task_stall_timeout=30000 tsc=watchdog"
 	torture_set "clocksourcewd-1" tools/testing/selftests/rcutorture/bin/kvm.sh --allcpus --duration 45s --configs TREE03 --kconfig "CONFIG_TEST_CLOCKSOURCE_WATCHDOG=y" --trust-make
 
-	torture_bootargs="rcupdate.rcu_cpu_stall_suppress_at_boot=1 torture.disable_onoff_at_boot rcupdate.rcu_task_stall_timeout=30000 clocksource.max_cswd_read_retries=1"
+	torture_bootargs="rcupdate.rcu_cpu_stall_suppress_at_boot=1 torture.disable_onoff_at_boot rcupdate.rcu_task_stall_timeout=30000 clocksource.max_cswd_read_retries=1 tsc=watchdog"
 	torture_set "clocksourcewd-2" tools/testing/selftests/rcutorture/bin/kvm.sh --allcpus --duration 45s --configs TREE03 --kconfig "CONFIG_TEST_CLOCKSOURCE_WATCHDOG=y" --trust-make
 
 	# In case our work is already done...
 	if test "$do_rcutorture" != "yes"
 	then
-		torture_bootargs="rcupdate.rcu_cpu_stall_suppress_at_boot=1 torture.disable_onoff_at_boot rcupdate.rcu_task_stall_timeout=30000"
+		torture_bootargs="rcupdate.rcu_cpu_stall_suppress_at_boot=1 torture.disable_onoff_at_boot rcupdate.rcu_task_stall_timeout=30000 tsc=watchdog"
 		torture_set "clocksourcewd-3" tools/testing/selftests/rcutorture/bin/kvm.sh --allcpus --duration 45s --configs TREE03 --trust-make
 	fi
 fi
-- 
2.40.0.rc1.284.g88254d51c5-goog


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 10/14] rcutorture: Create nocb kthreads only when testing rcu in CONFIG_RCU_NOCB_CPU=y kernels
       [not found] <20230315181902.4177819-1-joel@joelfernandes.org>
  2023-03-15 18:18 ` [PATCH v2 08/14] rcuscale: Rename kfree_rcu() to kfree_rcu_mightsleep() Joel Fernandes (Google)
  2023-03-15 18:18 ` [PATCH v2 09/14] torture: Enable clocksource watchdog with "tsc=watchdog" Joel Fernandes (Google)
@ 2023-03-15 18:18 ` Joel Fernandes (Google)
  2023-03-15 18:18 ` [PATCH v2 11/14] rcu/kvfree: Eliminate k[v]free_rcu() single argument macro Joel Fernandes (Google)
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 6+ messages in thread
From: Joel Fernandes (Google) @ 2023-03-15 18:18 UTC (permalink / raw)
  To: Davidlohr Bueso, Paul E. McKenney, Josh Triplett,
	Frederic Weisbecker, Neeraj Upadhyay, Steven Rostedt,
	Mathieu Desnoyers, Lai Jiangshan, Joel Fernandes
  Cc: Zqiang, linux-kernel, rcu

From: Zqiang <qiang1.zhang@intel.com>

Given a non-zero rcutorture.nocbs_nthreads module parameter, the specified
number of nocb kthreads will be created, regardless of whether or not
the RCU implementation under test is capable of offloading callbacks.
Please note that even vanilla RCU is incapable of offloading in kernels
built with CONFIG_RCU_NOCB_CPU=n.  And when the RCU implementation is
incapable of offloading callbacks, there is no point in creating those
kthreads.

This commit therefore checks the cur_ops.torture_type module parameter and
CONFIG_RCU_NOCB_CPU Kconfig option in order to avoid creating unnecessary
nocb tasks.

Signed-off-by: Zqiang <qiang1.zhang@intel.com>
Reviewed-by: Joel Fernandes (Google) <joel@joelfernandes.org>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
Signed-off-by: Joel Fernandes (Google) <joel@joelfernandes.org>
---
 kernel/rcu/rcutorture.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
index 8e6c023212cb..83870c4ae1b8 100644
--- a/kernel/rcu/rcutorture.c
+++ b/kernel/rcu/rcutorture.c
@@ -3501,6 +3501,12 @@ rcu_torture_init(void)
 		pr_alert("rcu-torture: ->fqs NULL and non-zero fqs_duration, fqs disabled.\n");
 		fqs_duration = 0;
 	}
+	if (nocbs_nthreads != 0 && (cur_ops != &rcu_ops ||
+					!IS_ENABLED(CONFIG_RCU_NOCB_CPU))) {
+		pr_alert("rcu-torture types: %s and CONFIG_RCU_NOCB_CPU=%d, nocb toggle disabled.\n",
+				cur_ops->name, IS_ENABLED(CONFIG_RCU_NOCB_CPU));
+		nocbs_nthreads = 0;
+	}
 	if (cur_ops->init)
 		cur_ops->init();
 
-- 
2.40.0.rc1.284.g88254d51c5-goog


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 11/14] rcu/kvfree: Eliminate k[v]free_rcu() single argument macro
       [not found] <20230315181902.4177819-1-joel@joelfernandes.org>
                   ` (2 preceding siblings ...)
  2023-03-15 18:18 ` [PATCH v2 10/14] rcutorture: Create nocb kthreads only when testing rcu in CONFIG_RCU_NOCB_CPU=y kernels Joel Fernandes (Google)
@ 2023-03-15 18:18 ` Joel Fernandes (Google)
       [not found] ` <CAEXW_YQehT7Zj0G4nBj-0b+Ndq_FTxFzxQ-WYnBGJ=87wPBHYw@mail.gmail.com>
       [not found] ` <20230315181902.4177819-5-joel@joelfernandes.org>
  5 siblings, 0 replies; 6+ messages in thread
From: Joel Fernandes (Google) @ 2023-03-15 18:18 UTC (permalink / raw)
  To: Paul E. McKenney, Frederic Weisbecker, Neeraj Upadhyay,
	Josh Triplett, Steven Rostedt, Mathieu Desnoyers, Lai Jiangshan,
	Joel Fernandes
  Cc: Uladzislau Rezki (Sony), rcu, linux-kernel

From: "Uladzislau Rezki (Sony)" <urezki@gmail.com>

The kvfree_rcu() and kfree_rcu() APIs are hazardous in that if you forget
the second argument, it works, but might sleep.  This sleeping can be a
correctness bug from atomic contexts, and even in non-atomic contexts it
might introduce unacceptable latencies.  This commit therefore removes the
single-argument kvfree_rcu() and kfree_rcu() macros.  Code that would have
previously used these single-argument kvfree_rcu() and kfree_rcu() macros
should instead use kvfree_rcu_mightsleep() or kfree_rcu_mightsleep().

[ paulmck: Apply Joel Fernandes feedback. ]

Signed-off-by: Uladzislau Rezki (Sony) <urezki@gmail.com>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
Signed-off-by: Joel Fernandes (Google) <joel@joelfernandes.org>
---
 include/linux/rcupdate.h | 29 ++++++++---------------------
 1 file changed, 8 insertions(+), 21 deletions(-)

diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
index 094321c17e48..7571dbfecb18 100644
--- a/include/linux/rcupdate.h
+++ b/include/linux/rcupdate.h
@@ -957,9 +957,8 @@ static inline notrace void rcu_read_unlock_sched_notrace(void)
 
 /**
  * kfree_rcu() - kfree an object after a grace period.
- * @ptr: pointer to kfree for both single- and double-argument invocations.
- * @rhf: the name of the struct rcu_head within the type of @ptr,
- *       but only for double-argument invocations.
+ * @ptr: pointer to kfree for double-argument invocations.
+ * @rhf: the name of the struct rcu_head within the type of @ptr.
  *
  * Many rcu callbacks functions just call kfree() on the base structure.
  * These functions are trivial, but their size adds up, and furthermore
@@ -982,26 +981,18 @@ static inline notrace void rcu_read_unlock_sched_notrace(void)
  * The BUILD_BUG_ON check must not involve any function calls, hence the
  * checks are done in macros here.
  */
-#define kfree_rcu(ptr, rhf...) kvfree_rcu(ptr, ## rhf)
+#define kfree_rcu(ptr, rhf) kvfree_rcu_arg_2(ptr, rhf)
+#define kvfree_rcu(ptr, rhf) kvfree_rcu_arg_2(ptr, rhf)
 
 /**
- * kvfree_rcu() - kvfree an object after a grace period.
- *
- * This macro consists of one or two arguments and it is
- * based on whether an object is head-less or not. If it
- * has a head then a semantic stays the same as it used
- * to be before:
- *
- *     kvfree_rcu(ptr, rhf);
- *
- * where @ptr is a pointer to kvfree(), @rhf is the name
- * of the rcu_head structure within the type of @ptr.
+ * kfree_rcu_mightsleep() - kfree an object after a grace period.
+ * @ptr: pointer to kfree for single-argument invocations.
  *
  * When it comes to head-less variant, only one argument
  * is passed and that is just a pointer which has to be
  * freed after a grace period. Therefore the semantic is
  *
- *     kvfree_rcu(ptr);
+ *     kfree_rcu_mightsleep(ptr);
  *
  * where @ptr is the pointer to be freed by kvfree().
  *
@@ -1010,13 +1001,9 @@ static inline notrace void rcu_read_unlock_sched_notrace(void)
  * annotation. Otherwise, please switch and embed the
  * rcu_head structure within the type of @ptr.
  */
-#define kvfree_rcu(...) KVFREE_GET_MACRO(__VA_ARGS__,		\
-	kvfree_rcu_arg_2, kvfree_rcu_arg_1)(__VA_ARGS__)
-
+#define kfree_rcu_mightsleep(ptr) kvfree_rcu_arg_1(ptr)
 #define kvfree_rcu_mightsleep(ptr) kvfree_rcu_arg_1(ptr)
-#define kfree_rcu_mightsleep(ptr) kvfree_rcu_mightsleep(ptr)
 
-#define KVFREE_GET_MACRO(_1, _2, NAME, ...) NAME
 #define kvfree_rcu_arg_2(ptr, rhf)					\
 do {									\
 	typeof (ptr) ___p = (ptr);					\
-- 
2.40.0.rc1.284.g88254d51c5-goog


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 01/14] drbd: Rename kvfree_rcu() to kvfree_rcu_mightsleep()
       [not found]   ` <e5b78f91-122a-0b0d-8d3f-922d462ba44d@kernel.dk>
@ 2023-03-30 15:38     ` Joel Fernandes
  0 siblings, 0 replies; 6+ messages in thread
From: Joel Fernandes @ 2023-03-30 15:38 UTC (permalink / raw)
  To: Jens Axboe; +Cc: Paul E . McKenney, rcu

On Mon, Mar 27, 2023 at 01:26:39PM -0600, Jens Axboe wrote:
> On 3/26/23 6:27 AM, Joel Fernandes wrote:
> > On Wed, Mar 15, 2023 at 2:19 PM Joel Fernandes (Google)
> > <joel@joelfernandes.org> wrote:
> >>
> >> From: "Uladzislau Rezki (Sony)" <urezki@gmail.com>
> >>
> >> The kvfree_rcu() macro's single-argument form is deprecated.  Therefore
> >> switch to the new kvfree_rcu_mightsleep() variant. The goal is to
> >> avoid accidental use of the single-argument forms, which can introduce
> >> functionality bugs in atomic contexts and latency bugs in non-atomic
> >> contexts.
> >>
> >> Cc: Jens Axboe <axboe@kernel.dk>
> >> Cc: Philipp Reisner <philipp.reisner@linbit.com>
> >> Cc: Lars Ellenberg <lars.ellenberg@linbit.com>
> > 
> > Jens/Others, any chance for an Ack here?
> 
> Begrudgingly-acked-by: Jens Axboe <axboe@kernel.dk>

I applied the Ack verbatim, thank you!

 - Joel


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 05/14] net/sysctl: Rename kvfree_rcu() to kvfree_rcu_mightsleep()
       [not found]     ` <20230327101411.5298b38c@kernel.org>
@ 2023-03-30 15:43       ` Joel Fernandes
  0 siblings, 0 replies; 6+ messages in thread
From: Joel Fernandes @ 2023-03-30 15:43 UTC (permalink / raw)
  To: Jakub Kicinski; +Cc: Paul E . McKenney, rcu, David S. Miller, Eric Dumazet

On Mon, Mar 27, 2023 at 1:14 PM Jakub Kicinski <kuba@kernel.org> wrote:
>
> On Sun, 26 Mar 2023 08:28:45 -0400 Joel Fernandes wrote:
> > > Cc: Eric Dumazet <edumazet@google.com>
> > > Cc: David S. Miller <davem@davemloft.net>
> >
> > Could anyone from the networking side Ack this patch so we can take it for 6.4?
> >
> > Eric or David?
>
> Let me help you. Perhaps it's a data point against keeping maintainers
> in an alphabetical order :-)
>
> Acked-by: Jakub Kicinski <kuba@kernel.org>

I applied this Ack to the patch, thank you!

 - Joel

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-03-30 15:44 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20230315181902.4177819-1-joel@joelfernandes.org>
2023-03-15 18:18 ` [PATCH v2 08/14] rcuscale: Rename kfree_rcu() to kfree_rcu_mightsleep() Joel Fernandes (Google)
2023-03-15 18:18 ` [PATCH v2 09/14] torture: Enable clocksource watchdog with "tsc=watchdog" Joel Fernandes (Google)
2023-03-15 18:18 ` [PATCH v2 10/14] rcutorture: Create nocb kthreads only when testing rcu in CONFIG_RCU_NOCB_CPU=y kernels Joel Fernandes (Google)
2023-03-15 18:18 ` [PATCH v2 11/14] rcu/kvfree: Eliminate k[v]free_rcu() single argument macro Joel Fernandes (Google)
     [not found] ` <CAEXW_YQehT7Zj0G4nBj-0b+Ndq_FTxFzxQ-WYnBGJ=87wPBHYw@mail.gmail.com>
     [not found]   ` <e5b78f91-122a-0b0d-8d3f-922d462ba44d@kernel.dk>
2023-03-30 15:38     ` [PATCH v2 01/14] drbd: Rename kvfree_rcu() to kvfree_rcu_mightsleep() Joel Fernandes
     [not found] ` <20230315181902.4177819-5-joel@joelfernandes.org>
     [not found]   ` <CAEXW_YR7njsiRxZtGpUftBQ0hFOzfzsLGQwfrgPwanucO8wATw@mail.gmail.com>
     [not found]     ` <20230327101411.5298b38c@kernel.org>
2023-03-30 15:43       ` [PATCH v2 05/14] net/sysctl: " Joel Fernandes

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox