All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: Ilya Leoshkevich <iii@linux.ibm.com>,
	Alan Maguire <alan.maguire@oracle.com>
Cc: Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>, bpf <bpf@vger.kernel.org>,
	Heiko Carstens <hca@linux.ibm.com>,
	Vasily Gorbik <gor@linux.ibm.com>
Subject: Re: [PATCH bpf-next 3/3] libbpf: Fix dumping __int128
Date: Tue, 12 Oct 2021 05:52:45 +0200	[thread overview]
Message-ID: <CAEf4BzYzgSZELHujELqggGPyDFPCN4nM6OwGLzyy8O5mJAcXJw@mail.gmail.com> (raw)
In-Reply-To: <20211012023218.399568-4-iii@linux.ibm.com>

On Tue, Oct 12, 2021 at 4:32 AM Ilya Leoshkevich <iii@linux.ibm.com> wrote:
>
> On s390 __int128 can be 8-byte aligned, therefore in libbpf will
> occasionally consider variables of this type non-aligned and try to
> dump them as a bitfield, which is supported for at most 64-bit
> integers.
>
> Fix by using the same trick as btf_dump_float_data(): copy non-aligned
> values to the local buffer.
>
> Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
> ---
>  tools/lib/bpf/btf_dump.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/tools/lib/bpf/btf_dump.c b/tools/lib/bpf/btf_dump.c
> index ab45771d0cb4..d8264c1762e8 100644
> --- a/tools/lib/bpf/btf_dump.c
> +++ b/tools/lib/bpf/btf_dump.c
> @@ -1672,9 +1672,10 @@ static int btf_dump_int_data(struct btf_dump *d,
>  {
>         __u8 encoding = btf_int_encoding(t);
>         bool sign = encoding & BTF_INT_SIGNED;
> +       char buf[16] __aligned(16);
>         int sz = t->size;
>
> -       if (sz == 0) {
> +       if (sz == 0 || sz > sizeof(buf)) {
>                 pr_warn("unexpected size %d for id [%u]\n", sz, type_id);
>                 return -EINVAL;
>         }
> @@ -1682,8 +1683,10 @@ static int btf_dump_int_data(struct btf_dump *d,
>         /* handle packed int data - accesses of integers not aligned on
>          * int boundaries can cause problems on some platforms.
>          */
> -       if (!ptr_is_aligned(data, sz))
> -               return btf_dump_bitfield_data(d, t, data, 0, 0);
> +       if (!ptr_is_aligned(data, sz)) {

I think ptr_is_aligned() logic is wrong. We should probably not assume
that __int128 has 16-byte alignment. Can you try fixing it by using
btf__align_of() API to get the natural alignment?

> +               memcpy(buf, data, sz);
> +               data = buf;
> +       }
>
>         switch (sz) {
>         case 16: {
> --
> 2.31.1
>

  reply	other threads:[~2021-10-12  3:52 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-12  2:32 [PATCH bpf-next 0/3] btf_dump fixes for s390 Ilya Leoshkevich
2021-10-12  2:32 ` [PATCH bpf-next 1/3] selftests/bpf: Use cpu_number only on arches that have it Ilya Leoshkevich
2021-10-12  3:56   ` Andrii Nakryiko
2021-10-12 11:02     ` Ilya Leoshkevich
2021-10-20 18:32       ` Andrii Nakryiko
2021-10-12  2:32 ` [PATCH bpf-next 2/3] libbpf: Fix dumping big-endian bitfields Ilya Leoshkevich
2021-10-12  4:03   ` Andrii Nakryiko
2021-10-12 11:43     ` Ilya Leoshkevich
2021-10-12  2:32 ` [PATCH bpf-next 3/3] libbpf: Fix dumping __int128 Ilya Leoshkevich
2021-10-12  3:52   ` Andrii Nakryiko [this message]
2021-10-12 11:44     ` Ilya Leoshkevich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAEf4BzYzgSZELHujELqggGPyDFPCN4nM6OwGLzyy8O5mJAcXJw@mail.gmail.com \
    --to=andrii.nakryiko@gmail.com \
    --cc=alan.maguire@oracle.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=iii@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.