Re: [PATCH 1/2 v2] af-packet: Use existing netdev reference for bound sockets.
From: Eric Dumazet <hidden>
Date: 2011-05-27 20:08:44
Le jeudi 26 mai 2011 à 21:11 -0700, Ben Greear a écrit :
On 05/26/2011 08:42 PM, Eric Dumazet wrote:quoted
Le jeudi 26 mai 2011 à 16:55 -0700, greearb@candelatech.com a écrit :quoted
quoted
out_free: kfree_skb(skb); out_unlock: - if (dev) + if (dev&& need_rls_dev) dev_put(dev); out: return err;Hmmm, I wonder why you want this Ben. IMHO this is buggy, because we can sleep in this function. We must take a ref on device (its really cheap these days, now we have a percpu device refcnt)Why must you take the reference? And if we must, why isn't the current code that assigns the prot_hook.dev without taking a reference OK?
If we sleep, device can disappear under us. The only way to not take a reference is to hold rcu_read_lock(), but you're not allowed to sleep under rcu_read_lock().
It seems a waste to do the lookup and free if we don't have to, and with thousands of devices, the lookup might take a reasonable amount of effort?
I understand you want to avoid the lookup, this part is fine for me, but you need to take a reference on the device before eventual sleep. Nowadays its a single "inc" instruction on x86, without even a lock prefix (this on a percpu integer)