Skip to content

Commit 8e4f0b1

Browse files
image-dragonAlexei Starovoitov
authored andcommitted
bpf: use rcu_read_lock_dont_migrate() for trampoline.c
Use rcu_read_lock_dont_migrate() and rcu_read_unlock_migrate() in trampoline.c to obtain better performance when PREEMPT_RCU is not enabled. Signed-off-by: Menglong Dong <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 427a36b commit 8e4f0b1

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

kernel/bpf/trampoline.c

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -899,8 +899,7 @@ static __always_inline u64 notrace bpf_prog_start_time(void)
899899
static u64 notrace __bpf_prog_enter_recur(struct bpf_prog *prog, struct bpf_tramp_run_ctx *run_ctx)
900900
__acquires(RCU)
901901
{
902-
rcu_read_lock();
903-
migrate_disable();
902+
rcu_read_lock_dont_migrate();
904903

905904
run_ctx->saved_run_ctx = bpf_set_run_ctx(&run_ctx->run_ctx);
906905

@@ -949,8 +948,7 @@ static void notrace __bpf_prog_exit_recur(struct bpf_prog *prog, u64 start,
949948

950949
update_prog_stats(prog, start);
951950
this_cpu_dec(*(prog->active));
952-
migrate_enable();
953-
rcu_read_unlock();
951+
rcu_read_unlock_migrate();
954952
}
955953

956954
static u64 notrace __bpf_prog_enter_lsm_cgroup(struct bpf_prog *prog,
@@ -960,8 +958,7 @@ static u64 notrace __bpf_prog_enter_lsm_cgroup(struct bpf_prog *prog,
960958
/* Runtime stats are exported via actual BPF_LSM_CGROUP
961959
* programs, not the shims.
962960
*/
963-
rcu_read_lock();
964-
migrate_disable();
961+
rcu_read_lock_dont_migrate();
965962

966963
run_ctx->saved_run_ctx = bpf_set_run_ctx(&run_ctx->run_ctx);
967964

@@ -974,8 +971,7 @@ static void notrace __bpf_prog_exit_lsm_cgroup(struct bpf_prog *prog, u64 start,
974971
{
975972
bpf_reset_run_ctx(run_ctx->saved_run_ctx);
976973

977-
migrate_enable();
978-
rcu_read_unlock();
974+
rcu_read_unlock_migrate();
979975
}
980976

981977
u64 notrace __bpf_prog_enter_sleepable_recur(struct bpf_prog *prog,
@@ -1033,8 +1029,7 @@ static u64 notrace __bpf_prog_enter(struct bpf_prog *prog,
10331029
struct bpf_tramp_run_ctx *run_ctx)
10341030
__acquires(RCU)
10351031
{
1036-
rcu_read_lock();
1037-
migrate_disable();
1032+
rcu_read_lock_dont_migrate();
10381033

10391034
run_ctx->saved_run_ctx = bpf_set_run_ctx(&run_ctx->run_ctx);
10401035

@@ -1048,8 +1043,7 @@ static void notrace __bpf_prog_exit(struct bpf_prog *prog, u64 start,
10481043
bpf_reset_run_ctx(run_ctx->saved_run_ctx);
10491044

10501045
update_prog_stats(prog, start);
1051-
migrate_enable();
1052-
rcu_read_unlock();
1046+
rcu_read_unlock_migrate();
10531047
}
10541048

10551049
void notrace __bpf_tramp_enter(struct bpf_tramp_image *tr)

0 commit comments

Comments
 (0)