Skip to contentSkip to conversation

tun: avoid unnecessary READ_ONCE in tun_net_xmit

PATCH Applied Willem de Bruijn 3 participants 3 messages Dec 6, 2017

Subsystems (3)
lore
Share & tools
lore

Willem de Bruijn

author maintainer
#0 lore raw

PATCH 1/1 tun: avoid unnecessary READ_ONCE in tun_net_xmit

From: Willem de Bruijn <[email protected]>

The statement no longer serves a purpose.

Commit fa35864e0bb7 ("tuntap: Fix for a race in accessing numqueues") added the ACCESS_ONCE to avoid a race condition with skb_queue_len.

Commit 436accebb530 ("tuntap: remove unnecessary sk_receive_queue length check during xmit") removed the affected skb_queue_len check.

Commit 96f84061620c ("tun: add eBPF based queue selection method") split the function, reading the field a second time in the callee. The temp variable is now only read once, so just remove it.

---
 drivers/net/tun.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/net/tun.c +1 -3
index 787cc35ef89b..c2ad8f3858d1 100644
@@ -990,14 +990,12 @@ static netdev_tx_t tun_net_xmit(struct sk_buff *skb, struct net_device *dev)
 	struct tun_struct *tun = netdev_priv(dev);
 	int txq = skb->queue_mapping;
 	struct tun_file *tfile;
-	u32 numqueues = 0;
 
 	rcu_read_lock();
 	tfile = rcu_dereference(tun->tfiles[txq]);
-	numqueues = READ_ONCE(tun->numqueues);
 
 	/* Drop packet if interface is not attached */
-	if (txq >= numqueues)
+	if (txq >= tun->numqueues)
 		goto drop;
 
 	if (!rcu_dereference(tun->steering_prog))
Signature · 1 line
2.15.1.424.g9478a66081-goog
Acked-by on v1 1/1
#1 lore raw
Quoted 29 lines · Willem de Bruijn

From: Willem de Bruijn <[email protected]>

The statement no longer serves a purpose.

Commit fa35864e0bb7 ("tuntap: Fix for a race in accessing numqueues") added the ACCESS_ONCE to avoid a race condition with skb_queue_len.

Commit 436accebb530 ("tuntap: remove unnecessary sk_receive_queue length check during xmit") removed the affected skb_queue_len check.

Commit 96f84061620c ("tun: add eBPF based queue selection method") split the function, reading the field a second time in the callee. The temp variable is now only read once, so just remove it.

---
  drivers/net/tun.c | 4 +---
  1 file changed, 1 insertion(+), 3 deletions(-)
drivers/net/tun.c +0 -1
index 787cc35ef89b..c2ad8f3858d1 100644
@@ -990,14 +990,12 @@ static netdev_tx_t tun_net_xmit(struct sk_buff *skb, struct net_device *dev)
  	struct tun_struct *tun = netdev_priv(dev);
  	int txq = skb->queue_mapping;
  	struct tun_file *tfile;
-	u32 numqueues = 0;
 

drivers/net/tun.c static netdev_tx_t tun_net_xmit(struct sk_buff *skb, struct net_device *dev) · line 1001

Quoted 10 lines
drivers/net/tun.c +1 -2
  	rcu_read_lock();
  	tfile = rcu_dereference(tun->tfiles[txq]);
-	numqueues = READ_ONCE(tun->numqueues);
 
  	/* Drop packet if interface is not attached */
-	if (txq >= numqueues)
+	if (txq >= tun->numqueues)
  		goto drop;
 
  	if (!rcu_dereference(tun->steering_prog))

Thanks

maintainer Applied
#2 lore raw
In reply to Willem de Bruijn

From: Willem de Bruijn <[email protected]>
Date: Tue, 5 Dec 2017 22:11:17 -0500

Quoted 7 lines

From: Willem de Bruijn <[email protected]>

The statement no longer serves a purpose.

Commit fa35864e0bb7 ("tuntap: Fix for a race in accessing numqueues") added the ACCESS_ONCE to avoid a race condition with skb_queue_len.

Quoted 8 lines

Commit 436accebb530 ("tuntap: remove unnecessary sk_receive_queue length check during xmit") removed the affected skb_queue_len check.

Commit 96f84061620c ("tun: add eBPF based queue selection method") split the function, reading the field a second time in the callee. The temp variable is now only read once, so just remove it.

Applied, thanks Willem.