From: Andrii Nakryiko <andrii@kernel.org>
To: <bpf@vger.kernel.org>, <ast@kernel.org>, <daniel@iogearbox.net>,
<martin.lau@kernel.org>
Cc: <andrii@kernel.org>, <kernel-team@meta.com>
Subject: [PATCH bpf-next 01/10] bpf: rearrange bpf_func_state fields to save a bit of memory
Date: Tue, 21 Nov 2023 17:16:47 -0800 [thread overview]
Message-ID: <20231122011656.1105943-2-andrii@kernel.org> (raw)
In-Reply-To: <20231122011656.1105943-1-andrii@kernel.org>
It's a trivial rearrangement saving 8 bytes. We have 4 bytes of padding
at the end which can be filled with another field without increasing
struct bpf_func_state.
copy_func_state() logic remains correct without any further changes.
BEFORE
======
struct bpf_func_state {
struct bpf_reg_state regs[11]; /* 0 1320 */
/* --- cacheline 20 boundary (1280 bytes) was 40 bytes ago --- */
int callsite; /* 1320 4 */
u32 frameno; /* 1324 4 */
u32 subprogno; /* 1328 4 */
u32 async_entry_cnt; /* 1332 4 */
bool in_callback_fn; /* 1336 1 */
/* XXX 7 bytes hole, try to pack */
/* --- cacheline 21 boundary (1344 bytes) --- */
struct tnum callback_ret_range; /* 1344 16 */
bool in_async_callback_fn; /* 1360 1 */
bool in_exception_callback_fn; /* 1361 1 */
/* XXX 2 bytes hole, try to pack */
int acquired_refs; /* 1364 4 */
struct bpf_reference_state * refs; /* 1368 8 */
int allocated_stack; /* 1376 4 */
/* XXX 4 bytes hole, try to pack */
struct bpf_stack_state * stack; /* 1384 8 */
/* size: 1392, cachelines: 22, members: 13 */
/* sum members: 1379, holes: 3, sum holes: 13 */
/* last cacheline: 48 bytes */
};
AFTER
=====
struct bpf_func_state {
struct bpf_reg_state regs[11]; /* 0 1320 */
/* --- cacheline 20 boundary (1280 bytes) was 40 bytes ago --- */
int callsite; /* 1320 4 */
u32 frameno; /* 1324 4 */
u32 subprogno; /* 1328 4 */
u32 async_entry_cnt; /* 1332 4 */
struct tnum callback_ret_range; /* 1336 16 */
/* --- cacheline 21 boundary (1344 bytes) was 8 bytes ago --- */
bool in_callback_fn; /* 1352 1 */
bool in_async_callback_fn; /* 1353 1 */
bool in_exception_callback_fn; /* 1354 1 */
/* XXX 1 byte hole, try to pack */
int acquired_refs; /* 1356 4 */
struct bpf_reference_state * refs; /* 1360 8 */
struct bpf_stack_state * stack; /* 1368 8 */
int allocated_stack; /* 1376 4 */
/* size: 1384, cachelines: 22, members: 13 */
/* sum members: 1379, holes: 1, sum holes: 1 */
/* padding: 4 */
/* last cacheline: 40 bytes */
};
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
include/linux/bpf_verifier.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/include/linux/bpf_verifier.h b/include/linux/bpf_verifier.h
index 39edc76f436e..f019da8bf423 100644
--- a/include/linux/bpf_verifier.h
+++ b/include/linux/bpf_verifier.h
@@ -297,16 +297,16 @@ struct bpf_func_state {
* void foo(void) { bpf_timer_set_callback(,foo); }
*/
u32 async_entry_cnt;
- bool in_callback_fn;
struct tnum callback_ret_range;
+ bool in_callback_fn;
bool in_async_callback_fn;
bool in_exception_callback_fn;
/* The following fields should be last. See copy_func_state() */
int acquired_refs;
struct bpf_reference_state *refs;
- int allocated_stack;
struct bpf_stack_state *stack;
+ int allocated_stack;
};
struct bpf_idx_pair {
--
2.34.1
next prev parent reply other threads:[~2023-11-22 1:17 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-22 1:16 [PATCH bpf-next 00/10] BPF verifier retval logic fixes Andrii Nakryiko
2023-11-22 1:16 ` Andrii Nakryiko [this message]
2023-11-22 15:12 ` [PATCH bpf-next 01/10] bpf: rearrange bpf_func_state fields to save a bit of memory Eduard Zingerman
2023-11-22 1:16 ` [PATCH bpf-next 02/10] bpf: provide correct register name for exception callback retval check Andrii Nakryiko
2023-11-22 15:12 ` Eduard Zingerman
2023-11-23 1:44 ` Alexei Starovoitov
2023-11-24 3:39 ` Andrii Nakryiko
2023-11-22 1:16 ` [PATCH bpf-next 03/10] bpf: enforce precision of R0 on callback return Andrii Nakryiko
2023-11-22 15:12 ` Eduard Zingerman
2023-11-22 1:16 ` [PATCH bpf-next 04/10] bpf: enforce exact retval range on subprog/callback exit Andrii Nakryiko
2023-11-22 15:13 ` Eduard Zingerman
2023-11-22 17:45 ` Andrii Nakryiko
2023-11-27 10:55 ` Shung-Hsi Yu
2023-11-27 18:19 ` Andrii Nakryiko
2023-11-22 1:16 ` [PATCH bpf-next 05/10] selftests/bpf: add selftest validating callback result is enforced Andrii Nakryiko
2023-11-22 15:13 ` Eduard Zingerman
2023-11-22 17:46 ` Andrii Nakryiko
2023-11-22 1:16 ` [PATCH bpf-next 06/10] bpf: enforce precise retval range on program exit Andrii Nakryiko
2023-11-22 15:13 ` Eduard Zingerman
2023-11-22 1:16 ` [PATCH bpf-next 07/10] bpf: unify async callback and program retval checks Andrii Nakryiko
2023-11-22 15:13 ` Eduard Zingerman
2023-11-22 1:16 ` [PATCH bpf-next 08/10] bpf: enforce precision of R0 on program/async callback return Andrii Nakryiko
2023-11-22 15:13 ` Eduard Zingerman
2023-11-22 1:16 ` [PATCH bpf-next 09/10] selftests/bpf: validate async callback return value check correctness Andrii Nakryiko
2023-11-22 15:13 ` Eduard Zingerman
2023-11-22 1:16 ` [PATCH bpf-next 10/10] selftests/bpf: adjust global_func15 test to validate prog exit precision Andrii Nakryiko
2023-11-22 15:13 ` Eduard Zingerman
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=20231122011656.1105943-2-andrii@kernel.org \
--to=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kernel-team@meta.com \
--cc=martin.lau@kernel.org \
/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