From: Jiri Olsa <olsajiri@gmail.com>
To: Alan Maguire <alan.maguire@oracle.com>
Cc: andrii@kernel.org, ast@kernel.org, daniel@iogearbox.net,
martin.lau@linux.dev, eddyz87@gmail.com, memxor@gmail.com,
song@kernel.org, yonghong.song@linux.dev, bpf@vger.kernel.org
Subject: Re: [PATCH v2 bpf-next 1/2] libbpf: Allow use of feature cache for non-token cases
Date: Wed, 8 Apr 2026 15:37:05 +0200 [thread overview]
Message-ID: <adZaASNAuZSaxcni@krava> (raw)
In-Reply-To: <20260408105324.663280-2-alan.maguire@oracle.com>
On Wed, Apr 08, 2026 at 11:53:23AM +0100, Alan Maguire wrote:
> Allow bpf object feat_cache assignment in BPF selftests
> to simulate missing features via inclusion of libbpf_internal.h
> and use of bpf_object_set_feat_cache() and bpf_object__sanitize_btf() to
> test BTF sanitization for cases where missing features are simulated.
>
> Signed-off-by: Alan Maguire <alan.maguire@oracle.com>
> ---
> tools/lib/bpf/libbpf.c | 12 ++++++++++--
> tools/lib/bpf/libbpf_internal.h | 3 ++-
> 2 files changed, 12 insertions(+), 3 deletions(-)
>
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index 42bdba4efd0c..b7b636786d38 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -3145,7 +3145,7 @@ static bool btf_needs_sanitization(struct bpf_object *obj)
> !has_layout;
> }
>
> -static struct btf *bpf_object__sanitize_btf(struct bpf_object *obj, struct btf *orig_btf)
> +struct btf *bpf_object__sanitize_btf(struct bpf_object *obj, struct btf *orig_btf)
> {
> bool has_func_global = kernel_supports(obj, FEAT_BTF_GLOBAL_FUNC);
> bool has_datasec = kernel_supports(obj, FEAT_BTF_DATASEC);
> @@ -5203,12 +5203,20 @@ bool kernel_supports(const struct bpf_object *obj, enum kern_feature_id feat_id)
> */
> return true;
>
> - if (obj->token_fd)
> + if (obj->feat_cache)
> return feat_supported(obj->feat_cache, feat_id);
>
> return feat_supported(NULL, feat_id);
> }
>
> +/* Used in testing to simulate missing features. */
> +void bpf_object_set_feat_cache(struct bpf_object *obj, struct kern_feature_cache *cache)
> +{
> + if (obj->feat_cache)
> + zfree(&obj->feat_cache);
nit, no need to zfree, we set it right below
jirka
> + obj->feat_cache = cache;
> +}
> +
> static bool map_is_reuse_compat(const struct bpf_map *map, int map_fd)
> {
> struct bpf_map_info map_info;
> diff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_internal.h
> index cabdaef79098..3781c45b46d3 100644
> --- a/tools/lib/bpf/libbpf_internal.h
> +++ b/tools/lib/bpf/libbpf_internal.h
> @@ -414,6 +414,7 @@ struct kern_feature_cache {
>
> bool feat_supported(struct kern_feature_cache *cache, enum kern_feature_id feat_id);
> bool kernel_supports(const struct bpf_object *obj, enum kern_feature_id feat_id);
> +void bpf_object_set_feat_cache(struct bpf_object *obj, struct kern_feature_cache *cache);
>
> int probe_kern_syscall_wrapper(int token_fd);
> int probe_memcg_account(int token_fd);
> @@ -427,7 +428,7 @@ int libbpf__load_raw_btf(const char *raw_types, size_t types_len,
> int libbpf__load_raw_btf_hdr(const struct btf_header *hdr,
> const char *raw_types, const char *str_sec,
> const char *layout_sec, int token_fd);
> -
> +struct btf *bpf_object__sanitize_btf(struct bpf_object *obj, struct btf *orig_btf);
> int btf_load_into_kernel(struct btf *btf,
> char *log_buf, size_t log_sz, __u32 log_level,
> int token_fd);
> --
> 2.39.3
>
next prev parent reply other threads:[~2026-04-08 13:37 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-08 10:53 [PATCH v2 bpf-next 0/2] selftests/bpf: Test BTF sanitization Alan Maguire
2026-04-08 10:53 ` [PATCH v2 bpf-next 1/2] libbpf: Allow use of feature cache for non-token cases Alan Maguire
2026-04-08 13:37 ` Jiri Olsa [this message]
2026-04-08 10:53 ` [PATCH v2 bpf-next 2/2] selftests/bpf: Add BTF sanitize test covering BTF layout Alan Maguire
2026-04-08 12:53 ` Chengkaitao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=adZaASNAuZSaxcni@krava \
--to=olsajiri@gmail.com \
--cc=alan.maguire@oracle.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=song@kernel.org \
--cc=yonghong.song@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox