[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <939115f0-3457-75f2-c1df-4cfc6a53ba52@iogearbox.net>
Date: Tue, 10 Jul 2018 22:02:07 +0200
From: Daniel Borkmann <daniel@...earbox.net>
To: Okash Khawaja <osk@...com>
Cc: Martin KaFai Lau <kafai@...com>,
Alexei Starovoitov <ast@...nel.org>,
Yonghong Song <yhs@...com>,
Jakub Kicinski <jakub.kicinski@...ronome.com>,
"David S. Miller" <davem@...emloft.net>, netdev@...r.kernel.org,
kernel-team@...com, linux-kernel@...r.kernel.org
Subject: Re: [PATCH bpf 1/1] bpf: btf: Fix bitfield extraction for big endian
On 07/10/2018 07:49 PM, Okash Khawaja wrote:
> On Tue, Jul 10, 2018 at 10:21:02AM +0200, Daniel Borkmann wrote:
>> On 07/09/2018 08:32 PM, Martin KaFai Lau wrote:
>>> On Sun, Jul 08, 2018 at 05:22:03PM -0700, Okash Khawaja wrote:
>>>> When extracting bitfield from a number, btf_int_bits_seq_show() builds
>>>> a mask and accesses least significant byte of the number in a way
>>>> specific to little-endian. This patch fixes that by checking endianness
>>>> of the machine and then shifting left and right the unneeded bits.
>>>>
>>>> Thanks to Martin Lau for the help in navigating potential pitfalls when
>>>> dealing with endianess and for the final solution.
>>>>
>>>> Fixes: b00b8daec828 ("bpf: btf: Add pretty print capability for data with BTF type info")
>>>> Signed-off-by: Okash Khawaja <osk@...com>
>>>>
>>>> ---
>>>> kernel/bpf/btf.c | 32 +++++++++++++++-----------------
>>>> 1 file changed, 15 insertions(+), 17 deletions(-)
>>>>
>>>> --- a/kernel/bpf/btf.c
>>>> +++ b/kernel/bpf/btf.c
>>>> @@ -162,6 +162,8 @@
>>>> #define BITS_ROUNDDOWN_BYTES(bits) ((bits) >> 3)
>>>> #define BITS_ROUNDUP_BYTES(bits) \
>>>> (BITS_ROUNDDOWN_BYTES(bits) + !!BITS_PER_BYTE_MASKED(bits))
>>>> +const int one = 1;
>>>> +#define is_big_endian() ((*(char *)&one) == 0)
>>
>> Also here, in the kernel archs provide proper definitions.
> Is this the __BIG_ENDIAN #define or are there better ways to check that?
Given this deals with bitfields, should be __{BIG,LITTLE}_ENDIAN_BITFIELD.
Powered by blists - more mailing lists