bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] libbpf: Fix build warning on ref_ctr_off
@ 2022-12-05  2:50 Khem Raj
  2022-12-07  0:14 ` Andrii Nakryiko
  0 siblings, 1 reply; 3+ messages in thread
From: Khem Raj @ 2022-12-05  2:50 UTC (permalink / raw)
  To: bpf
  Cc: Khem Raj, Alexei Starovoitov, Daniel Borkmann, Song Liu,
	Yonghong Song, Jiri Olsa, Paul Walmsley, Palmer Dabbelt,
	Nathan Chancellor, Nick Desaulniers

Clang warns on 32-bit ARM on this comparision

libbpf.c:10497:18: error: result of comparison of constant 4294967296 with expression of type 'size_t' (aka 'unsigned int') is always false [-Werror,-Wtautological-constant-out-of-range-compare]
        if (ref_ctr_off >= (1ULL << PERF_UPROBE_REF_CTR_OFFSET_BITS))
            ~~~~~~~~~~~ ^  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Check for platform long int to be larger than 32-bits before enabling
this check, it false on 32bit anyways.

Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Song Liu <song@kernel.org>
Cc: Yonghong Song <yhs@fb.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Paul Walmsley <paul.walmsley@sifive.com>
Cc: Palmer Dabbelt <palmer@dabbelt.com>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Nick Desaulniers <ndesaulniers@google.com>

Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
 tools/lib/bpf/libbpf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 91b7106a4a73..65cb70cdc22b 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -9837,7 +9837,7 @@ static int perf_event_open_probe(bool uprobe, bool retprobe, const char *name,
 	char errmsg[STRERR_BUFSIZE];
 	int type, pfd;
 
-	if (ref_ctr_off >= (1ULL << PERF_UPROBE_REF_CTR_OFFSET_BITS))
+	if (BITS_PER_LONG > 32 && ref_ctr_off >= (1ULL << PERF_UPROBE_REF_CTR_OFFSET_BITS))
 		return -EINVAL;
 
 	memset(&attr, 0, attr_sz);
-- 
2.38.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] libbpf: Fix build warning on ref_ctr_off
  2022-12-05  2:50 [PATCH] libbpf: Fix build warning on ref_ctr_off Khem Raj
@ 2022-12-07  0:14 ` Andrii Nakryiko
  2022-12-19 19:17   ` Khem Raj
  0 siblings, 1 reply; 3+ messages in thread
From: Andrii Nakryiko @ 2022-12-07  0:14 UTC (permalink / raw)
  To: Khem Raj
  Cc: bpf, Alexei Starovoitov, Daniel Borkmann, Song Liu,
	Yonghong Song, Jiri Olsa, Paul Walmsley, Palmer Dabbelt,
	Nathan Chancellor, Nick Desaulniers

On Sun, Dec 4, 2022 at 7:01 PM Khem Raj <raj.khem@gmail.com> wrote:
>
> Clang warns on 32-bit ARM on this comparision
>
> libbpf.c:10497:18: error: result of comparison of constant 4294967296 with expression of type 'size_t' (aka 'unsigned int') is always false [-Werror,-Wtautological-constant-out-of-range-compare]
>         if (ref_ctr_off >= (1ULL << PERF_UPROBE_REF_CTR_OFFSET_BITS))
>             ~~~~~~~~~~~ ^  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> Check for platform long int to be larger than 32-bits before enabling
> this check, it false on 32bit anyways.
>
> Cc: Alexei Starovoitov <ast@kernel.org>
> Cc: Daniel Borkmann <daniel@iogearbox.net>
> Cc: Song Liu <song@kernel.org>
> Cc: Yonghong Song <yhs@fb.com>
> Cc: Jiri Olsa <jolsa@kernel.org>
> Cc: Paul Walmsley <paul.walmsley@sifive.com>
> Cc: Palmer Dabbelt <palmer@dabbelt.com>
> Cc: Nathan Chancellor <nathan@kernel.org>
> Cc: Nick Desaulniers <ndesaulniers@google.com>
>
> Signed-off-by: Khem Raj <raj.khem@gmail.com>
> ---
>  tools/lib/bpf/libbpf.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index 91b7106a4a73..65cb70cdc22b 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -9837,7 +9837,7 @@ static int perf_event_open_probe(bool uprobe, bool retprobe, const char *name,
>         char errmsg[STRERR_BUFSIZE];
>         int type, pfd;
>
> -       if (ref_ctr_off >= (1ULL << PERF_UPROBE_REF_CTR_OFFSET_BITS))
> +       if (BITS_PER_LONG > 32 && ref_ctr_off >= (1ULL << PERF_UPROBE_REF_CTR_OFFSET_BITS))

Where is BITS_PER_LONG defined? Is it a compiler-provided macro? A bit
hesitant about taking dependency on such a macro. Also quick googling
suggests user-space programs should use __BITS_PER_LONG?

Can you try if just casting ref_ctr_off to __u64 would make this
warning go away?

>                 return -EINVAL;
>
>         memset(&attr, 0, attr_sz);
> --
> 2.38.1
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] libbpf: Fix build warning on ref_ctr_off
  2022-12-07  0:14 ` Andrii Nakryiko
@ 2022-12-19 19:17   ` Khem Raj
  0 siblings, 0 replies; 3+ messages in thread
From: Khem Raj @ 2022-12-19 19:17 UTC (permalink / raw)
  To: Andrii Nakryiko
  Cc: bpf, Alexei Starovoitov, Daniel Borkmann, Song Liu,
	Yonghong Song, Jiri Olsa, Paul Walmsley, Palmer Dabbelt,
	Nathan Chancellor, Nick Desaulniers

On Tue, Dec 6, 2022 at 4:14 PM Andrii Nakryiko
<andrii.nakryiko@gmail.com> wrote:
>
> On Sun, Dec 4, 2022 at 7:01 PM Khem Raj <raj.khem@gmail.com> wrote:
> >
> > Clang warns on 32-bit ARM on this comparision
> >
> > libbpf.c:10497:18: error: result of comparison of constant 4294967296 with expression of type 'size_t' (aka 'unsigned int') is always false [-Werror,-Wtautological-constant-out-of-range-compare]
> >         if (ref_ctr_off >= (1ULL << PERF_UPROBE_REF_CTR_OFFSET_BITS))
> >             ~~~~~~~~~~~ ^  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >
> > Check for platform long int to be larger than 32-bits before enabling
> > this check, it false on 32bit anyways.
> >
> > Cc: Alexei Starovoitov <ast@kernel.org>
> > Cc: Daniel Borkmann <daniel@iogearbox.net>
> > Cc: Song Liu <song@kernel.org>
> > Cc: Yonghong Song <yhs@fb.com>
> > Cc: Jiri Olsa <jolsa@kernel.org>
> > Cc: Paul Walmsley <paul.walmsley@sifive.com>
> > Cc: Palmer Dabbelt <palmer@dabbelt.com>
> > Cc: Nathan Chancellor <nathan@kernel.org>
> > Cc: Nick Desaulniers <ndesaulniers@google.com>
> >
> > Signed-off-by: Khem Raj <raj.khem@gmail.com>
> > ---
> >  tools/lib/bpf/libbpf.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> > index 91b7106a4a73..65cb70cdc22b 100644
> > --- a/tools/lib/bpf/libbpf.c
> > +++ b/tools/lib/bpf/libbpf.c
> > @@ -9837,7 +9837,7 @@ static int perf_event_open_probe(bool uprobe, bool retprobe, const char *name,
> >         char errmsg[STRERR_BUFSIZE];
> >         int type, pfd;
> >
> > -       if (ref_ctr_off >= (1ULL << PERF_UPROBE_REF_CTR_OFFSET_BITS))
> > +       if (BITS_PER_LONG > 32 && ref_ctr_off >= (1ULL << PERF_UPROBE_REF_CTR_OFFSET_BITS))
>
> Where is BITS_PER_LONG defined? Is it a compiler-provided macro? A bit
> hesitant about taking dependency on such a macro. Also quick googling
> suggests user-space programs should use __BITS_PER_LONG?

BITS_PER_LONG is in include/asm-generic/bitsperlong.h, I have sent v2
which implements your suggestion

>
> Can you try if just casting ref_ctr_off to __u64 would make this
> warning go away?
>
> >                 return -EINVAL;
> >
> >         memset(&attr, 0, attr_sz);
> > --
> > 2.38.1
> >

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-12-19 19:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-05  2:50 [PATCH] libbpf: Fix build warning on ref_ctr_off Khem Raj
2022-12-07  0:14 ` Andrii Nakryiko
2022-12-19 19:17   ` Khem Raj

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).