All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next-2.6] ifb: RCU locking avoids touching dev refcount
@ 2009-11-02  5:45 Eric Dumazet
  2009-11-02  7:57 ` David Miller
  2009-11-02 21:14 ` Jarek Poplawski
  0 siblings, 2 replies; 5+ messages in thread
From: Eric Dumazet @ 2009-11-02  5:45 UTC (permalink / raw)
  To: David S. Miller, Linux Netdev List

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();
 		skb->iif = _dev->ifindex;
 
 		if (from & AT_EGRESS) {

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH net-next-2.6] ifb: RCU locking avoids touching dev refcount
  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
  1 sibling, 0 replies; 5+ messages in thread
From: David Miller @ 2009-11-02  7:57 UTC (permalink / raw)
  To: eric.dumazet; +Cc: netdev

From: Eric Dumazet <eric.dumazet@gmail.com>
Date: Mon, 02 Nov 2009 06:45:16 +0100

> Avoids touching dev refcount in hotpath
> 
> Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>

Applied.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net-next-2.6] ifb: RCU locking avoids touching dev refcount
  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
  1 sibling, 1 reply; 5+ messages in thread
From: Jarek Poplawski @ 2009-11-02 21:14 UTC (permalink / raw)
  To: Eric Dumazet; +Cc: David S. Miller, Linux Netdev List

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?

Jarek P.

>                         netif_rx(skb);
>                 } else
>                         BUG();
>         }

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net-next-2.6] ifb: RCU locking avoids touching dev refcount
  2009-11-02 21:14 ` Jarek Poplawski
@ 2009-11-02 21:34   ` Eric Dumazet
  2009-11-02 21:40     ` Jarek Poplawski
  0 siblings, 1 reply; 5+ messages in thread
From: Eric Dumazet @ 2009-11-02 21:34 UTC (permalink / raw)
  To: Jarek Poplawski; +Cc: David S. Miller, Linux Netdev List

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.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net-next-2.6] ifb: RCU locking avoids touching dev refcount
  2009-11-02 21:34   ` Eric Dumazet
@ 2009-11-02 21:40     ` Jarek Poplawski
  0 siblings, 0 replies; 5+ messages in thread
From: Jarek Poplawski @ 2009-11-02 21:40 UTC (permalink / raw)
  To: Eric Dumazet; +Cc: David S. Miller, Linux Netdev List

On Mon, Nov 02, 2009 at 10:34:04PM +0100, Eric Dumazet wrote:
> Jarek Poplawski a écrit :
...
> > 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.

I think it's needed now at least for readability.

Jarek P.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2009-11-02 21:41 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2009-11-02 21:40     ` Jarek Poplawski

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.