[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250922095705.252519-1-dongml2@chinatelecom.cn>
Date: Mon, 22 Sep 2025 17:57:05 +0800
From: Menglong Dong <menglong8.dong@...il.com>
To: jolsa@...nel.org
Cc: kpsingh@...nel.org,
mattbobrowski@...gle.com,
song@...nel.org,
ast@...nel.org,
daniel@...earbox.net,
andrii@...nel.org,
martin.lau@...ux.dev,
eddyz87@...il.com,
yonghong.song@...ux.dev,
john.fastabend@...il.com,
sdf@...ichev.me,
haoluo@...gle.com,
rostedt@...dmis.org,
mhiramat@...nel.org,
mathieu.desnoyers@...icios.com,
bpf@...r.kernel.org,
linux-kernel@...r.kernel.org,
linux-trace-kernel@...r.kernel.org
Subject: [PATCH bpf-next] bpf: remove is_return in struct bpf_session_run_ctx
The "data" in struct bpf_session_run_ctx is always 8-bytes aligned.
Therefore, we can store the "is_return" to the last bit of the "data",
which can make bpf_session_run_ctx 8-bytes aligned and save memory.
Signed-off-by: Menglong Dong <dongml2@...natelecom.cn>
---
kernel/trace/bpf_trace.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index f2360579658e..b6a34aa039f6 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -2269,7 +2269,6 @@ fs_initcall(bpf_event_init);
struct bpf_session_run_ctx {
struct bpf_run_ctx run_ctx;
- bool is_return;
void *data;
};
@@ -2535,8 +2534,7 @@ kprobe_multi_link_prog_run(struct bpf_kprobe_multi_link *link,
{
struct bpf_kprobe_multi_run_ctx run_ctx = {
.session_ctx = {
- .is_return = is_return,
- .data = data,
+ .data = (void *)((unsigned long)data | !!is_return),
},
.link = link,
.entry_ip = entry_ip,
@@ -3058,8 +3056,7 @@ static int uprobe_prog_run(struct bpf_uprobe *uprobe,
struct bpf_uprobe_multi_link *link = uprobe->link;
struct bpf_uprobe_multi_run_ctx run_ctx = {
.session_ctx = {
- .is_return = is_return,
- .data = data,
+ .data = (void *)((unsigned long)data | !!is_return),
},
.entry_ip = entry_ip,
.uprobe = uprobe,
@@ -3316,7 +3313,7 @@ __bpf_kfunc bool bpf_session_is_return(void)
struct bpf_session_run_ctx *session_ctx;
session_ctx = container_of(current->bpf_ctx, struct bpf_session_run_ctx, run_ctx);
- return session_ctx->is_return;
+ return (unsigned long)session_ctx->data & 1;
}
__bpf_kfunc __u64 *bpf_session_cookie(void)
@@ -3324,7 +3321,7 @@ __bpf_kfunc __u64 *bpf_session_cookie(void)
struct bpf_session_run_ctx *session_ctx;
session_ctx = container_of(current->bpf_ctx, struct bpf_session_run_ctx, run_ctx);
- return session_ctx->data;
+ return (__u64 *)((unsigned long)session_ctx->data & ~1);
}
__bpf_kfunc_end_defs();
--
2.51.0
Powered by blists - more mailing lists