Commit cfe77683 authored by Alan Maguire's avatar Alan Maguire Committed by Alexei Starovoitov

selftests/bpf: Ensure snprintf_btf/bpf_iter tests compatibility with old vmlinux.h

Andrii reports that bpf selftests relying on "struct btf_ptr" and BTF_F_*
values will not build as vmlinux.h for older kernels will not include
"struct btf_ptr" or the BTF_F_* enum values.  Undefine and redefine
them to work around this.

Fixes: b72091bd ("selftests/bpf: Add test for bpf_seq_printf_btf helper")
Fixes: 076a95f5 ("selftests/bpf: Add bpf_snprintf_btf helper tests")
Reported-by: default avatarAndrii Nakryiko <andrii.nakryiko@gmail.com>
Signed-off-by: default avatarAlan Maguire <alan.maguire@oracle.com>
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
Acked-by: default avatarAndrii Nakryiko <andriin@fb.com>
Link: https://lore.kernel.org/bpf/1601379151-21449-3-git-send-email-alan.maguire@oracle.com
parent 96c48058
...@@ -14,6 +14,11 @@ ...@@ -14,6 +14,11 @@
#define bpf_iter__bpf_map_elem bpf_iter__bpf_map_elem___not_used #define bpf_iter__bpf_map_elem bpf_iter__bpf_map_elem___not_used
#define bpf_iter__bpf_sk_storage_map bpf_iter__bpf_sk_storage_map___not_used #define bpf_iter__bpf_sk_storage_map bpf_iter__bpf_sk_storage_map___not_used
#define bpf_iter__sockmap bpf_iter__sockmap___not_used #define bpf_iter__sockmap bpf_iter__sockmap___not_used
#define btf_ptr btf_ptr___not_used
#define BTF_F_COMPACT BTF_F_COMPACT___not_used
#define BTF_F_NONAME BTF_F_NONAME___not_used
#define BTF_F_PTR_RAW BTF_F_PTR_RAW___not_used
#define BTF_F_ZERO BTF_F_ZERO___not_used
#include "vmlinux.h" #include "vmlinux.h"
#undef bpf_iter_meta #undef bpf_iter_meta
#undef bpf_iter__bpf_map #undef bpf_iter__bpf_map
...@@ -28,6 +33,11 @@ ...@@ -28,6 +33,11 @@
#undef bpf_iter__bpf_map_elem #undef bpf_iter__bpf_map_elem
#undef bpf_iter__bpf_sk_storage_map #undef bpf_iter__bpf_sk_storage_map
#undef bpf_iter__sockmap #undef bpf_iter__sockmap
#undef btf_ptr
#undef BTF_F_COMPACT
#undef BTF_F_NONAME
#undef BTF_F_PTR_RAW
#undef BTF_F_ZERO
struct bpf_iter_meta { struct bpf_iter_meta {
struct seq_file *seq; struct seq_file *seq;
...@@ -105,3 +115,16 @@ struct bpf_iter__sockmap { ...@@ -105,3 +115,16 @@ struct bpf_iter__sockmap {
void *key; void *key;
struct sock *sk; struct sock *sk;
}; };
struct btf_ptr {
void *ptr;
__u32 type_id;
__u32 flags;
};
enum {
BTF_F_COMPACT = (1ULL << 0),
BTF_F_NONAME = (1ULL << 1),
BTF_F_PTR_RAW = (1ULL << 2),
BTF_F_ZERO = (1ULL << 3),
};
/* SPDX-License-Identifier: GPL-2.0 */
/* Copyright (c) 2020, Oracle and/or its affiliates. */
/* "undefine" structs in vmlinux.h, because we "override" them below */
#define btf_ptr btf_ptr___not_used
#define BTF_F_COMPACT BTF_F_COMPACT___not_used
#define BTF_F_NONAME BTF_F_NONAME___not_used
#define BTF_F_PTR_RAW BTF_F_PTR_RAW___not_used
#define BTF_F_ZERO BTF_F_ZERO___not_used
#include "vmlinux.h"
#undef btf_ptr
#undef BTF_F_COMPACT
#undef BTF_F_NONAME
#undef BTF_F_PTR_RAW
#undef BTF_F_ZERO
struct btf_ptr {
void *ptr;
__u32 type_id;
__u32 flags;
};
enum {
BTF_F_COMPACT = (1ULL << 0),
BTF_F_NONAME = (1ULL << 1),
BTF_F_PTR_RAW = (1ULL << 2),
BTF_F_ZERO = (1ULL << 3),
};
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2020, Oracle and/or its affiliates. */ /* Copyright (c) 2020, Oracle and/or its affiliates. */
#include "vmlinux.h" #include "btf_ptr.h"
#include <bpf/bpf_helpers.h> #include <bpf/bpf_helpers.h>
#include <bpf/bpf_tracing.h> #include <bpf/bpf_tracing.h>
#include <bpf/bpf_core_read.h> #include <bpf/bpf_core_read.h>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment