[tip: core/rcu] rcutorture: Use "all" and "N" in "nohz_full" and "rcu_nocbs"

2021-04-11 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: c71c39b344f7eec9d4492913f22126b03bb7b746
Gitweb:
https://git.kernel.org/tip/c71c39b344f7eec9d4492913f22126b03bb7b746
Author:Paul E. McKenney 
AuthorDate:Thu, 21 Jan 2021 15:56:53 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 08 Mar 2021 14:16:58 -08:00

rcutorture: Use "all" and "N" in "nohz_full" and "rcu_nocbs"

This commit uses the shiny new "all" and "N" cpumask options to decouple
the "nohz_full" and "rcu_nocbs" kernel boot parameters in the TREE04.boot
and TREE08.boot files from the CONFIG_NR_CPUS options in the TREE04 and
TREE08 files.

Reported-by: Paul Gortmaker 
Signed-off-by: Paul E. McKenney 
---
 tools/testing/selftests/rcutorture/configs/rcu/TREE04.boot | 2 +-
 tools/testing/selftests/rcutorture/configs/rcu/TREE08.boot | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/rcutorture/configs/rcu/TREE04.boot 
b/tools/testing/selftests/rcutorture/configs/rcu/TREE04.boot
index 5adc675..a8d94ca 100644
--- a/tools/testing/selftests/rcutorture/configs/rcu/TREE04.boot
+++ b/tools/testing/selftests/rcutorture/configs/rcu/TREE04.boot
@@ -1 +1 @@
-rcutree.rcu_fanout_leaf=4 nohz_full=1-7
+rcutree.rcu_fanout_leaf=4 nohz_full=1-N
diff --git a/tools/testing/selftests/rcutorture/configs/rcu/TREE08.boot 
b/tools/testing/selftests/rcutorture/configs/rcu/TREE08.boot
index 22478fd..94d3844 100644
--- a/tools/testing/selftests/rcutorture/configs/rcu/TREE08.boot
+++ b/tools/testing/selftests/rcutorture/configs/rcu/TREE08.boot
@@ -1,3 +1,3 @@
 rcupdate.rcu_self_test=1
 rcutree.rcu_fanout_exact=1
-rcu_nocbs=0-7
+rcu_nocbs=all


[tip: locking/core] tools/memory-model: Add access-marking documentation

2021-04-11 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the locking/core branch of tip:

Commit-ID: 49ab51b01ec6fd837ae3efe2e0cdb41fcf5cf048
Gitweb:
https://git.kernel.org/tip/49ab51b01ec6fd837ae3efe2e0cdb41fcf5cf048
Author:Paul E. McKenney 
AuthorDate:Thu, 11 Feb 2021 15:40:05 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 15 Mar 2021 13:59:47 -07:00

tools/memory-model: Add access-marking documentation

This commit adapts the "Concurrency bugs should fear the big bad data-race
detector (part 2)" LWN article (https://lwn.net/Articles/816854/)
to kernel-documentation form.  This allows more easily updating the
material as needed.

Suggested-by: Thomas Gleixner 
[ paulmck: Apply Marco Elver feedback. ]
[ paulmck: Update per Akira Yokosawa feedback. ]
Reviewed-by: Marco Elver 
Signed-off-by: Paul E. McKenney 
---
 tools/memory-model/Documentation/access-marking.txt | 479 +++-
 1 file changed, 479 insertions(+)
 create mode 100644 tools/memory-model/Documentation/access-marking.txt

diff --git a/tools/memory-model/Documentation/access-marking.txt 
b/tools/memory-model/Documentation/access-marking.txt
new file mode 100644
index 000..1ab189f
--- /dev/null
+++ b/tools/memory-model/Documentation/access-marking.txt
@@ -0,0 +1,479 @@
+MARKING SHARED-MEMORY ACCESSES
+==
+
+This document provides guidelines for marking intentionally concurrent
+normal accesses to shared memory, that is "normal" as in accesses that do
+not use read-modify-write atomic operations.  It also describes how to
+document these accesses, both with comments and with special assertions
+processed by the Kernel Concurrency Sanitizer (KCSAN).  This discussion
+builds on an earlier LWN article [1].
+
+
+ACCESS-MARKING OPTIONS
+==
+
+The Linux kernel provides the following access-marking options:
+
+1. Plain C-language accesses (unmarked), for example, "a = b;"
+
+2. Data-race marking, for example, "data_race(a = b);"
+
+3. READ_ONCE(), for example, "a = READ_ONCE(b);"
+   The various forms of atomic_read() also fit in here.
+
+4. WRITE_ONCE(), for example, "WRITE_ONCE(a, b);"
+   The various forms of atomic_set() also fit in here.
+
+
+These may be used in combination, as shown in this admittedly improbable
+example:
+
+   WRITE_ONCE(a, b + data_race(c + d) + READ_ONCE(e));
+
+Neither plain C-language accesses nor data_race() (#1 and #2 above) place
+any sort of constraint on the compiler's choice of optimizations [2].
+In contrast, READ_ONCE() and WRITE_ONCE() (#3 and #4 above) restrict the
+compiler's use of code-motion and common-subexpression optimizations.
+Therefore, if a given access is involved in an intentional data race,
+using READ_ONCE() for loads and WRITE_ONCE() for stores is usually
+preferable to data_race(), which in turn is usually preferable to plain
+C-language accesses.
+
+KCSAN will complain about many types of data races involving plain
+C-language accesses, but marking all accesses involved in a given data
+race with one of data_race(), READ_ONCE(), or WRITE_ONCE(), will prevent
+KCSAN from complaining.  Of course, lack of KCSAN complaints does not
+imply correct code.  Therefore, please take a thoughtful approach
+when responding to KCSAN complaints.  Churning the code base with
+ill-considered additions of data_race(), READ_ONCE(), and WRITE_ONCE()
+is unhelpful.
+
+In fact, the following sections describe situations where use of
+data_race() and even plain C-language accesses is preferable to
+READ_ONCE() and WRITE_ONCE().
+
+
+Use of the data_race() Macro
+
+
+Here are some situations where data_race() should be used instead of
+READ_ONCE() and WRITE_ONCE():
+
+1. Data-racy loads from shared variables whose values are used only
+   for diagnostic purposes.
+
+2. Data-racy reads whose values are checked against marked reload.
+
+3. Reads whose values feed into error-tolerant heuristics.
+
+4. Writes setting values that feed into error-tolerant heuristics.
+
+
+Data-Racy Reads for Approximate Diagnostics
+
+Approximate diagnostics include lockdep reports, monitoring/statistics
+(including /proc and /sys output), WARN*()/BUG*() checks whose return
+values are ignored, and other situations where reads from shared variables
+are not an integral part of the core concurrency design.
+
+In fact, use of data_race() instead READ_ONCE() for these diagnostic
+reads can enable better checking of the remaining accesses implementing
+the core concurrency design.  For example, suppose that the core design
+prevents any non-diagnostic reads from shared variable x from running
+concurrently with updates to x.  Then using plain C-language writes
+to x allows KCSAN to detect reads from x from within regions of code
+that fail to exclude the updates.  In this case, it is important to use
+data_race() for the diagnostic reads because otherwise KCSAN would give
+false-positive 

[tip: core/rcu] kvfree_rcu: Use __GFP_NOMEMALLOC for single-argument kvfree_rcu()

2021-04-11 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: b01b405092b7940bd366053a27ed54a87c84e96a
Gitweb:
https://git.kernel.org/tip/b01b405092b7940bd366053a27ed54a87c84e96a
Author:Paul E. McKenney 
AuthorDate:Wed, 20 Jan 2021 17:21:47 +01:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 08 Mar 2021 14:18:07 -08:00

kvfree_rcu: Use __GFP_NOMEMALLOC for single-argument kvfree_rcu()

This commit applies the __GFP_NOMEMALLOC gfp flag to memory allocations
carried out by the single-argument variant of kvfree_rcu(), thus avoiding
this can-sleep code path from dipping into the emergency reserves.

Acked-by: Michal Hocko 
Suggested-by: Michal Hocko 
Signed-off-by: Paul E. McKenney 
---
 kernel/rcu/tree.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
index 1f8c980..08b5044 100644
--- a/kernel/rcu/tree.c
+++ b/kernel/rcu/tree.c
@@ -3519,7 +3519,7 @@ add_ptr_to_bulk_krc_lock(struct kfree_rcu_cpu **krcp,
if (!bnode && can_alloc) {
krc_this_cpu_unlock(*krcp, *flags);
bnode = (struct kvfree_rcu_bulk_data *)
-   __get_free_page(GFP_KERNEL | 
__GFP_RETRY_MAYFAIL | __GFP_NOWARN);
+   __get_free_page(GFP_KERNEL | 
__GFP_RETRY_MAYFAIL | __GFP_NOMEMALLOC | __GFP_NOWARN);
*krcp = krc_this_cpu_lock(flags);
}
 


[tip: core/rcu] kvfree_rcu: Make krc_this_cpu_unlock() use raw_spin_unlock_irqrestore()

2021-04-11 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 7ffc9ec8eac196cbd85669a4d7920cd80f186a51
Gitweb:
https://git.kernel.org/tip/7ffc9ec8eac196cbd85669a4d7920cd80f186a51
Author:Paul E. McKenney 
AuthorDate:Wed, 20 Jan 2021 13:38:08 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 08 Mar 2021 14:18:07 -08:00

kvfree_rcu: Make krc_this_cpu_unlock() use raw_spin_unlock_irqrestore()

The krc_this_cpu_unlock() function does a raw_spin_unlock() immediately
followed by a local_irq_restore().  This commit saves a line of code by
merging them into a raw_spin_unlock_irqrestore().  This transformation
also reduces scheduling latency because raw_spin_unlock_irqrestore()
responds immediately to a reschedule request.  In contrast,
local_irq_restore() does a scheduling-oblivious enabling of interrupts.

Reported-by: Sebastian Andrzej Siewior 
Signed-off-by: Paul E. McKenney 
---
 kernel/rcu/tree.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
index 08b5044..7ee83f3 100644
--- a/kernel/rcu/tree.c
+++ b/kernel/rcu/tree.c
@@ -3229,8 +3229,7 @@ krc_this_cpu_lock(unsigned long *flags)
 static inline void
 krc_this_cpu_unlock(struct kfree_rcu_cpu *krcp, unsigned long flags)
 {
-   raw_spin_unlock(>lock);
-   local_irq_restore(flags);
+   raw_spin_unlock_irqrestore(>lock, flags);
 }
 
 static inline struct kvfree_rcu_bulk_data *


[tip: core/rcu] rcu: Add explicit barrier() to __rcu_read_unlock()

2021-04-11 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 7e937220afa3eada0d4611b31e4e3c60770e39b4
Gitweb:
https://git.kernel.org/tip/7e937220afa3eada0d4611b31e4e3c60770e39b4
Author:Paul E. McKenney 
AuthorDate:Fri, 26 Feb 2021 11:25:29 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 15 Mar 2021 13:53:24 -07:00

rcu: Add explicit barrier() to __rcu_read_unlock()

Because preemptible RCU's __rcu_read_unlock() is an external function,
the rough equivalent of an implicit barrier() is inserted by the compiler.
Except that there is a direct call to __rcu_read_unlock() in that same
file, and compilers are getting to the point where they might choose to
inline the fastpath of the __rcu_read_unlock() function.

This commit therefore adds an explicit barrier() to the very beginning
of __rcu_read_unlock().

Signed-off-by: Paul E. McKenney 
---
 kernel/rcu/tree_plugin.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
index 2d60377..a32494c 100644
--- a/kernel/rcu/tree_plugin.h
+++ b/kernel/rcu/tree_plugin.h
@@ -393,8 +393,9 @@ void __rcu_read_unlock(void)
 {
struct task_struct *t = current;
 
+   barrier();  // critical section before exit code.
if (rcu_preempt_read_exit() == 0) {
-   barrier();  /* critical section before exit code. */
+   barrier();  // critical-section exit before .s check.
if (unlikely(READ_ONCE(t->rcu_read_unlock_special.s)))
rcu_read_unlock_special(t);
}


[tip: core/rcu] docs: Correctly spell Stephen Hemminger's name

2021-04-11 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: e589c7c72315f7e52ebb5cffc19615dc18d0cc50
Gitweb:
https://git.kernel.org/tip/e589c7c72315f7e52ebb5cffc19615dc18d0cc50
Author:Paul E. McKenney 
AuthorDate:Tue, 23 Feb 2021 10:07:09 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 15 Mar 2021 13:53:24 -07:00

docs: Correctly spell Stephen Hemminger's name

This commit replaces "Steve" with the his real name, which is "Stephen".

Reported-by: Stephen Hemminger 
Signed-off-by: Paul E. McKenney 
---
 Documentation/RCU/RTFP.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Documentation/RCU/RTFP.txt b/Documentation/RCU/RTFP.txt
index 3b0876c..588d973 100644
--- a/Documentation/RCU/RTFP.txt
+++ b/Documentation/RCU/RTFP.txt
@@ -847,7 +847,7 @@ Symposium on Distributed Computing}
'It's entirely possible that the current user could be replaced
by RCU and/or seqlocks, and we could get rid of brlocks entirely.'
.
-   Steve Hemminger responds by replacing them with RCU.
+   Stephen Hemminger responds by replacing them with RCU.
 }
 }
 


[tip: core/rcu] mm: Don't build mm_dump_obj() on CONFIG_PRINTK=n kernels

2021-04-11 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 5bb1bb353cfe343fc3c84faf06f72ba309fde541
Gitweb:
https://git.kernel.org/tip/5bb1bb353cfe343fc3c84faf06f72ba309fde541
Author:Paul E. McKenney 
AuthorDate:Thu, 07 Jan 2021 13:46:11 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 08 Mar 2021 14:18:46 -08:00

mm: Don't build mm_dump_obj() on CONFIG_PRINTK=n kernels

The mem_dump_obj() functionality adds a few hundred bytes, which is a
small price to pay.  Except on kernels built with CONFIG_PRINTK=n, in
which mem_dump_obj() messages will be suppressed.  This commit therefore
makes mem_dump_obj() be a static inline empty function on kernels built
with CONFIG_PRINTK=n and excludes all of its support functions as well.
This avoids kernel bloat on systems that cannot use mem_dump_obj().

Cc: Christoph Lameter 
Cc: Pekka Enberg 
Cc: David Rientjes 
Cc: Joonsoo Kim 
Cc: 
Suggested-by: Andrew Morton 
Signed-off-by: Paul E. McKenney 
---
 include/linux/mm.h  | 4 
 include/linux/slab.h| 2 ++
 include/linux/vmalloc.h | 2 +-
 mm/slab.c   | 2 ++
 mm/slab.h   | 2 ++
 mm/slab_common.c| 2 ++
 mm/slob.c   | 2 ++
 mm/slub.c   | 2 ++
 mm/util.c   | 2 ++
 mm/vmalloc.c| 2 ++
 10 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index 77e64e3..89fca44 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -3135,7 +3135,11 @@ unsigned long wp_shared_mapping_range(struct 
address_space *mapping,
 
 extern int sysctl_nr_trim_pages;
 
+#ifdef CONFIG_PRINTK
 void mem_dump_obj(void *object);
+#else
+static inline void mem_dump_obj(void *object) {}
+#endif
 
 #endif /* __KERNEL__ */
 #endif /* _LINUX_MM_H */
diff --git a/include/linux/slab.h b/include/linux/slab.h
index 7ae6040..0c97d78 100644
--- a/include/linux/slab.h
+++ b/include/linux/slab.h
@@ -186,8 +186,10 @@ void kfree(const void *);
 void kfree_sensitive(const void *);
 size_t __ksize(const void *);
 size_t ksize(const void *);
+#ifdef CONFIG_PRINTK
 bool kmem_valid_obj(void *object);
 void kmem_dump_obj(void *object);
+#endif
 
 #ifdef CONFIG_HAVE_HARDENED_USERCOPY_ALLOCATOR
 void __check_heap_object(const void *ptr, unsigned long n, struct page *page,
diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
index df92211..3de7be6 100644
--- a/include/linux/vmalloc.h
+++ b/include/linux/vmalloc.h
@@ -241,7 +241,7 @@ pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms)
 int register_vmap_purge_notifier(struct notifier_block *nb);
 int unregister_vmap_purge_notifier(struct notifier_block *nb);
 
-#ifdef CONFIG_MMU
+#if defined(CONFIG_MMU) && defined(CONFIG_PRINTK)
 bool vmalloc_dump_obj(void *object);
 #else
 static inline bool vmalloc_dump_obj(void *object) { return false; }
diff --git a/mm/slab.c b/mm/slab.c
index 51fd424..2e64efe 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -3651,6 +3651,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t 
flags,
 EXPORT_SYMBOL(__kmalloc_node_track_caller);
 #endif /* CONFIG_NUMA */
 
+#ifdef CONFIG_PRINTK
 void kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct page *page)
 {
struct kmem_cache *cachep;
@@ -3670,6 +3671,7 @@ void kmem_obj_info(struct kmem_obj_info *kpp, void 
*object, struct page *page)
if (DEBUG && cachep->flags & SLAB_STORE_USER)
kpp->kp_ret = *dbg_userword(cachep, objp);
 }
+#endif
 
 /**
  * __do_kmalloc - allocate memory
diff --git a/mm/slab.h b/mm/slab.h
index 076582f..120b1d0 100644
--- a/mm/slab.h
+++ b/mm/slab.h
@@ -619,6 +619,7 @@ static inline bool slab_want_init_on_free(struct kmem_cache 
*c)
return false;
 }
 
+#ifdef CONFIG_PRINTK
 #define KS_ADDRS_COUNT 16
 struct kmem_obj_info {
void *kp_ptr;
@@ -630,5 +631,6 @@ struct kmem_obj_info {
void *kp_stack[KS_ADDRS_COUNT];
 };
 void kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct page *page);
+#endif
 
 #endif /* MM_SLAB_H */
diff --git a/mm/slab_common.c b/mm/slab_common.c
index 88e8339..cec9536 100644
--- a/mm/slab_common.c
+++ b/mm/slab_common.c
@@ -526,6 +526,7 @@ bool slab_is_available(void)
return slab_state >= UP;
 }
 
+#ifdef CONFIG_PRINTK
 /**
  * kmem_valid_obj - does the pointer reference a valid slab object?
  * @object: pointer to query.
@@ -600,6 +601,7 @@ void kmem_dump_obj(void *object)
pr_info("%pS\n", kp.kp_stack[i]);
}
 }
+#endif
 
 #ifndef CONFIG_SLOB
 /* Create a cache during boot when no slab services are available yet */
diff --git a/mm/slob.c b/mm/slob.c
index 0578429..74d3f6e 100644
--- a/mm/slob.c
+++ b/mm/slob.c
@@ -461,11 +461,13 @@ out:
spin_unlock_irqrestore(_lock, flags);
 }
 
+#ifdef CONFIG_PRINTK
 void kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct page *page)
 {
kpp->kp_ptr = object;
kpp->kp_page = page;
 }
+#endif
 
 /*
  * End of slob allocator proper. 

[tip: core/rcu] rcutorture: Add crude tests for mem_dump_obj()

2021-04-11 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 0d3dd2c8eadb7d4404b8788f552fb2b824fe2c7e
Gitweb:
https://git.kernel.org/tip/0d3dd2c8eadb7d4404b8788f552fb2b824fe2c7e
Author:Paul E. McKenney 
AuthorDate:Mon, 07 Dec 2020 21:23:36 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 08 Mar 2021 14:18:46 -08:00

rcutorture: Add crude tests for mem_dump_obj()

This commit adds a few crude tests for mem_dump_obj() to rcutorture
runs.  Just to prevent bitrot, you understand!

Signed-off-by: Paul E. McKenney 
---
 kernel/rcu/rcutorture.c | 39 +++
 mm/slab_common.c|  2 ++
 mm/util.c   |  1 +
 3 files changed, 42 insertions(+)

diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
index 99657ff..8e93f2e 100644
--- a/kernel/rcu/rcutorture.c
+++ b/kernel/rcu/rcutorture.c
@@ -1861,6 +1861,45 @@ 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, 
 = %px, rhp = %px,  = %px\n", stats_task, , rhp, );
+   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):", );
+   mem_dump_obj();
+   pr_alert("mem_dump_obj(%px):", rhp);
+   mem_dump_obj(rhp);
+   pr_alert("mem_dump_obj(%px):", >func);
+   mem_dump_obj(>func);
+   pr_alert("mem_dump_obj(%px):", );
+   mem_dump_obj();
+   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, 
 = %px, rhp = %px\n", stats_task, , rhp);
+   pr_alert("mem_dump_obj(kmalloc %px):", rhp);
+   mem_dump_obj(rhp);
+   pr_alert("mem_dump_obj(kmalloc %px):", >func);
+   mem_dump_obj(>func);
+   kfree(rhp);
+   rhp = vmalloc(4096);
+   pr_alert("mem_dump_obj() vmalloc test: rcu_torture_stats = %px, 
 = %px, rhp = %px\n", stats_task, , rhp);
+   pr_alert("mem_dump_obj(vmalloc %px):", rhp);
+   mem_dump_obj(rhp);
+   pr_alert("mem_dump_obj(vmalloc %px):", >func);
+   mem_dump_obj(>func);
+   vfree(rhp);
+   }
+
return 0;
 }
 
diff --git a/mm/slab_common.c b/mm/slab_common.c
index cec9536..4c6107e 100644
--- a/mm/slab_common.c
+++ b/mm/slab_common.c
@@ -545,6 +545,7 @@ bool kmem_valid_obj(void *object)
page = virt_to_head_page(object);
return PageSlab(page);
 }
+EXPORT_SYMBOL_GPL(kmem_valid_obj);
 
 /**
  * kmem_dump_obj - Print available slab provenance information
@@ -601,6 +602,7 @@ void kmem_dump_obj(void *object)
pr_info("%pS\n", kp.kp_stack[i]);
}
 }
+EXPORT_SYMBOL_GPL(kmem_dump_obj);
 #endif
 
 #ifndef CONFIG_SLOB
diff --git a/mm/util.c b/mm/util.c
index 2d497fe..c37e24d 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -1014,4 +1014,5 @@ void mem_dump_obj(void *object)
}
pr_cont(" non-slab/vmalloc memory.\n");
 }
+EXPORT_SYMBOL_GPL(mem_dump_obj);
 #endif


[tip: core/rcu] rcu: Expedite deboost in case of deferred quiescent state

2021-04-11 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 39bbfc62cc90d33f8f5f940464d08075e0275f8a
Gitweb:
https://git.kernel.org/tip/39bbfc62cc90d33f8f5f940464d08075e0275f8a
Author:Paul E. McKenney 
AuthorDate:Thu, 14 Jan 2021 10:39:31 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 08 Mar 2021 14:21:40 -08:00

rcu: Expedite deboost in case of deferred quiescent state

Historically, a task that has been subjected to RCU priority boosting is
deboosted at rcu_read_unlock() time.  However, with the advent of deferred
quiescent states, if the outermost rcu_read_unlock() was invoked with
either bottom halves, interrupts, or preemption disabled, the deboosting
will be delayed for some time.  During this time, a low-priority process
might be incorrectly running at a high real-time priority level.

Fortunately, rcu_read_unlock_special() already provides mechanisms for
forcing a minimal deferral of quiescent states, at least for kernels
built with CONFIG_IRQ_WORK=y.  These mechanisms are currently used
when expedited grace periods are pending that might be blocked by the
current task.  This commit therefore causes those mechanisms to also be
used in cases where the current task has been or might soon be subjected
to RCU priority boosting.  Note that this applies to all kernels built
with CONFIG_RCU_BOOST=y, regardless of whether or not they are also
built with CONFIG_PREEMPT_RT=y.

This approach assumes that kernels build for use with aggressive real-time
applications are built with CONFIG_IRQ_WORK=y.  It is likely to be far
simpler to enable CONFIG_IRQ_WORK=y than to implement a fast-deboosting
scheme that works correctly in its absence.

While in the area, alphabetize the rcu_preempt_deferred_qs_handler()
function's local variables.

Cc: Sebastian Andrzej Siewior 
Cc: Scott Wood 
Cc: Lai Jiangshan 
Cc: Thomas Gleixner 
Signed-off-by: Paul E. McKenney 
---
 kernel/rcu/tree_plugin.h | 26 ++
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
index 2d60377..e17cb23 100644
--- a/kernel/rcu/tree_plugin.h
+++ b/kernel/rcu/tree_plugin.h
@@ -598,9 +598,9 @@ static void rcu_preempt_deferred_qs_handler(struct irq_work 
*iwp)
 static void rcu_read_unlock_special(struct task_struct *t)
 {
unsigned long flags;
+   bool irqs_were_disabled;
bool preempt_bh_were_disabled =
!!(preempt_count() & (PREEMPT_MASK | SOFTIRQ_MASK));
-   bool irqs_were_disabled;
 
/* NMI handlers cannot block and cannot safely manipulate state. */
if (in_nmi())
@@ -609,30 +609,32 @@ static void rcu_read_unlock_special(struct task_struct *t)
local_irq_save(flags);
irqs_were_disabled = irqs_disabled_flags(flags);
if (preempt_bh_were_disabled || irqs_were_disabled) {
-   bool exp;
+   bool expboost; // Expedited GP in flight or possible boosting.
struct rcu_data *rdp = this_cpu_ptr(_data);
struct rcu_node *rnp = rdp->mynode;
 
-   exp = (t->rcu_blocked_node &&
-  READ_ONCE(t->rcu_blocked_node->exp_tasks)) ||
- (rdp->grpmask & READ_ONCE(rnp->expmask));
+   expboost = (t->rcu_blocked_node && 
READ_ONCE(t->rcu_blocked_node->exp_tasks)) ||
+  (rdp->grpmask & READ_ONCE(rnp->expmask)) ||
+  (IS_ENABLED(CONFIG_RCU_BOOST) && irqs_were_disabled 
&&
+   t->rcu_blocked_node);
// Need to defer quiescent state until everything is enabled.
-   if (use_softirq && (in_irq() || (exp && !irqs_were_disabled))) {
+   if (use_softirq && (in_irq() || (expboost && 
!irqs_were_disabled))) {
// Using softirq, safe to awaken, and either the
-   // wakeup is free or there is an expedited GP.
+   // wakeup is free or there is either an expedited
+   // GP in flight or a potential need to deboost.
raise_softirq_irqoff(RCU_SOFTIRQ);
} else {
// Enabling BH or preempt does reschedule, so...
-   // Also if no expediting, slow is OK.
-   // Plus nohz_full CPUs eventually get tick enabled.
+   // Also if no expediting and no possible deboosting,
+   // slow is OK.  Plus nohz_full CPUs eventually get
+   // tick enabled.
set_tsk_need_resched(current);
set_preempt_need_resched();
if (IS_ENABLED(CONFIG_IRQ_WORK) && irqs_were_disabled &&
-   !rdp->defer_qs_iw_pending && exp && 
cpu_online(rdp->cpu)) {
+   expboost && !rdp->defer_qs_iw_pending && 
cpu_online(rdp->cpu)) {
  

[tip: core/rcu] rcutorture: Fix testing of RCU priority boosting

2021-04-11 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 5e59fba573e64cffc3a7a3113fff2336d652f45a
Gitweb:
https://git.kernel.org/tip/5e59fba573e64cffc3a7a3113fff2336d652f45a
Author:Paul E. McKenney 
AuthorDate:Fri, 15 Jan 2021 13:30:38 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 08 Mar 2021 14:21:41 -08:00

rcutorture: Fix testing of RCU priority boosting

Currently, rcutorture refuses to test RCU priority boosting in
CONFIG_HOTPLUG_CPU=y kernels, which are the only kind normally built on
x86 these days.  This commit therefore updates rcutorture's tests of RCU
priority boosting to make them safe for CPU hotplug.  However, these tests
will fail unless TIMER_SOFTIRQ runs at realtime priority, which does not
happen in current mainline.  This commit therefore also refuses to test
RCU priority boosting except in kernels built with CONFIG_PREEMPT_RT=y.

While in the area, this commt adds some debug output at boost-fail time
that helps diagnose the cause of the failure, for example, failing to
run TIMER_SOFTIRQ at realtime priority.

Cc: Sebastian Andrzej Siewior 
Cc: Scott Wood 
Cc: Thomas Gleixner 
Signed-off-by: Paul E. McKenney 
---
 kernel/rcu/rcutorture.c | 36 ++--
 1 file changed, 22 insertions(+), 14 deletions(-)

diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
index 99657ff..af64bd8 100644
--- a/kernel/rcu/rcutorture.c
+++ b/kernel/rcu/rcutorture.c
@@ -245,11 +245,11 @@ static const char *rcu_torture_writer_state_getname(void)
return rcu_torture_writer_state_names[i];
 }
 
-#if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU)
-#define rcu_can_boost() 1
-#else /* #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU) */
-#define rcu_can_boost() 0
-#endif /* #else #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU) 
*/
+#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)
@@ -923,9 +923,13 @@ static void rcu_torture_enable_rt_throttle(void)
 
 static bool rcu_torture_boost_failed(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(_done, 1) && cur_ops->gp_kthread_dbg)
+   cur_ops->gp_kthread_dbg();
 
return true; /* failed */
}
@@ -948,8 +952,8 @@ static int rcu_torture_boost(void *arg)
init_rcu_head_on_stack();
/* Each pass through the following loop does one boost-test cycle. */
do {
-   /* Track if the test failed already in this test interval? */
-   bool failed = false;
+   bool failed = false; // Test failed already in this test 
interval
+   bool firsttime = true;
 
/* Increment n_rcu_torture_boosts once per boost-test */
while (!kthread_should_stop()) {
@@ -975,18 +979,17 @@ static int rcu_torture_boost(void *arg)
 
/* Do one boost-test interval. */
endtime = oldstarttime + test_boost_duration * HZ;
-   call_rcu_time = jiffies;
while (time_before(jiffies, endtime)) {
/* If we don't have a callback in flight, post one. */
if (!smp_load_acquire()) {
/* RCU core before ->inflight = 1. */
smp_store_release(, 1);
-   call_rcu(, rcu_torture_boost_cb);
+   cur_ops->call(, rcu_torture_boost_cb);
/* Check if the boost test failed */
-   failed = failed ||
-rcu_torture_boost_failed(call_rcu_time,
-jiffies);
+   if (!firsttime && !failed)
+   failed = 
rcu_torture_boost_failed(call_rcu_time, jiffies);
call_rcu_time = jiffies;
+   firsttime = false;
}
if (stutter_wait("rcu_torture_boost"))
sched_set_fifo_low(current);
@@ -999,7 +1002,7 @@ static int rcu_torture_boost(void *arg)
 * this case the boost check would never happen in the above
 * loop so do another one here.
 */
-   if (!failed && smp_load_acquire())
+   if (!firsttime && !failed && smp_load_acquire())
rcu_torture_boost_failed(call_rcu_time, jiffies);
 
/*
@@ -1025,6 +1028,9 @@ 

[tip: core/rcu] torturescript: Don't rerun failed rcutorture builds

2021-04-11 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: a519d21480d330918bd522499a323432c31b6ec2
Gitweb:
https://git.kernel.org/tip/a519d21480d330918bd522499a323432c31b6ec2
Author:Paul E. McKenney 
AuthorDate:Tue, 05 Jan 2021 10:50:32 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 08 Mar 2021 14:23:01 -08:00

torturescript: Don't rerun failed rcutorture builds

If the build fails when running multiple instances of a given rcutorture
scenario, for example, using the kvm.sh --configs "8*RUDE01" argument,
the build will be rerun an additional seven times.  This is in some sense
correct, but it can waste significant time.  This commit therefore checks
for a prior failed build and simply copies over that build's output.

Signed-off-by: Paul E. McKenney 
---
 tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh | 13 ++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh 
b/tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh
index 536d103..9d8a82c 100755
--- a/tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh
+++ b/tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh
@@ -73,7 +73,7 @@ config_override_param "--kconfig argument" KcList 
"$TORTURE_KCONFIG_ARG"
 cp $T/KcList $resdir/ConfigFragment
 
 base_resdir=`echo $resdir | sed -e 's/\.[0-9]\+$//'`
-if test "$base_resdir" != "$resdir" -a -f $base_resdir/bzImage -a -f 
$base_resdir/vmlinux
+if test "$base_resdir" != "$resdir" && test -f $base_resdir/bzImage && test -f 
$base_resdir/vmlinux
 then
# Rerunning previous test, so use that test's kernel.
QEMU="`identify_qemu $base_resdir/vmlinux`"
@@ -83,6 +83,17 @@ then
ln -s $base_resdir/.config $resdir  # for kvm-recheck.sh
# Arch-independent indicator
touch $resdir/builtkernel
+elif test "$base_resdir" != "$resdir"
+then
+   # Rerunning previous test for which build failed
+   ln -s $base_resdir/Make*.out $resdir  # for kvm-recheck.sh
+   ln -s $base_resdir/.config $resdir  # for kvm-recheck.sh
+   echo Initial build failed, not running KVM, see $resdir.
+   if test -f $builddir.wait
+   then
+   mv $builddir.wait $builddir.ready
+   fi
+   exit 1
 elif kvm-build.sh $T/KcList $resdir
 then
# Had to build a kernel for this test.


[tip: core/rcu] rcu: Make rcu_read_unlock_special() expedite strict grace periods

2021-04-11 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 7308e0240410d3644c9d7cc6263079a58e3effeb
Gitweb:
https://git.kernel.org/tip/7308e0240410d3644c9d7cc6263079a58e3effeb
Author:Paul E. McKenney 
AuthorDate:Wed, 27 Jan 2021 13:57:16 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 08 Mar 2021 14:21:41 -08:00

rcu: Make rcu_read_unlock_special() expedite strict grace periods

In kernels built with CONFIG_RCU_STRICT_GRACE_PERIOD=y, every grace
period is an expedited grace period.  However, rcu_read_unlock_special()
does not treat them that way, instead allowing the deferred quiescent
state to be reported whenever.  This commit therefore adds a check of
this Kconfig option that causes rcu_read_unlock_special() to treat all
grace periods as expedited for CONFIG_RCU_STRICT_GRACE_PERIOD=y kernels.

Signed-off-by: Paul E. McKenney 
---
 kernel/rcu/tree_plugin.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
index e17cb23..a21c41c 100644
--- a/kernel/rcu/tree_plugin.h
+++ b/kernel/rcu/tree_plugin.h
@@ -615,6 +615,7 @@ static void rcu_read_unlock_special(struct task_struct *t)
 
expboost = (t->rcu_blocked_node && 
READ_ONCE(t->rcu_blocked_node->exp_tasks)) ||
   (rdp->grpmask & READ_ONCE(rnp->expmask)) ||
+  IS_ENABLED(CONFIG_RCU_STRICT_GRACE_PERIOD) ||
   (IS_ENABLED(CONFIG_RCU_BOOST) && irqs_were_disabled 
&&
t->rcu_blocked_node);
// Need to defer quiescent state until everything is enabled.


[tip: core/rcu] torture: Make jitter.sh handle large systems

2021-04-11 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 8126c57f00cea3502a017b7c76df1fac58f89e88
Gitweb:
https://git.kernel.org/tip/8126c57f00cea3502a017b7c76df1fac58f89e88
Author:Paul E. McKenney 
AuthorDate:Wed, 10 Feb 2021 13:25:58 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 08 Mar 2021 14:21:41 -08:00

torture: Make jitter.sh handle large systems

The current jitter.sh script expects cpumask bits to fit into whatever
the awk interpreter uses for an integer, which clearly does not hold for
even medium-sized systems these days.  This means that on a large system,
only the first 32 or 64 CPUs (depending) are subjected to jitter.sh
CPU-time perturbations.  This commit therefore computes a given CPU's
cpumask using text manipulation rather than arithmetic shifts.

Reported-by: Sebastian Andrzej Siewior 
Signed-off-by: Paul E. McKenney 
---
 tools/testing/selftests/rcutorture/bin/jitter.sh | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/tools/testing/selftests/rcutorture/bin/jitter.sh 
b/tools/testing/selftests/rcutorture/bin/jitter.sh
index 188b864..3a856ec 100755
--- a/tools/testing/selftests/rcutorture/bin/jitter.sh
+++ b/tools/testing/selftests/rcutorture/bin/jitter.sh
@@ -67,10 +67,10 @@ do
srand(n + me + systime());
ncpus = split(cpus, ca);
curcpu = ca[int(rand() * ncpus + 1)];
-   mask = lshift(1, curcpu);
-   if (mask + 0 <= 0)
-   mask = 1;
-   printf("%#x\n", mask);
+   z = "";
+   for (i = 1; 4 * i <= curcpu; i++)
+   z = z "0";
+   print "0x" 2 ^ (curcpu % 4) z;
}' < /dev/null`
n=$(($n+1))
if ! taskset -p $cpumask $$ > /dev/null 2>&1


[tip: core/rcu] rcutorture: Make TREE03 use real-time tree.use_softirq setting

2021-04-11 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: e2b949d54392ad890bb10fb8954d967e2fcd7503
Gitweb:
https://git.kernel.org/tip/e2b949d54392ad890bb10fb8954d967e2fcd7503
Author:Paul E. McKenney 
AuthorDate:Thu, 14 Jan 2021 16:11:04 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 08 Mar 2021 14:21:40 -08:00

rcutorture: Make TREE03 use real-time tree.use_softirq setting

TREE03 tests RCU priority boosting, which is a real-time feature.
It would also be good if it tested something closer to what is
actually used by the real-time folks.  This commit therefore adds
tree.use_softirq=0 to the TREE03 kernel boot parameters in TREE03.boot.

Signed-off-by: Paul E. McKenney 
---
 tools/testing/selftests/rcutorture/configs/rcu/TREE03.boot | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/testing/selftests/rcutorture/configs/rcu/TREE03.boot 
b/tools/testing/selftests/rcutorture/configs/rcu/TREE03.boot
index 1c21894..64f864f 100644
--- a/tools/testing/selftests/rcutorture/configs/rcu/TREE03.boot
+++ b/tools/testing/selftests/rcutorture/configs/rcu/TREE03.boot
@@ -4,3 +4,4 @@ rcutree.gp_init_delay=3
 rcutree.gp_cleanup_delay=3
 rcutree.kthread_prio=2
 threadirqs
+tree.use_softirq=0


[tip: core/rcu] torture: Allow 1G of memory for torture.sh kvfree testing

2021-04-11 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 3d4977b68101b38c3f9d3be3d89e17ef1fdfc1d3
Gitweb:
https://git.kernel.org/tip/3d4977b68101b38c3f9d3be3d89e17ef1fdfc1d3
Author:Paul E. McKenney 
AuthorDate:Thu, 28 Jan 2021 16:38:19 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 08 Mar 2021 14:23:01 -08:00

torture: Allow 1G of memory for torture.sh kvfree testing

Yes, I do recall a time when 512MB of memory was a lot of mass storage,
much less main memory, but the rcuscale kvfree_rcu() testing invoked by
torture.sh can sometimes exceed it on large systems, resulting in OOM.
This commit therefore causes torture.sh to pase the "--memory 1G"
argument to kvm.sh to reserve a full gigabyte for this purpose.

Signed-off-by: Paul E. McKenney 
---
 tools/testing/selftests/rcutorture/bin/torture.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/rcutorture/bin/torture.sh 
b/tools/testing/selftests/rcutorture/bin/torture.sh
index ad7525b..56e2e1a 100755
--- a/tools/testing/selftests/rcutorture/bin/torture.sh
+++ b/tools/testing/selftests/rcutorture/bin/torture.sh
@@ -374,7 +374,7 @@ done
 if test "$do_kvfree" = "yes"
 then
torture_bootargs="rcuscale.kfree_rcu_test=1 rcuscale.kfree_nthreads=16 
rcuscale.holdoff=20 rcuscale.kfree_loops=1 torture.disable_onoff_at_boot"
-   torture_set "rcuscale-kvfree" 
tools/testing/selftests/rcutorture/bin/kvm.sh --torture rcuscale --allcpus 
--duration 10 --kconfig "CONFIG_NR_CPUS=$HALF_ALLOTED_CPUS" --trust-make
+   torture_set "rcuscale-kvfree" 
tools/testing/selftests/rcutorture/bin/kvm.sh --torture rcuscale --allcpus 
--duration 10 --kconfig "CONFIG_NR_CPUS=$HALF_ALLOTED_CPUS" --memory 1G 
--trust-make
 fi
 
 echo " --- " $scriptname $args


[tip: core/rcu] rcu-tasks: Add block comment laying out RCU Tasks Trace design

2021-04-11 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: a434dd10cd843c7348e7c54c77eb0fac27beceb4
Gitweb:
https://git.kernel.org/tip/a434dd10cd843c7348e7c54c77eb0fac27beceb4
Author:Paul E. McKenney 
AuthorDate:Thu, 25 Feb 2021 10:26:00 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 08 Mar 2021 14:22:02 -08:00

rcu-tasks: Add block comment laying out RCU Tasks Trace design

This commit adds a block comment that gives a high-level overview of
how RCU tasks trace grace periods progress.  It also adds a note about
how exiting tasks are handled, plus it gives an overview of the memory
ordering.

Reported-by: Peter Zijlstra 
Reported-by: Mathieu Desnoyers 
[ paulmck: Fix commit log per Mathieu Desnoyers feedback. ]
Signed-off-by: Paul E. McKenney 
---
 kernel/rcu/tasks.h | 36 
 1 file changed, 36 insertions(+)

diff --git a/kernel/rcu/tasks.h b/kernel/rcu/tasks.h
index 17c8ebe..350ebf5 100644
--- a/kernel/rcu/tasks.h
+++ b/kernel/rcu/tasks.h
@@ -726,6 +726,42 @@ EXPORT_SYMBOL_GPL(show_rcu_tasks_rude_gp_kthread);
 // flavors, rcu_preempt and rcu_sched.  The fact that RCU Tasks Trace
 // readers can operate from idle, offline, and exception entry/exit in no
 // way allows rcu_preempt and rcu_sched readers to also do so.
+//
+// The implementation uses rcu_tasks_wait_gp(), which relies on function
+// pointers in the rcu_tasks structure.  The rcu_spawn_tasks_trace_kthread()
+// function sets these function pointers up so that rcu_tasks_wait_gp()
+// invokes these functions in this order:
+//
+// rcu_tasks_trace_pregp_step():
+// Initialize the count of readers and block CPU-hotplug operations.
+// rcu_tasks_trace_pertask(), invoked on every non-idle task:
+// Initialize per-task state and attempt to identify an immediate
+// quiescent state for that task, or, failing that, attempt to
+// set that task's .need_qs flag so that task's next outermost
+// rcu_read_unlock_trace() will report the quiescent state (in which
+// case the count of readers is incremented).  If both attempts fail,
+// the task is added to a "holdout" list.
+// rcu_tasks_trace_postscan():
+// Initialize state and attempt to identify an immediate quiescent
+// state as above (but only for idle tasks), unblock CPU-hotplug
+// operations, and wait for an RCU grace period to avoid races with
+// tasks that are in the process of exiting.
+// check_all_holdout_tasks_trace(), repeatedly until holdout list is empty:
+// Scans the holdout list, attempting to identify a quiescent state
+// for each task on the list.  If there is a quiescent state, the
+// corresponding task is removed from the holdout list.
+// rcu_tasks_trace_postgp():
+// Wait for the count of readers do drop to zero, reporting any stalls.
+// Also execute full memory barriers to maintain ordering with code
+// executing after the grace period.
+//
+// The exit_tasks_rcu_finish_trace() synchronizes with exiting tasks.
+//
+// Pre-grace-period update-side code is ordered before the grace
+// period via the ->cbs_lock and barriers in rcu_tasks_kthread().
+// Pre-grace-period read-side code is ordered before the grace period by
+// atomic_dec_and_test() of the count of readers (for IPIed readers) and by
+// scheduler context-switch ordering (for locked-down non-running readers).
 
 // The lockdep state must be outside of #ifdef to be useful.
 #ifdef CONFIG_DEBUG_LOCK_ALLOC


[tip: core/rcu] torture: Eliminate jitter_pids file

2021-04-11 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 1f922db8eef015f261480347aaf79fa9a25728f2
Gitweb:
https://git.kernel.org/tip/1f922db8eef015f261480347aaf79fa9a25728f2
Author:Paul E. McKenney 
AuthorDate:Thu, 11 Feb 2021 10:56:42 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 08 Mar 2021 14:23:01 -08:00

torture: Eliminate jitter_pids file

Now that there is a reliable way to convince the jitter.sh scripts to
stop, the jitter_pids file is not needed, nor is the code that kills all
the PIDs contained in this file.  This commit therefore eliminates this
file and the code using it.

Signed-off-by: Paul E. McKenney 
---
 tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh | 14 +---
 tools/testing/selftests/rcutorture/bin/kvm.sh|  5 +---
 2 files changed, 1 insertion(+), 18 deletions(-)

diff --git a/tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh 
b/tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh
index fed6f10..eb5346b 100755
--- a/tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh
+++ b/tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh
@@ -270,20 +270,6 @@ do
echo "ps -fp $killpid" >> $resdir/Warnings 2>&1
ps -fp $killpid >> $resdir/Warnings 2>&1
fi
-   # Reduce probability of PID reuse by allowing a 
one-minute buffer
-   if test $((kruntime + 60)) -lt $seconds && test -s 
"$resdir/../jitter_pids"
-   then
-   awk < "$resdir/../jitter_pids" '
-   NF > 0 {
-   pidlist = pidlist " " $1;
-   n++;
-   }
-   END {
-   if (n > 0) {
-   print "kill " pidlist;
-   }
-   }' | sh
-   fi
else
echo ' ---' `date`: "Kernel done"
fi
diff --git a/tools/testing/selftests/rcutorture/bin/kvm.sh 
b/tools/testing/selftests/rcutorture/bin/kvm.sh
index 48da4cd..de93802 100755
--- a/tools/testing/selftests/rcutorture/bin/kvm.sh
+++ b/tools/testing/selftests/rcutorture/bin/kvm.sh
@@ -502,12 +502,9 @@ function dump(first, pastlast, batchnum)
print "if test -n \"$needqemurun\""
print "then"
print "\techo  Starting kernels. `date` | tee -a " rd "log";
-   print "\techo > " rd "jitter_pids"
print "\ttouch " rd "jittering"
-   for (j = 0; j < njitter; j++) {
+   for (j = 0; j < njitter; j++)
print "\tjitter.sh " j " " dur " " rd "jittering " ja[2] " " 
ja[3] "&"
-   print "\techo $! >> " rd "jitter_pids"
-   }
print "\twhile ls $runfiles > /dev/null 2>&1"
print "\tdo"
print "\t\t:"


[tip: core/rcu] torture: Provide bare-metal modprobe-based advice

2021-04-11 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: a8dafbf3a5465bea6d9b45a4f011ba9b56d8b267
Gitweb:
https://git.kernel.org/tip/a8dafbf3a5465bea6d9b45a4f011ba9b56d8b267
Author:Paul E. McKenney 
AuthorDate:Wed, 03 Feb 2021 15:44:29 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 08 Mar 2021 14:23:01 -08:00

torture: Provide bare-metal modprobe-based advice

In some environments, the torture-testing use of virtualization is
inconvenient.  In such cases, the modprobe and rmmod commands may be used
to do torture testing, but significant setup is required to build, boot,
and modprobe a kernel so as to match a given torture-test scenario.
This commit therefore creates a "bare-metal" file in each results
directory containing steps to run the corresponding scenario using the
modprobe command on bare metal.  For example, the contents of this file
after using kvm.sh to build an rcutorture TREE01 kernel, perhaps with
the --buildonly argument, is as follows:

To run this scenario on bare metal:

 1. Set your bare-metal build tree to the state shown in this file:

/home/git/linux-rcu/tools/testing/selftests/rcutorture/res/2021.02.04-17.10.19/testid.txt
 2. Update your bare-metal build tree's .config based on this file:

/home/git/linux-rcu/tools/testing/selftests/rcutorture/res/2021.02.04-17.10.19/TREE01/ConfigFragment
 3. Make the bare-metal kernel's build system aware of your .config updates:
$ yes "" | make oldconfig
 4. Build your bare-metal kernel.
 5. Boot your bare-metal kernel with the following parameters:
maxcpus=8 nr_cpus=43 rcutree.gp_preinit_delay=3 rcutree.gp_init_delay=3 
rcutree.gp_cleanup_delay=3 rcu_nocbs=0-1,3-7
 6. Start the test with the following command:
$ modprobe rcutorture nocbs_nthreads=8 nocbs_toggle=1000 fwd_progress=0 
onoff_interval=1000 onoff_holdoff=30 n_barrier_cbs=4 stat_interval=15 
shutdown_secs=120 test_no_idle_hz=1 verbose=1
 7. After some time, end the test with the following command:
$ rmmod rcutorture
 8. Copy your bare-metal kernel's .config file, overwriting this file:

/home/git/linux-rcu/tools/testing/selftests/rcutorture/res/2021.02.04-17.10.19/TREE01/.config
 9. Copy the console output from just before the modprobe to just after
the rmmod into this file:

/home/git/linux-rcu/tools/testing/selftests/rcutorture/res/2021.02.04-17.10.19/TREE01/console.log
10. Check for runtime errors using the following command:
   $ tools/testing/selftests/rcutorture/bin/kvm-recheck.sh 
/home/git/linux-rcu/tools/testing/selftests/rcutorture/res/2021.02.04-17.10.19

Signed-off-by: Paul E. McKenney 
---
 tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh | 44 ++-
 tools/testing/selftests/rcutorture/bin/kvm.sh|  4 +-
 2 files changed, 42 insertions(+), 6 deletions(-)

diff --git a/tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh 
b/tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh
index 9d8a82c..03c0410 100755
--- a/tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh
+++ b/tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh
@@ -7,15 +7,15 @@
 # Execute this in the source tree.  Do not run it as a background task
 # because qemu does not seem to like that much.
 #
-# Usage: kvm-test-1-run.sh config builddir resdir seconds qemu-args boot_args
+# Usage: kvm-test-1-run.sh config builddir resdir seconds qemu-args 
boot_args_in
 #
 # qemu-args defaults to "-enable-kvm -nographic", along with arguments
 #  specifying the number of CPUs and other options
 #  generated from the underlying CPU architecture.
-# boot_args defaults to value returned by the per_version_boot_params
+# boot_args_in defaults to value returned by the per_version_boot_params
 #  shell function.
 #
-# Anything you specify for either qemu-args or boot_args is appended to
+# Anything you specify for either qemu-args or boot_args_in is appended to
 # the default values.  The "-smp" value is deduced from the contents of
 # the config fragment.
 #
@@ -134,7 +134,7 @@ do
 done
 seconds=$4
 qemu_args=$5
-boot_args=$6
+boot_args_in=$6
 
 if test -z "$TORTURE_BUILDONLY"
 then
@@ -144,7 +144,7 @@ fi
 # Generate -smp qemu argument.
 qemu_args="-enable-kvm -nographic $qemu_args"
 cpu_count=`configNR_CPUS.sh $resdir/ConfigFragment`
-cpu_count=`configfrag_boot_cpus "$boot_args" "$config_template" "$cpu_count"`
+cpu_count=`configfrag_boot_cpus "$boot_args_in" "$config_template" 
"$cpu_count"`
 if test "$cpu_count" -gt "$TORTURE_ALLOTED_CPUS"
 then
echo CPU count limited from $cpu_count to $TORTURE_ALLOTED_CPUS | tee 
-a $resdir/Warnings
@@ -160,13 +160,45 @@ qemu_args="$qemu_args `identify_qemu_args "$QEMU" 
"$resdir/console.log"`"
 qemu_append="`identify_qemu_append "$QEMU"`"
 
 # Pull in Kconfig-fragment boot parameters
-boot_args="`configfrag_boot_params "$boot_args" "$config_template"`"
+boot_args="`configfrag_boot_params 

[tip: core/rcu] refscale: Disable verbose torture-test output

2021-04-11 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: aebf8c7bf6d508dfb4255db8f7355ca819d9e6c9
Gitweb:
https://git.kernel.org/tip/aebf8c7bf6d508dfb4255db8f7355ca819d9e6c9
Author:Paul E. McKenney 
AuthorDate:Thu, 28 Jan 2021 10:17:26 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 08 Mar 2021 14:23:01 -08:00

refscale: Disable verbose torture-test output

Given large numbers of threads, the quantity of torture-test output is
sufficient to sometimes result in RCU CPU stall warnings.  The probability
of these stall warnings was greatly reduced by batching the output,
but the warnings were not eliminated.  However, the actual test only
depends on console output that is printed even when refscale.verbose=0.
This commit therefore causes this test to run with refscale.verbose=0.

Signed-off-by: Paul E. McKenney 
---
 tools/testing/selftests/rcutorture/configs/refscale/ver_functions.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git 
a/tools/testing/selftests/rcutorture/configs/refscale/ver_functions.sh 
b/tools/testing/selftests/rcutorture/configs/refscale/ver_functions.sh
index 321e826..f81fa2c 100644
--- a/tools/testing/selftests/rcutorture/configs/refscale/ver_functions.sh
+++ b/tools/testing/selftests/rcutorture/configs/refscale/ver_functions.sh
@@ -12,5 +12,5 @@
 # Adds per-version torture-module parameters to kernels supporting them.
 per_version_boot_params () {
echo $1 refscale.shutdown=1 \
-   refscale.verbose=1
+   refscale.verbose=0
 }


[tip: core/rcu] torture: Reverse jittering and duration parameters for jitter.sh

2021-04-11 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 4cd54518c3d8afadd11ebd6ad4f03b00859f5e85
Gitweb:
https://git.kernel.org/tip/4cd54518c3d8afadd11ebd6ad4f03b00859f5e85
Author:Paul E. McKenney 
AuthorDate:Thu, 11 Feb 2021 11:54:43 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 08 Mar 2021 14:23:01 -08:00

torture: Reverse jittering and duration parameters for jitter.sh

Remote rcutorture testing requires that jitter.sh continue to be
invoked from the generated script for local runs, but that it instead
be invoked on the remote system for distributed runs.  This argues
for common jitterstart and jitterstop scripts.  But it would be good
for jitterstart and jitterstop to control the name and location of the
"jittering" file, while continuing to have the duration controlled by
the caller of these new scripts.

This commit therefore reverses the order of the jittering and duration
parameters for jitter.sh, so that the jittering parameter precedes the
duration parameter.

Signed-off-by: Paul E. McKenney 
---
 tools/testing/selftests/rcutorture/bin/jitter.sh | 6 +++---
 tools/testing/selftests/rcutorture/bin/kvm.sh| 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/tools/testing/selftests/rcutorture/bin/jitter.sh 
b/tools/testing/selftests/rcutorture/bin/jitter.sh
index ed0ea86..ff1d3e4 100755
--- a/tools/testing/selftests/rcutorture/bin/jitter.sh
+++ b/tools/testing/selftests/rcutorture/bin/jitter.sh
@@ -5,7 +5,7 @@
 # of this script is to inflict random OS jitter on a concurrently running
 # test.
 #
-# Usage: jitter.sh me duration jittering-path [ sleepmax [ spinmax ] ]
+# Usage: jitter.sh me jittering-path duration [ sleepmax [ spinmax ] ]
 #
 # me: Random-number-generator seed salt.
 # duration: Time to run in seconds.
@@ -18,8 +18,8 @@
 # Authors: Paul E. McKenney 
 
 me=$(($1 * 1000))
-duration=$2
-jittering=$3
+jittering=$2
+duration=$3
 sleepmax=${4-100}
 spinmax=${5-1000}
 
diff --git a/tools/testing/selftests/rcutorture/bin/kvm.sh 
b/tools/testing/selftests/rcutorture/bin/kvm.sh
index de93802..a2ee3f2 100755
--- a/tools/testing/selftests/rcutorture/bin/kvm.sh
+++ b/tools/testing/selftests/rcutorture/bin/kvm.sh
@@ -504,7 +504,7 @@ function dump(first, pastlast, batchnum)
print "\techo  Starting kernels. `date` | tee -a " rd "log";
print "\ttouch " rd "jittering"
for (j = 0; j < njitter; j++)
-   print "\tjitter.sh " j " " dur " " rd "jittering " ja[2] " " 
ja[3] "&"
+   print "\tjitter.sh " j " " rd "jittering " dur " " ja[2] " " 
ja[3] "&"
print "\twhile ls $runfiles > /dev/null 2>&1"
print "\tdo"
print "\t\t:"


[tip: core/rcu] torture: Use file-based protocol to mark batch's runs complete

2021-04-11 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: b674100e630bf9211d7edce06b5d734b125a74ee
Gitweb:
https://git.kernel.org/tip/b674100e630bf9211d7edce06b5d734b125a74ee
Author:Paul E. McKenney 
AuthorDate:Wed, 10 Feb 2021 16:28:44 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 08 Mar 2021 14:23:01 -08:00

torture: Use file-based protocol to mark batch's runs complete

Currently, the script generated by kvm.sh does a "wait" to wait on both
the current batch's guest OSes and any jitter.sh scripts.  This works,
but makes it hard to abstract the jittering so that common code can be
used for both local and distributed runs.  This commit therefore uses
"build.run" files in scenario directories, and these files are removed
after the corresponding scenario's guest OS has completed.

Note that --build-only runs do not create build.run files because they
also do not create guest OSes and do not run any jitter.sh scripts.

Signed-off-by: Paul E. McKenney 
---
 tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh |  3 ++-
 tools/testing/selftests/rcutorture/bin/kvm.sh| 13 +--
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh 
b/tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh
index 91578d3..fed6f10 100755
--- a/tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh
+++ b/tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh
@@ -345,4 +345,7 @@ then
echo Unknown PID, cannot kill qemu command
 fi
 
+# Tell the script that this run is done.
+rm -f $resdir/build.run
+
 parse-console.sh $resdir/console.log $title
diff --git a/tools/testing/selftests/rcutorture/bin/kvm.sh 
b/tools/testing/selftests/rcutorture/bin/kvm.sh
index 7944510..1f5f872 100755
--- a/tools/testing/selftests/rcutorture/bin/kvm.sh
+++ b/tools/testing/selftests/rcutorture/bin/kvm.sh
@@ -469,9 +469,15 @@ function dump(first, pastlast, batchnum)
print "echo ", cfr[jn], cpusr[jn] ovf ": Build complete. `date` 
| tee -a " rd "log";
jn++;
}
+   print "runfiles="
for (j = 1; j < jn; j++) {
builddir=rd cfr[j] "/build";
-   print "rm -f " builddir ".ready"
+   if (TORTURE_BUILDONLY)
+   print "rm -f " builddir ".ready"
+   else
+   print "mv " builddir ".ready " builddir ".run"
+   print "runfiles=\"$runfiles " builddir ".run\""
+   fi
print "if test -f \"" rd cfr[j] "/builtkernel\""
print "then"
print "\techo ", cfr[j], cpusr[j] ovf ": Kernel present. 
`date` | tee -a " rd "log";
@@ -501,7 +507,10 @@ function dump(first, pastlast, batchnum)
print "\tjitter.sh " j " " dur " " ja[2] " " ja[3] "&"
print "\techo $! >> " rd "jitter_pids"
}
-   print "\twait"
+   print "\twhile ls $runfiles > /dev/null 2>&1"
+   print "\tdo"
+   print "\t\t:"
+   print "\tdone"
print "\techo  All kernel runs complete. `date` | tee -a " rd "log";
print "else"
print "\twait"


[tip: core/rcu] torture: Improve readability of the testid.txt file

2021-04-11 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: f9d2f1e2c426ad6c4d7661cc7d90be4de2c4f7a4
Gitweb:
https://git.kernel.org/tip/f9d2f1e2c426ad6c4d7661cc7d90be4de2c4f7a4
Author:Paul E. McKenney 
AuthorDate:Thu, 04 Feb 2021 17:20:45 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 08 Mar 2021 14:23:01 -08:00

torture: Improve readability of the testid.txt file

The testid.txt file was intended for occasional in extremis use, but
now that the new "bare-metal" file references it, it might see more use.
This commit therefore labels sections of output and adds spacing to make
it easier to see what needs to be done to make a bare-metal build tree
match an rcutorture build tree.

Of course, you can avoid this whole issue by building your bare-metal
kernel in the same directory in which you ran rcutorture, but that might
not always be an option.

Signed-off-by: Paul E. McKenney 
---
 tools/testing/selftests/rcutorture/bin/kvm.sh |  9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/rcutorture/bin/kvm.sh 
b/tools/testing/selftests/rcutorture/bin/kvm.sh
index 35a2132..1de198d 100755
--- a/tools/testing/selftests/rcutorture/bin/kvm.sh
+++ b/tools/testing/selftests/rcutorture/bin/kvm.sh
@@ -404,11 +404,16 @@ echo $scriptname $args
 touch $resdir/$ds/log
 echo $scriptname $args >> $resdir/$ds/log
 echo ${TORTURE_SUITE} > $resdir/$ds/TORTURE_SUITE
-pwd > $resdir/$ds/testid.txt
+echo Build directory: `pwd` > $resdir/$ds/testid.txt
 if test -d .git
 then
+   echo Current commit: `git rev-parse HEAD` >> $resdir/$ds/testid.txt
+   echo >> $resdir/$ds/testid.txt
+   echo ' ---' Output of "'"git status"'": >> $resdir/$ds/testid.txt
git status >> $resdir/$ds/testid.txt
-   git rev-parse HEAD >> $resdir/$ds/testid.txt
+   echo >> $resdir/$ds/testid.txt
+   echo >> $resdir/$ds/testid.txt
+   echo ' ---' Output of "'"git diff HEAD"'": >> $resdir/$ds/testid.txt
git diff HEAD >> $resdir/$ds/testid.txt
 fi
 ___EOF___


[tip: core/rcu] rcuscale: Disable verbose torture-test output

2021-04-11 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 0e7457b550233314394574c6bdc890de9131daf5
Gitweb:
https://git.kernel.org/tip/0e7457b550233314394574c6bdc890de9131daf5
Author:Paul E. McKenney 
AuthorDate:Thu, 28 Jan 2021 10:15:02 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 08 Mar 2021 14:23:01 -08:00

rcuscale: Disable verbose torture-test output

Given large numbers of threads, the quantity of torture-test output is
sufficient to sometimes result in RCU CPU stall warnings.  The probability
of these stall warnings was greatly reduced by batching the output,
but the warnings were not eliminated.  However, the actual test only
depends on console output that is printed even when rcuscale.verbose=0.
This commit therefore causes this test to run with rcuscale.verbose=0.

Signed-off-by: Paul E. McKenney 
---
 tools/testing/selftests/rcutorture/configs/rcuscale/ver_functions.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git 
a/tools/testing/selftests/rcutorture/configs/rcuscale/ver_functions.sh 
b/tools/testing/selftests/rcutorture/configs/rcuscale/ver_functions.sh
index 0333e9b..ffbe151 100644
--- a/tools/testing/selftests/rcutorture/configs/rcuscale/ver_functions.sh
+++ b/tools/testing/selftests/rcutorture/configs/rcuscale/ver_functions.sh
@@ -12,5 +12,5 @@
 # Adds per-version torture-module parameters to kernels supporting them.
 per_version_boot_params () {
echo $1 rcuscale.shutdown=1 \
-   rcuscale.verbose=1
+   rcuscale.verbose=0
 }


[tip: core/rcu] torture: Move build/run synchronization files into scenario directories

2021-04-11 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 3c43ce53fdb39921f4ee71c65dc100296e15640f
Gitweb:
https://git.kernel.org/tip/3c43ce53fdb39921f4ee71c65dc100296e15640f
Author:Paul E. McKenney 
AuthorDate:Wed, 10 Feb 2021 15:15:13 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 08 Mar 2021 14:23:01 -08:00

torture: Move build/run synchronization files into scenario directories

Currently the bN.ready and bN.wait files are placed in the
rcutorture directory, which really is not at all a good place
for run-specific files.  This commit therefore renames these
files to build.ready and build.wait and then moves them into the
scenario directories within the "res" directory, for example, into
tools/testing/selftests/rcutorture/res/2021.02.10-15.08.23/TINY01.

Signed-off-by: Paul E. McKenney 
---
 tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh | 25 +++
 tools/testing/selftests/rcutorture/bin/kvm.sh| 10 +--
 2 files changed, 16 insertions(+), 19 deletions(-)

diff --git a/tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh 
b/tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh
index 03c0410..91578d3 100755
--- a/tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh
+++ b/tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh
@@ -7,7 +7,7 @@
 # Execute this in the source tree.  Do not run it as a background task
 # because qemu does not seem to like that much.
 #
-# Usage: kvm-test-1-run.sh config builddir resdir seconds qemu-args 
boot_args_in
+# Usage: kvm-test-1-run.sh config resdir seconds qemu-args boot_args_in
 #
 # qemu-args defaults to "-enable-kvm -nographic", along with arguments
 #  specifying the number of CPUs and other options
@@ -35,8 +35,7 @@ mkdir $T
 config_template=${1}
 config_dir=`echo $config_template | sed -e 's,/[^/]*$,,'`
 title=`echo $config_template | sed -e 's/^.*\///'`
-builddir=${2}
-resdir=${3}
+resdir=${2}
 if test -z "$resdir" -o ! -d "$resdir" -o ! -w "$resdir"
 then
echo "kvm-test-1-run.sh :$resdir: Not a writable directory, cannot 
store results into it"
@@ -89,9 +88,9 @@ then
ln -s $base_resdir/Make*.out $resdir  # for kvm-recheck.sh
ln -s $base_resdir/.config $resdir  # for kvm-recheck.sh
echo Initial build failed, not running KVM, see $resdir.
-   if test -f $builddir.wait
+   if test -f $resdir/build.wait
then
-   mv $builddir.wait $builddir.ready
+   mv $resdir/build.wait $resdir/build.ready
fi
exit 1
 elif kvm-build.sh $T/KcList $resdir
@@ -118,23 +117,23 @@ else
# Build failed.
cp .config $resdir || :
echo Build failed, not running KVM, see $resdir.
-   if test -f $builddir.wait
+   if test -f $resdir/build.wait
then
-   mv $builddir.wait $builddir.ready
+   mv $resdir/build.wait $resdir/build.ready
fi
exit 1
 fi
-if test -f $builddir.wait
+if test -f $resdir/build.wait
 then
-   mv $builddir.wait $builddir.ready
+   mv $resdir/build.wait $resdir/build.ready
 fi
-while test -f $builddir.ready
+while test -f $resdir/build.ready
 do
sleep 1
 done
-seconds=$4
-qemu_args=$5
-boot_args_in=$6
+seconds=$3
+qemu_args=$4
+boot_args_in=$5
 
 if test -z "$TORTURE_BUILDONLY"
 then
diff --git a/tools/testing/selftests/rcutorture/bin/kvm.sh 
b/tools/testing/selftests/rcutorture/bin/kvm.sh
index 1de198d..7944510 100755
--- a/tools/testing/selftests/rcutorture/bin/kvm.sh
+++ b/tools/testing/selftests/rcutorture/bin/kvm.sh
@@ -444,7 +444,6 @@ function dump(first, pastlast, batchnum)
print "needqemurun="
jn=1
for (j = first; j < pastlast; j++) {
-   builddir=KVM "/b" j - first + 1
cpusr[jn] = cpus[j];
if (cfrep[cf[j]] == "") {
cfr[jn] = cf[j];
@@ -453,15 +452,15 @@ function dump(first, pastlast, batchnum)
cfrep[cf[j]]++;
cfr[jn] = cf[j] "." cfrep[cf[j]];
}
+   builddir=rd cfr[jn] "/build";
if (cpusr[jn] > ncpus && ncpus != 0)
ovf = "-ovf";
else
ovf = "";
print "echo ", cfr[jn], cpusr[jn] ovf ": Starting build. `date` 
| tee -a " rd "log";
-   print "rm -f " builddir ".*";
-   print "touch " builddir ".wait";
print "mkdir " rd cfr[jn] " || :";
-   print "kvm-test-1-run.sh " CONFIGDIR cf[j], builddir, rd 
cfr[jn], dur " \"" TORTURE_QEMU_ARG "\" \"" TORTURE_BOOTARGS "\" > " rd cfr[jn] 
 "/kvm-test-1-run.sh.out 2>&1 &"
+   print "touch " builddir ".wait";
+   print "kvm-test-1-run.sh " CONFIGDIR cf[j], rd cfr[jn], dur " 
\"" TORTURE_QEMU_ARG "\" \"" TORTURE_BOOTARGS "\" > " rd cfr[jn]  
"/kvm-test-1-run.sh.out 2>&1 &"
print "echo ", 

[tip: core/rcu] torture: Use "jittering" file to control jitter.sh execution

2021-04-11 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 37812c9429722824859788cf754dd3e33f546908
Gitweb:
https://git.kernel.org/tip/37812c9429722824859788cf754dd3e33f546908
Author:Paul E. McKenney 
AuthorDate:Thu, 11 Feb 2021 10:39:28 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 08 Mar 2021 14:23:01 -08:00

torture: Use "jittering" file to control jitter.sh execution

Currently, jitter.sh execution is controlled by a time limit and by the
"kill" command.  The former allowed jitter.sh to run uselessly past
the end of a set of runs that panicked during boot, and the latter is
vulnerable to PID reuse.  This commit therefore introduces a "jittering"
file in the date-stamp directory within "res" that must be present for
the jitter.sh scripts to continue executing.  The time limit is still
in place in order to avoid disturbing runs featuring large trace dumps,
but the removal of the "jittering" file handles the panic-during-boot
scenario without relying on PIDs.

Signed-off-by: Paul E. McKenney 
---
 tools/testing/selftests/rcutorture/bin/jitter.sh | 10 ++
 tools/testing/selftests/rcutorture/bin/kvm.sh|  5 -
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/tools/testing/selftests/rcutorture/bin/jitter.sh 
b/tools/testing/selftests/rcutorture/bin/jitter.sh
index 188b864..ed0ea86 100755
--- a/tools/testing/selftests/rcutorture/bin/jitter.sh
+++ b/tools/testing/selftests/rcutorture/bin/jitter.sh
@@ -5,10 +5,11 @@
 # of this script is to inflict random OS jitter on a concurrently running
 # test.
 #
-# Usage: jitter.sh me duration [ sleepmax [ spinmax ] ]
+# Usage: jitter.sh me duration jittering-path [ sleepmax [ spinmax ] ]
 #
 # me: Random-number-generator seed salt.
 # duration: Time to run in seconds.
+# jittering-path: Path to file whose removal will stop this script.
 # sleepmax: Maximum microseconds to sleep, defaults to one second.
 # spinmax: Maximum microseconds to spin, defaults to one millisecond.
 #
@@ -18,8 +19,9 @@
 
 me=$(($1 * 1000))
 duration=$2
-sleepmax=${3-100}
-spinmax=${4-1000}
+jittering=$3
+sleepmax=${4-100}
+spinmax=${5-1000}
 
 n=1
 
@@ -47,7 +49,7 @@ do
fi
 
# Check for stop request.
-   if test -f "$TORTURE_STOPFILE"
+   if ! test -f "$jittering"
then
exit 1;
fi
diff --git a/tools/testing/selftests/rcutorture/bin/kvm.sh 
b/tools/testing/selftests/rcutorture/bin/kvm.sh
index 1f5f872..48da4cd 100755
--- a/tools/testing/selftests/rcutorture/bin/kvm.sh
+++ b/tools/testing/selftests/rcutorture/bin/kvm.sh
@@ -503,14 +503,17 @@ function dump(first, pastlast, batchnum)
print "then"
print "\techo  Starting kernels. `date` | tee -a " rd "log";
print "\techo > " rd "jitter_pids"
+   print "\ttouch " rd "jittering"
for (j = 0; j < njitter; j++) {
-   print "\tjitter.sh " j " " dur " " ja[2] " " ja[3] "&"
+   print "\tjitter.sh " j " " dur " " rd "jittering " ja[2] " " 
ja[3] "&"
print "\techo $! >> " rd "jitter_pids"
}
print "\twhile ls $runfiles > /dev/null 2>&1"
print "\tdo"
print "\t\t:"
print "\tdone"
+   print "\trm -f " rd "jittering"
+   print "\twait"
print "\techo  All kernel runs complete. `date` | tee -a " rd "log";
print "else"
print "\twait"


[tip: core/rcu] softirq: Don't try waking ksoftirqd before it has been spawned

2021-04-11 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 1c0c4bc1ceb580851b2d76fdef9712b3bdae134b
Gitweb:
https://git.kernel.org/tip/1c0c4bc1ceb580851b2d76fdef9712b3bdae134b
Author:Paul E. McKenney 
AuthorDate:Fri, 12 Feb 2021 16:20:40 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 15 Mar 2021 13:51:48 -07:00

softirq: Don't try waking ksoftirqd before it has been spawned

If there is heavy softirq activity, the softirq system will attempt
to awaken ksoftirqd and will stop the traditional back-of-interrupt
softirq processing.  This is all well and good, but only if the
ksoftirqd kthreads already exist, which is not the case during early
boot, in which case the system hangs.

One reproducer is as follows:

tools/testing/selftests/rcutorture/bin/kvm.sh --allcpus --duration 2 --configs 
"TREE03" --kconfig "CONFIG_DEBUG_LOCK_ALLOC=y CONFIG_PROVE_LOCKING=y 
CONFIG_NO_HZ_IDLE=y CONFIG_HZ_PERIODIC=n" --bootargs "threadirqs=1" --trust-make

This commit therefore adds a couple of existence checks for ksoftirqd
and forces back-of-interrupt softirq processing when ksoftirqd does not
yet exist.  With this change, the above test passes.

Reported-by: Sebastian Andrzej Siewior 
Reported-by: Uladzislau Rezki 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
[ paulmck: Remove unneeded check per Sebastian Siewior feedback. ]
Reviewed-by: Frederic Weisbecker 
Signed-off-by: Paul E. McKenney 
---
 kernel/softirq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/softirq.c b/kernel/softirq.c
index 9908ec4..bad14ca 100644
--- a/kernel/softirq.c
+++ b/kernel/softirq.c
@@ -211,7 +211,7 @@ static inline void invoke_softirq(void)
if (ksoftirqd_running(local_softirq_pending()))
return;
 
-   if (!force_irqthreads) {
+   if (!force_irqthreads || !__this_cpu_read(ksoftirqd)) {
 #ifdef CONFIG_HAVE_IRQ_EXIT_ON_IRQ_STACK
/*
 * We can safely execute softirq on the current stack if


[tip: core/rcu] torture: Record TORTURE_KCONFIG_GDB_ARG in qemu-cmd

2021-04-11 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: cc45716e07a41233b7c0b2183b0a3e60b85192e0
Gitweb:
https://git.kernel.org/tip/cc45716e07a41233b7c0b2183b0a3e60b85192e0
Author:Paul E. McKenney 
AuthorDate:Thu, 11 Feb 2021 16:19:29 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 22 Mar 2021 08:29:15 -07:00

torture: Record TORTURE_KCONFIG_GDB_ARG in qemu-cmd

When re-running old rcutorture builds, if the original run involved
gdb, the re-run also needs to do so.  This commit therefore records the
TORTURE_KCONFIG_GDB_ARG environment variable into the qemu-cmd file so
that the re-run can access it.

Signed-off-by: Paul E. McKenney 
---
 tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh 
b/tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh
index eb5346b..5d9ac90 100755
--- a/tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh
+++ b/tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh
@@ -201,6 +201,7 @@ echo kernel here: `head -n 1 $testid_txt | sed -e 's/^Build 
directory: //'`  >> 
 echo $QEMU $qemu_args -m $TORTURE_QEMU_MEM -kernel $KERNEL -append 
\"$qemu_append $boot_args\" $TORTURE_QEMU_GDB_ARG > $resdir/qemu-cmd
 echo "# TORTURE_SHUTDOWN_GRACE=$TORTURE_SHUTDOWN_GRACE" >> $resdir/qemu-cmd
 echo "# seconds=$seconds" >> $resdir/qemu-cmd
+echo "# TORTURE_KCONFIG_GDB_ARG=\"$TORTURE_KCONFIG_GDB_ARG\"" >> 
$resdir/qemu-cmd
 
 if test -n "$TORTURE_BUILDONLY"
 then


[tip: core/rcu] torture: Record kvm-test-1-run.sh and kvm-test-1-run-qemu.sh PIDs

2021-04-11 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: cb1fa863a00ba0e8faf69d2ebb960b75129bccd6
Gitweb:
https://git.kernel.org/tip/cb1fa863a00ba0e8faf69d2ebb960b75129bccd6
Author:Paul E. McKenney 
AuthorDate:Tue, 16 Feb 2021 16:55:04 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 22 Mar 2021 08:29:17 -07:00

torture: Record kvm-test-1-run.sh and kvm-test-1-run-qemu.sh PIDs

This commit records the process IDs of the kvm-test-1-run.sh and
kvm-test-1-run-qemu.sh scripts to ease monitoring of remotely running
instances of these scripts.

Signed-off-by: Paul E. McKenney 
---
 tools/testing/selftests/rcutorture/bin/kvm-test-1-run-qemu.sh | 2 ++
 tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh  | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/rcutorture/bin/kvm-test-1-run-qemu.sh 
b/tools/testing/selftests/rcutorture/bin/kvm-test-1-run-qemu.sh
index 6b0d71b..576a9b7 100755
--- a/tools/testing/selftests/rcutorture/bin/kvm-test-1-run-qemu.sh
+++ b/tools/testing/selftests/rcutorture/bin/kvm-test-1-run-qemu.sh
@@ -33,6 +33,8 @@ then
exit 1
 fi
 
+echo ' ---' `date`: Starting kernel, PID $$
+
 # Obtain settings from the qemu-cmd file.
 grep '^#' $resdir/qemu-cmd | sed -e 's/^# //' > $T/qemu-cmd-settings
 . $T/qemu-cmd-settings
diff --git a/tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh 
b/tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh
index a69f8ae..a386ca8 100755
--- a/tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh
+++ b/tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh
@@ -41,7 +41,7 @@ then
echo "kvm-test-1-run.sh :$resdir: Not a writable directory, cannot 
store results into it"
exit 1
 fi
-echo ' ---' `date`: Starting build
+echo ' ---' `date`: Starting build, PID $$
 echo ' ---' Kconfig fragment at: $config_template >> $resdir/log
 touch $resdir/ConfigFragment.input
 


[tip: core/rcu] rcu: Provide polling interfaces for Tree RCU grace periods

2021-04-11 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 7abb18bd7567480e34f46d3512369ec49499064e
Gitweb:
https://git.kernel.org/tip/7abb18bd7567480e34f46d3512369ec49499064e
Author:Paul E. McKenney 
AuthorDate:Thu, 25 Feb 2021 16:10:38 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 22 Mar 2021 08:23:48 -07:00

rcu: Provide polling interfaces for Tree RCU grace periods

There is a need for a non-blocking polling interface for RCU grace
periods, so this commit supplies start_poll_synchronize_rcu() and
poll_state_synchronize_rcu() for this purpose.  Note that the existing
get_state_synchronize_rcu() may be used if future grace periods are
inevitable (perhaps due to a later call_rcu() invocation).  The new
start_poll_synchronize_rcu() is to be used if future grace periods
might not otherwise happen.  Finally, poll_state_synchronize_rcu()
provides a lockless check for a grace period having elapsed since
the corresponding call to either of the get_state_synchronize_rcu()
or start_poll_synchronize_rcu().

As with get_state_synchronize_rcu(), the return value from either
get_state_synchronize_rcu() or start_poll_synchronize_rcu() is passed in
to a later call to either poll_state_synchronize_rcu() or the existing
(might_sleep) cond_synchronize_rcu().

[ paulmck: Remove redundant smp_mb() per Frederic Weisbecker feedback. ]
[ Update poll_state_synchronize_rcu() docbook per Frederic Weisbecker feedback. 
]
Reviewed-by: Frederic Weisbecker 
Signed-off-by: Paul E. McKenney 
---
 include/linux/rcutree.h |  2 +-
 kernel/rcu/tree.c   | 75 
 2 files changed, 70 insertions(+), 7 deletions(-)

diff --git a/include/linux/rcutree.h b/include/linux/rcutree.h
index df578b7..b89b541 100644
--- a/include/linux/rcutree.h
+++ b/include/linux/rcutree.h
@@ -41,6 +41,8 @@ void rcu_momentary_dyntick_idle(void);
 void kfree_rcu_scheduler_running(void);
 bool rcu_gp_might_be_stalled(void);
 unsigned long get_state_synchronize_rcu(void);
+unsigned long start_poll_synchronize_rcu(void);
+bool poll_state_synchronize_rcu(unsigned long oldstate);
 void cond_synchronize_rcu(unsigned long oldstate);
 
 void rcu_idle_enter(void);
diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
index da6f521..07e8122 100644
--- a/kernel/rcu/tree.c
+++ b/kernel/rcu/tree.c
@@ -3774,8 +3774,8 @@ EXPORT_SYMBOL_GPL(synchronize_rcu);
  * get_state_synchronize_rcu - Snapshot current RCU state
  *
  * Returns a cookie that is used by a later call to cond_synchronize_rcu()
- * to determine whether or not a full grace period has elapsed in the
- * meantime.
+ * or poll_state_synchronize_rcu() to determine whether or not a full
+ * grace period has elapsed in the meantime.
  */
 unsigned long get_state_synchronize_rcu(void)
 {
@@ -3789,13 +3789,76 @@ unsigned long get_state_synchronize_rcu(void)
 EXPORT_SYMBOL_GPL(get_state_synchronize_rcu);
 
 /**
+ * start_poll_synchronize_rcu - Snapshot and start RCU grace period
+ *
+ * Returns a cookie that is used by a later call to cond_synchronize_rcu()
+ * or poll_state_synchronize_rcu() to determine whether or not a full
+ * grace period has elapsed in the meantime.  If the needed grace period
+ * is not already slated to start, notifies RCU core of the need for that
+ * grace period.
+ *
+ * Interrupts must be enabled for the case where it is necessary to awaken
+ * the grace-period kthread.
+ */
+unsigned long start_poll_synchronize_rcu(void)
+{
+   unsigned long flags;
+   unsigned long gp_seq = get_state_synchronize_rcu();
+   bool needwake;
+   struct rcu_data *rdp;
+   struct rcu_node *rnp;
+
+   lockdep_assert_irqs_enabled();
+   local_irq_save(flags);
+   rdp = this_cpu_ptr(_data);
+   rnp = rdp->mynode;
+   raw_spin_lock_rcu_node(rnp); // irqs already disabled.
+   needwake = rcu_start_this_gp(rnp, rdp, gp_seq);
+   raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
+   if (needwake)
+   rcu_gp_kthread_wake();
+   return gp_seq;
+}
+EXPORT_SYMBOL_GPL(start_poll_synchronize_rcu);
+
+/**
+ * poll_state_synchronize_rcu - Conditionally wait for an RCU grace period
+ *
+ * @oldstate: return from call to get_state_synchronize_rcu() or 
start_poll_synchronize_rcu()
+ *
+ * If a full RCU grace period has elapsed since the earlier call from
+ * which oldstate was obtained, return @true, otherwise return @false.
+ * If @false is returned, it is the caller's responsibilty to invoke this
+ * function later on until it does return @true.  Alternatively, the caller
+ * can explicitly wait for a grace period, for example, by passing @oldstate
+ * to cond_synchronize_rcu() or by directly invoking synchronize_rcu().
+ *
+ * Yes, this function does not take counter wrap into account.
+ * But counter wrap is harmless.  If the counter wraps, we have waited for
+ * more than 2 billion grace periods (and way more on a 64-bit system!).
+ * Those needing to keep oldstate 

[tip: core/rcu] torture: Extract kvm-test-1-run-qemu.sh from kvm-test-1-run.sh

2021-04-11 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: d53f52d6fc220ba2074338ce6a91f837c7a7cba0
Gitweb:
https://git.kernel.org/tip/d53f52d6fc220ba2074338ce6a91f837c7a7cba0
Author:Paul E. McKenney 
AuthorDate:Fri, 12 Feb 2021 14:00:05 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 22 Mar 2021 08:29:16 -07:00

torture: Extract kvm-test-1-run-qemu.sh from kvm-test-1-run.sh

Currently, kvm-test-1-run.sh both builds and runs an rcutorture kernel,
which is inconvenient when it is necessary to re-run an old run or to
carry out a run on a remote system.  This commit therefore extracts the
portion of kvm-test-1-run.sh that invoke qemu to actually run rcutorture
and places it in kvm-test-1-run-qemu.sh.

Signed-off-by: Paul E. McKenney 
---
 tools/testing/selftests/rcutorture/bin/kvm-test-1-run-qemu.sh | 170 +++-
 tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh  | 127 +-
 2 files changed, 171 insertions(+), 126 deletions(-)
 create mode 100755 
tools/testing/selftests/rcutorture/bin/kvm-test-1-run-qemu.sh

diff --git a/tools/testing/selftests/rcutorture/bin/kvm-test-1-run-qemu.sh 
b/tools/testing/selftests/rcutorture/bin/kvm-test-1-run-qemu.sh
new file mode 100755
index 000..6b0d71b
--- /dev/null
+++ b/tools/testing/selftests/rcutorture/bin/kvm-test-1-run-qemu.sh
@@ -0,0 +1,170 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Carry out a kvm-based run for the specified qemu-cmd file, which might
+# have been generated by --build-only kvm.sh run.
+#
+# Usage: kvm-test-1-run-qemu.sh qemu-cmd-dir
+#
+# qemu-cmd-dir provides the directory containing qemu-cmd file.
+#  This is assumed to be of the form prefix/ds/scenario, where
+#  "ds" is the top-level date-stamped directory and "scenario"
+#  is the scenario name.  Any required adjustments to this file
+#  must have been made by the caller.  The shell-command comments
+#  at the end of the qemu-cmd file are not optional.
+#
+# Copyright (C) 2021 Facebook, Inc.
+#
+# Authors: Paul E. McKenney 
+
+T=${TMPDIR-/tmp}/kvm-test-1-run-qemu.sh.$$
+trap 'rm -rf $T' 0
+mkdir $T
+
+resdir="$1"
+if ! test -d "$resdir"
+then
+   echo $0: Nonexistent directory: $resdir
+   exit 1
+fi
+if ! test -f "$resdir/qemu-cmd"
+then
+   echo $0: Nonexistent qemu-cmd file: $resdir/qemu-cmd
+   exit 1
+fi
+
+# Obtain settings from the qemu-cmd file.
+grep '^#' $resdir/qemu-cmd | sed -e 's/^# //' > $T/qemu-cmd-settings
+. $T/qemu-cmd-settings
+
+# Decorate qemu-cmd with redirection, backgrounding, and PID capture
+sed -e 's/$/ 2>\&1 \&/' < $resdir/qemu-cmd > $T/qemu-cmd
+echo 'echo $! > $resdir/qemu_pid' >> $T/qemu-cmd
+
+# In case qemu refuses to run...
+echo "NOTE: $QEMU either did not run or was interactive" > $resdir/console.log
+
+# Attempt to run qemu
+kstarttime=`gawk 'BEGIN { print systime() }' < /dev/null`
+( . $T/qemu-cmd; wait `cat  $resdir/qemu_pid`; echo $? > $resdir/qemu-retval ) 
&
+commandcompleted=0
+if test -z "$TORTURE_KCONFIG_GDB_ARG"
+then
+   sleep 10 # Give qemu's pid a chance to reach the file
+   if test -s "$resdir/qemu_pid"
+   then
+   qemu_pid=`cat "$resdir/qemu_pid"`
+   echo Monitoring qemu job at pid $qemu_pid
+   else
+   qemu_pid=""
+   echo Monitoring qemu job at yet-as-unknown pid
+   fi
+fi
+if test -n "$TORTURE_KCONFIG_GDB_ARG"
+then
+   base_resdir=`echo $resdir | sed -e 's/\.[0-9]\+$//'`
+   if ! test -f $base_resdir/vmlinux
+   then
+   base_resdir=/path/to
+   fi
+   echo Waiting for you to attach a debug session, for example: > /dev/tty
+   echo "gdb $base_resdir/vmlinux" > /dev/tty
+   echo 'After symbols load and the "(gdb)" prompt appears:' > /dev/tty
+   echo "target remote :1234" > /dev/tty
+   echo "continue" > /dev/tty
+   kstarttime=`gawk 'BEGIN { print systime() }' < /dev/null`
+fi
+while :
+do
+   if test -z "$qemu_pid" -a -s "$resdir/qemu_pid"
+   then
+   qemu_pid=`cat "$resdir/qemu_pid"`
+   fi
+   kruntime=`gawk 'BEGIN { print systime() - '"$kstarttime"' }' < 
/dev/null`
+   if test -z "$qemu_pid" || kill -0 "$qemu_pid" > /dev/null 2>&1
+   then
+   if test -n "$TORTURE_KCONFIG_GDB_ARG"
+   then
+   :
+   elif test $kruntime -ge $seconds || test -f "$resdir/../STOP.1"
+   then
+   break;
+   fi
+   sleep 1
+   else
+   commandcompleted=1
+   if test $kruntime -lt $seconds
+   then
+   echo Completed in $kruntime vs. $seconds >> 
$resdir/Warnings 2>&1
+   grep "^(qemu) qemu:" $resdir/kvm-test-1-run.sh.out >> 
$resdir/Warnings 2>&1
+   killpid="`sed -n "s/^(qemu) qemu: terminating on signal 
[0-9]* from pid \([0-9]*\).*$/\1/p" 

[tip: core/rcu] torture: Abstract jitter.sh start/stop into scripts

2021-04-11 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 040accb3cd4ac4a8d151413f569b7ba6d918a19c
Gitweb:
https://git.kernel.org/tip/040accb3cd4ac4a8d151413f569b7ba6d918a19c
Author:Paul E. McKenney 
AuthorDate:Thu, 11 Feb 2021 12:37:46 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 22 Mar 2021 08:28:34 -07:00

torture: Abstract jitter.sh start/stop into scripts

This commit creates jitterstart.sh and jitterstop.sh scripts that handle
the starting and stopping of the jitter.sh scripts.  These must be sourced
using the bash "." command to allow the generated script to wait on the
backgrounded jitter.sh scripts.

Signed-off-by: Paul E. McKenney 
---
 tools/testing/selftests/rcutorture/bin/jitterstart.sh | 37 ++-
 tools/testing/selftests/rcutorture/bin/jitterstop.sh  | 23 ++-
 tools/testing/selftests/rcutorture/bin/kvm.sh |  7 +--
 3 files changed, 62 insertions(+), 5 deletions(-)
 create mode 100644 tools/testing/selftests/rcutorture/bin/jitterstart.sh
 create mode 100644 tools/testing/selftests/rcutorture/bin/jitterstop.sh

diff --git a/tools/testing/selftests/rcutorture/bin/jitterstart.sh 
b/tools/testing/selftests/rcutorture/bin/jitterstart.sh
new file mode 100644
index 000..3d710ad
--- /dev/null
+++ b/tools/testing/selftests/rcutorture/bin/jitterstart.sh
@@ -0,0 +1,37 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Start up the specified number of jitter.sh scripts in the background.
+#
+# Usage: . jitterstart.sh n jittering-dir duration [ sleepmax [ spinmax ] ]
+#
+# n: Number of jitter.sh scripts to start up.
+# jittering-dir: Directory in which to put "jittering" file.
+# duration: Time to run in seconds.
+# sleepmax: Maximum microseconds to sleep, defaults to one second.
+# spinmax: Maximum microseconds to spin, defaults to one millisecond.
+#
+# Copyright (C) 2021 Facebook, Inc.
+#
+# Authors: Paul E. McKenney 
+
+jitter_n=$1
+if test -z "$jitter_n"
+then
+   echo jitterstart.sh: Missing count of jitter.sh scripts to start.
+   exit 33
+fi
+jittering_dir=$2
+if test -z "$jittering_dir"
+then
+   echo jitterstart.sh: Missing directory in which to place jittering file.
+   exit 34
+fi
+shift
+shift
+
+touch ${jittering_dir}/jittering
+for ((jitter_i = 1; jitter_i <= $jitter_n; jitter_i++))
+do
+   jitter.sh $jitter_i "${jittering_dir}/jittering" "$@" &
+done
diff --git a/tools/testing/selftests/rcutorture/bin/jitterstop.sh 
b/tools/testing/selftests/rcutorture/bin/jitterstop.sh
new file mode 100644
index 000..576a4cf
--- /dev/null
+++ b/tools/testing/selftests/rcutorture/bin/jitterstop.sh
@@ -0,0 +1,23 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Remove the "jittering" file, signaling the jitter.sh scripts to stop,
+# then wait for them to terminate.
+#
+# Usage: . jitterstop.sh jittering-dir
+#
+# jittering-dir: Directory containing "jittering" file.
+#
+# Copyright (C) 2021 Facebook, Inc.
+#
+# Authors: Paul E. McKenney 
+
+jittering_dir=$1
+if test -z "$jittering_dir"
+then
+   echo jitterstop.sh: Missing directory in which to place jittering file.
+   exit 34
+fi
+
+rm -f ${jittering_dir}/jittering
+wait
diff --git a/tools/testing/selftests/rcutorture/bin/kvm.sh 
b/tools/testing/selftests/rcutorture/bin/kvm.sh
index a2ee3f2..d6973e4 100755
--- a/tools/testing/selftests/rcutorture/bin/kvm.sh
+++ b/tools/testing/selftests/rcutorture/bin/kvm.sh
@@ -502,15 +502,12 @@ function dump(first, pastlast, batchnum)
print "if test -n \"$needqemurun\""
print "then"
print "\techo  Starting kernels. `date` | tee -a " rd "log";
-   print "\ttouch " rd "jittering"
-   for (j = 0; j < njitter; j++)
-   print "\tjitter.sh " j " " rd "jittering " dur " " ja[2] " " 
ja[3] "&"
+   print "\t. jitterstart.sh " njitter " " rd " " dur " " ja[2] " " ja[3]
print "\twhile ls $runfiles > /dev/null 2>&1"
print "\tdo"
print "\t\t:"
print "\tdone"
-   print "\trm -f " rd "jittering"
-   print "\twait"
+   print "\t. jitterstop.sh " rd
print "\techo  All kernel runs complete. `date` | tee -a " rd "log";
print "else"
print "\twait"


[tip: core/rcu] rcu: Provide polling interfaces for Tiny RCU grace periods

2021-04-11 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 0909fc2b2c41aae50a18a36ac2858d156f521871
Gitweb:
https://git.kernel.org/tip/0909fc2b2c41aae50a18a36ac2858d156f521871
Author:Paul E. McKenney 
AuthorDate:Thu, 25 Feb 2021 17:36:06 -08:00
Committer: Paul E. McKenney 
CommitterDate: Wed, 24 Mar 2021 17:16:15 -07:00

rcu: Provide polling interfaces for Tiny RCU grace periods

There is a need for a non-blocking polling interface for RCU grace
periods, so this commit supplies start_poll_synchronize_rcu() and
poll_state_synchronize_rcu() for this purpose.  Note that the existing
get_state_synchronize_rcu() may be used if future grace periods are
inevitable (perhaps due to a later call_rcu() invocation).  The new
start_poll_synchronize_rcu() is to be used if future grace periods
might not otherwise happen.  Finally, poll_state_synchronize_rcu()
provides a lockless check for a grace period having elapsed since
the corresponding call to either of the get_state_synchronize_rcu()
or start_poll_synchronize_rcu().

As with get_state_synchronize_rcu(), the return value from either
get_state_synchronize_rcu() or start_poll_synchronize_rcu() is passed in
to a later call to either poll_state_synchronize_rcu() or the existing
(might_sleep) cond_synchronize_rcu().

[ paulmck: Revert cond_synchronize_rcu() to might_sleep() per Frederic 
Weisbecker feedback. ]
Reviewed-by: Frederic Weisbecker 
Signed-off-by: Paul E. McKenney 
---
 include/linux/rcutiny.h |  7 +++
 kernel/rcu/tiny.c   | 40 -
 2 files changed, 43 insertions(+), 4 deletions(-)

diff --git a/include/linux/rcutiny.h b/include/linux/rcutiny.h
index 2a97334..35e0be3 100644
--- a/include/linux/rcutiny.h
+++ b/include/linux/rcutiny.h
@@ -17,10 +17,9 @@
 /* Never flag non-existent other CPUs! */
 static inline bool rcu_eqs_special_set(int cpu) { return false; }
 
-static inline unsigned long get_state_synchronize_rcu(void)
-{
-   return 0;
-}
+unsigned long get_state_synchronize_rcu(void);
+unsigned long start_poll_synchronize_rcu(void);
+bool poll_state_synchronize_rcu(unsigned long oldstate);
 
 static inline void cond_synchronize_rcu(unsigned long oldstate)
 {
diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c
index aa897c3..c8a029f 100644
--- a/kernel/rcu/tiny.c
+++ b/kernel/rcu/tiny.c
@@ -32,12 +32,14 @@ struct rcu_ctrlblk {
struct rcu_head *rcucblist; /* List of pending callbacks (CBs). */
struct rcu_head **donetail; /* ->next pointer of last "done" CB. */
struct rcu_head **curtail;  /* ->next pointer of last CB. */
+   unsigned long gp_seq;   /* Grace-period counter. */
 };
 
 /* Definition for rcupdate control block. */
 static struct rcu_ctrlblk rcu_ctrlblk = {
.donetail   = _ctrlblk.rcucblist,
.curtail= _ctrlblk.rcucblist,
+   .gp_seq = 0 - 300UL,
 };
 
 void rcu_barrier(void)
@@ -56,6 +58,7 @@ void rcu_qs(void)
rcu_ctrlblk.donetail = rcu_ctrlblk.curtail;
raise_softirq_irqoff(RCU_SOFTIRQ);
}
+   WRITE_ONCE(rcu_ctrlblk.gp_seq, rcu_ctrlblk.gp_seq + 1);
local_irq_restore(flags);
 }
 
@@ -177,6 +180,43 @@ void call_rcu(struct rcu_head *head, rcu_callback_t func)
 }
 EXPORT_SYMBOL_GPL(call_rcu);
 
+/*
+ * Return a grace-period-counter "cookie".  For more information,
+ * see the Tree RCU header comment.
+ */
+unsigned long get_state_synchronize_rcu(void)
+{
+   return READ_ONCE(rcu_ctrlblk.gp_seq);
+}
+EXPORT_SYMBOL_GPL(get_state_synchronize_rcu);
+
+/*
+ * Return a grace-period-counter "cookie" and ensure that a future grace
+ * period completes.  For more information, see the Tree RCU header comment.
+ */
+unsigned long start_poll_synchronize_rcu(void)
+{
+   unsigned long gp_seq = get_state_synchronize_rcu();
+
+   if (unlikely(is_idle_task(current))) {
+   /* force scheduling for rcu_qs() */
+   resched_cpu(0);
+   }
+   return gp_seq;
+}
+EXPORT_SYMBOL_GPL(start_poll_synchronize_rcu);
+
+/*
+ * Return true if the grace period corresponding to oldstate has completed
+ * and false otherwise.  For more information, see the Tree RCU header
+ * comment.
+ */
+bool poll_state_synchronize_rcu(unsigned long oldstate)
+{
+   return READ_ONCE(rcu_ctrlblk.gp_seq) != oldstate;
+}
+EXPORT_SYMBOL_GPL(poll_state_synchronize_rcu);
+
 void __init rcu_init(void)
 {
open_softirq(RCU_SOFTIRQ, rcu_process_callbacks);


[tip: core/rcu] torture: Make upper-case-only no-dot no-slash scenario names official

2021-04-11 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: e633e63aa907feff98c654c1919101f3d53ebd5b
Gitweb:
https://git.kernel.org/tip/e633e63aa907feff98c654c1919101f3d53ebd5b
Author:Paul E. McKenney 
AuthorDate:Wed, 17 Feb 2021 07:15:41 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 22 Mar 2021 08:29:18 -07:00

torture: Make upper-case-only no-dot no-slash scenario names official

This commit enforces the defacto restriction on scenario names, which is
that they contain neither "/", ".", nor lowercase alphabetic characters.
This restriction avoids collisions between scenario names and the torture
scripting's files and directories.

Signed-off-by: Paul E. McKenney 
---
 tools/testing/selftests/rcutorture/bin/kvm.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/rcutorture/bin/kvm.sh 
b/tools/testing/selftests/rcutorture/bin/kvm.sh
index efcbd12..03364f4 100755
--- a/tools/testing/selftests/rcutorture/bin/kvm.sh
+++ b/tools/testing/selftests/rcutorture/bin/kvm.sh
@@ -104,7 +104,7 @@ do
TORTURE_BUILDONLY=1
;;
--configs|--config)
-   checkarg --configs "(list of config files)" "$#" "$2" 
'^[^/]\+$' '^--'
+   checkarg --configs "(list of config files)" "$#" "$2" 
'^[^/.a-z]\+$' '^--'
configs="$configs $2"
shift
;;


[tip: core/rcu] torture: Add --duration argument to kvm-again.sh

2021-04-11 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 00505165cf4484dffc488259d59689845ba77939
Gitweb:
https://git.kernel.org/tip/00505165cf4484dffc488259d59689845ba77939
Author:Paul E. McKenney 
AuthorDate:Mon, 22 Feb 2021 14:12:58 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 22 Mar 2021 08:29:19 -07:00

torture: Add --duration argument to kvm-again.sh

This commit adds a --duration argument to kvm-again.sh to allow the user
to override the --duration specified for the original kvm.sh run.

Signed-off-by: Paul E. McKenney 
---
 tools/testing/selftests/rcutorture/bin/kvm-again.sh | 25 ++-
 tools/testing/selftests/rcutorture/bin/kvm-transform.sh | 29 ++--
 2 files changed, 47 insertions(+), 7 deletions(-)

diff --git a/tools/testing/selftests/rcutorture/bin/kvm-again.sh 
b/tools/testing/selftests/rcutorture/bin/kvm-again.sh
index 4137440..e7e5458 100755
--- a/tools/testing/selftests/rcutorture/bin/kvm-again.sh
+++ b/tools/testing/selftests/rcutorture/bin/kvm-again.sh
@@ -52,6 +52,7 @@ PATH=${KVM}/bin:$PATH; export PATH
 . functions.sh
 
 dryrun=
+dur=
 default_link="cp -R"
 rundir="`pwd`/tools/testing/selftests/rcutorture/res/`date 
+%Y.%m.%d-%H.%M.%S-again`"
 
@@ -61,6 +62,7 @@ starttime="`get_starttime`"
 usage () {
echo "Usage: $scriptname $oldrun [ arguments ]:"
echo "   --dryrun"
+   echo "   --duration minutes | s | h | d"
echo "   --link hard|soft|copy"
echo "   --remote"
echo "   --rundir /new/res/path"
@@ -73,6 +75,23 @@ do
--dryrun)
dryrun=1
;;
+   --duration)
+   checkarg --duration "(minutes)" $# "$2" 
'^[0-9][0-9]*\(s\|m\|h\|d\|\)$' '^error'
+   mult=60
+   if echo "$2" | grep -q 's$'
+   then
+   mult=1
+   elif echo "$2" | grep -q 'h$'
+   then
+   mult=3600
+   elif echo "$2" | grep -q 'd$'
+   then
+   mult=86400
+   fi
+   ts=`echo $2 | sed -e 's/[smhd]$//'`
+   dur=$(($ts*mult))
+   shift
+   ;;
--link)
checkarg --link "hard|soft|copy" "$#" "$2" 'hard\|soft\|copy' 
'^--'
case "$2" in
@@ -134,7 +153,11 @@ do
cp "$i" $T
qemu_cmd_dir="`dirname "$i"`"
kernel_dir="`echo $qemu_cmd_dir | sed -e 's/\.[0-9]\+$//'`"
-   kvm-transform.sh $kernel_dir/bzImage $qemu_cmd_dir/console.log < 
$T/qemu-cmd > $i
+   kvm-transform.sh $kernel_dir/bzImage $qemu_cmd_dir/console.log $dur < 
$T/qemu-cmd > $i
+   if test -n "$dur"
+   then
+   echo "# seconds=$dur" >> $i
+   fi
echo "# TORTURE_KCONFIG_GDB_ARG=''" >> $i
 done
 grep -v '^#' $T/batches.oldrun | awk '
diff --git a/tools/testing/selftests/rcutorture/bin/kvm-transform.sh 
b/tools/testing/selftests/rcutorture/bin/kvm-transform.sh
index c45a953..162dddb 100755
--- a/tools/testing/selftests/rcutorture/bin/kvm-transform.sh
+++ b/tools/testing/selftests/rcutorture/bin/kvm-transform.sh
@@ -3,7 +3,7 @@
 #
 # Transform a qemu-cmd file to allow reuse.
 #
-# Usage: kvm-transform.sh bzImage console.log < qemu-cmd-in > qemu-cmd-out
+# Usage: kvm-transform.sh bzImage console.log [ seconds ] < qemu-cmd-in > 
qemu-cmd-out
 #
 #  bzImage: Kernel and initrd from the same prior kvm.sh run.
 #  console.log: File into which to place console output.
@@ -29,20 +29,37 @@ then
echo "Need console log file name."
exit 1
 fi
+seconds=$3
+if test -n "$seconds" && echo $seconds | grep -q '[^0-9]'
+then
+   echo "Invalid duration, should be numeric in seconds: '$seconds'"
+   exit 1
+fi
+
+awk -v image="$image" -v consolelog="$consolelog" -v seconds="$seconds" '
+/^#/ {
+   print $0;
+   next;
+}
 
-awk -v image="$image" -v consolelog="$consolelog" '
 {
line = "";
for (i = 1; i <= NF; i++) {
-   if (line == "")
+   if ("" seconds != "" && $i ~ /\.shutdown_secs=[0-9]*$/) {
+   sub(/[0-9]*$/, seconds, $i);
+   if (line == "")
+   line = $i;
+   else
+   line = line " " $i;
+   } else if (line == "") {
line = $i;
-   else
+   } else {
line = line " " $i;
+   }
if ($i == "-serial") {
i++;
line = line " file:" consolelog;
-   }
-   if ($i == "-kernel") {
+   } else if ($i == "-kernel") {
i++;
line = line " " image;
}


[tip: core/rcu] torture: Print proper vmlinux path for kvm-again.sh runs

2021-04-11 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 03edf700db335b9375c18310d59d0a0ab6c850df
Gitweb:
https://git.kernel.org/tip/03edf700db335b9375c18310d59d0a0ab6c850df
Author:Paul E. McKenney 
AuthorDate:Tue, 23 Feb 2021 13:12:41 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 22 Mar 2021 08:29:20 -07:00

torture: Print proper vmlinux path for kvm-again.sh runs

The kvm-again.sh script does not copy over the vmlinux files due to
their large size.  This means that a gdb run must use the vmlinux file
from the original "res" directory.  This commit therefore finds that
directory and prints it out so that the user can copy and pasted the
gdb command just as for the initial run.

Signed-off-by: Paul E. McKenney 
---
 tools/testing/selftests/rcutorture/bin/kvm-again.sh   | 5 -
 tools/testing/selftests/rcutorture/bin/kvm-test-1-run-qemu.sh | 6 +-
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/rcutorture/bin/kvm-again.sh 
b/tools/testing/selftests/rcutorture/bin/kvm-again.sh
index f1c80b0..668636e 100755
--- a/tools/testing/selftests/rcutorture/bin/kvm-again.sh
+++ b/tools/testing/selftests/rcutorture/bin/kvm-again.sh
@@ -159,7 +159,10 @@ do
then
echo "# seconds=$dur" >> $i
fi
-   echo "# TORTURE_KCONFIG_GDB_ARG=''" >> $i
+   if test -n "$arg_remote"
+   then
+   echo "# TORTURE_KCONFIG_GDB_ARG=''" >> $i
+   fi
 done
 
 # Extract settings from the last qemu-cmd file transformed above.
diff --git a/tools/testing/selftests/rcutorture/bin/kvm-test-1-run-qemu.sh 
b/tools/testing/selftests/rcutorture/bin/kvm-test-1-run-qemu.sh
index 576a9b7..5b1aa2a 100755
--- a/tools/testing/selftests/rcutorture/bin/kvm-test-1-run-qemu.sh
+++ b/tools/testing/selftests/rcutorture/bin/kvm-test-1-run-qemu.sh
@@ -67,7 +67,11 @@ then
base_resdir=`echo $resdir | sed -e 's/\.[0-9]\+$//'`
if ! test -f $base_resdir/vmlinux
then
-   base_resdir=/path/to
+   base_resdir="`cat re-run`/$resdir"
+   if ! test -f $base_resdir/vmlinux
+   then
+   base_resdir=/path/to
+   fi
fi
echo Waiting for you to attach a debug session, for example: > /dev/tty
echo "gdb $base_resdir/vmlinux" > /dev/tty


[tip: core/rcu] torture: Rename SRCU-t and SRCU-u to avoid lowercase characters

2021-04-11 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 00a447fabb5252d01035e78ae7f2943e5b4fff64
Gitweb:
https://git.kernel.org/tip/00a447fabb5252d01035e78ae7f2943e5b4fff64
Author:Paul E. McKenney 
AuthorDate:Sat, 20 Feb 2021 10:13:52 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 22 Mar 2021 08:29:17 -07:00

torture: Rename SRCU-t and SRCU-u to avoid lowercase characters

The convention that scenario names are all uppercase has two exceptions,
SRCU-t and SRCU-u.  This commit therefore renames them to SRCU-T and
SRCU-U, respectively, to bring them in line with this convention.  This in
turn permits tighter argument checking in the torture-test scripting.

Signed-off-by: Paul E. McKenney 
---
 tools/testing/selftests/rcutorture/configs/rcu/CFLIST  |  4 +--
 tools/testing/selftests/rcutorture/configs/rcu/SRCU-T  | 11 +++-
 tools/testing/selftests/rcutorture/configs/rcu/SRCU-T.boot |  1 +-
 tools/testing/selftests/rcutorture/configs/rcu/SRCU-U  |  9 ++-
 tools/testing/selftests/rcutorture/configs/rcu/SRCU-U.boot |  2 +-
 tools/testing/selftests/rcutorture/configs/rcu/SRCU-t  | 11 +---
 tools/testing/selftests/rcutorture/configs/rcu/SRCU-t.boot |  1 +-
 tools/testing/selftests/rcutorture/configs/rcu/SRCU-u  |  9 +--
 tools/testing/selftests/rcutorture/configs/rcu/SRCU-u.boot |  2 +-
 9 files changed, 25 insertions(+), 25 deletions(-)
 create mode 100644 tools/testing/selftests/rcutorture/configs/rcu/SRCU-T
 create mode 100644 tools/testing/selftests/rcutorture/configs/rcu/SRCU-T.boot
 create mode 100644 tools/testing/selftests/rcutorture/configs/rcu/SRCU-U
 create mode 100644 tools/testing/selftests/rcutorture/configs/rcu/SRCU-U.boot
 delete mode 100644 tools/testing/selftests/rcutorture/configs/rcu/SRCU-t
 delete mode 100644 tools/testing/selftests/rcutorture/configs/rcu/SRCU-t.boot
 delete mode 100644 tools/testing/selftests/rcutorture/configs/rcu/SRCU-u
 delete mode 100644 tools/testing/selftests/rcutorture/configs/rcu/SRCU-u.boot

diff --git a/tools/testing/selftests/rcutorture/configs/rcu/CFLIST 
b/tools/testing/selftests/rcutorture/configs/rcu/CFLIST
index f2b20db..98b6175 100644
--- a/tools/testing/selftests/rcutorture/configs/rcu/CFLIST
+++ b/tools/testing/selftests/rcutorture/configs/rcu/CFLIST
@@ -7,8 +7,8 @@ TREE07
 TREE09
 SRCU-N
 SRCU-P
-SRCU-t
-SRCU-u
+SRCU-T
+SRCU-U
 TINY01
 TINY02
 TASKS01
diff --git a/tools/testing/selftests/rcutorture/configs/rcu/SRCU-T 
b/tools/testing/selftests/rcutorture/configs/rcu/SRCU-T
new file mode 100644
index 000..d6557c3
--- /dev/null
+++ b/tools/testing/selftests/rcutorture/configs/rcu/SRCU-T
@@ -0,0 +1,11 @@
+CONFIG_SMP=n
+CONFIG_PREEMPT_NONE=y
+CONFIG_PREEMPT_VOLUNTARY=n
+CONFIG_PREEMPT=n
+#CHECK#CONFIG_TINY_SRCU=y
+CONFIG_RCU_TRACE=n
+CONFIG_DEBUG_LOCK_ALLOC=y
+CONFIG_PROVE_LOCKING=y
+CONFIG_DEBUG_OBJECTS_RCU_HEAD=n
+CONFIG_DEBUG_ATOMIC_SLEEP=y
+#CHECK#CONFIG_PREEMPT_COUNT=y
diff --git a/tools/testing/selftests/rcutorture/configs/rcu/SRCU-T.boot 
b/tools/testing/selftests/rcutorture/configs/rcu/SRCU-T.boot
new file mode 100644
index 000..238bfe3
--- /dev/null
+++ b/tools/testing/selftests/rcutorture/configs/rcu/SRCU-T.boot
@@ -0,0 +1 @@
+rcutorture.torture_type=srcu
diff --git a/tools/testing/selftests/rcutorture/configs/rcu/SRCU-U 
b/tools/testing/selftests/rcutorture/configs/rcu/SRCU-U
new file mode 100644
index 000..6bc24e9
--- /dev/null
+++ b/tools/testing/selftests/rcutorture/configs/rcu/SRCU-U
@@ -0,0 +1,9 @@
+CONFIG_SMP=n
+CONFIG_PREEMPT_NONE=y
+CONFIG_PREEMPT_VOLUNTARY=n
+CONFIG_PREEMPT=n
+#CHECK#CONFIG_TINY_SRCU=y
+CONFIG_RCU_TRACE=n
+CONFIG_DEBUG_LOCK_ALLOC=n
+CONFIG_DEBUG_OBJECTS_RCU_HEAD=n
+CONFIG_PREEMPT_COUNT=n
diff --git a/tools/testing/selftests/rcutorture/configs/rcu/SRCU-U.boot 
b/tools/testing/selftests/rcutorture/configs/rcu/SRCU-U.boot
new file mode 100644
index 000..ce48c7b
--- /dev/null
+++ b/tools/testing/selftests/rcutorture/configs/rcu/SRCU-U.boot
@@ -0,0 +1,2 @@
+rcutorture.torture_type=srcud
+rcupdate.rcu_self_test=1
diff --git a/tools/testing/selftests/rcutorture/configs/rcu/SRCU-t 
b/tools/testing/selftests/rcutorture/configs/rcu/SRCU-t
deleted file mode 100644
index d6557c3..000
--- a/tools/testing/selftests/rcutorture/configs/rcu/SRCU-t
+++ /dev/null
@@ -1,11 +0,0 @@
-CONFIG_SMP=n
-CONFIG_PREEMPT_NONE=y
-CONFIG_PREEMPT_VOLUNTARY=n
-CONFIG_PREEMPT=n
-#CHECK#CONFIG_TINY_SRCU=y
-CONFIG_RCU_TRACE=n
-CONFIG_DEBUG_LOCK_ALLOC=y
-CONFIG_PROVE_LOCKING=y
-CONFIG_DEBUG_OBJECTS_RCU_HEAD=n
-CONFIG_DEBUG_ATOMIC_SLEEP=y
-#CHECK#CONFIG_PREEMPT_COUNT=y
diff --git a/tools/testing/selftests/rcutorture/configs/rcu/SRCU-t.boot 
b/tools/testing/selftests/rcutorture/configs/rcu/SRCU-t.boot
deleted file mode 100644
index 238bfe3..000
--- a/tools/testing/selftests/rcutorture/configs/rcu/SRCU-t.boot
+++ /dev/null
@@ -1 +0,0 @@
-rcutorture.torture_type=srcu
diff --git a/tools/testing/selftests/rcutorture/configs/rcu/SRCU-u 

[tip: core/rcu] torture: Add kvm-again.sh to rerun a previous torture-test

2021-04-11 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 7cf86c0b6279d9d12bb697e58c7e8b2184a8f3db
Gitweb:
https://git.kernel.org/tip/7cf86c0b6279d9d12bb697e58c7e8b2184a8f3db
Author:Paul E. McKenney 
AuthorDate:Fri, 19 Feb 2021 17:49:58 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 22 Mar 2021 08:29:19 -07:00

torture: Add kvm-again.sh to rerun a previous torture-test

This commit adds a kvm-again.sh script that, given the results directory
of a torture-test run, re-runs that test.  This means that the kernels
need not be rebuilt, but it also is a step towards running torture tests
on remote systems.

This commit also adds a kvm-test-1-run-batch.sh script that runs one
batch out of the torture test.  The idea is to copy a results directory
tree to remote systems, then use kvm-test-1-run-batch.sh to run batches
on these systems.

Signed-off-by: Paul E. McKenney 
---
 tools/testing/selftests/rcutorture/bin/kvm-again.sh| 171 
++-
 tools/testing/selftests/rcutorture/bin/kvm-test-1-run-batch.sh |  67 
+++-
 2 files changed, 238 insertions(+)
 create mode 100755 tools/testing/selftests/rcutorture/bin/kvm-again.sh
 create mode 100755 
tools/testing/selftests/rcutorture/bin/kvm-test-1-run-batch.sh

diff --git a/tools/testing/selftests/rcutorture/bin/kvm-again.sh 
b/tools/testing/selftests/rcutorture/bin/kvm-again.sh
new file mode 100755
index 000..4137440
--- /dev/null
+++ b/tools/testing/selftests/rcutorture/bin/kvm-again.sh
@@ -0,0 +1,171 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Rerun a series of tests under KVM.
+#
+# Usage: kvm-again.sh /path/to/old/run [ options ]
+#
+# Copyright (C) 2021 Facebook, Inc.
+#
+# Authors: Paul E. McKenney 
+
+scriptname=$0
+args="$*"
+
+T=${TMPDIR-/tmp}/kvm-again.sh.$$
+trap 'rm -rf $T' 0
+mkdir $T
+
+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
+
+oldrun=$1
+shift
+if ! test -d "$oldrun"
+then
+   echo "Usage: $scriptname /path/to/old/run [ options ]"
+   exit 1
+fi
+if ! cp "$oldrun/batches" $T/batches.oldrun
+then
+   # Later on, can reconstitute this from console.log files.
+   echo Prior run batches file does not exist: $oldrun/batches
+   exit 1
+fi
+
+if test -f "$oldrun/torture_suite"
+then
+   torture_suite="`cat $oldrun/torture_suite`"
+elif test -f "$oldrun/TORTURE_SUITE"
+then
+   torture_suite="`cat $oldrun/TORTURE_SUITE`"
+else
+   echo "Prior run torture_suite file does not exist: 
$oldrun/{torture_suite,TORTURE_SUITE}"
+   exit 1
+fi
+
+KVM="`pwd`/tools/testing/selftests/rcutorture"; export KVM
+PATH=${KVM}/bin:$PATH; export PATH
+. functions.sh
+
+dryrun=
+default_link="cp -R"
+rundir="`pwd`/tools/testing/selftests/rcutorture/res/`date 
+%Y.%m.%d-%H.%M.%S-again`"
+
+startdate="`date`"
+starttime="`get_starttime`"
+
+usage () {
+   echo "Usage: $scriptname $oldrun [ arguments ]:"
+   echo "   --dryrun"
+   echo "   --link hard|soft|copy"
+   echo "   --remote"
+   echo "   --rundir /new/res/path"
+   exit 1
+}
+
+while test $# -gt 0
+do
+   case "$1" in
+   --dryrun)
+   dryrun=1
+   ;;
+   --link)
+   checkarg --link "hard|soft|copy" "$#" "$2" 'hard\|soft\|copy' 
'^--'
+   case "$2" in
+   copy)
+   arg_link="cp -R"
+   ;;
+   hard)
+   arg_link="cp -Rl"
+   ;;
+   soft)
+   arg_link="cp -Rs"
+   ;;
+   esac
+   shift
+   ;;
+   --remote)
+   arg_remote=1
+   default_link="cp -as"
+   ;;
+   --rundir)
+   checkarg --rundir "(absolute pathname)" "$#" "$2" '^/' '^error'
+   rundir=$2
+   if test -e "$rundir"
+   then
+   echo "--rundir $2: Already exists."
+   usage
+   fi
+   shift
+   ;;
+   *)
+   echo Unknown argument $1
+   usage
+   ;;
+   esac
+   shift
+done
+if test -z "$arg_link"
+then
+   arg_link="$default_link"
+fi
+
+echo  Re-run results directory: $rundir
+
+# Copy old run directory tree over and adjust.
+mkdir -p "`dirname "$rundir"`"
+if ! $arg_link "$oldrun" "$rundir"
+then
+   echo "Cannot copy from $oldrun to $rundir."
+   usage
+fi
+rm -f 
"$rundir"/*/{console.log,console.log.diags,qemu_pid,qemu-retval,Warnings,kvm-test-1-run.sh.out,kvm-test-1-run-qemu.sh.out,vmlinux}
 "$rundir"/log
+echo $oldrun > "$rundir/re-run"
+if ! test -d "$rundir/../../bin"
+then
+   $arg_link "$oldrun/../../bin" 

[tip: core/rcu] torture: Remove no-mpstat error message

2021-04-11 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 996a042e0a0684b7a666b9d745784623a3531b27
Gitweb:
https://git.kernel.org/tip/996a042e0a0684b7a666b9d745784623a3531b27
Author:Paul E. McKenney 
AuthorDate:Tue, 16 Feb 2021 20:17:44 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 22 Mar 2021 08:29:17 -07:00

torture: Remove no-mpstat error message

The cpus2use.sh script complains if the mpstat command is not available,
and instead uses all available CPUs.  Unfortunately, this complaint
goes to stdout, where it confuses invokers who expect a single number.
This commit removes this error message in order to avoid this confusion.
The tendency of late has been to give rcutorture a full system, so this
should not cause issues.

Signed-off-by: Paul E. McKenney 
---
 tools/testing/selftests/rcutorture/bin/cpus2use.sh | 1 -
 1 file changed, 1 deletion(-)

diff --git a/tools/testing/selftests/rcutorture/bin/cpus2use.sh 
b/tools/testing/selftests/rcutorture/bin/cpus2use.sh
index 1dbfb62..6bb9930 100755
--- a/tools/testing/selftests/rcutorture/bin/cpus2use.sh
+++ b/tools/testing/selftests/rcutorture/bin/cpus2use.sh
@@ -21,7 +21,6 @@ then
awk -v ncpus=$ncpus '{ print ncpus * ($7 + $NF) / 100 }'`
 else
# No mpstat command, so use all available CPUs.
-   echo The mpstat command is not available, so greedily using all CPUs.
idlecpus=$ncpus
 fi
 awk -v ncpus=$ncpus -v idlecpus=$idlecpus < /dev/null '


[tip: core/rcu] torture: De-capitalize TORTURE_SUITE

2021-04-11 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 7ef0d5a33c81cfb1993f2947c361784b1b02adc8
Gitweb:
https://git.kernel.org/tip/7ef0d5a33c81cfb1993f2947c361784b1b02adc8
Author:Paul E. McKenney 
AuthorDate:Wed, 17 Feb 2021 14:04:01 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 22 Mar 2021 08:29:18 -07:00

torture: De-capitalize TORTURE_SUITE

Although it might be unlikely that someone would name a scenario
"TORTURE_SUITE", they are within their rights to do so.  This script
therefore renames the "TORTURE_SUITE" file in the top-level date-stamped
directory within "res" to "torture_suite" to avoid this name collision.

Signed-off-by: Paul E. McKenney 
---
 tools/testing/selftests/rcutorture/bin/kvm-recheck.sh | 2 +-
 tools/testing/selftests/rcutorture/bin/kvm.sh | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/rcutorture/bin/kvm-recheck.sh 
b/tools/testing/selftests/rcutorture/bin/kvm-recheck.sh
index 47cf4db..e01b31b 100755
--- a/tools/testing/selftests/rcutorture/bin/kvm-recheck.sh
+++ b/tools/testing/selftests/rcutorture/bin/kvm-recheck.sh
@@ -30,7 +30,7 @@ do
resdir=`echo $i | sed -e 's,/$,,' -e 's,/[^/]*$,,'`
head -1 $resdir/log
fi
-   TORTURE_SUITE="`cat $i/../TORTURE_SUITE`"
+   TORTURE_SUITE="`cat $i/../torture_suite`"
configfile=`echo $i | sed -e 's,^.*/,,'`
rm -f $i/console.log.*.diags
kvm-recheck-${TORTURE_SUITE}.sh $i
diff --git a/tools/testing/selftests/rcutorture/bin/kvm.sh 
b/tools/testing/selftests/rcutorture/bin/kvm.sh
index 03364f4..a1cd05c 100755
--- a/tools/testing/selftests/rcutorture/bin/kvm.sh
+++ b/tools/testing/selftests/rcutorture/bin/kvm.sh
@@ -405,7 +405,7 @@ echo Results directory: $resdir/$ds
 echo $scriptname $args
 touch $resdir/$ds/log
 echo $scriptname $args >> $resdir/$ds/log
-echo ${TORTURE_SUITE} > $resdir/$ds/TORTURE_SUITE
+echo ${TORTURE_SUITE} > $resdir/$ds/torture_suite
 echo Build directory: `pwd` > $resdir/$ds/testid.txt
 if test -d .git
 then


[tip: core/rcu] torture: Record jitter start/stop commands

2021-04-11 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 7831b391fbf86d19ae92e2984a9274b1d2b4eb06
Gitweb:
https://git.kernel.org/tip/7831b391fbf86d19ae92e2984a9274b1d2b4eb06
Author:Paul E. McKenney 
AuthorDate:Tue, 16 Feb 2021 15:32:23 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 22 Mar 2021 08:29:16 -07:00

torture: Record jitter start/stop commands

Distributed runs of rcutorture will need to start and stop jittering on
the remote hosts, which means that the commands must be communicated to
those hosts.  The commit therefore causes kvm.sh to place these commands
in new TORTURE_JITTER_START and TORTURE_JITTER_STOP environment variables
to communicate them to the scripts that will set this up.  In addition,
this commit causes kvm-test-1-run.sh to append these commands to each
generated qemu-cmd file, which allows any remotely executing script to
extract the needed commands from this file.

Signed-off-by: Paul E. McKenney 
---
 tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh |  2 +-
 tools/testing/selftests/rcutorture/bin/kvm.sh| 24 ---
 2 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh 
b/tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh
index f3d2ded..a69f8ae 100755
--- a/tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh
+++ b/tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh
@@ -202,6 +202,8 @@ echo $QEMU $qemu_args -m $TORTURE_QEMU_MEM -kernel $KERNEL 
-append \"$qemu_appen
 echo "# TORTURE_SHUTDOWN_GRACE=$TORTURE_SHUTDOWN_GRACE" >> $resdir/qemu-cmd
 echo "# seconds=$seconds" >> $resdir/qemu-cmd
 echo "# TORTURE_KCONFIG_GDB_ARG=\"$TORTURE_KCONFIG_GDB_ARG\"" >> 
$resdir/qemu-cmd
+echo "# TORTURE_JITTER_START=\"$TORTURE_JITTER_START\"" >> $resdir/qemu-cmd
+echo "# TORTURE_JITTER_STOP=\"$TORTURE_JITTER_STOP\"" >> $resdir/qemu-cmd
 
 if test -n "$TORTURE_BUILDONLY"
 then
diff --git a/tools/testing/selftests/rcutorture/bin/kvm.sh 
b/tools/testing/selftests/rcutorture/bin/kvm.sh
index d6973e4..efcbd12 100755
--- a/tools/testing/selftests/rcutorture/bin/kvm.sh
+++ b/tools/testing/selftests/rcutorture/bin/kvm.sh
@@ -35,6 +35,8 @@ TORTURE_KCONFIG_ARG=""
 TORTURE_KCONFIG_GDB_ARG=""
 TORTURE_BOOT_GDB_ARG=""
 TORTURE_QEMU_GDB_ARG=""
+TORTURE_JITTER_START=""
+TORTURE_JITTER_STOP=""
 TORTURE_KCONFIG_KASAN_ARG=""
 TORTURE_KCONFIG_KCSAN_ARG=""
 TORTURE_KMAKE_ARG=""
@@ -443,6 +445,16 @@ function dump(first, pastlast, batchnum)
print "echo Start batch " batchnum ": `date` | tee -a " rd "log";
print "needqemurun="
jn=1
+   njitter = 0;
+   split(jitter, ja);
+   if (ja[1] == -1 && ncpus == 0)
+   njitter = 1;
+   else if (ja[1] == -1)
+   njitter = ncpus;
+   else
+   njitter = ja[1];
+   print "TORTURE_JITTER_START=\". jitterstart.sh " njitter " " rd " " dur 
" " ja[2] " " ja[3] "\"; export TORTURE_JITTER_START";
+   print "TORTURE_JITTER_STOP=\". jitterstop.sh " rd " \"; export 
TORTURE_JITTER_STOP"
for (j = first; j < pastlast; j++) {
cpusr[jn] = cpus[j];
if (cfrep[cf[j]] == "") {
@@ -484,14 +496,6 @@ function dump(first, pastlast, batchnum)
print "\tneedqemurun=1"
print "fi"
}
-   njitter = 0;
-   split(jitter, ja);
-   if (ja[1] == -1 && ncpus == 0)
-   njitter = 1;
-   else if (ja[1] == -1)
-   njitter = ncpus;
-   else
-   njitter = ja[1];
if (TORTURE_BUILDONLY && njitter != 0) {
njitter = 0;
print "echo Build-only run, so suppressing jitter | tee -a " rd 
"log"
@@ -502,12 +506,12 @@ function dump(first, pastlast, batchnum)
print "if test -n \"$needqemurun\""
print "then"
print "\techo  Starting kernels. `date` | tee -a " rd "log";
-   print "\t. jitterstart.sh " njitter " " rd " " dur " " ja[2] " " ja[3]
+   print "\t$TORTURE_JITTER_START";
print "\twhile ls $runfiles > /dev/null 2>&1"
print "\tdo"
print "\t\t:"
print "\tdone"
-   print "\t. jitterstop.sh " rd
+   print "\t$TORTURE_JITTER_STOP";
print "\techo  All kernel runs complete. `date` | tee -a " rd "log";
print "else"
print "\twait"


[tip: core/rcu] torture: Make kvm-transform.sh update jitter commands

2021-04-11 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 018629e909ffcabfc657388094371f20ba90649f
Gitweb:
https://git.kernel.org/tip/018629e909ffcabfc657388094371f20ba90649f
Author:Paul E. McKenney 
AuthorDate:Mon, 22 Feb 2021 14:58:41 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 22 Mar 2021 08:29:20 -07:00

torture: Make kvm-transform.sh update jitter commands

When rerunning an old run using kvm-again.sh, the jitter commands
will re-use the original "res" directory.  This works, but is clearly
an accident waiting to happen.  And this accident will happen with
remote runs, where the original directory lives on some other system.
This commit therefore updates the qemu-cmd commands to use the new res
directory created for this specific run.

Signed-off-by: Paul E. McKenney 
---
 tools/testing/selftests/rcutorture/bin/kvm-again.sh |  3 +-
 tools/testing/selftests/rcutorture/bin/kvm-transform.sh | 23 ++--
 2 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/tools/testing/selftests/rcutorture/bin/kvm-again.sh 
b/tools/testing/selftests/rcutorture/bin/kvm-again.sh
index e7e5458..3fb57ce 100755
--- a/tools/testing/selftests/rcutorture/bin/kvm-again.sh
+++ b/tools/testing/selftests/rcutorture/bin/kvm-again.sh
@@ -153,7 +153,8 @@ do
cp "$i" $T
qemu_cmd_dir="`dirname "$i"`"
kernel_dir="`echo $qemu_cmd_dir | sed -e 's/\.[0-9]\+$//'`"
-   kvm-transform.sh $kernel_dir/bzImage $qemu_cmd_dir/console.log $dur < 
$T/qemu-cmd > $i
+   jitter_dir="`dirname "$kernel_dir"`"
+   kvm-transform.sh "$kernel_dir/bzImage" "$qemu_cmd_dir/console.log" 
"$jitter_dir" $dur < $T/qemu-cmd > $i
if test -n "$dur"
then
echo "# seconds=$dur" >> $i
diff --git a/tools/testing/selftests/rcutorture/bin/kvm-transform.sh 
b/tools/testing/selftests/rcutorture/bin/kvm-transform.sh
index 162dddb..e9dcbce 100755
--- a/tools/testing/selftests/rcutorture/bin/kvm-transform.sh
+++ b/tools/testing/selftests/rcutorture/bin/kvm-transform.sh
@@ -3,7 +3,7 @@
 #
 # Transform a qemu-cmd file to allow reuse.
 #
-# Usage: kvm-transform.sh bzImage console.log [ seconds ] < qemu-cmd-in > 
qemu-cmd-out
+# Usage: kvm-transform.sh bzImage console.log jitter_dir [ seconds ] < 
qemu-cmd-in > qemu-cmd-out
 #
 #  bzImage: Kernel and initrd from the same prior kvm.sh run.
 #  console.log: File into which to place console output.
@@ -29,14 +29,31 @@ then
echo "Need console log file name."
exit 1
 fi
-seconds=$3
+jitter_dir="$3"
+if test -z "$jitter_dir" || ! test -d "$jitter_dir"
+then
+   echo "Need valid jitter directory: '$jitter_dir'"
+   exit 1
+fi
+seconds="$4"
 if test -n "$seconds" && echo $seconds | grep -q '[^0-9]'
 then
echo "Invalid duration, should be numeric in seconds: '$seconds'"
exit 1
 fi
 
-awk -v image="$image" -v consolelog="$consolelog" -v seconds="$seconds" '
+awk -v image="$image" -v consolelog="$consolelog" -v jitter_dir="$jitter_dir" \
+-v seconds="$seconds" '
+/^# TORTURE_JITTER_START=/ {
+   print "# TORTURE_JITTER_START=\". jitterstart.sh " $4 " " jitter_dir " 
" $6 " " $7;
+   next;
+}
+
+/^# TORTURE_JITTER_STOP=/ {
+   print "# TORTURE_JITTER_STOP=\". jitterstop.sh " " " jitter_dir " " $5;
+   next;
+}
+
 /^#/ {
print $0;
next;


[tip: core/rcu] torture: Create a "batches" file for build reuse

2021-04-11 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: d6100d764cc47100ecabdc704bde5ad0448c87cd
Gitweb:
https://git.kernel.org/tip/d6100d764cc47100ecabdc704bde5ad0448c87cd
Author:Paul E. McKenney 
AuthorDate:Wed, 17 Feb 2021 14:40:03 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 22 Mar 2021 08:29:18 -07:00

torture: Create a "batches" file for build reuse

This commit creates a "batches" file in the res/$ds directory, where $ds
is the datestamp.  This file contains the batches and the number of CPUs,
for example:

1 TREE03 16
1 SRCU-P 8
2 TREE07 16
2 TREE01 8
3 TREE02 8
3 TREE04 8
3 TREE05 8
4 SRCU-N 4
4 TRACE01 4
4 TRACE02 4
4 RUDE01 2
4 RUDE01.2 2
4 TASKS01 2
4 TASKS03 2
4 SRCU-t 1
4 SRCU-u 1
4 TASKS02 1
4 TINY01 1
5 TINY02 1
5 TREE09 1

The first column is the batch number, the second the scenario number
(possibly suffixed by a repetition number, as in "RUDE01.2"), and the
third is the number of CPUs required by that scenario.  The last line
shows the number of CPUs expected by this batch file, which allows
the run to be re-batched if a different number of CPUs is available.

Signed-off-by: Paul E. McKenney 
---
 tools/testing/selftests/rcutorture/bin/kvm.sh | 29 ++
 1 file changed, 17 insertions(+), 12 deletions(-)

diff --git a/tools/testing/selftests/rcutorture/bin/kvm.sh 
b/tools/testing/selftests/rcutorture/bin/kvm.sh
index a1cd05c..0add163 100755
--- a/tools/testing/selftests/rcutorture/bin/kvm.sh
+++ b/tools/testing/selftests/rcutorture/bin/kvm.sh
@@ -565,6 +565,18 @@ echo 'ret=$?' >> $T/script
 echo "cat $T/kvm-recheck.sh.out | tee -a $resdir/$ds/log" >> $T/script
 echo 'exit $ret' >> $T/script
 
+# Extract the tests and their batches from the script.
+egrep 'Start batch|Starting build\.' $T/script | grep -v ">>" |
+   sed -e 's/:.*$//' -e 's/^echo //' -e 's/-ovf//' |
+   awk '
+   /^Start/ {
+   batchno = $3;
+   next;
+   }
+   {
+   print batchno, $1, $2
+   }' > $T/batches
+
 if test "$dryrun" = script
 then
cat $T/script
@@ -583,21 +595,14 @@ then
exit 0
 elif test "$dryrun" = batches
 then
-   # Extract the tests and their batches from the script.
-   egrep 'Start batch|Starting build\.' $T/script | grep -v ">>" |
-   sed -e 's/:.*$//' -e 's/^echo //' -e 's/-ovf//' |
-   awk '
-   /^Start/ {
-   batchno = $3;
-   next;
-   }
-   {
-   print batchno, $1, $2
-   }'
+   cat $T/batches
+   exit 0
 else
-   # Not a dryrun, so run the script.
+   # 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
+   echo '#' cpus=$cpus >> $resdir/$ds/batches
echo " --- Done at `date` (`get_starttime_duration $starttime`) 
exitcode $ret" | tee -a $resdir/$ds/log
exit $ret
 fi


[tip: core/rcu] torture: Make TORTURE_TRUST_MAKE available in kvm-again.sh environment

2021-04-11 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: a5dbe2524f553a1283b3364ff91e96bfb618ceab
Gitweb:
https://git.kernel.org/tip/a5dbe2524f553a1283b3364ff91e96bfb618ceab
Author:Paul E. McKenney 
AuthorDate:Tue, 23 Feb 2021 12:07:39 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 22 Mar 2021 08:29:20 -07:00

torture: Make TORTURE_TRUST_MAKE available in kvm-again.sh environment

Because the TORTURE_TRUST_MAKE environment variable is not recorded,
kvm-again.sh runs can result in the parse-build.sh script emitting
false-positive "BUG: TREE03 no build" messages.  These messages are
intended to complain about any lack of compiler invocations when the
--trust-make flag is not given to kvm.sh.  However, when this flag is
given to kvm.sh (and thus when TORTURE_TRUST_MAKE=y), lack of compiler
invocations is expected behavior when rebuilding from identical source
code.

This commit therefore makes kvm-test-1-run.sh record the value of the
TORTURE_TRUST_MAKE environment variable as an additional comment in the
qemu-cmd file, and also makes kvm-again.sh reconstitute that variable
from that comment.

Signed-off-by: Paul E. McKenney 
---
 tools/testing/selftests/rcutorture/bin/kvm-again.sh  | 5 +
 tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh | 1 +
 2 files changed, 6 insertions(+)

diff --git a/tools/testing/selftests/rcutorture/bin/kvm-again.sh 
b/tools/testing/selftests/rcutorture/bin/kvm-again.sh
index 3fb57ce..f1c80b0 100755
--- a/tools/testing/selftests/rcutorture/bin/kvm-again.sh
+++ b/tools/testing/selftests/rcutorture/bin/kvm-again.sh
@@ -161,6 +161,11 @@ do
fi
echo "# TORTURE_KCONFIG_GDB_ARG=''" >> $i
 done
+
+# Extract settings from the last qemu-cmd file transformed above.
+grep '^#' $i | sed -e 's/^# //' > $T/qemu-cmd-settings
+. $T/qemu-cmd-settings
+
 grep -v '^#' $T/batches.oldrun | awk '
 BEGIN {
oldbatch = 1;
diff --git a/tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh 
b/tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh
index a386ca8..420ed5c 100755
--- a/tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh
+++ b/tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh
@@ -204,6 +204,7 @@ echo "# seconds=$seconds" >> $resdir/qemu-cmd
 echo "# TORTURE_KCONFIG_GDB_ARG=\"$TORTURE_KCONFIG_GDB_ARG\"" >> 
$resdir/qemu-cmd
 echo "# TORTURE_JITTER_START=\"$TORTURE_JITTER_START\"" >> $resdir/qemu-cmd
 echo "# TORTURE_JITTER_STOP=\"$TORTURE_JITTER_STOP\"" >> $resdir/qemu-cmd
+echo "# TORTURE_TRUST_MAKE=\"$TORTURE_TRUST_MAKE\"; export TORTURE_TRUST_MAKE" 
>> $resdir/qemu-cmd
 
 if test -n "$TORTURE_BUILDONLY"
 then


[tip: core/rcu] rcutorture: Test start_poll_synchronize_rcu() and poll_state_synchronize_rcu()

2021-04-11 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 7ac3fdf099bf784794eb944e0ba5bb69867ca06d
Gitweb:
https://git.kernel.org/tip/7ac3fdf099bf784794eb944e0ba5bb69867ca06d
Author:Paul E. McKenney 
AuthorDate:Thu, 25 Feb 2021 20:56:10 -08:00
Committer: Paul E. McKenney 
CommitterDate: Wed, 24 Mar 2021 17:17:38 -07:00

rcutorture: Test start_poll_synchronize_rcu() and poll_state_synchronize_rcu()

This commit causes rcutorture to test the new start_poll_synchronize_rcu()
and poll_state_synchronize_rcu() functions.  Because of the difficulty of
determining the nature of a synchronous RCU grace (expedited or not),
the test that insisted that poll_state_synchronize_rcu() detect an
intervening synchronize_rcu() had to be dropped.

Signed-off-by: Paul E. McKenney 
---
 kernel/rcu/rcutorture.c | 12 +++-
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
index 99657ff..956e6bf 100644
--- a/kernel/rcu/rcutorture.c
+++ b/kernel/rcu/rcutorture.c
@@ -494,6 +494,8 @@ static struct rcu_torture_ops rcu_ops = {
.sync   = synchronize_rcu,
.exp_sync   = synchronize_rcu_expedited,
.get_gp_state   = get_state_synchronize_rcu,
+   .start_gp_poll  = start_poll_synchronize_rcu,
+   .poll_gp_state  = poll_state_synchronize_rcu,
.cond_sync  = cond_synchronize_rcu,
.call   = call_rcu,
.cb_barrier = rcu_barrier,
@@ -1223,14 +1225,6 @@ rcu_torture_writer(void *arg)
WARN_ON_ONCE(1);
break;
}
-   if (cur_ops->get_gp_state && cur_ops->poll_gp_state)
-   WARN_ONCE(rcu_torture_writer_state != 
RTWS_DEF_FREE &&
- !cur_ops->poll_gp_state(cookie),
- "%s: Cookie check 2 failed %s(%d) 
%lu->%lu\n",
- __func__,
- rcu_torture_writer_state_getname(),
- rcu_torture_writer_state,
- cookie, cur_ops->get_gp_state());
}
WRITE_ONCE(rcu_torture_current_version,
   rcu_torture_current_version + 1);
@@ -1589,7 +1583,7 @@ static bool rcu_torture_one_read(struct 
torture_random_state *trsp, long myid)
preempt_enable();
if (cur_ops->get_gp_state && cur_ops->poll_gp_state)
WARN_ONCE(cur_ops->poll_gp_state(cookie),
- "%s: Cookie check 3 failed %s(%d) %lu->%lu\n",
+ "%s: Cookie check 2 failed %s(%d) %lu->%lu\n",
  __func__,
  rcu_torture_writer_state_getname(),
  rcu_torture_writer_state,


[tip: core/rcu] torture: Consolidate qemu-cmd duration editing into kvm-transform.sh

2021-04-11 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: a1ab2e89f36d678512a50cbebf6afc4201f41a31
Gitweb:
https://git.kernel.org/tip/a1ab2e89f36d678512a50cbebf6afc4201f41a31
Author:Paul E. McKenney 
AuthorDate:Tue, 23 Feb 2021 14:33:03 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 22 Mar 2021 08:29:21 -07:00

torture: Consolidate qemu-cmd duration editing into kvm-transform.sh

Currently, kvm-again.sh updates the duration in the "seconds=" comment
in the qemu-cmd file, but kvm-transform.sh updates the duration in the
actual qemu command arguments.  This is an accident waiting to happen.

This commit therefore consolidates these updates into kvm-transform.sh.

Signed-off-by: Paul E. McKenney 
---
 tools/testing/selftests/rcutorture/bin/kvm-again.sh | 4 
 tools/testing/selftests/rcutorture/bin/kvm-transform.sh | 8 
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/tools/testing/selftests/rcutorture/bin/kvm-again.sh 
b/tools/testing/selftests/rcutorture/bin/kvm-again.sh
index 668636e..46e47a0 100755
--- a/tools/testing/selftests/rcutorture/bin/kvm-again.sh
+++ b/tools/testing/selftests/rcutorture/bin/kvm-again.sh
@@ -155,10 +155,6 @@ do
kernel_dir="`echo $qemu_cmd_dir | sed -e 's/\.[0-9]\+$//'`"
jitter_dir="`dirname "$kernel_dir"`"
kvm-transform.sh "$kernel_dir/bzImage" "$qemu_cmd_dir/console.log" 
"$jitter_dir" $dur < $T/qemu-cmd > $i
-   if test -n "$dur"
-   then
-   echo "# seconds=$dur" >> $i
-   fi
if test -n "$arg_remote"
then
echo "# TORTURE_KCONFIG_GDB_ARG=''" >> $i
diff --git a/tools/testing/selftests/rcutorture/bin/kvm-transform.sh 
b/tools/testing/selftests/rcutorture/bin/kvm-transform.sh
index e9dcbce..d40b4e6 100755
--- a/tools/testing/selftests/rcutorture/bin/kvm-transform.sh
+++ b/tools/testing/selftests/rcutorture/bin/kvm-transform.sh
@@ -44,6 +44,14 @@ fi
 
 awk -v image="$image" -v consolelog="$consolelog" -v jitter_dir="$jitter_dir" \
 -v seconds="$seconds" '
+/^# seconds=/ {
+   if (seconds == "")
+   print $0;
+   else
+   print "# seconds=" seconds;
+   next;
+}
+
 /^# TORTURE_JITTER_START=/ {
print "# TORTURE_JITTER_START=\". jitterstart.sh " $4 " " jitter_dir " 
" $6 " " $7;
next;


[tip: core/rcu] torture: Fix kvm.sh --datestamp regex check

2021-04-11 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 114e4a4b4884c14ebd35874cbe3e1ca0d38efa5d
Gitweb:
https://git.kernel.org/tip/114e4a4b4884c14ebd35874cbe3e1ca0d38efa5d
Author:Paul E. McKenney 
AuthorDate:Sat, 27 Feb 2021 20:55:57 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 22 Mar 2021 08:29:21 -07:00

torture: Fix kvm.sh --datestamp regex check

Some versions of grep are happy to interpret a nonsensically placed "-"
within a "[]" pattern as a dash, while others give an error message.
This commit therefore places the "-" at the end of the expression where
it was supposed to be in the first place.

Signed-off-by: Paul E. McKenney 
---
 tools/testing/selftests/rcutorture/bin/kvm.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/rcutorture/bin/kvm.sh 
b/tools/testing/selftests/rcutorture/bin/kvm.sh
index 0add163..6bf00a0 100755
--- a/tools/testing/selftests/rcutorture/bin/kvm.sh
+++ b/tools/testing/selftests/rcutorture/bin/kvm.sh
@@ -120,7 +120,7 @@ do
shift
;;
--datestamp)
-   checkarg --datestamp "(relative pathname)" "$#" "$2" 
'^[a-zA-Z0-9._-/]*$' '^--'
+   checkarg --datestamp "(relative pathname)" "$#" "$2" 
'^[a-zA-Z0-9._/-]*$' '^--'
ds=$2
shift
;;


[tip: core/rcu] docs: Remove redundant "``" from Requirements.rst

2021-02-15 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: be06c2577eca6d9dbf61985d4078eb904024380f
Gitweb:
https://git.kernel.org/tip/be06c2577eca6d9dbf61985d4078eb904024380f
Author:Paul E. McKenney 
AuthorDate:Mon, 09 Nov 2020 08:22:16 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 04 Jan 2021 13:35:13 -08:00

docs: Remove redundant "``" from Requirements.rst

The docbook system has learned that "()" designates a function, so
this commit removes the no-longer-needed "``" to improve readability
of the raw .rst file.

Reported-by: Peter Zijlstra 
Cc: Mauro Carvalho Chehab 
Cc: Jonathan Corbet 
[ paulmck: Apply Stephen Rothwell feedback. ]
Signed-off-by: Paul E. McKenney 
---
 Documentation/RCU/Design/Requirements/Requirements.rst | 664 
 1 file changed, 332 insertions(+), 332 deletions(-)

diff --git a/Documentation/RCU/Design/Requirements/Requirements.rst 
b/Documentation/RCU/Design/Requirements/Requirements.rst
index e8c84fc..9b23be6 100644
--- a/Documentation/RCU/Design/Requirements/Requirements.rst
+++ b/Documentation/RCU/Design/Requirements/Requirements.rst
@@ -72,11 +72,11 @@ understanding of this guarantee.
 
 RCU's grace-period guarantee allows updaters to wait for the completion
 of all pre-existing RCU read-side critical sections. An RCU read-side
-critical section begins with the marker ``rcu_read_lock()`` and ends
-with the marker ``rcu_read_unlock()``. These markers may be nested, and
+critical section begins with the marker rcu_read_lock() and ends
+with the marker rcu_read_unlock(). These markers may be nested, and
 RCU treats a nested set as one big RCU read-side critical section.
-Production-quality implementations of ``rcu_read_lock()`` and
-``rcu_read_unlock()`` are extremely lightweight, and in fact have
+Production-quality implementations of rcu_read_lock() and
+rcu_read_unlock() are extremely lightweight, and in fact have
 exactly zero overhead in Linux kernels built for production use with
 ``CONFIG_PREEMPT=n``.
 
@@ -102,12 +102,12 @@ overhead to readers, for example:
   15   WRITE_ONCE(y, 1);
   16 }
 
-Because the ``synchronize_rcu()`` on line 14 waits for all pre-existing
-readers, any instance of ``thread0()`` that loads a value of zero from
-``x`` must complete before ``thread1()`` stores to ``y``, so that
+Because the synchronize_rcu() on line 14 waits for all pre-existing
+readers, any instance of thread0() that loads a value of zero from
+``x`` must complete before thread1() stores to ``y``, so that
 instance must also load a value of zero from ``y``. Similarly, any
-instance of ``thread0()`` that loads a value of one from ``y`` must have
-started after the ``synchronize_rcu()`` started, and must therefore also
+instance of thread0() that loads a value of one from ``y`` must have
+started after the synchronize_rcu() started, and must therefore also
 load a value of one from ``x``. Therefore, the outcome:
 
::
@@ -121,14 +121,14 @@ cannot happen.
 +---+
 | Wait a minute! You said that updaters can make useful forward |
 | progress concurrently with readers, but pre-existing readers will |
-| block ``synchronize_rcu()``!!!|
+| block synchronize_rcu()!!!|
 | Just who are you trying to fool???|
 +---+
 | **Answer**:   |
 +---+
 | First, if updaters do not wish to be blocked by readers, they can use |
-| ``call_rcu()`` or ``kfree_rcu()``, which will be discussed later. |
-| Second, even when using ``synchronize_rcu()``, the other update-side  |
+| call_rcu() or kfree_rcu(), which will be discussed later. |
+| Second, even when using synchronize_rcu(), the other update-side  |
 | code does run concurrently with readers, whether pre-existing or not. |
 +---+
 
@@ -170,34 +170,34 @@ recovery from node failure, more or less as follows:
   29   WRITE_ONCE(state, STATE_NORMAL);
   30 }
 
-The RCU read-side critical section in ``do_something_dlm()`` works with
-the ``synchronize_rcu()`` in ``start_recovery()`` to guarantee that
-``do_something()`` never runs concurrently with ``recovery()``, but with
-little or no synchronization overhead in ``do_something_dlm()``.
+The RCU read-side critical section in do_something_dlm() works with
+the synchronize_rcu() in start_recovery() to guarantee that
+do_something() never runs concurrently with recovery(), but with
+little or no synchronization overhead in do_something_dlm().
 
 +---+
 | **Quick Quiz**:  

[tip: core/rcu] doc: Remove obsolete RCU-bh and RCU-sched update-side API members

2021-02-15 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 2c8bce609f095a8879d3948e0c18d629881518dd
Gitweb:
https://git.kernel.org/tip/2c8bce609f095a8879d3948e0c18d629881518dd
Author:Paul E. McKenney 
AuthorDate:Tue, 10 Nov 2020 16:17:42 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 04 Jan 2021 13:35:13 -08:00

doc: Remove obsolete RCU-bh and RCU-sched update-side API members

synchronize_rcu_bh(), synchronize_rcu_bh_expedited(), call_rcu_bh(),
rcu_barrier_bh(), synchronize_sched(), synchronize_rcu_sched_expedited(),
call_rcu_sched(), and rcu_barrier_sched() no longer exist, so this
commit removes mention of them.

Reported-by: Joel Fernandes 
Signed-off-by: Paul E. McKenney 
---
 Documentation/RCU/Design/Requirements/Requirements.rst | 28 -
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/Documentation/RCU/Design/Requirements/Requirements.rst 
b/Documentation/RCU/Design/Requirements/Requirements.rst
index 9b23be6..1e3df77 100644
--- a/Documentation/RCU/Design/Requirements/Requirements.rst
+++ b/Documentation/RCU/Design/Requirements/Requirements.rst
@@ -2438,13 +2438,13 @@ glance as if rcu_read_unlock_bh() was executing very 
slowly.
 
 The `RCU-bh
 API `__
-includes rcu_read_lock_bh(), rcu_read_unlock_bh(),
-rcu_dereference_bh(), rcu_dereference_bh_check(),
-synchronize_rcu_bh(), synchronize_rcu_bh_expedited(),
-call_rcu_bh(), rcu_barrier_bh(), and
-rcu_read_lock_bh_held(). However, the update-side APIs are now
-simple wrappers for other RCU flavors, namely RCU-sched in
-CONFIG_PREEMPT=n kernels and RCU-preempt otherwise.
+includes rcu_read_lock_bh(), rcu_read_unlock_bh(), rcu_dereference_bh(),
+rcu_dereference_bh_check(), and rcu_read_lock_bh_held(). However, the
+old RCU-bh update-side APIs are now gone, replaced by synchronize_rcu(),
+synchronize_rcu_expedited(), call_rcu(), and rcu_barrier().  In addition,
+anything that disables bottom halves also marks an RCU-bh read-side
+critical section, including local_bh_disable() and local_bh_enable(),
+local_irq_save() and local_irq_restore(), and so on.
 
 Sched Flavor (Historical)
 ~
@@ -2481,13 +2481,13 @@ The `RCU-sched
 API `__
 includes rcu_read_lock_sched(), rcu_read_unlock_sched(),
 rcu_read_lock_sched_notrace(), rcu_read_unlock_sched_notrace(),
-rcu_dereference_sched(), rcu_dereference_sched_check(),
-synchronize_sched(), synchronize_rcu_sched_expedited(),
-call_rcu_sched(), rcu_barrier_sched(), and
-rcu_read_lock_sched_held(). However, anything that disables
-preemption also marks an RCU-sched read-side critical section, including
-preempt_disable() and preempt_enable(), local_irq_save() and
-local_irq_restore(), and so on.
+rcu_dereference_sched(), rcu_dereference_sched_check(), and
+rcu_read_lock_sched_held().  However, the old RCU-sched update-side APIs
+are now gone, replaced by synchronize_rcu(), synchronize_rcu_expedited(),
+call_rcu(), and rcu_barrier().  In addition, anything that disables
+preemption also marks an RCU-sched read-side critical section,
+including preempt_disable() and preempt_enable(), local_irq_save()
+and local_irq_restore(), and so on.
 
 Sleepable RCU
 ~


[tip: core/rcu] doc: Remove obsolete rcutree.rcu_idle_lazy_gp_delay boot parameter

2021-02-15 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 2252ec1464730ce718dc8087c13a419b9aa58758
Gitweb:
https://git.kernel.org/tip/2252ec1464730ce718dc8087c13a419b9aa58758
Author:Paul E. McKenney 
AuthorDate:Thu, 10 Dec 2020 09:53:50 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 04 Jan 2021 13:35:15 -08:00

doc: Remove obsolete rcutree.rcu_idle_lazy_gp_delay boot parameter

This commit removes documentation for the rcutree.rcu_idle_lazy_gp_delay
kernel boot parameter given that this parameter no longer exists.

Fixes: 77a40f97030b ("rcu: Remove kfree_rcu() special casing and lazy-callback 
handling")
Signed-off-by: Paul E. McKenney 
---
 Documentation/admin-guide/kernel-parameters.txt | 6 --
 1 file changed, 6 deletions(-)

diff --git a/Documentation/admin-guide/kernel-parameters.txt 
b/Documentation/admin-guide/kernel-parameters.txt
index c722ec1..b5baa8a 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -4179,12 +4179,6 @@
Set wakeup interval for idle CPUs that have
RCU callbacks (RCU_FAST_NO_HZ=y).
 
-   rcutree.rcu_idle_lazy_gp_delay= [KNL]
-   Set wakeup interval for idle CPUs that have
-   only "lazy" RCU callbacks (RCU_FAST_NO_HZ=y).
-   Lazy RCU callbacks are those which RCU can
-   prove do nothing more than free memory.
-
rcutree.rcu_kick_kthreads= [KNL]
Cause the grace-period kthread to get an extra
wake_up() if it sleeps three times longer than


[tip: core/rcu] srcu: Provide polling interfaces for Tiny SRCU grace periods

2021-02-15 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 8b5bd67cf6422b63ee100d76d8de8960ca2df7f0
Gitweb:
https://git.kernel.org/tip/8b5bd67cf6422b63ee100d76d8de8960ca2df7f0
Author:Paul E. McKenney 
AuthorDate:Fri, 13 Nov 2020 12:54:48 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 04 Jan 2021 13:53:38 -08:00

srcu: Provide polling interfaces for Tiny SRCU grace periods

There is a need for a polling interface for SRCU grace
periods, so this commit supplies get_state_synchronize_srcu(),
start_poll_synchronize_srcu(), and poll_state_synchronize_srcu() for this
purpose.  The first can be used if future grace periods are inevitable
(perhaps due to a later call_srcu() invocation), the second if future
grace periods might not otherwise happen, and the third to check if a
grace period has elapsed since the corresponding call to either of the
first two.

As with get_state_synchronize_rcu() and cond_synchronize_rcu(),
the return value from either get_state_synchronize_srcu() or
start_poll_synchronize_srcu() must be passed in to a later call to
poll_state_synchronize_srcu().

Link: https://lore.kernel.org/rcu/20201112201547.gf3365...@moria.home.lan/
Reported-by: Kent Overstreet 
[ paulmck: Add EXPORT_SYMBOL_GPL() per kernel test robot feedback. ]
[ paulmck: Apply feedback from Neeraj Upadhyay. ]
Link: https://lore.kernel.org/lkml/20201117004017.GA7444@paulmck-ThinkPad-P72/
Reviewed-by: Neeraj Upadhyay 
Signed-off-by: Paul E. McKenney 
---
 include/linux/rcupdate.h |  2 +-
 include/linux/srcu.h |  3 ++-
 include/linux/srcutiny.h |  1 +-
 kernel/rcu/srcutiny.c| 55 +--
 4 files changed, 59 insertions(+), 2 deletions(-)

diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
index de08264..e09c0d8 100644
--- a/include/linux/rcupdate.h
+++ b/include/linux/rcupdate.h
@@ -33,6 +33,8 @@
 #define ULONG_CMP_GE(a, b) (ULONG_MAX / 2 >= (a) - (b))
 #define ULONG_CMP_LT(a, b) (ULONG_MAX / 2 < (a) - (b))
 #define ulong2long(a)  (*(long *)(&(a)))
+#define USHORT_CMP_GE(a, b)(USHRT_MAX / 2 >= (unsigned short)((a) - (b)))
+#define USHORT_CMP_LT(a, b)(USHRT_MAX / 2 < (unsigned short)((a) - (b)))
 
 /* Exported common interfaces */
 void call_rcu(struct rcu_head *head, rcu_callback_t func);
diff --git a/include/linux/srcu.h b/include/linux/srcu.h
index e432cc9..a0895bb 100644
--- a/include/linux/srcu.h
+++ b/include/linux/srcu.h
@@ -60,6 +60,9 @@ void cleanup_srcu_struct(struct srcu_struct *ssp);
 int __srcu_read_lock(struct srcu_struct *ssp) __acquires(ssp);
 void __srcu_read_unlock(struct srcu_struct *ssp, int idx) __releases(ssp);
 void synchronize_srcu(struct srcu_struct *ssp);
+unsigned long get_state_synchronize_srcu(struct srcu_struct *ssp);
+unsigned long start_poll_synchronize_srcu(struct srcu_struct *ssp);
+bool poll_state_synchronize_srcu(struct srcu_struct *ssp, unsigned long 
cookie);
 
 #ifdef CONFIG_DEBUG_LOCK_ALLOC
 
diff --git a/include/linux/srcutiny.h b/include/linux/srcutiny.h
index b8b42d0..0e0cf4d 100644
--- a/include/linux/srcutiny.h
+++ b/include/linux/srcutiny.h
@@ -16,6 +16,7 @@
 struct srcu_struct {
short srcu_lock_nesting[2]; /* srcu_read_lock() nesting depth. */
unsigned short srcu_idx;/* Current reader array element in bit 
0x2. */
+   unsigned short srcu_idx_max;/* Furthest future srcu_idx request. */
u8 srcu_gp_running; /* GP workqueue running? */
u8 srcu_gp_waiting; /* GP waiting for readers? */
struct swait_queue_head srcu_wq;
diff --git a/kernel/rcu/srcutiny.c b/kernel/rcu/srcutiny.c
index 3bac1db..26344dc 100644
--- a/kernel/rcu/srcutiny.c
+++ b/kernel/rcu/srcutiny.c
@@ -34,6 +34,7 @@ static int init_srcu_struct_fields(struct srcu_struct *ssp)
ssp->srcu_gp_running = false;
ssp->srcu_gp_waiting = false;
ssp->srcu_idx = 0;
+   ssp->srcu_idx_max = 0;
INIT_WORK(>srcu_work, srcu_drive_gp);
INIT_LIST_HEAD(>srcu_work.entry);
return 0;
@@ -84,6 +85,8 @@ void cleanup_srcu_struct(struct srcu_struct *ssp)
WARN_ON(ssp->srcu_gp_waiting);
WARN_ON(ssp->srcu_cb_head);
WARN_ON(>srcu_cb_head != ssp->srcu_cb_tail);
+   WARN_ON(ssp->srcu_idx != ssp->srcu_idx_max);
+   WARN_ON(ssp->srcu_idx & 0x1);
 }
 EXPORT_SYMBOL_GPL(cleanup_srcu_struct);
 
@@ -114,7 +117,7 @@ void srcu_drive_gp(struct work_struct *wp)
struct srcu_struct *ssp;
 
ssp = container_of(wp, struct srcu_struct, srcu_work);
-   if (ssp->srcu_gp_running || !READ_ONCE(ssp->srcu_cb_head))
+   if (ssp->srcu_gp_running || USHORT_CMP_GE(ssp->srcu_idx, 
READ_ONCE(ssp->srcu_idx_max)))
return; /* Already running or nothing to do. */
 
/* Remove recently arrived callbacks and wait for readers. */
@@ -147,13 +150,19 @@ void srcu_drive_gp(struct work_struct *wp)
 * straighten that out.
 */

[tip: core/rcu] srcu: Provide polling interfaces for Tree SRCU grace periods

2021-02-15 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 5358c9fa54b09b5d3d7811b033aa0838c1bbaaf2
Gitweb:
https://git.kernel.org/tip/5358c9fa54b09b5d3d7811b033aa0838c1bbaaf2
Author:Paul E. McKenney 
AuthorDate:Fri, 13 Nov 2020 17:31:55 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 04 Jan 2021 13:53:38 -08:00

srcu: Provide polling interfaces for Tree SRCU grace periods

There is a need for a polling interface for SRCU grace
periods, so this commit supplies get_state_synchronize_srcu(),
start_poll_synchronize_srcu(), and poll_state_synchronize_srcu() for this
purpose.  The first can be used if future grace periods are inevitable
(perhaps due to a later call_srcu() invocation), the second if future
grace periods might not otherwise happen, and the third to check if a
grace period has elapsed since the corresponding call to either of the
first two.

As with get_state_synchronize_rcu() and cond_synchronize_rcu(),
the return value from either get_state_synchronize_srcu() or
start_poll_synchronize_srcu() must be passed in to a later call to
poll_state_synchronize_srcu().

Link: https://lore.kernel.org/rcu/20201112201547.gf3365...@moria.home.lan/
Reported-by: Kent Overstreet 
[ paulmck: Add EXPORT_SYMBOL_GPL() per kernel test robot feedback. ]
[ paulmck: Apply feedback from Neeraj Upadhyay. ]
Link: https://lore.kernel.org/lkml/20201117004017.GA7444@paulmck-ThinkPad-P72/
Reviewed-by: Neeraj Upadhyay 
Signed-off-by: Paul E. McKenney 
---
 kernel/rcu/srcutree.c | 67 +++---
 1 file changed, 63 insertions(+), 4 deletions(-)

diff --git a/kernel/rcu/srcutree.c b/kernel/rcu/srcutree.c
index 9a7b650..c5d0c03 100644
--- a/kernel/rcu/srcutree.c
+++ b/kernel/rcu/srcutree.c
@@ -810,7 +810,8 @@ static void srcu_leak_callback(struct rcu_head *rhp)
 /*
  * Start an SRCU grace period, and also queue the callback if non-NULL.
  */
-static void srcu_gp_start_if_needed(struct srcu_struct *ssp, struct rcu_head 
*rhp, bool do_norm)
+static unsigned long srcu_gp_start_if_needed(struct srcu_struct *ssp,
+struct rcu_head *rhp, bool do_norm)
 {
unsigned long flags;
int idx;
@@ -819,10 +820,12 @@ static void srcu_gp_start_if_needed(struct srcu_struct 
*ssp, struct rcu_head *rh
unsigned long s;
struct srcu_data *sdp;
 
+   check_init_srcu_struct(ssp);
idx = srcu_read_lock(ssp);
sdp = raw_cpu_ptr(ssp->sda);
spin_lock_irqsave_rcu_node(sdp, flags);
-   rcu_segcblist_enqueue(>srcu_cblist, rhp);
+   if (rhp)
+   rcu_segcblist_enqueue(>srcu_cblist, rhp);
rcu_segcblist_advance(>srcu_cblist,
  rcu_seq_current(>srcu_gp_seq));
s = rcu_seq_snap(>srcu_gp_seq);
@@ -841,6 +844,7 @@ static void srcu_gp_start_if_needed(struct srcu_struct 
*ssp, struct rcu_head *rh
else if (needexp)
srcu_funnel_exp_start(ssp, sdp->mynode, s);
srcu_read_unlock(ssp, idx);
+   return s;
 }
 
 /*
@@ -874,7 +878,6 @@ static void srcu_gp_start_if_needed(struct srcu_struct 
*ssp, struct rcu_head *rh
 static void __call_srcu(struct srcu_struct *ssp, struct rcu_head *rhp,
rcu_callback_t func, bool do_norm)
 {
-   check_init_srcu_struct(ssp);
if (debug_rcu_head_queue(rhp)) {
/* Probable double call_srcu(), so leak the callback. */
WRITE_ONCE(rhp->func, srcu_leak_callback);
@@ -882,7 +885,7 @@ static void __call_srcu(struct srcu_struct *ssp, struct 
rcu_head *rhp,
return;
}
rhp->func = func;
-   srcu_gp_start_if_needed(ssp, rhp, do_norm);
+   (void)srcu_gp_start_if_needed(ssp, rhp, do_norm);
 }
 
 /**
@@ -1011,6 +1014,62 @@ void synchronize_srcu(struct srcu_struct *ssp)
 }
 EXPORT_SYMBOL_GPL(synchronize_srcu);
 
+/**
+ * get_state_synchronize_srcu - Provide an end-of-grace-period cookie
+ * @ssp: srcu_struct to provide cookie for.
+ *
+ * This function returns a cookie that can be passed to
+ * poll_state_synchronize_srcu(), which will return true if a full grace
+ * period has elapsed in the meantime.  It is the caller's responsibility
+ * to make sure that grace period happens, for example, by invoking
+ * call_srcu() after return from get_state_synchronize_srcu().
+ */
+unsigned long get_state_synchronize_srcu(struct srcu_struct *ssp)
+{
+   // Any prior manipulation of SRCU-protected data must happen
+   // before the load from ->srcu_gp_seq.
+   smp_mb();
+   return rcu_seq_snap(>srcu_gp_seq);
+}
+EXPORT_SYMBOL_GPL(get_state_synchronize_srcu);
+
+/**
+ * start_poll_synchronize_srcu - Provide cookie and start grace period
+ * @ssp: srcu_struct to provide cookie for.
+ *
+ * This function returns a cookie that can be passed to
+ * poll_state_synchronize_srcu(), which will return true if a full grace
+ * period has elapsed in the meantime.  Unlike 

[tip: core/rcu] rcutorture: Prepare for ->start_gp_poll and ->poll_gp_state

2021-02-15 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: fd56f64b4e3b9c53fbb12ef74c6f1f5fde4cc1c8
Gitweb:
https://git.kernel.org/tip/fd56f64b4e3b9c53fbb12ef74c6f1f5fde4cc1c8
Author:Paul E. McKenney 
AuthorDate:Fri, 13 Nov 2020 20:14:27 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 04 Jan 2021 13:53:39 -08:00

rcutorture: Prepare for ->start_gp_poll and ->poll_gp_state

The new get_state_synchronize_srcu(), start_poll_synchronize_srcu() and
poll_state_synchronize_srcu() functions need to be tested, and so this
commit prepares by renaming the rcu_torture_ops field ->get_state to
->get_gp_state in order to be consistent with the upcoming ->start_gp_poll
and ->poll_gp_state fields.

Link: https://lore.kernel.org/rcu/20201112201547.gf3365...@moria.home.lan/
Reported-by: Kent Overstreet 
Signed-off-by: Paul E. McKenney 
---
 kernel/rcu/rcutorture.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
index 528ed10..bcea23c 100644
--- a/kernel/rcu/rcutorture.c
+++ b/kernel/rcu/rcutorture.c
@@ -311,7 +311,7 @@ struct rcu_torture_ops {
void (*deferred_free)(struct rcu_torture *p);
void (*sync)(void);
void (*exp_sync)(void);
-   unsigned long (*get_state)(void);
+   unsigned long (*get_gp_state)(void);
void (*cond_sync)(unsigned long oldstate);
call_rcu_func_t call;
void (*cb_barrier)(void);
@@ -461,7 +461,7 @@ static struct rcu_torture_ops rcu_ops = {
.deferred_free  = rcu_torture_deferred_free,
.sync   = synchronize_rcu,
.exp_sync   = synchronize_rcu_expedited,
-   .get_state  = get_state_synchronize_rcu,
+   .get_gp_state   = get_state_synchronize_rcu,
.cond_sync  = cond_synchronize_rcu,
.call   = call_rcu,
.cb_barrier = rcu_barrier,
@@ -1050,10 +1050,10 @@ rcu_torture_writer(void *arg)
/* Initialize synctype[] array.  If none set, take default. */
if (!gp_cond1 && !gp_exp1 && !gp_normal1 && !gp_sync1)
gp_cond1 = gp_exp1 = gp_normal1 = gp_sync1 = true;
-   if (gp_cond1 && cur_ops->get_state && cur_ops->cond_sync) {
+   if (gp_cond1 && cur_ops->get_gp_state && cur_ops->cond_sync) {
synctype[nsynctypes++] = RTWS_COND_GET;
pr_info("%s: Testing conditional GPs.\n", __func__);
-   } else if (gp_cond && (!cur_ops->get_state || !cur_ops->cond_sync)) {
+   } else if (gp_cond && (!cur_ops->get_gp_state || !cur_ops->cond_sync)) {
pr_alert("%s: gp_cond without primitives.\n", __func__);
}
if (gp_exp1 && cur_ops->exp_sync) {
@@ -1119,7 +1119,7 @@ rcu_torture_writer(void *arg)
break;
case RTWS_COND_GET:
rcu_torture_writer_state = RTWS_COND_GET;
-   gp_snap = cur_ops->get_state();
+   gp_snap = cur_ops->get_gp_state();
i = torture_random() % 16;
if (i != 0)
schedule_timeout_interruptible(i);


[tip: core/rcu] srcu: Add comment explaining cookie overflow/wrap

2021-02-15 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 4e7ccfae52b39aeee93ed39d4184d50ea201fbef
Gitweb:
https://git.kernel.org/tip/4e7ccfae52b39aeee93ed39d4184d50ea201fbef
Author:Paul E. McKenney 
AuthorDate:Sun, 15 Nov 2020 20:33:38 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 04 Jan 2021 13:53:39 -08:00

srcu: Add comment explaining cookie overflow/wrap

This commit adds to the poll_state_synchronize_srcu() header comment
describing the issues surrounding SRCU cookie overflow/wrap for the
different kernel configurations.

Link: https://lore.kernel.org/rcu/20201112201547.gf3365...@moria.home.lan/
Reported-by: Kent Overstreet 
Signed-off-by: Paul E. McKenney 
---
 kernel/rcu/srcutree.c | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/kernel/rcu/srcutree.c b/kernel/rcu/srcutree.c
index c5d0c03..119938d 100644
--- a/kernel/rcu/srcutree.c
+++ b/kernel/rcu/srcutree.c
@@ -1058,6 +1058,21 @@ EXPORT_SYMBOL_GPL(start_poll_synchronize_srcu);
  * get_state_synchronize_srcu() or start_poll_synchronize_srcu(), and
  * returns @true if an SRCU grace period elapsed since the time that the
  * cookie was created.
+ *
+ * Because cookies are finite in size, wrapping/overflow is possible.
+ * This is more pronounced on 32-bit systems where cookies are 32 bits,
+ * where in theory wrapping could happen in about 14 hours assuming
+ * 25-microsecond expedited SRCU grace periods.  However, a more likely
+ * overflow lower bound is on the order of 24 days in the case of
+ * one-millisecond SRCU grace periods.  Of course, wrapping in a 64-bit
+ * system requires geologic timespans, as in more than seven million years
+ * even for expedited SRCU grace periods.
+ *
+ * Wrapping/overflow is much more of an issue for CONFIG_SMP=n systems
+ * that also have CONFIG_PREEMPTION=n, which selects Tiny SRCU.  This uses
+ * a 16-bit cookie, which rcutorture routinely wraps in a matter of a
+ * few minutes.  If this proves to be a problem, this counter will be
+ * expanded to the same size as for Tree SRCU.
  */
 bool poll_state_synchronize_srcu(struct srcu_struct *ssp, unsigned long cookie)
 {


[tip: core/rcu] rcutorture: Add writer-side tests of polling grace-period API

2021-02-15 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 0fd0548db13346bfb3bb23860ab270a32d6e385a
Gitweb:
https://git.kernel.org/tip/0fd0548db13346bfb3bb23860ab270a32d6e385a
Author:Paul E. McKenney 
AuthorDate:Fri, 13 Nov 2020 20:43:59 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 04 Jan 2021 13:53:40 -08:00

rcutorture: Add writer-side tests of polling grace-period API

This commit adds writer-side testing of the polling grace-period API.
One test verifies that the polling API sees a grace period caused by
some other mechanism.  Another test verifies that using the polling API
to wait for a grace period does not result in too-short grace periods.
A third test verifies that the polling API does not report
completion within a read-side critical section.  A fourth and final
test verifies that the polling API does report completion given an
intervening grace period.

Link: https://lore.kernel.org/rcu/20201112201547.gf3365...@moria.home.lan/
Reported-by: Kent Overstreet 
Signed-off-by: Paul E. McKenney 
---
 kernel/rcu/rcutorture.c | 79 
 1 file changed, 72 insertions(+), 7 deletions(-)

diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
index bcea23c..78ba95d 100644
--- a/kernel/rcu/rcutorture.c
+++ b/kernel/rcu/rcutorture.c
@@ -85,6 +85,7 @@ torture_param(bool, gp_cond, false, "Use conditional/async GP 
wait primitives");
 torture_param(bool, gp_exp, false, "Use expedited GP wait primitives");
 torture_param(bool, gp_normal, false,
 "Use normal (non-expedited) GP wait primitives");
+torture_param(bool, gp_poll, false, "Use polling GP wait primitives");
 torture_param(bool, gp_sync, false, "Use synchronous GP wait primitives");
 torture_param(int, irqreader, 1, "Allow RCU readers from irq handlers");
 torture_param(int, leakpointer, 0, "Leak pointer dereferences from readers");
@@ -183,9 +184,11 @@ static int rcu_torture_writer_state;
 #define RTWS_EXP_SYNC  4
 #define RTWS_COND_GET  5
 #define RTWS_COND_SYNC 6
-#define RTWS_SYNC  7
-#define RTWS_STUTTER   8
-#define RTWS_STOPPING  9
+#define RTWS_POLL_GET  7
+#define RTWS_POLL_WAIT 8
+#define RTWS_SYNC  9
+#define RTWS_STUTTER   10
+#define RTWS_STOPPING  11
 static const char * const rcu_torture_writer_state_names[] = {
"RTWS_FIXED_DELAY",
"RTWS_DELAY",
@@ -194,6 +197,8 @@ static const char * const rcu_torture_writer_state_names[] 
= {
"RTWS_EXP_SYNC",
"RTWS_COND_GET",
"RTWS_COND_SYNC",
+   "RTWS_POLL_GET",
+   "RTWS_POLL_WAIT",
"RTWS_SYNC",
"RTWS_STUTTER",
"RTWS_STOPPING",
@@ -312,6 +317,8 @@ struct rcu_torture_ops {
void (*sync)(void);
void (*exp_sync)(void);
unsigned long (*get_gp_state)(void);
+   unsigned long (*start_gp_poll)(void);
+   bool (*poll_gp_state)(unsigned long oldstate);
void (*cond_sync)(unsigned long oldstate);
call_rcu_func_t call;
void (*cb_barrier)(void);
@@ -570,6 +577,21 @@ static void srcu_torture_synchronize(void)
synchronize_srcu(srcu_ctlp);
 }
 
+static unsigned long srcu_torture_get_gp_state(void)
+{
+   return get_state_synchronize_srcu(srcu_ctlp);
+}
+
+static unsigned long srcu_torture_start_gp_poll(void)
+{
+   return start_poll_synchronize_srcu(srcu_ctlp);
+}
+
+static bool srcu_torture_poll_gp_state(unsigned long oldstate)
+{
+   return poll_state_synchronize_srcu(srcu_ctlp, oldstate);
+}
+
 static void srcu_torture_call(struct rcu_head *head,
  rcu_callback_t func)
 {
@@ -601,6 +623,9 @@ static struct rcu_torture_ops srcu_ops = {
.deferred_free  = srcu_torture_deferred_free,
.sync   = srcu_torture_synchronize,
.exp_sync   = srcu_torture_synchronize_expedited,
+   .get_gp_state   = srcu_torture_get_gp_state,
+   .start_gp_poll  = srcu_torture_start_gp_poll,
+   .poll_gp_state  = srcu_torture_poll_gp_state,
.call   = srcu_torture_call,
.cb_barrier = srcu_torture_barrier,
.stats  = srcu_torture_stats,
@@ -1027,18 +1052,20 @@ static int
 rcu_torture_writer(void *arg)
 {
bool can_expedite = !rcu_gp_is_expedited() && !rcu_gp_is_normal();
+   unsigned long cookie;
int expediting = 0;
unsigned long gp_snap;
bool gp_cond1 = gp_cond, gp_exp1 = gp_exp, gp_normal1 = gp_normal;
-   bool gp_sync1 = gp_sync;
+   bool gp_poll1 = gp_poll, gp_sync1 = gp_sync;
int i;
+   int idx;
int oldnice = task_nice(current);
struct rcu_torture *rp;
struct rcu_torture *old_rp;
static DEFINE_TORTURE_RANDOM(rand);
bool stutter_waited;
int synctype[] = { RTWS_DEF_FREE, RTWS_EXP_SYNC,
-  RTWS_COND_GET, RTWS_SYNC };
+  

[tip: locking/core] tools/memory-model: Tie acquire loads to reads-from

2021-02-15 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the locking/core branch of tip:

Commit-ID: 8881e7a774a8d14088d6c6fde8730660f74a3642
Gitweb:
https://git.kernel.org/tip/8881e7a774a8d14088d6c6fde8730660f74a3642
Author:Paul E. McKenney 
AuthorDate:Fri, 06 Nov 2020 09:58:01 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 04 Jan 2021 14:40:49 -08:00

tools/memory-model: Tie acquire loads to reads-from

This commit explicitly makes the connection between acquire loads and
the reads-from relation.  It also adds an entry for happens-before,
and refers to the corresponding section of explanation.txt.

Reported-by: Boqun Feng 
Signed-off-by: Paul E. McKenney 
---
 tools/memory-model/Documentation/glossary.txt | 12 +---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/tools/memory-model/Documentation/glossary.txt 
b/tools/memory-model/Documentation/glossary.txt
index 79acb75..b2da636 100644
--- a/tools/memory-model/Documentation/glossary.txt
+++ b/tools/memory-model/Documentation/glossary.txt
@@ -33,10 +33,11 @@ Acquire:  With respect to a lock, acquiring that lock, for 
example,
acquire loads.
 
When an acquire load returns the value stored by a release store
-   to that same variable, then all operations preceding that store
-   happen before any operations following that load acquire.
+   to that same variable, (in other words, the acquire load "reads
+   from" the release store), then all operations preceding that
+   store "happen before" any operations following that load acquire.
 
-   See also "Relaxed" and "Release".
+   See also "Happens-Before", "Reads-From", "Relaxed", and "Release".
 
 Coherence (co):  When one CPU's store to a given variable overwrites
either the value from another CPU's store or some later value,
@@ -119,6 +120,11 @@ Fully Ordered:  An operation such as smp_mb() that orders 
all of
that orders all of its CPU's prior accesses, itself, and
all of its CPU's subsequent accesses.
 
+Happens-Before (hb): A relation between two accesses in which LKMM
+   guarantees the first access precedes the second.  For more
+   detail, please see the "THE HAPPENS-BEFORE RELATION: hb"
+   section of explanation.txt.
+
 Marked Access:  An access to a variable that uses an special function or
macro such as "r1 = READ_ONCE(x)" or "smp_store_release(, 1)".
 


[tip: core/rcu] doc: Update RCU requirements RCU_INIT_POINTER() description

2021-02-15 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: d756c74e6f6e76e99f8bffcea57833816dd335b6
Gitweb:
https://git.kernel.org/tip/d756c74e6f6e76e99f8bffcea57833816dd335b6
Author:Paul E. McKenney 
AuthorDate:Wed, 09 Dec 2020 16:54:41 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 04 Jan 2021 13:35:15 -08:00

doc: Update RCU requirements RCU_INIT_POINTER() description

Back in the day, RCU_INIT_POINTER() was the only way to avoid
memory-barrier instructions while storing NULL to an RCU-protected
pointer.  Fortunately, in 2016, rcu_assign_pointer() started checking for
compile-time NULL pointers and omitting the memory-barrier instructions in
that case.  Unfortunately, RCU's Requirements.rst document was not updated
accordingly.  This commit therefore at long last carries out that update.

Fixes: 3a37f7275cda ("rcu: No ordering for rcu_assign_pointer() of NULL")
Link: https://lore.kernel.org/lkml/20201209230755.gv7...@casper.infradead.org/
Reported-by: Matthew Wilcox 
Acked-by: Linus Torvalds 
Signed-off-by: Paul E. McKenney 
---
 Documentation/RCU/Design/Requirements/Requirements.rst | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/Documentation/RCU/Design/Requirements/Requirements.rst 
b/Documentation/RCU/Design/Requirements/Requirements.rst
index f32f8fa..65c7839 100644
--- a/Documentation/RCU/Design/Requirements/Requirements.rst
+++ b/Documentation/RCU/Design/Requirements/Requirements.rst
@@ -1668,8 +1668,7 @@ against mishaps and misuse:
this purpose.
 #. It is not necessary to use rcu_assign_pointer() when creating
linked structures that are to be published via a single external
-   pointer. The RCU_INIT_POINTER() macro is provided for this task
-   and also for assigning ``NULL`` pointers at runtime.
+   pointer. The RCU_INIT_POINTER() macro is provided for this task.
 
 This not a hard-and-fast list: RCU's diagnostic capabilities will
 continue to be guided by the number and type of usage bugs found in


[tip: core/rcu] srcu: Make Tiny SRCU use multi-bit grace-period counter

2021-02-15 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 74612a07b83fc46c2b2e6f71a541d55b024ebefc
Gitweb:
https://git.kernel.org/tip/74612a07b83fc46c2b2e6f71a541d55b024ebefc
Author:Paul E. McKenney 
AuthorDate:Thu, 12 Nov 2020 16:34:09 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 04 Jan 2021 13:53:36 -08:00

srcu: Make Tiny SRCU use multi-bit grace-period counter

There is a need for a polling interface for SRCU grace periods.  This
polling needs to distinguish between an SRCU instance being idle on the
one hand or in the middle of a grace period on the other.  This commit
therefore converts the Tiny SRCU srcu_struct structure's srcu_idx from
a defacto boolean to a free-running counter, using the bottom bit to
indicate that a grace period is in progress.  The second-from-bottom
bit is thus used as the index returned by srcu_read_lock().

Link: https://lore.kernel.org/rcu/20201112201547.gf3365...@moria.home.lan/
Reported-by: Kent Overstreet 
[ paulmck: Fix ->srcu_lock_nesting[] indexing per Neeraj Upadhyay. ]
Reviewed-by: Neeraj Upadhyay 
Signed-off-by: Paul E. McKenney 
---
 include/linux/srcutiny.h | 6 +++---
 kernel/rcu/srcutiny.c| 5 +++--
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/include/linux/srcutiny.h b/include/linux/srcutiny.h
index 5a5a194..b8b42d0 100644
--- a/include/linux/srcutiny.h
+++ b/include/linux/srcutiny.h
@@ -15,7 +15,7 @@
 
 struct srcu_struct {
short srcu_lock_nesting[2]; /* srcu_read_lock() nesting depth. */
-   short srcu_idx; /* Current reader array element. */
+   unsigned short srcu_idx;/* Current reader array element in bit 
0x2. */
u8 srcu_gp_running; /* GP workqueue running? */
u8 srcu_gp_waiting; /* GP waiting for readers? */
struct swait_queue_head srcu_wq;
@@ -59,7 +59,7 @@ static inline int __srcu_read_lock(struct srcu_struct *ssp)
 {
int idx;
 
-   idx = READ_ONCE(ssp->srcu_idx);
+   idx = ((READ_ONCE(ssp->srcu_idx) + 1) & 0x2) >> 1;
WRITE_ONCE(ssp->srcu_lock_nesting[idx], ssp->srcu_lock_nesting[idx] + 
1);
return idx;
 }
@@ -80,7 +80,7 @@ static inline void srcu_torture_stats_print(struct 
srcu_struct *ssp,
 {
int idx;
 
-   idx = READ_ONCE(ssp->srcu_idx) & 0x1;
+   idx = ((READ_ONCE(ssp->srcu_idx) + 1) & 0x2) >> 1;
pr_alert("%s%s Tiny SRCU per-CPU(idx=%d): (%hd,%hd)\n",
 tt, tf, idx,
 READ_ONCE(ssp->srcu_lock_nesting[!idx]),
diff --git a/kernel/rcu/srcutiny.c b/kernel/rcu/srcutiny.c
index 6208c1d..5598cf6 100644
--- a/kernel/rcu/srcutiny.c
+++ b/kernel/rcu/srcutiny.c
@@ -124,11 +124,12 @@ void srcu_drive_gp(struct work_struct *wp)
ssp->srcu_cb_head = NULL;
ssp->srcu_cb_tail = >srcu_cb_head;
local_irq_enable();
-   idx = ssp->srcu_idx;
-   WRITE_ONCE(ssp->srcu_idx, !ssp->srcu_idx);
+   idx = (ssp->srcu_idx & 0x2) / 2;
+   WRITE_ONCE(ssp->srcu_idx, ssp->srcu_idx + 1);
WRITE_ONCE(ssp->srcu_gp_waiting, true);  /* srcu_read_unlock() wakes! */
swait_event_exclusive(ssp->srcu_wq, 
!READ_ONCE(ssp->srcu_lock_nesting[idx]));
WRITE_ONCE(ssp->srcu_gp_waiting, false); /* srcu_read_unlock() cheap. */
+   WRITE_ONCE(ssp->srcu_idx, ssp->srcu_idx + 1);
 
/* Invoke the callbacks we removed above. */
while (lh) {


[tip: core/rcu] srcu: Provide internal interface to start a Tiny SRCU grace period

2021-02-15 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 1a893c711a600ab57526619b56e6f6b7be00956e
Gitweb:
https://git.kernel.org/tip/1a893c711a600ab57526619b56e6f6b7be00956e
Author:Paul E. McKenney 
AuthorDate:Fri, 13 Nov 2020 09:37:39 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 04 Jan 2021 13:53:37 -08:00

srcu: Provide internal interface to start a Tiny SRCU grace period

There is a need for a polling interface for SRCU grace periods.
This polling needs to initiate an SRCU grace period without
having to queue (and manage) a callback.  This commit therefore
splits the Tiny SRCU call_srcu() function into callback-queuing and
start-grace-period portions, with the latter in a new function named
srcu_gp_start_if_needed().

Link: https://lore.kernel.org/rcu/20201112201547.gf3365...@moria.home.lan/
Reported-by: Kent Overstreet 
Reviewed-by: Neeraj Upadhyay 
Signed-off-by: Paul E. McKenney 
---
 kernel/rcu/srcutiny.c | 17 +++--
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/kernel/rcu/srcutiny.c b/kernel/rcu/srcutiny.c
index 5598cf6..3bac1db 100644
--- a/kernel/rcu/srcutiny.c
+++ b/kernel/rcu/srcutiny.c
@@ -152,6 +152,16 @@ void srcu_drive_gp(struct work_struct *wp)
 }
 EXPORT_SYMBOL_GPL(srcu_drive_gp);
 
+static void srcu_gp_start_if_needed(struct srcu_struct *ssp)
+{
+   if (!READ_ONCE(ssp->srcu_gp_running)) {
+   if (likely(srcu_init_done))
+   schedule_work(>srcu_work);
+   else if (list_empty(>srcu_work.entry))
+   list_add(>srcu_work.entry, _boot_list);
+   }
+}
+
 /*
  * Enqueue an SRCU callback on the specified srcu_struct structure,
  * initiating grace-period processing if it is not already running.
@@ -167,12 +177,7 @@ void call_srcu(struct srcu_struct *ssp, struct rcu_head 
*rhp,
*ssp->srcu_cb_tail = rhp;
ssp->srcu_cb_tail = >next;
local_irq_restore(flags);
-   if (!READ_ONCE(ssp->srcu_gp_running)) {
-   if (likely(srcu_init_done))
-   schedule_work(>srcu_work);
-   else if (list_empty(>srcu_work.entry))
-   list_add(>srcu_work.entry, _boot_list);
-   }
+   srcu_gp_start_if_needed(ssp);
 }
 EXPORT_SYMBOL_GPL(call_srcu);
 


[tip: core/rcu] srcu: Document polling interfaces for Tree SRCU grace periods

2021-02-15 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: ee7f4a87a18cd3bb141b38e2ef0c3e53253cdf63
Gitweb:
https://git.kernel.org/tip/ee7f4a87a18cd3bb141b38e2ef0c3e53253cdf63
Author:Paul E. McKenney 
AuthorDate:Wed, 18 Nov 2020 16:01:32 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 04 Jan 2021 13:53:39 -08:00

srcu: Document polling interfaces for Tree SRCU grace periods

This commit adds requirements documentation for the
get_state_synchronize_srcu(), start_poll_synchronize_srcu(), and
poll_state_synchronize_srcu() functions.

Link: https://lore.kernel.org/rcu/20201112201547.gf3365...@moria.home.lan/
Reported-by: Kent Overstreet 
Reviewed-by: Neeraj Upadhyay 
Signed-off-by: Paul E. McKenney 
---
 Documentation/RCU/Design/Requirements/Requirements.rst | 18 +-
 1 file changed, 18 insertions(+)

diff --git a/Documentation/RCU/Design/Requirements/Requirements.rst 
b/Documentation/RCU/Design/Requirements/Requirements.rst
index e8c84fc..93a189a 100644
--- a/Documentation/RCU/Design/Requirements/Requirements.rst
+++ b/Documentation/RCU/Design/Requirements/Requirements.rst
@@ -2600,6 +2600,24 @@ also includes ``DEFINE_SRCU()``, 
``DEFINE_STATIC_SRCU()``, and
 ``init_srcu_struct()`` APIs for defining and initializing
 ``srcu_struct`` structures.
 
+More recently, the SRCU API has added polling interfaces:
+
+#. start_poll_synchronize_srcu() returns a cookie identifying
+   the completion of a future SRCU grace period and ensures
+   that this grace period will be started.
+#. poll_state_synchronize_srcu() returns ``true`` iff the
+   specified cookie corresponds to an already-completed
+   SRCU grace period.
+#. get_state_synchronize_srcu() returns a cookie just like
+   start_poll_synchronize_srcu() does, but differs in that
+   it does nothing to ensure that any future SRCU grace period
+   will be started.
+
+These functions are used to avoid unnecessary SRCU grace periods in
+certain types of buffer-cache algorithms having multi-stage age-out
+mechanisms.  The idea is that by the time the block has aged completely
+from the cache, an SRCU grace period will be very likely to have elapsed.
+
 Tasks RCU
 ~
 


[tip: core/rcu] srcu: Provide internal interface to start a Tree SRCU grace period

2021-02-15 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 29d2bb94a8a126ce80ffbb433b648b32fdea524e
Gitweb:
https://git.kernel.org/tip/29d2bb94a8a126ce80ffbb433b648b32fdea524e
Author:Paul E. McKenney 
AuthorDate:Fri, 13 Nov 2020 10:08:09 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 04 Jan 2021 13:53:37 -08:00

srcu: Provide internal interface to start a Tree SRCU grace period

There is a need for a polling interface for SRCU grace periods.
This polling needs to initiate an SRCU grace period without having
to queue (and manage) a callback.  This commit therefore splits the
Tree SRCU __call_srcu() function into callback-initialization and
queuing/start-grace-period portions, with the latter in a new function
named srcu_gp_start_if_needed().  This function may be passed a NULL
callback pointer, in which case it will refrain from queuing anything.

Why have the new function mess with queuing?  Locking considerations,
of course!

Link: https://lore.kernel.org/rcu/20201112201547.gf3365...@moria.home.lan/
Reported-by: Kent Overstreet 
Reviewed-by: Neeraj Upadhyay 
Signed-off-by: Paul E. McKenney 
---
 kernel/rcu/srcutree.c | 66 +++---
 1 file changed, 37 insertions(+), 29 deletions(-)

diff --git a/kernel/rcu/srcutree.c b/kernel/rcu/srcutree.c
index 0f23d20..9a7b650 100644
--- a/kernel/rcu/srcutree.c
+++ b/kernel/rcu/srcutree.c
@@ -808,6 +808,42 @@ static void srcu_leak_callback(struct rcu_head *rhp)
 }
 
 /*
+ * Start an SRCU grace period, and also queue the callback if non-NULL.
+ */
+static void srcu_gp_start_if_needed(struct srcu_struct *ssp, struct rcu_head 
*rhp, bool do_norm)
+{
+   unsigned long flags;
+   int idx;
+   bool needexp = false;
+   bool needgp = false;
+   unsigned long s;
+   struct srcu_data *sdp;
+
+   idx = srcu_read_lock(ssp);
+   sdp = raw_cpu_ptr(ssp->sda);
+   spin_lock_irqsave_rcu_node(sdp, flags);
+   rcu_segcblist_enqueue(>srcu_cblist, rhp);
+   rcu_segcblist_advance(>srcu_cblist,
+ rcu_seq_current(>srcu_gp_seq));
+   s = rcu_seq_snap(>srcu_gp_seq);
+   (void)rcu_segcblist_accelerate(>srcu_cblist, s);
+   if (ULONG_CMP_LT(sdp->srcu_gp_seq_needed, s)) {
+   sdp->srcu_gp_seq_needed = s;
+   needgp = true;
+   }
+   if (!do_norm && ULONG_CMP_LT(sdp->srcu_gp_seq_needed_exp, s)) {
+   sdp->srcu_gp_seq_needed_exp = s;
+   needexp = true;
+   }
+   spin_unlock_irqrestore_rcu_node(sdp, flags);
+   if (needgp)
+   srcu_funnel_gp_start(ssp, sdp, s, do_norm);
+   else if (needexp)
+   srcu_funnel_exp_start(ssp, sdp->mynode, s);
+   srcu_read_unlock(ssp, idx);
+}
+
+/*
  * Enqueue an SRCU callback on the srcu_data structure associated with
  * the current CPU and the specified srcu_struct structure, initiating
  * grace-period processing if it is not already running.
@@ -838,13 +874,6 @@ static void srcu_leak_callback(struct rcu_head *rhp)
 static void __call_srcu(struct srcu_struct *ssp, struct rcu_head *rhp,
rcu_callback_t func, bool do_norm)
 {
-   unsigned long flags;
-   int idx;
-   bool needexp = false;
-   bool needgp = false;
-   unsigned long s;
-   struct srcu_data *sdp;
-
check_init_srcu_struct(ssp);
if (debug_rcu_head_queue(rhp)) {
/* Probable double call_srcu(), so leak the callback. */
@@ -853,28 +882,7 @@ static void __call_srcu(struct srcu_struct *ssp, struct 
rcu_head *rhp,
return;
}
rhp->func = func;
-   idx = srcu_read_lock(ssp);
-   sdp = raw_cpu_ptr(ssp->sda);
-   spin_lock_irqsave_rcu_node(sdp, flags);
-   rcu_segcblist_enqueue(>srcu_cblist, rhp);
-   rcu_segcblist_advance(>srcu_cblist,
- rcu_seq_current(>srcu_gp_seq));
-   s = rcu_seq_snap(>srcu_gp_seq);
-   (void)rcu_segcblist_accelerate(>srcu_cblist, s);
-   if (ULONG_CMP_LT(sdp->srcu_gp_seq_needed, s)) {
-   sdp->srcu_gp_seq_needed = s;
-   needgp = true;
-   }
-   if (!do_norm && ULONG_CMP_LT(sdp->srcu_gp_seq_needed_exp, s)) {
-   sdp->srcu_gp_seq_needed_exp = s;
-   needexp = true;
-   }
-   spin_unlock_irqrestore_rcu_node(sdp, flags);
-   if (needgp)
-   srcu_funnel_gp_start(ssp, sdp, s, do_norm);
-   else if (needexp)
-   srcu_funnel_exp_start(ssp, sdp->mynode, s);
-   srcu_read_unlock(ssp, idx);
+   srcu_gp_start_if_needed(ssp, rhp, do_norm);
 }
 
 /**


[tip: core/rcu] rcutorture: Add reader-side tests of polling grace-period API

2021-02-15 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: bc480a6354ef2e15c26c3bdbd0db647026e788a7
Gitweb:
https://git.kernel.org/tip/bc480a6354ef2e15c26c3bdbd0db647026e788a7
Author:Paul E. McKenney 
AuthorDate:Sun, 15 Nov 2020 12:45:57 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 04 Jan 2021 13:53:40 -08:00

rcutorture: Add reader-side tests of polling grace-period API

This commit adds reader-side testing of the polling grace-period API.
This testing verifies that a cookie obtained in an SRCU read-side critical
section does not get a true return from poll_state_synchronize_srcu()
within that same critical section.

Link: https://lore.kernel.org/rcu/20201112201547.gf3365...@moria.home.lan/
Reported-by: Kent Overstreet 
Signed-off-by: Paul E. McKenney 
---
 kernel/rcu/rcutorture.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
index 78ba95d..96d55f0 100644
--- a/kernel/rcu/rcutorture.c
+++ b/kernel/rcu/rcutorture.c
@@ -1429,6 +1429,7 @@ rcutorture_loop_extend(int *readstate, struct 
torture_random_state *trsp,
  */
 static bool rcu_torture_one_read(struct torture_random_state *trsp)
 {
+   unsigned long cookie;
int i;
unsigned long started;
unsigned long completed;
@@ -1444,6 +1445,8 @@ static bool rcu_torture_one_read(struct 
torture_random_state *trsp)
WARN_ON_ONCE(!rcu_is_watching());
newstate = rcutorture_extend_mask(readstate, trsp);
rcutorture_one_extend(, newstate, trsp, rtrsp++);
+   if (cur_ops->get_gp_state && cur_ops->poll_gp_state)
+   cookie = cur_ops->get_gp_state();
started = cur_ops->get_gp_seq();
ts = rcu_trace_clock_local();
p = rcu_dereference_check(rcu_torture_current,
@@ -1480,6 +1483,13 @@ static bool rcu_torture_one_read(struct 
torture_random_state *trsp)
}
__this_cpu_inc(rcu_torture_batch[completed]);
preempt_enable();
+   if (cur_ops->get_gp_state && cur_ops->poll_gp_state)
+   WARN_ONCE(cur_ops->poll_gp_state(cookie),
+ "%s: Cookie check 3 failed %s(%d) %lu->%lu\n",
+ __func__,
+ rcu_torture_writer_state_getname(),
+ rcu_torture_writer_state,
+ cookie, cur_ops->get_gp_state());
rcutorture_one_extend(, 0, trsp, rtrsp);
WARN_ON_ONCE(readstate & RCUTORTURE_RDR_MASK);
// This next splat is expected behavior if leakpointer, especially


[tip: core/rcu] rcutorture: Add testing for RCU's global memory ordering

2021-02-15 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 00504537f44422a99d97f615f2b3ee17cfba194d
Gitweb:
https://git.kernel.org/tip/00504537f44422a99d97f615f2b3ee17cfba194d
Author:Paul E. McKenney 
AuthorDate:Thu, 29 Oct 2020 15:08:57 -07:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 04 Jan 2021 13:53:41 -08:00

rcutorture: Add testing for RCU's global memory ordering

RCU guarantees that anything seen by a given reader will also be seen
after any grace period that must wait on that reader.  This is very likely
to hold based on inspection, but the advantage of having rcutorture do
the inspecting is that rcutorture doesn't mind inspecting frequently
and often.

This commit therefore adds code to test RCU's global memory ordering.

Signed-off-by: Paul E. McKenney 
---
 kernel/rcu/rcutorture.c | 98 +---
 1 file changed, 92 insertions(+), 6 deletions(-)

diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
index 96d55f0..338e118 100644
--- a/kernel/rcu/rcutorture.c
+++ b/kernel/rcu/rcutorture.c
@@ -143,11 +143,22 @@ static struct task_struct *read_exit_task;
 
 #define RCU_TORTURE_PIPE_LEN 10
 
+// Mailbox-like structure to check RCU global memory ordering.
+struct rcu_torture_reader_check {
+   unsigned long rtc_myloops;
+   int rtc_chkrdr;
+   unsigned long rtc_chkloops;
+   int rtc_ready;
+   struct rcu_torture_reader_check *rtc_assigner;
+} cacheline_internodealigned_in_smp;
+
+// Update-side data structure used to check RCU readers.
 struct rcu_torture {
struct rcu_head rtort_rcu;
int rtort_pipe_count;
struct list_head rtort_free;
int rtort_mbtest;
+   struct rcu_torture_reader_check *rtort_chkp;
 };
 
 static LIST_HEAD(rcu_torture_freelist);
@@ -158,10 +169,13 @@ static DEFINE_SPINLOCK(rcu_torture_lock);
 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count);
 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch);
 static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
+static struct rcu_torture_reader_check *rcu_torture_reader_mbchk;
 static atomic_t n_rcu_torture_alloc;
 static atomic_t n_rcu_torture_alloc_fail;
 static atomic_t n_rcu_torture_free;
 static atomic_t n_rcu_torture_mberror;
+static atomic_t n_rcu_torture_mbchk_fail;
+static atomic_t n_rcu_torture_mbchk_tries;
 static atomic_t n_rcu_torture_error;
 static long n_rcu_torture_barrier_error;
 static long n_rcu_torture_boost_ktrerror;
@@ -393,7 +407,12 @@ static bool
 rcu_torture_pipe_update_one(struct rcu_torture *rp)
 {
int i;
+   struct rcu_torture_reader_check *rtrcp = READ_ONCE(rp->rtort_chkp);
 
+   if (rtrcp) {
+   WRITE_ONCE(rp->rtort_chkp, NULL);
+   smp_store_release(>rtc_ready, 1); // Pair with 
smp_load_acquire().
+   }
i = READ_ONCE(rp->rtort_pipe_count);
if (i > RCU_TORTURE_PIPE_LEN)
i = RCU_TORTURE_PIPE_LEN;
@@ -1292,6 +1311,62 @@ static void rcu_torture_timer_cb(struct rcu_head *rhp)
kfree(rhp);
 }
 
+// Set up and carry out testing of RCU's global memory ordering
+static void rcu_torture_reader_do_mbchk(long myid, struct rcu_torture *rtp,
+   struct torture_random_state *trsp)
+{
+   unsigned long loops;
+   int noc = num_online_cpus();
+   int rdrchked;
+   int rdrchker;
+   struct rcu_torture_reader_check *rtrcp; // Me.
+   struct rcu_torture_reader_check *rtrcp_assigner; // Assigned us to do 
checking.
+   struct rcu_torture_reader_check *rtrcp_chked; // Reader being checked.
+   struct rcu_torture_reader_check *rtrcp_chker; // Reader doing checking 
when not me.
+
+   if (myid < 0)
+   return; // Don't try this from timer handlers.
+
+   // Increment my counter.
+   rtrcp = _torture_reader_mbchk[myid];
+   WRITE_ONCE(rtrcp->rtc_myloops, rtrcp->rtc_myloops + 1);
+
+   // Attempt to assign someone else some checking work.
+   rdrchked = torture_random(trsp) % nrealreaders;
+   rtrcp_chked = _torture_reader_mbchk[rdrchked];
+   rdrchker = torture_random(trsp) % nrealreaders;
+   rtrcp_chker = _torture_reader_mbchk[rdrchker];
+   if (rdrchked != myid && rdrchked != rdrchker && noc >= rdrchked && noc 
>= rdrchker &&
+   smp_load_acquire(>rtc_chkrdr) < 0 && // Pairs with 
smp_store_release below.
+   !READ_ONCE(rtp->rtort_chkp) &&
+   !smp_load_acquire(_chker->rtc_assigner)) { // Pairs with 
smp_store_release below.
+   rtrcp->rtc_chkloops = READ_ONCE(rtrcp_chked->rtc_myloops);
+   WARN_ON_ONCE(rtrcp->rtc_chkrdr >= 0);
+   rtrcp->rtc_chkrdr = rdrchked;
+   WARN_ON_ONCE(rtrcp->rtc_ready); // This gets set after the 
grace period ends.
+   if (cmpxchg_relaxed(_chker->rtc_assigner, NULL, rtrcp) ||
+   

[tip: core/rcu] scftorture: Add debug output for wrong-CPU warning

2021-02-15 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: f3ea978b712f768a02137e867aced5bfdcea670e
Gitweb:
https://git.kernel.org/tip/f3ea978b712f768a02137e867aced5bfdcea670e
Author:Paul E. McKenney 
AuthorDate:Wed, 11 Nov 2020 10:12:05 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 04 Jan 2021 13:53:41 -08:00

scftorture: Add debug output for wrong-CPU warning

This commit adds the desired CPU, the actual CPU, and nr_cpu_ids to
the wrong-CPU warning in scftorture_invoker(), the better to help with
debugging.

Signed-off-by: Paul E. McKenney 
---
 kernel/scftorture.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/kernel/scftorture.c b/kernel/scftorture.c
index d55a9f8..2377cbb 100644
--- a/kernel/scftorture.c
+++ b/kernel/scftorture.c
@@ -398,6 +398,7 @@ static void scftorture_invoke_one(struct scf_statistics 
*scfp, struct torture_ra
 static int scftorture_invoker(void *arg)
 {
int cpu;
+   int curcpu;
DEFINE_TORTURE_RANDOM(rand);
struct scf_statistics *scfp = (struct scf_statistics *)arg;
bool was_offline = false;
@@ -412,7 +413,10 @@ static int scftorture_invoker(void *arg)
VERBOSE_SCFTORTOUT("scftorture_invoker %d: Waiting for all SCF 
torturers from cpu %d", scfp->cpu, smp_processor_id());
 
// Make sure that the CPU is affinitized appropriately during testing.
-   WARN_ON_ONCE(smp_processor_id() != scfp->cpu);
+   curcpu = smp_processor_id();
+   WARN_ONCE(curcpu != scfp->cpu % nr_cpu_ids,
+ "%s: Wanted CPU %d, running on %d, nr_cpu_ids = %d\n",
+ __func__, scfp->cpu, curcpu, nr_cpu_ids);
 
if (!atomic_dec_return(_started))
while (atomic_read_acquire(_started)) {


[tip: core/rcu] rcu: Mark obtuse portion of stall warning as internal debug

2021-02-15 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: b08ea1de6a8f8929c7dafd6f708799365fa90c11
Gitweb:
https://git.kernel.org/tip/b08ea1de6a8f8929c7dafd6f708799365fa90c11
Author:Paul E. McKenney 
AuthorDate:Fri, 06 Nov 2020 13:52:31 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 04 Jan 2021 13:54:40 -08:00

rcu: Mark obtuse portion of stall warning as internal debug

There is a rather obtuse string that can be printed as part of an
expedited RCU CPU stall-warning message that starts with "blocking
rcu_node structures".  Under normal conditions, most of this message
is just repeating the list of CPUs blocking the current expedited grace
period, but in a manner that is rather difficult to read.  This commit
therefore marks this message as "(internal RCU debug)" in an effort to
give people the option of avoiding wasting time attempting to extract
nonexistent additional meaning from this portion of the message.

Reported-by: Jonathan Lemon 
Signed-off-by: Paul E. McKenney 
---
 kernel/rcu/tree_exp.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/rcu/tree_exp.h b/kernel/rcu/tree_exp.h
index 8760b6e..6c6ff06 100644
--- a/kernel/rcu/tree_exp.h
+++ b/kernel/rcu/tree_exp.h
@@ -545,7 +545,7 @@ static void synchronize_rcu_expedited_wait(void)
data_race(rnp_root->expmask),
".T"[!!data_race(rnp_root->exp_tasks)]);
if (ndetected) {
-   pr_err("blocking rcu_node structures:");
+   pr_err("blocking rcu_node structures (internal RCU 
debug):");
rcu_for_each_node_breadth_first(rnp) {
if (rnp == rnp_root)
continue; /* printed unconditionally */


[tip: core/rcu] rcu: For RCU grace-period kthread starvation, dump last CPU it ran on

2021-02-15 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 243027a3c80564bf96e40437ffac46efb9f5f2b5
Gitweb:
https://git.kernel.org/tip/243027a3c80564bf96e40437ffac46efb9f5f2b5
Author:Paul E. McKenney 
AuthorDate:Wed, 11 Nov 2020 16:08:01 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 04 Jan 2021 13:59:41 -08:00

rcu: For RCU grace-period kthread starvation, dump last CPU it ran on

When the RCU CPU stall-warning code detects that the RCU grace-period
kthread is being starved, it dumps that kthread's stack.  This can
sometimes be useful, but it is also useful to know what is running on the
CPU that this kthread is attempting to run on.  This commit therefore
adds a stack trace of this CPU in order to help track down whatever it
is that might be preventing RCU's grace-period kthread from running.

Signed-off-by: Paul E. McKenney 
---
 kernel/rcu/tree_stall.h |  9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/kernel/rcu/tree_stall.h b/kernel/rcu/tree_stall.h
index 70d48c5..35c1355 100644
--- a/kernel/rcu/tree_stall.h
+++ b/kernel/rcu/tree_stall.h
@@ -449,20 +449,27 @@ static void print_cpu_stall_info(int cpu)
 /* Complain about starvation of grace-period kthread.  */
 static void rcu_check_gp_kthread_starvation(void)
 {
+   int cpu;
struct task_struct *gpk = rcu_state.gp_kthread;
unsigned long j;
 
if (rcu_is_gp_kthread_starving()) {
+   cpu = gpk ? task_cpu(gpk) : -1;
pr_err("%s kthread starved for %ld jiffies! g%ld f%#x %s(%d) 
->state=%#lx ->cpu=%d\n",
   rcu_state.name, j,
   (long)rcu_seq_current(_state.gp_seq),
   data_race(rcu_state.gp_flags),
   gp_state_getname(rcu_state.gp_state), rcu_state.gp_state,
-  gpk ? gpk->state : ~0, gpk ? task_cpu(gpk) : -1);
+  gpk ? gpk->state : ~0, cpu);
if (gpk) {
pr_err("\tUnless %s kthread gets sufficient CPU time, 
OOM is now expected behavior.\n", rcu_state.name);
pr_err("RCU grace-period kthread stack dump:\n");
sched_show_task(gpk);
+   if (cpu >= 0) {
+   pr_err("Stack dump where RCU grace-period 
kthread last ran:\n");
+   if (!trigger_single_cpu_backtrace(cpu))
+   dump_cpu_task(cpu);
+   }
wake_up_process(gpk);
}
}


[tip: core/rcu] torture: Make --kcsan specify lockdep

2021-02-15 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 0682aa7acd5d2688a8b781d91938e21ae4717c52
Gitweb:
https://git.kernel.org/tip/0682aa7acd5d2688a8b781d91938e21ae4717c52
Author:Paul E. McKenney 
AuthorDate:Thu, 05 Nov 2020 20:01:46 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 04 Jan 2021 14:01:17 -08:00

torture: Make --kcsan specify lockdep

The --kcsan argument to kvm.sh adds CONFIG_KCSAN_VERBOSE=y in order to
get more detail from the KCSAN reports.  However, this Kconfig option
requires lockdep to be enabled.  This commit therefore causes --kcsan
to also enable lockdep.

Signed-off-by: Paul E. McKenney 
---
 tools/testing/selftests/rcutorture/bin/kvm.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/rcutorture/bin/kvm.sh 
b/tools/testing/selftests/rcutorture/bin/kvm.sh
index 45d07b7..bd07df7 100755
--- a/tools/testing/selftests/rcutorture/bin/kvm.sh
+++ b/tools/testing/selftests/rcutorture/bin/kvm.sh
@@ -169,7 +169,7 @@ do
TORTURE_KCONFIG_KASAN_ARG="CONFIG_DEBUG_INFO=y CONFIG_KASAN=y"; 
export TORTURE_KCONFIG_KASAN_ARG
;;
--kcsan)
-   TORTURE_KCONFIG_KCSAN_ARG="CONFIG_DEBUG_INFO=y CONFIG_KCSAN=y 
CONFIG_KCSAN_ASSUME_PLAIN_WRITES_ATOMIC=n 
CONFIG_KCSAN_REPORT_VALUE_CHANGE_ONLY=n CONFIG_KCSAN_REPORT_ONCE_IN_MS=10 
CONFIG_KCSAN_VERBOSE=y CONFIG_KCSAN_INTERRUPT_WATCHER=y"; export 
TORTURE_KCONFIG_KCSAN_ARG
+   TORTURE_KCONFIG_KCSAN_ARG="CONFIG_DEBUG_INFO=y CONFIG_KCSAN=y 
CONFIG_KCSAN_ASSUME_PLAIN_WRITES_ATOMIC=n 
CONFIG_KCSAN_REPORT_VALUE_CHANGE_ONLY=n CONFIG_KCSAN_REPORT_ONCE_IN_MS=10 
CONFIG_KCSAN_INTERRUPT_WATCHER=y CONFIG_KCSAN_VERBOSE=y 
CONFIG_DEBUG_LOCK_ALLOC=y CONFIG_PROVE_LOCKING=y"; export 
TORTURE_KCONFIG_KCSAN_ARG
;;
--kmake-arg|--kmake-args)
checkarg --kmake-arg "(kernel make arguments)" $# "$2" '.*' 
'^error$'


[tip: core/rcu] torture: Make kvm.sh "--dryrun sched" summarize number of batches

2021-02-15 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 1f947be7f9696fca36e67f0897bc239b4755ae55
Gitweb:
https://git.kernel.org/tip/1f947be7f9696fca36e67f0897bc239b4755ae55
Author:Paul E. McKenney 
AuthorDate:Sun, 08 Nov 2020 15:38:26 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 04 Jan 2021 14:01:18 -08:00

torture: Make kvm.sh "--dryrun sched" summarize number of batches

Knowing the number of batches that kvm.sh will split a run into allows
estimation of the duration of a test, give or take the number of builds.
This commit therefore adds a line of output to "--dryrun sched" that
gives the number of batches that will be run.

Signed-off-by: Paul E. McKenney 
---
 tools/testing/selftests/rcutorture/bin/kvm.sh | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/testing/selftests/rcutorture/bin/kvm.sh 
b/tools/testing/selftests/rcutorture/bin/kvm.sh
index bd07df7..1078be1 100755
--- a/tools/testing/selftests/rcutorture/bin/kvm.sh
+++ b/tools/testing/selftests/rcutorture/bin/kvm.sh
@@ -536,6 +536,8 @@ then
egrep 'Start batch|Starting build\.' $T/script |
grep -v ">>" |
sed -e 's/:.*$//' -e 's/^echo //'
+   nbatches="`grep 'Start batch' $T/script | grep -v ">>" | wc -l`"
+   echo Total number of batches: $nbatches
exit 0
 else
# Not a dryrun, so run the script.


[tip: core/rcu] rcu: Do not NMI offline CPUs

2021-02-15 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 725969ac11d7fa50aa701321daa600ce421fc21b
Gitweb:
https://git.kernel.org/tip/725969ac11d7fa50aa701321daa600ce421fc21b
Author:Paul E. McKenney 
AuthorDate:Thu, 12 Nov 2020 12:19:47 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 04 Jan 2021 13:59:47 -08:00

rcu: Do not NMI offline CPUs

Currently, RCU CPU stall warning messages will NMI whatever CPU looks
like it is blocking either the current grace period or the grace-period
kthread.  This can produce confusing output if the target CPU is offline.
This commit therefore checks for offline CPUs.

Signed-off-by: Paul E. McKenney 
---
 kernel/rcu/tree_stall.h | 17 -
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/kernel/rcu/tree_stall.h b/kernel/rcu/tree_stall.h
index 35c1355..29cf096 100644
--- a/kernel/rcu/tree_stall.h
+++ b/kernel/rcu/tree_stall.h
@@ -333,9 +333,12 @@ static void rcu_dump_cpu_stacks(void)
rcu_for_each_leaf_node(rnp) {
raw_spin_lock_irqsave_rcu_node(rnp, flags);
for_each_leaf_node_possible_cpu(rnp, cpu)
-   if (rnp->qsmask & leaf_node_cpu_bit(rnp, cpu))
-   if (!trigger_single_cpu_backtrace(cpu))
+   if (rnp->qsmask & leaf_node_cpu_bit(rnp, cpu)) {
+   if (cpu_is_offline(cpu))
+   pr_err("Offline CPU %d blocking current 
GP.\n", cpu);
+   else if (!trigger_single_cpu_backtrace(cpu))
dump_cpu_task(cpu);
+   }
raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
}
 }
@@ -466,9 +469,13 @@ static void rcu_check_gp_kthread_starvation(void)
pr_err("RCU grace-period kthread stack dump:\n");
sched_show_task(gpk);
if (cpu >= 0) {
-   pr_err("Stack dump where RCU grace-period 
kthread last ran:\n");
-   if (!trigger_single_cpu_backtrace(cpu))
-   dump_cpu_task(cpu);
+   if (cpu_is_offline(cpu)) {
+   pr_err("RCU GP kthread last ran on 
offline CPU %d.\n", cpu);
+   } else  {
+   pr_err("Stack dump where RCU GP kthread 
last ran:\n");
+   if (!trigger_single_cpu_backtrace(cpu))
+   dump_cpu_task(cpu);
+   }
}
wake_up_process(gpk);
}


[tip: core/rcu] torture: Allow kvm.sh --datestamp to specify subdirectories

2021-02-12 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: bc4073587067f2128b422f260fedd9fe0a8f7c4e
Gitweb:
https://git.kernel.org/tip/bc4073587067f2128b422f260fedd9fe0a8f7c4e
Author:Paul E. McKenney 
AuthorDate:Wed, 11 Nov 2020 11:09:17 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 04 Jan 2021 14:01:19 -08:00

torture: Allow kvm.sh --datestamp to specify subdirectories

Scripts like kvm-check-branches.sh group runs under a single directory
in resdir in order to allow easier retrospective analysis.  However, they
do this by letting kvm.sh create a directory as usual and then moving it
after the run.  This can be very confusing when looking at the results
while kvm-check-branches.sh is running.  This commit therefore enables
--datestamp to hand subdirectories to kvm.sh.

Signed-off-by: Paul E. McKenney 
---
 tools/testing/selftests/rcutorture/bin/kvm.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/rcutorture/bin/kvm.sh 
b/tools/testing/selftests/rcutorture/bin/kvm.sh
index 55a18a9..0a9211a 100755
--- a/tools/testing/selftests/rcutorture/bin/kvm.sh
+++ b/tools/testing/selftests/rcutorture/bin/kvm.sh
@@ -113,7 +113,7 @@ do
shift
;;
--datestamp)
-   checkarg --datestamp "(relative pathname)" "$#" "$2" '^[^/]*$' 
'^--'
+   checkarg --datestamp "(relative pathname)" "$#" "$2" 
'^[a-zA-Z0-9._-/]*$' '^--'
ds=$2
shift
;;
@@ -375,7 +375,7 @@ if ! test -e $resdir
 then
mkdir -p "$resdir" || :
 fi
-mkdir $resdir/$ds
+mkdir -p $resdir/$ds
 TORTURE_RESDIR="$resdir/$ds"; export TORTURE_RESDIR
 TORTURE_STOPFILE="$resdir/$ds/STOP"; export TORTURE_STOPFILE
 echo Results directory: $resdir/$ds


[tip: core/rcu] torture: Make kvm.sh "--dryrun sched" summarize number of builds

2021-02-12 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: eca0501a7a2036d3e63aae80cf7f2594408374ff
Gitweb:
https://git.kernel.org/tip/eca0501a7a2036d3e63aae80cf7f2594408374ff
Author:Paul E. McKenney 
AuthorDate:Sun, 08 Nov 2020 15:52:30 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 04 Jan 2021 14:01:18 -08:00

torture: Make kvm.sh "--dryrun sched" summarize number of builds

Knowing the number of builds that kvm.sh will split a run into allows
estimation of the duration of a test, give or take build duration.
This commit therefore adds a line of output to "--dryrun sched" that
gives the number of builds that will be run.  This excludes "builds"
for repeated scenarios that reuse an earlier build.

Signed-off-by: Paul E. McKenney 
---
 tools/testing/selftests/rcutorture/bin/kvm.sh | 4 
 1 file changed, 4 insertions(+)

diff --git a/tools/testing/selftests/rcutorture/bin/kvm.sh 
b/tools/testing/selftests/rcutorture/bin/kvm.sh
index 1078be1..55a18a9 100755
--- a/tools/testing/selftests/rcutorture/bin/kvm.sh
+++ b/tools/testing/selftests/rcutorture/bin/kvm.sh
@@ -536,6 +536,10 @@ then
egrep 'Start batch|Starting build\.' $T/script |
grep -v ">>" |
sed -e 's/:.*$//' -e 's/^echo //'
+   nbuilds="`grep 'Starting build\.' $T/script |
+ grep -v ">>" | sed -e 's/:.*$//' -e 's/^echo //' |
+ awk '{ print $1 }' | grep -v '\.' | wc -l`"
+   echo Total number of builds: $nbuilds
nbatches="`grep 'Start batch' $T/script | grep -v ">>" | wc -l`"
echo Total number of batches: $nbatches
exit 0


[tip: core/rcu] torture: Add config2csv.sh script to compare torture scenarios

2021-02-12 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: d4a945e260b9eb59b1a90b9d6f2b0b953e27f803
Gitweb:
https://git.kernel.org/tip/d4a945e260b9eb59b1a90b9d6f2b0b953e27f803
Author:Paul E. McKenney 
AuthorDate:Tue, 17 Nov 2020 17:38:48 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 04 Jan 2021 14:01:19 -08:00

torture: Add config2csv.sh script to compare torture scenarios

This commit adds a config2csv.sh script that converts the specified
torture-test scenarios' Kconfig options and kernel-boot parameters to
.csv format.  This allows easier comparison of scenarios when one fails
and another does not.

Signed-off-by: Paul E. McKenney 
---
 tools/testing/selftests/rcutorture/bin/config2csv.sh | 67 +++-
 1 file changed, 67 insertions(+)
 create mode 100755 tools/testing/selftests/rcutorture/bin/config2csv.sh

diff --git a/tools/testing/selftests/rcutorture/bin/config2csv.sh 
b/tools/testing/selftests/rcutorture/bin/config2csv.sh
new file mode 100755
index 000..d5a1663
--- /dev/null
+++ b/tools/testing/selftests/rcutorture/bin/config2csv.sh
@@ -0,0 +1,67 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Create a spreadsheet from torture-test Kconfig options and kernel boot
+# parameters.  Run this in the directory containing the scenario files.
+#
+# Usage: config2csv path.csv [ "scenario1 scenario2 ..." ]
+#
+# By default, this script will take the list of scenarios from the CFLIST
+# file in that directory, otherwise it will consider only the scenarios
+# specified on the command line.  It will examine each scenario's file
+# and also its .boot file, if present, and create a column in the .csv
+# output file.  Note that "CFLIST" is a synonym for all the scenarios in the
+# CFLIST file, which allows easy comparison of those scenarios with selected
+# scenarios such as BUSTED that are normally omitted from CFLIST files.
+
+csvout=${1}
+if test -z "$csvout"
+then
+   echo "Need .csv output file as first argument."
+   exit 1
+fi
+shift
+defaultconfigs="`tr '\012' ' ' < CFLIST`"
+if test "$#" -eq 0
+then
+   scenariosarg=$defaultconfigs
+else
+   scenariosarg=$*
+fi
+scenarios="`echo $scenariosarg | sed -e "s/\/$defaultconfigs/g"`"
+
+T=/tmp/config2latex.sh.$$
+trap 'rm -rf $T' 0
+mkdir $T
+
+cat << '---EOF---' >> $T/p.awk
+END{
+---EOF---
+for i in $scenarios
+do
+   echo '  s["'$i'"] = 1;' >> $T/p.awk
+   grep -v '^#' < $i | grep -v '^ *$' > $T/p
+   if test -r $i.boot
+   then
+   tr -s ' ' '\012' < $i.boot | grep -v '^#' >> $T/p
+   fi
+   sed -e 's/^[^=]*$/&=?/' < $T/p |
+   sed -e 's/^\([^=]*\)=\(.*\)$/\tp["\1:'"$i"'"] = "\2";\n\tc["\1"] = 1;/' 
>> $T/p.awk
+done
+cat << '---EOF---' >> $T/p.awk
+   ns = asorti(s, ss);
+   nc = asorti(c, cs);
+   for (j = 1; j <= ns; j++)
+   printf ",\"%s\"", ss[j];
+   printf "\n";
+   for (i = 1; i <= nc; i++) {
+   printf "\"%s\"", cs[i];
+   for (j = 1; j <= ns; j++) {
+   printf ",\"%s\"", p[cs[i] ":" ss[j]];
+   }
+   printf "\n";
+   }
+}
+---EOF---
+awk -f $T/p.awk < /dev/null > $T/p.csv
+cp $T/p.csv $csvout


[tip: core/rcu] torture: Make kvm.sh arguments accumulate

2021-02-12 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 452613719eeea36de8ab13388a704fccb9d572dd
Gitweb:
https://git.kernel.org/tip/452613719eeea36de8ab13388a704fccb9d572dd
Author:Paul E. McKenney 
AuthorDate:Fri, 20 Nov 2020 20:09:55 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 04 Jan 2021 14:01:21 -08:00

torture: Make kvm.sh arguments accumulate

Given that kvm.sh in invoked from scripts, it is only natural for
different levels of scripting to provide their own Kconfig option values,
for example.  Unfortunately, right now, the last such argument on the
command line wins.

This commit therefore makes the --bootargs, --configs, --kconfigs,
--kmake-args, and --qemu-args argument values accumulate.  For example,
where "--configs TREE01 --configs TREE02" would previously have run only
scenario TREE02, now it will run both scenarios.

Signed-off-by: Paul E. McKenney 
---
 tools/testing/selftests/rcutorture/bin/kvm.sh | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/tools/testing/selftests/rcutorture/bin/kvm.sh 
b/tools/testing/selftests/rcutorture/bin/kvm.sh
index c8356d5..6fd7ef7 100755
--- a/tools/testing/selftests/rcutorture/bin/kvm.sh
+++ b/tools/testing/selftests/rcutorture/bin/kvm.sh
@@ -85,7 +85,7 @@ do
;;
--bootargs|--bootarg)
checkarg --bootargs "(list of kernel boot arguments)" "$#" "$2" 
'.*' '^--'
-   TORTURE_BOOTARGS="$2"
+   TORTURE_BOOTARGS="$TORTURE_BOOTARGS $2"
shift
;;
--bootimage)
@@ -97,8 +97,8 @@ do
TORTURE_BUILDONLY=1
;;
--configs|--config)
-   checkarg --configs "(list of config files)" "$#" "$2" '^[^/]*$' 
'^--'
-   configs="$2"
+   checkarg --configs "(list of config files)" "$#" "$2" 
'^[^/]\+$' '^--'
+   configs="$configs $2"
shift
;;
--cpus)
@@ -162,7 +162,7 @@ do
;;
--kconfig|--kconfigs)
checkarg --kconfig "(Kconfig options)" $# "$2" 
'^CONFIG_[A-Z0-9_]\+=\([ynm]\|[0-9]\+\)\( 
CONFIG_[A-Z0-9_]\+=\([ynm]\|[0-9]\+\)\)*$' '^error$'
-   TORTURE_KCONFIG_ARG="$2"
+   TORTURE_KCONFIG_ARG="`echo "$TORTURE_KCONFIG_ARG $2" | sed -e 
's/^ *//' -e 's/ *$//'`"
shift
;;
--kasan)
@@ -173,7 +173,7 @@ do
;;
--kmake-arg|--kmake-args)
checkarg --kmake-arg "(kernel make arguments)" $# "$2" '.*' 
'^error$'
-   TORTURE_KMAKE_ARG="$2"
+   TORTURE_KMAKE_ARG="`echo "$TORTURE_KMAKE_ARG $2" | sed -e 's/^ 
*//' -e 's/ *$//'`"
shift
;;
--mac)
@@ -191,7 +191,7 @@ do
;;
--qemu-args|--qemu-arg)
checkarg --qemu-args "(qemu arguments)" $# "$2" '^-' '^error'
-   TORTURE_QEMU_ARG="$2"
+   TORTURE_QEMU_ARG="`echo "$TORTURE_QEMU_ARG $2" | sed -e 's/^ 
*//' -e 's/ *$//'`"
shift
;;
--qemu-cmd)


[tip: core/rcu] torture: Prepare for splitting qemu execution from kvm-test-1-run.sh

2021-02-12 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 315957cad445aa80e567983a43d9bb2a24a8534d
Gitweb:
https://git.kernel.org/tip/315957cad445aa80e567983a43d9bb2a24a8534d
Author:Paul E. McKenney 
AuthorDate:Tue, 17 Nov 2020 16:28:18 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 04 Jan 2021 14:01:19 -08:00

torture: Prepare for splitting qemu execution from kvm-test-1-run.sh

Distributed execution of rcutorture is eased if the qemu execution can
be split from the building of the kernel, as this allows target systems
to be used that are not set up to build kernels.  It also avoids issues
with toolchain version skew across the cluster, aside of course from
qemu and KVM version skew.

This commit therefore records needed data as comments in the qemu-cmd file
and moves recording of the starting time to just before qemu is launched.

Signed-off-by: Paul E. McKenney 
---
 tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh 
b/tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh
index 3cd03d0..4bc0e62 100755
--- a/tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh
+++ b/tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh
@@ -125,7 +125,6 @@ seconds=$4
 qemu_args=$5
 boot_args=$6
 
-kstarttime=`gawk 'BEGIN { print systime() }' < /dev/null`
 if test -z "$TORTURE_BUILDONLY"
 then
echo ' ---' `date`: Starting kernel
@@ -158,6 +157,8 @@ then
boot_args="$boot_args $TORTURE_BOOT_GDB_ARG"
 fi
 echo $QEMU $qemu_args -m $TORTURE_QEMU_MEM -kernel $KERNEL -append 
\"$qemu_append $boot_args\" $TORTURE_QEMU_GDB_ARG > $resdir/qemu-cmd
+echo "# TORTURE_SHUTDOWN_GRACE=$TORTURE_SHUTDOWN_GRACE" >> $resdir/qemu-cmd
+echo "# seconds=$seconds" >> $resdir/qemu-cmd
 
 if test -n "$TORTURE_BUILDONLY"
 then
@@ -174,6 +175,7 @@ echo 'echo $! > $resdir/qemu_pid' >> $T/qemu-cmd
 echo "NOTE: $QEMU either did not run or was interactive" > $resdir/console.log
 
 # Attempt to run qemu
+kstarttime=`gawk 'BEGIN { print systime() }' < /dev/null`
 ( . $T/qemu-cmd; wait `cat  $resdir/qemu_pid`; echo $? > $resdir/qemu-retval ) 
&
 commandcompleted=0
 if test -z "$TORTURE_KCONFIG_GDB_ARG"


[tip: core/rcu] torture: Make kvm.sh "Test Summary" date be end of test

2021-02-12 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: cb212767346ceba58c8b7bfdbbf45339b86e09c0
Gitweb:
https://git.kernel.org/tip/cb212767346ceba58c8b7bfdbbf45339b86e09c0
Author:Paul E. McKenney 
AuthorDate:Thu, 19 Nov 2020 15:23:04 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 04 Jan 2021 14:01:20 -08:00

torture: Make kvm.sh "Test Summary" date be end of test

Currently, the "date" command producing the output on the kvm.sh "Test
Summary" line is executed at the beginning of the test, which produces a
date that is less than helpful to someone wanting to know the duration
of the test.  This commit therefore defers this command's execution to
the end of the test.

Signed-off-by: Paul E. McKenney 
---
 tools/testing/selftests/rcutorture/bin/kvm.sh | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/rcutorture/bin/kvm.sh 
b/tools/testing/selftests/rcutorture/bin/kvm.sh
index 0a9211a..c8356d5 100755
--- a/tools/testing/selftests/rcutorture/bin/kvm.sh
+++ b/tools/testing/selftests/rcutorture/bin/kvm.sh
@@ -517,10 +517,12 @@ END {
dump(first, i, batchnum);
 }' >> $T/script
 
-cat << ___EOF___ >> $T/script
+cat << '___EOF___' >> $T/script
 echo
 echo
 echo " --- `date` Test summary:"
+___EOF___
+cat << ___EOF___ >> $T/script
 echo Results directory: $resdir/$ds
 kcsan-collapse.sh $resdir/$ds
 kvm-recheck.sh $resdir/$ds


[tip: core/rcu] torture: Make kvm.sh return failure upon build failure

2021-02-12 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 23239fc075d60a942101227c42353b5ced804269
Gitweb:
https://git.kernel.org/tip/23239fc075d60a942101227c42353b5ced804269
Author:Paul E. McKenney 
AuthorDate:Mon, 23 Nov 2020 10:41:57 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 04 Jan 2021 14:01:22 -08:00

torture: Make kvm.sh return failure upon build failure

The kvm.sh script uses kvm-find-errors.sh to evaluate whether or not
a build failed.  Unfortunately, kvm-find-errors.sh returns success if
there are no failed runs (including when there are no runs at all) even if
there are build failures.  This commit therefore makes kvm-find-errors.sh
return failure in response to build failures.

Signed-off-by: Paul E. McKenney 
---
 tools/testing/selftests/rcutorture/bin/kvm-find-errors.sh | 8 ++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/rcutorture/bin/kvm-find-errors.sh 
b/tools/testing/selftests/rcutorture/bin/kvm-find-errors.sh
index 6f50722..be26598 100755
--- a/tools/testing/selftests/rcutorture/bin/kvm-find-errors.sh
+++ b/tools/testing/selftests/rcutorture/bin/kvm-find-errors.sh
@@ -39,6 +39,7 @@ done
 if test -n "$files"
 then
$editor $files
+   editorret=1
 else
echo No build errors.
 fi
@@ -62,5 +63,10 @@ then
exit 1
 else
echo No errors in console logs.
-   exit 0
+   if test -n "$editorret"
+   then
+   exit $editorret
+   else
+   exit 0
+   fi
 fi


[tip: core/rcu] torture: Print run duration at end of kvm.sh execution

2021-02-12 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 0bcca18348cfde8e59b77cdf6f3e278289a16e67
Gitweb:
https://git.kernel.org/tip/0bcca18348cfde8e59b77cdf6f3e278289a16e67
Author:Paul E. McKenney 
AuthorDate:Sun, 22 Nov 2020 09:55:34 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 04 Jan 2021 14:01:21 -08:00

torture: Print run duration at end of kvm.sh execution

Yes, you can mentally subtract the timestamps, but this commit makes
the computer do this work.

Signed-off-by: Paul E. McKenney 
---
 tools/testing/selftests/rcutorture/bin/functions.sh | 33 -
 tools/testing/selftests/rcutorture/bin/kvm.sh   |  6 ++-
 2 files changed, 39 insertions(+)

diff --git a/tools/testing/selftests/rcutorture/bin/functions.sh 
b/tools/testing/selftests/rcutorture/bin/functions.sh
index fef8b4b..97c3a17 100644
--- a/tools/testing/selftests/rcutorture/bin/functions.sh
+++ b/tools/testing/selftests/rcutorture/bin/functions.sh
@@ -108,6 +108,39 @@ configfrag_hotplug_cpu () {
grep -q '^CONFIG_HOTPLUG_CPU=y$' "$1"
 }
 
+# get_starttime
+#
+# Returns a cookie identifying the current time.
+get_starttime () {
+   awk 'BEGIN { print systime() }' < /dev/null
+}
+
+# get_starttime_duration starttime
+#
+# Given the return value from get_starttime, compute a human-readable
+# string denoting the time since get_starttime.
+get_starttime_duration () {
+   awk -v starttime=$1 '
+   BEGIN {
+   ts = systime() - starttime; 
+   tm = int(ts / 60);
+   th = int(ts / 3600);
+   td = int(ts / 86400);
+   d = td;
+   h = th - td * 24;
+   m = tm - th * 60;
+   s = ts - tm * 60;
+   if (d >= 1)
+   printf "%dd %d:%02d:%02d\n", d, h, m, s
+   else if (h >= 1)
+   printf "%d:%02d:%02d\n", h, m, s
+   else if (m >= 1)
+   printf "%d:%02d.0\n", m, s
+   else
+   print s " seconds"
+   }' < /dev/null
+}
+
 # identify_boot_image qemu-cmd
 #
 # Returns the relative path to the kernel build image.  This will be
diff --git a/tools/testing/selftests/rcutorture/bin/kvm.sh 
b/tools/testing/selftests/rcutorture/bin/kvm.sh
index 6fd7ef7..6f21268 100755
--- a/tools/testing/selftests/rcutorture/bin/kvm.sh
+++ b/tools/testing/selftests/rcutorture/bin/kvm.sh
@@ -47,6 +47,9 @@ cpus=0
 ds=`date +%Y.%m.%d-%H.%M.%S`
 jitter="-1"
 
+startdate="`date`"
+starttime="`get_starttime`"
+
 usage () {
echo "Usage: $scriptname optional arguments:"
echo "   --allcpus"
@@ -548,6 +551,9 @@ then
 else
# Not a dryrun, so run the script.
sh $T/script
+   ret=$?
+   echo " --- Done at `date` (`get_starttime_duration $starttime`)"
+   exit $ret
 fi
 
 # Tracing: 
trace_event=rcu:rcu_grace_period,rcu:rcu_future_grace_period,rcu:rcu_grace_period_init,rcu:rcu_nocb_wake,rcu:rcu_preempt_task,rcu:rcu_unlock_preempted_task,rcu:rcu_quiescent_state_report,rcu:rcu_fqs,rcu:rcu_callback,rcu:rcu_kfree_callback,rcu:rcu_batch_start,rcu:rcu_invoke_callback,rcu:rcu_invoke_kfree_callback,rcu:rcu_batch_end,rcu:rcu_torture_read,rcu:rcu_barrier


[tip: core/rcu] torture: Make kvm.sh include --kconfig arguments in CPU calculation

2021-02-12 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 22bf64cc94832a3b047a1412a4ad0f7d9bd6cd8b
Gitweb:
https://git.kernel.org/tip/22bf64cc94832a3b047a1412a4ad0f7d9bd6cd8b
Author:Paul E. McKenney 
AuthorDate:Tue, 24 Nov 2020 13:12:13 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 04 Jan 2021 14:01:22 -08:00

torture: Make kvm.sh include --kconfig arguments in CPU calculation

Currently, passing something like "--kconfig CONFIG_NR_CPUS=2" to kvm.sh
has no effect on scenario scheduling.  For scenarios that do not specify
the number of CPUs, this can result in kvm.sh wastefully scheduling only
one scenario at a time even when the --kconfig argument would allow
a number to be run concurrently.  This commit therefore makes kvm.sh
consider the --kconfig arguments when scheduling scenarios across the
available CPUs.

Signed-off-by: Paul E. McKenney 
---
 tools/testing/selftests/rcutorture/bin/kvm.sh | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/rcutorture/bin/kvm.sh 
b/tools/testing/selftests/rcutorture/bin/kvm.sh
index 6f21268..472929c 100755
--- a/tools/testing/selftests/rcutorture/bin/kvm.sh
+++ b/tools/testing/selftests/rcutorture/bin/kvm.sh
@@ -290,7 +290,13 @@ for CF1 in $configs_derep
 do
if test -f "$CONFIGFRAG/$CF1"
then
-   cpu_count=`configNR_CPUS.sh $CONFIGFRAG/$CF1`
+   if echo "$TORTURE_KCONFIG_ARG" | grep -q '\ $T/KCONFIG_ARG
+   cpu_count=`configNR_CPUS.sh $T/KCONFIG_ARG`
+   else
+   cpu_count=`configNR_CPUS.sh $CONFIGFRAG/$CF1`
+   fi
cpu_count=`configfrag_boot_cpus "$TORTURE_BOOTARGS" 
"$CONFIGFRAG/$CF1" "$cpu_count"`
cpu_count=`configfrag_boot_maxcpus "$TORTURE_BOOTARGS" 
"$CONFIGFRAG/$CF1" "$cpu_count"`
echo $CF1 $cpu_count >> $T/cfgcpu


[tip: core/rcu] torture: Add kvm.sh test summary to end of log file

2021-02-12 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 0beb394878a46bad6358f81dde2ef4aa0ef68af5
Gitweb:
https://git.kernel.org/tip/0beb394878a46bad6358f81dde2ef4aa0ef68af5
Author:Paul E. McKenney 
AuthorDate:Thu, 26 Nov 2020 15:27:57 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 04 Jan 2021 14:01:22 -08:00

torture: Add kvm.sh test summary to end of log file

This commit adds the test summary to the end of the log in the top-level
directory containing the kvm.sh test artifacts.  While in the area, it adds
the kvm.sh exit code to this test summary.

Signed-off-by: Paul E. McKenney 
---
 tools/testing/selftests/rcutorture/bin/kvm.sh | 19 ++
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/tools/testing/selftests/rcutorture/bin/kvm.sh 
b/tools/testing/selftests/rcutorture/bin/kvm.sh
index 472929c..667896f 100755
--- a/tools/testing/selftests/rcutorture/bin/kvm.sh
+++ b/tools/testing/selftests/rcutorture/bin/kvm.sh
@@ -527,15 +527,18 @@ END {
 }' >> $T/script
 
 cat << '___EOF___' >> $T/script
-echo
-echo
-echo " --- `date` Test summary:"
+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
-kcsan-collapse.sh $resdir/$ds
-kvm-recheck.sh $resdir/$ds
+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
 
 if test "$dryrun" = script
 then
@@ -556,9 +559,9 @@ then
exit 0
 else
# Not a dryrun, so run the script.
-   sh $T/script
+   bash $T/script
ret=$?
-   echo " --- Done at `date` (`get_starttime_duration $starttime`)"
+   echo " --- Done at `date` (`get_starttime_duration $starttime`) 
exitcode $ret" | tee -a $resdir/$ds/log
exit $ret
 fi
 


[tip: core/rcu] torture: Stop hanging on panic

2021-02-12 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: f716348f29d30e8ef3a1ceed3fea19490aba4fe4
Gitweb:
https://git.kernel.org/tip/f716348f29d30e8ef3a1ceed3fea19490aba4fe4
Author:Paul E. McKenney 
AuthorDate:Thu, 03 Dec 2020 13:27:42 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 04 Jan 2021 14:01:23 -08:00

torture: Stop hanging on panic

By default, the "panic" kernel parameter is zero, which causes the kernel
to loop indefinitely after a panic().  The rcutorture scripting will
eventually kill the corresponding qemu process, but only after waiting
for the full run duration plus a few minutes.  This works, but delays
notifying the developer of the failure.

This commit therefore causes the rcutorture scripting to pass the
"panic=-1" kernel parameter, which caused the kernel to instead
unceremoniously shut down immediately.  This in turn causes qemu to
terminate, so that if all of the runs in a given batch panic(), the
rcutorture scripting can immediately proceed to the next batch.

Signed-off-by: Paul E. McKenney 
---
 tools/testing/selftests/rcutorture/bin/functions.sh | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/testing/selftests/rcutorture/bin/functions.sh 
b/tools/testing/selftests/rcutorture/bin/functions.sh
index 97c3a17..c35ba24 100644
--- a/tools/testing/selftests/rcutorture/bin/functions.sh
+++ b/tools/testing/selftests/rcutorture/bin/functions.sh
@@ -203,6 +203,7 @@ identify_qemu () {
 # and the TORTURE_QEMU_INTERACTIVE environment variable.
 identify_qemu_append () {
echo debug_boot_weak_hash
+   echo panic=-1
local console=ttyS0
case "$1" in
qemu-system-x86_64|qemu-system-i386)


[tip: core/rcu] torture: Add --dryrun batches to help schedule a distributed run

2021-02-12 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 755cf0afc16477bf55c837a35bf3b15461850194
Gitweb:
https://git.kernel.org/tip/755cf0afc16477bf55c837a35bf3b15461850194
Author:Paul E. McKenney 
AuthorDate:Fri, 11 Dec 2020 16:26:50 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 04 Jan 2021 14:01:23 -08:00

torture: Add --dryrun batches to help schedule a distributed run

When all of the remote systems have the same number of CPUs, one
approach is to use one "--buildonly" run and one "--dryrun sched" run,
and then distributing the batches out one per remote system.  However,
the output of "--dryrun sched" is not made for parsing, so this commit
adds a "--dryrun batches" that provides the same information in easily
parsed form.

Signed-off-by: Paul E. McKenney 
---
 tools/testing/selftests/rcutorture/bin/kvm.sh | 22 +-
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/tools/testing/selftests/rcutorture/bin/kvm.sh 
b/tools/testing/selftests/rcutorture/bin/kvm.sh
index 667896f..6b90036 100755
--- a/tools/testing/selftests/rcutorture/bin/kvm.sh
+++ b/tools/testing/selftests/rcutorture/bin/kvm.sh
@@ -60,7 +60,7 @@ usage () {
echo "   --cpus N"
echo "   --datestamp string"
echo "   --defconfig string"
-   echo "   --dryrun sched|script"
+   echo "   --dryrun batches|sched|script"
echo "   --duration minutes | s | h | d"
echo "   --gdb"
echo "   --help"
@@ -126,7 +126,7 @@ do
shift
;;
--dryrun)
-   checkarg --dryrun "sched|script" $# "$2" 'sched\|script' '^--'
+   checkarg --dryrun "batches|sched|script" $# "$2" 
'batches\|sched\|script' '^--'
dryrun=$2
shift
;;
@@ -235,7 +235,7 @@ do
shift
 done
 
-if test -z "$TORTURE_INITRD" || 
tools/testing/selftests/rcutorture/bin/mkinitrd.sh
+if test -n "$dryrun" || test -z "$TORTURE_INITRD" || 
tools/testing/selftests/rcutorture/bin/mkinitrd.sh
 then
:
 else
@@ -547,8 +547,7 @@ then
 elif test "$dryrun" = sched
 then
# Extract the test run schedule from the script.
-   egrep 'Start batch|Starting build\.' $T/script |
-   grep -v ">>" |
+   egrep 'Start batch|Starting build\.' $T/script | grep -v ">>" |
sed -e 's/:.*$//' -e 's/^echo //'
nbuilds="`grep 'Starting build\.' $T/script |
  grep -v ">>" | sed -e 's/:.*$//' -e 's/^echo //' |
@@ -557,6 +556,19 @@ then
nbatches="`grep 'Start batch' $T/script | grep -v ">>" | wc -l`"
echo Total number of batches: $nbatches
exit 0
+elif test "$dryrun" = batches
+then
+   # Extract the tests and their batches from the script.
+   egrep 'Start batch|Starting build\.' $T/script | grep -v ">>" |
+   sed -e 's/:.*$//' -e 's/^echo //' -e 's/-ovf//' |
+   awk '
+   /^Start/ {
+   batchno = $3;
+   next;
+   }
+   {
+   print batchno, $1, $2
+   }'
 else
# Not a dryrun, so run the script.
bash $T/script


[tip: core/rcu] torture: s/STOP/STOP.1/ to avoid scenario collision

2021-02-12 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: c821f855f625f763a87c49f413aa4f60974b5071
Gitweb:
https://git.kernel.org/tip/c821f855f625f763a87c49f413aa4f60974b5071
Author:Paul E. McKenney 
AuthorDate:Fri, 11 Dec 2020 16:59:40 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 04 Jan 2021 14:01:24 -08:00

torture: s/STOP/STOP.1/ to avoid scenario collision

This commit changes the "STOP" file that is used to cleanly halt a running
rcutorture run to "STOP.1" because no scenario directory will ever end
with ".1".  If there really was a scenario named "STOP", its directories
would instead be named "STOP", "STOP.2", "STOP.3", and so on.  While in
the area, the commit also changes the kernel-run-time checks for this
file to look directly in the directory above $resdir, thus avoiding the
need to pass the TORTURE_STOPFILE environment variable to remote systems.

While in the area, move the STOP.1 file to the top-level directory
covering all of the scenarios.

Signed-off-by: Paul E. McKenney 
---
 tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh | 8 
 tools/testing/selftests/rcutorture/bin/kvm.sh| 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh 
b/tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh
index 4bc0e62..536d103 100755
--- a/tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh
+++ b/tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh
@@ -211,7 +211,7 @@ do
if test -n "$TORTURE_KCONFIG_GDB_ARG"
then
:
-   elif test $kruntime -ge $seconds || test -f "$TORTURE_STOPFILE"
+   elif test $kruntime -ge $seconds || test -f "$resdir/../STOP.1"
then
break;
fi
@@ -254,16 +254,16 @@ then
 fi
 if test $commandcompleted -eq 0 -a -n "$qemu_pid"
 then
-   if ! test -f "$TORTURE_STOPFILE"
+   if ! test -f "$resdir/../STOP.1"
then
echo Grace period for qemu job at pid $qemu_pid
fi
oldline="`tail $resdir/console.log`"
while :
do
-   if test -f "$TORTURE_STOPFILE"
+   if test -f "$resdir/../STOP.1"
then
-   echo "PID $qemu_pid killed due to run STOP request" >> 
$resdir/Warnings 2>&1
+   echo "PID $qemu_pid killed due to run STOP.1 request" 
>> $resdir/Warnings 2>&1
kill -KILL $qemu_pid
break
fi
diff --git a/tools/testing/selftests/rcutorture/bin/kvm.sh 
b/tools/testing/selftests/rcutorture/bin/kvm.sh
index 6b90036..6051868 100755
--- a/tools/testing/selftests/rcutorture/bin/kvm.sh
+++ b/tools/testing/selftests/rcutorture/bin/kvm.sh
@@ -386,7 +386,7 @@ then
 fi
 mkdir -p $resdir/$ds
 TORTURE_RESDIR="$resdir/$ds"; export TORTURE_RESDIR
-TORTURE_STOPFILE="$resdir/$ds/STOP"; export TORTURE_STOPFILE
+TORTURE_STOPFILE="$resdir/$ds/STOP.1"; export TORTURE_STOPFILE
 echo Results directory: $resdir/$ds
 echo $scriptname $args
 touch $resdir/$ds/log


[tip: core/rcu] torture: Remove "Failed to add ttynull console" false positive

2021-02-12 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 546eee2d931b3d76357a9c813778203001375fe1
Gitweb:
https://git.kernel.org/tip/546eee2d931b3d76357a9c813778203001375fe1
Author:Paul E. McKenney 
AuthorDate:Wed, 23 Dec 2020 10:35:39 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 04 Jan 2021 14:01:25 -08:00

torture: Remove "Failed to add ttynull console" false positive

Commit 757055ae8ded ("init/console: Use ttynull as a fallback when
there is no console") results in the string "Warning: Failed to add
ttynull console. No stdin, stdout, and stderr for the init process!"
appearing on the console, which the rcutorture scripting interprets as
a warning, which causes every rcutorture run to be flagged.  However,
the rcutorture init process never attempts to do any I/O, and thus does
not care that it has no stdin, stdout, or stderr.

This commit therefore causes the rcutorture scripting to ignore this
message.

Signed-off-by: Paul E. McKenney 
---
 tools/testing/selftests/rcutorture/bin/console-badness.sh | 1 +
 tools/testing/selftests/rcutorture/bin/parse-console.sh   | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/rcutorture/bin/console-badness.sh 
b/tools/testing/selftests/rcutorture/bin/console-badness.sh
index 80ae7f0..e6a132d 100755
--- a/tools/testing/selftests/rcutorture/bin/console-badness.sh
+++ b/tools/testing/selftests/rcutorture/bin/console-badness.sh
@@ -14,4 +14,5 @@ egrep 'Badness|WARNING:|Warn|BUG|===|Call 
Trace:|Oops:|detected stalls o
 grep -v 'ODEBUG: ' |
 grep -v 'This means that this is a DEBUG kernel and it is' |
 grep -v 'Warning: unable to open an initial console' |
+grep -v 'Warning: Failed to add ttynull console. No stdin, stdout, and 
stderr.*the init process!' |
 grep -v 'NOHZ tick-stop error: Non-RCU local softirq work is pending, handler'
diff --git a/tools/testing/selftests/rcutorture/bin/parse-console.sh 
b/tools/testing/selftests/rcutorture/bin/parse-console.sh
index 263b1be..9f624bd 100755
--- a/tools/testing/selftests/rcutorture/bin/parse-console.sh
+++ b/tools/testing/selftests/rcutorture/bin/parse-console.sh
@@ -128,7 +128,7 @@ then
then
summary="$summary  Badness: $n_badness"
fi
-   n_warn=`grep -v 'Warning: unable to open an initial console' $file | 
egrep -c 'WARNING:|Warn'`
+   n_warn=`grep -v 'Warning: unable to open an initial console' $file | 
grep -v 'Warning: Failed to add ttynull console. No stdin, stdout, and stderr 
for the init process' | egrep -c 'WARNING:|Warn'`
if test "$n_warn" -ne 0
then
summary="$summary  Warnings: $n_warn"


[tip: core/rcu] torture: Simplify exit-code plumbing for kvm-recheck.sh and kvm-find-errors.sh

2021-02-12 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 365dc5cb62c8714e27554e44464f6e0e9c1fdbdf
Gitweb:
https://git.kernel.org/tip/365dc5cb62c8714e27554e44464f6e0e9c1fdbdf
Author:Paul E. McKenney 
AuthorDate:Sun, 20 Dec 2020 16:52:29 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 04 Jan 2021 14:01:24 -08:00

torture: Simplify exit-code plumbing for kvm-recheck.sh and kvm-find-errors.sh

This commit simplifies exit-code plumbing.  It makes kvm-recheck.sh return
the value 1 for a build error and 2 for a runtime error.  It also makes
kvm-find-errors.sh avoid checking runtime files for --build-only runs.

Signed-off-by: Paul E. McKenney 
---
 tools/testing/selftests/rcutorture/bin/kvm-find-errors.sh | 1 +
 tools/testing/selftests/rcutorture/bin/kvm-recheck.sh | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/rcutorture/bin/kvm-find-errors.sh 
b/tools/testing/selftests/rcutorture/bin/kvm-find-errors.sh
index be26598..0670841 100755
--- a/tools/testing/selftests/rcutorture/bin/kvm-find-errors.sh
+++ b/tools/testing/selftests/rcutorture/bin/kvm-find-errors.sh
@@ -46,6 +46,7 @@ fi
 if grep -q -e "--buildonly" < ${rundir}/log
 then
echo Build-only run, no console logs to check.
+   exit $editorret
 fi
 
 # Find console logs with errors
diff --git a/tools/testing/selftests/rcutorture/bin/kvm-recheck.sh 
b/tools/testing/selftests/rcutorture/bin/kvm-recheck.sh
index 840a467..47cf4db 100755
--- a/tools/testing/selftests/rcutorture/bin/kvm-recheck.sh
+++ b/tools/testing/selftests/rcutorture/bin/kvm-recheck.sh
@@ -87,15 +87,16 @@ do
fi
 done
 EDITOR=echo kvm-find-errors.sh "${@: -1}" > $T 2>&1
-ret=$?
 builderrors="`tr ' ' '\012' < $T | grep -c '/Make.out.diags'`"
 if test "$builderrors" -gt 0
 then
echo $builderrors runs with build errors.
+   ret=1
 fi
 runerrors="`tr ' ' '\012' < $T | grep -c '/console.log.diags'`"
 if test "$runerrors" -gt 0
 then
echo $runerrors runs with runtime errors.
+   ret=2
 fi
 exit $ret


[tip: core/rcu] torture: Allow standalone kvm-recheck.sh run detect --trust-make

2021-02-12 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: b79b0b67791316e6ca0502bd0f2ecd7018d6d9e8
Gitweb:
https://git.kernel.org/tip/b79b0b67791316e6ca0502bd0f2ecd7018d6d9e8
Author:Paul E. McKenney 
AuthorDate:Wed, 23 Dec 2020 16:00:27 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 04 Jan 2021 14:01:25 -08:00

torture: Allow standalone kvm-recheck.sh run detect --trust-make

Normally, kvm-recheck.sh is run from kvm.sh, which provides the
TORTURE_TRUST_MAKE environment variable that, if a non-empty string,
indicates that the --trust-make command-line parameter has been passed
to kvm.sh.  If there was no --trust-make, kvm-recheck.sh insists
that the Make.out file contain at least one "CC" command.  Thus, when
kvm-recheck.sh is run standalone to evaluate a prior --trust-make run,
it will incorrectly insist that a proper kernel build did not happen.

This commit therefore causes kvm-recheck.sh to also search the "log"
file in the top-level results directory for the string "--trust-make".

Signed-off-by: Paul E. McKenney 
---
 tools/testing/selftests/rcutorture/bin/parse-build.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/rcutorture/bin/parse-build.sh 
b/tools/testing/selftests/rcutorture/bin/parse-build.sh
index 09155c1..9313e50 100755
--- a/tools/testing/selftests/rcutorture/bin/parse-build.sh
+++ b/tools/testing/selftests/rcutorture/bin/parse-build.sh
@@ -21,7 +21,7 @@ mkdir $T
 
 . functions.sh
 
-if grep -q CC < $F || test -n "$TORTURE_TRUST_MAKE"
+if grep -q CC < $F || test -n "$TORTURE_TRUST_MAKE" || grep -qe --trust-make < 
`dirname $F`/../log
 then
:
 else


[tip: core/rcu] rcu: Add lockdep_assert_irqs_disabled() to rcu_sched_clock_irq() and callees

2021-02-12 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: a649d25dcc671a33b9cc3176411920fdc5fbd98e
Gitweb:
https://git.kernel.org/tip/a649d25dcc671a33b9cc3176411920fdc5fbd98e
Author:Paul E. McKenney 
AuthorDate:Thu, 19 Nov 2020 10:13:06 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 04 Jan 2021 15:54:49 -08:00

rcu: Add lockdep_assert_irqs_disabled() to rcu_sched_clock_irq() and callees

This commit adds a number of lockdep_assert_irqs_disabled() calls
to rcu_sched_clock_irq() and a number of the functions that it calls.
The point of this is to help track down a situation where lockdep appears
to be insisting that interrupts are enabled within these functions, which
should only ever be invoked from the scheduling-clock interrupt handler.

Link: https://lore.kernel.org/lkml/2020133813.ga81...@elver.google.com/
Signed-off-by: Paul E. McKenney 
---
 kernel/rcu/tree.c| 4 
 kernel/rcu/tree_plugin.h | 1 +
 kernel/rcu/tree_stall.h  | 8 
 3 files changed, 13 insertions(+)

diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
index bd04b09..f70634f 100644
--- a/kernel/rcu/tree.c
+++ b/kernel/rcu/tree.c
@@ -2553,6 +2553,7 @@ static void rcu_do_batch(struct rcu_data *rdp)
 void rcu_sched_clock_irq(int user)
 {
trace_rcu_utilization(TPS("Start scheduler-tick"));
+   lockdep_assert_irqs_disabled();
raw_cpu_inc(rcu_data.ticks_this_gp);
/* The load-acquire pairs with the store-release setting to true. */
if (smp_load_acquire(this_cpu_ptr(_data.rcu_urgent_qs))) {
@@ -2566,6 +2567,7 @@ void rcu_sched_clock_irq(int user)
rcu_flavor_sched_clock_irq(user);
if (rcu_pending(user))
invoke_rcu_core();
+   lockdep_assert_irqs_disabled();
 
trace_rcu_utilization(TPS("End scheduler-tick"));
 }
@@ -3690,6 +3692,8 @@ static int rcu_pending(int user)
struct rcu_data *rdp = this_cpu_ptr(_data);
struct rcu_node *rnp = rdp->mynode;
 
+   lockdep_assert_irqs_disabled();
+
/* Check for CPU stalls, if enabled. */
check_cpu_stall(rdp);
 
diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
index fd8a52e..cb76e70 100644
--- a/kernel/rcu/tree_plugin.h
+++ b/kernel/rcu/tree_plugin.h
@@ -682,6 +682,7 @@ static void rcu_flavor_sched_clock_irq(int user)
 {
struct task_struct *t = current;
 
+   lockdep_assert_irqs_disabled();
if (user || rcu_is_cpu_rrupt_from_idle()) {
rcu_note_voluntary_context_switch(current);
}
diff --git a/kernel/rcu/tree_stall.h b/kernel/rcu/tree_stall.h
index ca21d28..4024dcc 100644
--- a/kernel/rcu/tree_stall.h
+++ b/kernel/rcu/tree_stall.h
@@ -260,6 +260,7 @@ static int rcu_print_task_stall(struct rcu_node *rnp, 
unsigned long flags)
struct task_struct *t;
struct task_struct *ts[8];
 
+   lockdep_assert_irqs_disabled();
if (!rcu_preempt_blocked_readers_cgp(rnp))
return 0;
pr_err("\tTasks blocked on level-%d rcu_node (CPUs %d-%d):",
@@ -284,6 +285,7 @@ static int rcu_print_task_stall(struct rcu_node *rnp, 
unsigned long flags)
".q"[rscr.rs.b.need_qs],
".e"[rscr.rs.b.exp_hint],
".l"[rscr.on_blkd_list]);
+   lockdep_assert_irqs_disabled();
put_task_struct(t);
ndetected++;
}
@@ -472,6 +474,8 @@ static void print_other_cpu_stall(unsigned long gp_seq, 
unsigned long gps)
struct rcu_node *rnp;
long totqlen = 0;
 
+   lockdep_assert_irqs_disabled();
+
/* Kick and suppress, if so configured. */
rcu_stall_kick_kthreads();
if (rcu_stall_is_suppressed())
@@ -493,6 +497,7 @@ static void print_other_cpu_stall(unsigned long gp_seq, 
unsigned long gps)
}
}
ndetected += rcu_print_task_stall(rnp, flags); // Releases 
rnp->lock.
+   lockdep_assert_irqs_disabled();
}
 
for_each_possible_cpu(cpu)
@@ -538,6 +543,8 @@ static void print_cpu_stall(unsigned long gps)
struct rcu_node *rnp = rcu_get_root();
long totqlen = 0;
 
+   lockdep_assert_irqs_disabled();
+
/* Kick and suppress, if so configured. */
rcu_stall_kick_kthreads();
if (rcu_stall_is_suppressed())
@@ -592,6 +599,7 @@ static void check_cpu_stall(struct rcu_data *rdp)
unsigned long js;
struct rcu_node *rnp;
 
+   lockdep_assert_irqs_disabled();
if ((rcu_stall_is_suppressed() && !READ_ONCE(rcu_kick_kthreads)) ||
!rcu_gp_in_progress())
return;


[tip: core/rcu] rcu: Add lockdep_assert_irqs_disabled() to raw_spin_unlock_rcu_node() macros

2021-02-12 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 7dffe01765d9309b8bd5505503933ec0ec53d192
Gitweb:
https://git.kernel.org/tip/7dffe01765d9309b8bd5505503933ec0ec53d192
Author:Paul E. McKenney 
AuthorDate:Thu, 19 Nov 2020 13:30:33 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 04 Jan 2021 15:54:49 -08:00

rcu: Add lockdep_assert_irqs_disabled() to raw_spin_unlock_rcu_node() macros

This commit adds a lockdep_assert_irqs_disabled() call to the
helper macros that release the rcu_node structure's ->lock, namely
to raw_spin_unlock_rcu_node(), raw_spin_unlock_irq_rcu_node() and
raw_spin_unlock_irqrestore_rcu_node().  The point of this is to help track
down a situation where lockdep appears to be insisting that interrupts
are enabled while holding an rcu_node structure's ->lock.

Link: https://lore.kernel.org/lkml/2020133813.ga81...@elver.google.com/
Signed-off-by: Paul E. McKenney 
---
 kernel/rcu/rcu.h | 16 +---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/kernel/rcu/rcu.h b/kernel/rcu/rcu.h
index e01cba5..839f5be 100644
--- a/kernel/rcu/rcu.h
+++ b/kernel/rcu/rcu.h
@@ -378,7 +378,11 @@ do {   
\
smp_mb__after_unlock_lock();\
 } while (0)
 
-#define raw_spin_unlock_rcu_node(p) raw_spin_unlock(_PRIVATE(p, lock))
+#define raw_spin_unlock_rcu_node(p)\
+do {   \
+   lockdep_assert_irqs_disabled(); \
+   raw_spin_unlock(_PRIVATE(p, lock));  \
+} while (0)
 
 #define raw_spin_lock_irq_rcu_node(p)  \
 do {   \
@@ -387,7 +391,10 @@ do {   
\
 } while (0)
 
 #define raw_spin_unlock_irq_rcu_node(p)
\
-   raw_spin_unlock_irq(_PRIVATE(p, lock))
+do {   \
+   lockdep_assert_irqs_disabled(); \
+   raw_spin_unlock_irq(_PRIVATE(p, lock));  \
+} while (0)
 
 #define raw_spin_lock_irqsave_rcu_node(p, flags)   \
 do {   \
@@ -396,7 +403,10 @@ do {   
\
 } while (0)
 
 #define raw_spin_unlock_irqrestore_rcu_node(p, flags)  \
-   raw_spin_unlock_irqrestore(_PRIVATE(p, lock), flags)
+do {   \
+   lockdep_assert_irqs_disabled(); \
+   raw_spin_unlock_irqrestore(_PRIVATE(p, lock), flags);\
+} while (0)
 
 #define raw_spin_trylock_rcu_node(p)   \
 ({ \


[tip: core/rcu] rcu: Make TASKS_TRACE_RCU select IRQ_WORK

2021-02-12 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: c26165efac41bce0c7764262b21f5897e771f34f
Gitweb:
https://git.kernel.org/tip/c26165efac41bce0c7764262b21f5897e771f34f
Author:Paul E. McKenney 
AuthorDate:Mon, 21 Dec 2020 21:00:18 -08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 04 Jan 2021 15:54:49 -08:00

rcu: Make TASKS_TRACE_RCU select IRQ_WORK

Tasks Trace RCU uses irq_work_queue() to safely awaken its grace-period
kthread, so this commit therefore causes the TASKS_TRACE_RCU Kconfig
option select the IRQ_WORK Kconfig option.

Reported-by: kernel test robot 
Acked-by: Randy Dunlap  # build-tested
Signed-off-by: Paul E. McKenney 
---
 kernel/rcu/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/kernel/rcu/Kconfig b/kernel/rcu/Kconfig
index b71e21f..84dfa8d 100644
--- a/kernel/rcu/Kconfig
+++ b/kernel/rcu/Kconfig
@@ -95,6 +95,7 @@ config TASKS_RUDE_RCU
 
 config TASKS_TRACE_RCU
def_bool 0
+   select IRQ_WORK
help
  This option enables a task-based RCU implementation that uses
  explicit rcu_read_lock_trace() read-side markers, and allows


[tip: core/rcu] torture: Do Kconfig analysis only once per scenario

2021-02-12 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 1120281713a5c8d9caffaa49db11fd0a25e34ef0
Gitweb:
https://git.kernel.org/tip/1120281713a5c8d9caffaa49db11fd0a25e34ef0
Author:Paul E. McKenney 
AuthorDate:Thu, 24 Dec 2020 15:28:14 -08:00
Committer: Paul E. McKenney 
CommitterDate: Tue, 05 Jan 2021 11:33:20 -08:00

torture: Do Kconfig analysis only once per scenario

Currently, if a scenario is repeated as in "--configs '4*TREE01'",
the Kconfig analysis is performed for each occurrance (four times in
this example) and each analysis places the exact same data into the
exact same files.  This is not really an issue in this repetition-four
example, but it can needlessly consume tens of seconds of wallclock time
for something like "--config '128*TINY01'".

This commit therefore does Kconfig analysis only once per set of
repeats of a given scenario, courtesy of the "sort -u" command and an
automatically generated awk script.

While in the area, this commit also wordsmiths a comment.

Signed-off-by: Paul E. McKenney 
---
 tools/testing/selftests/rcutorture/bin/kvm.sh | 22 --
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/tools/testing/selftests/rcutorture/bin/kvm.sh 
b/tools/testing/selftests/rcutorture/bin/kvm.sh
index 6051868..8d3c99b 100755
--- a/tools/testing/selftests/rcutorture/bin/kvm.sh
+++ b/tools/testing/selftests/rcutorture/bin/kvm.sh
@@ -286,7 +286,8 @@ then
exit 1
fi
 fi
-for CF1 in $configs_derep
+echo 'BEGIN {' > $T/cfgcpu.awk
+for CF1 in `echo $configs_derep | tr -s ' ' '\012' | sort -u`
 do
if test -f "$CONFIGFRAG/$CF1"
then
@@ -299,12 +300,20 @@ do
fi
cpu_count=`configfrag_boot_cpus "$TORTURE_BOOTARGS" 
"$CONFIGFRAG/$CF1" "$cpu_count"`
cpu_count=`configfrag_boot_maxcpus "$TORTURE_BOOTARGS" 
"$CONFIGFRAG/$CF1" "$cpu_count"`
-   echo $CF1 $cpu_count >> $T/cfgcpu
+   echo 'scenariocpu["'"$CF1"'"] = '"$cpu_count"';' >> 
$T/cfgcpu.awk
else
echo "The --configs file $CF1 does not exist, terminating."
exit 1
fi
 done
+cat << '___EOF___' >> $T/cfgcpu.awk
+}
+{
+   for (i = 1; i <= NF; i++)
+   print $i, scenariocpu[$i];
+}
+___EOF___
+echo $configs_derep | awk -f $T/cfgcpu.awk > $T/cfgcpu
 sort -k2nr $T/cfgcpu -T="$T" > $T/cfgcpu.sort
 
 # Use a greedy bin-packing algorithm, sorting the list accordingly.
@@ -324,11 +333,10 @@ END {
batch = 0;
nc = -1;
 
-   # Each pass through the following loop creates on test batch
-   # that can be executed concurrently given ncpus.  Note that a
-   # given test that requires more than the available CPUs will run in
-   # their own batch.  Such tests just have to make do with what
-   # is available.
+   # Each pass through the following loop creates on test batch that
+   # can be executed concurrently given ncpus.  Note that a given test
+   # that requires more than the available CPUs will run in its own
+   # batch.  Such tests just have to make do with what is available.
while (nc != ncpus) {
batch++;
nc = ncpus;


[tip: core/rcu] torture: Create doyesno helper function for torture.sh

2021-02-12 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: c9a9d8e8f2e6f34e70701a1d1580eef9c76265ef
Gitweb:
https://git.kernel.org/tip/c9a9d8e8f2e6f34e70701a1d1580eef9c76265ef
Author:Paul E. McKenney 
AuthorDate:Wed, 25 Nov 2020 10:14:24 -08:00
Committer: Paul E. McKenney 
CommitterDate: Wed, 06 Jan 2021 17:03:43 -08:00

torture: Create doyesno helper function for torture.sh

This commit saves a few lines of code by creating a doyesno helper bash
function for argument parsing.

Signed-off-by: Paul E. McKenney 
---
 tools/testing/selftests/rcutorture/bin/torture.sh | 78 +++---
 1 file changed, 19 insertions(+), 59 deletions(-)

diff --git a/tools/testing/selftests/rcutorture/bin/torture.sh 
b/tools/testing/selftests/rcutorture/bin/torture.sh
index a3c3c25..a01079e 100755
--- a/tools/testing/selftests/rcutorture/bin/torture.sh
+++ b/tools/testing/selftests/rcutorture/bin/torture.sh
@@ -47,6 +47,16 @@ do_kvfree=yes
 do_kasan=yes
 do_kcsan=no
 
+# doyesno - Helper function for yes/no arguments
+function doyesno () {
+   if test "$1" = "$2"
+   then
+   echo yes
+   else
+   echo no
+   fi
+}
+
 usage () {
echo "Usage: $scriptname optional arguments:"
echo "   --doall"
@@ -79,44 +89,19 @@ do
do_kcsan=yes
;;
--do-allmodconfig|--do-no-allmodconfig)
-   if test "$1" = --do-allmodconfig
-   then
-   do_allmodconfig=yes
-   else
-   do_allmodconfig=no
-   fi
+   do_allmodconfig=`doyesno "$1" --do-allmodconfig`
;;
--do-kasan|--do-no-kasan)
-   if test "$1" = --do-kasan
-   then
-   do_kasan=yes
-   else
-   do_kasan=no
-   fi
+   do_kasan=`doyesno "$1" --do-kasan`
;;
--do-kcsan|--do-no-kcsan)
-   if test "$1" = --do-kcsan
-   then
-   do_kcsan=yes
-   else
-   do_kcsan=no
-   fi
+   do_kcsan=`doyesno "$1" --do-kcsan`
;;
--do-kvfree|--do-no-kvfree)
-   if test "$1" = --do-kvfree
-   then
-   do_kvfree=yes
-   else
-   do_kvfree=no
-   fi
+   do_kvfree=`doyesno "$1" --do-kvfree`
;;
--do-locktorture|--do-no-locktorture)
-   if test "$1" = --do-locktorture
-   then
-   do_locktorture=yes
-   else
-   do_locktorture=no
-   fi
+   do_locktorture=`doyesno "$1" --do-locktorture`
;;
--do-none)
do_allmodconfig=no
@@ -130,36 +115,16 @@ do
do_kcsan=no
;;
--do-rcuscale|--do-no-rcuscale)
-   if test "$1" = --do-rcuscale
-   then
-   do_rcuscale=yes
-   else
-   do_rcuscale=no
-   fi
+   do_rcuscale=`doyesno "$1" --do-rcuscale`
;;
--do-rcutorture|--do-no-rcutorture)
-   if test "$1" = --do-rcutorture
-   then
-   do_rcutorture=yes
-   else
-   do_rcutorture=no
-   fi
+   do_rcutorture=`doyesno "$1" --do-rcutorture`
;;
--do-refscale|--do-no-refscale)
-   if test "$1" = --do-refscale
-   then
-   do_refscale=yes
-   else
-   do_refscale=no
-   fi
+   do_refscale=`doyesno "$1" --do-refscale`
;;
--do-scftorture|--do-no-scftorture)
-   if test "$1" = --do-scftorture
-   then
-   do_scftorture=yes
-   else
-   do_scftorture=no
-   fi
+   do_scftorture=`doyesno "$1" --do-scftorture`
;;
--duration)
checkarg --duration "(minutes)" $# "$2" 
'^[0-9][0-9]*\(m\|h\|d\|\)$' '^error'
@@ -363,11 +328,6 @@ fi
 exit $ret
 
 # @@@
-# RCU CPU stall warnings?
-# scftorture warnings?
 # Need a way for the invoker to specify clang.  Maybe --kcsan-kmake or some 
such.
-# Work out --configs based on number of available CPUs?
-# Need to sense CPUs to size scftorture run.  Ditto rcuscale and refscale.
 # --kconfig as with --bootargs (Both have overrides.)
 # Command line parameters for --bootargs, --config, --kconfig, --kmake-arg, 
and --qemu-arg
-# Ensure that build failures count as failures


[tip: core/rcu] torture: Add --kcsan-kmake-arg to torture.sh for KCSAN

2021-02-12 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: c54e413822701a18e7cf6bada2028ea9a9ecdaf9
Gitweb:
https://git.kernel.org/tip/c54e413822701a18e7cf6bada2028ea9a9ecdaf9
Author:Paul E. McKenney 
AuthorDate:Fri, 27 Nov 2020 18:06:57 -08:00
Committer: Paul E. McKenney 
CommitterDate: Wed, 06 Jan 2021 17:03:46 -08:00

torture: Add --kcsan-kmake-arg to torture.sh for KCSAN

In 2020, running KCSAN often requires careful choice of compiler.
This commit therefore adds a --kcsan-kmake-arg parameter to torture.sh
to allow specifying (for example) "CC=clang" to the kernel build process
to correctly build a KCSAN-enabled kernel.

Signed-off-by: Paul E. McKenney 
---
 tools/testing/selftests/rcutorture/bin/torture.sh | 21 ++
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/tools/testing/selftests/rcutorture/bin/torture.sh 
b/tools/testing/selftests/rcutorture/bin/torture.sh
index 90ca736..0867f30 100755
--- a/tools/testing/selftests/rcutorture/bin/torture.sh
+++ b/tools/testing/selftests/rcutorture/bin/torture.sh
@@ -34,6 +34,7 @@ fi
 configs_rcutorture=
 configs_locktorture=
 configs_scftorture=
+kcsan_kmake_args=
 
 # Default duration and apportionment.
 duration_base=10
@@ -79,6 +80,7 @@ usage () {
echo "   --do-refscale / --do-no-refscale"
echo "   --do-scftorture / --do-no-scftorture"
echo "   --duration [  | h | d ]"
+   echo "   --kcsan-kmake-arg kernel-make-arguments"
exit 1
 }
 
@@ -166,6 +168,11 @@ do
duration_base=$(($ts*mult))
shift
;;
+   --kcsan-kmake-arg|--kcsan-kmake-args)
+   checkarg --kcsan-kmake-arg "(kernel make arguments)" $# "$2" 
'.*' '^error$'
+   kcsan_kmake_args="`echo "$kcsan_kmake_args $2" | sed -e 's/^ 
*//' -e 's/ *$//'`"
+   shift
+   ;;
*)
echo Unknown argument $1
usage
@@ -269,6 +276,8 @@ function torture_one {
 # Note that quoting is problematic.  So on the command line, pass multiple
 # values with multiple kvm.sh argument instances.
 function torture_set {
+   local cur_kcsan_kmake_args=
+   local kcsan_kmake_tag=
local flavor=$1
shift
curflavor=$flavor
@@ -281,7 +290,12 @@ function torture_set {
if test "$do_kcsan" = "yes"
then
curflavor=${flavor}-kcsan
-   torture_one $* --kconfig "CONFIG_DEBUG_LOCK_ALLOC=y 
CONFIG_PROVE_LOCKING=y" --kmake-arg "CC=clang" --kcsan
+   if test -n "$kcsan_kmake_args"
+   then
+   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
fi
 }
 
@@ -382,8 +396,3 @@ then
cp $T/log $tdir
 fi
 exit $ret
-
-# @@@
-# Need a way for the invoker to specify clang.  Maybe --kcsan-kmake or some 
such.
-# --kconfig as with --bootargs (Both have overrides.)
-# Command line parameters for --bootargs, --config, --kconfig, --kmake-arg, 
and --qemu-arg


[tip: core/rcu] torture: Add fuzzed hrtimer-based sleep functions

2021-02-12 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: ae19aaafae95a5487469433e9cae4c208f8d15cd
Gitweb:
https://git.kernel.org/tip/ae19aaafae95a5487469433e9cae4c208f8d15cd
Author:Paul E. McKenney 
AuthorDate:Tue, 17 Nov 2020 11:30:18 -08:00
Committer: Paul E. McKenney 
CommitterDate: Wed, 06 Jan 2021 17:17:19 -08:00

torture: Add fuzzed hrtimer-based sleep functions

This commit adds torture_hrtimeout_ns(), torture_hrtimeout_us(),
torture_hrtimeout_ms(), torture_hrtimeout_jiffies(), and
torture_hrtimeout_s(), each of which uses hrtimers to block for a fuzzed
time interval.  These functions are intended to be used by the various
torture tests to decouple wakeups from the timer wheel, thus providing
more opportunity for Murphy to insert destructive race conditions.

Signed-off-by: Paul E. McKenney 
---
 include/linux/torture.h |  7 -
 kernel/torture.c| 75 -
 2 files changed, 82 insertions(+)

diff --git a/include/linux/torture.h b/include/linux/torture.h
index 7f65bd1..32941f8 100644
--- a/include/linux/torture.h
+++ b/include/linux/torture.h
@@ -61,6 +61,13 @@ static inline void torture_random_init(struct 
torture_random_state *trsp)
trsp->trs_count = 0;
 }
 
+/* Definitions for high-resolution-timer sleeps. */
+int torture_hrtimeout_ns(ktime_t baset_ns, u32 fuzzt_ns, struct 
torture_random_state *trsp);
+int torture_hrtimeout_us(u32 baset_us, u32 fuzzt_ns, struct 
torture_random_state *trsp);
+int torture_hrtimeout_ms(u32 baset_ms, u32 fuzzt_us, struct 
torture_random_state *trsp);
+int torture_hrtimeout_jiffies(u32 baset_j, struct torture_random_state *trsp);
+int torture_hrtimeout_s(u32 baset_s, u32 fuzzt_ms, struct torture_random_state 
*trsp);
+
 /* Task shuffler, which causes CPUs to occasionally go idle. */
 void torture_shuffle_task_register(struct task_struct *tp);
 int torture_shuffle_init(long shuffint);
diff --git a/kernel/torture.c b/kernel/torture.c
index 8562ac1..7548634 100644
--- a/kernel/torture.c
+++ b/kernel/torture.c
@@ -58,6 +58,81 @@ static int verbose;
 static int fullstop = FULLSTOP_RMMOD;
 static DEFINE_MUTEX(fullstop_mutex);
 
+/*
+ * Schedule a high-resolution-timer sleep in nanoseconds, with a 32-bit
+ * nanosecond random fuzz.  This function and its friends desynchronize
+ * testing from the timer wheel.
+ */
+int torture_hrtimeout_ns(ktime_t baset_ns, u32 fuzzt_ns, struct 
torture_random_state *trsp)
+{
+   ktime_t hto = baset_ns;
+
+   if (trsp)
+   hto += (torture_random(trsp) >> 3) % fuzzt_ns;
+   set_current_state(TASK_UNINTERRUPTIBLE);
+   return schedule_hrtimeout(, HRTIMER_MODE_REL);
+}
+EXPORT_SYMBOL_GPL(torture_hrtimeout_ns);
+
+/*
+ * Schedule a high-resolution-timer sleep in microseconds, with a 32-bit
+ * nanosecond (not microsecond!) random fuzz.
+ */
+int torture_hrtimeout_us(u32 baset_us, u32 fuzzt_ns, struct 
torture_random_state *trsp)
+{
+   ktime_t baset_ns = baset_us * NSEC_PER_USEC;
+
+   return torture_hrtimeout_ns(baset_ns, fuzzt_ns, trsp);
+}
+EXPORT_SYMBOL_GPL(torture_hrtimeout_us);
+
+/*
+ * Schedule a high-resolution-timer sleep in milliseconds, with a 32-bit
+ * microsecond (not millisecond!) random fuzz.
+ */
+int torture_hrtimeout_ms(u32 baset_ms, u32 fuzzt_us, struct 
torture_random_state *trsp)
+{
+   ktime_t baset_ns = baset_ms * NSEC_PER_MSEC;
+   u32 fuzzt_ns;
+
+   if ((u32)~0U / NSEC_PER_USEC < fuzzt_us)
+   fuzzt_ns = (u32)~0U;
+   else
+   fuzzt_ns = fuzzt_us * NSEC_PER_USEC;
+   return torture_hrtimeout_ns(baset_ns, fuzzt_ns, trsp);
+}
+EXPORT_SYMBOL_GPL(torture_hrtimeout_ms);
+
+/*
+ * Schedule a high-resolution-timer sleep in jiffies, with an
+ * implied one-jiffy random fuzz.  This is intended to replace calls to
+ * schedule_timeout_interruptible() and friends.
+ */
+int torture_hrtimeout_jiffies(u32 baset_j, struct torture_random_state *trsp)
+{
+   ktime_t baset_ns = jiffies_to_nsecs(baset_j);
+
+   return torture_hrtimeout_ns(baset_ns, jiffies_to_nsecs(1), trsp);
+}
+EXPORT_SYMBOL_GPL(torture_hrtimeout_jiffies);
+
+/*
+ * Schedule a high-resolution-timer sleep in milliseconds, with a 32-bit
+ * millisecond (not second!) random fuzz.
+ */
+int torture_hrtimeout_s(u32 baset_s, u32 fuzzt_ms, struct torture_random_state 
*trsp)
+{
+   ktime_t baset_ns = baset_s * NSEC_PER_SEC;
+   u32 fuzzt_ns;
+
+   if ((u32)~0U / NSEC_PER_MSEC < fuzzt_ms)
+   fuzzt_ns = (u32)~0U;
+   else
+   fuzzt_ns = fuzzt_ms * NSEC_PER_MSEC;
+   return torture_hrtimeout_ns(baset_ns, fuzzt_ns, trsp);
+}
+EXPORT_SYMBOL_GPL(torture_hrtimeout_s);
+
 #ifdef CONFIG_HOTPLUG_CPU
 
 /*


[tip: core/rcu] torture: Drop log.long generation from torture.sh

2021-02-12 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 5ae5f7453f93b21e06296e78e8481ba8b55e
Gitweb:
https://git.kernel.org/tip/5ae5f7453f93b21e06296e78e8481ba8b55e
Author:Paul E. McKenney 
AuthorDate:Thu, 26 Nov 2020 21:27:27 -08:00
Committer: Paul E. McKenney 
CommitterDate: Wed, 06 Jan 2021 17:03:45 -08:00

torture: Drop log.long generation from torture.sh

Now that kvm.sh puts all the relevant details in the "log" file,
there is no need for torture.sh to generate a separate "log.long"
file.  This commit therefore drops this from torture.sh.

Signed-off-by: Paul E. McKenney 
---
 tools/testing/selftests/rcutorture/bin/torture.sh | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/tools/testing/selftests/rcutorture/bin/torture.sh 
b/tools/testing/selftests/rcutorture/bin/torture.sh
index 43ef2c0..cf74123 100755
--- a/tools/testing/selftests/rcutorture/bin/torture.sh
+++ b/tools/testing/selftests/rcutorture/bin/torture.sh
@@ -203,11 +203,8 @@ function torture_one {
"$@" $boottag "$cur_bootargs" --datestamp "$ds/results-$curflavor" > 
$T/$curflavor.out 2>&1
retcode=$?
resdir="`grep '^Results directory: ' $T/$curflavor.out | tail -1 | sed 
-e 's/^Results directory: //'`"
-   if test -n "$resdir"
+   if test -z "$resdir"
then
-   cp $T/$curflavor.out $resdir/log.long
-   echo retcode=$retcode >> $resdir/log.long
-   else
cat $T/$curflavor.out | tee -a $T/log
echo retcode=$retcode | tee -a $T/log
fi


[tip: core/rcu] refscale: Allow summarization of verbose output

2021-02-12 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: e76506f0e85129d726c487c873a2245c92446515
Gitweb:
https://git.kernel.org/tip/e76506f0e85129d726c487c873a2245c92446515
Author:Paul E. McKenney 
AuthorDate:Sun, 15 Nov 2020 10:24:52 -08:00
Committer: Paul E. McKenney 
CommitterDate: Wed, 06 Jan 2021 17:08:09 -08:00

refscale: Allow summarization of verbose output

The refscale test prints enough per-kthread console output to provoke RCU
CPU stall warnings on large systems.  This commit therefore allows this
output to be summarized.  For example, the refscale.verbose_batched=32
boot parameter would causes only every 32nd line of output to be logged.

Signed-off-by: Paul E. McKenney 
---
 Documentation/admin-guide/kernel-parameters.txt |  6 +-
 kernel/rcu/refscale.c   | 21 
 2 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/Documentation/admin-guide/kernel-parameters.txt 
b/Documentation/admin-guide/kernel-parameters.txt
index c722ec1..3244f9e 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -4557,6 +4557,12 @@
refscale.verbose= [KNL]
Enable additional printk() statements.
 
+   refscale.verbose_batched= [KNL]
+   Batch the additional printk() statements.  If zero
+   (the default) or negative, print everything.  Otherwise,
+   print every Nth verbose statement, where N is the value
+   specified.
+
relax_domain_level=
[KNL, SMP] Set scheduler's default relax_domain_level.
See Documentation/admin-guide/cgroup-v1/cpusets.rst.
diff --git a/kernel/rcu/refscale.c b/kernel/rcu/refscale.c
index 23ff36a..3da246f 100644
--- a/kernel/rcu/refscale.c
+++ b/kernel/rcu/refscale.c
@@ -46,6 +46,16 @@
 #define VERBOSE_SCALEOUT(s, x...) \
do { if (verbose) pr_alert("%s" SCALE_FLAG s, scale_type, ## x); } 
while (0)
 
+static atomic_t verbose_batch_ctr;
+
+#define VERBOSE_SCALEOUT_BATCH(s, x...)
\
+do {   
\
+   if (verbose &&  
\
+   (verbose_batched <= 0 ||
\
+!(atomic_inc_return(_batch_ctr) % verbose_batched)))   
\
+   pr_alert("%s" SCALE_FLAG s, scale_type, ## x);  
\
+} while (0)
+
 #define VERBOSE_SCALEOUT_ERRSTRING(s, x...) \
do { if (verbose) pr_alert("%s" SCALE_FLAG "!!! " s, scale_type, ## x); 
} while (0)
 
@@ -57,6 +67,7 @@ module_param(scale_type, charp, 0444);
 MODULE_PARM_DESC(scale_type, "Type of test (rcu, srcu, refcnt, rwsem, 
rwlock.");
 
 torture_param(int, verbose, 0, "Enable verbose debugging printk()s");
+torture_param(int, verbose_batched, 0, "Batch verbose debugging printk()s");
 
 // Wait until there are multiple CPUs before starting test.
 torture_param(int, holdoff, IS_BUILTIN(CONFIG_RCU_REF_SCALE_TEST) ? 10 : 0,
@@ -368,14 +379,14 @@ ref_scale_reader(void *arg)
u64 start;
s64 duration;
 
-   VERBOSE_SCALEOUT("ref_scale_reader %ld: task started", me);
+   VERBOSE_SCALEOUT_BATCH("ref_scale_reader %ld: task started", me);
set_cpus_allowed_ptr(current, cpumask_of(me % nr_cpu_ids));
set_user_nice(current, MAX_NICE);
atomic_inc(_init);
if (holdoff)
schedule_timeout_interruptible(holdoff * HZ);
 repeat:
-   VERBOSE_SCALEOUT("ref_scale_reader %ld: waiting to start next 
experiment on cpu %d", me, smp_processor_id());
+   VERBOSE_SCALEOUT_BATCH("ref_scale_reader %ld: waiting to start next 
experiment on cpu %d", me, smp_processor_id());
 
// Wait for signal that this reader can start.
wait_event(rt->wq, (atomic_read(_exp) && 
smp_load_acquire(>start_reader)) ||
@@ -392,7 +403,7 @@ repeat:
while (atomic_read_acquire(_started))
cpu_relax();
 
-   VERBOSE_SCALEOUT("ref_scale_reader %ld: experiment %d started", me, 
exp_idx);
+   VERBOSE_SCALEOUT_BATCH("ref_scale_reader %ld: experiment %d started", 
me, exp_idx);
 
 
// To reduce noise, do an initial cache-warming invocation, check
@@ -421,8 +432,8 @@ repeat:
if (atomic_dec_and_test(_exp))
wake_up(_wq);
 
-   VERBOSE_SCALEOUT("ref_scale_reader %ld: experiment %d ended, (readers 
remaining=%d)",
-   me, exp_idx, atomic_read(_exp));
+   VERBOSE_SCALEOUT_BATCH("ref_scale_reader %ld: experiment %d ended, 
(readers remaining=%d)",
+   me, exp_idx, atomic_read(_exp));
 
if (!torture_must_stop())
goto repeat;


[tip: core/rcu] rcutorture: Make rcu_torture_fakewriter() use blocking wait primitives

2021-02-12 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 682189a3f874db57b3e755512f2a2953f61fc54e
Gitweb:
https://git.kernel.org/tip/682189a3f874db57b3e755512f2a2953f61fc54e
Author:Paul E. McKenney 
AuthorDate:Mon, 16 Nov 2020 17:10:39 -08:00
Committer: Paul E. McKenney 
CommitterDate: Wed, 06 Jan 2021 17:17:18 -08:00

rcutorture: Make rcu_torture_fakewriter() use blocking wait primitives

Full testing of the new SRCU polling API requires that the fake
writers also use it in order to test concurrent calls to all of the API
members, especially start_poll_synchronize_srcu().  This commit makes
rcu_torture_fakewriter() use all available blocking grace-period-wait
primitives available from the RCU flavor under test.

Link: https://lore.kernel.org/rcu/20201112201547.gf3365...@moria.home.lan/
Reported-by: Kent Overstreet 
Signed-off-by: Paul E. McKenney 
---
 kernel/rcu/rcutorture.c | 40 
 1 file changed, 32 insertions(+), 8 deletions(-)

diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
index 0d257e2..03bdf67 100644
--- a/kernel/rcu/rcutorture.c
+++ b/kernel/rcu/rcutorture.c
@@ -1289,6 +1289,8 @@ rcu_torture_writer(void *arg)
 static int
 rcu_torture_fakewriter(void *arg)
 {
+   unsigned long gp_snap;
+   int i;
DEFINE_TORTURE_RANDOM(rand);
 
VERBOSE_TOROUT_STRING("rcu_torture_fakewriter task started");
@@ -1300,15 +1302,37 @@ rcu_torture_fakewriter(void *arg)
if (cur_ops->cb_barrier != NULL &&
torture_random() % (nfakewriters * 8) == 0) {
cur_ops->cb_barrier();
-   } else if (gp_normal == gp_exp) {
-   if (cur_ops->sync && torture_random() & 0x80)
-   cur_ops->sync();
-   else if (cur_ops->exp_sync)
+   } else {
+   switch (synctype[torture_random() % nsynctypes]) {
+   case RTWS_DEF_FREE:
+   break;
+   case RTWS_EXP_SYNC:
cur_ops->exp_sync();
-   } else if (gp_normal && cur_ops->sync) {
-   cur_ops->sync();
-   } else if (cur_ops->exp_sync) {
-   cur_ops->exp_sync();
+   break;
+   case RTWS_COND_GET:
+   gp_snap = cur_ops->get_gp_state();
+   i = torture_random() % 16;
+   if (i != 0)
+   schedule_timeout_interruptible(i);
+   udelay(torture_random() % 1000);
+   cur_ops->cond_sync(gp_snap);
+   break;
+   case RTWS_POLL_GET:
+   gp_snap = cur_ops->start_gp_poll();
+   while (!cur_ops->poll_gp_state(gp_snap)) {
+   i = torture_random() % 16;
+   if (i != 0)
+   
schedule_timeout_interruptible(i);
+   udelay(torture_random() % 1000);
+   }
+   break;
+   case RTWS_SYNC:
+   cur_ops->sync();
+   break;
+   default:
+   WARN_ON_ONCE(1);
+   break;
+   }
}
stutter_wait("rcu_torture_fakewriter");
} while (!torture_must_stop());


[tip: core/rcu] rcutorture: Test runtime toggling of CPUs' callback offloading

2021-02-12 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 2c4319bd1d14d01f5b6654a90c2b6362f3a407d8
Gitweb:
https://git.kernel.org/tip/2c4319bd1d14d01f5b6654a90c2b6362f3a407d8
Author:Paul E. McKenney 
AuthorDate:Wed, 23 Sep 2020 17:39:46 -07:00
Committer: Paul E. McKenney 
CommitterDate: Wed, 06 Jan 2021 16:24:59 -08:00

rcutorture: Test runtime toggling of CPUs' callback offloading

Frederic Weisbecker is adding the ability to change the rcu_nocbs state
of CPUs at runtime, that is, to offload and deoffload their RCU callback
processing without the need to reboot.  As the old saying goes, "if it
ain't tested, it don't work", so this commit therefore adds prototype
rcutorture testing for this capability.

Signed-off-by: Paul E. McKenney 
Cc: Frederic Weisbecker 
---
 Documentation/admin-guide/kernel-parameters.txt |  8 +-
 kernel/rcu/rcutorture.c | 90 +++-
 2 files changed, 95 insertions(+), 3 deletions(-)

diff --git a/Documentation/admin-guide/kernel-parameters.txt 
b/Documentation/admin-guide/kernel-parameters.txt
index c722ec1..9f8ac77 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -4338,6 +4338,14 @@
stress RCU, they don't participate in the actual
test, hence the "fake".
 
+   rcutorture.nocbs_nthreads= [KNL]
+   Set number of RCU callback-offload togglers.
+   Zero (the default) disables toggling.
+
+   rcutorture.nocbs_toggle= [KNL]
+   Set the delay in milliseconds between successive
+   callback-offload toggling attempts.
+
rcutorture.nreaders= [KNL]
Set number of RCU readers.  The value -1 selects
N-1, where N is the number of CPUs.  A value
diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
index 528ed10..22735bc 100644
--- a/kernel/rcu/rcutorture.c
+++ b/kernel/rcu/rcutorture.c
@@ -97,6 +97,8 @@ torture_param(int, object_debug, 0,
 torture_param(int, onoff_holdoff, 0, "Time after boot before CPU hotplugs 
(s)");
 torture_param(int, onoff_interval, 0,
 "Time between CPU hotplugs (jiffies), 0=disable");
+torture_param(int, nocbs_nthreads, 0, "Number of NOCB toggle threads, 0 to 
disable");
+torture_param(int, nocbs_toggle, 1000, "Time between toggling nocb state 
(ms)");
 torture_param(int, read_exit_delay, 13,
  "Delay between read-then-exit episodes (s)");
 torture_param(int, read_exit_burst, 16,
@@ -127,10 +129,12 @@ static char *torture_type = "rcu";
 module_param(torture_type, charp, 0444);
 MODULE_PARM_DESC(torture_type, "Type of RCU to torture (rcu, srcu, ...)");
 
+static int nrealnocbers;
 static int nrealreaders;
 static struct task_struct *writer_task;
 static struct task_struct **fakewriter_tasks;
 static struct task_struct **reader_tasks;
+static struct task_struct **nocb_tasks;
 static struct task_struct *stats_task;
 static struct task_struct *fqs_task;
 static struct task_struct *boost_tasks[NR_CPUS];
@@ -174,6 +178,8 @@ static unsigned long n_read_exits;
 static struct list_head rcu_torture_removed;
 static unsigned long shutdown_jiffies;
 static unsigned long start_gp_seq;
+static atomic_long_t n_nocb_offload;
+static atomic_long_t n_nocb_deoffload;
 
 static int rcu_torture_writer_state;
 #define RTWS_FIXED_DELAY   0
@@ -1499,6 +1505,53 @@ rcu_torture_reader(void *arg)
 }
 
 /*
+ * Randomly Toggle CPUs' callback-offload state.  This uses hrtimers to
+ * increase race probabilities and fuzzes the interval between toggling.
+ */
+static int rcu_nocb_toggle(void *arg)
+{
+   int cpu;
+   int maxcpu = -1;
+   int oldnice = task_nice(current);
+   long r;
+   DEFINE_TORTURE_RANDOM(rand);
+   ktime_t toggle_delay;
+   unsigned long toggle_fuzz;
+   ktime_t toggle_interval = ms_to_ktime(nocbs_toggle);
+
+   VERBOSE_TOROUT_STRING("rcu_nocb_toggle task started");
+   while (!rcu_inkernel_boot_has_ended())
+   schedule_timeout_interruptible(HZ / 10);
+   for_each_online_cpu(cpu)
+   maxcpu = cpu;
+   WARN_ON(maxcpu < 0);
+   if (toggle_interval > ULONG_MAX)
+   toggle_fuzz = ULONG_MAX >> 3;
+   else
+   toggle_fuzz = toggle_interval >> 3;
+   if (toggle_fuzz <= 0)
+   toggle_fuzz = NSEC_PER_USEC;
+   do {
+   r = torture_random();
+   cpu = (r >> 4) % (maxcpu + 1);
+   if (r & 0x1) {
+   rcu_nocb_cpu_offload(cpu);
+   atomic_long_inc(_nocb_offload);
+   } else {
+   rcu_nocb_cpu_deoffload(cpu);
+   atomic_long_inc(_nocb_deoffload);
+   }
+   toggle_delay = torture_random() % toggle_fuzz + 
toggle_interval;
+   

[tip: core/rcu] rcu/nocb: Add grace period and task state to show_rcu_nocb_state() output

2021-02-12 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 341690611f8d488859f42a761f5d7cbac6ba2940
Gitweb:
https://git.kernel.org/tip/341690611f8d488859f42a761f5d7cbac6ba2940
Author:Paul E. McKenney 
AuthorDate:Fri, 18 Dec 2020 10:20:34 -08:00
Committer: Paul E. McKenney 
CommitterDate: Wed, 06 Jan 2021 16:25:00 -08:00

rcu/nocb: Add grace period and task state to show_rcu_nocb_state() output

This commit improves debuggability by indicating which grace period each
batch of nocb callbacks is waiting on and by showing the task state and
last CPU for reach nocb kthread.

[ paulmck: Handle !SMP CB offloading per kernel test robot feedback. ]
Signed-off-by: Paul E. McKenney 
---
 kernel/rcu/rcu_segcblist.h | 11 ++-
 kernel/rcu/tree_plugin.h   | 39 ++---
 2 files changed, 43 insertions(+), 7 deletions(-)

diff --git a/kernel/rcu/rcu_segcblist.h b/kernel/rcu/rcu_segcblist.h
index afad6fc..3110602 100644
--- a/kernel/rcu/rcu_segcblist.h
+++ b/kernel/rcu/rcu_segcblist.h
@@ -117,6 +117,17 @@ static inline bool rcu_segcblist_restempty(struct 
rcu_segcblist *rsclp, int seg)
return !READ_ONCE(*READ_ONCE(rsclp->tails[seg]));
 }
 
+/*
+ * Is the specified segment of the specified rcu_segcblist structure
+ * empty of callbacks?
+ */
+static inline bool rcu_segcblist_segempty(struct rcu_segcblist *rsclp, int seg)
+{
+   if (seg == RCU_DONE_TAIL)
+   return >head == rsclp->tails[RCU_DONE_TAIL];
+   return rsclp->tails[seg - 1] == rsclp->tails[seg];
+}
+
 void rcu_segcblist_inc_len(struct rcu_segcblist *rsclp);
 void rcu_segcblist_add_len(struct rcu_segcblist *rsclp, long v);
 void rcu_segcblist_init(struct rcu_segcblist *rsclp);
diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
index 8641b72..5ee1113 100644
--- a/kernel/rcu/tree_plugin.h
+++ b/kernel/rcu/tree_plugin.h
@@ -2672,6 +2672,19 @@ void rcu_bind_current_to_nocb(void)
 }
 EXPORT_SYMBOL_GPL(rcu_bind_current_to_nocb);
 
+// The ->on_cpu field is available only in CONFIG_SMP=y, so...
+#ifdef CONFIG_SMP
+static char *show_rcu_should_be_on_cpu(struct task_struct *tsp)
+{
+   return tsp && tsp->state == TASK_RUNNING && !tsp->on_cpu ? "!" : "";
+}
+#else // #ifdef CONFIG_SMP
+static char *show_rcu_should_be_on_cpu(struct task_struct *tsp)
+{
+   return "";
+}
+#endif // #else #ifdef CONFIG_SMP
+
 /*
  * Dump out nocb grace-period kthread state for the specified rcu_data
  * structure.
@@ -2680,7 +2693,7 @@ static void show_rcu_nocb_gp_state(struct rcu_data *rdp)
 {
struct rcu_node *rnp = rdp->mynode;
 
-   pr_info("nocb GP %d %c%c%c%c%c%c %c[%c%c] %c%c:%ld rnp %d:%d %lu\n",
+   pr_info("nocb GP %d %c%c%c%c%c%c %c[%c%c] %c%c:%ld rnp %d:%d %lu %c CPU 
%d%s\n",
rdp->cpu,
"kK"[!!rdp->nocb_gp_kthread],
"lL"[raw_spin_is_locked(>nocb_gp_lock)],
@@ -2694,12 +2707,17 @@ static void show_rcu_nocb_gp_state(struct rcu_data *rdp)
".B"[!!rdp->nocb_gp_bypass],
".G"[!!rdp->nocb_gp_gp],
(long)rdp->nocb_gp_seq,
-   rnp->grplo, rnp->grphi, READ_ONCE(rdp->nocb_gp_loops));
+   rnp->grplo, rnp->grphi, READ_ONCE(rdp->nocb_gp_loops),
+   rdp->nocb_gp_kthread ? task_state_to_char(rdp->nocb_gp_kthread) 
: '.',
+   rdp->nocb_cb_kthread ? (int)task_cpu(rdp->nocb_gp_kthread) : -1,
+   show_rcu_should_be_on_cpu(rdp->nocb_cb_kthread));
 }
 
 /* Dump out nocb kthread state for the specified rcu_data structure. */
 static void show_rcu_nocb_state(struct rcu_data *rdp)
 {
+   char bufw[20];
+   char bufr[20];
struct rcu_segcblist *rsclp = >cblist;
bool waslocked;
bool wastimer;
@@ -2708,7 +2726,9 @@ static void show_rcu_nocb_state(struct rcu_data *rdp)
if (rdp->nocb_gp_rdp == rdp)
show_rcu_nocb_gp_state(rdp);
 
-   pr_info("   CB %d->%d %c%c%c%c%c%c F%ld L%ld C%d %c%c%c%c%c q%ld\n",
+   sprintf(bufw, "%ld", rsclp->gp_seq[RCU_WAIT_TAIL]);
+   sprintf(bufr, "%ld", rsclp->gp_seq[RCU_NEXT_READY_TAIL]);
+   pr_info("   CB %d^%d->%d %c%c%c%c%c%c F%ld L%ld C%d %c%c%s%c%s%c%c q%ld 
%c CPU %d%s\n",
rdp->cpu, rdp->nocb_gp_rdp->cpu,
"kK"[!!rdp->nocb_cb_kthread],
"bB"[raw_spin_is_locked(>nocb_bypass_lock)],
@@ -2720,11 +2740,16 @@ static void show_rcu_nocb_state(struct rcu_data *rdp)
jiffies - rdp->nocb_nobypass_last,
rdp->nocb_nobypass_count,
".D"[rcu_segcblist_ready_cbs(rsclp)],
-   ".W"[!rcu_segcblist_restempty(rsclp, RCU_DONE_TAIL)],
-   ".R"[!rcu_segcblist_restempty(rsclp, RCU_WAIT_TAIL)],
-   ".N"[!rcu_segcblist_restempty(rsclp, RCU_NEXT_READY_TAIL)],
+   ".W"[!rcu_segcblist_segempty(rsclp, RCU_WAIT_TAIL)],
+   rcu_segcblist_segempty(rsclp, RCU_WAIT_TAIL) ? "" : bufw,
+ 

[tip: core/rcu] rcu/nocb: Add nocb CB kthread list to show_rcu_nocb_state() output

2021-02-12 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 3d0cef50f32e2bc69f60909584c18623bba9a6c6
Gitweb:
https://git.kernel.org/tip/3d0cef50f32e2bc69f60909584c18623bba9a6c6
Author:Paul E. McKenney 
AuthorDate:Fri, 18 Dec 2020 13:17:37 -08:00
Committer: Paul E. McKenney 
CommitterDate: Wed, 06 Jan 2021 16:25:00 -08:00

rcu/nocb: Add nocb CB kthread list to show_rcu_nocb_state() output

This commit improves debuggability by indicating laying out the order
in which rcuoc kthreads appear in the ->nocb_next_cb_rdp list.

Signed-off-by: Paul E. McKenney 
---
 kernel/rcu/tree_plugin.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
index 5ee1113..bc63a6b 100644
--- a/kernel/rcu/tree_plugin.h
+++ b/kernel/rcu/tree_plugin.h
@@ -2730,6 +2730,7 @@ static void show_rcu_nocb_state(struct rcu_data *rdp)
sprintf(bufr, "%ld", rsclp->gp_seq[RCU_NEXT_READY_TAIL]);
pr_info("   CB %d^%d->%d %c%c%c%c%c%c F%ld L%ld C%d %c%c%s%c%s%c%c q%ld 
%c CPU %d%s\n",
rdp->cpu, rdp->nocb_gp_rdp->cpu,
+   rdp->nocb_next_cb_rdp ? rdp->nocb_next_cb_rdp->cpu : -1,
"kK"[!!rdp->nocb_cb_kthread],
"bB"[raw_spin_is_locked(>nocb_bypass_lock)],
"cC"[!!atomic_read(>nocb_lock_contended)],


[tip: core/rcu] rcu/nocb: Code-style nits in callback-offloading toggling

2021-02-12 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: f759081e8f5ac640df1c7125540759bbcb4eb0e2
Gitweb:
https://git.kernel.org/tip/f759081e8f5ac640df1c7125540759bbcb4eb0e2
Author:Paul E. McKenney 
AuthorDate:Mon, 21 Dec 2020 11:17:16 -08:00
Committer: Paul E. McKenney 
CommitterDate: Wed, 06 Jan 2021 16:47:55 -08:00

rcu/nocb: Code-style nits in callback-offloading toggling

This commit addresses a few code-style nits in callback-offloading
toggling, including one that predates this toggling.

Cc: Frederic Weisbecker 
Signed-off-by: Paul E. McKenney 
---
 kernel/rcu/rcu_segcblist.h | 19 +---
 kernel/rcu/rcutorture.c|  2 +-
 kernel/rcu/tree_plugin.h   | 45 ++---
 kernel/time/timer.c|  1 +-
 4 files changed, 30 insertions(+), 37 deletions(-)

diff --git a/kernel/rcu/rcu_segcblist.h b/kernel/rcu/rcu_segcblist.h
index 3110602..9a19328 100644
--- a/kernel/rcu/rcu_segcblist.h
+++ b/kernel/rcu/rcu_segcblist.h
@@ -80,17 +80,12 @@ static inline bool rcu_segcblist_is_enabled(struct 
rcu_segcblist *rsclp)
return rcu_segcblist_test_flags(rsclp, SEGCBLIST_ENABLED);
 }
 
-/* Is the specified rcu_segcblist offloaded?  */
+/* Is the specified rcu_segcblist offloaded, or is SEGCBLIST_SOFTIRQ_ONLY set? 
*/
 static inline bool rcu_segcblist_is_offloaded(struct rcu_segcblist *rsclp)
 {
-   if (IS_ENABLED(CONFIG_RCU_NOCB_CPU)) {
-   /*
-* Complete de-offloading happens only when 
SEGCBLIST_SOFTIRQ_ONLY
-* is set.
-*/
-   if (!rcu_segcblist_test_flags(rsclp, SEGCBLIST_SOFTIRQ_ONLY))
-   return true;
-   }
+   if (IS_ENABLED(CONFIG_RCU_NOCB_CPU) &&
+   !rcu_segcblist_test_flags(rsclp, SEGCBLIST_SOFTIRQ_ONLY))
+   return true;
 
return false;
 }
@@ -99,10 +94,8 @@ static inline bool rcu_segcblist_completely_offloaded(struct 
rcu_segcblist *rscl
 {
int flags = SEGCBLIST_KTHREAD_CB | SEGCBLIST_KTHREAD_GP | 
SEGCBLIST_OFFLOADED;
 
-   if (IS_ENABLED(CONFIG_RCU_NOCB_CPU)) {
-   if ((rsclp->flags & flags) == flags)
-   return true;
-   }
+   if (IS_ENABLED(CONFIG_RCU_NOCB_CPU) && (rsclp->flags & flags) == flags)
+   return true;
 
return false;
 }
diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
index 22735bc..b9dd63c 100644
--- a/kernel/rcu/rcutorture.c
+++ b/kernel/rcu/rcutorture.c
@@ -1606,7 +1606,7 @@ rcu_torture_stats_print(void)
data_race(n_barrier_successes),
data_race(n_barrier_attempts),
data_race(n_rcu_torture_barrier_error));
-   pr_cont("read-exits: %ld ", data_race(n_read_exits));
+   pr_cont("read-exits: %ld ", data_race(n_read_exits)); // Statistic.
pr_cont("nocb-toggles: %ld:%ld\n",
atomic_long_read(_nocb_offload), 
atomic_long_read(_nocb_deoffload));
 
diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
index bc63a6b..6f56f9e 100644
--- a/kernel/rcu/tree_plugin.h
+++ b/kernel/rcu/tree_plugin.h
@@ -1962,17 +1962,17 @@ static inline bool nocb_gp_update_state(struct rcu_data 
*rdp, bool *needwake_sta
*needwake_state = true;
}
return true;
-   } else {
-   /*
-* De-offloading. Clear our flag and notify the de-offload 
worker.
-* We will ignore this rdp until it ever gets re-offloaded.
-*/
-   WARN_ON_ONCE(!rcu_segcblist_test_flags(cblist, 
SEGCBLIST_KTHREAD_GP));
-   rcu_segcblist_clear_flags(cblist, SEGCBLIST_KTHREAD_GP);
-   if (!rcu_segcblist_test_flags(cblist, SEGCBLIST_KTHREAD_CB))
-   *needwake_state = true;
-   return false;
}
+
+   /*
+* De-offloading. Clear our flag and notify the de-offload worker.
+* We will ignore this rdp until it ever gets re-offloaded.
+*/
+   WARN_ON_ONCE(!rcu_segcblist_test_flags(cblist, SEGCBLIST_KTHREAD_GP));
+   rcu_segcblist_clear_flags(cblist, SEGCBLIST_KTHREAD_GP);
+   if (!rcu_segcblist_test_flags(cblist, SEGCBLIST_KTHREAD_CB))
+   *needwake_state = true;
+   return false;
 }
 
 
@@ -2005,6 +2005,7 @@ static void nocb_gp_wait(struct rcu_data *my_rdp)
WARN_ON_ONCE(my_rdp->nocb_gp_rdp != my_rdp);
for (rdp = my_rdp; rdp; rdp = rdp->nocb_next_cb_rdp) {
bool needwake_state = false;
+
if (!nocb_gp_enabled_cb(rdp))
continue;
trace_rcu_nocb_wake(rcu_state.name, rdp->cpu, TPS("Check"));
@@ -2160,11 +2161,11 @@ static inline bool nocb_cb_wait_cond(struct rcu_data 
*rdp)
 static void nocb_cb_wait(struct rcu_data *rdp)
 {
struct rcu_segcblist *cblist = >cblist;
-   struct rcu_node *rnp = rdp->mynode;
-   bool 

[tip: core/rcu] rcu: Do any deferred nocb wakeups at CPU offline time

2021-02-12 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 147c6852d34563b87ff0e67383c2bf675e8248f6
Gitweb:
https://git.kernel.org/tip/147c6852d34563b87ff0e67383c2bf675e8248f6
Author:Paul E. McKenney 
AuthorDate:Tue, 22 Dec 2020 16:49:11 -08:00
Committer: Paul E. McKenney 
CommitterDate: Wed, 06 Jan 2021 16:50:24 -08:00

rcu: Do any deferred nocb wakeups at CPU offline time

Because the need to wake a nocb GP kthread ("rcuog") is sometimes
detected when wakeups cannot be done, these wakeups can be deferred.
The wakeups are then carried out by calls to do_nocb_deferred_wakeup()
at various safe points in the code, including RCU's idle hooks.  However,
when a CPU goes offline, it invokes arch_cpu_idle_dead() without invoking
any of RCU's idle hooks.

This commit therefore adds a call to do_nocb_deferred_wakeup() in
rcu_report_dead() in order to handle any deferred wakeups that have been
requested by the outgoing CPU.

Signed-off-by: Paul E. McKenney 
---
 kernel/rcu/tree.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
index 03810a5..e6dee71 100644
--- a/kernel/rcu/tree.c
+++ b/kernel/rcu/tree.c
@@ -4178,6 +4178,9 @@ void rcu_report_dead(unsigned int cpu)
struct rcu_data *rdp = per_cpu_ptr(_data, cpu);
struct rcu_node *rnp = rdp->mynode;  /* Outgoing CPU's rdp & rnp. */
 
+   // Do any dangling deferred wakeups.
+   do_nocb_deferred_wakeup(rdp);
+
/* QS for any half-done expedited grace period. */
preempt_disable();
rcu_report_exp_rdp(this_cpu_ptr(_data));


[tip: core/rcu] torture: Add torture.sh torture-everything script

2021-02-12 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: bfc19c13d24c70e4fb1dafd76900731bcee97683
Gitweb:
https://git.kernel.org/tip/bfc19c13d24c70e4fb1dafd76900731bcee97683
Author:Paul E. McKenney 
AuthorDate:Sat, 21 Nov 2020 14:09:48 -08:00
Committer: Paul E. McKenney 
CommitterDate: Wed, 06 Jan 2021 16:59:47 -08:00

torture: Add torture.sh torture-everything script

Although tailoring a specific set of kvm.sh runs has served rcutorture
testing well over many years, it requires a relatively distraction-free
environment, which is not always available.  This commit therefore
adds a prototype torture.sh script that by default tortures pretty much
everything the rcutorture scripting is designed to torture, and which
can be given command-line arguments to take a more focused approach.

Signed-off-by: Paul E. McKenney 
---
 tools/testing/selftests/rcutorture/bin/torture.sh | 301 +-
 1 file changed, 301 insertions(+)
 create mode 100644 tools/testing/selftests/rcutorture/bin/torture.sh

diff --git a/tools/testing/selftests/rcutorture/bin/torture.sh 
b/tools/testing/selftests/rcutorture/bin/torture.sh
new file mode 100644
index 000..7f21aab
--- /dev/null
+++ b/tools/testing/selftests/rcutorture/bin/torture.sh
@@ -0,0 +1,301 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Run a series of torture tests, intended for overnight or
+# longer timeframes, and also for large systems.
+#
+# Usage: torture.sh [ options ]
+#
+# Copyright (C) 2020 Facebook, Inc.
+#
+# Authors: Paul E. McKenney 
+
+scriptname=$0
+args="$*"
+
+# Default duration and apportionment.
+duration_base=10
+duration_rcutorture_frac=7
+duration_locktorture_frac=1
+duration_scftorture_frac=2
+
+# "yes" or "no" parameters
+do_rcutorture=yes
+do_locktorture=yes
+do_scftorture=yes
+do_rcuscale=yes
+do_refscale=yes
+do_kvfree=yes
+do_kasan=yes
+do_kcsan=no
+
+usage () {
+   echo "Usage: $scriptname optional arguments:"
+   echo "   --doall"
+   echo "   --do-kasan / --do-no-kasan"
+   echo "   --do-kcsan / --do-no-kcsan"
+   echo "   --do-kvfree / --do-no-kvfree"
+   echo "   --do-locktorture / --do-no-locktorture"
+   echo "   --do-none"
+   echo "   --do-rcuscale / --do-no-rcuscale"
+   echo "   --do-rcutorture / --do-no-rcutorture"
+   echo "   --do-refscale / --do-no-refscale"
+   echo "   --do-scftorture / --do-no-scftorture"
+   echo "   --duration [  | h | d ]"
+   exit 1
+}
+
+while test $# -gt 0
+do
+   case "$1" in
+   --doall)
+   do_rcutorture=yes
+   do_locktorture=yes
+   do_scftorture=yes
+   do_rcuscale=yes
+   do_refscale=yes
+   do_kvfree=yes
+   do_kasan=yes
+   do_kcsan=yes
+   ;;
+   --do-kasan|--do-no-kasan)
+   if test "$1" = --do-kasan
+   then
+   do_kasan=yes
+   else
+   do_kasan=no
+   fi
+   ;;
+   --do-kcsan|--do-no-kcsan)
+   if test "$1" = --do-kcsan
+   then
+   do_kcsan=yes
+   else
+   do_kcsan=no
+   fi
+   ;;
+   --do-kvfree|--do-no-kvfree)
+   if test "$1" = --do-kvfree
+   then
+   do_kvfree=yes
+   else
+   do_kvfree=no
+   fi
+   ;;
+   --do-locktorture|--do-no-locktorture)
+   if test "$1" = --do-locktorture
+   then
+   do_locktorture=yes
+   else
+   do_locktorture=no
+   fi
+   ;;
+   --do-none)
+   do_rcutorture=no
+   do_locktorture=no
+   do_scftorture=no
+   do_rcuscale=no
+   do_refscale=no
+   do_kvfree=no
+   do_kasan=no
+   do_kcsan=no
+   ;;
+   --do-rcuscale|--do-no-rcuscale)
+   if test "$1" = --do-rcuscale
+   then
+   do_rcuscale=yes
+   else
+   do_rcuscale=no
+   fi
+   ;;
+   --do-rcutorture|--do-no-rcutorture)
+   if test "$1" = --do-rcutorture
+   then
+   do_rcutorture=yes
+   else
+   do_rcutorture=no
+   fi
+   ;;
+   --do-refscale|--do-no-refscale)
+   if test "$1" = --do-refscale
+   then
+   do_refscale=yes
+   else
+   do_refscale=no
+   fi
+   ;;
+   --do-scftorture|--do-no-scftorture)
+   if test "$1" = --do-scftorture
+   then
+   

  1   2   3   4   >