bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ilya Leoshkevich <iii@linux.ibm.com>
To: Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: 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 relocating big-endian bitfields
Date: Fri, 22 Oct 2021 12:24:11 +0200	[thread overview]
Message-ID: <8e1c57c29be8812cbd6407112b00939c7ea780ab.camel@linux.ibm.com> (raw)
In-Reply-To: <20211021234653.643302-3-iii@linux.ibm.com>

On Fri, 2021-10-22 at 01:46 +0200, Ilya Leoshkevich wrote:
> This is the same as commit c9e982b87946 ("libbpf: Fix dumping
> big-endian bitfields"), but for CO-RE. Make the code structure as
> similar as possible to that of btf_dump_get_bitfield_value().
> 
> Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
> ---
>  tools/lib/bpf/relo_core.c | 11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/lib/bpf/relo_core.c b/tools/lib/bpf/relo_core.c
> index b5b8956a1be8..fd814b985e1e 100644
> --- a/tools/lib/bpf/relo_core.c
> +++ b/tools/lib/bpf/relo_core.c
> @@ -661,13 +661,18 @@ static int bpf_core_calc_field_relo(const char
> *prog_name,
>                 if (validate)
>                         *validate = true; /* signedness is never
> ambiguous */
>                 break;
> -       case BPF_FIELD_LSHIFT_U64:
> +       case BPF_FIELD_LSHIFT_U64: {
> +               __u32 bits_offset = bit_off - byte_off * 8;
> +               __u8 nr_copy_bits;
> +
>  #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
> -               *val = 64 - (bit_off + bit_sz - byte_off  * 8);
> +               nr_copy_bits = bit_sz + bits_offset;
>  #else
> -               *val = (8 - byte_sz) * 8 + (bit_off - byte_off * 8);
> +               nr_copy_bits = byte_sz * 8 - bits_offset;
>  #endif
> +               *val = 64 - nr_copy_bits;
>                 break;
> +       }
>         case BPF_FIELD_RSHIFT_U64:
>                 *val = 64 - bit_sz;
>                 if (validate)

At a closer look this patch is not necessary: the new and the old
expressions yield the same result. Please disregard it.

Best regards,
Ilya


  reply	other threads:[~2021-10-22 10:24 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-21 23:46 [PATCH bpf-next 0/3] core_reloc fixes for s390 Ilya Leoshkevich
2021-10-21 23:46 ` [PATCH bpf-next 1/3] bpf: Use __BYTE_ORDER__ everywhere Ilya Leoshkevich
2021-10-21 23:46 ` [PATCH bpf-next 2/3] libbpf: Fix relocating big-endian bitfields Ilya Leoshkevich
2021-10-22 10:24   ` Ilya Leoshkevich [this message]
2021-10-21 23:46 ` [PATCH bpf-next 3/3] selftests/bpf: Fix test_core_reloc_mods on big-endian machines Ilya Leoshkevich
2021-10-22 23:38 ` [PATCH bpf-next 0/3] core_reloc fixes for s390 Andrii Nakryiko

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=8e1c57c29be8812cbd6407112b00939c7ea780ab.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 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).