From: Ihor Solodrai <ihor.solodrai@linux.dev>
To: dwarves@vger.kernel.org, alan.maguire@oracle.com, acme@kernel.org
Cc: bpf@vger.kernel.org, andrii@kernel.org, ast@kernel.org,
eddyz87@gmail.com, tj@kernel.org, kernel-team@meta.com
Subject: [PATCH dwarves v1 2/2] btf_encoder: implement KF_IMPLICIT_PROG_AUX_ARG kfunc flag handling
Date: Wed, 24 Sep 2025 14:15:12 -0700 [thread overview]
Message-ID: <20250924211512.1287298-3-ihor.solodrai@linux.dev> (raw)
In-Reply-To: <20250924211512.1287298-1-ihor.solodrai@linux.dev>
When a kfunc is marked with KF_IMPLICIT_PROG_AUX_ARG, do not emit the
last parameter of this function to BTF.
Validate that the ommitted parameter has a type of `struct
bpf_prog_aux *`, otherwise report an error and fail BTF encoding.
Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev>
---
btf_encoder.c | 42 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)
diff --git a/btf_encoder.c b/btf_encoder.c
index 4906943..eb669f9 100644
--- a/btf_encoder.c
+++ b/btf_encoder.c
@@ -48,6 +48,7 @@
#define KF_ARENA_RET (1 << 13)
#define KF_ARENA_ARG1 (1 << 14)
#define KF_ARENA_ARG2 (1 << 15)
+#define KF_IMPLICIT_PROG_AUX_ARG (1 << 16)
struct btf_id_and_flag {
uint32_t id;
@@ -868,6 +869,41 @@ static int32_t btf_encoder__add_func_proto_for_ftype(struct btf_encoder *encoder
return id;
}
+static const struct btf_type *btf__unqualified_type_by_id(const struct btf *btf, int32_t type_id)
+{
+ const struct btf_type *t = btf__type_by_id(btf, type_id);
+ while (btf_is_const(t) || btf_is_volatile(t) || btf_is_restrict(t)) {
+ t = btf__type_by_id(btf, t->type);
+ }
+ return t;
+}
+
+static int validate_kfunc_with_implicit_prog_aux_arg(struct btf_encoder_func_state *state)
+{
+ /* The last argument must be a pointer to 'struct bpf_prog_aux' */
+ const struct btf_encoder_func_parm *p = &state->parms[state->nr_parms - 1];
+ const struct btf *btf = state->encoder->btf;
+ const struct btf_type *t = btf__unqualified_type_by_id(btf, p->type_id);
+ if (!btf_is_ptr(t))
+ goto out_err;
+
+ const uint32_t struct_type_id = t->type;
+ t = btf__unqualified_type_by_id(btf, struct_type_id);
+ if (!btf_is_struct(t))
+ goto out_err;
+
+ const char *name = btf__name_by_offset(btf, t->name_off);
+ if (strcmp(name, "bpf_prog_aux") != 0)
+ goto out_err;
+
+ return 0;
+out_err:
+ btf__log_err(btf, BTF_KIND_FUNC_PROTO, state->elf->name, true, 0,
+ "return=%u Error emitting BTF func proto for kfunc with implicit bpf_prog_aux: the last parameter is not 'struct bpf_prog_aux*'",
+ p->type_id);
+ return -1;
+}
+
static int32_t btf_encoder__add_func_proto_for_state(struct btf_encoder *encoder, struct btf_encoder_func_state *state)
{
uint16_t nr_params, param_idx;
@@ -887,6 +923,12 @@ static int32_t btf_encoder__add_func_proto_for_state(struct btf_encoder *encoder
nr_params = state->nr_parms;
type_id = state->ret_type_id;
+ if (is_kfunc_state(state) && KF_IMPLICIT_PROG_AUX_ARG & state->elf->kfunc_flags) {
+ if (validate_kfunc_with_implicit_prog_aux_arg(state))
+ return -1;
+ nr_params--;
+ }
+
id = btf_encoder__emit_func_proto(encoder, type_id, nr_params);
if (id < 0)
return id;
--
2.51.0
next prev parent reply other threads:[~2025-09-24 21:16 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-24 21:15 [PATCH dwarves v1 0/2] btf_encoder: KF_IMPLICIT_PROG_AUX_ARG support Ihor Solodrai
2025-09-24 21:15 ` [PATCH dwarves v1 1/2] btf_encoder: refactor btf_encoder__add_func_proto Ihor Solodrai
2025-09-24 21:15 ` Ihor Solodrai [this message]
2025-09-25 1:22 ` [PATCH dwarves v1 2/2] btf_encoder: implement KF_IMPLICIT_PROG_AUX_ARG kfunc flag handling Eduard Zingerman
2025-09-25 3:59 ` Ihor Solodrai
2025-09-25 13:28 ` Eduard Zingerman
2025-09-25 17:15 ` Andrii Nakryiko
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=20250924211512.1287298-3-ihor.solodrai@linux.dev \
--to=ihor.solodrai@linux.dev \
--cc=acme@kernel.org \
--cc=alan.maguire@oracle.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=dwarves@vger.kernel.org \
--cc=eddyz87@gmail.com \
--cc=kernel-team@meta.com \
--cc=tj@kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.