Skip to content

Commit 70f441d

Browse files
image-dragonKernel Patches Daemon
authored andcommitted
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 <[email protected]>
1 parent da4ec66 commit 70f441d

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

kernel/trace/bpf_trace.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2269,7 +2269,6 @@ fs_initcall(bpf_event_init);
22692269

22702270
struct bpf_session_run_ctx {
22712271
struct bpf_run_ctx run_ctx;
2272-
bool is_return;
22732272
void *data;
22742273
};
22752274

@@ -2535,8 +2534,7 @@ kprobe_multi_link_prog_run(struct bpf_kprobe_multi_link *link,
25352534
{
25362535
struct bpf_kprobe_multi_run_ctx run_ctx = {
25372536
.session_ctx = {
2538-
.is_return = is_return,
2539-
.data = data,
2537+
.data = (void *)((unsigned long)data | !!is_return),
25402538
},
25412539
.link = link,
25422540
.entry_ip = entry_ip,
@@ -3058,8 +3056,7 @@ static int uprobe_prog_run(struct bpf_uprobe *uprobe,
30583056
struct bpf_uprobe_multi_link *link = uprobe->link;
30593057
struct bpf_uprobe_multi_run_ctx run_ctx = {
30603058
.session_ctx = {
3061-
.is_return = is_return,
3062-
.data = data,
3059+
.data = (void *)((unsigned long)data | !!is_return),
30633060
},
30643061
.entry_ip = entry_ip,
30653062
.uprobe = uprobe,
@@ -3316,15 +3313,15 @@ __bpf_kfunc bool bpf_session_is_return(void)
33163313
struct bpf_session_run_ctx *session_ctx;
33173314

33183315
session_ctx = container_of(current->bpf_ctx, struct bpf_session_run_ctx, run_ctx);
3319-
return session_ctx->is_return;
3316+
return (unsigned long)session_ctx->data & 1;
33203317
}
33213318

33223319
__bpf_kfunc __u64 *bpf_session_cookie(void)
33233320
{
33243321
struct bpf_session_run_ctx *session_ctx;
33253322

33263323
session_ctx = container_of(current->bpf_ctx, struct bpf_session_run_ctx, run_ctx);
3327-
return session_ctx->data;
3324+
return (__u64 *)((unsigned long)session_ctx->data & ~1);
33283325
}
33293326

33303327
__bpf_kfunc_end_defs();

0 commit comments

Comments
 (0)