lkml.org 
[lkml]   [2017]   [Oct]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
SubjectRe: [PATCH 1/2] security/apparmor: Replace homebrew use of write_can_lock with lockdep
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 <john.johansen@canonical.com>
> > Cc: Peter Zijlstra <peterz@infradead.org>
> > Signed-off-by: Will Deacon <will.deacon@arm.com>
>
> 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 <linux/rwlock.h>

@@ -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; \
\
 
 \ /
  Last update: 2017-10-03 18:59    [W:0.048 / U:39.420 seconds]
©2003-2017 Jasper Spaans. hosted at Digital OceanAdvertise on this site