All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ilya Leoshkevich <iii@linux.ibm.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.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 2/3] libbpf: Fix dumping big-endian bitfields
Date: Tue, 12 Oct 2021 13:43:20 +0200	[thread overview]
Message-ID: <b4e2bd3d417a808cb747c09bf6cfa6f74404f1c0.camel@linux.ibm.com> (raw)
In-Reply-To: <CAEf4BzZeUQf4DzCNgkpR7yqsb41=Vvu8EPfdTQBwaBk95Dxi-w@mail.gmail.com>

On Tue, 2021-10-12 at 06:03 +0200, Andrii Nakryiko wrote:
> On Tue, Oct 12, 2021 at 4:32 AM Ilya Leoshkevich <iii@linux.ibm.com>
> wrote:
> > 
> > On big-endian arches not only bytes, but also bits are numbered in
> > reverse order (see e.g. S/390 ELF ABI Supplement, but this is also
> > true
> > for other big-endian arches as well).
> > 
> > Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
> > ---
> >  tools/lib/bpf/btf_dump.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> > 
> > diff --git a/tools/lib/bpf/btf_dump.c b/tools/lib/bpf/btf_dump.c
> > index ad6df97295ae..ab45771d0cb4 100644
> > --- a/tools/lib/bpf/btf_dump.c
> > +++ b/tools/lib/bpf/btf_dump.c
> > @@ -1577,14 +1577,15 @@ static int
> > btf_dump_get_bitfield_value(struct btf_dump *d,
> >         /* Bitfield value retrieval is done in two steps; first
> > relevant bytes are
> >          * stored in num, then we left/right shift num to eliminate
> > irrelevant bits.
> >          */
> > -       nr_copy_bits = bit_sz + bits_offset;
> >         nr_copy_bytes = t->size;
> >  #if __BYTE_ORDER == __LITTLE_ENDIAN
> >         for (i = nr_copy_bytes - 1; i >= 0; i--)
> >                 num = num * 256 + bytes[i];
> > +       nr_copy_bits = bit_sz + bits_offset;
> >  #elif __BYTE_ORDER == __BIG_ENDIAN
> >         for (i = 0; i < nr_copy_bytes; i++)
> >                 num = num * 256 + bytes[i];
> > +       nr_copy_bits = nr_copy_bytes * 8 - bits_offset;
> 
> oh, I remember dealing with this in the context of pahole. Just one
> nit, please use t->size instead of nr_copy_bytes, I think it will
> make
> it a bit more explicit (nr_copy_bytes is logically mutable, though
> only in little-endian case, but still).

Both sz and num_copy_bytes look redundant to be honest. What do you
think about dropping both completely and just using t->size everywhere
instead?

> 
> >  #else
> >  # error "Unrecognized __BYTE_ORDER__"
> >  #endif
> > --
> > 2.31.1
> > 



  reply	other threads:[~2021-10-12 11:43 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 [this message]
2021-10-12  2:32 ` [PATCH bpf-next 3/3] libbpf: Fix dumping __int128 Ilya Leoshkevich
2021-10-12  3:52   ` Andrii Nakryiko
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=b4e2bd3d417a808cb747c09bf6cfa6f74404f1c0.camel@linux.ibm.com \
    --to=iii@linux.ibm.com \
    --cc=andrii.nakryiko@gmail.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=gor@linux.ibm.com \
    --cc=hca@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.