Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1557565 > unrolled thread

Re: [PATCH v4 05/15] lockdep: Make check_prev_add can use a separate stack_trace

Started byPeter Zijlstra <peterz@infradead.org>
First post2017-01-12 17:20 +0100
Last post2017-01-13 11:20 +0100
Articles 6 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: [PATCH v4 05/15] lockdep: Make check_prev_add can use a separate  stack_trace Peter Zijlstra <peterz@infradead.org> - 2017-01-12 17:20 +0100
    Re: [PATCH v4 05/15] lockdep: Make check_prev_add can use a separate  stack_trace Byungchul Park <byungchul.park@lge.com> - 2017-01-13 03:50 +0100
    [PATCH] lockdep: Make a stack_trace instance passed to check_prev_add as an arg Byungchul Park <byungchul.park@lge.com> - 2017-01-13 05:10 +0100
      Re: [PATCH] lockdep: Make a stack_trace instance passed to  check_prev_add as an arg Byungchul Park <byungchul.park@lge.com> - 2017-01-13 05:40 +0100
    Re: [PATCH v4 05/15] lockdep: Make check_prev_add can use a separate  stack_trace Byungchul Park <byungchul.park@lge.com> - 2017-01-13 11:20 +0100
      [PATCH 2/2] lockdep: Pass a callback arg to check_prev_add() to handle stack_trace Byungchul Park <byungchul.park@lge.com> - 2017-01-13 11:20 +0100

#1557565 — Re: [PATCH v4 05/15] lockdep: Make check_prev_add can use a separate stack_trace

FromPeter Zijlstra <peterz@infradead.org>
Date2017-01-12 17:20 +0100
SubjectRe: [PATCH v4 05/15] lockdep: Make check_prev_add can use a separate stack_trace
Message-ID<sYQgy-66R-13@gated-at.bofh.it>
On Fri, Dec 09, 2016 at 02:12:01PM +0900, Byungchul Park wrote:
> check_prev_add() saves a stack trace of the current. But crossrelease
> feature needs to use a separate stack trace of another context in
> check_prev_add(). So make it use a separate stack trace instead of one
> of the current.
> 

So I was thinking, can't we make check_prevs_add() create the stack
trace unconditionally but record if we used it or not, and then return
the entries when unused. All that is serialized by graph_lock anyway and
that way we already pass a stack into check_prev_add() so we can easily
pass in a different one.

I think that removes a bunch of tricky and avoids all the new tricky.

[toc] | [next] | [standalone]


#1557969

FromByungchul Park <byungchul.park@lge.com>
Date2017-01-13 03:50 +0100
Message-ID<sZ06d-3zV-1@gated-at.bofh.it>
In reply to#1557565
On Thu, Jan 12, 2017 at 05:16:43PM +0100, Peter Zijlstra wrote:
> On Fri, Dec 09, 2016 at 02:12:01PM +0900, Byungchul Park wrote:
> > check_prev_add() saves a stack trace of the current. But crossrelease
> > feature needs to use a separate stack trace of another context in
> > check_prev_add(). So make it use a separate stack trace instead of one
> > of the current.
> > 
> 
> So I was thinking, can't we make check_prevs_add() create the stack
> trace unconditionally but record if we used it or not, and then return
> the entries when unused. All that is serialized by graph_lock anyway and
> that way we already pass a stack into check_prev_add() so we can easily
> pass in a different one.
> 
> I think that removes a bunch of tricky and avoids all the new tricky.

Looks very good.

[toc] | [prev] | [next] | [standalone]


#1558003 — [PATCH] lockdep: Make a stack_trace instance passed to check_prev_add as an arg

FromByungchul Park <byungchul.park@lge.com>
Date2017-01-13 05:10 +0100
Subject[PATCH] lockdep: Make a stack_trace instance passed to check_prev_add as an arg
Message-ID<sZ1lE-4Bb-15@gated-at.bofh.it>
In reply to#1557565
Like this. Right?

----->8-----
From c6173f29ff9bf801649f3cbeb80a914fdf1b998b Mon Sep 17 00:00:00 2001
From: Byungchul Park <byungchul.park@lge.com>
Date: Fri, 13 Jan 2017 12:02:02 +0900
Subject: [PATCH] lockdep: Make a stack_trace instance passed to check_prev_add
 as an arg

Saving stack_trace within check_prev_add needs many tricky codes. To
avoid these, this patch makes the stack_trace instance created out of
check_prev_add, but by caller and passed as an argument.

Signed-off-by: Byungchul Park <byungchul.park@lge.com>
---
 kernel/locking/lockdep.c | 30 +++++++++---------------------
 1 file changed, 9 insertions(+), 21 deletions(-)

diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
index 2081c31..049fc71 100644
--- a/kernel/locking/lockdep.c
+++ b/kernel/locking/lockdep.c
@@ -1797,20 +1797,13 @@ static inline void inc_chains(void)
  */
 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)
 {
 	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 <prev> -> <next> dependency would not
@@ -1858,26 +1851,20 @@ static inline void inc_chains(void)
 		}
 	}
 
-	if (!*stack_saved) {
-		if (!save_trace(&trace))
-			return 0;
-		*stack_saved = 1;
-	}
-
 	/*
 	 * Ok, all validations passed, add the new lock
 	 * to the previous lock's dependency list:
 	 */
 	ret = add_lock_to_list(hlock_class(prev), hlock_class(next),
 			       &hlock_class(prev)->locks_after,
-			       next->acquire_ip, distance, &trace);
+			       next->acquire_ip, distance, trace);
 
 	if (!ret)
 		return 0;
 
 	ret = add_lock_to_list(hlock_class(next), hlock_class(prev),
 			       &hlock_class(next)->locks_before,
-			       next->acquire_ip, distance, &trace);
+			       next->acquire_ip, distance, trace);
 	if (!ret)
 		return 0;
 
@@ -1885,8 +1872,6 @@ static inline void inc_chains(void)
 	 * 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));
@@ -1909,8 +1894,8 @@ static inline void inc_chains(void)
 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;
 
 	/*
 	 * Debugging checks.
@@ -1927,6 +1912,9 @@ static inline void inc_chains(void)
 			curr->held_locks[depth-1].irq_context)
 		goto out_bug;
 
+	if (!save_trace(&trace))
+		return 0;
+
 	for (;;) {
 		int distance = curr->lockdep_depth - depth + 1;
 		hlock = curr->held_locks + depth - 1;
@@ -1936,7 +1924,7 @@ static inline void inc_chains(void)
 		 */
 		if (hlock->read != 2 && hlock->check) {
 			if (!check_prev_add(curr, hlock, next,
-						distance, &stack_saved))
+						distance, &trace))
 				return 0;
 			/*
 			 * Stop after the first non-trylock entry,
-- 
1.9.1

[toc] | [prev] | [next] | [standalone]


#1558019 — Re: [PATCH] lockdep: Make a stack_trace instance passed to check_prev_add as an arg

FromByungchul Park <byungchul.park@lge.com>
Date2017-01-13 05:40 +0100
SubjectRe: [PATCH] lockdep: Make a stack_trace instance passed to check_prev_add as an arg
Message-ID<sZ1OG-4L0-11@gated-at.bofh.it>
In reply to#1558003
On Fri, Jan 13, 2017 at 01:09:41PM +0900, Byungchul Park wrote:
> Like this. Right?

Ignore this. We need to make save_trace work in different way first.

> 
> ----->8-----
> >From c6173f29ff9bf801649f3cbeb80a914fdf1b998b Mon Sep 17 00:00:00 2001
> From: Byungchul Park <byungchul.park@lge.com>
> Date: Fri, 13 Jan 2017 12:02:02 +0900
> Subject: [PATCH] lockdep: Make a stack_trace instance passed to check_prev_add
>  as an arg
> 
> Saving stack_trace within check_prev_add needs many tricky codes. To
> avoid these, this patch makes the stack_trace instance created out of
> check_prev_add, but by caller and passed as an argument.
> 
> Signed-off-by: Byungchul Park <byungchul.park@lge.com>
> ---
>  kernel/locking/lockdep.c | 30 +++++++++---------------------
>  1 file changed, 9 insertions(+), 21 deletions(-)
> 
> diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
> index 2081c31..049fc71 100644
> --- a/kernel/locking/lockdep.c
> +++ b/kernel/locking/lockdep.c
> @@ -1797,20 +1797,13 @@ static inline void inc_chains(void)
>   */
>  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)
>  {
>  	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 <prev> -> <next> dependency would not
> @@ -1858,26 +1851,20 @@ static inline void inc_chains(void)
>  		}
>  	}
>  
> -	if (!*stack_saved) {
> -		if (!save_trace(&trace))
> -			return 0;
> -		*stack_saved = 1;
> -	}
> -
>  	/*
>  	 * Ok, all validations passed, add the new lock
>  	 * to the previous lock's dependency list:
>  	 */
>  	ret = add_lock_to_list(hlock_class(prev), hlock_class(next),
>  			       &hlock_class(prev)->locks_after,
> -			       next->acquire_ip, distance, &trace);
> +			       next->acquire_ip, distance, trace);
>  
>  	if (!ret)
>  		return 0;
>  
>  	ret = add_lock_to_list(hlock_class(next), hlock_class(prev),
>  			       &hlock_class(next)->locks_before,
> -			       next->acquire_ip, distance, &trace);
> +			       next->acquire_ip, distance, trace);
>  	if (!ret)
>  		return 0;
>  
> @@ -1885,8 +1872,6 @@ static inline void inc_chains(void)
>  	 * 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));
> @@ -1909,8 +1894,8 @@ static inline void inc_chains(void)
>  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;
>  
>  	/*
>  	 * Debugging checks.
> @@ -1927,6 +1912,9 @@ static inline void inc_chains(void)
>  			curr->held_locks[depth-1].irq_context)
>  		goto out_bug;
>  
> +	if (!save_trace(&trace))
> +		return 0;
> +
>  	for (;;) {
>  		int distance = curr->lockdep_depth - depth + 1;
>  		hlock = curr->held_locks + depth - 1;
> @@ -1936,7 +1924,7 @@ static inline void inc_chains(void)
>  		 */
>  		if (hlock->read != 2 && hlock->check) {
>  			if (!check_prev_add(curr, hlock, next,
> -						distance, &stack_saved))
> +						distance, &trace))
>  				return 0;
>  			/*
>  			 * Stop after the first non-trylock entry,
> -- 
> 1.9.1

[toc] | [prev] | [next] | [standalone]


#1558183

FromByungchul Park <byungchul.park@lge.com>
Date2017-01-13 11:20 +0100
Message-ID<sZ77H-83Q-3@gated-at.bofh.it>
In reply to#1557565
What do you think about the following patches doing it?

[toc] | [prev] | [next] | [standalone]


#1558187 — [PATCH 2/2] lockdep: Pass a callback arg to check_prev_add() to handle stack_trace

FromByungchul Park <byungchul.park@lge.com>
Date2017-01-13 11:20 +0100
Subject[PATCH 2/2] lockdep: Pass a callback arg to check_prev_add() to handle stack_trace
Message-ID<sZ77I-83Q-21@gated-at.bofh.it>
In reply to#1558183
Currently, a separate stack_trace instance cannot be used in
check_prev_add(). The simplest way to achieve it is to pass a
stack_trace instance to check_prev_add() as an argument after
saving it. However, unnecessary saving can happen if so implemented.

The proper solution is to pass a callback function additionally along
with a stack_trace so that a caller can decide the way to save, for
example, doing nothing, calling save_trace() or doing something else.

Actually, crossrelease don't need to save stack_trace of current but
only need to copy stack_traces from temporary buffers to the global
stack_trace[].

Signed-off-by: Byungchul Park <byungchul.park@lge.com>
---
 kernel/locking/lockdep.c | 38 ++++++++++++++++++--------------------
 1 file changed, 18 insertions(+), 20 deletions(-)

diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
index e63ff97..75dc14a 100644
--- a/kernel/locking/lockdep.c
+++ b/kernel/locking/lockdep.c
@@ -1805,20 +1805,13 @@ static inline void inc_chains(void)
  */
 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 <prev> -> <next> dependency would not
