Skip to content

Commit cf1a1e0

Browse files
Paolo Abenidavem330
authored andcommitted
tun: do not compute the rxhash, if not needed
Currently, the tun driver, in absence of an eBPF steering program, always compute the rxhash in its rx path, even when such value is later unused due to additional checks ( This changeset moves the all the related checks just before the __skb_get_hash_symmetric(), so that the latter is no more computed when unneeded. Also replace an unneeded RCU section with rcu_access_pointer(). Signed-off-by: Paolo Abeni <pabeni@redhat.com> Acked-by: Jason Wang <jasowang@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 4962186 commit cf1a1e0

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

drivers/net/tun.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -525,11 +525,6 @@ static void tun_flow_update(struct tun_struct *tun, u32 rxhash,
525525

526526
rcu_read_lock();
527527

528-
/* We may get a very small possibility of OOO during switching, not
529-
* worth to optimize.*/
530-
if (tun->numqueues == 1 || tfile->detached)
531-
goto unlock;
532-
533528
e = tun_flow_find(head, rxhash);
534529
if (likely(e)) {
535530
/* TODO: keep queueing to old queue until it's empty? */
@@ -548,7 +543,6 @@ static void tun_flow_update(struct tun_struct *tun, u32 rxhash,
548543
spin_unlock_bh(&tun->lock);
549544
}
550545

551-
unlock:
552546
rcu_read_unlock();
553547
}
554548

@@ -1937,10 +1931,13 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
19371931
rcu_read_unlock();
19381932
}
19391933

1940-
rcu_read_lock();
1941-
if (!rcu_dereference(tun->steering_prog))
1934+
/* Compute the costly rx hash only if needed for flow updates.
1935+
* We may get a very small possibility of OOO during switching, not
1936+
* worth to optimize.
1937+
*/
1938+
if (!rcu_access_pointer(tun->steering_prog) && tun->numqueues > 1 &&
1939+
!tfile->detached)
19421940
rxhash = __skb_get_hash_symmetric(skb);
1943-
rcu_read_unlock();
19441941

19451942
if (frags) {
19461943
/* Exercise flow dissector code path. */

0 commit comments

Comments
 (0)