Re: [PATCH 1/5] locking: Add rwsem_is_write_locked()

From: Peter Zijlstra
Date: Wed Sep 13 2023 - 04:59:27 EST


On Tue, Sep 12, 2023 at 08:27:15AM -0700, Darrick J. Wong wrote:

> I could live with Longman's suggestion of an rwsem_assert_is_locked that
> only exists if DEBUG_RWSEMS is enabled. Something like:
>
> #ifdef CONFIG_DEBUG_RWSEMS
> static inline bool __rwsem_assert_is_locked(struct rw_semaphore *rwsem,
> const char *file, int line)
> {
> bool ret = rwsem_is_locked(rwsem);
> if (!ret)
> WARN(1, "!rwsem_is_locked(rwsem) at %s line %d", file, line);
> return ret;
> }
> #define rwsem_assert_is_locked(r) \
> __rwsem_assert_is_locked((r), __FILE__, __LINE__)
> #endif
>
> and then XFS could do:
>
> ASSERT(rwsem_assert_is_locked(&VFS_I(ip)->i_rwsem));
>
> Wherein ASSERT is only #defined if CONFIG_XFS_DEBUG, and XFS_DEBUG
> selects DEBUG_RWSEMS, per Longman's suggestion. That's work for what we
> want it for (simple cheap lock checking) without becoming a general
> lockabuse predicate.

Ack.