@@ -1866,11 +1859,8 @@ static inline void inc_chains(void)
 		}
 	}
 
-	if (!*stack_saved) {
-		if (!save_trace(&trace))
-			return 0;
-		*stack_saved = 1;
-	}
+	if (save && !save(trace))
+		return 0;
 
 	/*
 	 * Ok, all validations passed, add the new lock
@@ -1878,14 +1868,14 @@ static inline void inc_chains(void)
 	 */
 	ret = add_lock_to_list(hlock_class(prev), hlock_class(next),
 			       &hlock_class(prev)->locks_after,
-			       next->acquire_ip, distance, &trace);
+			       next->acquire_ip, distance, trace);
 
 	if (!ret)
 		return 0;
 
 	ret = add_lock_to_list(hlock_class(next), hlock_class(prev),
 			       &hlock_class(next)->locks_before,
-			       next->acquire_ip, distance, &trace);
+			       next->acquire_ip, distance, trace);
 	if (!ret)
 		return 0;
 
@@ -1893,8 +1883,6 @@ static inline void inc_chains(void)
 	 * 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));
@@ -1917,8 +1905,10 @@ static inline void inc_chains(void)
 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;
+	unsigned long start_nr = nr_stack_trace_entries;
+	int (*save)(struct stack_trace *trace) = save_trace;
 
 	/*
 	 * Debugging checks.
@@ -1944,8 +1934,16 @@ static inline void inc_chains(void)
 		 */
 		if (hlock->read != 2 && hlock->check) {
 			if (!check_prev_add(curr, hlock, next,
-						distance, &stack_saved))
+						distance, &trace, save))
 				return 0;
+
+			/*
+			 * Stop saving stack_trace if save_trace() was
+			 * called at least once:
+			 */
+			if (save && start_nr != nr_stack_trace_entries)
+				save = NULL;
+
 			/*
 			 * Stop after the first non-trylock entry,
 			 * as non-trylock entries have added their
-- 
1.9.1

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web