From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932354AbdJWNqc (ORCPT ); Mon, 23 Oct 2017 09:46:32 -0400 Received: from merlin.infradead.org ([205.233.59.134]:52892 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932245AbdJWNqb (ORCPT ); Mon, 23 Oct 2017 09:46:31 -0400 Date: Mon, 23 Oct 2017 15:46:22 +0200 From: Peter Zijlstra To: Mark Rutland Cc: linux-kernel@vger.kernel.org, Ingo Molnar Subject: Re: [PATCH] locking/spinlock/debug: snapshot lock fields Message-ID: <20171023134622.GE3165@worktop.lehotels.local> References: <20171023122910.28376-1-mark.rutland@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20171023122910.28376-1-mark.rutland@arm.com> User-Agent: Mutt/1.5.22.1 (2013-10-16) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > Cc: Peter Zijlstra > Cc: Ingo Molnar 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; > +}