mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Chris Arges <carges@cloudflare.com>
To: bpf@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: quentin@isovalent.com, ast@kernel.org, andrii@kernel.org
Subject: [PATCH] bpftool: ensure bytes_memlock json output is correct
Date: Thu, 10 Mar 2022 16:28:13 -0600	[thread overview]
Message-ID: <b6601087-0b11-33cc-904a-1133d1500a10@cloudflare.com> (raw)

From 40107402b805c4eaca5ce7a0db66d10e9219f2bf Mon Sep 17 00:00:00 2001
From: Chris J Arges <carges@cloudflare.com>
Date: Wed, 9 Mar 2022 15:41:58 -0600
Subject: [PATCH] bpftool: ensure bytes_memlock json output is correct

If a bpf map is created over 2^32 the memlock value as displayed in JSON
format will be incorrect. Use atoll instead of atoi so that the correct
number is displayed.

```
$ bpftool map create /sys/fs/bpf/test_bpfmap type hash key 4 \
  value 1024 entries 4194304 name test_bpfmap
$ bpftool map list
1: hash  name test_bpfmap  flags 0x0
        key 4B  value 1024B  max_entries 4194304  memlock 4328521728B
$ sudo bpftool map list -j | jq .[].bytes_memlock
33554432
```

Signed-off-by: Chris J Arges <carges@cloudflare.com>
---
 tools/bpf/bpftool/map.c  | 2 +-
 tools/bpf/bpftool/prog.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/bpf/bpftool/map.c b/tools/bpf/bpftool/map.c
index cc530a229812..7002f815b7ed 100644
--- a/tools/bpf/bpftool/map.c
+++ b/tools/bpf/bpftool/map.c
@@ -504,7 +504,7 @@ static int show_map_close_json(int fd, struct bpf_map_info *info)
 	jsonw_uint_field(json_wtr, "max_entries", info->max_entries);
 
 	if (memlock)
-		jsonw_int_field(json_wtr, "bytes_memlock", atoi(memlock));
+		jsonw_int_field(json_wtr, "bytes_memlock", atoll(memlock));
 	free(memlock);
 
 	if (info->type == BPF_MAP_TYPE_PROG_ARRAY) {
diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c
index 2a21d50516bc..edd8a9619341 100644
--- a/tools/bpf/bpftool/prog.c
+++ b/tools/bpf/bpftool/prog.c
@@ -480,7 +480,7 @@ static void print_prog_json(struct bpf_prog_info *info, int fd)
 
 	memlock = get_fdinfo(fd, "memlock");
 	if (memlock)
-		jsonw_int_field(json_wtr, "bytes_memlock", atoi(memlock));
+		jsonw_int_field(json_wtr, "bytes_memlock", atoll(memlock));
 	free(memlock);
 
 	if (info->nr_map_ids)
-- 
2.25.1


             reply	other threads:[~2022-03-10 22:28 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-10 22:28 Chris Arges [this message]
2022-03-10 23:30 ` 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=b6601087-0b11-33cc-904a-1133d1500a10@cloudflare.com \
    --to=carges@cloudflare.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=quentin@isovalent.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

all inboxes | Powered by JetHome®