From: Tonghao Zhang <redacted>
We may use bpf_redirect to redirect the packets to other
netdevice (e.g. ifb) in ingress and egress path.
The target netdevice may check the *skb_iif, *redirected
and *from_ingress, for example, if skb_iif or redirected
is 0, ifb will drop the packets.
bpf_redirect may be invoked in ingress or egress path, so
we set the *skb_iif unconditionally.
Fixes: a70b506efe89 ("bpf: enforce recursion limit on redirects")
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Andrii Nakryiko <andrii@kernel.org>
Cc: Martin KaFai Lau <redacted>
Cc: Song Liu <redacted>
Cc: Yonghong Song <redacted>
Cc: John Fastabend <john.fastabend@gmail.com>
Cc: KP Singh <kpsingh@kernel.org>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Tonghao Zhang <redacted>
---
net/core/filter.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
From: Tonghao Zhang <redacted>
Try to resolve the issues as below:
* We look up and then check tc_skip_classify flag in net
sched layer, even though skb don't want to be classified.
That case may consume a lot of cpu cycles.
Install the rules as below:
$ for id in $(seq 1 100); do
$ tc filter add ... egress prio $id ... action mirred egress redirect dev ifb0
$ done
netperf:
$ taskset -c 1 netperf -t TCP_RR -H ip -- -r 32,32
$ taskset -c 1 netperf -t TCP_STREAM -H ip -- -m 32
Before: 10662.33 tps, 108.95 Mbit/s
After: 12434.48 tps, 145.89 Mbit/s
For TCP_RR, there are 16.6% improvement, TCP_STREAM 33.9%.
* bpf_redirect may be invoked in egress path. if we don't
check the flags and then return immediately, the packets
will loopback.
$ tc filter add dev eth0 egress bpf direct-action obj \
test_tc_redirect_ifb.o sec redirect_ifb
Cc: Willem de Bruijn <willemb@google.com>
Cc: Cong Wang <redacted>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Andrii Nakryiko <andrii@kernel.org>
Cc: Martin KaFai Lau <redacted>
Cc: Song Liu <redacted>
Cc: Yonghong Song <redacted>
Cc: John Fastabend <john.fastabend@gmail.com>
Cc: KP Singh <kpsingh@kernel.org>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Antoine Tenart <atenart@kernel.org>
Cc: Alexander Lobakin <redacted>
Cc: Wei Wang <redacted>
Cc: "Björn Töpel" <bjorn@kernel.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Tonghao Zhang <redacted>
---
v2: https://patchwork.kernel.org/project/netdevbpf/patch/20211103143208.41282-1-xiangxia.m.yue@gmail.com/
Willem de Bruijn and Daniel Borkmann, comment this patch, but I think we should fix this,
bpf_redirect may also loopback the packets. I hope there are more comments?
---
net/core/dev.c | 3 +++
1 file changed, 3 insertions(+)
@@ -3823,6 +3823,9 @@ sch_handle_egress(struct sk_buff *skb, int *ret, struct net_device *dev)if(!miniq)returnskb;+if(skb_skip_tc_classify(skb))+returnskb;+/* qdisc_skb_cb(skb)->pkt_len was already set by the caller. */qdisc_skb_cb(skb)->mru=0;qdisc_skb_cb(skb)->post_ct=false;
From: Tonghao Zhang <redacted>
ifb netdev is used for queueing incoming traffic for shaping.
we may run bpf progs in tc cls hook(ingress or egress), to
redirect the packets to ifb.
This patch adds this test, for bpf.
Cc: Willem de Bruijn <willemb@google.com>
Cc: Cong Wang <redacted>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Andrii Nakryiko <andrii@kernel.org>
Cc: Martin KaFai Lau <redacted>
Cc: Song Liu <redacted>
Cc: Yonghong Song <redacted>
Cc: John Fastabend <john.fastabend@gmail.com>
Cc: KP Singh <kpsingh@kernel.org>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Antoine Tenart <atenart@kernel.org>
Cc: Alexander Lobakin <redacted>
Cc: Wei Wang <redacted>
Cc: "Björn Töpel" <bjorn@kernel.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Tonghao Zhang <redacted>
---
tools/testing/selftests/bpf/Makefile | 1 +
.../bpf/progs/test_bpf_redirect_ifb.c | 10 +++
.../selftests/bpf/test_bpf_redirect_ifb.sh | 73 +++++++++++++++++++
3 files changed, 84 insertions(+)
create mode 100644 tools/testing/selftests/bpf/progs/test_bpf_redirect_ifb.c
create mode 100755 tools/testing/selftests/bpf/test_bpf_redirect_ifb.sh
From: Eric Dumazet <edumazet@google.com> Date: 2021-11-29 22:43:43
On Sun, Nov 28, 2021 at 8:55 PM [off-list ref] wrote:
From: Tonghao Zhang <redacted>
Try to resolve the issues as below:
* We look up and then check tc_skip_classify flag in net
sched layer, even though skb don't want to be classified.
That case may consume a lot of cpu cycles.
Install the rules as below:
$ for id in $(seq 1 100); do
$ tc filter add ... egress prio $id ... action mirred egress redirect dev ifb0
$ done
netperf:
$ taskset -c 1 netperf -t TCP_RR -H ip -- -r 32,32
$ taskset -c 1 netperf -t TCP_STREAM -H ip -- -m 32
Before: 10662.33 tps, 108.95 Mbit/s
After: 12434.48 tps, 145.89 Mbit/s
For TCP_RR, there are 16.6% improvement, TCP_STREAM 33.9%.
These numbers mean nothing, really.
I think you should put 10,000 filters instead of 100 so that the
numbers look even better ?
As a matter of fact, you add yet another check in fast path.
For some reason I have not received the cover letter and patch 1/3.
On Tue, Nov 30, 2021 at 1:44 AM Eric Dumazet [off-list ref] wrote:
On Sun, Nov 28, 2021 at 8:55 PM [off-list ref] wrote:
quoted
From: Tonghao Zhang <redacted>
Try to resolve the issues as below:
* We look up and then check tc_skip_classify flag in net
sched layer, even though skb don't want to be classified.
That case may consume a lot of cpu cycles.
Install the rules as below:
$ for id in $(seq 1 100); do
$ tc filter add ... egress prio $id ... action mirred egress redirect dev ifb0
$ done
netperf:
$ taskset -c 1 netperf -t TCP_RR -H ip -- -r 32,32
$ taskset -c 1 netperf -t TCP_STREAM -H ip -- -m 32
Before: 10662.33 tps, 108.95 Mbit/s
After: 12434.48 tps, 145.89 Mbit/s
For TCP_RR, there are 16.6% improvement, TCP_STREAM 33.9%.
These numbers mean nothing, really.
I think you should put 10,000 filters instead of 100 so that the
numbers look even better ?
This 100 filters with different prio, I will install 10,000 filters
and test again. Thanks.
As a matter of fact, you add yet another check in fast path.
For some reason I have not received the cover letter and patch 1/3.
On Tue, Nov 30, 2021 at 9:24 AM Tonghao Zhang [off-list ref] wrote:
On Tue, Nov 30, 2021 at 1:44 AM Eric Dumazet [off-list ref] wrote:
quoted
On Sun, Nov 28, 2021 at 8:55 PM [off-list ref] wrote:
quoted
From: Tonghao Zhang <redacted>
Try to resolve the issues as below:
* We look up and then check tc_skip_classify flag in net
sched layer, even though skb don't want to be classified.
That case may consume a lot of cpu cycles.
Install the rules as below:
$ for id in $(seq 1 100); do
$ tc filter add ... egress prio $id ... action mirred egress redirect dev ifb0
$ done
netperf:
$ taskset -c 1 netperf -t TCP_RR -H ip -- -r 32,32
$ taskset -c 1 netperf -t TCP_STREAM -H ip -- -m 32
Before: 10662.33 tps, 108.95 Mbit/s
After: 12434.48 tps, 145.89 Mbit/s
For TCP_RR, there are 16.6% improvement, TCP_STREAM 33.9%.
These numbers mean nothing, really.
I think you should put 10,000 filters instead of 100 so that the
numbers look even better ?
This 100 filters with different prio, I will install 10,000 filters
and test again. Thanks.
Hi Eric
I install 10,000 filters with different prio: for example
tc filter add dev enp5s0f0 egress protocol ip prio 10000 flower
skip_hw src_ip 4.4.39.16 action mirred egress redirect dev ifb0
Test test commands:
taskset -c 1 netperf -t TCP_RR -L 4.4.39.16 -H 4.4.200.200 -- -r 32,32
taskset -c 1 netperf -t TCP_STREAM -L 4.4.39.16 -H 4.4.200.200 -- -m 32
Without patch:
152.04 tps
0.58 10^6bits/sec
With patch:
303.07 tps
1.51 10^6bits/sec
quoted
As a matter of fact, you add yet another check in fast path.
For some reason I have not received the cover letter and patch 1/3.