Skip to contentSkip to conversation

Lock warning cleanups

PATCH Applied Jules Irenge 8 participants 23 messages Mar 11, 2020 – Mar 27, 2020

Subsystems (8)
lore
Share & tools
lore
#0 lore raw

cover Lock warning cleanups

This patch series adds missing annotations to various functions, that register warnings of context imbalance when built with Sparse tool. The adds fix the warnings, improve on readability odf the code and give better insight or directive on what the functions are actually doing.

Jules Irenge (8):
bpf: Add missing annotations for __bpf_prog_enter() and

    __bpf_prog_exit()
  raw: Add missing annotations to raw_seq_start() and raw_seq_stop()
  tcp: Add missing annotation for tcp_child_process()
  netfilter: Add missing annotation for ctnetlink_parse_nat_setup()
  netfilter: conntrack: Add missing annotations for
    nf_conntrack_all_lock() and nf_conntrack_all_unlock()
  net: Add missing annotation for *netlink_seq_start()
  ALSA: firewire-tascam: Add missing annotation for
    tscm_hwdep_read_queue()
  ALSA: firewire-tascam: Add missing annotation for
    tscm_hwdep_read_locked()
 kernel/bpf/trampoline.c              | 2 ++
 net/ipv4/raw.c                       | 2 ++
 net/ipv4/tcp_minisocks.c             | 1 +
 net/netfilter/nf_conntrack_core.c    | 2 ++
 net/netfilter/nf_conntrack_netlink.c | 1 +
 net/netlink/af_netlink.c             | 1 +
 sound/firewire/tascam/tascam-hwdep.c | 2 ++
 7 files changed, 11 insertions(+)
Signature · 1 line
2.24.1
#1 lore raw

PATCH 1/8 bpf: Add missing annotations for __bpf_prog_enter() and __bpf_prog_exit()

Sparse reports a warning at __bpf_prog_enter() and __bpf_prog_exit()

warning: context imbalance in __bpf_prog_enter() - wrong count at exit
warning: context imbalance in __bpf_prog_exit() - unexpected unlock

The root cause is the missing annotation at __bpf_prog_enter() and __bpf_prog_exit()

Add the missing __acquires(RCU) annotation
Add the missing __releases(RCU) annotation

---
 kernel/bpf/trampoline.c | 2 ++
 1 file changed, 2 insertions(+)
kernel/bpf/trampoline.c +2 -0
index 6b264a92064b..09bce10ad1cc 100644
@@ -374,6 +374,7 @@ void bpf_trampoline_put(struct bpf_trampoline *tr)
  * call __bpf_prog_exit
  */
 u64 notrace __bpf_prog_enter(void)
+	__acquires(RCU)
 {
 	u64 start = 0;
 
@@ -385,6 +386,7 @@ u64 notrace __bpf_prog_enter(void)
 }
 
 void notrace __bpf_prog_exit(struct bpf_prog *prog, u64 start)
+	__releases(RCU)
 {
 	struct bpf_prog_stats *stats;
 
Signature · 1 line
2.24.1
maintainer Applied
#2 lore raw

Re: [PATCH 1/8] bpf: Add missing annotations for __bpf_prog_enter() and __bpf_prog_exit()

Quoted 5 lines · Jules Irenge

Sparse reports a warning at __bpf_prog_enter() and __bpf_prog_exit()

warning: context imbalance in __bpf_prog_enter() - wrong count at exit
warning: context imbalance in __bpf_prog_exit() - unexpected unlock

Quoted 7 lines

The root cause is the missing annotation at __bpf_prog_enter() and __bpf_prog_exit()

Add the missing __acquires(RCU) annotation
Add the missing __releases(RCU) annotation

Applied this one to bpf-next, thanks!

#3 lore raw

PATCH 2/8 raw: Add missing annotations to raw_seq_start() and raw_seq_stop()

In reply to Jules Irenge

Sparse reports warnings at raw_seq_start() and raw_seq_stop()

warning: context imbalance in raw_seq_start() - wrong count at exit
warning: context imbalance in raw_seq_stop() - unexpected unlock

The root cause is the missing annotations at raw_seq_start()
and raw_seq_stop()
Add the missing __acquires(&h->lock) annotation Add the missing __releases(&h->lock) annotation

---
 net/ipv4/raw.c | 2 ++
 1 file changed, 2 insertions(+)
net/ipv4/raw.c +2 -0
index 3183413ebc6c..47665919048f 100644
@@ -1034,6 +1034,7 @@ static struct sock *raw_get_idx(struct seq_file *seq, loff_t pos)
 }
 
 void *raw_seq_start(struct seq_file *seq, loff_t *pos)
+	__acquires(&h->lock)
 {
 	struct raw_hashinfo *h = PDE_DATA(file_inode(seq->file));
 
@@ -1056,6 +1057,7 @@ void *raw_seq_next(struct seq_file *seq, void *v, loff_t *pos)
 EXPORT_SYMBOL_GPL(raw_seq_next);
 
 void raw_seq_stop(struct seq_file *seq, void *v)
+	__releases(&h->lock)
 {
 	struct raw_hashinfo *h = PDE_DATA(file_inode(seq->file));
 
Signature · 1 line
2.24.1
#4 lore raw

Re: [PATCH 2/8] raw: Add missing annotations to raw_seq_start() and raw_seq_stop()

Quoted 20 lines · Jules Irenge

Sparse reports warnings at raw_seq_start() and raw_seq_stop()

warning: context imbalance in raw_seq_start() - wrong count at exit
warning: context imbalance in raw_seq_stop() - unexpected unlock

The root cause is the missing annotations at raw_seq_start()
and raw_seq_stop()
Add the missing __acquires(&h->lock) annotation Add the missing __releases(&h->lock) annotation

---
 net/ipv4/raw.c | 2 ++
 1 file changed, 2 insertions(+)
net/ipv4/raw.c +0 -0
index 3183413ebc6c..47665919048f 100644

net/ipv4/raw.c static struct sock *raw_get_idx(struct seq_file *seq, loff_t pos) · line 1037

Quoted 4 lines
net/ipv4/raw.c +1 -0
@@ -1034,6 +1034,7 @@ static struct sock *raw_get_idx(struct seq_file *seq, loff_t pos)
 }
 
 void *raw_seq_start(struct seq_file *seq, loff_t *pos)
+	__acquires(&h->lock)

I dunno, h variable is not yet defined/declared at this point, this looks weird.

Quoted 12 lines
net/ipv4/raw.c +1 -0
 {
 	struct raw_hashinfo *h = PDE_DATA(file_inode(seq->file));
 
@@ -1056,6 +1057,7 @@ void *raw_seq_next(struct seq_file *seq, void *v, loff_t *pos)
 EXPORT_SYMBOL_GPL(raw_seq_next);
 
 void raw_seq_stop(struct seq_file *seq, void *v)
+	__releases(&h->lock)
 {
 	struct raw_hashinfo *h = PDE_DATA(file_inode(seq->file));
 
#5 lore raw

Re: [PATCH 2/8] raw: Add missing annotations to raw_seq_start() and raw_seq_stop()

Quoted 37 lines · Eric Dumazet
Quoted 20 lines · Jules Irenge

Sparse reports warnings at raw_seq_start() and raw_seq_stop()

warning: context imbalance in raw_seq_start() - wrong count at exit
warning: context imbalance in raw_seq_stop() - unexpected unlock

The root cause is the missing annotations at raw_seq_start()
and raw_seq_stop()
Add the missing __acquires(&h->lock) annotation Add the missing __releases(&h->lock) annotation

---
 net/ipv4/raw.c | 2 ++
 1 file changed, 2 insertions(+)
net/ipv4/raw.c +0 -0
index 3183413ebc6c..47665919048f 100644

net/ipv4/raw.c static struct sock *raw_get_idx(struct seq_file *seq, loff_t pos) · line 1037

Quoted 4 lines
net/ipv4/raw.c +1 -0
@@ -1034,6 +1034,7 @@ static struct sock *raw_get_idx(struct seq_file *seq, loff_t pos)
 }
 
 void *raw_seq_start(struct seq_file *seq, loff_t *pos)
+	__acquires(&h->lock)

I dunno, h variable is not yet defined/declared at this point, this looks weird.

Quoted 6 lines
net/ipv4/raw.c +0 -0
 {
 	struct raw_hashinfo *h = PDE_DATA(file_inode(seq->file));
 
@@ -1056,6 +1057,7 @@ void *raw_seq_next(struct seq_file *seq, void *v, loff_t *pos)
 EXPORT_SYMBOL_GPL(raw_seq_next);
 
Quoted 7 lines

net/ipv4/raw.c void *raw_seq_next(struct seq_file *seq, void *v, loff_t *pos) · line 1063

Quoted 6 lines
net/ipv4/raw.c +1 -0
 void raw_seq_stop(struct seq_file *seq, void *v)
+	__releases(&h->lock)
 {
 	struct raw_hashinfo *h = PDE_DATA(file_inode(seq->file));
 

Thanks for the feedback,

I think h is a pointer of type struct raw_hashinfo, in which member lock is initialized on line number 89.

Kind regards

maintainer Applied
#6 lore raw

Re: [PATCH 2/8] raw: Add missing annotations to raw_seq_start() and raw_seq_stop()

In reply to Jules Irenge

From: Jules Irenge <[email protected]>
Date: Wed, 11 Mar 2020 01:09:02 +0000

Quoted 11 lines

Sparse reports warnings at raw_seq_start() and raw_seq_stop()

warning: context imbalance in raw_seq_start() - wrong count at exit
warning: context imbalance in raw_seq_stop() - unexpected unlock

The root cause is the missing annotations at raw_seq_start()
and raw_seq_stop()
Add the missing __acquires(&h->lock) annotation Add the missing __releases(&h->lock) annotation

Applied.

#7 lore raw

PATCH 3/8 tcp: Add missing annotation for tcp_child_process()

In reply to Jules Irenge

Sparse reports warning at tcp_child_process()
warning: context imbalance in tcp_child_process() - unexpected unlock The root cause is the missing annotation at tcp_child_process()

Add the missing __releases(&((child)->sk_lock.slock)) annotation

---
 net/ipv4/tcp_minisocks.c | 1 +
 1 file changed, 1 insertion(+)
net/ipv4/tcp_minisocks.c +1 -0
index ad3b56d9fa71..0e8a5b6e477c 100644
@@ -817,6 +817,7 @@ EXPORT_SYMBOL(tcp_check_req);
 
 int tcp_child_process(struct sock *parent, struct sock *child,
 		      struct sk_buff *skb)
+	__releases(&((child)->sk_lock.slock))
 {
 	int ret = 0;
 	int state = child->sk_state;
Signature · 1 line
2.24.1
Reviewed-by on v1 3/8
#8 lore raw

Re: [PATCH 3/8] tcp: Add missing annotation for tcp_child_process()

Quoted 17 lines · Jules Irenge

Sparse reports warning at tcp_child_process()
warning: context imbalance in tcp_child_process() - unexpected unlock The root cause is the missing annotation at tcp_child_process()

Add the missing __releases(&((child)->sk_lock.slock)) annotation

---
 net/ipv4/tcp_minisocks.c | 1 +
 1 file changed, 1 insertion(+)
net/ipv4/tcp_minisocks.c +0 -0
index ad3b56d9fa71..0e8a5b6e477c 100644

net/ipv4/tcp_minisocks.c EXPORT_SYMBOL(tcp_check_req); · line 823

Quoted 7 lines
net/ipv4/tcp_minisocks.c +1 -0
@@ -817,6 +817,7 @@ EXPORT_SYMBOL(tcp_check_req);
 
 int tcp_child_process(struct sock *parent, struct sock *child,
                      struct sk_buff *skb)
+       __releases(&((child)->sk_lock.slock))
 {
        int ret = 0;
        int state = child->sk_state;

Yeah, although we prefer to use lockdep these days ;)

#9 lore raw

Re: [PATCH 3/8] tcp: Add missing annotation for tcp_child_process()

Thanks for the feedbacks. Good to know I have not used lockdep but I will try it.

Quoted 31 lines · Eric Dumazet
Quoted 17 lines · Jules Irenge

Sparse reports warning at tcp_child_process()
warning: context imbalance in tcp_child_process() - unexpected unlock The root cause is the missing annotation at tcp_child_process()

Add the missing __releases(&((child)->sk_lock.slock)) annotation

---
 net/ipv4/tcp_minisocks.c | 1 +
 1 file changed, 1 insertion(+)
net/ipv4/tcp_minisocks.c +0 -0
index ad3b56d9fa71..0e8a5b6e477c 100644

net/ipv4/tcp_minisocks.c EXPORT_SYMBOL(tcp_check_req); · line 823

Quoted 7 lines
net/ipv4/tcp_minisocks.c +1 -0
@@ -817,6 +817,7 @@ EXPORT_SYMBOL(tcp_check_req);
 
 int tcp_child_process(struct sock *parent, struct sock *child,
                      struct sk_buff *skb)
+       __releases(&((child)->sk_lock.slock))
 {
        int ret = 0;
        int state = child->sk_state;

Yeah, although we prefer to use lockdep these days ;)

maintainer Applied
#10 lore raw

Re: [PATCH 3/8] tcp: Add missing annotation for tcp_child_process()

In reply to Jules Irenge

From: Jules Irenge <[email protected]>
Date: Wed, 11 Mar 2020 01:09:03 +0000

Quoted 7 lines

Sparse reports warning at tcp_child_process()
warning: context imbalance in tcp_child_process() - unexpected unlock The root cause is the missing annotation at tcp_child_process()

Add the missing __releases(&((child)->sk_lock.slock)) annotation

Applied.

#11 lore raw

PATCH 4/8 netfilter: Add missing annotation for ctnetlink_parse_nat_setup()

In reply to Jules Irenge

Sparse reports a warning at ctnetlink_parse_nat_setup()

warning: context imbalance in ctnetlink_parse_nat_setup()
- unexpected unlock

The root cause is the missing annotation at ctnetlink_parse_nat_setup() Add the missing __must_hold(RCU) annotation

---
 net/netfilter/nf_conntrack_netlink.c | 1 +
 1 file changed, 1 insertion(+)
net/netfilter/nf_conntrack_netlink.c +1 -0
index 6a1c8f1f6171..eb190206cd12 100644
@@ -1533,6 +1533,7 @@ static int
 ctnetlink_parse_nat_setup(struct nf_conn *ct,
 			  enum nf_nat_manip_type manip,
 			  const struct nlattr *attr)
+	__must_hold(RCU)
 {
 	struct nf_nat_hook *nat_hook;
 	int err;
Signature · 1 line
2.24.1
maintainer Applied
#12 lore raw

Re: [PATCH 4/8] netfilter: Add missing annotation for ctnetlink_parse_nat_setup()

Quoted 7 lines · Jules Irenge

Sparse reports a warning at ctnetlink_parse_nat_setup()

warning: context imbalance in ctnetlink_parse_nat_setup()
- unexpected unlock

The root cause is the missing annotation at ctnetlink_parse_nat_setup() Add the missing __must_hold(RCU) annotation

Applied, thanks.

#13 lore raw

PATCH 5/8 netfilter: conntrack: Add missing annotations for nf_conntrack_all_lock() and nf_conntrack_all_unlock()

In reply to Jules Irenge

Sparse reports warnings at nf_conntrack_all_lock()
and nf_conntrack_all_unlock()

warning: context imbalance in nf_conntrack_all_lock()
- wrong count at exit
warning: context imbalance in nf_conntrack_all_unlock()
- unexpected unlock

Add the missing __acquires(&nf_conntrack_locks_all_lock) Add missing __releases(&nf_conntrack_locks_all_lock)

---
 net/netfilter/nf_conntrack_core.c | 2 ++
 1 file changed, 2 insertions(+)
net/netfilter/nf_conntrack_core.c +2 -0
index d1305423640f..a0bc122d5df1 100644
@@ -143,6 +143,7 @@ static bool nf_conntrack_double_lock(struct net *net, unsigned int h1,
 }
 
 static void nf_conntrack_all_lock(void)
+	__acquires(&nf_conntrack_locks_all_lock)
 {
 	int i;
 
@@ -162,6 +163,7 @@ static void nf_conntrack_all_lock(void)
 }
 
 static void nf_conntrack_all_unlock(void)
+	__releases(&nf_conntrack_locks_all_lock)
 {
 	/* All prior stores must be complete before we clear
 	 * 'nf_conntrack_locks_all'. Otherwise nf_conntrack_lock()
Signature · 1 line
2.24.1
#14 lore raw

Re: [PATCH 5/8] netfilter: conntrack: Add missing annotations for nf_conntrack_all_lock() and nf_conntrack_all_unlock()

Quoted 10 lines · Jules Irenge

Sparse reports warnings at nf_conntrack_all_lock()
and nf_conntrack_all_unlock()

warning: context imbalance in nf_conntrack_all_lock()
- wrong count at exit
warning: context imbalance in nf_conntrack_all_unlock()
- unexpected unlock

Add the missing __acquires(&nf_conntrack_locks_all_lock) Add missing __releases(&nf_conntrack_locks_all_lock)

Also applied, thanks.

#15 lore raw

PATCH 6/8 net: Add missing annotation for *netlink_seq_start()

In reply to Jules Irenge

Sparse reports a warning at netlink_seq_start()

warning: context imbalance in netlink_seq_start() - wrong count at exit The root cause is the missing annotation at netlink_seq_start() Add the missing __acquires(RCU) annotation

---
 net/netlink/af_netlink.c | 1 +
 1 file changed, 1 insertion(+)
net/netlink/af_netlink.c +1 -0
index 7a287dc73f63..99eef04a51ec 100644
@@ -2582,6 +2582,7 @@ static void *__netlink_seq_next(struct seq_file *seq)
 }
 
 static void *netlink_seq_start(struct seq_file *seq, loff_t *posp)
+	__acquires(RCU)
 {
 	struct nl_seq_iter *iter = seq->private;
 	void *obj = SEQ_START_TOKEN;
Signature · 1 line
2.24.1
maintainer Applied
#16 lore raw

Re: [PATCH 6/8] net: Add missing annotation for *netlink_seq_start()

From: Jules Irenge <[email protected]>
Date: Wed, 11 Mar 2020 01:09:06 +0000

Quoted 7 lines

Sparse reports a warning at netlink_seq_start()

warning: context imbalance in netlink_seq_start() - wrong count at exit The root cause is the missing annotation at netlink_seq_start() Add the missing __acquires(RCU) annotation

Applied.

#17 lore raw

PATCH 7/8 ALSA: firewire-tascam: Add missing annotation for tscm_hwdep_read_queue()

In reply to Jules Irenge

Sparse reports a warning at tscm_hwdep_read_queue()

warning: context imbalance in tscm_hwdep_read_queue() - unexpected unlock

The root cause is the missing annotation at tscm_hwdep_read_queue() Add the missing __releases(&tscm->lock) annotation

---
 sound/firewire/tascam/tascam-hwdep.c | 1 +
 1 file changed, 1 insertion(+)
sound/firewire/tascam/tascam-hwdep.c +1 -0
index c29a97f6f638..9801e33e7f2a 100644
@@ -36,6 +36,7 @@ static long tscm_hwdep_read_locked(struct snd_tscm *tscm, char __user *buf,
 
 static long tscm_hwdep_read_queue(struct snd_tscm *tscm, char __user *buf,
 				  long remained, loff_t *offset)
+	__releases(&tscm->lock)
 {
 	char __user *pos = buf;
 	unsigned int type = SNDRV_FIREWIRE_EVENT_TASCAM_CONTROL;
Signature · 1 line
2.24.1
maintainer Acked-by on v1 7/8
#18 lore raw

Re: [PATCH 7/8] ALSA: firewire-tascam: Add missing annotation for tscm_hwdep_read_queue()

Quoted 11 lines · Jules Irenge

Sparse reports a warning at tscm_hwdep_read_queue()

warning: context imbalance in tscm_hwdep_read_queue() - unexpected unlock

The root cause is the missing annotation at tscm_hwdep_read_queue() Add the missing __releases(&tscm->lock) annotation

---
 sound/firewire/tascam/tascam-hwdep.c | 1 +
 1 file changed, 1 insertion(+)

This looks good.

Quoted 14 lines
sound/firewire/tascam/tascam-hwdep.c +1 -0
index c29a97f6f638..9801e33e7f2a 100644
@@ -36,6 +36,7 @@ static long tscm_hwdep_read_locked(struct snd_tscm *tscm, char __user *buf,
 
 static long tscm_hwdep_read_queue(struct snd_tscm *tscm, char __user *buf,
 				  long remained, loff_t *offset)
+	__releases(&tscm->lock)
 {
 	char __user *pos = buf;
 	unsigned int type = SNDRV_FIREWIRE_EVENT_TASCAM_CONTROL;
Signature · 1 line
2.24.1

Regards

Takashi Sakamoto

Applied
#19 lore raw

Re: [PATCH 7/8] ALSA: firewire-tascam: Add missing annotation for tscm_hwdep_read_queue()

In reply to Jules Irenge
Quoted 9 lines · Jules Irenge

Sparse reports a warning at tscm_hwdep_read_queue()

warning: context imbalance in tscm_hwdep_read_queue() - unexpected unlock

The root cause is the missing annotation at tscm_hwdep_read_queue() Add the missing __releases(&tscm->lock) annotation

Applied, thanks.

Takashi

#20 lore raw

PATCH 8/8 ALSA: firewire-tascam: Add missing annotation for tscm_hwdep_read_locked()

In reply to Jules Irenge

Sparse reports a warning at tscm_hwdep_read_locked()

warning: context imbalance in tscm_hwdep_read_locked() - unexpected unlock

The root cause is the missing annotation at tscm_hwdep_read_locked() Add the missing __releases(&tscm->lock) annotation

---
 sound/firewire/tascam/tascam-hwdep.c | 1 +
 1 file changed, 1 insertion(+)
sound/firewire/tascam/tascam-hwdep.c +1 -0
index 9801e33e7f2a..6f38335fe10b 100644
@@ -17,6 +17,7 @@
 
 static long tscm_hwdep_read_locked(struct snd_tscm *tscm, char __user *buf,
 				   long count, loff_t *offset)
+	__releases(&tscm->lock)
 {
 	struct snd_firewire_event_lock_status event = {
 		.type = SNDRV_FIREWIRE_EVENT_LOCK_STATUS,
Signature · 1 line
2.24.1
maintainer Acked-by on v1 8/8
#21 lore raw

Re: [PATCH 8/8] ALSA: firewire-tascam: Add missing annotation for tscm_hwdep_read_locked()

Hi,

Quoted 11 lines · Jules Irenge

Sparse reports a warning at tscm_hwdep_read_locked()

warning: context imbalance in tscm_hwdep_read_locked() - unexpected unlock

The root cause is the missing annotation at tscm_hwdep_read_locked() Add the missing __releases(&tscm->lock) annotation

---
 sound/firewire/tascam/tascam-hwdep.c | 1 +
 1 file changed, 1 insertion(+)

Thanks for your care of the warning. Although I have found it, I had no idea to suppress it.

Quoted 15 lines
sound/firewire/tascam/tascam-hwdep.c +1 -0
index 9801e33e7f2a..6f38335fe10b 100644
@@ -17,6 +17,7 @@
 
 static long tscm_hwdep_read_locked(struct snd_tscm *tscm, char __user *buf,
 				   long count, loff_t *offset)
+	__releases(&tscm->lock)
 {
 	struct snd_firewire_event_lock_status event = {
 		.type = SNDRV_FIREWIRE_EVENT_LOCK_STATUS,
Signature · 1 line
2.24.1
Applied
#22 lore raw

Re: [PATCH 8/8] ALSA: firewire-tascam: Add missing annotation for tscm_hwdep_read_locked()

In reply to Jules Irenge
Quoted 9 lines · Jules Irenge

Sparse reports a warning at tscm_hwdep_read_locked()

warning: context imbalance in tscm_hwdep_read_locked() - unexpected unlock

The root cause is the missing annotation at tscm_hwdep_read_locked() Add the missing __releases(&tscm->lock) annotation

Applied, thanks.

Takashi