mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Mark Rutland <mark.rutland@arm.com>
Cc: linux-kernel@vger.kernel.org, Ingo Molnar <mingo@redhat.com>
Subject: Re: [PATCH] locking/spinlock/debug: snapshot lock fields
Date: Mon, 23 Oct 2017 15:46:22 +0200	[thread overview]
Message-ID: <20171023134622.GE3165@worktop.lehotels.local> (raw)
In-Reply-To: <20171023122910.28376-1-mark.rutland@arm.com>

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;
> +}

  reply	other threads:[~2017-10-23 13:46 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-23 12:29 Mark Rutland
2017-10-23 13:46 ` Peter Zijlstra [this message]
2017-10-23 20:22 ` kbuild test robot
2017-10-23 20:26 ` kbuild test robot

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=20171023134622.GE3165@worktop.lehotels.local \
    --to=peterz@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.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

all inboxes | Powered by JetHome®