2009-11-17 01:48:37 +08:00
|
|
|
#ifndef __LINUX_RWLOCK_API_SMP_H
|
|
|
|
#define __LINUX_RWLOCK_API_SMP_H
|
|
|
|
|
|
|
|
#ifndef __LINUX_SPINLOCK_API_SMP_H
|
|
|
|
# error "please don't include this file directly"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* include/linux/rwlock_api_smp.h
|
|
|
|
*
|
|
|
|
* spinlock API declarations on SMP (and debug)
|
|
|
|
* (implemented in kernel/spinlock.c)
|
|
|
|
*
|
|
|
|
* portions Copyright 2005, Red Hat, Inc., Ingo Molnar
|
|
|
|
* Released under the General Public License (GPL).
|
|
|
|
*/
|
|
|
|
|
2009-12-04 04:52:18 +08:00
|
|
|
void __lockfunc _raw_read_lock(rwlock_t *lock) __acquires(lock);
|
|
|
|
void __lockfunc _raw_write_lock(rwlock_t *lock) __acquires(lock);
|
2022-01-22 14:14:10 +08:00
|
|
|
void __lockfunc _raw_write_lock_nested(rwlock_t *lock, int subclass) __acquires(lock);
|
2009-12-04 04:52:18 +08:00
|
|
|
void __lockfunc _raw_read_lock_bh(rwlock_t *lock) __acquires(lock);
|
|
|
|
void __lockfunc _raw_write_lock_bh(rwlock_t *lock) __acquires(lock);
|
|
|
|
void __lockfunc _raw_read_lock_irq(rwlock_t *lock) __acquires(lock);
|
|
|
|
void __lockfunc _raw_write_lock_irq(rwlock_t *lock) __acquires(lock);
|
|
|
|
unsigned long __lockfunc _raw_read_lock_irqsave(rwlock_t *lock)
|
2009-11-17 01:48:37 +08:00
|
|
|
__acquires(lock);
|
2009-12-04 04:52:18 +08:00
|
|
|
unsigned long __lockfunc _raw_write_lock_irqsave(rwlock_t *lock)
|
2009-11-17 01:48:37 +08:00
|
|
|
__acquires(lock);
|
2009-12-04 04:52:18 +08:00
|
|
|
int __lockfunc _raw_read_trylock(rwlock_t *lock);
|
|
|
|
int __lockfunc _raw_write_trylock(rwlock_t *lock);
|
|
|
|
void __lockfunc _raw_read_unlock(rwlock_t *lock) __releases(lock);
|
|
|
|
void __lockfunc _raw_write_unlock(rwlock_t *lock) __releases(lock);
|
|
|
|
void __lockfunc _raw_read_unlock_bh(rwlock_t *lock) __releases(lock);
|
|
|
|
void __lockfunc _raw_write_unlock_bh(rwlock_t *lock) __releases(lock);
|
|
|
|
void __lockfunc _raw_read_unlock_irq(rwlock_t *lock) __releases(lock);
|
|
|
|
void __lockfunc _raw_write_unlock_irq(rwlock_t *lock) __releases(lock);
|
|
|
|
void __lockfunc
|
|
|
|
_raw_read_unlock_irqrestore(rwlock_t *lock, unsigned long flags)
|
2009-11-17 01:48:37 +08:00
|
|
|
__releases(lock);
|
2009-12-04 04:52:18 +08:00
|
|
|
void __lockfunc
|
|
|
|
_raw_write_unlock_irqrestore(rwlock_t *lock, unsigned long flags)
|
2009-11-17 01:48:37 +08:00
|
|
|
__releases(lock);
|
|
|
|
|
|
|
|
#ifdef CONFIG_INLINE_READ_LOCK
|
2009-12-04 04:52:18 +08:00
|
|
|
#define _raw_read_lock(lock) __raw_read_lock(lock)
|
2009-11-17 01:48:37 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_INLINE_WRITE_LOCK
|
2009-12-04 04:52:18 +08:00
|
|
|
#define _raw_write_lock(lock) __raw_write_lock(lock)
|
2009-11-17 01:48:37 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_INLINE_READ_LOCK_BH
|
2009-12-04 04:52:18 +08:00
|
|
|
#define _raw_read_lock_bh(lock) __raw_read_lock_bh(lock)
|
2009-11-17 01:48:37 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_INLINE_WRITE_LOCK_BH
|
2009-12-04 04:52:18 +08:00
|
|
|
#define _raw_write_lock_bh(lock) __raw_write_lock_bh(lock)
|
2009-11-17 01:48:37 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_INLINE_READ_LOCK_IRQ
|
2009-12-04 04:52:18 +08:00
|
|
|
#define _raw_read_lock_irq(lock) __raw_read_lock_irq(lock)
|
2009-11-17 01:48:37 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_INLINE_WRITE_LOCK_IRQ
|
2009-12-04 04:52:18 +08:00
|
|
|
#define _raw_write_lock_irq(lock) __raw_write_lock_irq(lock)
|
2009-11-17 01:48:37 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_INLINE_READ_LOCK_IRQSAVE
|
2009-12-04 04:52:18 +08:00
|
|
|
#define _raw_read_lock_irqsave(lock) __raw_read_lock_irqsave(lock)
|
2009-11-17 01:48:37 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_INLINE_WRITE_LOCK_IRQSAVE
|
2009-12-04 04:52:18 +08:00
|
|
|
#define _raw_write_lock_irqsave(lock) __raw_write_lock_irqsave(lock)
|
2009-11-17 01:48:37 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_INLINE_READ_TRYLOCK
|
2009-12-04 04:52:18 +08:00
|
|
|
#define _raw_read_trylock(lock) __raw_read_trylock(lock)
|
2009-11-17 01:48:37 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_INLINE_WRITE_TRYLOCK
|
2009-12-04 04:52:18 +08:00
|
|
|
#define _raw_write_trylock(lock) __raw_write_trylock(lock)
|
2009-11-17 01:48:37 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_INLINE_READ_UNLOCK
|
2009-12-04 04:52:18 +08:00
|
|
|
#define _raw_read_unlock(lock) __raw_read_unlock(lock)
|
2009-11-17 01:48:37 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_INLINE_WRITE_UNLOCK
|
2009-12-04 04:52:18 +08:00
|
|
|
#define _raw_write_unlock(lock) __raw_write_unlock(lock)
|
2009-11-17 01:48:37 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_INLINE_READ_UNLOCK_BH
|
2009-12-04 04:52:18 +08:00
|
|
|
#define _raw_read_unlock_bh(lock) __raw_read_unlock_bh(lock)
|
2009-11-17 01:48:37 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_INLINE_WRITE_UNLOCK_BH
|
2009-12-04 04:52:18 +08:00
|
|
|
#define _raw_write_unlock_bh(lock) __raw_write_unlock_bh(lock)
|
2009-11-17 01:48:37 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_INLINE_READ_UNLOCK_IRQ
|
2009-12-04 04:52:18 +08:00
|
|
|
#define _raw_read_unlock_irq(lock) __raw_read_unlock_irq(lock)
|
2009-11-17 01:48:37 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_INLINE_WRITE_UNLOCK_IRQ
|
2009-12-04 04:52:18 +08:00
|
|
|
#define _raw_write_unlock_irq(lock) __raw_write_unlock_irq(lock)
|
2009-11-17 01:48:37 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_INLINE_READ_UNLOCK_IRQRESTORE
|
2009-12-04 04:52:18 +08:00
|
|
|
#define _raw_read_unlock_irqrestore(lock, flags) \
|
|
|
|
__raw_read_unlock_irqrestore(lock, flags)
|
2009-11-17 01:48:37 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_INLINE_WRITE_UNLOCK_IRQRESTORE
|
2009-12-04 04:52:18 +08:00
|
|
|
#define _raw_write_unlock_irqrestore(lock, flags) \
|
|
|
|
__raw_write_unlock_irqrestore(lock, flags)
|
2009-11-17 01:48:37 +08:00
|
|
|
#endif
|
|
|
|
|
2009-12-04 04:52:18 +08:00
|
|
|
static inline int __raw_read_trylock(rwlock_t *lock)
|
2009-11-17 01:48:37 +08:00
|
|
|
{
|
|
|
|
preempt_disable();
|
2009-12-04 03:55:53 +08:00
|
|
|
if (do_raw_read_trylock(lock)) {
|
2009-11-17 01:48:37 +08:00
|
|
|
rwlock_acquire_read(&lock->dep_map, 0, 1, _RET_IP_);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
preempt_enable();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-12-04 04:52:18 +08:00
|
|
|
static inline int __raw_write_trylock(rwlock_t *lock)
|
2009-11-17 01:48:37 +08:00
|
|
|
{
|
|
|
|
preempt_disable();
|
2009-12-04 03:55:53 +08:00
|
|
|
if (do_raw_write_trylock(lock)) {
|
2009-11-17 01:48:37 +08:00
|
|
|
rwlock_acquire(&lock->dep_map, 0, 1, _RET_IP_);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
preempt_enable();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If lockdep is enabled then we use the non-preemption spin-ops
|
|
|
|
* even on CONFIG_PREEMPT, because lockdep assumes that interrupts are
|
|
|
|
* not re-enabled during lock-acquire (which the preempt-spin-ops do):
|
|
|
|
*/
|
|
|
|
#if !defined(CONFIG_GENERIC_LOCKBREAK) || defined(CONFIG_DEBUG_LOCK_ALLOC)
|
|
|
|
|
2009-12-04 04:52:18 +08:00
|
|
|
static inline void __raw_read_lock(rwlock_t *lock)
|
2009-11-17 01:48:37 +08:00
|
|
|
{
|
|
|
|
preempt_disable();
|
|
|
|
rwlock_acquire_read(&lock->dep_map, 0, 0, _RET_IP_);
|
2009-12-04 03:55:53 +08:00
|
|
|
LOCK_CONTENDED(lock, do_raw_read_trylock, do_raw_read_lock);
|
2009-11-17 01:48:37 +08:00
|
|
|
}
|
|
|
|
|
2009-12-04 04:52:18 +08:00
|
|
|
static inline unsigned long __raw_read_lock_irqsave(rwlock_t *lock)
|
2009-11-17 01:48:37 +08:00
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
local_irq_save(flags);
|
|
|
|
preempt_disable();
|
|
|
|
rwlock_acquire_read(&lock->dep_map, 0, 0, _RET_IP_);
|
locking: Remove spin_lock_flags() etc
parisc, ia64 and powerpc32 are the only remaining architectures that
provide custom arch_{spin,read,write}_lock_flags() functions, which are
meant to re-enable interrupts while waiting for a spinlock.
However, none of these can actually run into this codepath, because
it is only called on architectures without CONFIG_GENERIC_LOCKBREAK,
or when CONFIG_DEBUG_LOCK_ALLOC is set without CONFIG_LOCKDEP, and none
of those combinations are possible on the three architectures.
Going back in the git history, it appears that arch/mn10300 may have
been able to run into this code path, but there is a good chance that
it never worked. On the architectures that still exist, it was
already impossible to hit back in 2008 after the introduction of
CONFIG_GENERIC_LOCKBREAK, and possibly earlier.
As this is all dead code, just remove it and the helper functions built
around it. For arch/ia64, the inline asm could be cleaned up, but
it seems safer to leave it untouched.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Helge Deller <deller@gmx.de> # parisc
Link: https://lore.kernel.org/r/20211022120058.1031690-1-arnd@kernel.org
2021-10-22 19:59:38 +08:00
|
|
|
LOCK_CONTENDED(lock, do_raw_read_trylock, do_raw_read_lock);
|
2009-11-17 01:48:37 +08:00
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
2009-12-04 04:52:18 +08:00
|
|
|
static inline void __raw_read_lock_irq(rwlock_t *lock)
|
2009-11-17 01:48:37 +08:00
|
|
|
{
|
|
|
|
local_irq_disable();
|
|
|
|
preempt_disable();
|
|
|
|
rwlock_acquire_read(&lock->dep_map, 0, 0, _RET_IP_);
|
2009-12-04 03:55:53 +08:00
|
|
|
LOCK_CONTENDED(lock, do_raw_read_trylock, do_raw_read_lock);
|
2009-11-17 01:48:37 +08:00
|
|
|
}
|
|
|
|
|
2009-12-04 04:52:18 +08:00
|
|
|
static inline void __raw_read_lock_bh(rwlock_t *lock)
|
2009-11-17 01:48:37 +08:00
|
|
|
{
|
2013-11-19 23:13:38 +08:00
|
|
|
__local_bh_disable_ip(_RET_IP_, SOFTIRQ_LOCK_OFFSET);
|
2009-11-17 01:48:37 +08:00
|
|
|
rwlock_acquire_read(&lock->dep_map, 0, 0, _RET_IP_);
|
2009-12-04 03:55:53 +08:00
|
|
|
LOCK_CONTENDED(lock, do_raw_read_trylock, do_raw_read_lock);
|
2009-11-17 01:48:37 +08:00
|
|
|
}
|
|
|
|
|
2009-12-04 04:52:18 +08:00
|
|
|
static inline unsigned long __raw_write_lock_irqsave(rwlock_t *lock)
|
2009-11-17 01:48:37 +08:00
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
local_irq_save(flags);
|
|
|
|
preempt_disable();
|
|
|
|
rwlock_acquire(&lock->dep_map, 0, 0, _RET_IP_);
|
locking: Remove spin_lock_flags() etc
parisc, ia64 and powerpc32 are the only remaining architectures that
provide custom arch_{spin,read,write}_lock_flags() functions, which are
meant to re-enable interrupts while waiting for a spinlock.
However, none of these can actually run into this codepath, because
it is only called on architectures without CONFIG_GENERIC_LOCKBREAK,
or when CONFIG_DEBUG_LOCK_ALLOC is set without CONFIG_LOCKDEP, and none
of those combinations are possible on the three architectures.
Going back in the git history, it appears that arch/mn10300 may have
been able to run into this code path, but there is a good chance that
it never worked. On the architectures that still exist, it was
already impossible to hit back in 2008 after the introduction of
CONFIG_GENERIC_LOCKBREAK, and possibly earlier.
As this is all dead code, just remove it and the helper functions built
around it. For arch/ia64, the inline asm could be cleaned up, but
it seems safer to leave it untouched.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Helge Deller <deller@gmx.de> # parisc
Link: https://lore.kernel.org/r/20211022120058.1031690-1-arnd@kernel.org
2021-10-22 19:59:38 +08:00
|
|
|
LOCK_CONTENDED(lock, do_raw_write_trylock, do_raw_write_lock);
|
2009-11-17 01:48:37 +08:00
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
2009-12-04 04:52:18 +08:00
|
|
|
static inline void __raw_write_lock_irq(rwlock_t *lock)
|
2009-11-17 01:48:37 +08:00
|
|
|
{
|
|
|
|
local_irq_disable();
|
|
|
|
preempt_disable();
|
|
|
|
rwlock_acquire(&lock->dep_map, 0, 0, _RET_IP_);
|
2009-12-04 03:55:53 +08:00
|
|
|
LOCK_CONTENDED(lock, do_raw_write_trylock, do_raw_write_lock);
|
2009-11-17 01:48:37 +08:00
|
|
|
}
|
|
|
|
|
2009-12-04 04:52:18 +08:00
|
|
|
static inline void __raw_write_lock_bh(rwlock_t *lock)
|
2009-11-17 01:48:37 +08:00
|
|
|
{
|
2013-11-19 23:13:38 +08:00
|
|
|
__local_bh_disable_ip(_RET_IP_, SOFTIRQ_LOCK_OFFSET);
|
2009-11-17 01:48:37 +08:00
|
|
|
rwlock_acquire(&lock->dep_map, 0, 0, _RET_IP_);
|
2009-12-04 03:55:53 +08:00
|
|
|
LOCK_CONTENDED(lock, do_raw_write_trylock, do_raw_write_lock);
|
2009-11-17 01:48:37 +08:00
|
|
|
}
|
|
|
|
|
2009-12-04 04:52:18 +08:00
|
|
|
static inline void __raw_write_lock(rwlock_t *lock)
|
2009-11-17 01:48:37 +08:00
|
|
|
{
|
|
|
|
preempt_disable();
|
|
|
|
rwlock_acquire(&lock->dep_map, 0, 0, _RET_IP_);
|
2009-12-04 03:55:53 +08:00
|
|
|
LOCK_CONTENDED(lock, do_raw_write_trylock, do_raw_write_lock);
|
2009-11-17 01:48:37 +08:00
|
|
|
}
|
|
|
|
|
2022-01-22 14:14:10 +08:00
|
|
|
static inline void __raw_write_lock_nested(rwlock_t *lock, int subclass)
|
|
|
|
{
|
|
|
|
preempt_disable();
|
|
|
|
rwlock_acquire(&lock->dep_map, subclass, 0, _RET_IP_);
|
|
|
|
LOCK_CONTENDED(lock, do_raw_write_trylock, do_raw_write_lock);
|
|
|
|
}
|
|
|
|
|
2017-11-03 18:59:48 +08:00
|
|
|
#endif /* !CONFIG_GENERIC_LOCKBREAK || CONFIG_DEBUG_LOCK_ALLOC */
|
2009-11-17 01:48:37 +08:00
|
|
|
|
2009-12-04 04:52:18 +08:00
|
|
|
static inline void __raw_write_unlock(rwlock_t *lock)
|
2009-11-17 01:48:37 +08:00
|
|
|
{
|
2019-09-20 00:09:40 +08:00
|
|
|
rwlock_release(&lock->dep_map, _RET_IP_);
|
2009-12-04 03:55:53 +08:00
|
|
|
do_raw_write_unlock(lock);
|
2009-11-17 01:48:37 +08:00
|
|
|
preempt_enable();
|
|
|
|
}
|
|
|
|
|
2009-12-04 04:52:18 +08:00
|
|
|
static inline void __raw_read_unlock(rwlock_t *lock)
|
2009-11-17 01:48:37 +08:00
|
|
|
{
|
2019-09-20 00:09:40 +08:00
|
|
|
rwlock_release(&lock->dep_map, _RET_IP_);
|
2009-12-04 03:55:53 +08:00
|
|
|
do_raw_read_unlock(lock);
|
2009-11-17 01:48:37 +08:00
|
|
|
preempt_enable();
|
|
|
|
}
|
|
|
|
|
2009-12-04 04:52:18 +08:00
|
|
|
static inline void
|
|
|
|
__raw_read_unlock_irqrestore(rwlock_t *lock, unsigned long flags)
|
2009-11-17 01:48:37 +08:00
|
|
|
{
|
2019-09-20 00:09:40 +08:00
|
|
|
rwlock_release(&lock->dep_map, _RET_IP_);
|
2009-12-04 03:55:53 +08:00
|
|
|
do_raw_read_unlock(lock);
|
2009-11-17 01:48:37 +08:00
|
|
|
local_irq_restore(flags);
|
|
|
|
preempt_enable();
|
|
|
|
}
|
|
|
|
|
2009-12-04 04:52:18 +08:00
|
|
|
static inline void __raw_read_unlock_irq(rwlock_t *lock)
|
2009-11-17 01:48:37 +08:00
|
|
|
{
|
2019-09-20 00:09:40 +08:00
|
|
|
rwlock_release(&lock->dep_map, _RET_IP_);
|
2009-12-04 03:55:53 +08:00
|
|
|
do_raw_read_unlock(lock);
|
2009-11-17 01:48:37 +08:00
|
|
|
local_irq_enable();
|
|
|
|
preempt_enable();
|
|
|
|
}
|
|
|
|
|
2009-12-04 04:52:18 +08:00
|
|
|
static inline void __raw_read_unlock_bh(rwlock_t *lock)
|
2009-11-17 01:48:37 +08:00
|
|
|
{
|
2019-09-20 00:09:40 +08:00
|
|
|
rwlock_release(&lock->dep_map, _RET_IP_);
|
2009-12-04 03:55:53 +08:00
|
|
|
do_raw_read_unlock(lock);
|
2013-11-19 23:13:38 +08:00
|
|
|
__local_bh_enable_ip(_RET_IP_, SOFTIRQ_LOCK_OFFSET);
|
2009-11-17 01:48:37 +08:00
|
|
|
}
|
|
|
|
|
2009-12-04 04:52:18 +08:00
|
|
|
static inline void __raw_write_unlock_irqrestore(rwlock_t *lock,
|
2009-11-17 01:48:37 +08:00
|
|
|
unsigned long flags)
|
|
|
|
{
|
2019-09-20 00:09:40 +08:00
|
|
|
rwlock_release(&lock->dep_map, _RET_IP_);
|
2009-12-04 03:55:53 +08:00
|
|
|
do_raw_write_unlock(lock);
|
2009-11-17 01:48:37 +08:00
|
|
|
local_irq_restore(flags);
|
|
|
|
preempt_enable();
|
|
|
|
}
|
|
|
|
|
2009-12-04 04:52:18 +08:00
|
|
|
static inline void __raw_write_unlock_irq(rwlock_t *lock)
|
2009-11-17 01:48:37 +08:00
|
|
|
{
|
2019-09-20 00:09:40 +08:00
|
|
|
rwlock_release(&lock->dep_map, _RET_IP_);
|
2009-12-04 03:55:53 +08:00
|
|
|
do_raw_write_unlock(lock);
|
2009-11-17 01:48:37 +08:00
|
|
|
local_irq_enable();
|
|
|
|
preempt_enable();
|
|
|
|
}
|
|
|
|
|
2009-12-04 04:52:18 +08:00
|
|
|
static inline void __raw_write_unlock_bh(rwlock_t *lock)
|
2009-11-17 01:48:37 +08:00
|
|
|
{
|
2019-09-20 00:09:40 +08:00
|
|
|
rwlock_release(&lock->dep_map, _RET_IP_);
|
2009-12-04 03:55:53 +08:00
|
|
|
do_raw_write_unlock(lock);
|
2013-11-19 23:13:38 +08:00
|
|
|
__local_bh_enable_ip(_RET_IP_, SOFTIRQ_LOCK_OFFSET);
|
2009-11-17 01:48:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* __LINUX_RWLOCK_API_SMP_H */
|