]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
bpf: Simplify bpf_prog_pack_[size|mask]
authorSong Liu <song@kernel.org>
Wed, 13 Jul 2022 20:49:50 +0000 (13:49 -0700)
committerDaniel Borkmann <daniel@iogearbox.net>
Fri, 22 Jul 2022 20:08:27 +0000 (22:08 +0200)
commitea2babac63d40e59926dc5de4550dac94cc3c6d2
treee05b3cd0a679152dba31f3ca293b43626525555d
parent00963a2e75a872e5fce4d0115ac2786ec86b57a6
bpf: Simplify bpf_prog_pack_[size|mask]

Simplify the logic that selects bpf_prog_pack_size, and always use
(PMD_SIZE * num_possible_nodes()). This is a good tradeoff, as most of
the performance benefit observed is from less direct map fragmentation [0].

Also, module_alloc(4MB) may not allocate 4MB aligned memory. Therefore,
we cannot use (ptr & bpf_prog_pack_mask) to find the correct address of
bpf_prog_pack. Fix this by checking the header address falls in the range
of pack->ptr and (pack->ptr + bpf_prog_pack_size).

  [0] https://lore.kernel.org/bpf/20220707223546.4124919-1-song@kernel.org/

Signed-off-by: Song Liu <song@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Reviewed-by: Stanislav Fomichev <sdf@google.com>
Link: https://lore.kernel.org/bpf/20220713204950.3015201-1-song@kernel.org
kernel/bpf/core.c