Lock warning cleanups
cover Lock warning cleanups
This patch series adds missing annotations to functions that register warnings of context imbalance when built with Sparse tool. The adds fix these warnings and give insight on what the functions are actually doing.
1. futex: a __must_hold(q->lock_ptr) is added as fixup_pi_state_owner() hold the lock at entry and exit.
2. futex: a __releases(&pi_state->pi_mutex.wait_lock) is added as wake_futex_pi() releases the lock at exit.
3. hrtimer: an __acquires() annotation is added as lock_hrtimer_base does actually call READ_ONCE(). This add fixes the warning on other functions that call lock_hrtimer_base()
Jules Irenge (3):
hrtimer: Add missing annotation to lock_hrtimer_base()
futex: Add missing annotation for wake_futex_pi()
futex: Add missing annotation for fixup_pi_state_owner()
kernel/futex.c | 2 ++ kernel/time/hrtimer.c | 1 + 2 files changed, 3 insertions(+)
Signature · 1 line
2.24.1
PATCH 1/3 hrtimer: Add missing annotation to lock_hrtimer_base()
Sparse reports several warnings;
warning: context imbalance in lock_hrtimer_base() - wrong count at exit
warning: context imbalance in hrtimer_start_range_ns() - unexpected unlock
warning: context imbalance in hrtimer_try_to_cancel() - unexpected unlock
warning: context imbalance in __hrtimer_get_remaining() - unexpected unlock
The root cause is a missing annotation of lock_hrtimer_base() which causes also the "unexpected unlock" warnings.
Add the missing __acquires(timer->base) annotation
--- kernel/time/hrtimer.c | 1 + 1 file changed, 1 insertion(+)
kernel/time/hrtimer.c +1 -0
@@ -160,6 +160,7 @@ static inline bool is_migration_base(struct hrtimer_clock_base *base)static struct hrtimer_clock_base *lock_hrtimer_base (const struct hrtimer *timer,unsigned long *flags) + __acquires(timer->base) {struct hrtimer_clock_base *base;
Signature · 1 line
2.24.1
PATCH 2/3 futex: Add missing annotation for wake_futex_pi()
In reply to Jules IrengeSparse reports a warning at wake_futex_pi()
warning: context imbalance in wake_futex_pi() - unexpected unlock
The root cause is amissing annotation of wake_futex_pi().
Add the missing __releases(&pi_state->pi_mutex.wait_lock) annotation
--- kernel/futex.c | 1 + 1 file changed, 1 insertion(+)
kernel/futex.c +1 -0
@@ -1550,6 +1550,7 @@ static void mark_wake_futex(struct wake_q_head *wake_q, struct futex_q *q)* Caller must hold a reference on @pi_state. */ static int wake_futex_pi (u32 __user *uaddr,u32 uval,struct futex_pi_state *pi_state) + __releases(&pi_state->pi_mutex.wait_lock) {u32 uninitialized_var (curval ), newval;struct task_struct *new_owner;
Signature · 1 line
2.24.1
PATCH 3/3 futex: Add missing annotation for fixup_pi_state_owner()
In reply to Jules IrengeSparse reports a warning at fixup_pi_state_owner()
warning: context imbalance in fixup_pi_state_owner() - unexpected unlock
The root cause is a missing annotation of fixup_pi_state_owner().
Add the missing __must_hold(q->lock_ptr) annotation
--- kernel/futex.c | 1 + 1 file changed, 1 insertion(+)
kernel/futex.c +1 -0
@@ -2440,6 +2440,7 @@ static void unqueue_me_pi(struct futex_q *q)static int fixup_pi_state_owner (u32 __user *uaddr,struct futex_q *q,struct task_struct *argowner) + __must_hold(q->lock_ptr) {struct futex_pi_state *pi_state = q->pi_state;u32 uval,uninitialized_var (curval ), newval;
Signature · 1 line
2.24.1