Skip to content

Commit fe72248

Browse files
AsphalttKernel Patches Daemon
authored andcommitted
bpf: Allow union argument in trampoline based programs
Currently, functions with 'union' arguments cannot be traced with fentry/fexit: bpftrace -e 'fentry:release_pages { exit(); }' -v The function release_pages arg0 type UNION is unsupported. The type of the 'release_pages' arg0 is defined as: typedef union { struct page **pages; struct folio **folios; struct encoded_page **encoded_pages; } release_pages_arg __attribute__ ((__transparent_union__)); This patch relaxes the restriction by allowing function arguments of type 'union' to be traced in verifier. Reviewed-by: Amery Hung <[email protected]> Signed-off-by: Leon Hwang <[email protected]>
1 parent a98c373 commit fe72248

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

include/linux/bpf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1118,7 +1118,7 @@ struct bpf_prog_offload {
11181118
*/
11191119
#define MAX_BPF_FUNC_REG_ARGS 5
11201120

1121-
/* The argument is a structure. */
1121+
/* The argument is a structure or a union. */
11221122
#define BTF_FMODEL_STRUCT_ARG BIT(0)
11231123

11241124
/* The argument is signed. */

kernel/bpf/btf.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6762,7 +6762,7 @@ bool btf_ctx_access(int off, int size, enum bpf_access_type type,
67626762
/* skip modifiers */
67636763
while (btf_type_is_modifier(t))
67646764
t = btf_type_by_id(btf, t->type);
6765-
if (btf_type_is_small_int(t) || btf_is_any_enum(t) || __btf_type_is_struct(t))
6765+
if (btf_type_is_small_int(t) || btf_is_any_enum(t) || btf_type_is_struct(t))
67666766
/* accessing a scalar */
67676767
return true;
67686768
if (!btf_type_is_ptr(t)) {
@@ -7334,7 +7334,7 @@ static int __get_type_size(struct btf *btf, u32 btf_id,
73347334
if (btf_type_is_ptr(t))
73357335
/* kernel size of pointer. Not BPF's size of pointer*/
73367336
return sizeof(void *);
7337-
if (btf_type_is_int(t) || btf_is_any_enum(t) || __btf_type_is_struct(t))
7337+
if (btf_type_is_int(t) || btf_is_any_enum(t) || btf_type_is_struct(t))
73387338
return t->size;
73397339
return -EINVAL;
73407340
}
@@ -7343,7 +7343,7 @@ static u8 __get_type_fmodel_flags(const struct btf_type *t)
73437343
{
73447344
u8 flags = 0;
73457345

7346-
if (__btf_type_is_struct(t))
7346+
if (btf_type_is_struct(t))
73477347
flags |= BTF_FMODEL_STRUCT_ARG;
73487348
if (btf_type_is_signed_int(t))
73497349
flags |= BTF_FMODEL_SIGNED_ARG;
@@ -7384,7 +7384,7 @@ int btf_distill_func_proto(struct bpf_verifier_log *log,
73847384
return -EINVAL;
73857385
}
73867386
ret = __get_type_size(btf, func->type, &t);
7387-
if (ret < 0 || __btf_type_is_struct(t)) {
7387+
if (ret < 0 || btf_type_is_struct(t)) {
73887388
bpf_log(log,
73897389
"The function %s return type %s is unsupported.\n",
73907390
tname, btf_type_str(t));

0 commit comments

Comments
 (0)