linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Byungchul Park <byungchul.park@lge.com>
To: peterz@infradead.org, mingo@kernel.org
Cc: tglx@linutronix.de, walken@google.com, boqun.feng@gmail.com,
	kirill@shutemov.name, linux-kernel@vger.kernel.org,
	linux-mm@kvack.org, iamjoonsoo.kim@lge.com,
	akpm@linux-foundation.org, npiggin@gmail.com
Subject: Re: [PATCH v5 05/13] lockdep: Pass a callback arg to check_prev_add() to handle stack_trace
Date: Thu, 26 Jan 2017 16:43:33 +0900	[thread overview]
Message-ID: <20170126074333.GA16086@X58A-UD3R> (raw)
In-Reply-To: <1484745459-2055-6-git-send-email-byungchul.park@lge.com>

I fixed a hole that peterz pointed out. And then, I think the following
is reasonable. Don't you think so?

----->8-----
commit ac185d1820ee7223773ec3e23f614c1fe5c079fc
Author: Byungchul Park <byungchul.park@lge.com>
Date:   Tue Jan 24 14:46:14 2017 +0900

    lockdep: Pass a callback arg to check_prev_add() to handle stack_trace
    
    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. 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[].
    
    In addition, check_prev_add() returns 2 in case that the lock does not
    need to be added into the dependency graph because it was already in.
    However, the return value is not used any more. So, this patch changes
    it to mean that lockdep successfully save stack_trace and add the lock
    to the graph.
    
    Signed-off-by: Byungchul Park <byungchul.park@lge.com>

diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
index 7fe6af1..9562b29 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
@@ -1862,15 +1855,12 @@ static inline void inc_chains(void)
 		if (entry->class == hlock_class(next)) {
 			if (distance == 1)
 				entry->distance = 1;
-			return 2;
+			return 1;
 		}
 	}
 
-	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));
@@ -1902,9 +1890,10 @@ static inline void inc_chains(void)
 		print_lock_name(hlock_class(next));
 		printk(KERN_CONT "\n");
 		dump_stack();
-		return graph_lock();
+		if (!graph_lock())
+			return 0;
 	}
