Skip to content

Commit 5c2e773

Browse files
efzrhPeter Zijlstra
authored andcommitted
rust: helpers: Avoid raw_spin_lock initialization for PREEMPT_RT
When PREEMPT_RT=y, spin locks are mapped to rt_mutex types, so using spinlock_check() + __raw_spin_lock_init() to initialize spin locks is incorrect, and would cause build errors. Introduce __spin_lock_init() to initialize a spin lock with lockdep rquired information for PREEMPT_RT builds, and use it in the Rust helper. Fixes: d2d6422 ("x86: Allow to enable PREEMPT_RT.") Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/ Reported-by: kernel test robot <[email protected]> Signed-off-by: Eder Zulian <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: Boqun Feng <[email protected]> Tested-by: Boqun Feng <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 183ec5f commit 5c2e773

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

include/linux/spinlock_rt.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,21 @@ static inline void __rt_spin_lock_init(spinlock_t *lock, const char *name,
1616
}
1717
#endif
1818

19-
#define spin_lock_init(slock) \
19+
#define __spin_lock_init(slock, name, key, percpu) \
2020
do { \
21-
static struct lock_class_key __key; \
22-
\
2321
rt_mutex_base_init(&(slock)->lock); \
24-
__rt_spin_lock_init(slock, #slock, &__key, false); \
22+
__rt_spin_lock_init(slock, name, key, percpu); \
2523
} while (0)
2624

27-
#define local_spin_lock_init(slock) \
25+
#define _spin_lock_init(slock, percpu) \
2826
do { \
2927
static struct lock_class_key __key; \
30-
\
31-
rt_mutex_base_init(&(slock)->lock); \
32-
__rt_spin_lock_init(slock, #slock, &__key, true); \
28+
__spin_lock_init(slock, #slock, &__key, percpu); \
3329
} while (0)
3430

31+
#define spin_lock_init(slock) _spin_lock_init(slock, false)
32+
#define local_spin_lock_init(slock) _spin_lock_init(slock, true)
33+
3534
extern void rt_spin_lock(spinlock_t *lock) __acquires(lock);
3635
extern void rt_spin_lock_nested(spinlock_t *lock, int subclass) __acquires(lock);
3736
extern void rt_spin_lock_nest_lock(spinlock_t *lock, struct lockdep_map *nest_lock) __acquires(lock);

rust/helpers/spinlock.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@ void rust_helper___spin_lock_init(spinlock_t *lock, const char *name,
77
struct lock_class_key *key)
88
{
99
#ifdef CONFIG_DEBUG_SPINLOCK
10+
# if defined(CONFIG_PREEMPT_RT)
11+
__spin_lock_init(lock, name, key, false);
12+
# else /*!CONFIG_PREEMPT_RT */
1013
__raw_spin_lock_init(spinlock_check(lock), name, key, LD_WAIT_CONFIG);
11-
#else
14+
# endif /* CONFIG_PREEMPT_RT */
15+
#else /* !CONFIG_DEBUG_SPINLOCK */
1216
spin_lock_init(lock);
13-
#endif
17+
#endif /* CONFIG_DEBUG_SPINLOCK */
1418
}
1519

1620
void rust_helper_spin_lock(spinlock_t *lock)

0 commit comments

Comments
 (0)