bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH] libbpf: extending BTF_KIND_INIT to accommodate some unusual types
@ 2024-04-23 13:15 Xin Liu
  2024-04-23 14:30 ` Alan Maguire
  2024-04-23 20:12 ` Yonghong Song
  0 siblings, 2 replies; 8+ messages in thread
From: Xin Liu @ 2024-04-23 13:15 UTC (permalink / raw)
  To: ast, daniel, andrii, martin.lau, song, yhs, john.fastabend,
	kpsingh, sdf, haoluo, jolsa
  Cc: bpf, linux-kernel, yanan, wuchangye, xiesongyang, kongweibin2,
	zhangmingyi5, liwei883, liuxin350

On Mon, 22 Apr 2024 10:43:38 -0700 Andrii Nakryiko <andrii.nakryiko@gmail.com> wrote:

> On Mon, Apr 22, 2024 at 7:46 AM Xin Liu <liuxin350@huawei.com> wrote:
> >
> > In btf__add_int, the size of the new btf_kind_int type is limited.
> > When the size is greater than 16, btf__add_int fails to be added
> > and -EINVAL is returned. This is usually effective.
> >
> > However, when the built-in type __builtin_aarch64_simd_xi in the
> > NEON instruction is used in the code in the arm64 system, the value
> > of DW_AT_byte_size is 64. This causes btf__add_int to fail to
> > properly add btf information to it.
> >
> > like this:
> >   ...
> >    <1><cf>: Abbrev Number: 2 (DW_TAG_base_type)
> >     <d0>   DW_AT_byte_size   : 64              // over max size 16
> >     <d1>   DW_AT_encoding    : 5        (signed)
> >     <d2>   DW_AT_name        : (indirect string, offset: 0x53): __builtin_aarch64_simd_xi
> >    <1><d6>: Abbrev Number: 0
> >   ...
> >
> > An easier way to solve this problem is to treat it as a base type
> > and set byte_size to 64. This patch is modified along these lines.
> >
> > Fixes: 4a3b33f8579a ("libbpf: Add BTF writing APIs")
> > Signed-off-by: Xin Liu <liuxin350@huawei.com>
> > ---
> >  tools/lib/bpf/btf.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
> > index 2d0840ef599a..0af121293b65 100644
> > --- a/tools/lib/bpf/btf.c
> > +++ b/tools/lib/bpf/btf.c
> > @@ -1934,7 +1934,7 @@ int btf__add_int(struct btf *btf, const char *name, size_t byte_sz, int encoding
> >         if (!name || !name[0])
> >                 return libbpf_err(-EINVAL);
> >         /* byte_sz must be power of 2 */
> > -       if (!byte_sz || (byte_sz & (byte_sz - 1)) || byte_sz > 16)
> > +       if (!byte_sz || (byte_sz & (byte_sz - 1)) || byte_sz > 64)
> 
> 
> maybe we should just remove byte_sz upper limit? We can probably
> imagine 256-byte integers at some point, so why bother artificially
> restricting it?
> 
> pw-bot: cr

In the current definition of btf_kind_int, bits has only 8 bits, followed
by 8 bits of unused interval. When we expand, we should only use 16 bits
at most, so the maximum value should be 8192(1 << 16 / 8), directly removing
the limit of byte_sz. It may not fit the current design. For INT type btfs
greater than 255, how to dump is still a challenge.

Does the current version support a maximum of 8192 bytes?

> 
> >                 return libbpf_err(-EINVAL);
> >         if (encoding & ~(BTF_INT_SIGNED | BTF_INT_CHAR | BTF_INT_BOOL))
> >                 return libbpf_err(-EINVAL);
> > --
> > 2.33.0
> >
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] libbpf: extending BTF_KIND_INIT to accommodate some unusual types
  2024-04-23 13:15 [PATCH] libbpf: extending BTF_KIND_INIT to accommodate some unusual types Xin Liu
@ 2024-04-23 14:30 ` Alan Maguire
  2024-04-24  6:52   ` Xin Liu
  2024-04-23 20:12 ` Yonghong Song
  1 sibling, 1 reply; 8+ messages in thread
From: Alan Maguire @ 2024-04-23 14:30 UTC (permalink / raw)
  To: Xin Liu, ast, daniel, andrii, martin.lau, song, yhs,
	john.fastabend, kpsingh, sdf, haoluo, jolsa
  Cc: bpf, linux-kernel, yanan, wuchangye, xiesongyang, kongweibin2,
	zhangmingyi5, liwei883

On 23/04/2024 14:15, Xin Liu wrote:
> On Mon, 22 Apr 2024 10:43:38 -0700 Andrii Nakryiko <andrii.nakryiko@gmail.com> wrote:
> 
>> On Mon, Apr 22, 2024 at 7:46 AM Xin Liu <liuxin350@huawei.com> wrote:
>>>
>>> In btf__add_int, the size of the new btf_kind_int type is limited.
>>> When the size is greater than 16, btf__add_int fails to be added
>>> and -EINVAL is returned. This is usually effective.
>>>
>>> However, when the built-in type __builtin_aarch64_simd_xi in the
>>> NEON instruction is used in the code in the arm64 system, the value
>>> of DW_AT_byte_size is 64. This causes btf__add_int to fail to
>>> properly add btf information to it.
>>>
>>> like this:
>>>   ...
>>>    <1><cf>: Abbrev Number: 2 (DW_TAG_base_type)
>>>     <d0>   DW_AT_byte_size   : 64              // over max size 16
>>>     <d1>   DW_AT_encoding    : 5        (signed)
>>>     <d2>   DW_AT_name        : (indirect string, offset: 0x53): __builtin_aarch64_simd_xi
>>>    <1><d6>: Abbrev Number: 0
>>>   ...
>>>
>>> An easier way to solve this problem is to treat it as a base type
>>> and set byte_size to 64. This patch is modified along these lines.
>>>
>>> Fixes: 4a3b33f8579a ("libbpf: Add BTF writing APIs")
>>> Signed-off-by: Xin Liu <liuxin350@huawei.com>
>>> ---
>>>  tools/lib/bpf/btf.c | 2 +-
>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
>>> index 2d0840ef599a..0af121293b65 100644
>>> --- a/tools/lib/bpf/btf.c
>>> +++ b/tools/lib/bpf/btf.c
>>> @@ -1934,7 +1934,7 @@ int btf__add_int(struct btf *btf, const char *name, size_t byte_sz, int encoding
>>>         if (!name || !name[0])
>>>                 return libbpf_err(-EINVAL);
>>>         /* byte_sz must be power of 2 */
>>> -       if (!byte_sz || (byte_sz & (byte_sz - 1)) || byte_sz > 16)
>>> +       if (!byte_sz || (byte_sz & (byte_sz - 1)) || byte_sz > 64)
>>
>>
>> maybe we should just remove byte_sz upper limit? We can probably
>> imagine 256-byte integers at some point, so why bother artificially
>> restricting it?
>>
>> pw-bot: cr
> 
> In the current definition of btf_kind_int, bits has only 8 bits, followed
> by 8 bits of unused interval. When we expand, we should only use 16 bits
> at most, so the maximum value should be 8192(1 << 16 / 8), directly removing
> the limit of byte_sz. It may not fit the current design. For INT type btfs
> greater than 255, how to dump is still a challenge.
> 
> Does the current version support a maximum of 8192 bytes?
> 

Presuming we expanded BTF_INT_BITS() as per

-#define BTF_INT_BITS(VAL)       ((VAL)  & 0x000000ff)
+#define BTF_INT_BITS(VAL)       ((VAL)  & 0x0000ffff)

...as you say we'd be able to represent a 65535-bit value. So if we
preserve the power-of-two restriction on byte sizes, we'd have to choose
between either having ints which

- have a byte_sz maximum of <= 4096 bytes, with all 32768 bits usable; or
- have a byte_sz maximum of <= 8192 bytes, with 65535 out of 65536 bits
usable

The first option seems more intuitive to me.

In terms of dumping, we could probably just dump a hex representation of
the relevant bytes.

>>
>>>                 return libbpf_err(-EINVAL);
>>>         if (encoding & ~(BTF_INT_SIGNED | BTF_INT_CHAR | BTF_INT_BOOL))
>>>                 return libbpf_err(-EINVAL);
>>> --
>>> 2.33.0
>>>
>>
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] libbpf: extending BTF_KIND_INIT to accommodate some unusual types
  2024-04-23 13:15 [PATCH] libbpf: extending BTF_KIND_INIT to accommodate some unusual types Xin Liu
  2024-04-23 14:30 ` Alan Maguire
