From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752086AbdJCQ6t (ORCPT ); Tue, 3 Oct 2017 12:58:49 -0400 Received: from foss.arm.com ([217.140.101.70]:51676 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751649AbdJCQ6s (ORCPT ); Tue, 3 Oct 2017 12:58:48 -0400 Date: Tue, 3 Oct 2017 17:58:48 +0100 From: Will Deacon To: Peter Zijlstra Cc: linux-kernel@vger.kernel.org, john.johansen@canonical.com, paulmck@linux.vnet.ibm.com Subject: Re: [PATCH 1/2] security/apparmor: Replace homebrew use of write_can_lock with lockdep Message-ID: <20171003165848.GA12696@arm.com> References: <1507041166-10618-1-git-send-email-will.deacon@arm.com> <20171003150709.53fz7daydyomfuly@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20171003150709.53fz7daydyomfuly@hirez.programming.kicks-ass.net> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 03, 2017 at 05:07:09PM +0200, Peter Zijlstra wrote: > On Tue, Oct 03, 2017 at 03:32:45PM +0100, Will Deacon wrote: > > The lockdep subsystem provides a robust way to assert that a lock is > > held, so use that instead of write_can_lock, which can give incorrect > > results for qrwlocks. > > > > Cc: John Johansen > > Cc: Peter Zijlstra > > Signed-off-by: Will Deacon > > Thanks Will, good to be able to finally remove that API. Yup, but my grep-fu missed these guys in kernel/locking/spinlock.c: while (!raw_##op##_can_lock(lock) && (lock)->break_lock so diff below to catch those and remove spin_can_lock too. Let me spin a v2... Will --->8 diff --git a/include/linux/spinlock.h b/include/linux/spinlock.h index 69e079c5ff98..1e3e48041800 100644 --- a/include/linux/spinlock.h +++ b/include/linux/spinlock.h @@ -278,12 +278,6 @@ static inline void do_raw_spin_unlock(raw_spinlock_t *lock) __releases(lock) 1 : ({ local_irq_restore(flags); 0; }); \ }) -/** - * raw_spin_can_lock - would raw_spin_trylock() succeed? - * @lock: the spinlock in question. - */ -#define raw_spin_can_lock(lock) (!raw_spin_is_locked(lock)) - /* Include rwlock functions */ #include @@ -396,11 +390,6 @@ static __always_inline int spin_is_contended(spinlock_t *lock) return raw_spin_is_contended(&lock->rlock); } -static __always_inline int spin_can_lock(spinlock_t *lock) -{ - return raw_spin_can_lock(&lock->rlock); -} - #define assert_spin_locked(lock) assert_raw_spin_locked(&(lock)->rlock) /* diff --git a/kernel/locking/spinlock.c b/kernel/locking/spinlock.c index 42ee9d0a1ea4..8fd48b5552a7 100644 --- a/kernel/locking/spinlock.c +++ b/kernel/locking/spinlock.c @@ -66,7 +66,7 @@ void __lockfunc __raw_##op##_lock(locktype##_t *lock) \ \ if (!(lock)->break_lock) \ (lock)->break_lock = 1; \ - while (!raw_##op##_can_lock(lock) && (lock)->break_lock)\ + while ((lock)->break_lock) \ arch_##op##_relax(&lock->raw_lock); \ } \ (lock)->break_lock = 0; \ @@ -86,7 +86,7 @@ unsigned long __lockfunc __raw_##op##_lock_irqsave(locktype##_t *lock) \ \ if (!(lock)->break_lock) \ (lock)->break_lock = 1; \ - while (!raw_##op##_can_lock(lock) && (lock)->break_lock)\ + while ((lock)->break_lock) \ arch_##op##_relax(&lock->raw_lock); \ } \ (lock)->break_lock = 0; \