mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/2] Fix a bug in crossrelease
@ 2017-08-14  7:00 Byungchul Park
  2017-08-14  7:00 ` [PATCH 1/2] lockdep: Add a comment about crossrelease_hist_end() in lockdep_sys_exit() Byungchul Park
  2017-08-14  7:00 ` [PATCH 2/2] lockdep: Fix the rollback and overwrite detection in crossrelease Byungchul Park
  0 siblings, 2 replies; 5+ messages in thread
From: Byungchul Park @ 2017-08-14  7:00 UTC (permalink / raw)
  To: peterz, mingo
  Cc: tglx, walken, boqun.feng, kirill, linux-kernel, linux-mm, akpm,
	willy, npiggin, kernel-team

Thanks to Boqun, we found out a bug with regard to the rollback and
overwrite-detection. I like Boqun's or Peterz's suggestions more, but
please consider this fix-up first if we need time to decide which one
to choose.

https://lkml.org/lkml/2017/8/11/383

Byungchul Park (2):
  lockdep: Add a comment about crossrelease_hist_end() in
    lockdep_sys_exit()
  lockdep: Fix the rollback and overwrite detection in crossrelease

 kernel/locking/lockdep.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

-- 
1.9.1

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] lockdep: Add a comment about crossrelease_hist_end() in lockdep_sys_exit()
  2017-08-14  7:00 [PATCH 0/2] Fix a bug in crossrelease Byungchul Park
@ 2017-08-14  7:00 ` Byungchul Park
  2017-08-14 11:45   ` [tip:locking/core] locking/lockdep: " tip-bot for Byungchul Park
  2017-08-14  7:00 ` [PATCH 2/2] lockdep: Fix the rollback and overwrite detection in crossrelease Byungchul Park
  1 sibling, 1 reply; 5+ messages in thread
From: Byungchul Park @ 2017-08-14  7:00 UTC (permalink / raw)
  To: peterz, mingo
  Cc: tglx, walken, boqun.feng, kirill, linux-kernel, linux-mm, akpm,
	willy, npiggin, kernel-team

In lockdep_sys_exit(), crossrelease_hist_end() is called unconditionally
even when getting here without having started e.g. just after forked.
But it's no problem since it anyway would rollback to an invalid element.
A comment would be helpful to understand this situation.

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

diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
index 1114dc4..1ae4258 100644
--- a/kernel/locking/lockdep.c
+++ b/kernel/locking/lockdep.c
@@ -4623,6 +4623,10 @@ asmlinkage __visible void lockdep_sys_exit(void)
 	/*
 	 * The lock history for each syscall should be independent. So wipe the
 	 * slate clean on return to userspace.
+	 *
+	 * crossrelease_hist_end() would work well even when getting here
+	 * without starting just after forked, it rollbacks back the index
+	 * to point to the last which is already invalid.
 	 */
 	crossrelease_hist_end(XHLOCK_PROC);
 	crossrelease_hist_start(XHLOCK_PROC);
-- 
1.9.1

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2/2] lockdep: Fix the rollback and overwrite detection in crossrelease
  2017-08-14  7:00 [PATCH 0/2] Fix a bug in crossrelease Byungchul Park
  2017-08-14  7:00 ` [PATCH 1/2] lockdep: Add a comment about crossrelease_hist_end() in lockdep_sys_exit() Byungchul Park
@ 2017-08-14  7:00 ` Byungchul Park
  2017-08-14 11:46   ` [tip:locking/core] locking/lockdep: Fix the rollback and overwrite detection logic " tip-bot for Byungchul Park
  1 sibling, 1 reply; 5+ messages in thread
From: Byungchul Park @ 2017-08-14  7:00 UTC (permalink / raw)
  To: peterz, mingo
  Cc: tglx, walken, boqun.feng, kirill, linux-kernel, linux-mm, akpm,
	willy, npiggin, kernel-team

As Boqun pointed out, current->hist_id should be aligned with the latest
valid xhlock->hist_id so that hist_id_save[] storing current->hist_id
can be comparable with xhlock->hist_id. Fix it.

