netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Dumazet <eric.dumazet@gmail.com>
To: Jarek Poplawski <jarkao2@gmail.com>
Cc: "David S. Miller" <davem@davemloft.net>,
	Linux Netdev List <netdev@vger.kernel.org>
Subject: Re: [PATCH net-next-2.6] ifb: RCU locking avoids touching dev refcount
Date: Mon, 02 Nov 2009 22:34:04 +0100	[thread overview]
Message-ID: <4AEF504C.7000401@gmail.com> (raw)
In-Reply-To: <4AEF4B9B.7000205@gmail.com>

Jarek Poplawski a écrit :
> Eric Dumazet wrote, On 11/02/2009 06:45 AM:
> 
>> Avoids touching dev refcount in hotpath
>>
>> Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
>> ---
>>  drivers/net/ifb.c |    6 ++++--
>>  1 files changed, 4 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/net/ifb.c b/drivers/net/ifb.c
>> index 030913f..69c2566 100644
>> --- a/drivers/net/ifb.c
>> +++ b/drivers/net/ifb.c
>> @@ -98,13 +98,15 @@ static void ri_tasklet(unsigned long dev)
>>  		stats->tx_packets++;
>>  		stats->tx_bytes +=skb->len;
>>  
>> -		skb->dev = dev_get_by_index(&init_net, skb->iif);
>> +		rcu_read_lock();
>> +		skb->dev = dev_get_by_index_rcu(&init_net, skb->iif);
>>  		if (!skb->dev) {
>> +			rcu_read_unlock();
>>  			dev_kfree_skb(skb);
>>  			stats->tx_dropped++;
>>  			break;
>>  		}
>> -		dev_put(skb->dev);
>> +		rcu_read_unlock();
> 
> I wonder if this rcu_read_unlock() isn't too early here. I know, it
> functionally fully replaces the old method, but as a whole it looks
> strange:
> 
>>                 rcu_read_lock();
>>                 skb->dev = dev_get_by_index_rcu(&init_net, skb->iif);
>>                 if (!skb->dev) {
>>                         rcu_read_unlock();
>>                         dev_kfree_skb(skb);
>>                         stats->tx_dropped++;
>>                         break;
>>                 }
>>                 rcu_read_unlock();
>>                 skb->iif = _dev->ifindex;
>>
>>                 if (from & AT_EGRESS) {
>>                         dp->st_rx_frm_egr++;
>>                         dev_queue_xmit(skb);
>>                 } else if (from & AT_INGRESS) {
>>                         dp->st_rx_frm_ing++;
>>                         skb_pull(skb, skb->dev->hard_header_len);
> 
> 
> So, how is skb->dev protected here, above and below? It seems these
> rcu read blocks need extending, don't they?
> 

Well, this might be true, but we run under tasklet (softirq) with preemption disabled.

We might move rcu_read_unlock() some lines down to not rely on this.

  reply	other threads:[~2009-11-02 21:34 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-02  5:45 [PATCH net-next-2.6] ifb: RCU locking avoids touching dev refcount Eric Dumazet
2009-11-02  7:57 ` David Miller
2009-11-02 21:14 ` Jarek Poplawski
2009-11-02 21:34   ` Eric Dumazet [this message]
2009-11-02 21:40     ` Jarek Poplawski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4AEF504C.7000401@gmail.com \
    --to=eric.dumazet@gmail.com \
    --cc=davem@davemloft.net \
    --cc=jarkao2@gmail.com \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).