@ 2024-04-23 20:12 ` Yonghong Song
  2024-04-24  7:06   ` Xin Liu
  1 sibling, 1 reply; 8+ messages in thread
From: Yonghong Song @ 2024-04-23 20:12 UTC (permalink / raw)
  To: Xin Liu, ast, daniel, andrii, martin.lau, song, yhs,
	john.fastabend, kpsingh, sdf, haoluo, jolsa
  Cc: bpf, linux-kernel, yanan, wuchangye, xiesongyang, kongweibin2,
	zhangmingyi5, liwei883


On 4/23/24 6:15 AM, Xin Liu wrote:
> On Mon, 22 Apr 2024 10:43:38 -0700 Andrii Nakryiko <andrii.nakryiko@gmail.com> wrote:
>
>> On Mon, Apr 22, 2024 at 7:46 AM Xin Liu <liuxin350@huawei.com> wrote:
>>> In btf__add_int, the size of the new btf_kind_int type is limited.
>>> When the size is greater than 16, btf__add_int fails to be added
>>> and -EINVAL is returned. This is usually effective.
>>>
>>> However, when the built-in type __builtin_aarch64_simd_xi in the
>>> NEON instruction is used in the code in the arm64 system, the value
>>> of DW_AT_byte_size is 64. This causes btf__add_int to fail to
>>> properly add btf information to it.
>>>
>>> like this:
>>>    ...
>>>     <1><cf>: Abbrev Number: 2 (DW_TAG_base_type)
>>>      <d0>   DW_AT_byte_size   : 64              // over max size 16
>>>      <d1>   DW_AT_encoding    : 5        (signed)
>>>      <d2>   DW_AT_name        : (indirect string, offset: 0x53): __builtin_aarch64_simd_xi
>>>     <1><d6>: Abbrev Number: 0
>>>    ...
>>>
>>> An easier way to solve this problem is to treat it as a base type
>>> and set byte_size to 64. This patch is modified along these lines.
>>>
>>> Fixes: 4a3b33f8579a ("libbpf: Add BTF writing APIs")
>>> Signed-off-by: Xin Liu <liuxin350@huawei.com>
>>> ---
>>>   tools/lib/bpf/btf.c | 2 +-
>>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
>>> index 2d0840ef599a..0af121293b65 100644
>>> --- a/tools/lib/bpf/btf.c
>>> +++ b/tools/lib/bpf/btf.c
>>> @@ -1934,7 +1934,7 @@ int btf__add_int(struct btf *btf, const char *name, size_t byte_sz, int encoding
>>>          if (!name || !name[0])
>>>                  return libbpf_err(-EINVAL);
>>>          /* byte_sz must be power of 2 */
>>> -       if (!byte_sz || (byte_sz & (byte_sz - 1)) || byte_sz > 16)
>>> +       if (!byte_sz || (byte_sz & (byte_sz - 1)) || byte_sz > 64)
>>
>> maybe we should just remove byte_sz upper limit? We can probably
>> imagine 256-byte integers at some point, so why bother artificially
>> restricting it?
>>
>> pw-bot: cr
> In the current definition of btf_kind_int, bits has only 8 bits, followed
> by 8 bits of unused interval. When we expand, we should only use 16 bits
> at most, so the maximum value should be 8192(1 << 16 / 8), directly removing
> the limit of byte_sz. It may not fit the current design. For INT type btfs
> greater than 255, how to dump is still a challenge.

Looking at this patch. Now I remember that I have an old pahole patch
to address similar issues
   https://lore.kernel.org/bpf/20230426055030.3743074-1-yhs@fb.com/
which is not merged and I forgot that.

In that particular case, the int size is 1024 bytes.
Currently the int type more than 16 bytes cannot be dumped in libbpf.
Do you have a particular use case to use your__builtin_aarch64_simd_xi() type
in bpf program? I guess probably not as BPF does not support
builtin function your__builtin_aarch64_simd_xi().

>
> Does the current version support a maximum of 8192 bytes?
>
>>>                  return libbpf_err(-EINVAL);
>>>          if (encoding & ~(BTF_INT_SIGNED | BTF_INT_CHAR | BTF_INT_BOOL))
>>>                  return libbpf_err(-EINVAL);
>>> --
>>> 2.33.0
>>>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] libbpf: extending BTF_KIND_INIT to accommodate some unusual types
  2024-04-23 14:30 ` Alan Maguire
@ 2024-04-24  6:52   ` Xin Liu
  0 siblings, 0 replies; 8+ messages in thread
