* [PATCH net-next] samples/bpf: Fix map interation in xdp1_user
@ 2022-10-13 20:09 Gerhard Engleder
2022-10-17 16:27 ` Song Liu
2022-10-19 18:00 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Gerhard Engleder @ 2022-10-13 20:09 UTC (permalink / raw)
To: ast, daniel, davem, kuba, hawk, john.fastabend
Cc: bpf, netdev, Gerhard Engleder
BPF map iteration in xdp1_user results in endless loop without any
output, because the return value of bpf_map_get_next_key() is checked
against the wrong value.
Other call locations of bpf_map_get_next_key() check for equal 0 for
continuing the iteration. xdp1_user checks against unequal -1. This is
wrong for a function which can return arbitrary negative errno values,
because a return value of e.g. -2 results in an endless loop.
With this fix xdp1_user is printing statistics again:
proto 0: 1 pkt/s
proto 0: 1 pkt/s
proto 17: 107383 pkt/s
proto 17: 881655 pkt/s
proto 17: 882083 pkt/s
proto 17: 881758 pkt/s
Signed-off-by: Gerhard Engleder <gerhard@engleder-embedded.com>
---
samples/bpf/xdp1_user.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/samples/bpf/xdp1_user.c b/samples/bpf/xdp1_user.c
index ac370e638fa3..281dc964de8d 100644
--- a/samples/bpf/xdp1_user.c
+++ b/samples/bpf/xdp1_user.c
@@ -51,7 +51,7 @@ static void poll_stats(int map_fd, int interval)
sleep(interval);
- while (bpf_map_get_next_key(map_fd, &key, &key) != -1) {
+ while (bpf_map_get_next_key(map_fd, &key, &key) == 0) {
__u64 sum = 0;
assert(bpf_map_lookup_elem(map_fd, &key, values) == 0);
--
2.30.2
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH net-next] samples/bpf: Fix map interation in xdp1_user
2022-10-13 20:09 [PATCH net-next] samples/bpf: Fix map interation in xdp1_user Gerhard Engleder
@ 2022-10-17 16:27 ` Song Liu
2022-10-19 18:00 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Song Liu @ 2022-10-17 16:27 UTC (permalink / raw)
To: Gerhard Engleder
Cc: ast, daniel, davem, kuba, hawk, john.fastabend, bpf, netdev
On Thu, Oct 13, 2022 at 2:01 PM Gerhard Engleder
<gerhard@engleder-embedded.com> wrote:
>
> BPF map iteration in xdp1_user results in endless loop without any
> output, because the return value of bpf_map_get_next_key() is checked
> against the wrong value.
>
> Other call locations of bpf_map_get_next_key() check for equal 0 for
> continuing the iteration. xdp1_user checks against unequal -1. This is
> wrong for a function which can return arbitrary negative errno values,
> because a return value of e.g. -2 results in an endless loop.
>
> With this fix xdp1_user is printing statistics again:
> proto 0: 1 pkt/s
> proto 0: 1 pkt/s
> proto 17: 107383 pkt/s
> proto 17: 881655 pkt/s
> proto 17: 882083 pkt/s
> proto 17: 881758 pkt/s
>
> Signed-off-by: Gerhard Engleder <gerhard@engleder-embedded.com>
Acked-by: Song Liu <song@kernel.org>
> ---
> samples/bpf/xdp1_user.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/samples/bpf/xdp1_user.c b/samples/bpf/xdp1_user.c
> index ac370e638fa3..281dc964de8d 100644
> --- a/samples/bpf/xdp1_user.c
> +++ b/samples/bpf/xdp1_user.c
> @@ -51,7 +51,7 @@ static void poll_stats(int map_fd, int interval)
>
> sleep(interval);
>
> - while (bpf_map_get_next_key(map_fd, &key, &key) != -1) {
> + while (bpf_map_get_next_key(map_fd, &key, &key) == 0) {
> __u64 sum = 0;
>
> assert(bpf_map_lookup_elem(map_fd, &key, values) == 0);
> --
> 2.30.2
>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH net-next] samples/bpf: Fix map interation in xdp1_user
2022-10-13 20:09 [PATCH net-next] samples/bpf: Fix map interation in xdp1_user Gerhard Engleder
2022-10-17 16:27 ` Song Liu
@ 2022-10-19 18:00 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-10-19 18:00 UTC (permalink / raw)
To: Gerhard Engleder
Cc: ast, daniel, davem, kuba, hawk, john.fastabend, bpf, netdev
Hello:
This patch was applied to bpf/bpf-next.git (master)
by Martin KaFai Lau <martin.lau@kernel.org>:
On Thu, 13 Oct 2022 22:09:22 +0200 you wrote:
> BPF map iteration in xdp1_user results in endless loop without any
> output, because the return value of bpf_map_get_next_key() is checked
> against the wrong value.
>
> Other call locations of bpf_map_get_next_key() check for equal 0 for
> continuing the iteration. xdp1_user checks against unequal -1. This is
> wrong for a function which can return arbitrary negative errno values,
> because a return value of e.g. -2 results in an endless loop.
>
> [...]
Here is the summary with links:
- [net-next] samples/bpf: Fix map interation in xdp1_user
https://git.kernel.org/bpf/bpf-next/c/05ee658c654b
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-10-19 18:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-13 20:09 [PATCH net-next] samples/bpf: Fix map interation in xdp1_user Gerhard Engleder
2022-10-17 16:27 ` Song Liu
2022-10-19 18:00 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox