* [PATCH bpf-next] selftests: bpf: Use BTF map in sk_assign
@ 2023-02-06 16:07 Felix Maurer
2023-02-06 22:58 ` Andrii Nakryiko
0 siblings, 1 reply; 3+ messages in thread
From: Felix Maurer @ 2023-02-06 16:07 UTC (permalink / raw)
To: bpf
Cc: andrii, mykolal, ast, daniel, martin.lau, song, yhs,
john.fastabend, kpsingh, sdf, haoluo, jolsa
The sk_assign selftest uses tc to load the BPF object file for the test. If
tc is linked against libbpf 1.0+, this test failed, because the BPF file
used the legacy maps section. This approach is considered legacy by libbpf
and tc (see examples/bpf/README in the iproute2 repo).
Therefore, switch to the approach recommended by iproute2 and use a BTF
defined map. This is also well supported by libbpf.
Signed-off-by: Felix Maurer <fmaurer@redhat.com>
---
.../selftests/bpf/progs/test_sk_assign.c | 24 +++++--------------
1 file changed, 6 insertions(+), 18 deletions(-)
diff --git a/tools/testing/selftests/bpf/progs/test_sk_assign.c b/tools/testing/selftests/bpf/progs/test_sk_assign.c
index 98c6493d9b91..b0536bdc002b 100644
--- a/tools/testing/selftests/bpf/progs/test_sk_assign.c
+++ b/tools/testing/selftests/bpf/progs/test_sk_assign.c
@@ -16,25 +16,13 @@
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_endian.h>
-/* Pin map under /sys/fs/bpf/tc/globals/<map name> */
-#define PIN_GLOBAL_NS 2
-
-/* Must match struct bpf_elf_map layout from iproute2 */
struct {
- __u32 type;
- __u32 size_key;
- __u32 size_value;
- __u32 max_elem;
- __u32 flags;
- __u32 id;
- __u32 pinning;
-} server_map SEC("maps") = {
- .type = BPF_MAP_TYPE_SOCKMAP,
- .size_key = sizeof(int),
- .size_value = sizeof(__u64),
- .max_elem = 1,
- .pinning = PIN_GLOBAL_NS,
-};
+ __uint(type, BPF_MAP_TYPE_SOCKMAP);
+ __uint(key_size, sizeof(int));
+ __uint(value_size, sizeof(__u64));
+ __uint(max_entries, 1);
+ __uint(pinning, LIBBPF_PIN_BY_NAME);
+} server_map SEC(".maps");
char _license[] SEC("license") = "GPL";
--
2.39.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH bpf-next] selftests: bpf: Use BTF map in sk_assign
2023-02-06 16:07 [PATCH bpf-next] selftests: bpf: Use BTF map in sk_assign Felix Maurer
@ 2023-02-06 22:58 ` Andrii Nakryiko
2023-02-07 11:25 ` Felix Maurer
0 siblings, 1 reply; 3+ messages in thread
From: Andrii Nakryiko @ 2023-02-06 22:58 UTC (permalink / raw)
To: Felix Maurer
Cc: bpf, andrii, mykolal, ast, daniel, martin.lau, song, yhs,
john.fastabend, kpsingh, sdf, haoluo, jolsa
On Mon, Feb 6, 2023 at 8:07 AM Felix Maurer <fmaurer@redhat.com> wrote:
>
> The sk_assign selftest uses tc to load the BPF object file for the test. If
> tc is linked against libbpf 1.0+, this test failed, because the BPF file
> used the legacy maps section. This approach is considered legacy by libbpf
> and tc (see examples/bpf/README in the iproute2 repo).
>
> Therefore, switch to the approach recommended by iproute2 and use a BTF
> defined map. This is also well supported by libbpf.
>
> Signed-off-by: Felix Maurer <fmaurer@redhat.com>
> ---
This test was updated (see [0]) to support iproute2 version with and
without libbpf support. Please check the latest bpf-next/master.
[0] 7ce878ca81bc ("selftests/bpf: Fix sk_assign on s390x")
> .../selftests/bpf/progs/test_sk_assign.c | 24 +++++--------------
> 1 file changed, 6 insertions(+), 18 deletions(-)
>
> diff --git a/tools/testing/selftests/bpf/progs/test_sk_assign.c b/tools/testing/selftests/bpf/progs/test_sk_assign.c
> index 98c6493d9b91..b0536bdc002b 100644
> --- a/tools/testing/selftests/bpf/progs/test_sk_assign.c
> +++ b/tools/testing/selftests/bpf/progs/test_sk_assign.c
> @@ -16,25 +16,13 @@
> #include <bpf/bpf_helpers.h>
> #include <bpf/bpf_endian.h>
>
> -/* Pin map under /sys/fs/bpf/tc/globals/<map name> */
> -#define PIN_GLOBAL_NS 2
> -
> -/* Must match struct bpf_elf_map layout from iproute2 */
> struct {
> - __u32 type;
> - __u32 size_key;
> - __u32 size_value;
> - __u32 max_elem;
> - __u32 flags;
> - __u32 id;
> - __u32 pinning;
> -} server_map SEC("maps") = {
> - .type = BPF_MAP_TYPE_SOCKMAP,
> - .size_key = sizeof(int),
> - .size_value = sizeof(__u64),
> - .max_elem = 1,
> - .pinning = PIN_GLOBAL_NS,
> -};
> + __uint(type, BPF_MAP_TYPE_SOCKMAP);
> + __uint(key_size, sizeof(int));
> + __uint(value_size, sizeof(__u64));
> + __uint(max_entries, 1);
> + __uint(pinning, LIBBPF_PIN_BY_NAME);
> +} server_map SEC(".maps");
>
> char _license[] SEC("license") = "GPL";
>
> --
> 2.39.1
>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH bpf-next] selftests: bpf: Use BTF map in sk_assign
2023-02-06 22:58 ` Andrii Nakryiko
@ 2023-02-07 11:25 ` Felix Maurer
0 siblings, 0 replies; 3+ messages in thread
From: Felix Maurer @ 2023-02-07 11:25 UTC (permalink / raw)
To: Andrii Nakryiko
Cc: bpf, andrii, mykolal, ast, daniel, martin.lau, song, yhs,
john.fastabend, kpsingh, sdf, haoluo, jolsa
On 06.02.23 23:58, Andrii Nakryiko wrote:
> On Mon, Feb 6, 2023 at 8:07 AM Felix Maurer <fmaurer@redhat.com> wrote:
>>
>> The sk_assign selftest uses tc to load the BPF object file for the test. If
>> tc is linked against libbpf 1.0+, this test failed, because the BPF file
>> used the legacy maps section. This approach is considered legacy by libbpf
>> and tc (see examples/bpf/README in the iproute2 repo).
>>
>> Therefore, switch to the approach recommended by iproute2 and use a BTF
>> defined map. This is also well supported by libbpf.
>>
>> Signed-off-by: Felix Maurer <fmaurer@redhat.com>
>> ---
>
> This test was updated (see [0]) to support iproute2 version with and
> without libbpf support. Please check the latest bpf-next/master.
>
> [0] 7ce878ca81bc ("selftests/bpf: Fix sk_assign on s390x")
Sorry for the noise, I missed that commit. Forget about my patch then.
Felix
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-02-07 11:26 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-06 16:07 [PATCH bpf-next] selftests: bpf: Use BTF map in sk_assign Felix Maurer
2023-02-06 22:58 ` Andrii Nakryiko
2023-02-07 11:25 ` Felix Maurer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox