From: Jiri Olsa <olsajiri@gmail.com>
To: Alan Maguire <alan.maguire@oracle.com>
Cc: quentin@isovalent.com, ast@kernel.org, daniel@iogearbox.net,
andrii@kernel.org, martin.lau@linux.dev, song@kernel.org,
yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org,
sdf@google.com, haoluo@google.com, kuba@kernel.org,
bpf@vger.kernel.org, Nicky Veitch <nicky.veitch@oracle.com>
Subject: Re: [PATCH bpf] tools: bpftool: JIT limited misreported as negative value on aarch64
Date: Fri, 12 May 2023 13:58:14 +0200 [thread overview]
Message-ID: <ZF4p1qAaJ1UwjInt@krava> (raw)
In-Reply-To: <20230512113134.58996-1-alan.maguire@oracle.com>
On Fri, May 12, 2023 at 12:31:34PM +0100, Alan Maguire wrote:
> On aarch64, "bpftool feature" reports an incorrect BPF JIT limit:
>
> $ sudo /sbin/bpftool feature
> Scanning system configuration...
> bpf() syscall restricted to privileged users
> JIT compiler is enabled
> JIT compiler hardening is disabled
> JIT compiler kallsyms exports are enabled for root
> skipping kernel config, can't open file: No such file or directory
> Global memory limit for JIT compiler for unprivileged users is -201326592 bytes
>
> This is because /proc/sys/net/core/bpf_jit_limit reports
>
> $ sudo cat /proc/sys/net/core/bpf_jit_limit
> 68169519595520
>
> ...and an int is assumed in read_procfs(). Change read_procfs()
> to return a long to avoid negative value reporting.
>
> Fixes: 7a4522bbef0c ("tools: bpftool: add probes for /proc/ eBPF parameters")
> Reported-by: Nicky Veitch <nicky.veitch@oracle.com>
> Signed-off-by: Alan Maguire <alan.maguire@oracle.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
jirka
> ---
> tools/bpf/bpftool/feature.c | 24 ++++++++++++------------
> 1 file changed, 12 insertions(+), 12 deletions(-)
>
> diff --git a/tools/bpf/bpftool/feature.c b/tools/bpf/bpftool/feature.c
> index da16e6a27ccc..0675d6a46413 100644
> --- a/tools/bpf/bpftool/feature.c
> +++ b/tools/bpf/bpftool/feature.c
> @@ -167,12 +167,12 @@ static int get_vendor_id(int ifindex)
> return strtol(buf, NULL, 0);
> }
>
> -static int read_procfs(const char *path)
> +static long read_procfs(const char *path)
> {
> char *endptr, *line = NULL;
> size_t len = 0;
> FILE *fd;
> - int res;
> + long res;
>
> fd = fopen(path, "r");
> if (!fd)
> @@ -194,7 +194,7 @@ static int read_procfs(const char *path)
>
> static void probe_unprivileged_disabled(void)
> {
> - int res;
> + long res;
>
> /* No support for C-style ouptut */
>
> @@ -216,14 +216,14 @@ static void probe_unprivileged_disabled(void)
> printf("Unable to retrieve required privileges for bpf() syscall\n");
> break;
> default:
> - printf("bpf() syscall restriction has unknown value %d\n", res);
> + printf("bpf() syscall restriction has unknown value %ld\n", res);
> }
> }
> }
>
> static void probe_jit_enable(void)
> {
> - int res;
> + long res;
>
> /* No support for C-style ouptut */
>
> @@ -245,7 +245,7 @@ static void probe_jit_enable(void)
> printf("Unable to retrieve JIT-compiler status\n");
> break;
> default:
> - printf("JIT-compiler status has unknown value %d\n",
> + printf("JIT-compiler status has unknown value %ld\n",
> res);
> }
> }
> @@ -253,7 +253,7 @@ static void probe_jit_enable(void)
>
> static void probe_jit_harden(void)
> {
> - int res;
> + long res;
>
> /* No support for C-style ouptut */
>
> @@ -275,7 +275,7 @@ static void probe_jit_harden(void)
> printf("Unable to retrieve JIT hardening status\n");
> break;
> default:
> - printf("JIT hardening status has unknown value %d\n",
> + printf("JIT hardening status has unknown value %ld\n",
> res);
> }
> }
> @@ -283,7 +283,7 @@ static void probe_jit_harden(void)
>
> static void probe_jit_kallsyms(void)
> {
> - int res;
> + long res;
>
> /* No support for C-style ouptut */
>
> @@ -302,14 +302,14 @@ static void probe_jit_kallsyms(void)
> printf("Unable to retrieve JIT kallsyms export status\n");
> break;
> default:
> - printf("JIT kallsyms exports status has unknown value %d\n", res);
> + printf("JIT kallsyms exports status has unknown value %ld\n", res);
> }
> }
> }
>
> static void probe_jit_limit(void)
> {
> - int res;
> + long res;
>
> /* No support for C-style ouptut */
>
> @@ -322,7 +322,7 @@ static void probe_jit_limit(void)
> printf("Unable to retrieve global memory limit for JIT compiler for unprivileged users\n");
> break;
> default:
> - printf("Global memory limit for JIT compiler for unprivileged users is %d bytes\n", res);
> + printf("Global memory limit for JIT compiler for unprivileged users is %ld bytes\n", res);
> }
> }
> }
> --
> 2.31.1
>
next prev parent reply other threads:[~2023-05-12 11:58 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-12 11:31 [PATCH bpf] tools: bpftool: JIT limited misreported as negative value on aarch64 Alan Maguire
2023-05-12 11:58 ` Jiri Olsa [this message]
2023-05-12 12:09 ` Quentin Monnet
2023-05-15 19:20 ` patchwork-bot+netdevbpf
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=ZF4p1qAaJ1UwjInt@krava \
--to=olsajiri@gmail.com \
--cc=alan.maguire@oracle.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=kpsingh@kernel.org \
--cc=kuba@kernel.org \
--cc=martin.lau@linux.dev \
--cc=nicky.veitch@oracle.com \
--cc=quentin@isovalent.com \
--cc=sdf@google.com \
--cc=song@kernel.org \
--cc=yhs@fb.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