Patch "bpf: Fix dev's rx stats for bpf_redirect_peer traffic" has been added to the 6.6-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    bpf: Fix dev's rx stats for bpf_redirect_peer traffic

to the 6.6-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     bpf-fix-dev-s-rx-stats-for-bpf_redirect_peer-traffic.patch
and it can be found in the queue-6.6 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit aff8308229e5dc0dcfac6b14589ea28a885e802a
Author: Peilin Ye <peilin.ye@xxxxxxxxxxxxx>
Date:   Tue Nov 14 01:42:17 2023 +0100

    bpf: Fix dev's rx stats for bpf_redirect_peer traffic
    
    [ Upstream commit 024ee930cb3c9ae49e4266aee89cfde0ebb407e1 ]
    
    Traffic redirected by bpf_redirect_peer() (used by recent CNIs like Cilium)
    is not accounted for in the RX stats of supported devices (that is, veth
    and netkit), confusing user space metrics collectors such as cAdvisor [0],
    as reported by Youlun.
    
    Fix it by calling dev_sw_netstats_rx_add() in skb_do_redirect(), to update
    RX traffic counters. Devices that support ndo_get_peer_dev _must_ use the
    @tstats per-CPU counters (instead of @lstats, or @dstats).
    
    To make this more fool-proof, error out when ndo_get_peer_dev is set but
    @tstats are not selected.
    
      [0] Specifically, the "container_network_receive_{byte,packet}s_total"
          counters are affected.
    
    Fixes: 9aa1206e8f48 ("bpf: Add redirect_peer helper")
    Reported-by: Youlun Zhang <zhangyoulun@xxxxxxxxxxxxx>
    Signed-off-by: Peilin Ye <peilin.ye@xxxxxxxxxxxxx>
    Co-developed-by: Daniel Borkmann <daniel@xxxxxxxxxxxxx>
    Signed-off-by: Daniel Borkmann <daniel@xxxxxxxxxxxxx>
    Reviewed-by: Nikolay Aleksandrov <razor@xxxxxxxxxxxxx>
    Link: https://lore.kernel.org/r/20231114004220.6495-6-daniel@xxxxxxxxxxxxx
    Signed-off-by: Martin KaFai Lau <martin.lau@xxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/net/core/dev.c b/net/core/dev.c
index 37444c8e22054..9bf90b2a75b6a 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -10054,6 +10054,14 @@ static int netdev_do_alloc_pcpu_stats(struct net_device *dev)
 {
 	void __percpu *v;
 
+	/* Drivers implementing ndo_get_peer_dev must support tstat
+	 * accounting, so that skb_do_redirect() can bump the dev's
+	 * RX stats upon network namespace switch.
+	 */
+	if (dev->netdev_ops->ndo_get_peer_dev &&
+	    dev->pcpu_stat_type != NETDEV_PCPU_STAT_TSTATS)
+		return -EOPNOTSUPP;
+
 	switch (dev->pcpu_stat_type) {
 	case NETDEV_PCPU_STAT_NONE:
 		return 0;
diff --git a/net/core/filter.c b/net/core/filter.c
index a094694899c99..b149a165c405c 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -2489,6 +2489,7 @@ int skb_do_redirect(struct sk_buff *skb)
 			     net_eq(net, dev_net(dev))))
 			goto out_drop;
 		skb->dev = dev;
+		dev_sw_netstats_rx_add(dev, skb->len);
 		return -EAGAIN;
 	}
 	return flags & BPF_F_NEIGH ?



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux