linux-mm.kvack.org archive mirror
 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; 3+ 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

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 3+ 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  7:00 ` [PATCH 2/2] lockdep: Fix the rollback and overwrite detection in crossrelease Byungchul Park
  1 sibling, 0 replies; 3+ 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

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 3+ 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
  1 sibling, 0 replies; 3+ 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

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

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

Thread overview: 3+ 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  7:00 ` [PATCH 2/2] lockdep: Fix the rollback and overwrite detection in crossrelease Byungchul Park

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