Skip to contentSkip to conversation

Lock warning clean up

PATCH Applied Jules Irenge 3 participants 5 messages Jan 30, 2020 – Jan 31, 2020 RCU

lore
Share & tools
lore
#0 lore raw

cover Lock warning clean up

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.
In the core kernel,
1. RCU: a __releases() annotation is added as the functin exit trhe
critical section
2. acct: Multiple warnings were reported, adding __releases(RCU) to the
fs_pin header file function declaration location clears these warnings
as the function releases RCU lock at exit.
Jules Irenge (2):
fs_pin: Add missing annotation to pin_kill() declaration
rcu/nocb: Add missing annotation for rcu_nocb_bypass_unlock()

 include/linux/fs_pin.h   | 2 +-
 kernel/rcu/tree_plugin.h | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
Signature · 1 line
2.24.1
#1 lore raw

PATCH 1/2 fs_pin: Add missing annotation to pin_kill() declaration

Sparse reports several warnings within the kernel acct.c file

warning: context imbalance in acct_on()
- different lock contexts for basic block
warning: context imbalance in __se_sys_acct()
- different lock contexts for basic block
warning: context imbalance in acct_exit_ns()
- wrong count at exit

The root cause is a missing annotation at declaration of pin_kill() within the header file Given that pin_kill() does actually call read_rcu_unlock()in its function definition

Add the missing __releases(RCU) annotation.

---
 include/linux/fs_pin.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/fs_pin.h +1 -1
index bdd09fd2520c..d2fcf1a5112f 100644
@@ -21,4 +21,4 @@ static inline void init_fs_pin(struct fs_pin *p, void (*kill)(struct fs_pin *))
 
 void pin_remove(struct fs_pin *);
 void pin_insert(struct fs_pin *, struct vfsmount *);
-void pin_kill(struct fs_pin *);
+void pin_kill(struct fs_pin *) __releases(RCU);
Signature · 1 line
2.24.1
#2 lore raw

PATCH 2/2 rcu/nocb: Add missing annotation for rcu_nocb_bypass_unlock()

In reply to Jules Irenge

Sparse reports warning at rcu_nocb_bypass_unlock()

warning: context imbalance in rcu_nocb_bypass_unlock() - unexpected unlock

The root cause is a missing annotation of rcu_nocb_bypass_unlock() which causes the warning.

Add the missing __releases(&rdp->nocb_bypass_lock) annotation.

---
 kernel/rcu/tree_plugin.h | 1 +
 1 file changed, 1 insertion(+)
kernel/rcu/tree_plugin.h +1 -0
index 9d21cb07d57c..8783d19a58b2 100644
@@ -1553,6 +1553,7 @@ static bool rcu_nocb_bypass_trylock(struct rcu_data *rdp)
  * Release the specified rcu_data structure's ->nocb_bypass_lock.
  */
 static void rcu_nocb_bypass_unlock(struct rcu_data *rdp)
+	__releases(&rdp->nocb_bypass_lock)
 {
 	lockdep_assert_irqs_disabled();
 	raw_spin_unlock(&rdp->nocb_bypass_lock);
Signature · 1 line
2.24.1
Acked-by on v1 2/2
#3 lore raw

Re: [PATCH 2/2] rcu/nocb: Add missing annotation for rcu_nocb_bypass_unlock()

Quoted 10 lines · Jules Irenge

Sparse reports warning at rcu_nocb_bypass_unlock()

warning: context imbalance in rcu_nocb_bypass_unlock() - unexpected unlock

The root cause is a missing annotation of rcu_nocb_bypass_unlock() which causes the warning.

Add the missing __releases(&rdp->nocb_bypass_lock) annotation.

Quoted 19 lines
---
 kernel/rcu/tree_plugin.h | 1 +
 1 file changed, 1 insertion(+)
kernel/rcu/tree_plugin.h +1 -0
index 9d21cb07d57c..8783d19a58b2 100644
@@ -1553,6 +1553,7 @@ static bool rcu_nocb_bypass_trylock(struct rcu_data *rdp)
  * Release the specified rcu_data structure's ->nocb_bypass_lock.
  */
 static void rcu_nocb_bypass_unlock(struct rcu_data *rdp)
+	__releases(&rdp->nocb_bypass_lock)
 {
 	lockdep_assert_irqs_disabled();
 	raw_spin_unlock(&rdp->nocb_bypass_lock);
Signature · 1 line
2.24.1
maintainer Applied
#4 lore raw

Re: [PATCH 2/2] rcu/nocb: Add missing annotation for rcu_nocb_bypass_unlock()

Quoted 5 lines · Boqun Feng
Quoted 4 lines · Jules Irenge

Sparse reports warning at rcu_nocb_bypass_unlock()

warning: context imbalance in rcu_nocb_bypass_unlock() - unexpected unlock

Quoted 8 lines
Quoted 6 lines

The root cause is a missing annotation of rcu_nocb_bypass_unlock() which causes the warning.

Add the missing __releases(&rdp->nocb_bypass_lock) annotation.

Applied, thank you both!

Thanx, Paul

Quoted 19 lines
Quoted 19 lines
---
 kernel/rcu/tree_plugin.h | 1 +
 1 file changed, 1 insertion(+)
kernel/rcu/tree_plugin.h +1 -0
index 9d21cb07d57c..8783d19a58b2 100644
@@ -1553,6 +1553,7 @@ static bool rcu_nocb_bypass_trylock(struct rcu_data *rdp)
  * Release the specified rcu_data structure's ->nocb_bypass_lock.
  */
 static void rcu_nocb_bypass_unlock(struct rcu_data *rdp)
+	__releases(&rdp->nocb_bypass_lock)
 {
 	lockdep_assert_irqs_disabled();
 	raw_spin_unlock(&rdp->nocb_bypass_lock);
Signature · 1 line
2.24.1