Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: create netdev_nl_sock to wrap bindings list

No functional changes. Next patches will add more granular locking
to netdev_nl_sock.

Signed-off-by: Stanislav Fomichev <sdf@fomichev.me>
Reviewed-by: Mina Almasry <almasrymina@google.com>
Link: https://patch.msgid.link/20250311144026.4154277-2-sdf@fomichev.me
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Stanislav Fomichev and committed by
Jakub Kicinski
b6b67141 17fef204

+27 -17
+2 -2
Documentation/netlink/specs/netdev.yaml
··· 745 745 - irq-suspend-timeout 746 746 747 747 kernel-family: 748 - headers: [ "linux/list.h"] 749 - sock-priv: struct list_head 748 + headers: [ "net/netdev_netlink.h"] 749 + sock-priv: struct netdev_nl_sock 750 750 751 751 mcast-groups: 752 752 list:
+11
include/net/netdev_netlink.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #ifndef __NET_NETDEV_NETLINK_H 3 + #define __NET_NETDEV_NETLINK_H 4 + 5 + #include <linux/list.h> 6 + 7 + struct netdev_nl_sock { 8 + struct list_head bindings; 9 + }; 10 + 11 + #endif /* __NET_NETDEV_NETLINK_H */
+2 -2
net/core/netdev-genl-gen.c
··· 9 9 #include "netdev-genl-gen.h" 10 10 11 11 #include <uapi/linux/netdev.h> 12 - #include <linux/list.h> 12 + #include <net/netdev_netlink.h> 13 13 14 14 /* Integer value ranges */ 15 15 static const struct netlink_range_validation netdev_a_page_pool_id_range = { ··· 217 217 .n_split_ops = ARRAY_SIZE(netdev_nl_ops), 218 218 .mcgrps = netdev_nl_mcgrps, 219 219 .n_mcgrps = ARRAY_SIZE(netdev_nl_mcgrps), 220 - .sock_priv_size = sizeof(struct list_head), 220 + .sock_priv_size = sizeof(struct netdev_nl_sock), 221 221 .sock_priv_init = __netdev_nl_sock_priv_init, 222 222 .sock_priv_destroy = __netdev_nl_sock_priv_destroy, 223 223 };
+3 -3
net/core/netdev-genl-gen.h
··· 10 10 #include <net/genetlink.h> 11 11 12 12 #include <uapi/linux/netdev.h> 13 - #include <linux/list.h> 13 + #include <net/netdev_netlink.h> 14 14 15 15 /* Common nested types */ 16 16 extern const struct nla_policy netdev_page_pool_info_nl_policy[NETDEV_A_PAGE_POOL_IFINDEX + 1]; ··· 42 42 43 43 extern struct genl_family netdev_nl_family; 44 44 45 - void netdev_nl_sock_priv_init(struct list_head *priv); 46 - void netdev_nl_sock_priv_destroy(struct list_head *priv); 45 + void netdev_nl_sock_priv_init(struct netdev_nl_sock *priv); 46 + void netdev_nl_sock_priv_destroy(struct netdev_nl_sock *priv); 47 47 48 48 #endif /* _LINUX_NETDEV_GEN_H */
+9 -10
net/core/netdev-genl.c
··· 829 829 { 830 830 struct nlattr *tb[ARRAY_SIZE(netdev_queue_id_nl_policy)]; 831 831 struct net_devmem_dmabuf_binding *binding; 832 - struct list_head *sock_binding_list; 833 832 u32 ifindex, dmabuf_fd, rxq_idx; 833 + struct netdev_nl_sock *priv; 834 834 struct net_device *netdev; 835 835 struct sk_buff *rsp; 836 836 struct nlattr *attr; ··· 845 845 ifindex = nla_get_u32(info->attrs[NETDEV_A_DEV_IFINDEX]); 846 846 dmabuf_fd = nla_get_u32(info->attrs[NETDEV_A_DMABUF_FD]); 847 847 848 - sock_binding_list = genl_sk_priv_get(&netdev_nl_family, 849 - NETLINK_CB(skb).sk); 850 - if (IS_ERR(sock_binding_list)) 851 - return PTR_ERR(sock_binding_list); 848 + priv = genl_sk_priv_get(&netdev_nl_family, NETLINK_CB(skb).sk); 849 + if (IS_ERR(priv)) 850 + return PTR_ERR(priv); 852 851 853 852 rsp = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_KERNEL); 854 853 if (!rsp) ··· 908 909 goto err_unbind; 909 910 } 910 911 911 - list_add(&binding->list, sock_binding_list); 912 + list_add(&binding->list, &priv->bindings); 912 913 913 914 nla_put_u32(rsp, NETDEV_A_DMABUF_ID, binding->id); 914 915 genlmsg_end(rsp, hdr); ··· 930 931 return err; 931 932 } 932 933 933 - void netdev_nl_sock_priv_init(struct list_head *priv) 934 + void netdev_nl_sock_priv_init(struct netdev_nl_sock *priv) 934 935 { 935 - INIT_LIST_HEAD(priv); 936 + INIT_LIST_HEAD(&priv->bindings); 936 937 } 937 938 938 - void netdev_nl_sock_priv_destroy(struct list_head *priv) 939 + void netdev_nl_sock_priv_destroy(struct netdev_nl_sock *priv) 939 940 { 940 941 struct net_devmem_dmabuf_binding *binding; 941 942 struct net_devmem_dmabuf_binding *temp; 942 943 943 - list_for_each_entry_safe(binding, temp, priv, list) { 944 + list_for_each_entry_safe(binding, temp, &priv->bindings, list) { 944 945 rtnl_lock(); 945 946 net_devmem_unbind_dmabuf(binding); 946 947 rtnl_unlock();