Skip to contentSkip to conversation

genetlink: hold read cb_lock during iteration of genl_fam_idr in genl_bind()

PATCH Applied Jiri Pirko 2 participants 2 messages Aug 25, 2022 – Aug 27, 2022

Subsystems (2)
lore
Share & tools
lore

Jiri Pirko

author
#0 lore raw

PATCH 1/1 genetlink: hold read cb_lock during iteration of genl_fam_idr in genl_bind()

From: Jiri Pirko <[email protected]>

In genl_bind(), currently genl_lock and write cb_lock are taken for iteration of genl_fam_idr and processing of static values stored in struct genl_family. Take just read cb_lock for this task as it is sufficient to guard the idr and the struct against concurrent genl_register/unregister_family() calls.

This will allow to run genl command processing in genl_rcv() and mnl_socket_setsockopt(.., NETLINK_ADD_MEMBERSHIP, ..) in parallel.

---
 net/netlink/genetlink.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/netlink/genetlink.c +2 -2
index 57010927e20a..76aed0571e3a 100644
@@ -1362,7 +1362,7 @@ static int genl_bind(struct net *net, int group)
 	unsigned int id;
 	int ret = 0;
 
-	genl_lock_all();
+	down_read(&cb_lock);
 
 	idr_for_each_entry(&genl_fam_idr, family, id) {
 		const struct genl_multicast_group *grp;
@@ -1383,7 +1383,7 @@ static int genl_bind(struct net *net, int group)
 		break;
 	}
 
-	genl_unlock_all();
+	up_read(&cb_lock);
 	return ret;
 }
 
Signature · 1 line
2.37.1
#1 lore raw
This patch was applied to netdev/net-next.git (master) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (master) by Jakub Kicinski <[email protected]>:

Quoted 9 lines · On Thu, 25 Aug 2022 10:19:40 +0200 you wrote:

From: Jiri Pirko <[email protected]>

In genl_bind(), currently genl_lock and write cb_lock are taken for iteration of genl_fam_idr and processing of static values stored in struct genl_family. Take just read cb_lock for this task as it is sufficient to guard the idr and the struct against concurrent genl_register/unregister_family() calls.

[...]

Here is the summary with links:
- [net-next] genetlink: hold read cb_lock during iteration of genl_fam_idr in genl_bind()

    https://git.kernel.org/netdev/net-next/c/8f1948bdcf2f

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html