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

Configure Feed

Select the types of activity you want to include in your feed.

mctp: no longer rely on net->dev_index_head[]

mctp_dump_addrinfo() is one of the last users of
net->dev_index_head[] in the control path.

Switch to for_each_netdev_dump() for better scalability.

Use C99 for mctp_device_rtnl_msg_handlers[] to prepare
future RTNL removal from mctp_dump_addrinfo()

(mdev->addrs is not yet RCU protected)

Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Matt Johnston <matt@codeconstruct.com.au>
Reviewed-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Acked-by: Jeremy Kerr <jk@codeconstruct.com.au>
Link: https://patch.msgid.link/20241206223811.1343076-1-edumazet@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Eric Dumazet and committed by
Jakub Kicinski
2d20773a f9663b7c

+19 -31
+19 -31
net/mctp/device.c
··· 20 20 #include <net/sock.h> 21 21 22 22 struct mctp_dump_cb { 23 - int h; 24 - int idx; 23 + unsigned long ifindex; 25 24 size_t a_idx; 26 25 }; 27 26 ··· 114 115 { 115 116 struct mctp_dump_cb *mcb = (void *)cb->ctx; 116 117 struct net *net = sock_net(skb->sk); 117 - struct hlist_head *head; 118 118 struct net_device *dev; 119 119 struct ifaddrmsg *hdr; 120 120 struct mctp_dev *mdev; 121 - int ifindex; 122 - int idx = 0, rc; 121 + int ifindex, rc; 123 122 124 123 hdr = nlmsg_data(cb->nlh); 125 124 // filter by ifindex if requested 126 125 ifindex = hdr->ifa_index; 127 126 128 127 rcu_read_lock(); 129 - for (; mcb->h < NETDEV_HASHENTRIES; mcb->h++, mcb->idx = 0) { 130 - idx = 0; 131 - head = &net->dev_index_head[mcb->h]; 132 - hlist_for_each_entry_rcu(dev, head, index_hlist) { 133 - if (idx >= mcb->idx && 134 - (ifindex == 0 || ifindex == dev->ifindex)) { 135 - mdev = __mctp_dev_get(dev); 136 - if (mdev) { 137 - rc = mctp_dump_dev_addrinfo(mdev, 138 - skb, cb); 139 - mctp_dev_put(mdev); 140 - // Error indicates full buffer, this 141 - // callback will get retried. 142 - if (rc < 0) 143 - goto out; 144 - } 145 - } 146 - idx++; 147 - // reset for next iteration 148 - mcb->a_idx = 0; 149 - } 128 + for_each_netdev_dump(net, dev, mcb->ifindex) { 129 + if (ifindex && ifindex != dev->ifindex) 130 + continue; 131 + mdev = __mctp_dev_get(dev); 132 + if (!mdev) 133 + continue; 134 + rc = mctp_dump_dev_addrinfo(mdev, skb, cb); 135 + mctp_dev_put(mdev); 136 + if (rc < 0) 137 + break; 138 + mcb->a_idx = 0; 150 139 } 151 - out: 152 140 rcu_read_unlock(); 153 - mcb->idx = idx; 154 141 155 142 return skb->len; 156 143 } ··· 516 531 }; 517 532 518 533 static const struct rtnl_msg_handler mctp_device_rtnl_msg_handlers[] = { 519 - {THIS_MODULE, PF_MCTP, RTM_NEWADDR, mctp_rtm_newaddr, NULL, 0}, 520 - {THIS_MODULE, PF_MCTP, RTM_DELADDR, mctp_rtm_deladdr, NULL, 0}, 521 - {THIS_MODULE, PF_MCTP, RTM_GETADDR, NULL, mctp_dump_addrinfo, 0}, 534 + {.owner = THIS_MODULE, .protocol = PF_MCTP, .msgtype = RTM_NEWADDR, 535 + .doit = mctp_rtm_newaddr}, 536 + {.owner = THIS_MODULE, .protocol = PF_MCTP, .msgtype = RTM_DELADDR, 537 + .doit = mctp_rtm_deladdr}, 538 + {.owner = THIS_MODULE, .protocol = PF_MCTP, .msgtype = RTM_GETADDR, 539 + .dumpit = mctp_dump_addrinfo}, 522 540 }; 523 541 524 542 int __init mctp_device_init(void)