Skip to content

bpf: Support struct btf_struct_meta via KF_IMPLICIT_ARGS#11385

Closed
kernel-patches-daemon-bpf[bot] wants to merge 2 commits intobpf-next_basefrom
series/1065888=>bpf-next
Closed

bpf: Support struct btf_struct_meta via KF_IMPLICIT_ARGS#11385
kernel-patches-daemon-bpf[bot] wants to merge 2 commits intobpf-next_basefrom
series/1065888=>bpf-next

Conversation

@kernel-patches-daemon-bpf
Copy link
Copy Markdown

Pull request for series with
subject: bpf: Support struct btf_struct_meta via KF_IMPLICIT_ARGS
version: 1
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=1065888

@kernel-patches-daemon-bpf
Copy link
Copy Markdown
Author

Upstream branch: ca0f39a
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1065888
version: 1

@kernel-patches-review-bot
Copy link
Copy Markdown

commit a8c144a47f9df6b37f18ab77c2434c232b710e9f
Author: Ihor Solodrai <ihor.solodrai@linux.dev>

bpf: Support struct btf_struct_meta via KF_IMPLICIT_ARGS

Add new kfuncs with KF_IMPLICIT_ARGS that correspond to each _impl
kfunc accepting meta__ign, with typed struct btf_struct_meta *meta
parameters. The existing _impl kfuncs become thin wrappers for
backwards compatibility.

Link: https://lore.kernel.org/bpf/20260120222638.3976562-1-ihor.solodrai@linux.dev/

> diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c
> index cb6d242bd093..e5c8fb6596e7 100644
> --- a/kernel/bpf/helpers.c
> +++ b/kernel/bpf/helpers.c

[ ... ]

> +__bpf_kfunc void *bpf_percpu_obj_new(u64 local_type_id__k, struct btf_struct_meta *meta)
> +{
> +	u64 size = local_type_id__k;
> +
> +	/* The verifier has ensured that meta__ign must be NULL */
> +	return bpf_mem_alloc(&bpf_global_percpu_ma, size);
> +}

The parameter here is named "meta", not "meta__ign". Should this
comment say "meta" instead?

[ ... ]

> +__bpf_kfunc void bpf_percpu_obj_drop(void *p__alloc, struct btf_struct_meta *meta)
> +{
> +	/* The verifier has ensured that meta__ign must be NULL */
> +	bpf_mem_free_rcu(&bpf_global_percpu_ma, p__alloc);
> +}

Same here -- the comment references "meta__ign" but the parameter is
"meta".

> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index 4fbacd2149cd..2e4f1e9b1d37 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c

[ ... ]

