[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <8e5291b7-bd89-6fea-bfb7-954cacdb8523@iogearbox.net>
Date: Mon, 20 Jun 2022 14:39:34 +0200
From: Daniel Borkmann <daniel@...earbox.net>
To: Tiezhu Yang <yangtiezhu@...ngson.cn>,
Alexei Starovoitov <ast@...nel.org>,
Andrii Nakryiko <andrii@...nel.org>
Cc: Pavel Machek <pavel@....cz>, netdev@...r.kernel.org,
bpf@...r.kernel.org
Subject: Re: [PATCH bpf-next v2] libbpf: Include linux/log2.h to use
is_power_of_2()
On 6/20/22 10:23 AM, Tiezhu Yang wrote:
> is_power_of_2() is already defined in tools/include/linux/log2.h [1],
> so no need to define it again in tools/lib/bpf/libbpf_internal.h, so
> just include linux/log2.h directly.
>
> [1] https://lore.kernel.org/bpf/20220619171248.GC3362@bug/
>
> Suggested-by: Pavel Machek <pavel@....cz>
> Signed-off-by: Tiezhu Yang <yangtiezhu@...ngson.cn>
> ---
> tools/lib/bpf/libbpf.c | 2 +-
> tools/lib/bpf/libbpf_internal.h | 6 +-----
> tools/lib/bpf/linker.c | 2 +-
> 3 files changed, 3 insertions(+), 7 deletions(-)
>
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index 49e359c..5252e51 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -5131,7 +5131,7 @@ static size_t adjust_ringbuf_sz(size_t sz)
> * a power-of-2 multiple of kernel's page size. If user diligently
> * satisified these conditions, pass the size through.
> */
> - if ((sz % page_sz) == 0 && is_pow_of_2(sz / page_sz))
> + if ((sz % page_sz) == 0 && is_power_of_2(sz / page_sz))
> return sz;
>
> /* Otherwise find closest (page_sz * power_of_2) product bigger than
> diff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_internal.h
> index a1ad145..021946a 100644
> --- a/tools/lib/bpf/libbpf_internal.h
> +++ b/tools/lib/bpf/libbpf_internal.h
> @@ -13,6 +13,7 @@
> #include <limits.h>
> #include <errno.h>
> #include <linux/err.h>
> +#include <linux/log2.h>
> #include <fcntl.h>
> #include <unistd.h>
> #include "libbpf_legacy.h"
> @@ -582,9 +583,4 @@ struct bpf_link * usdt_manager_attach_usdt(struct usdt_manager *man,
> const char *usdt_provider, const char *usdt_name,
> __u64 usdt_cookie);
>
> -static inline bool is_pow_of_2(size_t x)
> -{
> - return x && (x & (x - 1)) == 0;
> -}
I don't think this is worth the extra pain and I would just leave above as-is, because then
we would also need a `LGPL-2.1 OR BSD-2-Clause` compatible reimplementation of linux/log2.h
header inside the standalone repo https://github.com/libbpf/libbpf/tree/master/include/linux
in order to build libbpf there once this get imported to it.
> #endif /* __LIBBPF_LIBBPF_INTERNAL_H */
> diff --git a/tools/lib/bpf/linker.c b/tools/lib/bpf/linker.c
> index 4ac02c2..b2edb5f 100644
> --- a/tools/lib/bpf/linker.c
> +++ b/tools/lib/bpf/linker.c
> @@ -719,7 +719,7 @@ static int linker_sanity_check_elf(struct src_obj *obj)
> return -EINVAL;
> }
>
> - if (sec->shdr->sh_addralign && !is_pow_of_2(sec->shdr->sh_addralign))
> + if (sec->shdr->sh_addralign && !is_power_of_2(sec->shdr->sh_addralign))
> return -EINVAL;
> if (sec->shdr->sh_addralign != sec->data->d_align)
> return -EINVAL;
>
Powered by blists - more mailing lists