Eric,
Thank you for your patient apply.
There is still a question, 
In receive path, driver does not call dev_hold(), when skb goes to host stack, 
skb->dev is likely to be used. 
If device is destroyed before that, it seems dangerous.

Thank you!
Zhangjie
-----Original Message-----
From: Eric Dumazet [mailto:eric.duma...@gmail.com] 
Sent: Tuesday, August 25, 2015 10:25 PM
To: Zhangjie (HZ)
Cc: Jason Wang; netdev@vger.kernel.org; Qinchuanyu; Yewudi; liuyongan 00175866; 
Wangbicheng; Yan Chen
Subject: Re: [Question] Usage of dev_hold()/dev_put()

On Tue, 2015-08-25 at 08:28 +0000, Zhangjie (HZ) wrote:
> Hi,
> 
> The comment of function dev_hold() and dev_put() are really simple.
> 
> Actually, I can’t find a rule to follow.
> 
> Where should I call dev_hold()/dev_put()?
> 
> Are they necessary during xmit or receive or only in register/release?
> 
> I find that, for tap, it calls dev_hold()/dev_put() for every
> tun_sendmsg/tun_recvmsg:
> 
> So, should I call dev_hold()/dev_put() for each quote, such like:
> “skb->dev = dev” ?
> 
> But, for physical nic, I can’t find dev_hold()/dev_put() during xmit 
> or receive.
> 
> What kind of scene is it necessary to call dev_hold()/dev_put()?
> 
>  
> 
> Look forward for your feedback. 
> 
> Thank you ! J
> 
> Zhangjie
> 
> 
Please do not send HTML mails, otherwise they do not reach netdev mailing list

In general, you need to use dev_hold() for every reference on 'dev'
stored in the object.

However they are some paths were you do not need that : For example in transmit 
path, skb are stored either in a qdisc or device driver internal queue/ring. At 
device dismantle we properly delete all these skb, so we do not have to worry 
about used dev_hold()/dev_put() in transmit.

In drivers/net/tun.c, the dev_hold()/dev_put() only is required so that device 
doesnt disappear between tun_get() and actual use of it after a potentially 
long copy from user space (that might trigger page faults)



Reply via email to