From: Xin Liu @ 2024-04-24  6:52 UTC (permalink / raw)
  To: alan.maguire
  Cc: andrii, ast, bpf, daniel, haoluo, john.fastabend, jolsa,
	kongweibin2, kpsingh, linux-kernel, liuxin350, liwei883,
	martin.lau, sdf, song, wuchangye, xiesongyang, yanan, yhs,
	zhangmingyi5

On Tue, 23 Apr 2024 15:30:03 +0100 Alan Maguire <alan.maguire@oracle.com> wrote:
> On 23/04/2024 14:15, Xin Liu wrote:
> > On Mon, 22 Apr 2024 10:43:38 -0700 Andrii Nakryiko <andrii.nakryiko@gmail.com> wrote:
> > 
> >> On Mon, Apr 22, 2024 at 7:46 AM Xin Liu <liuxin350@huawei.com> wrote:
> >>>
> >>> In btf__add_int, the size of the new btf_kind_int type is limited.
> >>> When the size is greater than 16, btf__add_int fails to be added
> >>> and -EINVAL is returned. This is usually effective.
> >>>
> >>> However, when the built-in type __builtin_aarch64_simd_xi in the
> >>> NEON instruction is used in the code in the arm64 system, the value
> >>> of DW_AT_byte_size is 64. This causes btf__add_int to fail to
> >>> properly add btf information to it.
> >>>
> >>> like this:
> >>>   ...
> >>>    <1><cf>: Abbrev Number: 2 (DW_TAG_base_type)
> >>>     <d0>   DW_AT_byte_size   : 64              // over max size 16
> >>>     <d1>   DW_AT_encoding    : 5        (signed)
> >>>     <d2>   DW_AT_name        : (indirect string, offset: 0x53): __builtin_aarch64_simd_xi
> >>>    <1><d6>: Abbrev Number: 0
> >>>   ...
> >>>
> >>> An easier way to solve this problem is to treat it as a base type
> >>> and set byte_size to 64. This patch is modified along these lines.
> >>>
> >>> Fixes: 4a3b33f8579a ("libbpf: Add BTF writing APIs")
> >>> Signed-off-by: Xin Liu <liuxin350@huawei.com>
> >>> ---
> >>>  tools/lib/bpf/btf.c | 2 +-
> >>>  1 file changed, 1 insertion(+), 1 deletion(-)
> >>>
> >>> diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
> >>> index 2d0840ef599a..0af121293b65 100644
> >>> --- a/tools/lib/bpf/btf.c
> >>> +++ b/tools/lib/bpf/btf.c
> >>> @@ -1934,7 +1934,7 @@ int btf__add_int(struct btf *btf, const char *name, size_t byte_sz, int encoding
> >>>         if (!name || !name[0])
> >>>                 return libbpf_err(-EINVAL);
> >>>         /* byte_sz must be power of 2 */
> >>> -       if (!byte_sz || (byte_sz & (byte_sz - 1)) || byte_sz > 16)
> >>> +       if (!byte_sz || (byte_sz & (byte_sz - 1)) || byte_sz > 64)
> >>
> >>
> >> maybe we should just remove byte_sz upper limit? We can probably
> >> imagine 256-byte integers at some point, so why bother artificially
> >> restricting it?
> >>
> >> pw-bot: cr
> > 
> > In the current definition of btf_kind_int, bits has only 8 bits, followed
> > by 8 bits of unused interval. When we expand, we should only use 16 bits
> > at most, so the maximum value should be 8192(1 << 16 / 8), directly removing
> > the limit of byte_sz. It may not fit the current design. For INT type btfs
> > greater than 255, how to dump is still a challenge.
> > 
> > Does the current version support a maximum of 8192 bytes?
> > 
> 
> Presuming we expanded BTF_INT_BITS() as per
> 
> -#define BTF_INT_BITS(VAL)       ((VAL)  & 0x000000ff)
> +#define BTF_INT_BITS(VAL)       ((VAL)  & 0x0000ffff)
> 
> ...as you say we'd be able to represent a 65535-bit value. So if we
> preserve the power-of-two restriction on byte sizes, we'd have to choose
> between either having ints which
> 
> - have a byte_sz maximum of <= 4096 bytes, with all 32768 bits usable; or
> - have a byte_sz maximum of <= 8192 bytes, with 65535 out of 65536 bits
> usable
> 
> The first option seems more intuitive to me.
> 
> In terms of dumping, we could probably just dump a hex representation of
> the relevant bytes.
> 

Currently, there is actually no scenario to use built-in structs in btf. 
As Song and Andrii said, can we remove this restriction first?

> >>
> >>>                 return libbpf_err(-EINVAL);
> >>>         if (encoding & ~(BTF_INT_SIGNED | BTF_INT_CHAR | BTF_INT_BOOL))
> >>>                 return libbpf_err(-EINVAL);
> >>> --
> >>> 2.33.0
> >>>
> >>
> > 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] libbpf: extending BTF_KIND_INIT to accommodate some unusual types
  2024-04-23 20:12 ` Yonghong Song
@ 2024-04-24  7:06   ` Xin Liu
  2024-04-24 22:11     ` Yonghong Song
  0 siblings, 1 reply; 8+ messages in thread
From: Xin Liu @ 2024-04-24  7:06 UTC (permalink / raw)
  To: yonghong.song
  Cc: andrii, ast, bpf, daniel, haoluo, john.fastabend, jolsa,
	kongweibin2, kpsingh, linux-kernel, liuxin350, liwei883,
	martin.lau, sdf, song, wuchangye, xiesongyang, yanan, yhs,
	zhangmingyi5

On Tue, 23 Apr 2024 13:12:04 -0700 Yonghong Song <yonghong.song@linux.dev> wrote:
> On 4/23/24 6:15 AM, Xin Liu wrote:
> > On Mon, 22 Apr 2024 10:43:38 -0700 Andrii Nakryiko <andrii.nakryiko@gmail.com> wrote:
> >
> >> On Mon, Apr 22, 2024 at 7:46 AM Xin Liu <liuxin350@huawei.com> wrote:
> >>> In btf__add_int, the size of the new btf_kind_int type is limited.
> >>> When the size is greater than 16, btf__add_int fails to be added
> >>> and -EINVAL is returned. This is usually effective.
> >>>
> >>> However, when the built-in type __builtin_aarch64_simd_xi in the
> >>> NEON instruction is used in the code in the arm64 system, the value
> >>> of DW_AT_byte_size is 64. This causes btf__add_int to fail to
> >>> properly add btf information to it.
> >>>
> >>> like this:
> >>>    ...
> >>>     <1><cf>: Abbrev Number: 2 (DW_TAG_base_type)
> >>>      <d0>   DW_AT_byte_size   : 64              // over max size 16
> >>>      <d1>   DW_AT_encoding    : 5        (signed)
> >>>      <d2>   DW_AT_name        : (indirect string, offset: 0x53): __builtin_aarch64_simd_xi
> >>>     <1><d6>: Abbrev Number: 0
> >>>    ...
> >>>
> >>> An easier way to solve this problem is to treat it as a base type
> >>> and set byte_size to 64. This patch is modified along these lines.
> >>>
> >>> Fixes: 4a3b33f8579a ("libbpf: Add BTF writing APIs")
> >>> Signed-off-by: Xin Liu <liuxin350@huawei.com>
> >>> ---
> >>>   tools/lib/bpf/btf.c | 2 +-
> >>>   1 file changed, 1 insertion(+), 1 deletion(-)
> >>>
> >>> diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
> >>> index 2d0840ef599a..0af121293b65 100644
> >>> --- a/tools/lib/bpf/btf.c
> >>> +++ b/tools/lib/bpf/btf.c
> >>> @@ -1934,7 +1934,7 @@ int btf__add_int(struct btf *btf, const char *name, size_t byte_sz, int encoding
> >>>          if (!name || !name[0])
> >>>                  return libbpf_err(-EINVAL);
> >>>          /* byte_sz must be power of 2 */
> >>> -       if (!byte_sz || (byte_sz & (byte_sz - 1)) || byte_sz > 16)
> >>> +       if (!byte_sz || (byte_sz & (byte_sz - 1)) || byte_sz > 64)
> >>
> >> maybe we should just remove byte_sz upper limit? We can probably
> >> imagine 256-byte integers at some point, so why bother artificially
> >> restricting it?
> >>
> >> pw-bot: cr
> > In the current definition of btf_kind_int, bits has only 8 bits, followed
> > by 8 bits of unused interval. When we expand, we should only use 16 bits
> > at most, so the maximum value should be 8192(1 << 16 / 8), directly removing
> > the limit of byte_sz. It may not fit the current design. For INT type btfs
> > greater than 255, how to dump is still a challenge.
> 
> Looking at this patch. Now I remember that I have an old pahole patch
> to address similar issues
>    https://lore.kernel.org/bpf/20230426055030.3743074-1-yhs@fb.com/
> which is not merged and I forgot that.
> 
> In that particular case, the int size is 1024 bytes.
> Currently the int type more than 16 bytes cannot be dumped in libbpf.
> Do you have a particular use case to use your__builtin_aarch64_simd_xi() type
> in bpf program? I guess probably not as BPF does not support
> builtin function your__builtin_aarch64_simd_xi().
> 

Currently, there is no use case of byte_sz in btf, so let's remove
__builtin_aarch64_simd_xi first.At least this will support the kernel
compilation phase without causing the kernel to fail directly when
generating btf.

> >
> > Does the current version support a maximum of 8192 bytes?
> >
> >>>                  return libbpf_err(-EINVAL);
> >>>          if (encoding & ~(BTF_INT_SIGNED | BTF_INT_CHAR | BTF_INT_BOOL))
> >>>                  return libbpf_err(-EINVAL);
> >>> --
> >>> 2.33.0
> >>>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] libbpf: extending BTF_KIND_INIT to accommodate some unusual types
  2024-04-24  7:06   ` Xin Liu
@ 2024-04-24 22:11     ` Yonghong Song
  0 siblings, 0 replies; 8+ messages in thread
From: Yonghong Song @ 2024-04-24 22:11 UTC (permalink / raw)
  To: Xin Liu
  Cc: andrii, ast, bpf, daniel, haoluo, john.fastabend, jolsa,
	kongweibin2, kpsingh, linux-kernel, liwei883, martin.lau, sdf,
	song, wuchangye, xiesongyang, yanan, yhs, zhangmingyi5


On 4/24/24 12:06 AM, Xin Liu wrote:
> On Tue, 23 Apr 2024 13:12:04 -0700 Yonghong Song <yonghong.song@linux.dev> wrote:
>> On 4/23/24 6:15 AM, Xin Liu wrote:
>>> On Mon, 22 Apr 2024 10:43:38 -0700 Andrii Nakryiko <andrii.nakryiko@gmail.com> wrote:
>>>
>>>> On Mon, Apr 22, 2024 at 7:46 AM Xin Liu <liuxin350@huawei.com> wrote:
>>>>> In btf__add_int, the size of the new btf_kind_int type is limited.
>>>>> When the size is greater than 16, btf__add_int fails to be added
>>>>> and -EINVAL is returned. This is usually effective.
>>>>>
>>>>> However, when the built-in type __builtin_aarch64_simd_xi in the
>>>>> NEON instruction is used in the code in the arm64 system, the value
>>>>> of DW_AT_byte_size is 64. This causes btf__add_int to fail to
>>>>> properly add btf information to it.
>>>>>
>>>>> like this:
>>>>>     ...
>>>>>      <1><cf>: Abbrev Number: 2 (DW_TAG_base_type)
>>>>>       <d0>   DW_AT_byte_size   : 64              // over max size 16
>>>>>       <d1>   DW_AT_encoding    : 5        (signed)
>>>>>       <d2>   DW_AT_name        : (indirect string, offset: 0x53): __builtin_aarch64_simd_xi
>>>>>      <1><d6>: Abbrev Number: 0
>>>>>     ...
>>>>>
>>>>> An easier way to solve this problem is to treat it as a base type
>>>>> and set byte_size to 64. This patch is modified along these lines.
>>>>>
>>>>> Fixes: 4a3b33f8579a ("libbpf: Add BTF writing APIs")
>>>>> Signed-off-by: Xin Liu <liuxin350@huawei.com>
>>>>> ---
>>>>>    tools/lib/bpf/btf.c | 2 +-
>>>>>    1 file changed, 1 insertion(+), 1 deletion(-)
>>>>>
>>>>> diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
>>>>> index 2d0840ef599a..0af121293b65 100644
>>>>> --- a/tools/lib/bpf/btf.c
>>>>> +++ b/tools/lib/bpf/btf.c
>>>>> @@ -1934,7 +1934,7 @@ int btf__add_int(struct btf *btf, const char *name, size_t byte_sz, int encoding
>>>>>           if (!name || !name[0])
>>>>>                   return libbpf_err(-EINVAL);
>>>>>           /* byte_sz must be power of 2 */
>>>>> -       if (!byte_sz || (byte_sz & (byte_sz - 1)) || byte_sz > 16)
>>>>> +       if (!byte_sz || (byte_sz & (byte_sz - 1)) || byte_sz > 64)
>>>> maybe we should just remove byte_sz upper limit? We can probably
>>>> imagine 256-byte integers at some point, so why bother artificially
>>>> restricting it?
>>>>
>>>> pw-bot: cr
>>> In the current definition of btf_kind_int, bits has only 8 bits, followed
>>> by 8 bits of unused interval. When we expand, we should only use 16 bits
>>> at most, so the maximum value should be 8192(1 << 16 / 8), directly removing
>>> the limit of byte_sz. It may not fit the current design. For INT type btfs
>>> greater than 255, how to dump is still a challenge.
>> Looking at this patch. Now I remember that I have an old pahole patch
>> to address similar issues
>>     https://lore.kernel.org/bpf/20230426055030.3743074-1-yhs@fb.com/
>> which is not merged and I forgot that.
>>
>> In that particular case, the int size is 1024 bytes.
>> Currently the int type more than 16 bytes cannot be dumped in libbpf.
>> Do you have a particular use case to use your__builtin_aarch64_simd_xi() type
>> in bpf program? I guess probably not as BPF does not support
>> builtin function your__builtin_aarch64_simd_xi().
>>
> Currently, there is no use case of byte_sz in btf, so let's remove
> __builtin_aarch64_simd_xi first.At least this will support the kernel
> compilation phase without causing the kernel to fail directly when
> generating btf.

Okay, I will resend my pahole patch later to address this issue.

>
>>> Does the current version support a maximum of 8192 bytes?
>>>
>>>>>                   return libbpf_err(-EINVAL);
>>>>>           if (encoding & ~(BTF_INT_SIGNED | BTF_INT_CHAR | BTF_INT_BOOL))
>>>>>                   return libbpf_err(-EINVAL);
>>>>> --
>>>>> 2.33.0
>>>>>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] libbpf: extending BTF_KIND_INIT to accommodate some unusual types
  2024-04-22 14:45 Xin Liu
@ 2024-04-22 17:43 ` Andrii Nakryiko
  0 siblings, 0 replies; 8+ messages in thread
From: Andrii Nakryiko @ 2024-04-22 17:43 UTC (permalink / raw)
  To: Xin Liu
  Cc: ast, daniel, andrii, martin.lau, song, yhs, john.fastabend,
	kpsingh, sdf, haoluo, jolsa, bpf, linux-kernel, yanan, wuchangye,
	xiesongyang, kongweibin2, zhangmingyi5, liwei883

On Mon, Apr 22, 2024 at 7:46 AM Xin Liu <liuxin350@huawei.com> wrote:
>
> In btf__add_int, the size of the new btf_kind_int type is limited.
> When the size is greater than 16, btf__add_int fails to be added
> and -EINVAL is returned. This is usually effective.
>
> However, when the built-in type __builtin_aarch64_simd_xi in the
> NEON instruction is used in the code in the arm64 system, the value
> of DW_AT_byte_size is 64. This causes btf__add_int to fail to
> properly add btf information to it.
>
> like this:
>   ...
>    <1><cf>: Abbrev Number: 2 (DW_TAG_base_type)
>     <d0>   DW_AT_byte_size   : 64              // over max size 16
>     <d1>   DW_AT_encoding    : 5        (signed)
>     <d2>   DW_AT_name        : (indirect string, offset: 0x53): __builtin_aarch64_simd_xi
>    <1><d6>: Abbrev Number: 0
>   ...
>
> An easier way to solve this problem is to treat it as a base type
> and set byte_size to 64. This patch is modified along these lines.
>
> Fixes: 4a3b33f8579a ("libbpf: Add BTF writing APIs")
> Signed-off-by: Xin Liu <liuxin350@huawei.com>
> ---
>  tools/lib/bpf/btf.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
> index 2d0840ef599a..0af121293b65 100644
> --- a/tools/lib/bpf/btf.c
> +++ b/tools/lib/bpf/btf.c
> @@ -1934,7 +1934,7 @@ int btf__add_int(struct btf *btf, const char *name, size_t byte_sz, int encoding
>         if (!name || !name[0])
>                 return libbpf_err(-EINVAL);
>         /* byte_sz must be power of 2 */
> -       if (!byte_sz || (byte_sz & (byte_sz - 1)) || byte_sz > 16)
> +       if (!byte_sz || (byte_sz & (byte_sz - 1)) || byte_sz > 64)


maybe we should just remove byte_sz upper limit? We can probably
imagine 256-byte integers at some point, so why bother artificially
restricting it?

pw-bot: cr

>                 return libbpf_err(-EINVAL);
>         if (encoding & ~(BTF_INT_SIGNED | BTF_INT_CHAR | BTF_INT_BOOL))
>                 return libbpf_err(-EINVAL);
> --
> 2.33.0
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH] libbpf: extending BTF_KIND_INIT to accommodate some unusual types
@ 2024-04-22 14:45 Xin Liu
  2024-04-22 17:43 ` Andrii Nakryiko
  0 siblings, 1 reply; 8+ messages in thread
From: Xin Liu @ 2024-04-22 14:45 UTC (permalink / raw)
  To: ast, daniel, andrii, martin.lau, song, yhs, john.fastabend,
	kpsingh, sdf, haoluo, jolsa
  Cc: bpf, linux-kernel, yanan, wuchangye, xiesongyang, kongweibin2,
	zhangmingyi5, liwei883, liuxin350

In btf__add_int, the size of the new btf_kind_int type is limited.
When the size is greater than 16, btf__add_int fails to be added
and -EINVAL is returned. This is usually effective.

However, when the built-in type __builtin_aarch64_simd_xi in the
NEON instruction is used in the code in the arm64 system, the value
of DW_AT_byte_size is 64. This causes btf__add_int to fail to
properly add btf information to it.

like this:
  ...
   <1><cf>: Abbrev Number: 2 (DW_TAG_base_type)
    <d0>   DW_AT_byte_size   : 64              // over max size 16
    <d1>   DW_AT_encoding    : 5        (signed)
    <d2>   DW_AT_name        : (indirect string, offset: 0x53): __builtin_aarch64_simd_xi
   <1><d6>: Abbrev Number: 0
  ...

An easier way to solve this problem is to treat it as a base type
and set byte_size to 64. This patch is modified along these lines.

Fixes: 4a3b33f8579a ("libbpf: Add BTF writing APIs")
Signed-off-by: Xin Liu <liuxin350@huawei.com>
---
 tools/lib/bpf/btf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
index 2d0840ef599a..0af121293b65 100644
--- a/tools/lib/bpf/btf.c
+++ b/tools/lib/bpf/btf.c
@@ -1934,7 +1934,7 @@ int btf__add_int(struct btf *btf, const char *name, size_t byte_sz, int encoding
 	if (!name || !name[0])
 		return libbpf_err(-EINVAL);
 	/* byte_sz must be power of 2 */
-	if (!byte_sz || (byte_sz & (byte_sz - 1)) || byte_sz > 16)
+	if (!byte_sz || (byte_sz & (byte_sz - 1)) || byte_sz > 64)
 		return libbpf_err(-EINVAL);
 	if (encoding & ~(BTF_INT_SIGNED | BTF_INT_CHAR | BTF_INT_BOOL))
 		return libbpf_err(-EINVAL);
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-04-24 22:11 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-23 13:15 [PATCH] libbpf: extending BTF_KIND_INIT to accommodate some unusual types Xin Liu
2024-04-23 14:30 ` Alan Maguire
2024-04-24  6:52   ` Xin Liu
2024-04-23 20:12 ` Yonghong Song
2024-04-24  7:06   ` Xin Liu
2024-04-24 22:11     ` Yonghong Song
  -- strict thread matches above, loose matches on Subject: below --
2024-04-22 14:45 Xin Liu
2024-04-22 17:43 ` Andrii Nakryiko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).