diff mbox series

[bpf-next] selftests: bpf: Use BTF map in sk_assign

Message ID 4ebd4e68dec83863c51a9114e6507524c8feafb7.1675698070.git.fmaurer@redhat.com (mailing list archive)
State Rejected
Delegated to: BPF
Headers show
Series [bpf-next] selftests: bpf: Use BTF map in sk_assign | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for bpf-next
netdev/apply fail Patch does not apply to bpf-next

Commit Message

Felix Maurer Feb. 6, 2023, 4:07 p.m. UTC
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(-)

Comments

Andrii Nakryiko Feb. 6, 2023, 10:58 p.m. UTC | #1
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
>
Felix Maurer Feb. 7, 2023, 11:25 a.m. UTC | #2
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
diff mbox series

Patch

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";