net: add net device refcount tracker to struct packet_type
Subsystems (4)
PATCH 1/1 net: add net device refcount tracker to struct packet_type
From: Eric Dumazet <[email protected]>
Most notable changes are in af_packet, tipc ones are trivial.
Signed-off-by Eric Dumazet <[email protected]>
Cc Jon Maloy <[email protected]>
Cc Ying Xue <[email protected]>
--- include/linux/netdevice.h | 1 + net/packet/af_packet.c | 14 +++++++++++--- net/tipc/bearer.c | 4 ++-- 3 files changed, 14 insertions(+), 5 deletions(-)
include/linux/netdevice.h +1 -0
@@ -2533,6 +2533,7 @@ struct packet_type {__be16 type;/* This is really htons(ether_type). */ bool ignore_outgoing;struct net_device *dev;/* NULL is wildcarded here */ +netdevice_tracker dev_tracker; int (*func) (struct sk_buff *, struct net_device *, struct packet_type *,
net/packet/af_packet.c +11 -3
@@ -3109,7 +3109,7 @@ static int packet_release(struct socket *sock)packet_cached_dev_reset (po);if (po->prot_hook.dev) { -dev_put (po->prot_hook.dev); +dev_put_track (po->prot_hook.dev, &po->prot_hook.dev_tracker); po->prot_hook.dev =NULL ; }spin_unlock (&po->bind_lock);
@@ -3217,18 +3217,25 @@ static int packet_do_bind(struct sock *sk, const char *name, int ifindex,WRITE_ONCE (po->num, proto); po->prot_hook.type = proto; +dev_put_track (dev_curr, &po->prot_hook.dev_tracker); + dev_curr =NULL ; +if (unlikely (unlisted)) {dev_put (dev); po->prot_hook.dev =NULL ;WRITE_ONCE (po->ifindex,-1 );packet_cached_dev_reset (po); }else { +if (dev) +netdev_tracker_alloc (dev, + &po->prot_hook.dev_tracker, +GFP_ATOMIC ); po->prot_hook.dev = dev;WRITE_ONCE (po->ifindex, dev ? dev->ifindex :0 );packet_cached_dev_assign (po, dev); } } -dev_put (dev_curr); +dev_put_track (dev_curr, &po->prot_hook.dev_tracker);if (proto ==0 || !need_rehook) goto out_unlock;
@@ -4138,7 +4145,8 @@ static int packet_notifier(struct notifier_block *this,if (msg ==NETDEV_UNREGISTER ) {packet_cached_dev_reset (po);WRITE_ONCE (po->ifindex,-1 ); -dev_put (po->prot_hook.dev); +dev_put_track (po->prot_hook.dev, + &po->prot_hook.dev_tracker); po->prot_hook.dev =NULL ; }spin_unlock (&po->bind_lock);
net/tipc/bearer.c +2 -2
@@ -787,7 +787,7 @@ int tipc_attach_loopback(struct net *net)if (!dev)return -ENODEV ; -dev_hold (dev); +dev_hold_track (dev, &tn->loopback_pt.dev_tracker,GFP_KERNEL ); tn->loopback_pt.dev = dev; tn->loopback_pt.type =htons (ETH_P_TIPC ); tn->loopback_pt.func = tipc_loopback_rcv_pkt;
@@ -800,7 +800,7 @@ void tipc_detach_loopback(struct net *net)struct tipc_net *tn =tipc_net (net);dev_remove_pack (&tn->loopback_pt); -dev_put (net->loopback_dev); +dev_put_track (net->loopback_dev, &tn->loopback_pt.dev_tracker); }/* Caller should hold rtnl_lock to protect the bearer */
Signature · 1 line
2.34.1.173.g76aa8bc2d0-goog
This patch was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:
Quoted 9 lines · On Tue, 14 Dec 2021 07:09:33 -0800 you wrote:
From: Eric Dumazet <[email protected]>
Most notable changes are in
af_packet, tipc ones are trivial.Signed-off-by Eric Dumazet <[email protected]>Cc Jon Maloy <[email protected]>Cc Ying Xue <[email protected]>[...]
Here is the summary with links:
- [net-next] net: add net device refcount tracker to struct packet_type
https://git.kernel.org/netdev/net-next/c/f1d9268e0618
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
Quoted 89 lines · Eric Dumazet
From: Eric Dumazet <[email protected]>
Most notable changes are in
af_packet, tipc ones are trivial.Signed-off-by Eric Dumazet <[email protected]>Cc Jon Maloy <[email protected]>Cc Ying Xue <[email protected]>--- include/linux/netdevice.h | 1 + net/packet/af_packet.c | 14 +++++++++++--- net/tipc/bearer.c | 4 ++-- 3 files changed, 14 insertions(+), 5 deletions(-)include/linux/netdevice.h +1
-0@@ -2533,6 +2533,7 @@ struct packet_type {__be16 type;/* This is really htons(ether_type). */ bool ignore_outgoing;struct net_device *dev;/* NULL is wildcarded here */ +netdevice_tracker dev_tracker; int (*func) (struct sk_buff *, struct net_device *, struct packet_type *,net/packet/af_packet.c +11
-3@@ -3109,7 +3109,7 @@ static int packet_release(struct socket *sock)packet_cached_dev_reset (po);if (po->prot_hook.dev) { -dev_put (po->prot_hook.dev); +dev_put_track (po->prot_hook.dev, &po->prot_hook.dev_tracker); po->prot_hook.dev =NULL ; }spin_unlock (&po->bind_lock);@@ -3217,18 +3217,25 @@ static int packet_do_bind(struct sock *sk, const char *name, int ifindex,WRITE_ONCE (po->num, proto); po->prot_hook.type = proto; +dev_put_track (dev_curr, &po->prot_hook.dev_tracker); + dev_curr =NULL ; +if (unlikely (unlisted)) {dev_put (dev); po->prot_hook.dev =NULL ;WRITE_ONCE (po->ifindex,-1 );packet_cached_dev_reset (po); }else { +if (dev) +netdev_tracker_alloc (dev, + &po->prot_hook.dev_tracker, +GFP_ATOMIC ); po->prot_hook.dev = dev;WRITE_ONCE (po->ifindex, dev ? dev->ifindex :0 );packet_cached_dev_assign (po, dev); } } -dev_put (dev_curr); +dev_put_track (dev_curr, &po->prot_hook.dev_tracker);if (proto ==0 || !need_rehook) goto out_unlock;@@ -4138,7 +4145,8 @@ static int packet_notifier(struct notifier_block *this,if (msg ==NETDEV_UNREGISTER ) {packet_cached_dev_reset (po);WRITE_ONCE (po->ifindex,-1 ); -dev_put (po->prot_hook.dev); +dev_put_track (po->prot_hook.dev, + &po->prot_hook.dev_tracker); po->prot_hook.dev =NULL ; }spin_unlock (&po->bind_lock);net/tipc/bearer.c +1
-1@@ -787,7 +787,7 @@ int tipc_attach_loopback(struct net *net)if (!dev)return -ENODEV ; -dev_hold (dev); +dev_hold_track (dev, &tn->loopback_pt.dev_tracker,GFP_KERNEL ); tn->loopback_pt.dev = dev; tn->loopback_pt.type =htons (ETH_P_TIPC ); tn->loopback_pt.func = tipc_loopback_rcv_pkt;
net/tipc/bearer.c void tipc_detach_loopback(struct net *net) · line 806
Quoted 8 lines
net/tipc/bearer.c +1
-1@@ -800,7 +800,7 @@ void tipc_detach_loopback(struct net *net)struct tipc_net *tn =tipc_net (net);dev_remove_pack (&tn->loopback_pt); -dev_put (net->loopback_dev); +dev_put_track (net->loopback_dev, &tn->loopback_pt.dev_tracker); }/* Caller should hold rtnl_lock to protect the bearer */
Acked-by Jon Maloy <[email protected]>