Skip to content

Commit ccb4f5d

Browse files
AsphalttAlexei Starovoitov
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]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 2383e45 commit ccb4f5d

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
@@ -1128,7 +1128,7 @@ struct bpf_prog_offload {
11281128
*/
11291129
#define MAX_BPF_FUNC_REG_ARGS 5
11301130

1131-
/* The argument is a structure. */
1131+
/* The argument is a structure or a union. */
11321132
#define BTF_FMODEL_STRUCT_ARG BIT(0)
11331133

11341134
/* The argument is signed. */

kernel/bpf/btf.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6751,7 +6751,7 @@ bool btf_ctx_access(int off, int size, enum bpf_access_type type,
67516751
/* skip modifiers */
67526752
while (btf_type_is_modifier(t))
67536753
t = btf_type_by_id(btf, t->type);
6754-
if (btf_type_is_small_int(t) || btf_is_any_enum(t) || __btf_type_is_struct(t))
6754+
if (btf_type_is_small_int(t) || btf_is_any_enum(t) || btf_type_is_struct(t))
67556755
/* accessing a scalar */
67566756
return true;
67576757
if (!btf_type_is_ptr(t)) {
@@ -7323,7 +7323,7 @@ static int __get_type_size(struct btf *btf, u32 btf_id,
73237323
if (btf_type_is_ptr(t))
73247324
/* kernel size of pointer. Not BPF's size of pointer*/
73257325
return sizeof(void *);
7326-
if (btf_type_is_int(t) || btf_is_any_enum(t) || __btf_type_is_struct(t))
7326+
if (btf_type_is_int(t) || btf_is_any_enum(t) || btf_type_is_struct(t))
73277327
return t->size;
73287328
return -EINVAL;
73297329
}
@@ -7332,7 +7332,7 @@ static u8 __get_type_fmodel_flags(const struct btf_type *t)
73327332
{
73337333
u8 flags = 0;
73347334

7335-
if (__btf_type_is_struct(t))
7335+
if (btf_type_is_struct(t))
73367336
flags |= BTF_FMODEL_STRUCT_ARG;
73377337
if (btf_type_is_signed_int(t))
73387338
flags |= BTF_FMODEL_SIGNED_ARG;
@@ -7373,7 +7373,7 @@ int btf_distill_func_proto(struct bpf_verifier_log *log,
73737373
return -EINVAL;
73747374
}
73757375
ret = __get_type_size(btf, func->type, &t);
7376-
if (ret < 0 || __btf_type_is_struct(t)) {
7376+
if (ret < 0 || btf_type_is_struct(t)) {
73777377
bpf_log(log,
73787378
"The function %s return type %s is unsupported.\n",
73797379
tname, btf_type_str(t));

0 commit comments

Comments
 (0)