Skip to contentSkip to conversation

net/mlx5: Replace fs_node mutex with reader/writer semaphore

bug report Dan Carpenter 1 participant 1 message Aug 25, 2021

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

[ This is not really the correct commit, but you seem like a person who
understands this locking. - dan ]

Hello Maor Gottlieb,

The patch c7784b1c8ab3: "net/mlx5: Replace fs_node mutex with reader/writer semaphore" from Aug 27, 2017, leads to the following Smatch static checker warning:

drivers/net/ethernet/mellanox/mlx5/core/fs_core.c:336 down_write_ref_node()
warn: sleeping in atomic context

drivers/net/ethernet/mellanox/mlx5/core/fs_core.c

    332 static void down_write_ref_node(struct fs_node *node, bool locked)
    333 {
    334 	if (node) {
    335 		if (!locked)
--> 336 			down_write(&node->lock);
    337 		refcount_inc(&node->refcount);
    338 	}
    339 }

The call tree is this:

build_match_list() <- disables preempt
-> free_match_list()
-> tree_put_node()

      -> down_write_ref_node()

The build_match_list() function takes rcu_read_lock(). What would make the checker happy is if we did this. But it's not the correct fix because locked is talking about &node->lock... Could you look at it and give me a Reported-by cookie if you find a fix?

drivers/net/ethernet/mellanox/mlx5/core/fs_core.c +1 -1
index 9fe8e3c204d6..41ee18be1a3b 100644
@@ -1682,7 +1682,7 @@ static int build_match_list(struct match_list *match_head,
 
 		curr_match = kmalloc(sizeof(*curr_match), GFP_ATOMIC);
 		if (!curr_match) {
-			free_match_list(match_head, ft_locked);
+			free_match_list(match_head, true);
 			err = -ENOMEM;
 			goto out;
 		}

regards,
dan carpenter