Torture-test updates for v5.14
Subsystems (7)
Paul E. McKenney
maintainercover Torture-test updates for v5.14
Hello!
This series provides torture-test updates:
1. Fix remaining erroneous torture.sh instance of $*.
2. Add "scenarios" option to kvm.sh --dryrun parameter.
3. Make kvm-again.sh use "scenarios" rather than "batches" file.
4. Allow CPU hotplug to be enabled.
5. Allow CPU hotplug to be enabled.
6. Add kvm-remote.sh script for distributed rcutorture test runs.
7. Add acqrel, lock, and lock-irq.
8. Abstract read-lock-held checks.
9. Fix grace-period rate output.
10. Abstract end-of-run summary.
11. Make kvm.sh use abstracted kvm-end-run-stats.sh.
12. Make the build machine control N in "make -jN".
13. Make kvm-find-errors.sh account for kvm-remote.sh.
14. Judge RCU priority boosting on grace periods, not callbacks.
15. Correctly fetch number of CPUs for non-English languages,
courtesy of Frederic Weisbecker.
16. Set kvm.sh language to English.
17. Delay-based false positives for RCU priority boosting tests.
18. Consolidate rcu_torture_boost() timing and statistics.
19. Make rcu_torture_boost_failed() check for GP end.
20. Add BUSTED-BOOST to test RCU priority boosting tests.
21. Forgive RCU boost failures when CPUs don't pass through QS.
22. Don't count CPU-stalled time against priority boosting.
23. Make kvm-remote.sh account for network failure in pathname checks.
24. Don't cap remote runs by build-system number of CPUs.
25. Move mem_dump_obj() tests into separate function.
26. Don't penalize priority boosting when there is nothing to boost.
Thanx, Paul
------------------------------------------------------------------------
b/kernel/rcu/rcu.h | 2 b/kernel/rcu/rcutorture.c | 29 b/kernel/rcu/refscale.c | 109 +++ b/kernel/rcu/tree_stall.h | 36 + b/tools/testing/selftests/rcutorture/bin/kvm-again.sh | 22 b/tools/testing/selftests/rcutorture/bin/kvm-build.sh | 6 b/tools/testing/selftests/rcutorture/bin/kvm-end-run-stats.sh | 40 + b/tools/testing/selftests/rcutorture/bin/kvm-find-errors.sh | 2 b/tools/testing/selftests/rcutorture/bin/kvm-recheck-rcu.sh | 2 b/tools/testing/selftests/rcutorture/bin/kvm-remote.sh | 227 +++++++ b/tools/testing/selftests/rcutorture/bin/kvm.sh | 28 b/tools/testing/selftests/rcutorture/bin/torture.sh | 2 b/tools/testing/selftests/rcutorture/configs/rcu/BUSTED-BOOST | 17 b/tools/testing/selftests/rcutorture/configs/rcu/BUSTED-BOOST.boot | 8 b/tools/testing/selftests/rcutorture/configs/rcuscale/TREE | 2 b/tools/testing/selftests/rcutorture/configs/rcuscale/TREE54 | 2 b/tools/testing/selftests/rcutorture/configs/refscale/NOPREEMPT | 2 b/tools/testing/selftests/rcutorture/configs/refscale/PREEMPT | 2 kernel/rcu/rcutorture.c | 300 +++++----- kernel/rcu/tree_stall.h | 27 tools/testing/selftests/rcutorture/bin/kvm-again.sh | 11 tools/testing/selftests/rcutorture/bin/kvm-build.sh | 2 tools/testing/selftests/rcutorture/bin/kvm-remote.sh | 30 - tools/testing/selftests/rcutorture/bin/kvm.sh | 33 - 24 files changed, 726 insertions(+), 215 deletions(-)
Paul E. McKenney
maintainerPATCH 1/26 torture: Fix remaining erroneous torture.sh instance of $*
Although "eval" was removed from torture.sh, that commit failed to update the KCSAN instance of $* to "$@". This results in failures when (for example) --bootargs is given more than one argument. This commit therefore makes this change.
There is one remaining instance of $* in torture.sh, but this is used only in the "echo" command, where quoting doesn't matter so much.
--- tools/testing/selftests/rcutorture/bin/torture.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/rcutorture/bin/torture.sh +1 -1
@@ -302,7 +302,7 @@ function torture_set { kcsan_kmake_tag="--kmake-args" cur_kcsan_kmake_args="$kcsan_kmake_args" fi - torture_one $* --kconfig "CONFIG_DEBUG_LOCK_ALLOC=y CONFIG_PROVE_LOCKING=y" $kcsan_kmake_tag $cur_kcsan_kmake_args --kcsan + torture_one "$@" --kconfig "CONFIG_DEBUG_LOCK_ALLOC=y CONFIG_PROVE_LOCKING=y" $kcsan_kmake_tag $cur_kcsan_kmake_args --kcsan fi }
Signature · 1 line
2.31.1.189.g2e36527f23
Paul E. McKenney
maintainerPATCH 2/26 torture: Add "scenarios" option to kvm.sh --dryrun parameter
In reply to Paul E. McKenneyThis commit adds "--dryrun scenarios" to kvm.sh, which prints something like this:
1. TREE03 2. TREE07 3. SRCU-P SRCU-N 4. TREE01 TRACE01 5. TREE02 TRACE02 6. TREE04 RUDE01 TASKS01 7. TREE05 TASKS03 SRCU-T SRCU-U 8. TASKS02 TINY01 TINY02 TREE09
This format is more convenient for scripts that run batches of scenarios.
--- tools/testing/selftests/rcutorture/bin/kvm.sh | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-)
tools/testing/selftests/rcutorture/bin/kvm.sh +26 -2
@@ -64,7 +64,7 @@ usage () { echo " --cpus N" echo " --datestamp string" echo " --defconfig string" - echo " --dryrun batches|sched|script" + echo " --dryrun batches|scenarios|sched|script" echo " --duration minutes | <seconds>s | <hours>h | <days>d" echo " --gdb" echo " --help"
@@ -130,7 +130,7 @@ do shift ;; --dryrun) - checkarg --dryrun "batches|sched|script" $# "$2" 'batches\|sched\|script' '^--' + checkarg --dryrun "batches|sched|script" $# "$2" 'batches\|scenarios\|sched\|script' '^--' dryrun=$2 shift ;;
@@ -577,6 +577,25 @@ egrep 'Start batch|Starting build\.' $T/script | grep -v ">>" | print batchno, $1, $2 }' > $T/batches +# As above, but one line per batch. +grep -v '^#' $T/batches | awk ' +BEGIN { + oldbatch = 1; +} + +{ + if (oldbatch != $1) { + print ++n ". " curbatch; + curbatch = ""; + oldbatch = $1; + } + curbatch = curbatch " " $2; +} + +END { + print ++n ". " curbatch; +}' > $T/scenarios + if test "$dryrun" = script then cat $T/script
@@ -597,11 +616,16 @@ elif test "$dryrun" = batches then cat $T/batches exit 0 +elif test "$dryrun" = scenarios +then + cat $T/scenarios + exit 0 else # Not a dryrun. Record the batches and the number of CPUs, then run the script. bash $T/script ret=$? cp $T/batches $resdir/$ds/batches + cp $T/scenarios $resdir/$ds/scenarios echo '#' cpus=$cpus >> $resdir/$ds/batches echo " --- Done at `date` (`get_starttime_duration $starttime`) exitcode $ret" | tee -a $resdir/$ds/log exit $ret
Signature · 1 line
2.31.1.189.g2e36527f23
Paul E. McKenney
maintainerPATCH 3/26 torture: Make kvm-again.sh use "scenarios" rather than "batches" file
In reply to Paul E. McKenneyThis commit saves a few lines of code by making kvm-again.sh use the "scenarios" file rather than the "batches" file, both of which are generated by kvm.sh.
This results in a break point because new versions of kvm-again.sh cannot handle "res" directories produced by old versions of kvm.sh, which lack the "scenarios" file. In the unlikely event that this becomes a problem, a trivial script suffices to convert the "batches" file to a "scenarios" file, and this script may be easily extracted from kvm.sh.
--- .../selftests/rcutorture/bin/kvm-again.sh | 22 +++++-------------- 1 file changed, 6 insertions(+), 16 deletions(-)
tools/testing/selftests/rcutorture/bin/kvm-again.sh +6 -16
@@ -29,7 +29,7 @@ then echo "Usage: $scriptname /path/to/old/run [ options ]" exit 1 fi -if ! cp "$oldrun/batches" $T/batches.oldrun +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
@@ -165,22 +165,12 @@ done grep '^#' $i | sed -e 's/^# //' > $T/qemu-cmd-settings . $T/qemu-cmd-settings -grep -v '^#' $T/batches.oldrun | awk ' -BEGIN { - oldbatch = 1; -} - +grep -v '^#' $T/scenarios.oldrun | awk ' { - if (oldbatch != $1) { - print "kvm-test-1-run-batch.sh" curbatch; - curbatch = ""; - oldbatch = $1; - } - curbatch = curbatch " " $2; -} - -END { - print "kvm-test-1-run-batch.sh" curbatch + curbatch = ""; + for (i = 2; i <= NF; i++) + curbatch = curbatch " " $i; + print "kvm-test-1-run-batch.sh" curbatch; }' > $T/runbatches.sh if test -n "$dryrun"
Signature · 1 line
2.31.1.189.g2e36527f23
Paul E. McKenney
maintainerPATCH 4/26 refscale: Allow CPU hotplug to be enabled
In reply to Paul E. McKenneyIt is no longer possible to disable CPU hotplug in many configurations, which means that the CONFIG_HOTPLUG_CPU=n lines in refscale's Kconfig options are just a source of useless diagnostics. In addition, refscale doesn't do CPU-hotplug operations in any case. This commit therefore changes these lines to read CONFIG_HOTPLUG_CPU=y.
--- tools/testing/selftests/rcutorture/configs/refscale/NOPREEMPT | 2 +- tools/testing/selftests/rcutorture/configs/refscale/PREEMPT | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/rcutorture/configs/refscale/NOPREEMPT +1 -1
@@ -7,7 +7,7 @@ CONFIG_HZ_PERIODIC=n CONFIG_NO_HZ_IDLE=y CONFIG_NO_HZ_FULL=n CONFIG_RCU_FAST_NO_HZ=n -CONFIG_HOTPLUG_CPU=n +CONFIG_HOTPLUG_CPU=y CONFIG_SUSPEND=n CONFIG_HIBERNATION=n CONFIG_RCU_NOCB_CPU=n
tools/testing/selftests/rcutorture/configs/refscale/PREEMPT +1 -1
@@ -7,7 +7,7 @@ CONFIG_HZ_PERIODIC=n CONFIG_NO_HZ_IDLE=y CONFIG_NO_HZ_FULL=n CONFIG_RCU_FAST_NO_HZ=n -CONFIG_HOTPLUG_CPU=n +CONFIG_HOTPLUG_CPU=y CONFIG_SUSPEND=n CONFIG_HIBERNATION=n CONFIG_RCU_NOCB_CPU=n
Signature · 1 line
2.31.1.189.g2e36527f23
Paul E. McKenney
maintainerPATCH 5/26 rcuscale: Allow CPU hotplug to be enabled
In reply to Paul E. McKenneyIt is no longer possible to disable CPU hotplug in many configurations, which means that the CONFIG_HOTPLUG_CPU=n lines in rcuscale's Kconfig options are just a source of useless diagnostics. In addition, rcuscale doesn't do CPU-hotplug operations in any case. This commit therefore changes these lines to read CONFIG_HOTPLUG_CPU=y.
--- tools/testing/selftests/rcutorture/configs/rcuscale/TREE | 2 +- tools/testing/selftests/rcutorture/configs/rcuscale/TREE54 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/rcutorture/configs/rcuscale/TREE +1 -1
@@ -7,7 +7,7 @@ CONFIG_HZ_PERIODIC=n CONFIG_NO_HZ_IDLE=y CONFIG_NO_HZ_FULL=n CONFIG_RCU_FAST_NO_HZ=n -CONFIG_HOTPLUG_CPU=n +CONFIG_HOTPLUG_CPU=y CONFIG_SUSPEND=n CONFIG_HIBERNATION=n CONFIG_RCU_NOCB_CPU=n
tools/testing/selftests/rcutorture/configs/rcuscale/TREE54 +1 -1
@@ -8,7 +8,7 @@ CONFIG_HZ_PERIODIC=n CONFIG_NO_HZ_IDLE=y CONFIG_NO_HZ_FULL=n CONFIG_RCU_FAST_NO_HZ=n -CONFIG_HOTPLUG_CPU=n +CONFIG_HOTPLUG_CPU=y CONFIG_SUSPEND=n CONFIG_HIBERNATION=n CONFIG_RCU_FANOUT=3
Signature · 1 line
2.31.1.189.g2e36527f23
Paul E. McKenney
maintainerPATCH 6/26 torture: Add kvm-remote.sh script for distributed rcutorture test runs
In reply to Paul E. McKenneyThis commit adds a kvm-remote.sh script that prepares a tarball that is then downloaded to the remote system(s) and executed. The user is responsible for having set up the remote systems to run qemu, but all the kernel builds are done on the system running the kvm-remote.sh script. The user is also responsible for setting up the remote systems so that ssh can be run non-interactively, given that ssh is used to poll the remote systems in order to detect completion of each batch.
See the script's header comment for usage information.
--- .../selftests/rcutorture/bin/kvm-remote.sh | 227 ++++++++++++++++++ 1 file changed, 227 insertions(+) create mode 100755 tools/testing/selftests/rcutorture/bin/kvm-remote.sh
tools/testing/selftests/rcutorture/bin/kvm-remote.sh new file +227 -0
@@ -0,0 +1,227 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0+ +# +# Run a series of tests on remote systems under KVM. +# +# Usage: kvm-remote.sh "systems" [ <kvm.sh args> ] +# kvm-remote.sh "systems" /path/to/old/run [ <kvm-again.sh args> ] +# +# Copyright (C) 2021 Facebook, Inc. +# +# Authors: Paul E. McKenney <[email protected]> + +scriptname=$0 +args="$*" + +if ! test -d tools/testing/selftests/rcutorture/bin +then + echo $scriptname must be run from top-level directory of kernel source tree. + exit 1 +fi + +KVM="`pwd`/tools/testing/selftests/rcutorture"; export KVM +PATH=${KVM}/bin:$PATH; export PATH +. functions.sh + +starttime="`get_starttime`" + +systems="$1" +if test -z "$systems" +then + echo $scriptname: Empty list of systems will go nowhere good, giving up. + exit 1 +fi +shift + +# Pathnames: +# T: /tmp/kvm-remote.sh.$$ +# resdir: /tmp/kvm-remote.sh.$$/res +# rundir: /tmp/kvm-remote.sh.$$/res/$ds ("-remote" suffix) +# oldrun: `pwd`/tools/testing/.../res/$otherds +# +# Pathname segments: +# TD: kvm-remote.sh.$$ +# ds: yyyy.mm.dd-hh.mm.ss-remote + +TD=kvm-remote.sh.$$ +T=${TMPDIR-/tmp}/$TD +trap 'rm -rf $T' 0 +mkdir $T + +resdir="$T/res" +ds=`date +%Y.%m.%d-%H.%M.%S`-remote +rundir=$resdir/$ds +echo Results directory: $rundir +echo $scriptname $args +if echo $1 | grep -q '^--' +then + # Fresh build. Create a datestamp unless the caller supplied one. + datestamp="`echo "$@" | awk -v ds="$ds" '{ + for (i = 1; i < NF; i++) { + if ($i == "--datestamp") { + ds = ""; + break; + } + } + if (ds != "") + print "--datestamp " ds; + }'`" + kvm.sh "$@" $datestamp --buildonly > $T/kvm.sh.out 2>&1 + ret=$? + if test "$ret" -ne 0 + then + echo $scriptname: kvm.sh failed exit code $? + cat $T/kvm.sh.out + exit 2 + fi + oldrun="`grep -m 1 "^Results directory: " $T/kvm.sh.out | awk '{ print $3 }'`" + touch "$oldrun/remote-log" + echo $scriptname $args >> "$oldrun/remote-log" + echo | tee -a "$oldrun/remote-log" + echo " ----" kvm.sh output: "(`date`)" | tee -a "$oldrun/remote-log" + cat $T/kvm.sh.out | tee -a "$oldrun/remote-log" + # We are going to run this, so remove the buildonly files. + rm -f "$oldrun"/*/buildonly + kvm-again.sh $oldrun --dryrun --remote --rundir "$rundir" > $T/kvm-again.sh.out 2>&1 + ret=$? + if test "$ret" -ne 0 + then + echo $scriptname: kvm-again.sh failed exit code $? | tee -a "$oldrun/remote-log" + cat $T/kvm-again.sh.out | tee -a "$oldrun/remote-log" + exit 2 + fi +else + # Re-use old run. + oldrun="$1" + if ! echo $oldrun | grep -q '^/' + then + oldrun="`pwd`/$oldrun" + fi + shift + touch "$oldrun/remote-log" + echo $scriptname $args >> "$oldrun/remote-log" + kvm-again.sh "$oldrun" "$@" --dryrun --remote --rundir "$rundir" > $T/kvm-again.sh.out 2>&1 + ret=$? + if test "$ret" -ne 0 + then + echo $scriptname: kvm-again.sh failed exit code $? | tee -a "$oldrun/remote-log" + cat $T/kvm-again.sh.out | tee -a "$oldrun/remote-log" + exit 2 + fi + cp -a "$rundir" "$KVM/res/" + oldrun="$KVM/res/$ds" +fi +echo | tee -a "$oldrun/remote-log" +echo " ----" kvm-again.sh output: "(`date`)" | tee -a "$oldrun/remote-log" +cat $T/kvm-again.sh.out +echo | tee -a "$oldrun/remote-log" +echo Remote run directory: $rundir | tee -a "$oldrun/remote-log" +echo Local build-side run directory: $oldrun | tee -a "$oldrun/remote-log" + +# Create the kvm-remote-N.sh scripts in the bin directory. +awk < "$rundir"/scenarios -v dest="$T/bin" -v rundir="$rundir" ' +{ + n = $1; + sub(/\./, "", n); + fn = dest "/kvm-remote-" n ".sh" + scenarios = ""; + for (i = 2; i <= NF; i++) + scenarios = scenarios " " $i; + print "kvm-test-1-run-batch.sh" scenarios > fn; + print "rm " rundir "/remote.run" >> fn; +}' +chmod +x $T/bin/kvm-remote-*.sh +( cd "`dirname $T`"; tar -chzf $T/binres.tgz "$TD/bin" "$TD/res" ) + +# Check first to avoid the need for cleanup for system-name typos +for i in $systems +do + ncpus="`ssh $i lscpu | grep '^CPU(' | awk '{ print $2 }'`" + echo $i: $ncpus CPUs " " `date` | tee -a "$oldrun/remote-log" + ret=$? + if test "$ret" -ne 0 + then + echo System $i unreachable, giving up. | tee -a "$oldrun/remote-log" + exit 4 | tee -a "$oldrun/remote-log" + fi +done + +# Download and expand the tarball on all systems. +for i in $systems +do + echo Downloading tarball to $i `date` | tee -a "$oldrun/remote-log" + cat $T/binres.tgz | ssh $i "cd /tmp; tar -xzf -" + ret=$? + if test "$ret" -ne 0 + then + echo Unable to download $T/binres.tgz to system $i, giving up. | tee -a "$oldrun/remote-log" + exit 10 | tee -a "$oldrun/remote-log" + fi +done + +# Function to start batches on idle remote $systems +# +# Usage: startbatches curbatch nbatches +# +# Batches are numbered starting at 1. Returns the next batch to start. +# Be careful to redirect all debug output to FD 2 (stderr). +startbatches () { + local curbatch="$1" + local nbatches="$2" + local ret + + # Each pass through the following loop examines one system. + for i in $systems + do + if test "$curbatch" -gt "$nbatches" + then + echo $((nbatches + 1)) + return 0 + fi + if ssh "$i" "test -f \"$resdir/$ds/remote.run\"" 1>&2 + then + continue # System still running last test, skip. + fi + ssh "$i" "cd \"$resdir/$ds\"; touch remote.run; PATH=\"$T/bin:$PATH\" nohup kvm-remote-$curbatch.sh > kvm-remote-$curbatch.sh.out 2>&1 &" 1>&2 + ret=$? + if test "$ret" -ne 0 + then + echo ssh $i failed: exitcode $ret 1>&2 + exit 11 + fi + echo " ----" System $i Batch `head -n $curbatch < "$rundir"/scenarios | tail -1` `date` 1>&2 + curbatch=$((curbatch + 1)) + done + echo $curbatch +} + +# Launch all the scenarios. +nbatches="`wc -l "$rundir"/scenarios | awk '{ print $1 }'`" +curbatch=1 +while test "$curbatch" -le "$nbatches" +do + startbatches $curbatch $nbatches > $T/curbatch 2> $T/startbatches.stderr + curbatch="`cat $T/curbatch`" + if test -s "$T/startbatches.stderr" + then + cat "$T/startbatches.stderr" | tee -a "$oldrun/remote-log" + fi + if test "$curbatch" -le "$nbatches" + then + sleep 30 + fi +done +echo All batches started. `date` + +# Wait for all remaining scenarios to complete and collect results. +for i in $systems +do + while ssh "$i" "test -f \"$resdir/$ds/remote.run\"" + do + sleep 30 + done + ( cd "$oldrun"; ssh $i "cd $rundir; tar -czf - kvm-remote-*.sh.out */console.log */kvm-test-1-run*.sh.out */qemu_pid */qemu-retval; rm -rf $T > /dev/null 2>&1" | tar -xzf - ) +done + +( kvm-end-run-stats.sh "$oldrun" "$starttime"; echo $? > $T/exitcode ) | tee -a "$oldrun/remote-log" +exit "`cat $T/exitcode`"
Signature · 1 line
2.31.1.189.g2e36527f23
Paul E. McKenney
maintainerPATCH 7/26 refscale: Add acqrel, lock, and lock-irq
In reply to Paul E. McKenneyThis commit adds scale_type of acqrel, lock, and lock-irq to test acquisition and release. Note that the refscale.nreaders=1 module parameter is required if you wish to test uncontended locking. In contrast, acqrel uses a per-CPU variable, so should be just fine with large values of the refscale.nreaders=1 module parameter.
--- kernel/rcu/refscale.c | 109 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 107 insertions(+), 2 deletions(-)
kernel/rcu/refscale.c +107 -2
@@ -362,6 +362,111 @@ static struct ref_scale_ops rwsem_ops = { .name = "rwsem" }; +// Definitions for global spinlock +static DEFINE_SPINLOCK (test_lock); + +static void ref_lock_section (const int nloops) +{ +int i; + +preempt_disable (); +for (i = nloops; i >=0 ; i--) { +spin_lock (&test_lock); +spin_unlock (&test_lock); + } +preempt_enable (); +} + +static void ref_lock_delay_section (const int nloops,const int udl,const int ndl) +{ +int i; + +preempt_disable (); +for (i = nloops; i >=0 ; i--) { +spin_lock (&test_lock); +un_delay (udl, ndl); +spin_unlock (&test_lock); + } +preempt_enable (); +} + +static struct ref_scale_ops lock_ops = { + .readsection = ref_lock_section, + .delaysection = ref_lock_delay_section, + .name ="lock" +}; + +// Definitions for global irq-save spinlock + +static void ref_lock_irq_section (const int nloops) +{ +unsigned long flags; +int i; + +preempt_disable (); +for (i = nloops; i >=0 ; i--) { +spin_lock_irqsave (&test_lock, flags); +spin_unlock_irqrestore (&test_lock, flags); + } +preempt_enable (); +} + +static void ref_lock_irq_delay_section (const int nloops,const int udl,const int ndl) +{ +unsigned long flags; +int i; + +preempt_disable (); +for (i = nloops; i >=0 ; i--) { +spin_lock_irqsave (&test_lock, flags); +un_delay (udl, ndl); +spin_unlock_irqrestore (&test_lock, flags); + } +preempt_enable (); +} + +static struct ref_scale_ops lock_irq_ops = { + .readsection = ref_lock_irq_section, + .delaysection = ref_lock_irq_delay_section, + .name ="lock-irq" +}; + +// Definitions acquire-release. +static DEFINE_PER_CPU(unsigned long, test_acqrel); + +static void ref_acqrel_section (const int nloops) +{ +unsigned long x; +int i; + +preempt_disable (); +for (i = nloops; i >=0 ; i--) { + x =smp_load_acquire (this_cpu_ptr (&test_acqrel)); +smp_store_release (this_cpu_ptr (&test_acqrel), x +1 ); + } +preempt_enable (); +} + +static void ref_acqrel_delay_section (const int nloops,const int udl,const int ndl) +{ +unsigned long x; +int i; + +preempt_disable (); +for (i = nloops; i >=0 ; i--) { + x =smp_load_acquire (this_cpu_ptr (&test_acqrel)); +un_delay (udl, ndl); +smp_store_release (this_cpu_ptr (&test_acqrel), x +1 ); + } +preempt_enable (); +} + +static struct ref_scale_ops acqrel_ops = { + .readsection = ref_acqrel_section, + .delaysection = ref_acqrel_delay_section, + .name ="acqrel" +}; +static void rcu_scale_one_reader (void ) {if (readdelay <=0 )
@@ -653,8 +758,8 @@ ref_scale_init(void)long i;int firsterr =0 ;static struct ref_scale_ops *scale_ops[] = { - &rcu_ops, &srcu_ops, &rcu_trace_ops, &rcu_tasks_ops, - &refcnt_ops, &rwlock_ops, &rwsem_ops, + &rcu_ops, &srcu_ops, &rcu_trace_ops, &rcu_tasks_ops, &refcnt_ops, &rwlock_ops, + &rwsem_ops, &lock_ops, &lock_irq_ops, &acqrel_ops, };if (!torture_init_begin (scale_type, verbose))
Signature · 1 line
2.31.1.189.g2e36527f23
Paul E. McKenney
maintainerPATCH 8/26 rcutorture: Abstract read-lock-held checks
In reply to Paul E. McKenneyThis commit adds a (*readlock_held)() function pointer to the rcu_torture_ops structure in order to make the rcu_torture_one_read() function's rcu_dereference_check() lockdep expression more appropriate for a given run.
--- kernel/rcu/rcutorture.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-)
kernel/rcu/rcutorture.c +19 -10
@@ -331,6 +331,7 @@ struct rcu_torture_ops {void (*read_delay)(struct torture_random_state *rrsp,struct rt_read_seg *rtrsp);void (*readunlock)(int idx); +int (*readlock_held)(void );unsigned long (*get_gp_seq)(void );unsigned long (*gp_diff)(unsigned long new,unsigned long old);void (*deferred_free)(struct rcu_torture *p);
@@ -359,6 +360,11 @@ static struct rcu_torture_ops *cur_ops;* Definitions for rcu torture testing. */ +static int torture_readlock_not_held (void ) +{ +return rcu_read_lock_bh_held () ||rcu_read_lock_sched_held (); +} +static int rcu_torture_read_lock (void )__acquires (RCU ) {rcu_read_lock ();
@@ -488,6 +494,7 @@ static struct rcu_torture_ops rcu_ops = { .readlock = rcu_torture_read_lock, .read_delay = rcu_read_delay, .readunlock = rcu_torture_read_unlock, + .readlock_held = torture_readlock_not_held, .get_gp_seq = rcu_get_gp_seq, .gp_diff = rcu_seq_diff, .deferred_free = rcu_torture_deferred_free,
@@ -540,6 +547,7 @@ static struct rcu_torture_ops rcu_busted_ops = { .readlock = rcu_torture_read_lock, .read_delay = rcu_read_delay, /* just reuse rcu's version. */ .readunlock = rcu_torture_read_unlock, + .readlock_held = torture_readlock_not_held, .get_gp_seq = rcu_no_completed, .deferred_free = rcu_busted_torture_deferred_free, .sync = synchronize_rcu_busted,
@@ -589,6 +597,11 @@ static void srcu_torture_read_unlock(int idx) __releases(srcu_ctlp)srcu_read_unlock (srcu_ctlp, idx); } +static int torture_srcu_read_lock_held (void ) +{ +return srcu_read_lock_held (srcu_ctlp); +} +static unsigned long srcu_torture_completed (void ) {return srcu_batches_completed (srcu_ctlp);
@@ -646,6 +659,7 @@ static struct rcu_torture_ops srcu_ops = { .readlock = srcu_torture_read_lock, .read_delay = srcu_read_delay, .readunlock = srcu_torture_read_unlock, + .readlock_held = torture_srcu_read_lock_held, .get_gp_seq = srcu_torture_completed, .deferred_free = srcu_torture_deferred_free, .sync = srcu_torture_synchronize,
@@ -681,6 +695,7 @@ static struct rcu_torture_ops srcud_ops = { .readlock = srcu_torture_read_lock, .read_delay = srcu_read_delay, .readunlock = srcu_torture_read_unlock, + .readlock_held = torture_srcu_read_lock_held, .get_gp_seq = srcu_torture_completed, .deferred_free = srcu_torture_deferred_free, .sync = srcu_torture_synchronize,
@@ -700,6 +715,7 @@ static struct rcu_torture_ops busted_srcud_ops = { .readlock = srcu_torture_read_lock, .read_delay = rcu_read_delay, .readunlock = srcu_torture_read_unlock, + .readlock_held = torture_srcu_read_lock_held, .get_gp_seq = srcu_torture_completed, .deferred_free = srcu_torture_deferred_free, .sync = srcu_torture_synchronize,
@@ -787,6 +803,7 @@ static struct rcu_torture_ops trivial_ops = { .readlock = rcu_torture_read_lock_trivial, .read_delay = rcu_read_delay, /* just reuse rcu's version. */ .readunlock = rcu_torture_read_unlock_trivial, + .readlock_held = torture_readlock_not_held, .get_gp_seq = rcu_no_completed, .sync = synchronize_rcu_trivial, .exp_sync = synchronize_rcu_trivial,
@@ -850,6 +867,7 @@ static struct rcu_torture_ops tasks_tracing_ops = { .readlock = tasks_tracing_torture_read_lock, .read_delay = srcu_read_delay, /* just reuse srcu's version. */ .readunlock = tasks_tracing_torture_read_unlock, + .readlock_held = rcu_read_lock_trace_held, .get_gp_seq = rcu_no_completed, .deferred_free = rcu_tasks_tracing_torture_deferred_free, .sync = synchronize_rcu_tasks_trace,
@@ -871,11 +889,6 @@ static unsigned long rcutorture_seq_diff(unsigned long new, unsigned long old)return cur_ops->gp_diff (new, old); } -static bool __maybe_unused torturing_tasks (void ) -{ -return cur_ops == &tasks_ops || cur_ops == &tasks_rude_ops; -} -/* * RCU torture priority-boost testing. Runs one real-time thread per * CPU for moderate bursts, repeatedly registering RCU callbacks and
@@ -1553,11 +1566,7 @@ static bool rcu_torture_one_read(struct torture_random_state *trsp, long myid) started = cur_ops->get_gp_seq (); ts =rcu_trace_clock_local (); p =rcu_dereference_check (rcu_torture_current, -rcu_read_lock_bh_held () || -rcu_read_lock_sched_held () || -srcu_read_lock_held (srcu_ctlp) || -rcu_read_lock_trace_held () || -torturing_tasks ()); + !cur_ops->readlock_held || cur_ops->readlock_held ());if (p ==NULL ) {/* Wait for rcu_torture_writer to get underway */ rcutorture_one_extend (&readstate,0 , trsp, rtrsp);
Signature · 1 line
2.31.1.189.g2e36527f23
Paul E. McKenney
maintainerPATCH 9/26 torture: Fix grace-period rate output
In reply to Paul E. McKenneyThe kvm-again.sh script relies on shell comments added to the qemu-cmd file, but this means that code extracting values from the QEMU command in this file must grep out those commment. Which kvm-recheck-rcu.sh failed to do, which destroyed its grace-period-per-second calculation. This commit therefore adds the needed "grep -v '^#'" to kvm-recheck-rcu.sh.
--- tools/testing/selftests/rcutorture/bin/kvm-recheck-rcu.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/rcutorture/bin/kvm-recheck-rcu.sh +1 -1
@@ -31,7 +31,7 @@ then echo "$configfile ------- " $stopstate else title="$configfile ------- $ngps GPs" - dur=`sed -e 's/^.* rcutorture.shutdown_secs=//' -e 's/ .*$//' < $i/qemu-cmd 2> /dev/null` + dur=`grep -v '^#' $i/qemu-cmd | sed -e 's/^.* rcutorture.shutdown_secs=//' -e 's/ .*$//'` if test -z "$dur" then :
Signature · 1 line
2.31.1.189.g2e36527f23
Paul E. McKenney
maintainerPATCH 10/26 torture: Abstract end-of-run summary
In reply to Paul E. McKenneyThis commit abstractst the end-of-run summary from kvm-again.sh, and, while in the area, brings its format into line with that of kvm.sh.
--- .../selftests/rcutorture/bin/kvm-again.sh | 11 ++--- .../rcutorture/bin/kvm-end-run-stats.sh | 40 +++++++++++++++++++ 2 files changed, 43 insertions(+), 8 deletions(-) create mode 100755 tools/testing/selftests/rcutorture/bin/kvm-end-run-stats.sh
tools/testing/selftests/rcutorture/bin/kvm-again.sh +3 -8
@@ -143,6 +143,8 @@ then usage fi rm -f "$rundir"/*/{console.log,console.log.diags,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
@@ -178,12 +180,5 @@ then echo ---- Dryrun complete, directory: $rundir | tee -a "$rundir/log" else ( cd "$rundir"; sh $T/runbatches.sh ) - kcsan-collapse.sh "$rundir" | tee -a "$rundir/log" - echo | tee -a "$rundir/log" - echo ---- Results directory: $rundir | tee -a "$rundir/log" - kvm-recheck.sh "$rundir" > $T/kvm-recheck.sh.out 2>&1 - ret=$? - cat $T/kvm-recheck.sh.out | tee -a "$rundir/log" - echo " --- Done at `date` (`get_starttime_duration $starttime`) exitcode $ret" | tee -a "$rundir/log" - exit $ret + kvm-end-run-stats.sh "$rundir" "$starttime" fi
tools/testing/selftests/rcutorture/bin/kvm-end-run-stats.sh new file +40 -0
@@ -0,0 +1,40 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0+ +# +# Check the status of the specified run. +# +# Usage: kvm-end-run-stats.sh /path/to/run starttime +# +# Copyright (C) 2021 Facebook, Inc. +# +# Authors: Paul E. McKenney <[email protected]> + +# scriptname=$0 +# args="$*" +rundir="$1" +if ! test -d "$rundir" +then + echo kvm-end-run-stats.sh: Specified run directory does not exist: $rundir + exit 1 +fi + +T=${TMPDIR-/tmp}/kvm-end-run-stats.sh.$$ +trap 'rm -rf $T' 0 +mkdir $T + +KVM="`pwd`/tools/testing/selftests/rcutorture"; export KVM +PATH=${KVM}/bin:$PATH; export PATH +. functions.sh +default_starttime="`get_starttime`" +starttime="${2-default_starttime}" + +echo | tee -a "$rundir/log" +echo | tee -a "$rundir/log" +echo " --- `date` Test summary:" | tee -a "$rundir/log" +echo Results directory: $rundir | tee -a "$rundir/log" +kcsan-collapse.sh "$rundir" | tee -a "$rundir/log" +kvm-recheck.sh "$rundir" > $T/kvm-recheck.sh.out 2>&1 +ret=$? +cat $T/kvm-recheck.sh.out | tee -a "$rundir/log" +echo " --- Done at `date` (`get_starttime_duration $starttime`) exitcode $ret" | tee -a "$rundir/log" +exit $ret
Signature · 1 line
2.31.1.189.g2e36527f23
Paul E. McKenney
maintainerPATCH 11/26 torture: Make kvm.sh use abstracted kvm-end-run-stats.sh
In reply to Paul E. McKenneyThis commit reduces duplicate code by making kvm.sh use the new kvm-end-run-stats.sh script rather than taking its historical approach of open-coding it.
--- tools/testing/selftests/rcutorture/bin/kvm.sh | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-)
tools/testing/selftests/rcutorture/bin/kvm.sh +1 -15
@@ -550,20 +550,7 @@ END { if (ncpus != 0) dump(first, i, batchnum); }' >> $T/script - -cat << '___EOF___' >> $T/script -echo | tee -a $TORTURE_RESDIR/log -echo | tee -a $TORTURE_RESDIR/log -echo " --- `date` Test summary:" | tee -a $TORTURE_RESDIR/log -___EOF___ -cat << ___EOF___ >> $T/script -echo Results directory: $resdir/$ds | tee -a $resdir/$ds/log -kcsan-collapse.sh $resdir/$ds | tee -a $resdir/$ds/log -kvm-recheck.sh $resdir/$ds > $T/kvm-recheck.sh.out 2>&1 -___EOF___ -echo 'ret=$?' >> $T/script -echo "cat $T/kvm-recheck.sh.out | tee -a $resdir/$ds/log" >> $T/script -echo 'exit $ret' >> $T/script +echo kvm-end-run-stats.sh "$resdir/$ds" "$starttime" >> $T/script # Extract the tests and their batches from the script. egrep 'Start batch|Starting build\.' $T/script | grep -v ">>" |
@@ -627,7 +614,6 @@ else cp $T/batches $resdir/$ds/batches cp $T/scenarios $resdir/$ds/scenarios echo '#' cpus=$cpus >> $resdir/$ds/batches - echo " --- Done at `date` (`get_starttime_duration $starttime`) exitcode $ret" | tee -a $resdir/$ds/log exit $ret fi
Signature · 1 line
2.31.1.189.g2e36527f23
Paul E. McKenney
maintainerPATCH 12/26 torture: Make the build machine control N in "make -jN"
In reply to Paul E. McKenneyGiven remote rcutorture runs, it is quite possible that the build system will have fewer CPUs than the system(s) running the actual test scenarios. In such cases, using the number of CPUs on the test systems can overload the build system, slowing down the build or, worse, OOMing the build system. This commit therefore uses the build system's CPU count to set N in "make -jN", and by tradition sets "N" to double the CPU count.
--- tools/testing/selftests/rcutorture/bin/kvm-build.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
tools/testing/selftests/rcutorture/bin/kvm-build.sh +4 -2
@@ -40,8 +40,10 @@ if test $retval -gt 1 then exit 2 fi -ncpus=`cpus2use.sh` -make -j$ncpus $TORTURE_KMAKE_ARG > $resdir/Make.out 2>&1 + +# Tell "make" to use double the number of real CPUs on the build system. +ncpus="`lscpu | grep '^CPU(' | awk '{ print $2 }'`" +make -j$((2 * ncpus)) $TORTURE_KMAKE_ARG > $resdir/Make.out 2>&1 retval=$? if test $retval -ne 0 || grep "rcu[^/]*": < $resdir/Make.out | egrep -q "Stop|Error|error:|warning:" || egrep -q "Stop|Error|error:" < $resdir/Make.out then
Signature · 1 line
2.31.1.189.g2e36527f23
Paul E. McKenney
maintainerPATCH 13/26 torture: Make kvm-find-errors.sh account for kvm-remote.sh
In reply to Paul E. McKenneyCurrently, kvm-find-errors.sh assumes that if "--buildonly" appears in the log file, then the run did builds but ran no kernels. This breaks with kvm-remote.sh, which uses kvm.sh to do a build, then kvm-again.sh to run the kernels built on remote systems. This commit therefore adds a check for a kvm-remote.sh run.
While in the area, this commit checks for "--build-only" as well as "--build-only".
--- tools/testing/selftests/rcutorture/bin/kvm-find-errors.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/rcutorture/bin/kvm-find-errors.sh +1 -1
@@ -43,7 +43,7 @@ then else echo No build errors. fi -if grep -q -e "--buildonly" < ${rundir}/log +if grep -q -e "--build-\?only" < ${rundir}/log && ! test -f "${rundir}/remote-log" then echo Build-only run, no console logs to check. exit $editorret
Signature · 1 line
2.31.1.189.g2e36527f23
Paul E. McKenney
maintainerPATCH 14/26 rcutorture: Judge RCU priority boosting on grace periods, not callbacks
In reply to Paul E. McKenneyCurrently, rcutorture's testing of RCU priority boosting insists not only that grace periods complete, but also that callbacks be invoked. Although this is in fact what the user would want, ensuring that there is sufficient CPU bandwidth devoted to callback execution is in fact the user's responsibility. One could argue that rcutorture can take on that responsibility, which is true in theory. But in practice, ensuring sufficient CPU bandwidth to ksoftirqd, any rcuc kthreads, and any rcuo kthreads is not particularly consistent with rcutorture's main job, that of stress-testing RCU. In addition, if the system administrator (say) makes very poor choices when pinning rcuo kthreads and then runs rcutorture, there really isn't much rcutorture can do.
Besides, RCU priority boosting only boosts lagging readers, not all the machinery required to invoke callbacks in a timely fashion.
This commit therefore switches rcutorture's evaluation of RCU priority boosting from callback execution to grace-period completion by using the new start_poll_synchronize_rcu() and poll_state_synchronize_rcu() functions. When rcutorture is built in (as in when there is no innocent workload to inconvenience), the ksoftirqd ktheads are boosted to real-time priority 2 in order to allow timeouts to work properly in the face of rcutorture's testing of RCU priority boosting.
Indeed, it is not as easy as it looks to create a reliable test of RCU priority boosting without destroying the rest of the kernel!
--- kernel/rcu/rcutorture.c | 111 ++++++++++++++++++---------------------- 1 file changed, 51 insertions(+), 60 deletions(-)
kernel/rcu/rcutorture.c +51 -60
@@ -245,12 +245,6 @@ static const char *rcu_torture_writer_state_getname(void)return rcu_torture_writer_state_names[i]; } -#if defined(CONFIG_RCU_BOOST ) && defined(CONFIG_PREEMPT_RT ) -# define rcu_can_boost () 1 -#else -# define rcu_can_boost () 0 -#endif -#ifdef CONFIG_RCU_TRACE static u64 notrace rcu_trace_clock_local(void) {
@@ -511,7 +505,7 @@ static struct rcu_torture_ops rcu_ops = { .gp_kthread_dbg = show_rcu_gp_kthreads, .stall_dur = rcu_jiffies_till_stall_check, .irq_capable = 1, - .can_boost = rcu_can_boost(), + .can_boost = IS_ENABLED(CONFIG_RCU_BOOST), .extendables = RCUTORTURE_MAX_EXTEND, .name = "rcu" };
@@ -891,25 +885,11 @@ static unsigned long rcutorture_seq_diff(unsigned long new, unsigned long old)/* * RCU torture priority-boost testing. Runs one real-time thread per -* CPU for moderate bursts, repeatedly registering RCU callbacks and -* spinning waiting for them to be invoked. If a given callback takes -* too long to be invoked, we assume that priority inversion has occurred. +* CPU for moderate bursts, repeatedly starting grace periods and waiting +* for them to complete. If a given grace period takes too long, we assume +* that priority inversion has occurred. */ -struct rcu_boost_inflight { -struct rcu_head rcu; -int inflight; -}; - -static void rcu_torture_boost_cb (struct rcu_head *head) -{ -struct rcu_boost_inflight *rbip = - container_of(head, struct rcu_boost_inflight, rcu); - -/* Ensure RCU-core accesses precede clearing ->inflight */ -smp_store_release (&rbip->inflight,0 ); -} -static int old_rt_runtime =-1 ;static void rcu_torture_disable_rt_throttle (void )
@@ -936,15 +916,18 @@ static void rcu_torture_enable_rt_throttle(void) old_rt_runtime =-1 ; } -static bool rcu_torture_boost_failed (unsigned long start,unsigned long end) +static bool rcu_torture_boost_failed (unsigned long gp_state,unsigned long start,unsigned long end) {static int dbg_done;if (end - start > test_boost_duration *HZ -HZ /2 ) {VERBOSE_TOROUT_STRING ("rcu_torture_boost boosting failed" ); n_rcu_torture_boost_failure++; -if (!xchg (&dbg_done,1 ) && cur_ops->gp_kthread_dbg) +if (!xchg (&dbg_done,1 ) && cur_ops->gp_kthread_dbg) { +pr_info ("Boost inversion thread ->rt_priority %u gp_state %lu jiffies %lu\n" , + current->rt_priority, gp_state, end - start); cur_ops->gp_kthread_dbg (); + }return true;/* failed */ }
@@ -954,21 +937,20 @@ static bool rcu_torture_boost_failed(unsigned long start, unsigned long end)static int rcu_torture_boost (void *arg) { -unsigned long call_rcu_time;unsigned long endtime; +unsigned long gp_state; +unsigned long gp_state_time;unsigned long oldstarttime; -struct rcu_boost_inflight rbi = { .inflight =0 };VERBOSE_TOROUT_STRING ("rcu_torture_boost started" );/* Set real-time priority. */ sched_set_fifo_low (current); -init_rcu_head_on_stack (&rbi.rcu);/* Each pass through the following loop does one boost-test cycle. */ do { bool failed = false; // Test failed already in this test interval - bool firsttime = true; + bool gp_initiated = false; /* Increment n_rcu_torture_boosts once per boost-test */ while (!kthread_should_stop()) {
@@ -992,33 +974,33 @@ static int rcu_torture_boost(void *arg) goto checkwait; } -/* Do one boost-test interval. */ +// Do one boost-test interval. endtime = oldstarttime + test_boost_duration *HZ ;while (time_before (jiffies, endtime)) { -/* If we don't have a callback in flight, post one. */ -if (!smp_load_acquire (&rbi.inflight)) { -/* RCU core before ->inflight = 1. */ -smp_store_release (&rbi.inflight,1 ); - cur_ops->call (&rbi.rcu, rcu_torture_boost_cb); -/* Check if the boost test failed */ -if (!firsttime && !failed) - failed =rcu_torture_boost_failed (call_rcu_time, jiffies); - call_rcu_time = jiffies; - firsttime = false; +// Has current GP gone too long? +if (gp_initiated && !failed && !cur_ops->poll_gp_state (gp_state)) + failed =rcu_torture_boost_failed (gp_state, gp_state_time, jiffies); +// If we don't have a grace period in flight, start one. +if (!gp_initiated || cur_ops->poll_gp_state (gp_state)) { + gp_state = cur_ops->start_gp_poll (); + gp_initiated = true; + gp_state_time = jiffies; } -if (stutter_wait ("rcu_torture_boost" )) +if (stutter_wait ("rcu_torture_boost" )) {sched_set_fifo_low (current); +// If the grace period already ended, +// we don't know when that happened, so +// start over. +if (cur_ops->poll_gp_state (gp_state)) + gp_initiated = false; + }if (torture_must_stop ()) goto checkwait; } -/* -* If boost never happened, then inflight will always be 1, in -* this case the boost check would never happen in the above -* loop so do another one here. -*/ -if (!firsttime && !failed &&smp_load_acquire (&rbi.inflight)) -rcu_torture_boost_failed (call_rcu_time, jiffies); +// In case the grace period extended beyond the end of the loop. +if (gp_initiated && !failed && !cur_ops->poll_gp_state (gp_state)) +rcu_torture_boost_failed (gp_state, gp_state_time, jiffies);/* * Set the start time of the next test interval.
@@ -1027,11 +1009,9 @@ static int rcu_torture_boost(void *arg)* interval. Besides, we are running at RT priority, * so delays should be relatively rare. */ -while (oldstarttime == boost_starttime && - !kthread_should_stop ()) { +while (oldstarttime == boost_starttime && !kthread_should_stop ()) {if (mutex_trylock (&boost_mutex)) { - boost_starttime = jiffies + - test_boost_interval *HZ ; + boost_starttime = jiffies + test_boost_interval *HZ ;mutex_unlock (&boost_mutex);break ; }
@@ -1043,15 +1023,11 @@ checkwait: if (stutter_wait("rcu_torture_boost"))sched_set_fifo_low (current); }while (!torture_must_stop ()); -while (smp_load_acquire (&rbi.inflight)) -schedule_timeout_uninterruptible (1 );// rcu_barrier() deadlocks. -/* Clean up and exit. */ -while (!kthread_should_stop () ||smp_load_acquire (&rbi.inflight)) { +while (!kthread_should_stop ()) {torture_shutdown_absorb ("rcu_torture_boost" );schedule_timeout_uninterruptible (1 ); } -destroy_rcu_head_on_stack (&rbi.rcu);torture_kthread_stopping ("rcu_torture_boost" );return 0 ; }
@@ -2643,7 +2619,7 @@ static bool rcu_torture_can_boost(void)if (!(test_boost ==1 && cur_ops->can_boost) && test_boost !=2 )return false; -if (!cur_ops->call) +if (!cur_ops->start_gp_poll || !cur_ops->poll_gp_state)return false; prio =rcu_get_gp_kthreads_prio ();
@@ -2651,7 +2627,7 @@ static bool rcu_torture_can_boost(void)return false;if (prio <2 ) { -if (boost_warn_once ==1 ) +if (boost_warn_once ==1 )return false;pr_alert ("%s: WARN: RCU kthread priority too low to test boosting. Skipping RCU boost test. Try passing rcutree.kthread_prio > 1 on the kernel command line.\n" ,KBUILD_MODNAME );
@@ -3129,6 +3105,21 @@ rcu_torture_init(void)if (firsterr <0 ) goto unwind; rcutor_hp = firsterr; + +// Testing RCU priority boosting requires rcutorture do +// some serious abuse. Counter this by running ksoftirqd +// at higher priority. +if (IS_BUILTIN (CONFIG_RCU_TORTURE_TEST )) { +for_each_online_cpu (cpu) { +struct sched_param sp; +struct task_struct *t; + + t =per_cpu (ksoftirqd, cpu); +WARN_ON_ONCE (!t); + sp.sched_priority =2 ; +sched_setscheduler_nocheck (t,SCHED_FIFO , &sp); + } + } } shutdown_jiffies = jiffies + shutdown_secs *HZ ; firsterr =torture_shutdown_init (shutdown_secs, rcu_torture_cleanup);
Signature · 1 line
2.31.1.189.g2e36527f23
Paul E. McKenney
maintainerPATCH 15/26 torture: Correctly fetch number of CPUs for non-English languages
In reply to Paul E. McKenneyFrom: Frederic Weisbecker <[email protected]>
Grepping for "CPU" on lscpu output isn't always successful, depending on the local language setting. As a result, the build can be aborted early with:
"make: the '-j' option requires a positive integer argument"
This commit therefore uses the human-language-independent approach available via the getconf command, both in kvm-build.sh and in kvm-remote.sh.
--- tools/testing/selftests/rcutorture/bin/kvm-build.sh | 2 +- tools/testing/selftests/rcutorture/bin/kvm-remote.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/rcutorture/bin/kvm-build.sh +1 -1
@@ -42,7 +42,7 @@ then fi # Tell "make" to use double the number of real CPUs on the build system. -ncpus="`lscpu | grep '^CPU(' | awk '{ print $2 }'`" +ncpus="`getconf _NPROCESSORS_ONLN`" make -j$((2 * ncpus)) $TORTURE_KMAKE_ARG > $resdir/Make.out 2>&1 retval=$? if test $retval -ne 0 || grep "rcu[^/]*": < $resdir/Make.out | egrep -q "Stop|Error|error:|warning:" || egrep -q "Stop|Error|error:" < $resdir/Make.out
tools/testing/selftests/rcutorture/bin/kvm-remote.sh +1 -1
@@ -136,7 +136,7 @@ chmod +x $T/bin/kvm-remote-*.sh # Check first to avoid the need for cleanup for system-name typos for i in $systems do - ncpus="`ssh $i lscpu | grep '^CPU(' | awk '{ print $2 }'`" + ncpus="`ssh $i getconf _NPROCESSORS_ONLN 2> /dev/null`" echo $i: $ncpus CPUs " " `date` | tee -a "$oldrun/remote-log" ret=$? if test "$ret" -ne 0
Signature · 1 line
2.31.1.189.g2e36527f23
Paul E. McKenney
maintainerPATCH 16/26 torture: Set kvm.sh language to English
In reply to Paul E. McKenneySome of the code invoked directly and indirectly from kvm.sh parses the output of commands. This parsing assumes English, which can cause failures if the user has set some other language. In a few cases, there are language-independent commands available, but this is not always the case. Therefore, as an alternative to polyglot parsing, this commit sets the LANG environment variable to en_US.UTF-8.
--- tools/testing/selftests/rcutorture/bin/kvm.sh | 3 +++ 1 file changed, 3 insertions(+)
tools/testing/selftests/rcutorture/bin/kvm.sh +3 -0
@@ -20,6 +20,9 @@ mkdir $T cd `dirname $scriptname`/../../../../../ +# This script knows only English. +LANG=en_US.UTF-8; export LANG + dur=$((30*60)) dryrun="" KVM="`pwd`/tools/testing/selftests/rcutorture"; export KVM
Signature · 1 line
2.31.1.189.g2e36527f23
Paul E. McKenney
maintainerPATCH 17/26 rcutorture: Delay-based false positives for RCU priority boosting tests
In reply to Paul E. McKenneyIf an rcu_torture_boost() kthread determines that its grace period has not yet ended, it invokes rcu_torture_boost_failed() which checks whether enough time has elapsed for this to be considered a failure of RCU priority boosting, and, if so, flags the error.
Unfortunately, that kthread might be preempted for some seconds between the time that it checks the grace period and the time that it checks the time. This delay can result in a false positive, featuring a complaint that a particular grace period has not ended, followed by a diagnostic dump featuring a much later grace period.
This commit avoids these false positives by rechecking for the end of the grace period after the time check.
--- kernel/rcu/rcutorture.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
kernel/rcu/rcutorture.c +6 -2
@@ -921,6 +921,10 @@ static bool rcu_torture_boost_failed(unsigned long gp_state, unsigned long startstatic int dbg_done;if (end - start > test_boost_duration *HZ -HZ /2 ) { +// Recheck after checking time to avoid false positives. +smp_mb ();// Time check before grace-period check. +if (cur_ops->poll_gp_state (gp_state)) +return false;// passed, though perhaps just barely VERBOSE_TOROUT_STRING ("rcu_torture_boost boosting failed" ); n_rcu_torture_boost_failure++;if (!xchg (&dbg_done,1 ) && cur_ops->gp_kthread_dbg) {
@@ -929,10 +933,10 @@ static bool rcu_torture_boost_failed(unsigned long gp_state, unsigned long start cur_ops->gp_kthread_dbg (); } -return true;/* failed */ +return true;// failed } -return false;/* passed */ +return false;// passed }static int rcu_torture_boost (void *arg)
Signature · 1 line
2.31.1.189.g2e36527f23
Paul E. McKenney
maintainerPATCH 18/26 rcutorture: Consolidate rcu_torture_boost() timing and statistics
In reply to Paul E. McKenneyThis commit consolidates two loops in rcu_torture_boost(), one of which counts the number of boost-test episodes and the other of which computes the start time of the next episode, into one loop that does both with but a single acquisition of boost_mutex. This means that the count of the number of boost-test episodes is incremented after an episode completes rather than before it starts, but it also avoids the over-counting that was possible previously.
--- kernel/rcu/rcutorture.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-)
kernel/rcu/rcutorture.c +4 -10
@@ -956,15 +956,6 @@ static int rcu_torture_boost(void *arg)bool failed = false;// Test failed already in this test interval bool gp_initiated = false; -/* Increment n_rcu_torture_boosts once per boost-test */ -while (!kthread_should_stop ()) { -if (mutex_trylock (&boost_mutex)) { - n_rcu_torture_boosts++; -mutex_unlock (&boost_mutex); -break ; - } -schedule_timeout_uninterruptible (1 ); - }if (kthread_should_stop ()) goto checkwait;
@@ -1015,7 +1006,10 @@ static int rcu_torture_boost(void *arg)*/ while (oldstarttime == boost_starttime && !kthread_should_stop ()) {if (mutex_trylock (&boost_mutex)) { - boost_starttime = jiffies + test_boost_interval *HZ ; +if (oldstarttime == boost_starttime) { + boost_starttime = jiffies + test_boost_interval *HZ ; + n_rcu_torture_boosts++; + }mutex_unlock (&boost_mutex);break ; }
Signature · 1 line
2.31.1.189.g2e36527f23
Paul E. McKenney
maintainerPATCH 19/26 rcutorture: Make rcu_torture_boost_failed() check for GP end
In reply to Paul E. McKenneyIt is possible that a delayed grace period that rcu_torture_boost() was polling for ended while rcu_torture_boost_failed() was printing the failure splat. It would be good to know when this happens. This commit therefore has rcu_torture_boost_failed() recheck the grace period after printing the splat, and printing a message indicating whether or not the grace period has ended.
--- kernel/rcu/rcutorture.c | 6 ++++++ 1 file changed, 6 insertions(+)
kernel/rcu/rcutorture.c +6 -0
@@ -919,6 +919,7 @@ static void rcu_torture_enable_rt_throttle(void)static bool rcu_torture_boost_failed (unsigned long gp_state,unsigned long start,unsigned long end) {static int dbg_done; +bool gp_done;if (end - start > test_boost_duration *HZ -HZ /2 ) {// Recheck after checking time to avoid false positives.
@@ -931,6 +932,11 @@ static bool rcu_torture_boost_failed(unsigned long gp_state, unsigned long startpr_info ("Boost inversion thread ->rt_priority %u gp_state %lu jiffies %lu\n" , current->rt_priority, gp_state, end - start); cur_ops->gp_kthread_dbg (); +// Recheck after print to flag grace period ending during splat. + gp_done = cur_ops->poll_gp_state (gp_state); +pr_info ("Boost inversion: GP %lu %s.\n" , gp_state, + gp_done ?"ended already" :"still pending" ); + }return true;// failed
Signature · 1 line
2.31.1.189.g2e36527f23
Paul E. McKenney
maintainerPATCH 20/26 rcutorture: Add BUSTED-BOOST to test RCU priority boosting tests
In reply to Paul E. McKenneyThis commit adds the BUSTED-BOOST rcutorture scenario, which can be used to test rcutorture's ability to test RCU priority boosting.
--- .../rcutorture/configs/rcu/BUSTED-BOOST | 17 +++++++++++++++++ .../rcutorture/configs/rcu/BUSTED-BOOST.boot | 8 ++++++++ 2 files changed, 25 insertions(+) create mode 100644 tools/testing/selftests/rcutorture/configs/rcu/BUSTED-BOOST create mode 100644 tools/testing/selftests/rcutorture/configs/rcu/BUSTED-BOOST.boot
tools/testing/selftests/rcutorture/configs/rcu/BUSTED-BOOST new file +17 -0
@@ -0,0 +1,17 @@ +CONFIG_SMP=y +CONFIG_NR_CPUS=16 +CONFIG_PREEMPT_NONE=n +CONFIG_PREEMPT_VOLUNTARY=n +CONFIG_PREEMPT=y +#CHECK#CONFIG_PREEMPT_RCU=y +CONFIG_HZ_PERIODIC=y +CONFIG_NO_HZ_IDLE=n +CONFIG_NO_HZ_FULL=n +CONFIG_RCU_TRACE=y +CONFIG_HOTPLUG_CPU=y +CONFIG_RCU_FANOUT=2 +CONFIG_RCU_FANOUT_LEAF=2 +CONFIG_RCU_NOCB_CPU=n +CONFIG_DEBUG_LOCK_ALLOC=n +CONFIG_DEBUG_OBJECTS_RCU_HEAD=n +CONFIG_RCU_EXPERT=y
tools/testing/selftests/rcutorture/configs/rcu/BUSTED-BOOST.boot new file +8 -0
@@ -0,0 +1,8 @@ +rcutorture.test_boost=2 +rcutorture.stutter=0 +rcutree.gp_preinit_delay=12 +rcutree.gp_init_delay=3 +rcutree.gp_cleanup_delay=3 +rcutree.kthread_prio=2 +threadirqs +tree.use_softirq=0
Signature · 1 line
2.31.1.189.g2e36527f23
Paul E. McKenney
maintainerPATCH 21/26 rcutorture: Forgive RCU boost failures when CPUs don't pass through QS
In reply to Paul E. McKenneyCurrently, rcu_torture_boost() runs CPU-bound at real-time priority to force RCU priority inversions. It then checks that grace periods progress during this CPU-bound time. If grace periods fail to progress, it reports and RCU priority boosting failure.
However, it is possible (and sometimes does happen) that the grace period fails to progress due to a CPU failing to pass through a quiescent state for an extended time period (3.5 seconds by default). This can happen due to vCPU preemption, long-running interrupts, and much else besides. There is nothing that RCU priority boosting can do about these situations, and so they should not be counted as RCU priority boosting failures.
This commit therefore checks for CPUs (as opposed to preempted tasks) holding up a grace period, and flags the resulting RCU priority boosting failures, but does not splat nor count them as errors. It does rate-limit them to avoid flooding the console log.
--- kernel/rcu/rcu.h | 2 ++ kernel/rcu/rcutorture.c | 67 +++++++++++++++++++++++++---------------- kernel/rcu/tree_stall.h | 36 ++++++++++++++++++++++ 3 files changed, 79 insertions(+), 26 deletions(-)
kernel/rcu/rcu.h +2 -0
@@ -519,6 +519,7 @@ static inline unsigned long rcu_exp_batches_completed(void) { return 0; }static inline unsigned long srcu_batches_completed (struct srcu_struct *sp) {return 0 ; }static inline void rcu_force_quiescent_state (void ) { } +static inline bool rcu_check_boost_fail (unsigned long gp_state,int *cpup) {return true; }static inline void show_rcu_gp_kthreads (void ) { }static inline int rcu_get_gp_kthreads_prio (void ) {return 0 ; }static inline void rcu_fwd_progress_check (unsigned long j) { }
@@ -527,6 +528,7 @@ bool rcu_dynticks_zero_in_eqs(int cpu, int *vp);unsigned long rcu_get_gp_seq (void );unsigned long rcu_exp_batches_completed (void );unsigned long srcu_batches_completed (struct srcu_struct *sp); +bool rcu_check_boost_fail (unsigned long gp_state,int *cpup);void show_rcu_gp_kthreads (void );int rcu_get_gp_kthreads_prio (void );void rcu_fwd_progress_check (unsigned long j);
kernel/rcu/rcutorture.c +41 -26
92 lines not on this page · raw message
kernel/rcu/tree_stall.h +36 -0
@@ -716,6 +716,42 @@ static void check_cpu_stall(struct rcu_data *rdp)// RCU forward-progress mechanisms, including of callback invocation. +/* +* Check to see if a failure to end RCU priority inversion was due to +* a CPU not passing through a quiescent state. When this happens, there +* is nothing that RCU priority boosting can do to help, so we shouldn't +* count this as an RCU priority boosting failure. A return of true says +* RCU priority boosting is to blame, and false says otherwise. If false +* is returned, the first of the CPUs to blame is stored through cpup. +*/ +bool rcu_check_boost_fail (unsigned long gp_state,int *cpup) +{ +int cpu; +unsigned long flags; +struct rcu_node *rnp; + +rcu_for_each_leaf_node (rnp) { +raw_spin_lock_irqsave_rcu_node (rnp, flags); +if (!rnp->qsmask) { +// No CPUs without quiescent states for this rnp. +raw_spin_unlock_irqrestore_rcu_node (rnp, flags); +continue ; + } +// Find the first holdout CPU. +for_each_leaf_node_possible_cpu (rnp, cpu) { +if (rnp->qsmask & (1UL << (cpu - rnp->grplo))) { +raw_spin_unlock_irqrestore_rcu_node (rnp, flags); + *cpup = cpu; +return false; + } + } +raw_spin_unlock_irqrestore_rcu_node (rnp, flags); + } +// Can't blame CPUs, so must blame RCU priority boosting. +return true; +} +EXPORT_SYMBOL_GPL (rcu_check_boost_fail); +/* * Show the state of the grace-period kthreads. */
Signature · 1 line
2.31.1.189.g2e36527f23
Paul E. McKenney
maintainerPATCH 22/26 rcutorture: Don't count CPU-stalled time against priority boosting
In reply to Paul E. McKenneyIt will frequently be the case that rcu_torture_boost() will get a ->start_gp_poll() cookie that needs almost all of the current grace period plus an additional grace period to elapse before ->poll_gp_state() will return true. It is quite possible that the current grace period will have (say) two seconds of stall by a CPU failing to pass through a quiescent state, followed by 300 milliseconds of delay due to a preempted reader. The next grace period might suffer only one second of stall by a CPU, followed by another 300 milliseconds of delay due to a preempted reader. This is an example of RCU priority boosting doing its job, but the full elapsed time of 3.6 seconds exceeds the 3.5-second limit. In addition, there is no CPU stall in force at the 3.5-second mark, so this would nevertheless currently be counted as an RCU priority boosting failure.
This commit therefore avoids this sort of false positive by resetting the gp_state_time timestamp any time that the current grace period is being blocked by a CPU. This results in extremely frequent calls to the ->check_boost_failed() function, so this commit provides a lockless fastpath that is selected by supplying a NULL CPU-number pointer.
--- kernel/rcu/rcutorture.c | 13 ++++++++----- kernel/rcu/tree_stall.h | 10 ++++++++++ 2 files changed, 18 insertions(+), 5 deletions(-)
kernel/rcu/rcutorture.c +8 -5
@@ -918,17 +918,18 @@ static void rcu_torture_enable_rt_throttle(void) old_rt_runtime =-1 ; } -static bool rcu_torture_boost_failed (unsigned long gp_state,unsigned long start,unsigned long end) +static bool rcu_torture_boost_failed (unsigned long gp_state,unsigned long *start) {int cpu;static int dbg_done; +unsigned long end = jiffies;bool gp_done;unsigned long j;static unsigned long last_persist;unsigned long lp;unsigned long mininterval = test_boost_duration *HZ -HZ /2 ; -if (end - start > mininterval) { +if (end - *start > mininterval) {// Recheck after checking time to avoid false positives. smp_mb ();// Time check before grace-period check. if (cur_ops->poll_gp_state (gp_state))
@@ -945,7 +946,7 @@ static bool rcu_torture_boost_failed(unsigned long gp_state, unsigned long start n_rcu_torture_boost_failure++;if (!xchg (&dbg_done,1 ) && cur_ops->gp_kthread_dbg) {pr_info ("Boost inversion thread ->rt_priority %u gp_state %lu jiffies %lu\n" , - current->rt_priority, gp_state, end - start); + current->rt_priority, gp_state, end - *start); cur_ops->gp_kthread_dbg ();// Recheck after print to flag grace period ending during splat. gp_done = cur_ops->poll_gp_state (gp_state);
@@ -955,6 +956,8 @@ static bool rcu_torture_boost_failed(unsigned long gp_state, unsigned long start }return true;// failed + }else if (cur_ops->check_boost_failed && !cur_ops->check_boost_failed (gp_state,NULL )) { + *start = jiffies; }return false;// passed
@@ -995,7 +998,7 @@ static int rcu_torture_boost(void *arg)while (time_before (jiffies, endtime)) {// Has current GP gone too long? if (gp_initiated && !failed && !cur_ops->poll_gp_state (gp_state)) - failed =rcu_torture_boost_failed (gp_state, gp_state_time, jiffies); + failed =rcu_torture_boost_failed (gp_state, &gp_state_time);// If we don't have a grace period in flight, start one. if (!gp_initiated || cur_ops->poll_gp_state (gp_state)) { gp_state = cur_ops->start_gp_poll ();
@@ -1016,7 +1019,7 @@ static int rcu_torture_boost(void *arg)// In case the grace period extended beyond the end of the loop. if (gp_initiated && !failed && !cur_ops->poll_gp_state (gp_state)) -rcu_torture_boost_failed (gp_state, gp_state_time, jiffies); +rcu_torture_boost_failed (gp_state, &gp_state_time);/* * Set the start time of the next test interval.
kernel/rcu/tree_stall.h +10 -0
@@ -723,6 +723,10 @@ static void check_cpu_stall(struct rcu_data *rdp)* count this as an RCU priority boosting failure. A return of true says * RCU priority boosting is to blame, and false says otherwise. If false * is returned, the first of the CPUs to blame is stored through cpup. +* +* If cpup is NULL, then a lockless quick check is carried out, suitable +* for high-rate usage. On the other hand, if cpup is non-NULL, each +* rcu_node structure's ->lock is acquired, ruling out high-rate usage. */ bool rcu_check_boost_fail (unsigned long gp_state,int *cpup) {
@@ -731,6 +735,12 @@ bool rcu_check_boost_fail(unsigned long gp_state, int *cpup)struct rcu_node *rnp;rcu_for_each_leaf_node (rnp) { +if (!cpup) { +if (READ_ONCE (rnp->qsmask)) +return false; +else +continue ; + }raw_spin_lock_irqsave_rcu_node (rnp, flags);if (!rnp->qsmask) {// No CPUs without quiescent states for this rnp.
Signature · 1 line
2.31.1.189.g2e36527f23
Paul E. McKenney
maintainerPATCH 23/26 torture: Make kvm-remote.sh account for network failure in pathname checks
In reply to Paul E. McKenneyIn a long-duration kvm-remote.sh run, almost all of the remote accesses will be simple file-existence checks. These are thus the most likely to be caught out by network failures, which do happen from time to time.
This commit therefore takes a first step towards tolerating temporary network outages by making the file-existence checks repeat in the face of such an outage. They also print a message every minute during a outage, allowing the user to take appropriate action.
--- .../selftests/rcutorture/bin/kvm-remote.sh | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-)
tools/testing/selftests/rcutorture/bin/kvm-remote.sh +24 -2
@@ -159,6 +159,28 @@ do fi done +# Function to check for presence of a file on the specified system. +# Complain if the system cannot be reached, and retry after a wait. +# Currently just waits forever if a machine disappears. +# +# Usage: checkremotefile system pathname +checkremotefile () { + local ret + local sleeptime=60 + + while : + do + ssh $1 "test -f \"$2\"" + ret=$? + if test "$ret" -ne 255 + then + return $ret + fi + echo " ---" ssh failure to $1 checking for file $2, retry after $sleeptime seconds. `date` + sleep $sleeptime + done +} + # Function to start batches on idle remote $systems # # Usage: startbatches curbatch nbatches
@@ -178,7 +200,7 @@ startbatches () { echo $((nbatches + 1)) return 0 fi - if ssh "$i" "test -f \"$resdir/$ds/remote.run\"" 1>&2 + if checkremotefile "$i" "$resdir/$ds/remote.run" 1>&2 then continue # System still running last test, skip. fi
@@ -216,7 +238,7 @@ echo All batches started. `date` # Wait for all remaining scenarios to complete and collect results. for i in $systems do - while ssh "$i" "test -f \"$resdir/$ds/remote.run\"" + while checkremotefile "$i" "$resdir/$ds/remote.run" do sleep 30 done
Signature · 1 line
2.31.1.189.g2e36527f23
Paul E. McKenney
maintainerPATCH 24/26 torture: Don't cap remote runs by build-system number of CPUs
In reply to Paul E. McKenneyCurrently, if a torture scenario requires more CPUs than are present on the build system, kvm.sh and friends limit the CPUs available to that scenario. This makes total sense when the build system and the system running the scenarios are one and the same, but not so much when remote systems might well have more CPUs.
This commit therefore introduces a --remote flag to kvm.sh that suppresses this CPU-limiting behavior, and causes kvm-remote.sh to use this flag.
--- .../testing/selftests/rcutorture/bin/kvm-remote.sh | 2 +- tools/testing/selftests/rcutorture/bin/kvm.sh | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-)
tools/testing/selftests/rcutorture/bin/kvm-remote.sh +1 -1
@@ -66,7 +66,7 @@ then if (ds != "") print "--datestamp " ds; }'`" - kvm.sh "$@" $datestamp --buildonly > $T/kvm.sh.out 2>&1 + kvm.sh --remote "$@" $datestamp --buildonly > $T/kvm.sh.out 2>&1 ret=$? if test "$ret" -ne 0 then
tools/testing/selftests/rcutorture/bin/kvm.sh +11 -3
@@ -44,6 +44,7 @@ TORTURE_KCONFIG_KASAN_ARG="" TORTURE_KCONFIG_KCSAN_ARG="" TORTURE_KMAKE_ARG="" TORTURE_QEMU_MEM=512 +TORTURE_REMOTE= TORTURE_SHUTDOWN_GRACE=180 TORTURE_SUITE=rcu TORTURE_MOD=rcutorture
@@ -80,6 +81,7 @@ usage () { echo " --no-initrd" echo " --qemu-args qemu-arguments" echo " --qemu-cmd qemu-system-..." + echo " --remote" echo " --results absolute-pathname" echo " --torture lock|rcu|rcuscale|refscale|scf" echo " --trust-make"
@@ -115,10 +117,13 @@ do checkarg --cpus "(number)" "$#" "$2" '^[0-9]*$' '^--' cpus=$2 TORTURE_ALLOTED_CPUS="$2" - max_cpus="`identify_qemu_vcpus`" - if test "$TORTURE_ALLOTED_CPUS" -gt "$max_cpus" + if test -z "$TORTURE_REMOTE" then - TORTURE_ALLOTED_CPUS=$max_cpus + max_cpus="`identify_qemu_vcpus`" + if test "$TORTURE_ALLOTED_CPUS" -gt "$max_cpus" + then + TORTURE_ALLOTED_CPUS=$max_cpus + fi fi shift ;;
@@ -209,6 +214,9 @@ do TORTURE_QEMU_CMD="$2" shift ;; + --remote) + TORTURE_REMOTE=1 + ;; --results) checkarg --results "(absolute pathname)" "$#" "$2" '^/' '^error' resdir=$2
Signature · 1 line
2.31.1.189.g2e36527f23
Paul E. McKenney
maintainerPATCH 25/26 rcutorture: Move mem_dump_obj() tests into separate function
In reply to Paul E. McKenneyTo make the purpose of the code more apparent, this commit moves the tests of mem_dump_obj() to a new rcu_torture_mem_dump_obj() function and calls it from rcu_torture_cleanup().
--- kernel/rcu/rcutorture.c | 81 +++++++++++++++++++++-------------------- 1 file changed, 42 insertions(+), 39 deletions(-)
kernel/rcu/rcutorture.c +42 -39
@@ -1868,48 +1868,49 @@ rcu_torture_stats(void *arg)torture_shutdown_absorb ("rcu_torture_stats" ); }while (!torture_must_stop ());torture_kthread_stopping ("rcu_torture_stats" ); - - { -struct rcu_head *rhp; -struct kmem_cache *kcp; -static int z; - - kcp =kmem_cache_create ("rcuscale" ,136 ,8 ,SLAB_STORE_USER ,NULL ); - rhp =kmem_cache_alloc (kcp,GFP_KERNEL ); -pr_alert ("mem_dump_obj() slab test: rcu_torture_stats = %px, &rhp = %px, rhp = %px, &z = %px\n" , stats_task, &rhp, rhp, &z); -pr_alert ("mem_dump_obj(ZERO_SIZE_PTR):" ); -mem_dump_obj (ZERO_SIZE_PTR ); -pr_alert ("mem_dump_obj(NULL):" ); -mem_dump_obj (NULL ); -pr_alert ("mem_dump_obj(%px):" , &rhp); -mem_dump_obj (&rhp); -pr_alert ("mem_dump_obj(%px):" , rhp); -mem_dump_obj (rhp); -pr_alert ("mem_dump_obj(%px):" , &rhp->func); -mem_dump_obj (&rhp->func); -pr_alert ("mem_dump_obj(%px):" , &z); -mem_dump_obj (&z); -kmem_cache_free (kcp, rhp); -kmem_cache_destroy (kcp); - rhp =kmalloc (sizeof (*rhp),GFP_KERNEL ); -pr_alert ("mem_dump_obj() kmalloc test: rcu_torture_stats = %px, &rhp = %px, rhp = %px\n" , stats_task, &rhp, rhp); -pr_alert ("mem_dump_obj(kmalloc %px):" , rhp); -mem_dump_obj (rhp); -pr_alert ("mem_dump_obj(kmalloc %px):" , &rhp->func); -mem_dump_obj (&rhp->func); -kfree (rhp); - rhp =vmalloc (4096 ); -pr_alert ("mem_dump_obj() vmalloc test: rcu_torture_stats = %px, &rhp = %px, rhp = %px\n" , stats_task, &rhp, rhp); -pr_alert ("mem_dump_obj(vmalloc %px):" , rhp); -mem_dump_obj (rhp); -pr_alert ("mem_dump_obj(vmalloc %px):" , &rhp->func); -mem_dump_obj (&rhp->func); -vfree (rhp); - } -return 0 ; } +/* Test mem_dump_obj() and friends. */ +static void rcu_torture_mem_dump_obj (void ) +{ +struct rcu_head *rhp; +struct kmem_cache *kcp; +static int z; + + kcp =kmem_cache_create ("rcuscale" ,136 ,8 ,SLAB_STORE_USER ,NULL ); + rhp =kmem_cache_alloc (kcp,GFP_KERNEL ); +pr_alert ("mem_dump_obj() slab test: rcu_torture_stats = %px, &rhp = %px, rhp = %px, &z = %px\n" , stats_task, &rhp, rhp, &z); +pr_alert ("mem_dump_obj(ZERO_SIZE_PTR):" ); +mem_dump_obj (ZERO_SIZE_PTR ); +pr_alert ("mem_dump_obj(NULL):" ); +mem_dump_obj (NULL ); +pr_alert ("mem_dump_obj(%px):" , &rhp); +mem_dump_obj (&rhp); +pr_alert ("mem_dump_obj(%px):" , rhp); +mem_dump_obj (rhp); +pr_alert ("mem_dump_obj(%px):" , &rhp->func); +mem_dump_obj (&rhp->func); +pr_alert ("mem_dump_obj(%px):" , &z); +mem_dump_obj (&z); +kmem_cache_free (kcp, rhp); +kmem_cache_destroy (kcp); + rhp =kmalloc (sizeof (*rhp),GFP_KERNEL ); +pr_alert ("mem_dump_obj() kmalloc test: rcu_torture_stats = %px, &rhp = %px, rhp = %px\n" , stats_task, &rhp, rhp); +pr_alert ("mem_dump_obj(kmalloc %px):" , rhp); +mem_dump_obj (rhp); +pr_alert ("mem_dump_obj(kmalloc %px):" , &rhp->func); +mem_dump_obj (&rhp->func); +kfree (rhp); + rhp =vmalloc (4096 ); +pr_alert ("mem_dump_obj() vmalloc test: rcu_torture_stats = %px, &rhp = %px, rhp = %px\n" , stats_task, &rhp, rhp); +pr_alert ("mem_dump_obj(vmalloc %px):" , rhp); +mem_dump_obj (rhp); +pr_alert ("mem_dump_obj(vmalloc %px):" , &rhp->func); +mem_dump_obj (&rhp->func); +vfree (rhp); +} +static void rcu_torture_print_module_parms (struct rcu_torture_ops *cur_ops,const char *tag) {
@@ -2825,6 +2826,8 @@ rcu_torture_cleanup(void)if (cur_ops->cleanup !=NULL ) cur_ops->cleanup (); +rcu_torture_mem_dump_obj (); +rcu_torture_stats_print ();/* -After- the stats thread is stopped! */ if (err_segs_recorded) {
Signature · 1 line
2.31.1.189.g2e36527f23
Paul E. McKenney
maintainerPATCH 26/26 rcu: Don't penalize priority boosting when there is nothing to boost
In reply to Paul E. McKenneyRCU priority boosting cannot do anything unless there is at least one task blocking the current RCU grace period that was preempted within the RCU read-side critical section that it still resides in. However, the current rcu_torture_boost_failed() code will count this as an RCU priority-boosting failure if there were no CPUs blocking the current grace period. This situation can happen (for example) if the last CPU blocking the current grace period was subjected to vCPU preemption, which is always a risk for rcutorture guest OSes.
This commit therefore causes rcu_torture_boost_failed() to refrain from reporting failure unless there is at least one task blocking the current RCU grace period that was preempted within the RCU read-side critical section that it still resides in.
--- kernel/rcu/tree_stall.h | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)
kernel/rcu/tree_stall.h +14 -3
@@ -723,6 +723,10 @@ static void check_cpu_stall(struct rcu_data *rdp)* count this as an RCU priority boosting failure. A return of true says * RCU priority boosting is to blame, and false says otherwise. If false * is returned, the first of the CPUs to blame is stored through cpup. +* If there was no CPU blocking the current grace period, but also nothing +* in need of being boosted, *cpup is set to -1. This can happen in case +* of vCPU preemption while the last CPU is reporting its quiscent state, +* for example. * * If cpup is NULL, then a lockless quick check is carried out, suitable * for high-rate usage. On the other hand, if cpup is non-NULL, each
@@ -730,18 +734,25 @@ static void check_cpu_stall(struct rcu_data *rdp)*/ bool rcu_check_boost_fail (unsigned long gp_state,int *cpup) { +bool atb = false;int cpu;unsigned long flags;struct rcu_node *rnp;rcu_for_each_leaf_node (rnp) {if (!cpup) { -if (READ_ONCE (rnp->qsmask)) +if (READ_ONCE (rnp->qsmask)) {return false; -else + }else { +if (READ_ONCE (rnp->gp_tasks)) + atb = true;continue ; + } } + *cpup =-1 ;raw_spin_lock_irqsave_rcu_node (rnp, flags); +if (rnp->gp_tasks) + atb = true;if (!rnp->qsmask) {// No CPUs without quiescent states for this rnp. raw_spin_unlock_irqrestore_rcu_node (rnp, flags);
@@ -758,7 +769,7 @@ bool rcu_check_boost_fail(unsigned long gp_state, int *cpup)raw_spin_unlock_irqrestore_rcu_node (rnp, flags); }// Can't blame CPUs, so must blame RCU priority boosting. -return true; +return atb; }EXPORT_SYMBOL_GPL (rcu_check_boost_fail);
Signature · 1 line
2.31.1.189.g2e36527f23
Paul E. McKenney
maintainerPATCH 1/10 kcsan: Add pointer to access-marking.txt to data_race() bullet
In reply to Paul E. McKenneyThis commit references tools/memory-model/Documentation/access-marking.txt in the bullet introducing data_race(). The access-marking.txt file gives advice on when data_race() should and should not be used.
--- Documentation/dev-tools/kcsan.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
Documentation/dev-tools/kcsan.rst +3 -1
@@ -106,7 +106,9 @@ the below options are available: * KCSAN understands the ``data_race(expr)`` annotation, which tells KCSAN that any data races due to accesses in ``expr`` should be ignored and resulting - behaviour when encountering a data race is deemed safe. + behaviour when encountering a data race is deemed safe. Please see + ``tools/memory-model/Documentation/access-marking.txt`` in the kernel source + tree for more information. * Disabling data race detection for entire functions can be accomplished by using the function attribute ``__no_kcsan``::
Signature · 1 line
2.31.1.189.g2e36527f23
Re: [PATCH tip/core/rcu 01/10] kcsan: Add pointer to access-marking.txt to data_race() bullet
Hi Paul,
Quoted 16 lines · Paul E. McKenney
This commit references
tools/memory-model/Documentation/access-marking.txtin the bullet introducingdata_race(). The access-marking.txt file gives advice on whendata_race()should and should not be used.Suggested-by Akira Yokosawa <[email protected]>Signed-off-by Paul E. McKenney <[email protected]>--- Documentation/dev-tools/kcsan.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)Documentation/dev-tools/kcsan.rst +0
-0
Documentation/dev-tools/kcsan.rst the below options are available: · line 114
Quoted 10 lines
Documentation/dev-tools/kcsan.rst +3
-1@@ -106,7 +106,9 @@ the below options are available: * KCSAN understands the ``data_race(expr)`` annotation, which tells KCSAN that any data races due to accesses in ``expr`` should be ignored and resulting - behaviour when encountering a data race is deemed safe. + behaviour when encountering a data race is deemed safe. Please see + ``tools/memory-model/Documentation/access-marking.txt`` in the kernel source + tree for more information. * Disabling data race detection for entire functions can be accomplished by using the function attribute ``__no_kcsan``::
I think this needs some adjustment for overall consistency. A possible follow-up patch (relative to the change above) would look like the following.
Thoughts?
Thanks, Akira
-------8<--------
From: Akira Yokosawa <[email protected]>
Subject: [PATCH] kcsan: Use URL link for pointing access-marking.txt
For consistency within kcsan.rst, use a URL link as the same as in section "Data Races".
--- Documentation/dev-tools/kcsan.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
Documentation/dev-tools/kcsan.rst +3 -2
@@ -107,8 +107,7 @@ the below options are available: * KCSAN understands the ``data_race(expr)`` annotation, which tells KCSAN that any data races due to accesses in ``expr`` should be ignored and resulting behaviour when encountering a data race is deemed safe. Please see - ``tools/memory-model/Documentation/access-marking.txt`` in the kernel source - tree for more information. + `"Marking Shared-Memory Accesses" in the LKMM`_ for more information. * Disabling data race detection for entire functions can be accomplished by using the function attribute ``__no_kcsan``::
@@ -130,6 +129,8 @@ the below options are available: KCSAN_SANITIZE := n +.. _"Marking Shared-Memory Accesses" in the LKMM: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/memory-model/Documentation/access-marking.txt + Furthermore, it is possible to tell KCSAN to show or hide entire classes of data races, depending on preferences. These can be changed via the following Kconfig options:
Signature · 1 line
2.17.1
Re: [PATCH tip/core/rcu 01/10] kcsan: Add pointer to access-marking.txt to data_race() bullet
Quoted 43 lines · Akira Yokosawa
Hi Paul,
Quoted 16 lines · Paul E. McKenney
This commit references
tools/memory-model/Documentation/access-marking.txtin the bullet introducingdata_race(). The access-marking.txt file gives advice on whendata_race()should and should not be used.Suggested-by Akira Yokosawa <[email protected]>Signed-off-by Paul E. McKenney <[email protected]>--- Documentation/dev-tools/kcsan.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)Documentation/dev-tools/kcsan.rst +0
-0Documentation/dev-tools/kcsan.rst the below options are available: · line 114
Quoted 10 lines
Documentation/dev-tools/kcsan.rst +3
-1@@ -106,7 +106,9 @@ the below options are available: * KCSAN understands the ``data_race(expr)`` annotation, which tells KCSAN that any data races due to accesses in ``expr`` should be ignored and resulting - behaviour when encountering a data race is deemed safe. + behaviour when encountering a data race is deemed safe. Please see + ``tools/memory-model/Documentation/access-marking.txt`` in the kernel source + tree for more information. * Disabling data race detection for entire functions can be accomplished by using the function attribute ``__no_kcsan``::I think this needs some adjustment for overall consistency. A possible follow-up patch (relative to the change above) would look like the following.
Thoughts?
Thanks, Akira
-------8<--------
From: Akira Yokosawa <[email protected]>
Subject: [PATCH] kcsan: Use URL link for pointing access-marking.txt
Quoted 5 lines
For consistency within
kcsan.rst, use a URL link as the same as in section "Data Races".Signed-off-by Akira Yokosawa <[email protected]>Cc Paul E. McKenney <[email protected]>
Good catch. I'd be in favour of this change, as it makes it simpler to just follow the link. Because in most cases I usually just point folks at the rendered version of this:
https://www.kernel.org/doc/html/latest/dev-tools/kcsan.html
Quoted 29 lines
--- Documentation/dev-tools/kcsan.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)Documentation/dev-tools/kcsan.rst +3
-3@@ -107,8 +107,7 @@ the below options are available: * KCSAN understands the ``data_race(expr)`` annotation, which tells KCSAN that any data races due to accesses in ``expr`` should be ignored and resulting behaviour when encountering a data race is deemed safe. Please see - ``tools/memory-model/Documentation/access-marking.txt`` in the kernel source - tree for more information. + `"Marking Shared-Memory Accesses" in the LKMM`_ for more information. * Disabling data race detection for entire functions can be accomplished by using the function attribute ``__no_kcsan``::@@ -130,6 +129,8 @@ the below options are available: KCSAN_SANITIZE := n +.. _"Marking Shared-Memory Accesses" in the LKMM: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/memory-model/Documentation/access-marking.txt + Furthermore, it is possible to tell KCSAN to show or hide entire classes of data races, depending on preferences. These can be changed via the following Kconfig options: --2.17.1
Re: [PATCH tip/core/rcu 01/10] kcsan: Add pointer to access-marking.txt to data_race() bullet
Quoted 50 lines · Marco Elver
Quoted 43 lines · Akira Yokosawa
Hi Paul,
Quoted 16 lines · Paul E. McKenney
This commit references
tools/memory-model/Documentation/access-marking.txtin the bullet introducingdata_race(). The access-marking.txt file gives advice on whendata_race()should and should not be used.Suggested-by Akira Yokosawa <[email protected]>Signed-off-by Paul E. McKenney <[email protected]>--- Documentation/dev-tools/kcsan.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)Documentation/dev-tools/kcsan.rst +0
-0Documentation/dev-tools/kcsan.rst the below options are available: · line 114
Quoted 10 lines
Documentation/dev-tools/kcsan.rst +3
-1@@ -106,7 +106,9 @@ the below options are available: * KCSAN understands the ``data_race(expr)`` annotation, which tells KCSAN that any data races due to accesses in ``expr`` should be ignored and resulting - behaviour when encountering a data race is deemed safe. + behaviour when encountering a data race is deemed safe. Please see + ``tools/memory-model/Documentation/access-marking.txt`` in the kernel source + tree for more information. * Disabling data race detection for entire functions can be accomplished by using the function attribute ``__no_kcsan``::I think this needs some adjustment for overall consistency. A possible follow-up patch (relative to the change above) would look like the following.
Thoughts?
Thanks, Akira
-------8<--------
From: Akira Yokosawa <[email protected]>
Subject: [PATCH] kcsan: Use URL link for pointing access-marking.txtQuoted 5 lines
For consistency within
kcsan.rst, use a URL link as the same as in section "Data Races".Signed-off-by Akira Yokosawa <[email protected]>Cc Paul E. McKenney <[email protected]>
Quoted 6 lines
Good catch. I'd be in favour of this change, as it makes it simpler to just follow the link. Because in most cases I usually just point folks at the rendered version of this:
https://www.kernel.org/doc/html/latest/dev-tools/kcsan.htmlAcked-by Marco Elver <[email protected]>
Queued with Marco's ack, thank you both!
Thanx, Paul
Quoted 29 lines
Quoted 29 lines
--- Documentation/dev-tools/kcsan.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)Documentation/dev-tools/kcsan.rst +3
-3@@ -107,8 +107,7 @@ the below options are available: * KCSAN understands the ``data_race(expr)`` annotation, which tells KCSAN that any data races due to accesses in ``expr`` should be ignored and resulting behaviour when encountering a data race is deemed safe. Please see - ``tools/memory-model/Documentation/access-marking.txt`` in the kernel source - tree for more information. + `"Marking Shared-Memory Accesses" in the LKMM`_ for more information. * Disabling data race detection for entire functions can be accomplished by using the function attribute ``__no_kcsan``::@@ -130,6 +129,8 @@ the below options are available: KCSAN_SANITIZE := n +.. _"Marking Shared-Memory Accesses" in the LKMM: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/memory-model/Documentation/access-marking.txt + Furthermore, it is possible to tell KCSAN to show or hide entire classes of data races, depending on preferences. These can be changed via the following Kconfig options: --2.17.1
Paul E. McKenney
maintainerPATCH 2/10 kcsan: Simplify value change detection
In reply to Paul E. McKenneyFrom: Mark Rutland <[email protected]>
In kcsan_setup_watchpoint() we store snapshots of a watched value into a union of u8/u16/u32/u64 sized fields, modify this in place using a consistent field, then later check for any changes via the u64 field.
We can achieve the safe effect more simply by always treating the field as a u64, as smaller values will be zero-extended. As the values are zero-extended, we don't need to truncate the access_mask when we apply it, and can always apply the full 64-bit access_mask to the 64-bit value.
Finally, we can store the two snapshots and calculated difference separately, which makes the code a little easier to read, and will permit reporting the old/new values in subsequent patches.
There should be no functional change as a result of this patch.
--- kernel/kcsan/core.c | 40 ++++++++++++++++------------------------ 1 file changed, 16 insertions(+), 24 deletions(-)
kernel/kcsan/core.c +16 -24
@@ -407,12 +407,7 @@ kcsan_setup_watchpoint(const volatile void *ptr, size_t size, int type)const bool is_write = (type &KCSAN_ACCESS_WRITE ) !=0 ;const bool is_assert = (type &KCSAN_ACCESS_ASSERT ) !=0 ;atomic_long_t *watchpoint; -union { -u8 _1; -u16 _2; -u32 _4; -u64 _8; - } expect_value; +u64 old, new, diff;unsigned long access_mask;enum kcsan_value_change value_change =KCSAN_VALUE_CHANGE_MAYBE ;unsigned long ua_flags =user_access_save ();
@@ -468,19 +463,19 @@ kcsan_setup_watchpoint(const volatile void *ptr, size_t size, int type)* Read the current value, to later check and infer a race if the data * was modified via a non-instrumented access, e.g. from a device. */ - expect_value._8 =0 ; + old =0 ;switch (size) {case 1 : - expect_value._1 =READ_ONCE (*(const u8 *)ptr); + old =READ_ONCE (*(const u8 *)ptr);break ;case 2 : - expect_value._2 =READ_ONCE (*(const u16 *)ptr); + old =READ_ONCE (*(const u16 *)ptr);break ;case 4 : - expect_value._4 =READ_ONCE (*(const u32 *)ptr); + old =READ_ONCE (*(const u32 *)ptr);break ;case 8 : - expect_value._8 =READ_ONCE (*(const u64 *)ptr); + old =READ_ONCE (*(const u64 *)ptr);break ;default :break ;/* ignore; we do not diff the values */
@@ -506,33 +501,30 @@ kcsan_setup_watchpoint(const volatile void *ptr, size_t size, int type)* racy access. */ access_mask =get_ctx ()->access_mask; + new =0 ;switch (size) {case 1 : - expect_value._1 ^=READ_ONCE (*(const u8 *)ptr); -if (access_mask) - expect_value._1 &= (u8 )access_mask; + new =READ_ONCE (*(const u8 *)ptr);break ;case 2 : - expect_value._2 ^=READ_ONCE (*(const u16 *)ptr); -if (access_mask) - expect_value._2 &= (u16 )access_mask; + new =READ_ONCE (*(const u16 *)ptr);break ;case 4 : - expect_value._4 ^=READ_ONCE (*(const u32 *)ptr); -if (access_mask) - expect_value._4 &= (u32 )access_mask; + new =READ_ONCE (*(const u32 *)ptr);break ;case 8 : - expect_value._8 ^=READ_ONCE (*(const u64 *)ptr); -if (access_mask) - expect_value._8 &= (u64 )access_mask; + new =READ_ONCE (*(const u64 *)ptr);break ;default :break ;/* ignore; we do not diff the values */ } + diff = old ^ new; +if (access_mask) + diff &= access_mask; +/* Were we able to observe a value-change? */ -if (expect_value._8 !=0 ) +if (diff !=0 ) value_change =KCSAN_VALUE_CHANGE_TRUE ;/* Check if this access raced with another. */
Signature · 1 line
2.31.1.189.g2e36527f23
Paul E. McKenney
maintainerPATCH 3/10 kcsan: Distinguish kcsan_report() calls
In reply to Paul E. McKenneyFrom: Mark Rutland <[email protected]>
Currently kcsan_report() is used to handle three distinct cases:
* The caller hit a watchpoint when attempting an access. Some information regarding the caller and access are recorded, but no output is produced.
* A caller which previously setup a watchpoint detected that the watchpoint has been hit, and possibly detected a change to the location in memory being watched. This may result in output reporting the interaction between this caller and the caller which hit the watchpoint.
* A caller detected a change to a modification to a memory location which wasn't detected by a watchpoint, for which there is no information on the other thread. This may result in output reporting the unexpected change.
... depending on the specific case the caller has distinct pieces of information available, but the prototype of kcsan_report() has to handle all three cases. This means that in some cases we pass redundant information, and in others we don't pass all the information we could pass. This also means that the report code has to demux these three cases.
So that we can pass some additional information while also simplifying the callers and report code, add separate kcsan_report_*() functions for the distinct cases, updating callers accordingly. As the watchpoint_idx is unused in the case of kcsan_report_unknown_origin(), this passes a dummy value into kcsan_report(). Subsequent patches will refactor the report code to avoid this.
There should be no functional change as a result of this patch.
--- kernel/kcsan/core.c | 12 ++++-------- kernel/kcsan/kcsan.h | 10 ++++++---- kernel/kcsan/report.c | 26 +++++++++++++++++++++++--- 3 files changed, 33 insertions(+), 15 deletions(-)
kernel/kcsan/core.c +4 -8
@@ -380,9 +380,7 @@ static noinline void kcsan_found_watchpoint(const volatile void *ptr,if (consumed) {kcsan_save_irqtrace (current); -kcsan_report (ptr, size, type,KCSAN_VALUE_CHANGE_MAYBE , -KCSAN_REPORT_CONSUMED_WATCHPOINT , - watchpoint - watchpoints); +kcsan_report_set_info (ptr, size, type, watchpoint - watchpoints);kcsan_restore_irqtrace (current); }else {/*
@@ -558,8 +556,8 @@ kcsan_setup_watchpoint(const volatile void *ptr, size_t size, int type)if (is_assert && value_change ==KCSAN_VALUE_CHANGE_TRUE )atomic_long_inc (&kcsan_counters[KCSAN_COUNTER_ASSERT_FAILURES ]); -kcsan_report (ptr, size, type, value_change,KCSAN_REPORT_RACE_SIGNAL , - watchpoint - watchpoints); +kcsan_report_known_origin (ptr, size, type, value_change, + watchpoint - watchpoints); }else if (value_change ==KCSAN_VALUE_CHANGE_TRUE ) {/* Inferring a race, since the value should not have changed. */
@@ -568,9 +566,7 @@ kcsan_setup_watchpoint(const volatile void *ptr, size_t size, int type)atomic_long_inc (&kcsan_counters[KCSAN_COUNTER_ASSERT_FAILURES ]);if (IS_ENABLED (CONFIG_KCSAN_REPORT_RACE_UNKNOWN_ORIGIN ) || is_assert) -kcsan_report (ptr, size, type,KCSAN_VALUE_CHANGE_TRUE , -KCSAN_REPORT_RACE_UNKNOWN_ORIGIN , - watchpoint - watchpoints); +kcsan_report_unknown_origin (ptr, size, type); }/*
kernel/kcsan/kcsan.h +6 -4
@@ -136,10 +136,12 @@ enum kcsan_report_type { };/* -* Print a race report from thread that encountered the race. +* Notify the report code that a race occurred. */ -extern void kcsan_report (const volatile void *ptr,size_t size,int access_type, -enum kcsan_value_change value_change, -enum kcsan_report_type type,int watchpoint_idx); +void kcsan_report_set_info (const volatile void *ptr,size_t size,int access_type, +int watchpoint_idx); +void kcsan_report_known_origin (const volatile void *ptr,size_t size,int access_type, +enum kcsan_value_change value_change,int watchpoint_idx); +void kcsan_report_unknown_origin (const volatile void *ptr,size_t size,int access_type);#endif /* _KERNEL_KCSAN_KCSAN_H */
kernel/kcsan/report.c +23 -3
@@ -598,9 +598,9 @@ static noinline bool prepare_report(unsigned long *flags, } } -void kcsan_report (const volatile void *ptr,size_t size,int access_type, -enum kcsan_value_change value_change, -enum kcsan_report_type type,int watchpoint_idx) +static void kcsan_report (const volatile void *ptr,size_t size,int access_type, +enum kcsan_value_change value_change, +enum kcsan_report_type type,int watchpoint_idx) {unsigned long flags =0 ;const struct access_info ai = {
@@ -645,3 +645,23 @@ void kcsan_report(const volatile void *ptr, size_t size, int access_type, out:kcsan_enable_current (); } + +void kcsan_report_set_info (const volatile void *ptr,size_t size,int access_type, +int watchpoint_idx) +{ +kcsan_report (ptr, size, access_type,KCSAN_VALUE_CHANGE_MAYBE , +KCSAN_REPORT_CONSUMED_WATCHPOINT , watchpoint_idx); +} + +void kcsan_report_known_origin (const volatile void *ptr,size_t size,int access_type, +enum kcsan_value_change value_change,int watchpoint_idx) +{ +kcsan_report (ptr, size, access_type, value_change, +KCSAN_REPORT_RACE_SIGNAL , watchpoint_idx); +} + +void kcsan_report_unknown_origin (const volatile void *ptr,size_t size,int access_type) +{ +kcsan_report (ptr, size, access_type,KCSAN_VALUE_CHANGE_TRUE , +KCSAN_REPORT_RACE_UNKNOWN_ORIGIN ,0 ); +}
Signature · 1 line
2.31.1.189.g2e36527f23
Paul E. McKenney
maintainerPATCH 4/10 kcsan: Refactor passing watchpoint/other_info
In reply to Paul E. McKenneyFrom: Mark Rutland <[email protected]>
The watchpoint_idx argument to kcsan_report() isn't meaningful for races which were not detected by a watchpoint, and it would be clearer if callers passed the other_info directly so that a NULL value can be passed in this case.
Given that callers manipulate their watchpoints before passing the index into kcsan_report_*(), and given we index the other_infos array using this before we sanity-check it, the subsequent sanity check isn't all that useful.
Let's remove the watchpoint_idx sanity check, and move the job of finding the other_info out of kcsan_report().
Other than the removal of the check, there should be no functional change as a result of this patch.
--- kernel/kcsan/report.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-)
kernel/kcsan/report.c +4 -9
@@ -600,7 +600,7 @@ static noinline bool prepare_report(unsigned long *flags,static void kcsan_report (const volatile void *ptr,size_t size,int access_type,enum kcsan_value_change value_change, -enum kcsan_report_type type,int watchpoint_idx) +enum kcsan_report_type type,struct other_info *other_info) {unsigned long flags =0 ;const struct access_info ai = {
@@ -610,12 +610,8 @@ static void kcsan_report(const volatile void *ptr, size_t size, int access_type, .task_pid = in_task() ? task_pid_nr(current) : -1, .cpu_id = raw_smp_processor_id() }; -struct other_info *other_info = type ==KCSAN_REPORT_RACE_UNKNOWN_ORIGIN - ?NULL : &other_infos[watchpoint_idx];kcsan_disable_current (); -if (WARN_ON (watchpoint_idx <0 || watchpoint_idx >=ARRAY_SIZE (other_infos))) - goto out;/* * Because we may generate reports when we're in scheduler code, the use
@@ -642,7 +638,6 @@ static void kcsan_report(const volatile void *ptr, size_t size, int access_type, }lockdep_on (); -out:kcsan_enable_current (); }
@@ -650,18 +645,18 @@ void kcsan_report_set_info(const volatile void *ptr, size_t size, int access_typ int watchpoint_idx) {kcsan_report (ptr, size, access_type,KCSAN_VALUE_CHANGE_MAYBE , -KCSAN_REPORT_CONSUMED_WATCHPOINT , watchpoint_idx); +KCSAN_REPORT_CONSUMED_WATCHPOINT , &other_infos[watchpoint_idx]); }void kcsan_report_known_origin (const volatile void *ptr,size_t size,int access_type,enum kcsan_value_change value_change,int watchpoint_idx) {kcsan_report (ptr, size, access_type, value_change, -KCSAN_REPORT_RACE_SIGNAL , watchpoint_idx); +KCSAN_REPORT_RACE_SIGNAL , &other_infos[watchpoint_idx]); }void kcsan_report_unknown_origin (const volatile void *ptr,size_t size,int access_type) {kcsan_report (ptr, size, access_type,KCSAN_VALUE_CHANGE_TRUE , -KCSAN_REPORT_RACE_UNKNOWN_ORIGIN ,0 ); +KCSAN_REPORT_RACE_UNKNOWN_ORIGIN ,NULL ); }
Signature · 1 line
2.31.1.189.g2e36527f23
Paul E. McKenney
maintainerPATCH 5/10 kcsan: Fold panic() call into print_report()
In reply to Paul E. McKenneyFrom: Mark Rutland <[email protected]>
So that we can add more callers of print_report(), lets fold the panic() call into print_report() so the caller doesn't have to handle this explicitly.
There should be no functional change as a result of this patch.
--- kernel/kcsan/report.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-)
kernel/kcsan/report.c +8 -13
@@ -325,10 +325,7 @@ static void print_verbose_info(struct task_struct *task)print_irqtrace_events (task); } -/* -* Returns true if a report was generated, false otherwise. -*/ -static bool print_report (enum kcsan_value_change value_change, +static void print_report (enum kcsan_value_change value_change,enum kcsan_report_type type,const struct access_info *ai,const struct other_info *other_info)
@@ -344,7 +341,7 @@ static bool print_report(enum kcsan_value_change value_change,* Must check report filter rules before starting to print. */ if (skip_report (KCSAN_VALUE_CHANGE_TRUE , stack_entries[skipnr])) -return false; +return ;if (type ==KCSAN_REPORT_RACE_SIGNAL ) { other_skipnr = get_stack_skipnr(other_info->stack_entries,
@@ -353,11 +350,11 @@ static bool print_report(enum kcsan_value_change value_change,/* @value_change is only known for the other thread */ if (skip_report (value_change, other_frame)) -return false; +return ; }if (rate_limit_report (this_frame, other_frame)) -return false; +return ;/* Print report header. */ pr_err ("==================================================================\n" );
@@ -431,7 +428,8 @@ static bool print_report(enum kcsan_value_change value_change,dump_stack_print_info (KERN_DEFAULT );pr_err ("==================================================================\n" ); -return true; +if (panic_on_warn) +panic ("panic_on_warn set ...\n" ); }static void release_report (unsigned long *flags,struct other_info *other_info)
@@ -628,11 +626,8 @@ static void kcsan_report(const volatile void *ptr, size_t size, int access_type,* either TRUE or MAYBE. In case of MAYBE, further filtering may * be done once we know the full stack trace in print_report(). */ -bool reported = value_change !=KCSAN_VALUE_CHANGE_FALSE && -print_report (value_change, type, &ai, other_info); - -if (reported && panic_on_warn) -panic ("panic_on_warn set ...\n" ); +if (value_change !=KCSAN_VALUE_CHANGE_FALSE ) +print_report (value_change, type, &ai, other_info);release_report (&flags, other_info); }
Signature · 1 line
2.31.1.189.g2e36527f23
Paul E. McKenney
maintainerPATCH 6/10 kcsan: Refactor access_info initialization
In reply to Paul E. McKenneyFrom: Mark Rutland <[email protected]>
In subsequent patches we'll want to split kcsan_report() into distinct handlers for each report type. The largest bit of common work is initializing the access_info, so let's factor this out into a helper, and have the kcsan_report_*() functions pass the aaccess_info as a parameter to kcsan_report().
There should be no functional change as a result of this patch.
--- kernel/kcsan/report.c | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-)
kernel/kcsan/report.c +25 -17
@@ -596,18 +596,10 @@ static noinline bool prepare_report(unsigned long *flags, } } -static void kcsan_report (const volatile void *ptr,size_t size,int access_type, -enum kcsan_value_change value_change, +static void kcsan_report (const struct access_info *ai,enum kcsan_value_change value_change,enum kcsan_report_type type,struct other_info *other_info) {unsigned long flags =0 ; -const struct access_info ai = { - .ptr = ptr, - .size = size, - .access_type = access_type, - .task_pid =in_task () ?task_pid_nr (current) :-1 , - .cpu_id =raw_smp_processor_id () - };kcsan_disable_current ();
@@ -620,14 +612,14 @@ static void kcsan_report(const volatile void *ptr, size_t size, int access_type,*/ lockdep_off (); -if (prepare_report (&flags, type, &ai, other_info)) { +if (prepare_report (&flags, type, ai, other_info)) {/* * Never report if value_change is FALSE, only if we it is * either TRUE or MAYBE. In case of MAYBE, further filtering may * be done once we know the full stack trace in print_report(). */ if (value_change !=KCSAN_VALUE_CHANGE_FALSE ) -print_report (value_change, type, &ai, other_info); +print_report (value_change, type, ai, other_info);release_report (&flags, other_info); }
@@ -636,22 +628,38 @@ static void kcsan_report(const volatile void *ptr, size_t size, int access_type,kcsan_enable_current (); } +static struct access_info prepare_access_info (const volatile void *ptr,size_t size, +int access_type) +{ +return (struct access_info ) { + .ptr = ptr, + .size = size, + .access_type = access_type, + .task_pid =in_task () ?task_pid_nr (current) :-1 , + .cpu_id =raw_smp_processor_id () + }; +} +void kcsan_report_set_info (const volatile void *ptr,size_t size,int access_type,int watchpoint_idx) { -kcsan_report (ptr, size, access_type,KCSAN_VALUE_CHANGE_MAYBE , -KCSAN_REPORT_CONSUMED_WATCHPOINT , &other_infos[watchpoint_idx]); +const struct access_info ai =prepare_access_info (ptr, size, access_type); + +kcsan_report (&ai,KCSAN_VALUE_CHANGE_MAYBE ,KCSAN_REPORT_CONSUMED_WATCHPOINT , + &other_infos[watchpoint_idx]); }void kcsan_report_known_origin (const volatile void *ptr,size_t size,int access_type,enum kcsan_value_change value_change,int watchpoint_idx) { -kcsan_report (ptr, size, access_type, value_change, -KCSAN_REPORT_RACE_SIGNAL , &other_infos[watchpoint_idx]); +const struct access_info ai =prepare_access_info (ptr, size, access_type); + +kcsan_report (&ai, value_change,KCSAN_REPORT_RACE_SIGNAL , &other_infos[watchpoint_idx]); }void kcsan_report_unknown_origin (const volatile void *ptr,size_t size,int access_type) { -kcsan_report (ptr, size, access_type,KCSAN_VALUE_CHANGE_TRUE , -KCSAN_REPORT_RACE_UNKNOWN_ORIGIN ,NULL ); +const struct access_info ai =prepare_access_info (ptr, size, access_type); + +kcsan_report (&ai,KCSAN_VALUE_CHANGE_TRUE ,KCSAN_REPORT_RACE_UNKNOWN_ORIGIN ,NULL ); }
Signature · 1 line
2.31.1.189.g2e36527f23
Paul E. McKenney
maintainerPATCH 7/10 kcsan: Remove reporting indirection
In reply to Paul E. McKenneyFrom: Mark Rutland <[email protected]>
Now that we have separate kcsan_report_*() functions, we can factor the distinct logic for each of the report cases out of kcsan_report(). While this means each case has to handle mutual exclusion independently, this minimizes the conditionality of code and makes it easier to read, and will permit passing distinct bits of information to print_report() in future.
There should be no functional change as a result of this patch.
--- kernel/kcsan/report.c | 115 ++++++++++++++++++------------------------ 1 file changed, 49 insertions(+), 66 deletions(-)
kernel/kcsan/report.c +49 -66
@@ -434,13 +434,11 @@ static void print_report(enum kcsan_value_change value_change,static void release_report (unsigned long *flags,struct other_info *other_info) { -if (other_info) -/* -* Use size to denote valid/invalid, since KCSAN entirely -* ignores 0-sized accesses. -*/ - other_info->ai.size =0 ; - +/* +* Use size to denote valid/invalid, since KCSAN entirely ignores +* 0-sized accesses. +*/ + other_info->ai.size =0 ;raw_spin_unlock_irqrestore (&report_lock, *flags); }
@@ -573,61 +571,6 @@ static bool prepare_report_consumer(unsigned long *flags,return false; } -/* -* Depending on the report type either sets @other_info and returns false, or -* awaits @other_info and returns true. If @other_info is not required for the -* report type, simply acquires @report_lock and returns true. -*/ -static noinline bool prepare_report(unsigned long *flags, -enum kcsan_report_type type, -const struct access_info *ai, -struct other_info *other_info) -{ -switch (type) { -case KCSAN_REPORT_CONSUMED_WATCHPOINT : -prepare_report_producer (flags, ai, other_info); -return false; -case KCSAN_REPORT_RACE_SIGNAL : -return prepare_report_consumer (flags, ai, other_info); -default : -/* @other_info not required; just acquire @report_lock. */ -raw_spin_lock_irqsave (&report_lock, *flags); -return true; - } -} - -static void kcsan_report (const struct access_info *ai,enum kcsan_value_change value_change, -enum kcsan_report_type type,struct other_info *other_info) -{ -unsigned long flags =0 ; - -kcsan_disable_current (); - -/* -* Because we may generate reports when we're in scheduler code, the use -* of printk() could deadlock. Until such time that all printing code -* called in print_report() is scheduler-safe, accept the risk, and just -* get our message out. As such, also disable lockdep to hide the -* warning, and avoid disabling lockdep for the rest of the kernel. -*/ -lockdep_off (); - -if (prepare_report (&flags, type, ai, other_info)) { -/* -* Never report if value_change is FALSE, only if we it is -* either TRUE or MAYBE. In case of MAYBE, further filtering may -* be done once we know the full stack trace in print_report(). -*/ -if (value_change !=KCSAN_VALUE_CHANGE_FALSE ) -print_report (value_change, type, ai, other_info); - -release_report (&flags, other_info); - } - -lockdep_on (); -kcsan_enable_current (); -} -static struct access_info prepare_access_info (const volatile void *ptr,size_t size,int access_type) {
@@ -644,22 +587,62 @@ void kcsan_report_set_info(const volatile void *ptr, size_t size, int access_typ int watchpoint_idx) {const struct access_info ai =prepare_access_info (ptr, size, access_type); +unsigned long flags; + +kcsan_disable_current (); +lockdep_off ();/* See kcsan_report_known_origin(). */ -kcsan_report (&ai,KCSAN_VALUE_CHANGE_MAYBE ,KCSAN_REPORT_CONSUMED_WATCHPOINT , - &other_infos[watchpoint_idx]); +prepare_report_producer (&flags, &ai, &other_infos[watchpoint_idx]); + +lockdep_on (); +kcsan_enable_current (); }void kcsan_report_known_origin (const volatile void *ptr,size_t size,int access_type,enum kcsan_value_change value_change,int watchpoint_idx) {const struct access_info ai =prepare_access_info (ptr, size, access_type); +struct other_info *other_info = &other_infos[watchpoint_idx]; +unsigned long flags =0 ; -kcsan_report (&ai, value_change,KCSAN_REPORT_RACE_SIGNAL , &other_infos[watchpoint_idx]); +kcsan_disable_current (); +/* +* Because we may generate reports when we're in scheduler code, the use +* of printk() could deadlock. Until such time that all printing code +* called in print_report() is scheduler-safe, accept the risk, and just +* get our message out. As such, also disable lockdep to hide the +* warning, and avoid disabling lockdep for the rest of the kernel. +*/ +lockdep_off (); + +if (!prepare_report_consumer (&flags, &ai, other_info)) + goto out; +/* +* Never report if value_change is FALSE, only when it is +* either TRUE or MAYBE. In case of MAYBE, further filtering may +* be done once we know the full stack trace in print_report(). +*/ +if (value_change !=KCSAN_VALUE_CHANGE_FALSE ) +print_report (value_change,KCSAN_REPORT_RACE_SIGNAL , &ai, other_info); + +release_report (&flags, other_info); +out: +lockdep_on (); +kcsan_enable_current (); }void kcsan_report_unknown_origin (const volatile void *ptr,size_t size,int access_type) {const struct access_info ai =prepare_access_info (ptr, size, access_type); +unsigned long flags; + +kcsan_disable_current (); +lockdep_off ();/* See kcsan_report_known_origin(). */ + +raw_spin_lock_irqsave (&report_lock, flags); +print_report (KCSAN_VALUE_CHANGE_TRUE ,KCSAN_REPORT_RACE_UNKNOWN_ORIGIN , &ai,NULL ); +raw_spin_unlock_irqrestore (&report_lock, flags); -kcsan_report (&ai,KCSAN_VALUE_CHANGE_TRUE ,KCSAN_REPORT_RACE_UNKNOWN_ORIGIN ,NULL ); +lockdep_on (); +kcsan_enable_current (); }
Signature · 1 line
2.31.1.189.g2e36527f23
Paul E. McKenney
maintainerPATCH 8/10 kcsan: Remove kcsan_report_type
In reply to Paul E. McKenneyFrom: Mark Rutland <[email protected]>
Now that the reporting code has been refactored, it's clear by construction that print_report() can only be passed KCSAN_REPORT_RACE_SIGNAL or KCSAN_REPORT_RACE_UNKNOWN_ORIGIN, and these can also be distinguished by the presence of other_info.
Let's simplify things and remove the report type enum, and instead let's check other_info to distinguish these cases. This allows us to remove code for cases which are impossible and generally makes the code simpler.
There should be no functional change as a result of this patch.
--- kernel/kcsan/kcsan.h | 33 +++++++++++++-------------------- kernel/kcsan/report.c | 29 +++++++---------------------- 2 files changed, 20 insertions(+), 42 deletions(-)
kernel/kcsan/kcsan.h +13 -20
@@ -116,32 +116,25 @@ enum kcsan_value_change { KCSAN_VALUE_CHANGE_TRUE, }; -enum kcsan_report_type { -/* -* The thread that set up the watchpoint and briefly stalled was -* signalled that another thread triggered the watchpoint. -*/ -KCSAN_REPORT_RACE_SIGNAL , - -/* -* A thread found and consumed a matching watchpoint. -*/ -KCSAN_REPORT_CONSUMED_WATCHPOINT , - -/* -* No other thread was observed to race with the access, but the data -* value before and after the stall differs. -*/ -KCSAN_REPORT_RACE_UNKNOWN_ORIGIN , -}; -/* -* Notify the report code that a race occurred. +* The calling thread hit and consumed a watchpoint: set the access information +* to be consumed by the reporting thread. No report is printed yet. */ void kcsan_report_set_info (const volatile void *ptr,size_t size,int access_type,int watchpoint_idx); + +/* +* The calling thread observed that the watchpoint it set up was hit and +* consumed: print the full report based on information set by the racing +* thread. +*/ void kcsan_report_known_origin (const volatile void *ptr,size_t size,int access_type,enum kcsan_value_change value_change,int watchpoint_idx); + +/* +* No other thread was observed to race with the access, but the data value +* before and after the stall differs. Reports a race of "unknown origin". +*/ void kcsan_report_unknown_origin (const volatile void *ptr,size_t size,int access_type);#endif /* _KERNEL_KCSAN_KCSAN_H */
kernel/kcsan/report.c +7 -22
@@ -326,7 +326,6 @@ static void print_verbose_info(struct task_struct *task) }static void print_report (enum kcsan_value_change value_change, -enum kcsan_report_type type,const struct access_info *ai,const struct other_info *other_info) {
@@ -343,7 +342,7 @@ static void print_report(enum kcsan_value_change value_change,if (skip_report (KCSAN_VALUE_CHANGE_TRUE , stack_entries[skipnr]))return ; -if (type ==KCSAN_REPORT_RACE_SIGNAL ) { +if (other_info) { other_skipnr =get_stack_skipnr (other_info->stack_entries, other_info->num_stack_entries); other_frame = other_info->stack_entries[other_skipnr];
@@ -358,8 +357,7 @@ static void print_report(enum kcsan_value_change value_change,/* Print report header. */ pr_err ("==================================================================\n" ); -switch (type) { -case KCSAN_REPORT_RACE_SIGNAL : { +if (other_info) {int cmp;/*
@@ -371,22 +369,15 @@ static void print_report(enum kcsan_value_change value_change,get_bug_type (ai->access_type | other_info->ai.access_type), (void *)(cmp <0 ? other_frame : this_frame), (void *)(cmp < 0 ? this_frame : other_frame)); - }break ; - -case KCSAN_REPORT_RACE_UNKNOWN_ORIGIN : + }else {pr_err ("BUG: KCSAN: %s in %pS\n" ,get_bug_type (ai->access_type), (void *)this_frame); -break ; - -default : -BUG (); }pr_err ("\n" );/* Print information about the racing accesses. */ -switch (type) { -case KCSAN_REPORT_RACE_SIGNAL : +if (other_info) { pr_err("%s to 0x%px of %zu bytes by %s on cpu %i:\n", get_access_type(other_info->ai.access_type), other_info->ai.ptr, other_info->ai.size, get_thread_desc(other_info->ai.task_pid),
@@ -404,16 +395,10 @@ static void print_report(enum kcsan_value_change value_change,pr_err ("%s to 0x%px of %zu bytes by %s on cpu %i:\n" ,get_access_type (ai->access_type), ai->ptr, ai->size,get_thread_desc (ai->task_pid), ai->cpu_id); -break ; - -case KCSAN_REPORT_RACE_UNKNOWN_ORIGIN : + }else {pr_err ("race at unknown origin, with %s to 0x%px of %zu bytes by %s on cpu %i:\n" ,get_access_type (ai->access_type), ai->ptr, ai->size,get_thread_desc (ai->task_pid), ai->cpu_id); -break ; - -default : -BUG (); }/* Print stack trace of this thread. */ stack_trace_print(stack_entries + skipnr, num_stack_entries - skipnr,
@@ -623,7 +608,7 @@ void kcsan_report_known_origin(const volatile void *ptr, size_t size, int access* be done once we know the full stack trace in print_report(). */ if (value_change !=KCSAN_VALUE_CHANGE_FALSE ) -print_report (value_change,KCSAN_REPORT_RACE_SIGNAL , &ai, other_info); +print_report (value_change, &ai, other_info);release_report (&flags, other_info); out:
@@ -640,7 +625,7 @@ void kcsan_report_unknown_origin(const volatile void *ptr, size_t size, int accelockdep_off ();/* See kcsan_report_known_origin(). */ raw_spin_lock_irqsave (&report_lock, flags); -print_report (KCSAN_VALUE_CHANGE_TRUE ,KCSAN_REPORT_RACE_UNKNOWN_ORIGIN , &ai,NULL ); +print_report (KCSAN_VALUE_CHANGE_TRUE , &ai,NULL );raw_spin_unlock_irqrestore (&report_lock, flags);lockdep_on ();
Signature · 1 line
2.31.1.189.g2e36527f23
Paul E. McKenney
maintainerPATCH 9/10 kcsan: Report observed value changes
In reply to Paul E. McKenneyFrom: Mark Rutland <[email protected]>
When a thread detects that a memory location was modified without its watchpoint being hit, the report notes that a change was detected, but does not provide concrete values for the change. Knowing the concrete values can be very helpful in tracking down any racy writers (e.g. as specific values may only be written in some portions of code, or under certain conditions).
When we detect a modification, let's report the concrete old/new values, along with the access's mask of relevant bits (and which relevant bits were modified). This can make it easier to identify potential racy writers. As the snapshots are at most 8 bytes, we can only report values for acceses up to this size, but this appears to cater for the common case.
When we detect a race via a watchpoint, we may or may not have concrete values for the modification. To be helpful, let's attempt to log them when we do as they can be ignored where irrelevant.
The resulting reports appears as follows, with values zero-padded to the access width:
| ================================================================== | BUG: KCSAN: data-race in el0_svc_common+0x34/0x25c arch/arm64/kernel/syscall.c:96 | | race at unknown origin, with read to 0xffff00007ae6aa00 of 8 bytes by task 223 on cpu 1: | el0_svc_common+0x34/0x25c arch/arm64/kernel/syscall.c:96 | do_el0_svc+0x48/0xec arch/arm64/kernel/syscall.c:178 | el0_svc arch/arm64/kernel/entry-common.c:226 [inline] | el0_sync_handler+0x1a4/0x390 arch/arm64/kernel/entry-common.c:236 | el0_sync+0x140/0x180 arch/arm64/kernel/entry.S:674 | | value changed: 0x0000000000000000 -> 0x0000000000000002 | | Reported by Kernel Concurrency Sanitizer on: | CPU: 1 PID: 223 Comm: syz-executor.1 Not tainted 5.8.0-rc3-00094-ga73f923ecc8e-dirty #3 | Hardware name: linux,dummy-virt (DT) | ==================================================================
If an access mask is set, it is shown underneath the "value changed" line as "bits changed: 0x<bits changed> with mask 0x<non-zero mask>".
[ [email protected]: align "value changed" and "bits changed" lines,
which required massaging the message; do not print bits+mask if no mask set. ]
--- kernel/kcsan/core.c | 5 +++-- kernel/kcsan/kcsan.h | 6 ++++-- kernel/kcsan/report.c | 31 ++++++++++++++++++++++++++----- 3 files changed, 33 insertions(+), 9 deletions(-)
kernel/kcsan/core.c +3 -2
@@ -557,7 +557,8 @@ kcsan_setup_watchpoint(const volatile void *ptr, size_t size, int type)atomic_long_inc (&kcsan_counters[KCSAN_COUNTER_ASSERT_FAILURES ]);kcsan_report_known_origin (ptr, size, type, value_change, - watchpoint - watchpoints); + watchpoint - watchpoints, + old, new, access_mask); }else if (value_change ==KCSAN_VALUE_CHANGE_TRUE ) {/* Inferring a race, since the value should not have changed. */
@@ -566,7 +567,7 @@ kcsan_setup_watchpoint(const volatile void *ptr, size_t size, int type)atomic_long_inc (&kcsan_counters[KCSAN_COUNTER_ASSERT_FAILURES ]);if (IS_ENABLED (CONFIG_KCSAN_REPORT_RACE_UNKNOWN_ORIGIN ) || is_assert) -kcsan_report_unknown_origin (ptr, size, type); +kcsan_report_unknown_origin (ptr, size, type, old, new, access_mask); }/*
kernel/kcsan/kcsan.h +4 -2
@@ -129,12 +129,14 @@ void kcsan_report_set_info(const volatile void *ptr, size_t size, int access_typ* thread. */ void kcsan_report_known_origin (const volatile void *ptr,size_t size,int access_type, -enum kcsan_value_change value_change,int watchpoint_idx); +enum kcsan_value_change value_change,int watchpoint_idx, +u64 old,u64 new,u64 mask);/* * No other thread was observed to race with the access, but the data value * before and after the stall differs. Reports a race of "unknown origin". */ -void kcsan_report_unknown_origin (const volatile void *ptr,size_t size,int access_type); +void kcsan_report_unknown_origin (const volatile void *ptr,size_t size,int access_type, +u64 old,u64 new,u64 mask);#endif /* _KERNEL_KCSAN_KCSAN_H */
kernel/kcsan/report.c +26 -5
@@ -327,7 +327,8 @@ static void print_verbose_info(struct task_struct *task)static void print_report (enum kcsan_value_change value_change,const struct access_info *ai, -const struct other_info *other_info) +const struct other_info *other_info, +u64 old,u64 new,u64 mask) {unsigned long stack_entries[NUM_STACK_ENTRIES ] = {0 };int num_stack_entries =stack_trace_save (stack_entries,NUM_STACK_ENTRIES ,1 );
@@ -407,6 +408,24 @@ static void print_report(enum kcsan_value_change value_change,if (IS_ENABLED (CONFIG_KCSAN_VERBOSE ))print_verbose_info (current); +/* Print observed value change. */ +if (ai->size <=8 ) { +int hex_len = ai->size *2 ; +u64 diff = old ^ new; + +if (mask) + diff &= mask; +if (diff) { +pr_err ("\n" ); +pr_err ("value changed: 0x%0*llx -> 0x%0*llx\n" , + hex_len, old, hex_len, new); +if (mask) { +pr_err (" bits changed: 0x%0*llx with mask 0x%0*llx\n" , + hex_len, diff, hex_len, mask); + } + } + } +/* Print report footer. */ pr_err ("\n" );pr_err ("Reported by Kernel Concurrency Sanitizer on:\n" );
@@ -584,7 +603,8 @@ void kcsan_report_set_info(const volatile void *ptr, size_t size, int access_typ }void kcsan_report_known_origin (const volatile void *ptr,size_t size,int access_type, -enum kcsan_value_change value_change,int watchpoint_idx) +enum kcsan_value_change value_change,int watchpoint_idx, +u64 old,u64 new,u64 mask) {const struct access_info ai =prepare_access_info (ptr, size, access_type);struct other_info *other_info = &other_infos[watchpoint_idx];
@@ -608,7 +628,7 @@ void kcsan_report_known_origin(const volatile void *ptr, size_t size, int access* be done once we know the full stack trace in print_report(). */ if (value_change !=KCSAN_VALUE_CHANGE_FALSE ) -print_report (value_change, &ai, other_info); +print_report (value_change, &ai, other_info, old, new, mask);release_report (&flags, other_info); out:
@@ -616,7 +636,8 @@ void kcsan_report_known_origin(const volatile void *ptr, size_t size, int accesskcsan_enable_current (); } -void kcsan_report_unknown_origin (const volatile void *ptr,size_t size,int access_type) +void kcsan_report_unknown_origin (const volatile void *ptr,size_t size,int access_type, +u64 old,u64 new,u64 mask) {const struct access_info ai =prepare_access_info (ptr, size, access_type);unsigned long flags;
@@ -625,7 +646,7 @@ void kcsan_report_unknown_origin(const volatile void *ptr, size_t size, int accelockdep_off ();/* See kcsan_report_known_origin(). */ raw_spin_lock_irqsave (&report_lock, flags); -print_report (KCSAN_VALUE_CHANGE_TRUE , &ai,NULL ); +print_report (KCSAN_VALUE_CHANGE_TRUE , &ai,NULL , old, new, mask);raw_spin_unlock_irqrestore (&report_lock, flags);lockdep_on ();
Signature · 1 line
2.31.1.189.g2e36527f23
Paul E. McKenney
maintainerPATCH 10/10 kcsan: Document "value changed" line
In reply to Paul E. McKenneyFrom: Marco Elver <[email protected]>
Update the example reports based on the latest reports generated by kcsan_test module, which now include the "value changed" line. Add a brief description of the "value changed" line.
--- Documentation/dev-tools/kcsan.rst | 88 ++++++++++++------------------- 1 file changed, 35 insertions(+), 53 deletions(-)
Documentation/dev-tools/kcsan.rst +35 -53
@@ -27,75 +27,57 @@ Error reports A typical data race report looks like this:: ================================================================== - BUG: KCSAN: data-race in generic_permission / kernfs_refresh_inode - - write to 0xffff8fee4c40700c of 4 bytes by task 175 on cpu 4: - kernfs_refresh_inode+0x70/0x170 - kernfs_iop_permission+0x4f/0x90 - inode_permission+0x190/0x200 - link_path_walk.part.0+0x503/0x8e0 - path_lookupat.isra.0+0x69/0x4d0 - filename_lookup+0x136/0x280 - user_path_at_empty+0x47/0x60 - vfs_statx+0x9b/0x130 - __do_sys_newlstat+0x50/0xb0 - __x64_sys_newlstat+0x37/0x50 - do_syscall_64+0x85/0x260 - entry_SYSCALL_64_after_hwframe+0x44/0xa9 - - read to 0xffff8fee4c40700c of 4 bytes by task 166 on cpu 6: - generic_permission+0x5b/0x2a0 - kernfs_iop_permission+0x66/0x90 - inode_permission+0x190/0x200 - link_path_walk.part.0+0x503/0x8e0 - path_lookupat.isra.0+0x69/0x4d0 - filename_lookup+0x136/0x280 - user_path_at_empty+0x47/0x60 - do_faccessat+0x11a/0x390 - __x64_sys_access+0x3c/0x50 - do_syscall_64+0x85/0x260 - entry_SYSCALL_64_after_hwframe+0x44/0xa9 + BUG: KCSAN: data-race in test_kernel_read / test_kernel_write + + write to 0xffffffffc009a628 of 8 bytes by task 487 on cpu 0: + test_kernel_write+0x1d/0x30 + access_thread+0x89/0xd0 + kthread+0x23e/0x260 + ret_from_fork+0x22/0x30 + + read to 0xffffffffc009a628 of 8 bytes by task 488 on cpu 6: + test_kernel_read+0x10/0x20 + access_thread+0x89/0xd0 + kthread+0x23e/0x260 + ret_from_fork+0x22/0x30 + + value changed: 0x00000000000009a6 -> 0x00000000000009b2 Reported by Kernel Concurrency Sanitizer on: - CPU: 6 PID: 166 Comm: systemd-journal Not tainted 5.3.0-rc7+ #1 - Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.12.0-1 04/01/2014 + CPU: 6 PID: 488 Comm: access_thread Not tainted 5.12.0-rc2+ #1 + Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.14.0-2 04/01/2014 ================================================================== The header of the report provides a short summary of the functions involved in the race. It is followed by the access types and stack traces of the 2 threads -involved in the data race. +involved in the data race. If KCSAN also observed a value change, the observed +old value and new value are shown on the "value changed" line respectively. The other less common type of data race report looks like this:: ================================================================== - BUG: KCSAN: data-race in e1000_clean_rx_irq+0x551/0xb10 - - race at unknown origin, with read to 0xffff933db8a2ae6c of 1 bytes by interrupt on cpu 0: - e1000_clean_rx_irq+0x551/0xb10 - e1000_clean+0x533/0xda0 - net_rx_action+0x329/0x900 - __do_softirq+0xdb/0x2db - irq_exit+0x9b/0xa0 - do_IRQ+0x9c/0xf0 - ret_from_intr+0x0/0x18 - default_idle+0x3f/0x220 - arch_cpu_idle+0x21/0x30 - do_idle+0x1df/0x230 - cpu_startup_entry+0x14/0x20 - rest_init+0xc5/0xcb - arch_call_rest_init+0x13/0x2b - start_kernel+0x6db/0x700 + BUG: KCSAN: data-race in test_kernel_rmw_array+0x71/0xd0 + + race at unknown origin, with read to 0xffffffffc009bdb0 of 8 bytes by task 515 on cpu 2: + test_kernel_rmw_array+0x71/0xd0 + access_thread+0x89/0xd0 + kthread+0x23e/0x260 + ret_from_fork+0x22/0x30 + + value changed: 0x0000000000002328 -> 0x0000000000002329 Reported by Kernel Concurrency Sanitizer on: - CPU: 0 PID: 0 Comm: swapper/0 Not tainted 5.3.0-rc7+ #2 - Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.12.0-1 04/01/2014 + CPU: 2 PID: 515 Comm: access_thread Not tainted 5.12.0-rc2+ #1 + Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.14.0-2 04/01/2014 ================================================================== This report is generated where it was not possible to determine the other racing thread, but a race was inferred due to the data value of the watched -memory location having changed. These can occur either due to missing -instrumentation or e.g. DMA accesses. These reports will only be generated if -``CONFIG_KCSAN_REPORT_RACE_UNKNOWN_ORIGIN=y`` (selected by default). +memory location having changed. These reports always show a "value changed" +line. A common reason for reports of this type are missing instrumentation in +the racing thread, but could also occur due to e.g. DMA accesses. Such reports +are shown only if ``CONFIG_KCSAN_REPORT_RACE_UNKNOWN_ORIGIN=y``, which is +enabled by default. Selective analysis ~~~~~~~~~~~~~~~~~~
Signature · 1 line
2.31.1.189.g2e36527f23