2023-04-17 08:11:09

by Feng Zhou

[permalink] [raw]
Subject: [PATCH 1/2] bpf: support access variable length array of integer type

From: Feng Zhou <[email protected]>

After this commit:
bpf: Support variable length array in tracing programs (9c5f8a1008a1)
Trace programs can access variable length array, but for structure
type. This patch adds support for integer type.

Example:
Hook load_balance
struct sched_domain {
...
unsigned long span[];
}

The access: sd->span[0].

Co-developed-by: Chengming Zhou <[email protected]>
Signed-off-by: Chengming Zhou <[email protected]>
Signed-off-by: Feng Zhou <[email protected]>
---
kernel/bpf/btf.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
index 027f9f8a3551..a0887ee44e89 100644
--- a/kernel/bpf/btf.c
+++ b/kernel/bpf/btf.c
@@ -6157,11 +6157,13 @@ static int btf_struct_walk(struct bpf_verifier_log *log, const struct btf *btf,
if (off < moff)
goto error;

- /* Only allow structure for now, can be relaxed for
- * other types later.
- */
+ /* allow structure and integer */
t = btf_type_skip_modifiers(btf, array_elem->type,
NULL);
+
+ if (btf_type_is_int(t))
+ return WALK_SCALAR;
+
if (!btf_type_is_struct(t))
goto error;

--
2.20.1


2023-04-18 00:25:52

by Alexei Starovoitov

[permalink] [raw]
Subject: Re: [PATCH 1/2] bpf: support access variable length array of integer type

On Mon, Apr 17, 2023 at 04:07:48PM +0800, Feng zhou wrote:
> From: Feng Zhou <[email protected]>
>
> After this commit:
> bpf: Support variable length array in tracing programs (9c5f8a1008a1)
> Trace programs can access variable length array, but for structure
> type. This patch adds support for integer type.
>
> Example:
> Hook load_balance
> struct sched_domain {
> ...
> unsigned long span[];
> }
>
> The access: sd->span[0].

The use case makes sense.
Please add it as a selftest. Either combine it with patch 2 or another patch 3.
and then resubmit.
Make sure to use [PATCH bpf-next] subject, so BPF CI knows how to test it.

2023-04-18 02:57:39

by Feng Zhou

[permalink] [raw]
Subject: Re: Re: [PATCH 1/2] bpf: support access variable length array of integer type

在 2023/4/18 08:08, Alexei Starovoitov 写道:
> On Mon, Apr 17, 2023 at 04:07:48PM +0800, Feng zhou wrote:
>> From: Feng Zhou <[email protected]>
>>
>> After this commit:
>> bpf: Support variable length array in tracing programs (9c5f8a1008a1)
>> Trace programs can access variable length array, but for structure
>> type. This patch adds support for integer type.
>>
>> Example:
>> Hook load_balance
>> struct sched_domain {
>> ...
>> unsigned long span[];
>> }
>>
>> The access: sd->span[0].
> The use case makes sense.
> Please add it as a selftest. Either combine it with patch 2 or another patch 3.
> and then resubmit.
> Make sure to use [PATCH bpf-next] subject, so BPF CI knows how to test it.

Will do, thanks.