* sk_buff and reference counting netdev pointers
@ 2017-01-23 22:37 Joel Cunningham
2017-01-23 23:45 ` Cong Wang
0 siblings, 1 reply; 3+ messages in thread
From: Joel Cunningham @ 2017-01-23 22:37 UTC (permalink / raw)
To: netdev
Hi,
I’m working on a research effort to understand the synchronization mechanisms for accessing and modifying a struct net_device object. One area that isn’t clear is the net device pointer (dev) stored in a struct sk_buff. From my investigation, the pointer appears to be assigned without increasing the struct net_device’s reference count (example __netdev_alloc_skb doesn’t call dev_hold) and also when the sk_buff is freed (kfree_skb) no call to dev_put() is made. This seems to leave a possibility of an skb referencing a stale net device unless something is cleaning up all the skbs during unregister_netdevice() (which waits for all outstanding references to be released). Any insight in understanding how this is working would be appreciated!
Joel
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: sk_buff and reference counting netdev pointers
2017-01-23 22:37 sk_buff and reference counting netdev pointers Joel Cunningham
@ 2017-01-23 23:45 ` Cong Wang
2017-01-25 21:31 ` Joel Cunningham
0 siblings, 1 reply; 3+ messages in thread
From: Cong Wang @ 2017-01-23 23:45 UTC (permalink / raw)
To: Joel Cunningham; +Cc: Linux Kernel Network Developers
On Mon, Jan 23, 2017 at 2:37 PM, Joel Cunningham <joel.cunningham@me.com> wrote:
> Hi,
>
> I’m working on a research effort to understand the synchronization mechanisms for accessing and modifying a struct net_device object. One area that isn’t clear is the net device pointer (dev) stored in a struct sk_buff. From my investigation, the pointer appears to be assigned without increasing the struct net_device’s reference count (example __netdev_alloc_skb doesn’t call dev_hold) and also when the sk_buff is freed (kfree_skb) no call to dev_put() is made. This seems to leave a possibility of an skb referencing a stale net device unless something is cleaning up all the skbs during unregister_netdevice() (which waits for all outstanding references to be released). Any insight in understanding how this is working would be appreciated!
>
This is a very common question.
synchronize_net() is supposed to wait for on-flying packets, since
both for TX and RX paths we acquire RCU read lock.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: sk_buff and reference counting netdev pointers
2017-01-23 23:45 ` Cong Wang
@ 2017-01-25 21:31 ` Joel Cunningham
0 siblings, 0 replies; 3+ messages in thread
From: Joel Cunningham @ 2017-01-25 21:31 UTC (permalink / raw)
To: Cong Wang; +Cc: Linux Kernel Network Developers
> On Jan 23, 2017, at 5:45 PM, Cong Wang <xiyou.wangcong@gmail.com> wrote:
>
> On Mon, Jan 23, 2017 at 2:37 PM, Joel Cunningham <joel.cunningham@me.com> wrote:
>> Hi,
>>
>> I’m working on a research effort to understand the synchronization mechanisms for accessing and modifying a struct net_device object. One area that isn’t clear is the net device pointer (dev) stored in a struct sk_buff. From my investigation, the pointer appears to be assigned without increasing the struct net_device’s reference count (example __netdev_alloc_skb doesn’t call dev_hold) and also when the sk_buff is freed (kfree_skb) no call to dev_put() is made. This seems to leave a possibility of an skb referencing a stale net device unless something is cleaning up all the skbs during unregister_netdevice() (which waits for all outstanding references to be released). Any insight in understanding how this is working would be appreciated!
>>
>
> This is a very common question.
>
> synchronize_net() is supposed to wait for on-flying packets, since
> both for TX and RX paths we acquire RCU read lock.
Thanks for the insight on in-flight packets! I continued my research effort on how queued/outstanding sk_buffs with dev pointer set are cleaned up during an unregister. Do my findings sound correct?
1. RX packets queued in the link-layer backlog are freed via flush_backlog (called from netdev_run_todo)
2. RX packets that have been processed and queued in an upper layer buffer have already had their sk_buff->dev pointer NULLed out (I saw this in tcp_v4_rcv() and sock_queue_rcv_skb() for UDP pathway)
3. TX packets waiting in a queue discipline are freed via device_deactive_many()/dev_deactivate_queue()
4. TX packets that have been accepted by the driver in ndo_start_xmit() but are queued for asynchronous transmit will be freed during ndo_stop()
Thanks,
Joel
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-01-25 21:31 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-01-23 22:37 sk_buff and reference counting netdev pointers Joel Cunningham
2017-01-23 23:45 ` Cong Wang
2017-01-25 21:31 ` Joel Cunningham
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox