* [PATCH v2 1/5] locktorture: Fix memory leak in param_set_cpumask()
2025-11-05 20:19 [PATCH v2 0/5] Miscellaneous RCU updates for v6.19 Paul E. McKenney
@ 2025-11-05 20:19 ` Paul E. McKenney
2025-11-05 20:19 ` [PATCH v2 2/5] rcu: use WRITE_ONCE() for ->next and ->pprev of hlist_nulls Paul E. McKenney
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Paul E. McKenney @ 2025-11-05 20:19 UTC (permalink / raw)
To: rcu
Cc: linux-kernel, kernel-team, rostedt, Wang Liang, Zhang Changzhong,
Paul E . McKenney
From: Wang Liang <wangliang74@huawei.com>
With CONFIG_CPUMASK_OFFSTACK=y, the 'bind_writers' buffer is allocated via
alloc_cpumask_var() in param_set_cpumask(). But it is not freed, when
setting the module parameter multiple times by sysfs interface or removing
module.
Below kmemleak trace is seen for this issue:
unreferenced object 0xffff888100aabff8 (size 8):
comm "bash", pid 323, jiffies 4295059233
hex dump (first 8 bytes):
07 00 00 00 00 00 00 00 ........
backtrace (crc ac50919):
__kmalloc_node_noprof+0x2e5/0x420
alloc_cpumask_var_node+0x1f/0x30
param_set_cpumask+0x26/0xb0 [locktorture]
param_attr_store+0x93/0x100
module_attr_store+0x1b/0x30
kernfs_fop_write_iter+0x114/0x1b0
vfs_write+0x300/0x410
ksys_write+0x60/0xd0
do_syscall_64+0xa4/0x260
entry_SYSCALL_64_after_hwframe+0x77/0x7f
This issue can be reproduced by:
insmod locktorture.ko bind_writers=1
rmmod locktorture
or:
insmod locktorture.ko bind_writers=1
echo 2 > /sys/module/locktorture/parameters/bind_writers
Considering that setting the module parameter 'bind_writers' or
'bind_readers' by sysfs interface has no real effect, set the parameter
permissions to 0444. To fix the memory leak when removing module, free
'bind_writers' and 'bind_readers' memory in lock_torture_cleanup().
Fixes: 73e341242483 ("locktorture: Add readers_bind and writers_bind module parameters")
Suggested-by: Zhang Changzhong <zhangchangzhong@huawei.com>
Signed-off-by: Wang Liang <wangliang74@huawei.com>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
---
kernel/locking/locktorture.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/kernel/locking/locktorture.c b/kernel/locking/locktorture.c
index ce0362f0a871..6567e5eeacc0 100644
--- a/kernel/locking/locktorture.c
+++ b/kernel/locking/locktorture.c
@@ -103,8 +103,8 @@ static const struct kernel_param_ops lt_bind_ops = {
.get = param_get_cpumask,
};
-module_param_cb(bind_readers, <_bind_ops, &bind_readers, 0644);
-module_param_cb(bind_writers, <_bind_ops, &bind_writers, 0644);
+module_param_cb(bind_readers, <_bind_ops, &bind_readers, 0444);
+module_param_cb(bind_writers, <_bind_ops, &bind_writers, 0444);
long torture_sched_setaffinity(pid_t pid, const struct cpumask *in_mask, bool dowarn);
@@ -1211,6 +1211,10 @@ static void lock_torture_cleanup(void)
cxt.cur_ops->exit();
cxt.init_called = false;
}
+
+ free_cpumask_var(bind_readers);
+ free_cpumask_var(bind_writers);
+
torture_cleanup_end();
}
--
2.40.1
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH v2 2/5] rcu: use WRITE_ONCE() for ->next and ->pprev of hlist_nulls
2025-11-05 20:19 [PATCH v2 0/5] Miscellaneous RCU updates for v6.19 Paul E. McKenney
2025-11-05 20:19 ` [PATCH v2 1/5] locktorture: Fix memory leak in param_set_cpumask() Paul E. McKenney
@ 2025-11-05 20:19 ` Paul E. McKenney
2025-11-05 20:19 ` [PATCH v2 3/5] torture: Add kvm-series.sh to test commit/scenario combination Paul E. McKenney
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Paul E. McKenney @ 2025-11-05 20:19 UTC (permalink / raw)
To: rcu; +Cc: linux-kernel, kernel-team, rostedt, Xuanqiang Luo,
Paul E . McKenney
From: Xuanqiang Luo <luoxuanqiang@kylinos.cn>
In rculist_nulls.h we can still see ordinary assignments to ->pprev and
->next of hlist_nulls.
As noted in the two patches below:
commit efd04f8a8b45 ("rcu: Use WRITE_ONCE() for assignments to ->next for
rculist_nulls")
commit 860c8802ace1 ("rcu: Use WRITE_ONCE() for assignments to ->pprev for
hlist_nulls")
We should use WRITE_ONCE().
Signed-off-by: Xuanqiang Luo <luoxuanqiang@kylinos.cn>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
---
include/linux/rculist_nulls.h | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/include/linux/rculist_nulls.h b/include/linux/rculist_nulls.h
index 89186c499dd4..d5a656cc4c6a 100644
--- a/include/linux/rculist_nulls.h
+++ b/include/linux/rculist_nulls.h
@@ -138,7 +138,7 @@ static inline void hlist_nulls_add_tail_rcu(struct hlist_nulls_node *n,
if (last) {
WRITE_ONCE(n->next, last->next);
- n->pprev = &last->next;
+ WRITE_ONCE(n->pprev, &last->next);
rcu_assign_pointer(hlist_nulls_next_rcu(last), n);
} else {
hlist_nulls_add_head_rcu(n, h);
@@ -148,8 +148,8 @@ static inline void hlist_nulls_add_tail_rcu(struct hlist_nulls_node *n,
/* after that hlist_nulls_del will work */
static inline void hlist_nulls_add_fake(struct hlist_nulls_node *n)
{
- n->pprev = &n->next;
- n->next = (struct hlist_nulls_node *)NULLS_MARKER(NULL);
+ WRITE_ONCE(n->pprev, &n->next);
+ WRITE_ONCE(n->next, (struct hlist_nulls_node *)NULLS_MARKER(NULL));
}
/**
--
2.40.1
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH v2 3/5] torture: Add kvm-series.sh to test commit/scenario combination
2025-11-05 20:19 [PATCH v2 0/5] Miscellaneous RCU updates for v6.19 Paul E. McKenney
2025-11-05 20:19 ` [PATCH v2 1/5] locktorture: Fix memory leak in param_set_cpumask() Paul E. McKenney
2025-11-05 20:19 ` [PATCH v2 2/5] rcu: use WRITE_ONCE() for ->next and ->pprev of hlist_nulls Paul E. McKenney
@ 2025-11-05 20:19 ` Paul E. McKenney
2025-11-05 20:19 ` [PATCH v2 4/5] rcutorture: Permit kvm-again.sh to re-use the build directory Paul E. McKenney
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Paul E. McKenney @ 2025-11-05 20:19 UTC (permalink / raw)
To: rcu; +Cc: linux-kernel, kernel-team, rostedt, Paul E. McKenney
This commit adds a kvm-series.sh script that takes a list of scenarios and
a list of commits, and then runs each scenario on all of the commits.
A given scenario is run on all the commits before advancing to the
next scenario to minimize build times. The successes and failures are
summarized at the end of the run.
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
---
.../selftests/rcutorture/bin/kvm-series.sh | 116 ++++++++++++++++++
1 file changed, 116 insertions(+)
create mode 100755 tools/testing/selftests/rcutorture/bin/kvm-series.sh
diff --git a/tools/testing/selftests/rcutorture/bin/kvm-series.sh b/tools/testing/selftests/rcutorture/bin/kvm-series.sh
new file mode 100755
index 000000000000..2ff905a1853b
--- /dev/null
+++ b/tools/testing/selftests/rcutorture/bin/kvm-series.sh
@@ -0,0 +1,116 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Usage: kvm-series.sh config-list commit-id-list [ kvm.sh parameters ]
+#
+# Tests the specified list of unadorned configs ("TREE01 SRCU-P" but not
+# "CFLIST" or "3*TRACE01") and an indication of a set of commits to test,
+# then runs each commit through the specified list of commits using kvm.sh.
+# The runs are grouped into a -series/config/commit directory tree.
+# Each run defaults to a duration of one minute.
+#
+# Run in top-level Linux source directory. Please note that this is in
+# no way a replacement for "git bisect"!!!
+#
+# This script is intended to replace kvm-check-branches.sh by providing
+# ease of use and faster execution.
+
+T="`mktemp -d ${TMPDIR-/tmp}/kvm-series.sh.XXXXXX`"
+trap 'rm -rf $T' 0
+
+scriptname=$0
+args="$*"
+
+config_list="${1}"
+if test -z "${config_list}"
+then
+ echo "$0: Need a quoted list of --config arguments for first argument."
+ exit 1
+fi
+if test -z "${config_list}" || echo "${config_list}" | grep -q '\*'
+then
+ echo "$0: Repetition ('*') not allowed in config list."
+ exit 1
+fi
+
+commit_list="${2}"
+if test -z "${commit_list}"
+then
+ echo "$0: Need a list of commits (e.g., HEAD^^^..) for second argument."
+ exit 2
+fi
+git log --pretty=format:"%h" "${commit_list}" > $T/commits
+ret=$?
+if test "${ret}" -ne 0
+then
+ echo "$0: Invalid commit list ('${commit_list}')."
+ exit 2
+fi
+sha1_list=`cat $T/commits`
+
+shift
+shift
+
+RCUTORTURE="`pwd`/tools/testing/selftests/rcutorture"; export RCUTORTURE
+PATH=${RCUTORTURE}/bin:$PATH; export PATH
+. functions.sh
+
+ret=0
+nfail=0
+nsuccess=0
+faillist=
+successlist=
+cursha1="`git rev-parse --abbrev-ref HEAD`"
+ds="`date +%Y.%m.%d-%H.%M.%S`-series"
+startdate="`date`"
+starttime="`get_starttime`"
+
+echo " --- " $scriptname $args | tee -a $T/log
+echo " --- Results directory: " $ds | tee -a $T/log
+
+for config in ${config_list}
+do
+ sha_n=0
+ for sha in ${sha1_list}
+ do
+ sha1=${sha_n}.${sha} # Enable "sort -k1nr" to list commits in order.
+ echo Starting ${config}/${sha1} at `date` | tee -a $T/log
+ git checkout "${sha}"
+ time tools/testing/selftests/rcutorture/bin/kvm.sh --configs "$config" --datestamp "$ds/${config}/${sha1}" --duration 1 "$@"
+ curret=$?
+ if test "${curret}" -ne 0
+ then
+ nfail=$((nfail+1))
+ faillist="$faillist ${config}/${sha1}(${curret})"
+ else
+ nsuccess=$((nsuccess+1))
+ successlist="$successlist ${config}/${sha1}"
+ # Successful run, so remove large files.
+ rm -f ${RCUTORTURE}/$ds/${config}/${sha1}/{vmlinux,bzImage,System.map,Module.symvers}
+ fi
+ if test "${ret}" -eq 0
+ then
+ ret=${curret}
+ fi
+ sha_n=$((sha_n+1))
+ done
+done
+git checkout "${cursha1}"
+
+echo ${nsuccess} SUCCESSES: | tee -a $T/log
+echo ${successlist} | fmt | tee -a $T/log
+echo | tee -a $T/log
+echo ${nfail} FAILURES: | tee -a $T/log
+echo ${faillist} | fmt | tee -a $T/log
+if test -n "${faillist}"
+then
+ echo | tee -a $T/log
+ echo Failures across commits: | tee -a $T/log
+ echo ${faillist} | tr ' ' '\012' | sed -e 's,^[^/]*/,,' -e 's/([0-9]*)//' |
+ sort | uniq -c | sort -k2n | tee -a $T/log
+fi
+echo Started at $startdate, ended at `date`, duration `get_starttime_duration $starttime`. | tee -a $T/log
+echo Summary: Successes: ${nsuccess} Failures: ${nfail} | tee -a $T/log
+cp $T/log tools/testing/selftests/rcutorture/res/${ds}
+
+exit "${ret}"
--
2.40.1
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH v2 4/5] rcutorture: Permit kvm-again.sh to re-use the build directory
2025-11-05 20:19 [PATCH v2 0/5] Miscellaneous RCU updates for v6.19 Paul E. McKenney
` (2 preceding siblings ...)
2025-11-05 20:19 ` [PATCH v2 3/5] torture: Add kvm-series.sh to test commit/scenario combination Paul E. McKenney
@ 2025-11-05 20:19 ` Paul E. McKenney
2025-11-05 20:20 ` [PATCH v2 5/5] rcutorture: Remove redundant rcutorture_one_extend() from rcu_torture_one_read() Paul E. McKenney
2025-11-05 23:06 ` [PATCH v2 0/5] Miscellaneous RCU updates for v6.19 Frederic Weisbecker
5 siblings, 0 replies; 7+ messages in thread
From: Paul E. McKenney @ 2025-11-05 20:19 UTC (permalink / raw)
To: rcu; +Cc: linux-kernel, kernel-team, rostedt, Paul E. McKenney
This commit adds "inplace" and "inplace-force" values to the kvm-again.sh
"--link" argument, which causes the run's output to be placed into the
build directory. This could be used to save build time if the machine
went down partway into a run, but it can also be used to do a large
number of builds, and run the resulting kernels concurrently even if the
builds are based on different commits. A later commit will add this
latter capability to kvm-series.sh in order to produce large speedups
for branch-checking operations.
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
---
.../selftests/rcutorture/bin/kvm-again.sh | 56 +++++++++++++------
1 file changed, 40 insertions(+), 16 deletions(-)
diff --git a/tools/testing/selftests/rcutorture/bin/kvm-again.sh b/tools/testing/selftests/rcutorture/bin/kvm-again.sh
index 88ca4e368489..b5239b52cb5d 100755
--- a/tools/testing/selftests/rcutorture/bin/kvm-again.sh
+++ b/tools/testing/selftests/rcutorture/bin/kvm-again.sh
@@ -31,7 +31,7 @@ fi
if ! cp "$oldrun/scenarios" $T/scenarios.oldrun
then
# Later on, can reconstitute this from console.log files.
- echo Prior run batches file does not exist: $oldrun/batches
+ echo Prior run scenarios file does not exist: $oldrun/scenarios
exit 1
fi
@@ -68,7 +68,7 @@ usage () {
echo " --datestamp string"
echo " --dryrun"
echo " --duration minutes | <seconds>s | <hours>h | <days>d"
- echo " --link hard|soft|copy"
+ echo " --link hard|soft|copy|inplace|inplace-force"
echo " --remote"
echo " --rundir /new/res/path"
echo "Command line: $scriptname $args"
@@ -121,7 +121,7 @@ do
shift
;;
--link)
- checkarg --link "hard|soft|copy" "$#" "$2" 'hard\|soft\|copy' '^--'
+ checkarg --link "hard|soft|copy|inplace|inplace-force" "$#" "$2" 'hard\|soft\|copy\|inplace\|inplace-force' '^--'
case "$2" in
copy)
arg_link="cp -R"
@@ -132,6 +132,14 @@ do
soft)
arg_link="cp -Rs"
;;
+ inplace)
+ arg_link="inplace"
+ rundir="$oldrun"
+ ;;
+ inplace-force)
+ arg_link="inplace-force"
+ rundir="$oldrun"
+ ;;
esac
shift
;;
@@ -172,21 +180,37 @@ fi
echo ---- Re-run results directory: $rundir
-# Copy old run directory tree over and adjust.
-mkdir -p "`dirname "$rundir"`"
-if ! $arg_link "$oldrun" "$rundir"
-then
- echo "Cannot copy from $oldrun to $rundir."
- usage
-fi
-rm -f "$rundir"/*/{console.log,console.log.diags,qemu_pid,qemu-pid,qemu-retval,Warnings,kvm-test-1-run.sh.out,kvm-test-1-run-qemu.sh.out,vmlinux} "$rundir"/log
-touch "$rundir/log"
-echo $scriptname $args | tee -a "$rundir/log"
-echo $oldrun > "$rundir/re-run"
-if ! test -d "$rundir/../../bin"
+if test "$oldrun" != "$rundir"
then
- $arg_link "$oldrun/../../bin" "$rundir/../.."
+ # Copy old run directory tree over and adjust.
+ mkdir -p "`dirname "$rundir"`"
+ if ! $arg_link "$oldrun" "$rundir"
+ then
+ echo "Cannot copy from $oldrun to $rundir."
+ usage
+ fi
+ rm -f "$rundir"/*/{console.log,console.log.diags,qemu_pid,qemu-pid,qemu-retval,Warnings,kvm-test-1-run.sh.out,kvm-test-1-run-qemu.sh.out,vmlinux} "$rundir"/log
+ touch "$rundir/log"
+ echo $scriptname $args | tee -a "$rundir/log"
+ echo $oldrun > "$rundir/re-run"
+ if ! test -d "$rundir/../../bin"
+ then
+ $arg_link "$oldrun/../../bin" "$rundir/../.."
+ fi
+else
+ # Check for a run having already happened.
+ find "$rundir" -name console.log -print > $T/oldrun-console.log
+ if test -s $T/oldrun-console.log
+ then
+ echo Run already took place in $rundir
+ if test "$arg_link" = inplace
+ then
+ usage
+ fi
+ fi
fi
+
+# Find runs to be done based on their qemu-cmd files.
for i in $rundir/*/qemu-cmd
do
cp "$i" $T
--
2.40.1
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH v2 5/5] rcutorture: Remove redundant rcutorture_one_extend() from rcu_torture_one_read()
2025-11-05 20:19 [PATCH v2 0/5] Miscellaneous RCU updates for v6.19 Paul E. McKenney
` (3 preceding siblings ...)
2025-11-05 20:19 ` [PATCH v2 4/5] rcutorture: Permit kvm-again.sh to re-use the build directory Paul E. McKenney
@ 2025-11-05 20:20 ` Paul E. McKenney
2025-11-05 23:06 ` [PATCH v2 0/5] Miscellaneous RCU updates for v6.19 Frederic Weisbecker
5 siblings, 0 replies; 7+ messages in thread
From: Paul E. McKenney @ 2025-11-05 20:20 UTC (permalink / raw)
To: rcu; +Cc: linux-kernel, kernel-team, rostedt, Paul E. McKenney
This commit removes a harmless but potentially confusing invocation of
rcutorture_one_extend() within rcu_torture_one_read(). The immediately
preceding call to rcu_torture_one_read_start() already does this cleanup,
and the other call to rcu_torture_one_read_start() already relies on this.
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
---
kernel/rcu/rcutorture.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
index 72619e5e8549..318bea62ed3e 100644
--- a/kernel/rcu/rcutorture.c
+++ b/kernel/rcu/rcutorture.c
@@ -2384,10 +2384,8 @@ static bool rcu_torture_one_read(struct torture_random_state *trsp, long myid)
newstate = rcutorture_extend_mask(rtors.readstate, trsp);
WARN_ON_ONCE(newstate & RCUTORTURE_RDR_UPDOWN);
rcutorture_one_extend(&rtors.readstate, newstate, trsp, rtors.rtrsp++);
- if (!rcu_torture_one_read_start(&rtors, trsp, myid)) {
- rcutorture_one_extend(&rtors.readstate, 0, trsp, rtors.rtrsp);
+ if (!rcu_torture_one_read_start(&rtors, trsp, myid))
return false;
- }
rtors.rtrsp = rcutorture_loop_extend(&rtors.readstate, trsp, rtors.rtrsp);
rcu_torture_one_read_end(&rtors, trsp);
return true;
--
2.40.1
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH v2 0/5] Miscellaneous RCU updates for v6.19
2025-11-05 20:19 [PATCH v2 0/5] Miscellaneous RCU updates for v6.19 Paul E. McKenney
` (4 preceding siblings ...)
2025-11-05 20:20 ` [PATCH v2 5/5] rcutorture: Remove redundant rcutorture_one_extend() from rcu_torture_one_read() Paul E. McKenney
@ 2025-11-05 23:06 ` Frederic Weisbecker
5 siblings, 0 replies; 7+ messages in thread
From: Frederic Weisbecker @ 2025-11-05 23:06 UTC (permalink / raw)
To: Paul E. McKenney; +Cc: rcu, linux-kernel, kernel-team, rostedt
Le Wed, Nov 05, 2025 at 12:19:51PM -0800, Paul E. McKenney a écrit :
> Hello!
>
> This series provides miscellaneous RCU updates:
>
> 1. Fix memory leak in param_set_cpumask(), courtesy of Wang Liang.
>
> 2. use WRITE_ONCE() for ->next and ->pprev of hlist_nulls, courtesy
> of Xuanqiang Luo.
>
> 3. Add kvm-series.sh to test commit/scenario combination.
>
> 4. Permit kvm-again.sh to re-use the build directory.
>
> 5. Remove redundant rcutorture_one_extend() from
> rcu_torture_one_read().
>
> Changes since v1:
>
> o Make kvm-again.sh able to reuse the rcutorture res directory
> in support of upcoming parallel execution of kvm-series.sh
> guest OSes. This is #3 above.
>
> o Remove a redundant call to rcutorture_one_extend(). This is
> #4 above.
>
> o Add the SPDX line to kvm-again.sh and remove a trailing space
> character from the comment header.
>
> Thanx, Paul
>
> ------------------------------------------------------------------------
>
> include/linux/rculist_nulls.h | 6
> kernel/locking/locktorture.c | 8 -
> kernel/rcu/rcutorture.c | 4
> tools/testing/selftests/rcutorture/bin/kvm-again.sh | 56 ++++++---
> tools/testing/selftests/rcutorture/bin/kvm-series.sh | 116 +++++++++++++++++++
> 5 files changed, 166 insertions(+), 24 deletions(-)
>
Applied to rcu/misc (and also applied the refscale patches for rcu/refscale).
Thanks!
--
Frederic Weisbecker
SUSE Labs
^ permalink raw reply [flat|nested] 7+ messages in thread