[tip:locking/core] locking/lockdep: Make check_prev_add() able to handle external stack_trace

2017-08-10 Thread tip-bot for Byungchul Park
Commit-ID:  ce07a9415f266e181a0a33033a5f7138760240a4
Gitweb: http://git.kernel.org/tip/ce07a9415f266e181a0a33033a5f7138760240a4
Author: Byungchul Park 
AuthorDate: Mon, 7 Aug 2017 16:12:51 +0900
Committer:  Ingo Molnar 
CommitDate: Thu, 10 Aug 2017 12:29:06 +0200

locking/lockdep: Make check_prev_add() able to handle external stack_trace

Currently, a space for stack_trace is pinned in check_prev_add(), that
makes us not able to use external stack_trace. The simplest way to
achieve it is to pass an external stack_trace as an argument.

A more suitable solution is to pass a callback additionally along with
a stack_trace so that callers can decide the way to save or whether to
save. Actually crossrelease needs to do other than saving a stack_trace.
So pass a stack_trace and callback to handle it, to check_prev_add().

Signed-off-by: Byungchul Park 
Signed-off-by: Peter Zijlstra (Intel) 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: a...@linux-foundation.org
Cc: boqun.f...@gmail.com
Cc: kernel-t...@lge.com
Cc: kir...@shutemov.name
Cc: npig...@gmail.com
Cc: wal...@google.com
Cc: wi...@infradead.org
Link: 
http://lkml.kernel.org/r/1502089981-21272-5-git-send-email-byungchul.p...@lge.com
Signed-off-by: Ingo Molnar 
---
 kernel/locking/lockdep.c | 40 +++-
 1 file changed, 19 insertions(+), 21 deletions(-)

diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
index 7cf02fa..841828b 100644
--- a/kernel/locking/lockdep.c
+++ b/kernel/locking/lockdep.c
@@ -1824,20 +1824,13 @@ check_deadlock(struct task_struct *curr, struct 
held_lock *next,
  */
 static int
 check_prev_add(struct task_struct *curr, struct held_lock *prev,
-  struct held_lock *next, int distance, int *stack_saved)
+  struct held_lock *next, int distance, struct stack_trace *trace,
+  int (*save)(struct stack_trace *trace))
 {
struct lock_list *entry;
int ret;
struct lock_list this;
struct lock_list *uninitialized_var(target_entry);
-   /*
-* Static variable, serialized by the graph_lock().
-*
-* We use this static variable to save the stack trace in case
-* we call into this function multiple times due to encountering
-* trylocks in the held lock stack.
-*/
-   static struct stack_trace trace;
 
/*
 * Prove that the new  ->  dependency would not
@@ -1899,11 +1892,8 @@ check_prev_add(struct task_struct *curr, struct 
held_lock *prev,
return print_bfs_bug(ret);
 
 
-   if (!*stack_saved) {
-   if (!save_trace())
-   return 0;
-   *stack_saved = 1;
-   }
+   if (save && !save(trace))
+   return 0;
 
/*
 * Ok, all validations passed, add the new lock
@@ -1911,14 +1901,14 @@ check_prev_add(struct task_struct *curr, struct 
held_lock *prev,
 */
ret = add_lock_to_list(hlock_class(next),
   _class(prev)->locks_after,
-  next->acquire_ip, distance, );
+  next->acquire_ip, distance, trace);
 
if (!ret)
return 0;
 
ret = add_lock_to_list(hlock_class(prev),
   _class(next)->locks_before,
-  next->acquire_ip, distance, );
+  next->acquire_ip, distance, trace);
if (!ret)
return 0;
 
@@ -1926,8 +1916,6 @@ check_prev_add(struct task_struct *curr, struct held_lock 
*prev,
 * Debugging printouts:
 */
if (verbose(hlock_class(prev)) || verbose(hlock_class(next))) {
-   /* We drop graph lock, so another thread can overwrite trace. */
-   *stack_saved = 0;
graph_unlock();
printk("\n new dependency: ");
print_lock_name(hlock_class(prev));
@@ -1951,8 +1939,9 @@ static int
 check_prevs_add(struct task_struct *curr, struct held_lock *next)
 {
int depth = curr->lockdep_depth;
-   int stack_saved = 0;
struct held_lock *hlock;
+   struct stack_trace trace;
+   int (*save)(struct stack_trace *trace) = save_trace;
 
/*
 * Debugging checks.
@@ -1977,9 +1966,18 @@ check_prevs_add(struct task_struct *curr, struct 
held_lock *next)
 * added:
 */
if (hlock->read != 2 && hlock->check) {
-   if (!check_prev_add(curr, hlock, next,
-   distance, _saved))
+   int ret = check_prev_add(curr, hlock, next,
+   distance, , save);
+   if (!ret)
   

[tip:locking/core] locking/lockdep: Make check_prev_add() able to handle external stack_trace

2017-08-10 Thread tip-bot for Byungchul Park
Commit-ID:  ce07a9415f266e181a0a33033a5f7138760240a4
Gitweb: http://git.kernel.org/tip/ce07a9415f266e181a0a33033a5f7138760240a4
Author: Byungchul Park 
AuthorDate: Mon, 7 Aug 2017 16:12:51 +0900
Committer:  Ingo Molnar 
CommitDate: Thu, 10 Aug 2017 12:29:06 +0200

locking/lockdep: Make check_prev_add() able to handle external stack_trace

Currently, a space for stack_trace is pinned in check_prev_add(), that
makes us not able to use external stack_trace. The simplest way to
achieve it is to pass an external stack_trace as an argument.

A more suitable solution is to pass a callback additionally along with
a stack_trace so that callers can decide the way to save or whether to
save. Actually crossrelease needs to do other than saving a stack_trace.
So pass a stack_trace and callback to handle it, to check_prev_add().

Signed-off-by: Byungchul Park 
Signed-off-by: Peter Zijlstra (Intel) 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: a...@linux-foundation.org
Cc: boqun.f...@gmail.com
Cc: kernel-t...@lge.com
Cc: kir...@shutemov.name
Cc: npig...@gmail.com
Cc: wal...@google.com
Cc: wi...@infradead.org
Link: 
http://lkml.kernel.org/r/1502089981-21272-5-git-send-email-byungchul.p...@lge.com
Signed-off-by: Ingo Molnar 
---
 kernel/locking/lockdep.c | 40 +++-
 1 file changed, 19 insertions(+), 21 deletions(-)

diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
index 7cf02fa..841828b 100644
--- a/kernel/locking/lockdep.c
+++ b/kernel/locking/lockdep.c
@@ -1824,20 +1824,13 @@ check_deadlock(struct task_struct *curr, struct 
held_lock *next,
  */
 static int
 check_prev_add(struct task_struct *curr, struct held_lock *prev,
-  struct held_lock *next, int distance, int *stack_saved)
+  struct held_lock *next, int distance, struct stack_trace *trace,
+  int (*save)(struct stack_trace *trace))
 {
struct lock_list *entry;
int ret;
struct lock_list this;
struct lock_list *uninitialized_var(target_entry);
-   /*
-* Static variable, serialized by the graph_lock().
-*
-* We use this static variable to save the stack trace in case
-* we call into this function multiple times due to encountering
-* trylocks in the held lock stack.
-*/
-   static struct stack_trace trace;
 
/*
 * Prove that the new  ->  dependency would not
@@ -1899,11 +1892,8 @@ check_prev_add(struct task_struct *curr, struct 
held_lock *prev,
return print_bfs_bug(ret);
 
 
-   if (!*stack_saved) {
-   if (!save_trace())
-   return 0;
-   *stack_saved = 1;
-   }
+   if (save && !save(trace))
+   return 0;
 
/*
 * Ok, all validations passed, add the new lock
@@ -1911,14 +1901,14 @@ check_prev_add(struct task_struct *curr, struct 
held_lock *prev,
 */
ret = add_lock_to_list(hlock_class(next),
   _class(prev)->locks_after,
-  next->acquire_ip, distance, );
+  next->acquire_ip, distance, trace);
 
if (!ret)
return 0;
 
ret = add_lock_to_list(hlock_class(prev),
   _class(next)->locks_before,
-  next->acquire_ip, distance, );
+  next->acquire_ip, distance, trace);
if (!ret)
return 0;
 
@@ -1926,8 +1916,6 @@ check_prev_add(struct task_struct *curr, struct held_lock 
*prev,
 * Debugging printouts:
 */
if (verbose(hlock_class(prev)) || verbose(hlock_class(next))) {
-   /* We drop graph lock, so another thread can overwrite trace. */
-   *stack_saved = 0;
graph_unlock();
printk("\n new dependency: ");
print_lock_name(hlock_class(prev));
@@ -1951,8 +1939,9 @@ static int
 check_prevs_add(struct task_struct *curr, struct held_lock *next)
 {
int depth = curr->lockdep_depth;
-   int stack_saved = 0;
struct held_lock *hlock;
+   struct stack_trace trace;
+   int (*save)(struct stack_trace *trace) = save_trace;
 
/*
 * Debugging checks.
@@ -1977,9 +1966,18 @@ check_prevs_add(struct task_struct *curr, struct 
held_lock *next)
 * added:
 */
if (hlock->read != 2 && hlock->check) {
-   if (!check_prev_add(curr, hlock, next,
-   distance, _saved))
+   int ret = check_prev_add(curr, hlock, next,
+   distance, , save);
+   if (!ret)
return 0;
+
+   /*
+* Stop saving stack_trace if save_trace() was
+* called at