2020-02-01 00:05:55

by Jules Irenge

[permalink] [raw]
Subject: [PATCH 0/3] 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(+)

--
2.24.1


2020-02-01 00:05:59

by Jules Irenge

[permalink] [raw]
Subject: [PATCH 3/3] futex: Add missing annotation for fixup_pi_state_owner()

Sparse 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

Signed-off-by: Jules Irenge <[email protected]>
---
kernel/futex.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/kernel/futex.c b/kernel/futex.c
index 93e7510a5b36..5263cce46c06 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -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;
--
2.24.1

2020-02-01 00:06:31

by Jules Irenge

[permalink] [raw]
Subject: [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

Signed-off-by: Jules Irenge <[email protected]>
---
kernel/time/hrtimer.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
index 3a609e7344f3..bb8340e2a3b9 100644
--- a/kernel/time/hrtimer.c
+++ b/kernel/time/hrtimer.c
@@ -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;

--
2.24.1

2020-02-01 00:07:26

by Jules Irenge

[permalink] [raw]
Subject: [PATCH 2/3] futex: Add missing annotation for wake_futex_pi()

Sparse 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

Signed-off-by: Jules Irenge <[email protected]>
---
kernel/futex.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/kernel/futex.c b/kernel/futex.c
index 0cf84c8664f2..93e7510a5b36 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -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;
--
2.24.1