From: Dave Marchevsky <davemarchevsky@meta.com>
To: Andrii Nakryiko <andrii@kernel.org>,
bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net
Cc: kernel-team@fb.com
Subject: Re: [PATCH bpf-next 3/3] libbpf: add non-mmapable data section selftest
Date: Tue, 18 Oct 2022 16:56:52 -0400 [thread overview]
Message-ID: <dae252af-70a2-bd8c-77cf-58492747c4e6@meta.com> (raw)
In-Reply-To: <20221018035646.1294873-4-andrii@kernel.org>
On 10/17/22 11:56 PM, Andrii Nakryiko wrote:
> Add non-mmapable data section to test_skeleton selftest and make sure it
> really isn't mmapable by trying to mmap() it anyways.
>
> Also make sure that libbpf doesn't report BPF_F_MMAPABLE flag to users.
>
> Additional, some more manual testing was performed that this feature
> works as intended.
>
> Looking at created map through bpftool shows that flags passed to kernel are
> indeed zero:
>
> $ bpftool map show
> ...
> 1782: array name .data.non_mmapa flags 0x0
> key 4B value 16B max_entries 1 memlock 4096B
> btf_id 1169
> pids test_progs(8311)
> ...
>
> Checking BTF uploaded to kernel for this map shows that zero_key and
> zero_value are indeed marked as static, even though zero_key is actually
> original global (but STV_HIDDEN) variable:
>
> $ bpftool btf dump id 1169
> ...
> [51] VAR 'zero_key' type_id=2, linkage=static
> [52] VAR 'zero_value' type_id=7, linkage=static
> ...
> [62] DATASEC '.data.non_mmapable' size=16 vlen=2
> type_id=51 offset=0 size=4 (VAR 'zero_key')
> type_id=52 offset=4 size=12 (VAR 'zero_value')
> ...
>
> And original BTF does have zero_key marked as linkage=global:
>
> $ bpftool btf dump file test_skeleton.bpf.linked3.o
> ...
> [51] VAR 'zero_key' type_id=2, linkage=global
> [52] VAR 'zero_value' type_id=7, linkage=static
> ...
> [62] DATASEC '.data.non_mmapable' size=16 vlen=2
> type_id=51 offset=0 size=4 (VAR 'zero_key')
> type_id=52 offset=4 size=12 (VAR 'zero_value')
>
> Bpftool didn't require any changes at all because it checks whether internal
> map is mmapable already, but just to double-check generated skeleton, we
> see that .data.non_mmapable neither sets mmaped pointer nor has
> a corresponding field in the skeleton:
>
> $ grep non_mmapable test_skeleton.skel.h
> struct bpf_map *data_non_mmapable;
> s->maps[7].name = ".data.non_mmapable";
> s->maps[7].map = &obj->maps.data_non_mmapable;
>
> But .data.read_mostly has all of those things:
>
> $ grep read_mostly test_skeleton.skel.h
> struct bpf_map *data_read_mostly;
> struct test_skeleton__data_read_mostly {
> int read_mostly_var;
> } *data_read_mostly;
> s->maps[6].name = ".data.read_mostly";
> s->maps[6].map = &obj->maps.data_read_mostly;
> s->maps[6].mmaped = (void **)&obj->data_read_mostly;
> _Static_assert(sizeof(s->data_read_mostly->read_mostly_var) == 4, "unexpected size of 'read_mostly_var'");
>
> Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
> ---
Signed-off-by: Dave Marchevsky <davemarchevsky@fb.com>
next prev parent reply other threads:[~2022-10-18 20:57 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-18 3:56 [PATCH bpf-next 0/3] libbpf: support non-mmap()'able data sections Andrii Nakryiko
2022-10-18 3:56 ` [PATCH bpf-next 1/3] libbpf: clean up and refactor BTF fixup step Andrii Nakryiko
2022-10-18 18:47 ` sdf
2022-10-18 23:18 ` Andrii Nakryiko
2022-10-19 0:15 ` Stanislav Fomichev
2022-10-18 3:56 ` [PATCH bpf-next 2/3] libbpf: only add BPF_F_MMAPABLE flag for data maps with global vars Andrii Nakryiko
2022-10-18 18:52 ` sdf
2022-10-18 23:20 ` Andrii Nakryiko
2022-10-18 3:56 ` [PATCH bpf-next 3/3] libbpf: add non-mmapable data section selftest Andrii Nakryiko
2022-10-18 18:55 ` sdf
2022-10-18 20:56 ` Dave Marchevsky [this message]
2022-10-18 21:02 ` Dave Marchevsky
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=dae252af-70a2-bd8c-77cf-58492747c4e6@meta.com \
--to=davemarchevsky@meta.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kernel-team@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