Skip to content

Commit

Permalink
locking/lockdep: Fix the rollback and overwrite detection logic in cr…
Browse files Browse the repository at this point in the history
…ossrelease

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>
  • Loading branch information
Byungchul Park authored and Ingo Molnar committed Aug 14, 2017
1 parent a10b5c5 commit 907dc16
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions kernel/locking/lockdep.c
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 907dc16

Please sign in to comment.