Skip to content

Commit fa1f511

Browse files
Sebastian Andrzej SiewiorKAGA-KOKO
authored andcommitted
locking: Make rwsem_assert_held_write_nolockdep() build with PREEMPT_RT=y
The commit cited below broke the build for PREEMPT_RT because rwsem_assert_held_write_nolockdep() passes a struct rw_semaphore but rw_base_assert_held_write() expects struct rwbase_rt. Fixing the type alone leads to the problem that WARN_ON() is not found because bug.h is missing. In order to resolve this: - Keep the assert (WARN_ON()) in rwsem.h (not rwbase_rt.h) - Make rwsem_assert_held_write_nolockdep() do the implementation specific (rw_base) writer check. - Replace the "inline" with __always_inline which was used before. Fixes: f70405a ("locking: Add rwsem_assert_held() and rwsem_assert_held_write()") Reported-by: Clark Williams <[email protected]> Signed-off-by: Sebastian Andrzej Siewior <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Reviewed-by: Waiman Long <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent fec50db commit fa1f511

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

include/linux/rwbase_rt.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ static __always_inline bool rw_base_is_locked(const struct rwbase_rt *rwb)
3131
return atomic_read(&rwb->readers) != READER_BIAS;
3232
}
3333

34-
static inline void rw_base_assert_held_write(const struct rwbase_rt *rwb)
34+
static __always_inline bool rw_base_is_write_locked(const struct rwbase_rt *rwb)
3535
{
36-
WARN_ON(atomic_read(&rwb->readers) != WRITER_BIAS);
36+
return atomic_read(&rwb->readers) == WRITER_BIAS;
3737
}
3838

3939
static __always_inline bool rw_base_is_contended(const struct rwbase_rt *rwb)

include/linux/rwsem.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,14 @@ static __always_inline int rwsem_is_locked(const struct rw_semaphore *sem)
167167
return rw_base_is_locked(&sem->rwbase);
168168
}
169169

170-
static inline void rwsem_assert_held_nolockdep(const struct rw_semaphore *sem)
170+
static __always_inline void rwsem_assert_held_nolockdep(const struct rw_semaphore *sem)
171171
{
172172
WARN_ON(!rwsem_is_locked(sem));
173173
}
174174

175-
static inline void rwsem_assert_held_write_nolockdep(const struct rw_semaphore *sem)
175+
static __always_inline void rwsem_assert_held_write_nolockdep(const struct rw_semaphore *sem)
176176
{
177-
rw_base_assert_held_write(sem);
177+
WARN_ON(!rw_base_is_write_locked(&sem->rwbase));
178178
}
179179

180180
static __always_inline int rwsem_is_contended(struct rw_semaphore *sem)

0 commit comments

Comments
 (0)