diff mbox series

bpf/btf: Fix is_int_ptr()

Message ID 20221012125815.76120-1-zhouchengming@bytedance.com (mailing list archive)
State Changes Requested
Delegated to: BPF
Headers show
Series bpf/btf: Fix is_int_ptr() | expand

Checks

Context Check Description
netdev/tree_selection success Guessed tree name to be net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 4 this patch: 4
netdev/cc_maintainers success CCed 12 of 12 maintainers
netdev/build_clang success Errors and warnings before: 5 this patch: 5
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 4 this patch: 4
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 10 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-next-VM_Test-4 success Logs for llvm-toolchain
bpf/vmtest-bpf-next-VM_Test-5 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-2 success Logs for build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-3 success Logs for build for x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-1 success Logs for build for s390x with gcc
bpf/vmtest-bpf-next-VM_Test-15 success Logs for test_verifier on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-16 success Logs for test_verifier on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-17 success Logs for test_verifier on x86_64 with llvm-16
bpf/vmtest-bpf-next-PR fail PR summary
bpf/vmtest-bpf-next-VM_Test-6 success Logs for test_maps on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-7 success Logs for test_maps on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-8 success Logs for test_maps on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-9 success Logs for test_progs on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-10 fail Logs for test_progs on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-11 fail Logs for test_progs on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-12 success Logs for test_progs_no_alu32 on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-13 fail Logs for test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-14 fail Logs for test_progs_no_alu32 on x86_64 with llvm-16

Commit Message

Chengming Zhou Oct. 12, 2022, 12:58 p.m. UTC
When tracing a kernel function with arg type is u32*, btf_ctx_access()
would report error: arg2 type INT is not a struct.

The commit bb6728d75611 ("bpf: Allow access to int pointer arguments
in tracing programs") added support for int pointer, but don't skip
modifiers before checking it's type. This patch fixes it.

Fixes: bb6728d75611 ("bpf: Allow access to int pointer arguments in tracing programs")
Signed-off-by: Chengming Zhou <zhouchengming@bytedance.com>
---
 kernel/bpf/btf.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Martin KaFai Lau Oct. 13, 2022, 12:50 a.m. UTC | #1
On 10/12/22 5:58 AM, Chengming Zhou wrote:
> When tracing a kernel function with arg type is u32*, btf_ctx_access()
> would report error: arg2 type INT is not a struct.
> 
> The commit bb6728d75611 ("bpf: Allow access to int pointer arguments
> in tracing programs") added support for int pointer, but don't skip
> modifiers before checking it's type. This patch fixes it.

A selftest is needed.  You can refer to the selftest added in the patch set [0] 
of the commit bb6728d75611.

This belongs to bpf-next.  Please tag it as bpf-next and also v2 in the next 
revision:
Documentation/bpf/bpf_devel_QA.rst  (Q: How do I indicate which tree....)

[0]: https://lore.kernel.org/bpf/20211208193245.172141-2-jolsa@kernel.org/

> 
> Fixes: bb6728d75611 ("bpf: Allow access to int pointer arguments in tracing programs")
> Signed-off-by: Chengming Zhou <zhouchengming@bytedance.com>
> ---
>   kernel/bpf/btf.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
> index eba603cec2c5..2b343c42ed10 100644
> --- a/kernel/bpf/btf.c
> +++ b/kernel/bpf/btf.c
> @@ -5316,8 +5316,8 @@ static bool is_int_ptr(struct btf *btf, const struct btf_type *t)
>   	/* t comes in already as a pointer */
>   	t = btf_type_by_id(btf, t->type);
>   
> -	/* allow const */
> -	if (BTF_INFO_KIND(t->info) == BTF_KIND_CONST)
> +	/* skip modifiers */
> +	while (btf_type_is_modifier(t))

There is btf_type_skip_modifiers() that should be useful here.

>   		t = btf_type_by_id(btf, t->type);
>   
>   	return btf_type_is_int(t);
Chengming Zhou Oct. 13, 2022, 2:27 a.m. UTC | #2
On 2022/10/13 08:50, Martin KaFai Lau wrote:
> On 10/12/22 5:58 AM, Chengming Zhou wrote:
>> When tracing a kernel function with arg type is u32*, btf_ctx_access()
>> would report error: arg2 type INT is not a struct.
>>
>> The commit bb6728d75611 ("bpf: Allow access to int pointer arguments
>> in tracing programs") added support for int pointer, but don't skip
>> modifiers before checking it's type. This patch fixes it.
> 
> A selftest is needed.  You can refer to the selftest added in the patch set [0] of the commit bb6728d75611.
> 
> This belongs to bpf-next.  Please tag it as bpf-next and also v2 in the next revision:
> Documentation/bpf/bpf_devel_QA.rst  (Q: How do I indicate which tree....)
> 
> [0]: https://lore.kernel.org/bpf/20211208193245.172141-2-jolsa@kernel.org/

Thanks for these helpful references, will do.

> 
>>
>> Fixes: bb6728d75611 ("bpf: Allow access to int pointer arguments in tracing programs")
>> Signed-off-by: Chengming Zhou <zhouchengming@bytedance.com>
>> ---
>>   kernel/bpf/btf.c | 4 ++--
>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
>> index eba603cec2c5..2b343c42ed10 100644
>> --- a/kernel/bpf/btf.c
>> +++ b/kernel/bpf/btf.c
>> @@ -5316,8 +5316,8 @@ static bool is_int_ptr(struct btf *btf, const struct btf_type *t)
>>       /* t comes in already as a pointer */
>>       t = btf_type_by_id(btf, t->type);
>>   -    /* allow const */
>> -    if (BTF_INFO_KIND(t->info) == BTF_KIND_CONST)
>> +    /* skip modifiers */
>> +    while (btf_type_is_modifier(t))
> 
> There is btf_type_skip_modifiers() that should be useful here.

Ok, will change to use this.

> 
>>           t = btf_type_by_id(btf, t->type);
>>         return btf_type_is_int(t);
>
diff mbox series

Patch

diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
index eba603cec2c5..2b343c42ed10 100644
--- a/kernel/bpf/btf.c
+++ b/kernel/bpf/btf.c
@@ -5316,8 +5316,8 @@  static bool is_int_ptr(struct btf *btf, const struct btf_type *t)
 	/* t comes in already as a pointer */
 	t = btf_type_by_id(btf, t->type);
 
-	/* allow const */
-	if (BTF_INFO_KIND(t->info) == BTF_KIND_CONST)
+	/* skip modifiers */
+	while (btf_type_is_modifier(t))
 		t = btf_type_by_id(btf, t->type);
 
 	return btf_type_is_int(t);