lkml.org 
[lkml]   [2017]   [Oct]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] locking/spinlock/debug: snapshot lock fields
On Mon, Oct 23, 2017 at 01:29:10PM +0100, Mark Rutland wrote:
> Currently, the lock debug code doesn't use {READ,WRITE}_ONCE() to access
> lock fields, and thus may observe torn values given a suitably unhelpful
> compiler. These could result in false positives and/or false negatives
> for some sanity checks.
>
> Further, as we don't snapshot the values of various fields, these might
> change between the time they are sanity checked and the time they are
> logged, making debugging difficult.
>
> This patch ensures that lock fields are accessed with
> {READ,WRITE}_ONCE(), and uses a snapshot of the lock to ensure that
> logged values are the same as those used for the sanity checks.
>
> Signed-off-by: Mark Rutland <mark.rutland@arm.com>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Ingo Molnar <mingo@redhat.com>

ACK, I'll try and remember to look at this if there's anything further
we can remove from this file.

> +static inline raw_spinlock_t
> +debug_spin_lock_snapshot(raw_spinlock_t *lockp)
> +{
> + raw_spinlock_t lock;
> +
> + lock.raw_lock = READ_ONCE(lockp->raw_lock);

I think you want to make that an smp_load_acquire(), such that we
preserve the release-acquire relation for the lock.

Since this happens _before_ the regular lock, but debug_spin_unlock()
also happens before the regular unlock. So the unlock release is still
placed right. But we've messed up our acquire.

> + lock.magic = READ_ONCE(lockp->magic);
> + lock.owner_cpu = READ_ONCE(lockp->owner_cpu);
> + lock.owner = READ_ONCE(lockp->owner);
> +
> + return lock;
> +}

\
 
 \ /
  Last update: 2017-10-23 15:46    [W:0.040 / U:0.492 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site