-	return 1;
+	return 2;
 }
 
 /*
@@ -1917,8 +1906,9 @@ 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;
+	int (*save)(struct stack_trace *trace) = save_trace;
 
 	/*
 	 * Debugging checks.
@@ -1943,9 +1933,18 @@ static inline void inc_chains(void)
 		 * added:
 		 */
 		if (hlock->read != 2 && hlock->check) {
-			if (!check_prev_add(curr, hlock, next,
-						distance, &stack_saved))
+			int ret = check_prev_add(curr, hlock, next,
+						distance, &trace, save);
+			if (!ret)
 				return 0;
+
+			/*
+			 * Stop saving stack_trace if save_trace() was
+			 * called at least once:
+			 */
+			if (save && ret == 2)
+				save = NULL;
+
 			/*
 			 * Stop after the first non-trylock entry,
 			 * as non-trylock entries have added their

  reply	other threads:[~2017-01-26  7:43 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-18 13:17 [PATCH v5 00/13] lockdep: Implement crossrelease feature Byungchul Park
2017-01-18 13:17 ` [PATCH v5 01/13] lockdep: Refactor lookup_chain_cache() Byungchul Park
2017-01-19  9:16   ` Boqun Feng
2017-01-19  9:52     ` Byungchul Park
2017-01-26  7:53     ` Byungchul Park
2017-01-18 13:17 ` [PATCH v5 02/13] lockdep: Fix wrong condition to print bug msgs for MAX_LOCKDEP_CHAIN_HLOCKS Byungchul Park
2017-01-18 13:17 ` [PATCH v5 03/13] lockdep: Add a function building a chain between two classes Byungchul Park
2017-01-18 13:17 ` [PATCH v5 04/13] lockdep: Refactor save_trace() Byungchul Park
2017-01-18 13:17 ` [PATCH v5 05/13] lockdep: Pass a callback arg to check_prev_add() to handle stack_trace Byungchul Park
2017-01-26  7:43   ` Byungchul Park [this message]
2017-01-18 13:17 ` [PATCH v5 06/13] lockdep: Implement crossrelease feature Byungchul Park
2017-02-28 12:26   ` Peter Zijlstra
2017-02-28 12:45   ` Peter Zijlstra
2017-02-28 12:49     ` Peter Zijlstra
2017-03-01  6:20       ` Byungchul Park
2017-02-28 13:05   ` Peter Zijlstra
2017-02-28 13:28     ` Byungchul Park
2017-02-28 13:35       ` Peter Zijlstra
2017-02-28 14:00         ` Byungchul Park
2017-02-28 13:10   ` Peter Zijlstra
2017-02-28 13:24     ` Byungchul Park
2017-02-28 18:29       ` Peter Zijlstra
2017-03-01  4:40         ` Byungchul Park
2017-03-01 10:45           ` Peter Zijlstra
2017-03-01 12:10             ` Byungchul Park
2017-02-28 13:40   ` Peter Zijlstra
2017-03-01  5:43     ` Byungchul Park
2017-03-01 12:28       ` Peter Zijlstra
2017-03-02 13:40         ` Peter Zijlstra
2017-03-03  0:17           ` Byungchul Park
2017-03-03  8:14             ` Peter Zijlstra
2017-03-03  9:13               ` Peter Zijlstra
2017-03-03  9:32                 ` Peter Zijlstra
2017-03-05  3:33                 ` Byungchul Park
2017-08-10 12:18                 ` [tip:locking/core] locking/lockdep: Avoid creating redundant links tip-bot for Peter Zijlstra
2017-03-05  3:08               ` [PATCH v5 06/13] lockdep: Implement crossrelease feature Byungchul Park
2017-03-07 11:42                 ` Peter Zijlstra
2017-03-03  0:39           ` Byungchul Park
2017-02-28 15:49   ` Peter Zijlstra
2017-03-01  5:17     ` Byungchul Park
2017-03-01  6:18       ` Byungchul Park
2017-03-02  2:52       ` Byungchul Park
2017-02-28 18:15   ` Peter Zijlstra
2017-03-01  7:21     ` Byungchul Park
2017-03-01 10:43       ` Peter Zijlstra
2017-03-01 12:27         ` Byungchul Park
2017-03-02  4:20     ` Matthew Wilcox
2017-03-02  4:45       ` byungchul.park
2017-03-02 14:39         ` Matthew Wilcox
2017-03-02 23:50           ` Byungchul Park
2017-03-05  8:01             ` Byungchul Park
2017-03-14  7:36     ` Byungchul Park
2017-03-02 13:41   ` Peter Zijlstra
2017-03-02 23:43     ` Byungchul Park
2017-01-18 13:17 ` [PATCH v5 07/13] lockdep: Make print_circular_bug() aware of crossrelease Byungchul Park
2017-01-18 13:17 ` [PATCH v5 08/13] lockdep: Apply crossrelease to completions Byungchul Park
2017-01-18 13:17 ` [PATCH v5 09/13] pagemap.h: Remove trailing white space Byungchul Park
2017-01-18 13:17 ` [PATCH v5 10/13] lockdep: Apply crossrelease to PG_locked locks Byungchul Park
2017-01-18 13:17 ` [PATCH v5 11/13] lockdep: Apply lock_acquire(release) on __Set(__Clear)PageLocked Byungchul Park
2017-01-18 13:17 ` [PATCH v5 12/13] lockdep: Move data of CONFIG_LOCKDEP_PAGELOCK from page to page_ext Byungchul Park
2017-01-18 13:17 ` [PATCH v5 13/13] lockdep: Crossrelease feature documentation Byungchul Park
2017-01-20  9:08   ` [REVISED DOCUMENT] " Byungchul Park
2017-02-20  8:38 ` [PATCH v5 00/13] lockdep: Implement crossrelease feature Byungchul Park

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170126074333.GA16086@X58A-UD3R \
    --to=byungchul.park@lge.com \
    --cc=akpm@linux-foundation.org \
    --cc=boqun.feng@gmail.com \
    --cc=iamjoonsoo.kim@lge.com \
    --cc=kirill@shutemov.name \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mingo@kernel.org \
    --cc=npiggin@gmail.com \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=walken@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).