diff mbox series

[bpf-next,2/3] libbpf: Fix relocating big-endian bitfields

Message ID 20211021234653.643302-3-iii@linux.ibm.com (mailing list archive)
State Superseded
Delegated to: BPF
Headers show
Series core_reloc fixes for s390 | expand

Checks

Context Check Description
netdev/cover_letter success Series has a cover letter
netdev/fixes_present success Fixes tag not required for -next series
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for bpf-next
netdev/subject_prefix success Link
netdev/cc_maintainers warning 7 maintainers not CCed: john.fastabend@gmail.com yhs@fb.com netdev@vger.kernel.org songliubraving@fb.com kafai@fb.com kpsingh@kernel.org andrii@kernel.org
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success No Fixes tag
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 21 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/header_inline success No static functions without inline keyword in header files
bpf/vmtest-bpf-next success VM_Test
bpf/vmtest-bpf-next-PR success PR summary

Commit Message

Ilya Leoshkevich Oct. 21, 2021, 11:46 p.m. UTC
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(-)

Comments

Ilya Leoshkevich Oct. 22, 2021, 10:24 a.m. UTC | #1
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
diff mbox series

Patch

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)