Additionally, the condition for overwrite-detection should be the
opposite. Fix it with modifying comment.

           <- direction to visit
hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh (h: history)
                 ^^        ^
                 ||        start from here
                 |previous entry
                 current entry

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

diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
index 1ae4258..f0e6649 100644
--- a/kernel/locking/lockdep.c
+++ b/kernel/locking/lockdep.c
@@ -4853,7 +4853,7 @@ static void add_xhlock(struct held_lock *hlock)
 
 	/* Initialize hist_lock's members */
 	xhlock->hlock = *hlock;
-	xhlock->hist_id = current->hist_id++;
+	xhlock->hist_id = ++current->hist_id;
 
 	xhlock->trace.nr_entries = 0;
 	xhlock->trace.max_entries = MAX_XHLOCK_TRACE_ENTRIES;
@@ -5030,11 +5030,11 @@ static void commit_xhlocks(struct cross_lock *xlock)
 
 			/*
 			 * Filter out the cases that the ring buffer was
-			 * overwritten and the previous entry has a bigger
-			 * hist_id than the following one, which is impossible
+			 * overwritten and the current entry has a bigger
+			 * hist_id than the previous one, which is impossible
 			 * otherwise.
 			 */
-			if (unlikely(before(xhlock->hist_id, prev_hist_id)))
+			if (unlikely(before(prev_hist_id, xhlock->hist_id)))
 				break;
 
 			prev_hist_id = xhlock->hist_id;
-- 
1.9.1

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [tip:locking/core] locking/lockdep: Add a comment about crossrelease_hist_end() in lockdep_sys_exit()
  2017-08-14  7:00 ` [PATCH 1/2] lockdep: Add a comment about crossrelease_hist_end() in lockdep_sys_exit() Byungchul Park
@ 2017-08-14 11:45   ` tip-bot for Byungchul Park
  0 siblings, 0 replies; 5+ messages in thread
From: tip-bot for Byungchul Park @ 2017-08-14 11:45 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: byungchul.park, hpa, linux-kernel, peterz, mingo, tglx, torvalds

Commit-ID:  a10b5c564741cd3b6708f085a1fa892b63c2063d
Gitweb:     http://git.kernel.org/tip/a10b5c564741cd3b6708f085a1fa892b63c2063d
Author:     Byungchul Park <byungchul.park@lge.com>
AuthorDate: Mon, 14 Aug 2017 16:00:51 +0900
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Mon, 14 Aug 2017 12:52:17 +0200

locking/lockdep: Add a comment about crossrelease_hist_end() in lockdep_sys_exit()

In lockdep_sys_exit(), crossrelease_hist_end() is called unconditionally
even when getting here without having started e.g. just after forking.

But it's no problem since it would roll back to an invalid entry anyway.
Add a comment to explain this.

Signed-off-by: Byungchul Park <byungchul.park@lge.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: akpm@linux-foundation.org
Cc: boqun.feng@gmail.com
Cc: kernel-team@lge.com
Cc: kirill@shutemov.name
Cc: linux-mm@kvack.org
Cc: npiggin@gmail.com
Cc: walken@google.com
Cc: willy@infradead.org
Link: http://lkml.kernel.org/r/1502694052-16085-2-git-send-email-byungchul.park@lge.com
[ Improved the description and the comments. ]
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 kernel/locking/lockdep.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
index 1114dc4..257931e 100644
--- a/kernel/locking/lockdep.c
+++ b/kernel/locking/lockdep.c
@@ -4623,6 +4623,10 @@ asmlinkage __visible void lockdep_sys_exit(void)
 	/*
 	 * The lock history for each syscall should be independent. So wipe the
 	 * slate clean on return to userspace.
+	 *
+	 * crossrelease_hist_end() works well here even when getting here
+	 * without starting (i.e. just after forking), because it rolls back
+	 * the index to point to the last entry, which is already invalid.
 	 */
 	crossrelease_hist_end(XHLOCK_PROC);
 	crossrelease_hist_start(XHLOCK_PROC);

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [tip:locking/core] locking/lockdep: Fix the rollback and overwrite detection logic in crossrelease
  2017-08-14  7:00 ` [PATCH 2/2] lockdep: Fix the rollback and overwrite detection in crossrelease Byungchul Park
@ 2017-08-14 11:46   ` tip-bot for Byungchul Park
  0 siblings, 0 replies; 5+ messages in thread