> @@ -13575,12 +13658,12 @@ static int check_kfunc_args(struct bpf_verifier_env *env, struct bpf_kfunc_call_
>  		case KF_ARG_PTR_TO_ALLOC_BTF_ID:
>  			if (reg->type == (PTR_TO_BTF_ID | MEM_ALLOC)) {
> -				if (meta->func_id != special_kfunc_list[KF_bpf_obj_drop_impl]) {
> +				if (!is_bpf_obj_drop_kfunc(meta->func_id)) {
>  					verbose(env, "arg#%d expected for bpf_obj_drop_impl()\n", i);
>  					return -EINVAL;
>  				}
>  			} else if (reg->type == (PTR_TO_BTF_ID | MEM_ALLOC | MEM_PERCPU)) {
> -				if (meta->func_id != special_kfunc_list[KF_bpf_percpu_obj_drop_impl]) {
> +				if (!is_bpf_percpu_obj_drop_kfunc(meta->func_id)) {
>  					verbose(env, "arg#%d expected for bpf_percpu_obj_drop_impl()\n", i);
>  					return -EINVAL;
>  				}

The conditions now match both bpf_obj_drop and bpf_obj_drop_impl (and
their percpu variants), but the error messages still reference only
the _impl names. Would it make sense to update these to say
"bpf_obj_drop" and "bpf_percpu_obj_drop" respectively, so that a
developer calling the new variants sees the right function name in
the error?



AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

In-Reply-To-Subject: bpf: Support struct btf_struct_meta via KF_IMPLICIT_ARGS
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/23020502189

@kernel-patches-review-bot
Copy link
Copy Markdown

commit 1cf438425c438fadc801d3c0024a225f7bcdff92
Author: Ihor Solodrai <ihor.solodrai@linux.dev>

selftests/bpf: Update kfuncs using btf_struct_meta to new variants

Update selftests to use the new non-_impl kfuncs marked with
KF_IMPLICIT_ARGS by removing redundant declarations and macros from
bpf_experimental.h and updating relevant callsites.

> diff --git a/tools/testing/selftests/bpf/bpf_experimental.h b/tools/testing/selftests/bpf/bpf_experimental.h
> --- a/tools/testing/selftests/bpf/bpf_experimental.h
> +++ b/tools/testing/selftests/bpf/bpf_experimental.h
> @@ -8,156 +8,11 @@ #define __BPF_EXPERIMENTAL__
>  #define __contains(name, node) __attribute__((btf_decl_tag("contains:" #name ":" #node)))

[ ... ]

> -extern void *bpf_percpu_obj_new_impl(__u64 local_type_id, void *meta) __ksym;
> +/* Convenience macro to wrap over bpf_obj_new */
> +#define bpf_obj_new(type) ((type *)bpf_obj_new(bpf_core_type_id_local(type)))
>
>  /* Convenience macro to wrap over bpf_percpu_obj_new_impl */
> -#define bpf_percpu_obj_new(type) ((type __percpu_kptr *)bpf_percpu_obj_new_impl(bpf_core_type_id_local(type), NULL))
> +#define bpf_percpu_obj_new(type) ((type __percpu_kptr *)bpf_percpu_obj_new(bpf_core_type_id_local(type)))

The comment above bpf_percpu_obj_new still says "wrap over
bpf_percpu_obj_new_impl" but the macro now wraps bpf_percpu_obj_new.

> -extern void bpf_percpu_obj_drop_impl(void *kptr, void *meta) __ksym;

The extern for bpf_percpu_obj_drop_impl is removed here, but later
in the same file the bpf_percpu_obj_drop macro was not updated:

    /* Convenience macro to wrap over bpf_obj_drop_impl */
    #define bpf_percpu_obj_drop(kptr) bpf_percpu_obj_drop_impl(kptr, NULL)

Was bpf_percpu_obj_drop missed? Every other kfunc in this commit was
moved from the _impl variant to the new KF_IMPLICIT_ARGS variant
(bpf_obj_new, bpf_obj_drop, bpf_percpu_obj_new, bpf_refcount_acquire,
bpf_list_push_front, bpf_list_push_back, bpf_rbtree_add), but
bpf_percpu_obj_drop still goes through bpf_percpu_obj_drop_impl.

The macro is used in test_bpf_ma.c in batch_percpu_alloc() and
batch_percpu_free().



AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

In-Reply-To-Subject: selftests/bpf: Update kfuncs using btf_struct_meta to new variants
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/23020502189

@kernel-patches-daemon-bpf
Copy link
Copy Markdown
Author

@kernel-patches-daemon-bpf
Copy link
Copy Markdown
Author

@kernel-patches-daemon-bpf
Copy link
Copy Markdown
Author

Upstream branch: bb41fce
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1065888
version: 1

@kernel-patches-daemon-bpf
Copy link
Copy Markdown
Author

Upstream branch: bb41fce
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1065888
version: 1

@kernel-patches-daemon-bpf
Copy link
Copy Markdown
Author

Upstream branch: 202e42e
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1065888
version: 1

@kernel-patches-daemon-bpf
Copy link
Copy Markdown
Author

Upstream branch: 6c8e1a9
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1065888
version: 1

@kernel-patches-daemon-bpf
Copy link
Copy Markdown
Author

Upstream branch: 2364959
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1065888
version: 1

@kernel-patches-daemon-bpf
Copy link
Copy Markdown
Author

Upstream branch: 2364959
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1065888
version: 1

@kernel-patches-daemon-bpf
Copy link
Copy Markdown
Author

Upstream branch: 2364959
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1065888
version: 1

@kernel-patches-daemon-bpf
Copy link
Copy Markdown
Author

Upstream branch: 2364959
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1065888
version: 1

@kernel-patches-daemon-bpf
Copy link
Copy Markdown
Author

Upstream branch: 2364959
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1065888
version: 1

@kernel-patches-daemon-bpf
Copy link
Copy Markdown
Author

Upstream branch: 77378da
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1065888
version: 1

@kernel-patches-daemon-bpf
Copy link
Copy Markdown
Author

Upstream branch: 77378da
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1065888
version: 1

theihor added 2 commits March 18, 2026 09:25
The following kfuncs currently accept void *meta__ign argument:
  * bpf_obj_new_impl
  * bpf_obj_drop_impl
  * bpf_percpu_obj_new_impl
  * bpf_percpu_obj_drop_impl
  * bpf_refcount_acquire_impl
  * bpf_list_push_front_impl
  * bpf_rbtree_add_impl

The __ign suffix is an indicator for the verifier to skip the argument
in check_kfunc_args(). Then, in fixup_kfunc_call() the verifier may
set the value of this argument to struct btf_struct_meta *
kptr_struct_meta from insn_aux_data.

BPF programs must pass a dummy NULL value when caling these kfuncs.

Additionally, the list and rbtree _impl kfuncs also accept an implicit
u64 argument, which doesn't require __ign suffix because it's a
scalar, and BPF programs explicitly pass 0.

Add new kfuncs with KF_IMPLICIT_ARGS [1], that correspond to each
_impl kfunc accepting meta__ign. The existing _impl kfuncs remain
unchanged for backwards compatibility.

To support this, add "btf_struct_meta" to the list of recognized
implicit argument types in resolve_btfids.

Implement is_kfunc_arg_implicit() in the verifier, that determines
implicit args by inspecting both (_impl and non-_impl) BTF prototypes
of the kfunc.

Update the special_kfunc_list in the verifier and relevant checks to
support both the old _impl and the new KF_IMPLICIT_ARGS variants of
btf_struct_meta users.

[1] https://lore.kernel.org/bpf/20260120222638.3976562-1-ihor.solodrai@linux.dev/

Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev>
Update selftests to use the new non-_impl kfuncs marked with
KF_IMPLICIT_ARGS by removing redundant declarations and macros from
bpf_experimental.h (the new kfuncs are present in the vmlinux.h) and
updating relevant callsites.

Fix spin_lock verifier-log matching for lock_id_kptr_preserve by
accepting variable instruction numbers. The calls to kfuncs with
implicit arguments do not have register moves (e.g. r5 = 0)
corresponding to dummy arguments anymore, so the order of instructions
has shifted.

Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev>
@kernel-patches-daemon-bpf kernel-patches-daemon-bpf Bot deleted the series/1065888=>bpf-next branch March 20, 2026 23:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant