Skip to content

Commit f58423a

Browse files
lmbborkmann
authored andcommitted
bpf, sockmap: Add locking annotations to iterator
The sparse checker currently outputs the following warnings: include/linux/rcupdate.h:632:9: sparse: sparse: context imbalance in 'sock_hash_seq_start' - wrong count at exit include/linux/rcupdate.h:632:9: sparse: sparse: context imbalance in 'sock_map_seq_start' - wrong count at exit Add the necessary __acquires and __release annotations to make the iterator locking schema palatable to sparse. Also add __must_hold for good measure. The kernel codebase uses both __acquires(rcu) and __acquires(RCU). I couldn't find any guidance which one is preferred, so I used what is easier to type out. Fixes: 0365351 ("net: Allow iterating sockmap and sockhash") Reported-by: kernel test robot <[email protected]> Signed-off-by: Lorenz Bauer <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: John Fastabend <[email protected]> Acked-by: Jakub Sitnicki <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent e688c3d commit f58423a

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

net/core/sock_map.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,7 @@ static void *sock_map_seq_lookup_elem(struct sock_map_seq_info *info)
745745
}
746746

747747
static void *sock_map_seq_start(struct seq_file *seq, loff_t *pos)
748+
__acquires(rcu)
748749
{
749750
struct sock_map_seq_info *info = seq->private;
750751

@@ -757,6 +758,7 @@ static void *sock_map_seq_start(struct seq_file *seq, loff_t *pos)
757758
}
758759

759760
static void *sock_map_seq_next(struct seq_file *seq, void *v, loff_t *pos)
761+
__must_hold(rcu)
760762
{
761763
struct sock_map_seq_info *info = seq->private;
762764

@@ -767,6 +769,7 @@ static void *sock_map_seq_next(struct seq_file *seq, void *v, loff_t *pos)
767769
}
768770

769771
static int sock_map_seq_show(struct seq_file *seq, void *v)
772+
__must_hold(rcu)
770773
{
771774
struct sock_map_seq_info *info = seq->private;
772775
struct bpf_iter__sockmap ctx = {};
@@ -789,6 +792,7 @@ static int sock_map_seq_show(struct seq_file *seq, void *v)
789792
}
790793

791794
static void sock_map_seq_stop(struct seq_file *seq, void *v)
795+
__releases(rcu)
792796
{
793797
if (!v)
794798
(void)sock_map_seq_show(seq, NULL);
@@ -1353,6 +1357,7 @@ static void *sock_hash_seq_find_next(struct sock_hash_seq_info *info,
13531357
}
13541358

13551359
static void *sock_hash_seq_start(struct seq_file *seq, loff_t *pos)
1360+
__acquires(rcu)
13561361
{
13571362
struct sock_hash_seq_info *info = seq->private;
13581363

@@ -1365,6 +1370,7 @@ static void *sock_hash_seq_start(struct seq_file *seq, loff_t *pos)
13651370
}
13661371

13671372
static void *sock_hash_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1373+
__must_hold(rcu)
13681374
{
13691375
struct sock_hash_seq_info *info = seq->private;
13701376

@@ -1373,6 +1379,7 @@ static void *sock_hash_seq_next(struct seq_file *seq, void *v, loff_t *pos)
13731379
}
13741380

13751381
static int sock_hash_seq_show(struct seq_file *seq, void *v)
1382+
__must_hold(rcu)
13761383
{
13771384
struct sock_hash_seq_info *info = seq->private;
13781385
struct bpf_iter__sockmap ctx = {};
@@ -1396,6 +1403,7 @@ static int sock_hash_seq_show(struct seq_file *seq, void *v)
13961403
}
13971404

13981405
static void sock_hash_seq_stop(struct seq_file *seq, void *v)
1406+
__releases(rcu)
13991407
{
14001408
if (!v)
14011409
(void)sock_hash_seq_show(seq, NULL);

0 commit comments

Comments
 (0)