From: tip-bot for Byungchul Park @ 2017-08-14 11:46 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: hpa, byungchul.park, peterz, boqun.feng, torvalds, mingo, tglx,
	linux-kernel

Commit-ID:  907dc16d7e23ec81a126c9585435494fa1b3a4b7
Gitweb:     http://git.kernel.org/tip/907dc16d7e23ec81a126c9585435494fa1b3a4b7
Author:     Byungchul Park <byungchul.park@lge.com>
AuthorDate: Mon, 14 Aug 2017 16:00:52 +0900
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Mon, 14 Aug 2017 12:52:17 +0200

locking/lockdep: Fix the rollback and overwrite detection logic in crossrelease

As Boqun Feng pointed out, current->hist_id should be aligned with the
latest valid xhlock->hist_id so that hist_id_save[] storing current->hist_id
can be comparable with xhlock->hist_id. Fix it.

Additionally, the condition for overwrite-detection should be the
opposite. Fix the code and the comments as well.

           <- direction to visit
hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh (h: history)
                 ^^        ^
                 ||        start from here
                 |previous entry
                 current entry

Reported-by: Boqun Feng <boqun.feng@gmail.com>
Signed-off-by: Byungchul Park <byungchul.park@lge.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: akpm@linux-foundation.org
Cc: kernel-team@lge.com
Cc: kirill@shutemov.name
Cc: linux-mm@kvack.org
Cc: npiggin@gmail.com
Cc: walken@google.com
Cc: willy@infradead.org
Link: http://lkml.kernel.org/r/1502694052-16085-3-git-send-email-byungchul.park@lge.com
[ Improve the comments some more. ]
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 kernel/locking/lockdep.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
index 257931e..66011c9 100644
--- a/kernel/locking/lockdep.c
+++ b/kernel/locking/lockdep.c
@@ -4853,7 +4853,7 @@ static void add_xhlock(struct held_lock *hlock)
 
 	/* Initialize hist_lock's members */
 	xhlock->hlock = *hlock;
-	xhlock->hist_id = current->hist_id++;
+	xhlock->hist_id = ++current->hist_id;
 
 	xhlock->trace.nr_entries = 0;
 	xhlock->trace.max_entries = MAX_XHLOCK_TRACE_ENTRIES;
@@ -5029,12 +5029,12 @@ static void commit_xhlocks(struct cross_lock *xlock)
 				break;
 
 			/*
-			 * Filter out the cases that the ring buffer was
-			 * overwritten and the previous entry has a bigger
-			 * hist_id than the following one, which is impossible
-			 * otherwise.
+			 * Filter out the cases where the ring buffer was
+			 * overwritten and the current entry has a bigger
+			 * hist_id than the previous one, which is impossible
+			 * otherwise:
 			 */
-			if (unlikely(before(xhlock->hist_id, prev_hist_id)))
+			if (unlikely(before(prev_hist_id, xhlock->hist_id)))
 				break;
 
 			prev_hist_id = xhlock->hist_id;

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-08-14 11:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-14  7:00 [PATCH 0/2] Fix a bug in crossrelease Byungchul Park
2017-08-14  7:00 ` [PATCH 1/2] lockdep: Add a comment about crossrelease_hist_end() in lockdep_sys_exit() Byungchul Park
2017-08-14 11:45   ` [tip:locking/core] locking/lockdep: " tip-bot for Byungchul Park
2017-08-14  7:00 ` [PATCH 2/2] lockdep: Fix the rollback and overwrite detection in crossrelease Byungchul Park
2017-08-14 11:46   ` [tip:locking/core] locking/lockdep: Fix the rollback and overwrite detection logic " tip-bot for Byungchul Park

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome