1. 03 Sep, 2020 5 commits
    • Paul E. McKenney's avatar
      Merge branch 'strictgp.2020.08.24a' into HEAD · 7fbe67e4
      Paul E. McKenney authored
      strictgp.2020.08.24a: Strict grace periods for KASAN testing.
      7fbe67e4
    • Paul E. McKenney's avatar
      Merge branch 'scftorture.2020.08.24a' into HEAD · f511ce14
      Paul E. McKenney authored
      scftorture.2020.08.24a: Torture tests for smp_call_function() and friends.
      f511ce14
    • Paul E. McKenney's avatar
      Merge branches 'doc.2020.08.24a', 'fixes.2020.09.03b' and 'torture.2020.08.24a' into HEAD · cfb2c107
      Paul E. McKenney authored
      doc.2020.08.24a: Documentation updates.
      fixes.2020.09.03b: Miscellaneous fixes.
      torture.2020.08.24a: Torture-test updates.
      cfb2c107
    • Zqiang's avatar
      rcu: Shrink each possible cpu krcp · 70060b87
      Zqiang authored
      CPUs can go offline shortly after kfree_call_rcu() has been invoked,
      which can leave memory stranded until those CPUs come back online.
      This commit therefore drains the kcrp of each CPU, not just the
      ones that happen to be online.
      Acked-by: default avatarJoel Fernandes <joel@joelfernandes.org>
      Signed-off-by: default avatarZqiang <qiang.zhang@windriver.com>
      Signed-off-by: default avatarPaul E. McKenney <paulmck@kernel.org>
      70060b87
    • Joel Fernandes (Google)'s avatar
      rcu/segcblist: Prevent useless GP start if no CBs to accelerate · 53922270
      Joel Fernandes (Google) authored
      The rcu_segcblist_accelerate() function returns true iff it is necessary
      to request another grace period.  A tracing session showed that this
      function unnecessarily requests grace periods.
      
      For example, consider the following sequence of events:
      1. Callbacks are queued only on the NEXT segment of CPU A's callback list.
      2. CPU A runs RCU_SOFTIRQ, accelerating these callbacks from NEXT to WAIT.
      3. Thus rcu_segcblist_accelerate() returns true, requesting grace period N.
      4. RCU's grace-period kthread wakes up on CPU B and starts grace period N.
      4. CPU A notices the new grace period and invokes RCU_SOFTIRQ.
      5. CPU A's RCU_SOFTIRQ again invokes rcu_segcblist_accelerate(), but
         there are no new callbacks.  However, rcu_segcblist_accelerate()
         nevertheless (uselessly) requests a new grace period N+1.
      
      This extra grace period results in additional lock contention and also
      additional wakeups, all for no good reason.
      
      This commit therefore adds a check to rcu_segcblist_accelerate() that
      prevents the return of true when there are no new callbacks.
      
      This change reduces the number of grace periods (GPs) and wakeups in each
      of eleven five-second rcutorture runs as follows:
      
      +----+-------------------+-------------------+
      | #  | Number of GPs     | Number of Wakeups |
      +====+=========+=========+=========+=========+
      | 1  | With    | Without | With    | Without |
      +----+---------+---------+---------+---------+
      | 2  |      75 |      89 |     113 |     119 |
      +----+---------+---------+---------+---------+
      | 3  |      62 |      91 |     105 |     123 |
      +----+---------+---------+---------+---------+
      | 4  |      60 |      79 |      98 |     110 |
      +----+---------+---------+---------+---------+
      | 5  |      63 |      79 |      99 |     112 |
      +----+---------+---------+---------+---------+
      | 6  |      57 |      89 |      96 |     123 |
      +----+---------+---------+---------+---------+
      | 7  |      64 |      85 |      97 |     118 |
      +----+---------+---------+---------+---------+
      | 8  |      58 |      83 |      98 |     113 |
      +----+---------+---------+---------+---------+
      | 9  |      57 |      77 |      89 |     104 |
      +----+---------+---------+---------+---------+
      | 10 |      66 |      82 |      98 |     119 |
      +----+---------+---------+---------+---------+
      | 11 |      52 |      82 |      83 |     117 |
      +----+---------+---------+---------+---------+
      
      The reduction in the number of wakeups ranges from 5% to 40%.
      
      Cc: urezki@gmail.com
      [ paulmck: Rework commit log and comment. ]
      Signed-off-by: default avatarJoel Fernandes (Google) <joel@joelfernandes.org>
      Signed-off-by: default avatarPaul E. McKenney <paulmck@kernel.org>
      53922270
  2. 25 Aug, 2020 35 commits
    • Paul E. McKenney's avatar
      torture: Add gdb support · b67a9170
      Paul E. McKenney authored
      This commit adds a "--gdb" parameter to kvm.sh, which causes
      "CONFIG_DEBUG_INFO=y" to be added to the Kconfig options, "nokaslr"
      to be added to the boot parameters, and "-s -S" to be added to the qemu
      arguments.  Furthermore, the scripting prints messages telling the user
      how to start up gdb for the run in question.
      
      Because of the interactive nature of gdb sessions, only one "--configs"
      scenario is permitted when "--gdb" is specified.  For most torture types,
      this means that a "--configs" argument is required, and that argument
      must specify the single scenario of interest.
      
      The usual cautions about breakpoints and timing apply, for example,
      staring at your gdb prompt for too long will likely get you many
      complaints, including RCU CPU stall warnings.  Omar Sandoval further
      suggests using gdb's "hbreak" command instead of the "break" command on
      systems supporting hardware breakpoints, and further using the "commands"
      option because the resulting non-interactive breakpoints are less likely
      to get you RCU CPU stall warnings.
      Signed-off-by: default avatarPaul E. McKenney <paulmck@kernel.org>
      b67a9170
    • Paul E. McKenney's avatar
      rcutorture: Allow pointer leaks to test diagnostic code · d6855142
      Paul E. McKenney authored
      This commit adds an rcutorture.leakpointer module parameter that
      intentionally leaks an RCU-protected pointer out of the RCU read-side
      critical section and checks to see if the corresponding grace period
      has elapsed, emitting a WARN_ON_ONCE() if so.  This module parameter can
      be used to test facilities like CONFIG_RCU_STRICT_GRACE_PERIOD that end
      grace periods quickly.
      
      While in the area, also document rcutorture.irqreader, which was
      previously left out.
      
      Reported-by Jann Horn <jannh@google.com>
      Signed-off-by: default avatarPaul E. McKenney <paulmck@kernel.org>
      d6855142
    • Paul E. McKenney's avatar
      rcutorture: Hoist OOM registry up one level · 299c7d94
      Paul E. McKenney authored
      Currently, registering and unregistering the OOM notifier is done
      right before and after the test, respectively.  This will not work
      well for multi-threaded tests, so this commit hoists this registering
      and unregistering up into the rcu_torture_fwd_prog_init() and
      rcu_torture_fwd_prog_cleanup() functions.
      Signed-off-by: default avatarPaul E. McKenney <paulmck@kernel.org>
      299c7d94
    • Colin Ian King's avatar
      refperf: Avoid null pointer dereference when buf fails to allocate · 58db5785
      Colin Ian King authored
      Currently in the unlikely event that buf fails to be allocated it
      is dereferenced a few times.  Use the errexit flag to determine if
      buf should be written to to avoid the null pointer dereferences.
      
      Addresses-Coverity: ("Dereference after null check")
      Fixes: f518f154 ("refperf: Dynamically allocate experiment-summary output buffer")
      Signed-off-by: default avatarColin Ian King <colin.king@canonical.com>
      Signed-off-by: default avatarPaul E. McKenney <paulmck@kernel.org>
      58db5785
    • Paul E. McKenney's avatar
      rcutorture: Properly synchronize with OOM notifier · 57f60202
      Paul E. McKenney authored
      The current rcutorture forward-progress code assumes that it is the
      only cause of out-of-memory (OOM) events.  For script-based rcutorture
      testing, this assumption is in fact correct.  However, testing based
      on modprobe/rmmod might well encounter external OOM events, which could
      happen at any time.
      
      This commit therefore properly synchronizes the interaction between
      rcutorture's forward-progress testing and its OOM notifier by adding a
      global mutex.
      Signed-off-by: default avatarPaul E. McKenney <paulmck@kernel.org>
      57f60202
    • Paul E. McKenney's avatar
      rcutorture: Properly set rcu_fwds for OOM handling · c8fa6371
      Paul E. McKenney authored
      The conversion of rcu_fwds to dynamic allocation failed to actually
      allocate the required structure.  This commit therefore allocates it,
      frees it, and updates rcu_fwds accordingly.  While in the area, it
      abstracts the cleanup actions into rcu_torture_fwd_prog_cleanup().
      
      Fixes: 5155be99 ("rcutorture: Dynamically allocate rcu_fwds structure")
      Reported-by: default avatarkernel test robot <rong.a.chen@intel.com>
      Signed-off-by: default avatarPaul E. McKenney <paulmck@kernel.org>
      c8fa6371
    • Paul E. McKenney's avatar
      torture: Add kvm.sh --help and update help message · 54618088
      Paul E. McKenney authored
      This commit adds a --help argument (along with its synonym -h) to display
      the help text.  While in the area, this commit also updates the help text.
      Signed-off-by: default avatarPaul E. McKenney <paulmck@kernel.org>
      54618088
    • Paul E. McKenney's avatar
      rcutorture: Add CONFIG_PROVE_RCU_LIST to TREE05 · fc848cf4
      Paul E. McKenney authored
      Currently, the CONFIG_PROVE_RCU_LIST=y case is untested.  This commit
      therefore adds CONFIG_PROVE_RCU_LIST=y to rcutorture's TREE05 scenario.
      
      Cc: Madhuparna Bhowmik <madhuparnabhowmik10@gmail.com>
      Cc: Joel Fernandes (Google) <joel@joelfernandes.org>
      Signed-off-by: default avatarPaul E. McKenney <paulmck@kernel.org>
      fc848cf4
    • Paul E. McKenney's avatar
      torture: Update initrd documentation · 33595581
      Paul E. McKenney authored
      The rcu-test-image.txt documentation covers a very uncommon case where
      a real userspace environment is required.  However, someone reading this
      document might reasonably conclude that this is in fact a prerequisite.
      In addition, the initrd.txt file mentions dracut, which is no longer used.
      This commit therefore provides the needed updates.
      Signed-off-by: default avatarPaul E. McKenney <paulmck@kernel.org>
      33595581
    • Alexander A. Klimov's avatar
      rcutorture: Replace HTTP links with HTTPS ones · afcdf231
      Alexander A. Klimov authored
      Rationale:
      Reduces attack surface on kernel devs opening the links for MITM
      as HTTPS traffic is much harder to manipulate.
      
      Deterministic algorithm:
      For each file:
        If not .svg:
          For each line:
            If doesn't contain `\bxmlns\b`:
              For each link, `\bhttp://[^# \t\r\n]*(?:\w|/)`:
      	  If neither `\bgnu\.org/license`, nor `\bmozilla\.org/MPL\b`:
                  If both the HTTP and HTTPS versions
                  return 200 OK and serve the same content:
                    Replace HTTP with HTTPS.
      Signed-off-by: default avatarAlexander A. Klimov <grandmaster@al2klimov.de>
      Signed-off-by: default avatarPaul E. McKenney <paulmck@kernel.org>
      afcdf231
    • Wei Yongjun's avatar
      locktorture: Make function torture_percpu_rwsem_init() static · d49bed9a
      Wei Yongjun authored
      The sparse tool complains as follows:
      
      kernel/locking/locktorture.c:569:6: warning:
       symbol 'torture_percpu_rwsem_init' was not declared. Should it be static?
      
      And this function is not used outside of locktorture.c,
      so this commit marks it static.
      Signed-off-by: default avatarWei Yongjun <weiyongjun1@huawei.com>
      Signed-off-by: default avatarPaul E. McKenney <paulmck@kernel.org>
      d49bed9a
    • Paul Gortmaker's avatar
    • Joel Fernandes (Google)'s avatar
      rcutorture: Output number of elapsed grace periods · 959954df
      Joel Fernandes (Google) authored
      This commit adds code to print the grace-period number at the start
      of the test along with both the grace-period number and the number of
      elapsed grace periods at the end of the test.  Note that variants of
      RCU)without the notion of a grace-period number (for example, Tiny RCU)
      just print zeroes.
      
      [ paulmck: Adjust commit log. ]
      Signed-off-by: default avatarJoel Fernandes (Google) <joel@joelfernandes.org>
      Signed-off-by: default avatarPaul E. McKenney <paulmck@kernel.org>
      959954df
    • Paul E. McKenney's avatar
      rcutorture: Remove KCSAN stubs · 83224afd
      Paul E. McKenney authored
      KCSAN is now in mainline, so this commit removes the stubs for the
      data_race(), ASSERT_EXCLUSIVE_WRITER(), and ASSERT_EXCLUSIVE_ACCESS()
      macros.
      Signed-off-by: default avatarPaul E. McKenney <paulmck@kernel.org>
      83224afd
    • Paul E. McKenney's avatar
      rcu: Remove unused "cpu" parameter from rcu_report_qs_rdp() · cfeac397
      Paul E. McKenney authored
      The "cpu" parameter to rcu_report_qs_rdp() is not used, with rdp->cpu
      being used instead.  Furtheremore, every call to rcu_report_qs_rdp()
      invokes it on rdp->cpu.  This commit therefore removes this unused "cpu"
      parameter and converts a check of rdp->cpu against smp_processor_id()
      to a WARN_ON_ONCE().
      Reported-by: default avatarJann Horn <jannh@google.com>
      Signed-off-by: default avatarPaul E. McKenney <paulmck@kernel.org>
      cfeac397
    • Paul E. McKenney's avatar
      rcu: Report QS for outermost PREEMPT=n rcu_read_unlock() for strict GPs · aa40c138
      Paul E. McKenney authored
      The CONFIG_PREEMPT=n instance of rcu_read_unlock is even more
      aggressively than that of CONFIG_PREEMPT=y in deferring reporting
      quiescent states to the RCU core.  This is just what is wanted in normal
      use because it reduces overhead, but the resulting delay is not what
      is wanted for kernels built with CONFIG_RCU_STRICT_GRACE_PERIOD=y.
      This commit therefore adds an rcu_read_unlock_strict() function that
      checks for exceptional conditions, and reports the newly started
      quiescent state if it is safe to do so, also doing a spin-delay if
      requested via rcutree.rcu_unlock_delay.  This commit also adds a call
      to rcu_read_unlock_strict() from the CONFIG_PREEMPT=n instance of
      __rcu_read_unlock().
      
      [ paulmck: Fixed bug located by kernel test robot <lkp@intel.com> ]
      Reported-by Jann Horn <jannh@google.com>
      Signed-off-by: default avatarPaul E. McKenney <paulmck@kernel.org>
      aa40c138
    • Paul E. McKenney's avatar
      rcu: Execute RCU reader shortly after rcu_core for strict GPs · a657f261
      Paul E. McKenney authored
      A kernel built with CONFIG_RCU_STRICT_GRACE_PERIOD=y needs a quiescent
      state to appear very shortly after a CPU has noticed a new grace period.
      Placing an RCU reader immediately after this point is ineffective because
      this normally happens in softirq context, which acts as a big RCU reader.
      This commit therefore introduces a new per-CPU work_struct, which is
      used at the end of rcu_core() processing to schedule an RCU read-side
      critical section from within a clean environment.
      
      Reported-by Jann Horn <jannh@google.com>
      Signed-off-by: default avatarPaul E. McKenney <paulmck@kernel.org>
      a657f261
    • Paul E. McKenney's avatar
      rcu: Provide optional RCU-reader exit delay for strict GPs · 3d29aaf1
      Paul E. McKenney authored
      The goal of this series is to increase the probability of tools like
      KASAN detecting that an RCU-protected pointer was used outside of its
      RCU read-side critical section.  Thus far, the approach has been to make
      grace periods and callback processing happen faster.  Another approach
      is to delay the pointer leaker.  This commit therefore allows a delay
      to be applied to exit from RCU read-side critical sections.
      
      This slowdown is specified by a new rcutree.rcu_unlock_delay kernel boot
      parameter that specifies this delay in microseconds, defaulting to zero.
      
      Reported-by Jann Horn <jannh@google.com>
      Signed-off-by: default avatarPaul E. McKenney <paulmck@kernel.org>
      3d29aaf1
    • Paul E. McKenney's avatar
      rcu: IPI all CPUs at GP end for strict GPs · 4e025f52
      Paul E. McKenney authored
      Currently, each CPU discovers the end of a given grace period on its
      own time, which is again good for efficiency but bad for fast grace
      periods, given that it is things like kfree() within the RCU callbacks
      that will cause trouble for pointers leaked from RCU read-side critical
      sections.  This commit therefore uses on_each_cpu() to IPI each CPU
      after grace-period cleanup in order to inform each CPU of the end of
      the old grace period in a timely manner, but only in kernels build with
      CONFIG_RCU_STRICT_GRACE_PERIOD=y.
      
      Reported-by Jann Horn <jannh@google.com>
      Signed-off-by: default avatarPaul E. McKenney <paulmck@kernel.org>
      4e025f52
    • Paul E. McKenney's avatar
      rcu: IPI all CPUs at GP start for strict GPs · 933ada2c
      Paul E. McKenney authored
      Currently, each CPU discovers the beginning of a given grace period
      on its own time, which is again good for efficiency but bad for fast
      grace periods.  This commit therefore uses on_each_cpu() to IPI each
      CPU after grace-period initialization in order to inform each CPU of
      the new grace period in a timely manner, but only in kernels build with
      CONFIG_RCU_STRICT_GRACE_PERIOD=y.
      
      Reported-by Jann Horn <jannh@google.com>
      Signed-off-by: default avatarPaul E. McKenney <paulmck@kernel.org>
      933ada2c
    • Paul E. McKenney's avatar
      rcu: Attempt QS when CPU discovers GP for strict GPs · 1a2f5d57
      Paul E. McKenney authored
      A given CPU normally notes a new grace period during one RCU_SOFTIRQ,
      but avoids reporting the corresponding quiescent state until some later
      RCU_SOFTIRQ.  This leisurly approach improves efficiency by increasing
      the number of update requests served by each grace period, but is not
      what is needed for kernels built with CONFIG_RCU_STRICT_GRACE_PERIOD=y.
      
      This commit therefore adds a new rcu_strict_gp_check_qs() function
      which, in CONFIG_RCU_STRICT_GRACE_PERIOD=y kernels, simply enters and
      immediately exist an RCU read-side critical section.  If the CPU is
      in a quiescent state, the rcu_read_unlock() will attempt to report an
      immediate quiescent state.  This rcu_strict_gp_check_qs() function is
      invoked from note_gp_changes(), so that a CPU just noticing a new grace
      period might immediately report a quiescent state for that grace period.
      
      Reported-by Jann Horn <jannh@google.com>
      Signed-off-by: default avatarPaul E. McKenney <paulmck@kernel.org>
      1a2f5d57
    • Paul E. McKenney's avatar
      rcu: Do full report for .need_qs for strict GPs · 44bad5b3
      Paul E. McKenney authored
      The rcu_preempt_deferred_qs_irqrestore() function is invoked at
      the end of an RCU read-side critical section (for example, directly
      from rcu_read_unlock()) and, if .need_qs is set, invokes rcu_qs() to
      report the new quiescent state.  This works, except that rcu_qs() only
      updates per-CPU state, leaving reporting of the actual quiescent state
      to a later call to rcu_report_qs_rdp(), for example from within a later
      RCU_SOFTIRQ instance.  Although this approach is exactly what you want if
      you are more concerned about efficiency than about short grace periods,
      in CONFIG_RCU_STRICT_GRACE_PERIOD=y kernels, short grace periods are
      the name of the game.
      
      This commit therefore makes rcu_preempt_deferred_qs_irqrestore() directly
      invoke rcu_report_qs_rdp() in CONFIG_RCU_STRICT_GRACE_PERIOD=y, thus
      shortening grace periods.
      
      Historical note:  To the best of my knowledge, causing rcu_read_unlock()
      to directly report a quiescent state first appeared in Jim Houston's
      and Joe Korty's JRCU.  This is the second instance of a Linux-kernel RCU
      feature being inspired by JRCU, the first being RCU callback offloading
      (as in the RCU_NOCB_CPU Kconfig option).
      
      Reported-by Jann Horn <jannh@google.com>
      Signed-off-by: default avatarPaul E. McKenney <paulmck@kernel.org>
      44bad5b3
    • Paul E. McKenney's avatar
      rcu: Always set .need_qs from __rcu_read_lock() for strict GPs · f19920e4
      Paul E. McKenney authored
      The ->rcu_read_unlock_special.b.need_qs field in the task_struct
      structure indicates that the RCU core needs a quiscent state from the
      corresponding task.  The __rcu_read_unlock() function checks this (via
      an eventual call to rcu_preempt_deferred_qs_irqrestore()), and if set
      reports a quiscent state immediately upon exit from the outermost RCU
      read-side critical section.
      
      Currently, this flag is only set when the scheduling-clock interrupt
      decides that the current RCU grace period is too old, as in about
      one full second too old.  But if the kernel has been built with
      CONFIG_RCU_STRICT_GRACE_PERIOD=y, we clearly do not want to wait that
      long.  This commit therefore sets the .need_qs field immediately at the
      start of the RCU read-side critical section from within __rcu_read_lock()
      in order to unconditionally enlist help from __rcu_read_unlock().
      
      But note the additional check for rcu_state.gp_kthread, which prevents
      attempts to awaken RCU's grace-period kthread during early boot before
      there is a scheduler.  Leaving off this check results in early boot hangs.
      So early that there is no console output.  Thus, this additional check
      fails until such time as RCU's grace-period kthread has been created,
      avoiding these empty-console hangs.
      
      Reported-by Jann Horn <jannh@google.com>
      Signed-off-by: default avatarPaul E. McKenney <paulmck@kernel.org>
      f19920e4
    • Paul E. McKenney's avatar
      rcu: Force DEFAULT_RCU_BLIMIT to 1000 for strict RCU GPs · 29fc5f93
      Paul E. McKenney authored
      The value of DEFAULT_RCU_BLIMIT is normally set to 10, the idea being to
      avoid needless response-time degradation due to RCU callback invocation.
      However, when CONFIG_RCU_STRICT_GRACE_PERIOD=y it is better to avoid
      throttling callback execution in order to better detect pointer
      leaks from RCU read-side critical sections.  This commit therefore
      sets the value of DEFAULT_RCU_BLIMIT to 1000 in kernels built with
      CONFIG_RCU_STRICT_GRACE_PERIOD=y.
      
      Reported-by Jann Horn <jannh@google.com>
      Signed-off-by: default avatarPaul E. McKenney <paulmck@kernel.org>
      29fc5f93
    • Paul E. McKenney's avatar
      rcu: Restrict default jiffies_till_first_fqs for strict RCU GPs · aecd34b9
      Paul E. McKenney authored
      If there are idle CPUs, RCU's grace-period kthread will wait several
      jiffies before even thinking about polling them.  This promotes
      efficiency, which is normally a good thing, but when the kernel
      has been built with CONFIG_RCU_STRICT_GRACE_PERIOD=y, we care more
      about short grace periods.  This commit therefore restricts the
      default jiffies_till_first_fqs value to zero in kernels built with
      CONFIG_RCU_STRICT_GRACE_PERIOD=y, which causes RCU's grace-period kthread
      to poll for idle CPUs immediately after starting a grace period.
      
      Reported-by Jann Horn <jannh@google.com>
      Signed-off-by: default avatarPaul E. McKenney <paulmck@kernel.org>
      aecd34b9
    • Paul E. McKenney's avatar
      rcu: Reduce leaf fanout for strict RCU grace periods · dc126918
      Paul E. McKenney authored
      Because strict RCU grace periods will complete more quickly, they will
      experience greater lock contention on each leaf rcu_node structure's
      ->lock.  This commit therefore reduces the leaf fanout in order to reduce
      this lock contention.
      
      Note that this also has the effect of reducing the number of CPUs
      supported to 16 in the case of CONFIG_RCU_FANOUT_LEAF=2 or 81 in the
      case of CONFIG_RCU_FANOUT_LEAF=3.  However, greater numbers of CPUs are
      probably a bad idea when using CONFIG_RCU_STRICT_GRACE_PERIOD=y.  Those
      wishing to live dangerously are free to edit their kernel/rcu/Kconfig
      files accordingly.
      
      Reported-by Jann Horn <jannh@google.com>
      Signed-off-by: default avatarPaul E. McKenney <paulmck@kernel.org>
      dc126918
    • Paul E. McKenney's avatar
      rcu: Add Kconfig option for strict RCU grace periods · 8cbd0e38
      Paul E. McKenney authored
      People running automated tests have asked for a way to make RCU minimize
      grace-period duration in order to increase the probability of KASAN
      detecting a pointer being improperly leaked from an RCU read-side critical
      section, for example, like this:
      
      	rcu_read_lock();
      	p = rcu_dereference(gp);
      	do_something_with(p); // OK
      	rcu_read_unlock();
      	do_something_else_with(p); // BUG!!!
      
      The rcupdate.rcu_expedited boot parameter is a start in this direction,
      given that it makes calls to synchronize_rcu() instead invoke the faster
      (and more wasteful) synchronize_rcu_expedited().  However, this does
      nothing to shorten RCU grace periods that are instead initiated by
      call_rcu(), and RCU pointer-leak bugs can involve call_rcu() just as
      surely as they can synchronize_rcu().
      
      This commit therefore adds a RCU_STRICT_GRACE_PERIOD Kconfig option
      that will be used to shorten normal (non-expedited) RCU grace periods.
      This commit also dumps out a message when this option is in effect.
      Later commits will actually shorten grace periods.
      
      Reported-by Jann Horn <jannh@google.com>
      Signed-off-by: default avatarPaul E. McKenney <paulmck@kernel.org>
      8cbd0e38
    • Paul E. McKenney's avatar
      rcuperf: Change rcuperf to rcuscale · 4e88ec4a
      Paul E. McKenney authored
      This commit further avoids conflation of rcuperf with the kernel's perf
      feature by renaming kernel/rcu/rcuperf.c to kernel/rcu/rcuscale.c, and
      also by similarly renaming the functions and variables inside this file.
      This has the side effect of changing the names of the kernel boot
      parameters, so kernel-parameters.txt and ver_functions.sh are also
      updated.  The rcutorture --torture type was also updated from rcuperf
      to rcuscale.
      
      [ paulmck: Fix bugs located by Stephen Rothwell. ]
      Reported-by: default avatarIngo Molnar <mingo@kernel.org>
      Signed-off-by: default avatarPaul E. McKenney <paulmck@kernel.org>
      4e88ec4a
    • Paul E. McKenney's avatar
      scftorture: Add cond_resched() to test loop · 65bd77f5
      Paul E. McKenney authored
      Although the test loop does randomly delay, which would provide quiescent
      states and so forth, it is possible for there to be a series of long
      smp_call_function*() handler runtimes with no delays, which results in
      softlockup and RCU CPU stall warning messages.  This commit therefore
      inserts a cond_resched() into the main test loop.
      Signed-off-by: default avatarPaul E. McKenney <paulmck@kernel.org>
      65bd77f5
    • Paul E. McKenney's avatar
      scftorture: Adapt memory-ordering test to UP operation · 9e66bf03
      Paul E. McKenney authored
      On uniprocessor systems, smp_call_function() does nothing.  This commit
      therefore avoids complaining about the lack of handler accesses in the
      single-CPU case where there is no handler.
      Signed-off-by: default avatarPaul E. McKenney <paulmck@kernel.org>
      9e66bf03
    • Paul E. McKenney's avatar
      scftorture: Block scftorture_invoker() kthreads for offline CPUs · a7c072ef
      Paul E. McKenney authored
      Currently, CPU-hotplug operations might result in all but two
      of (say) 100 CPUs being offline, which in turn might result in
      false-positive diagnostics due to overload.  This commit therefore
      causes scftorture_invoker() kthreads for offline CPUs to loop blocking
      for 200 milliseconds at a time, thus continuously adjusting the number
      of threads to match the number of online CPUs.
      Signed-off-by: default avatarPaul E. McKenney <paulmck@kernel.org>
      a7c072ef
    • Paul E. McKenney's avatar
      scftorture: Check unexpected "switch" statement value · de77d4da
      Paul E. McKenney authored
      This commit adds a "default" case to the switch statement in
      scftorture_invoke_one() which contains a WARN_ON_ONCE() and an assignment
      to ->scfc_out to suppress knock-on warnings.  These knock-on warnings
      could otherwise cause the user to think that there was a memory-ordering
      problem in smp_call_function() instead of a bug in scftorture.c itself.
      Signed-off-by: default avatarPaul E. McKenney <paulmck@kernel.org>
      de77d4da
    • Wei Yongjun's avatar
      scftorture: Make symbol 'scf_torture_rand' static · 9a52a574
      Wei Yongjun authored
      The sparse tool complains as follows
      
      kernel/scftorture.c:124:1: warning:
       symbol '__pcpu_scope_scf_torture_rand' was not declared. Should it be static?
      
      And this per-CPU variable is not used outside of scftorture.c,
      so this commit marks it static.
      Reported-by: default avatarHulk Robot <hulkci@huawei.com>
      Signed-off-by: default avatarWei Yongjun <weiyongjun1@huawei.com>
      Signed-off-by: default avatarPaul E. McKenney <paulmck@kernel.org>
      9a52a574
    • Paul E. McKenney's avatar
      scftorture: Prevent compiler from reducing race probabilities · ee7035d2
      Paul E. McKenney authored
      Detecting smp_call_function() memory misordering requires close timing,
      so it is necessary to have the checks immediately before and after
      the call to the smp_call_function*() function under test.  This commit
      therefore inserts barrier() calls to prevent the compiler from optimizing
      memory-misordering detection down into the zone of extreme improbability.
      Signed-off-by: default avatarPaul E. McKenney <paulmck@kernel.org>
      ee7035d2
    • Paul E. McKenney's avatar
      scftorture: Flag errors in torture-compatible manner · dbf83b65
      Paul E. McKenney authored
      This commit prints error counts on the statistics line and also adds a
      "!!!" if any of the counters are non-zero.  Allocation failures are
      (somewhat) forgiven, but all other errors result in a "FAILURE" print
      at the end of the test.
      Signed-off-by: default avatarPaul E. McKenney <paulmck@kernel.org>
      dbf83b65