Skip to content

bpf: introduce and use rcu_migrate_{enable,disable} #5754

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: bpf-next_base
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions include/linux/rcupdate.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ static inline bool same_state_synchronize_rcu(unsigned long oldstate1, unsigned
void __rcu_read_lock(void);
void __rcu_read_unlock(void);

static inline void rcu_migrate_enable(void)
{
migrate_enable();
}

static inline void rcu_migrate_disable(void)
{
migrate_disable();
}

/*
* Defined as a macro as it is a very low level header included from
* areas that don't even know about current. This gives the rcu_read_lock()
Expand Down Expand Up @@ -105,6 +115,14 @@ static inline int rcu_preempt_depth(void)
return 0;
}

static inline void rcu_migrate_enable(void)
{
}

static inline void rcu_migrate_disable(void)
{
}

#endif /* #else #ifdef CONFIG_PREEMPT_RCU */

#ifdef CONFIG_RCU_LAZY
Expand Down
4 changes: 2 additions & 2 deletions kernel/bpf/bpf_cgrp_storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void bpf_cgrp_storage_free(struct cgroup *cgroup)
{
struct bpf_local_storage *local_storage;

migrate_disable();
rcu_migrate_disable();
rcu_read_lock();
local_storage = rcu_dereference(cgroup->bpf_cgrp_storage);
if (!local_storage)
Expand All @@ -56,7 +56,7 @@ void bpf_cgrp_storage_free(struct cgroup *cgroup)
bpf_cgrp_storage_unlock();
out:
rcu_read_unlock();
migrate_enable();
rcu_migrate_enable();
}

static struct bpf_local_storage_data *
Expand Down
4 changes: 2 additions & 2 deletions kernel/bpf/bpf_inode_storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void bpf_inode_storage_free(struct inode *inode)
if (!bsb)
return;

migrate_disable();
rcu_migrate_disable();
rcu_read_lock();

local_storage = rcu_dereference(bsb->storage);
Expand All @@ -72,7 +72,7 @@ void bpf_inode_storage_free(struct inode *inode)
bpf_local_storage_destroy(local_storage);
out:
rcu_read_unlock();
migrate_enable();
rcu_migrate_enable();
}

static void *bpf_fd_inode_storage_lookup_elem(struct bpf_map *map, void *key)
Expand Down
4 changes: 2 additions & 2 deletions kernel/bpf/bpf_iter.c
Original file line number Diff line number Diff line change
Expand Up @@ -706,11 +706,11 @@ int bpf_iter_run_prog(struct bpf_prog *prog, void *ctx)
rcu_read_unlock_trace();
} else {
rcu_read_lock();
migrate_disable();
rcu_migrate_disable();
old_run_ctx = bpf_set_run_ctx(&run_ctx);
ret = bpf_prog_run(prog, ctx);
bpf_reset_run_ctx(old_run_ctx);
migrate_enable();
rcu_migrate_enable();
rcu_read_unlock();
}

Expand Down
4 changes: 2 additions & 2 deletions kernel/bpf/bpf_task_storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void bpf_task_storage_free(struct task_struct *task)
{
struct bpf_local_storage *local_storage;

migrate_disable();
rcu_migrate_disable();
rcu_read_lock();

local_storage = rcu_dereference(task->bpf_storage);
Expand All @@ -82,7 +82,7 @@ void bpf_task_storage_free(struct task_struct *task)
bpf_task_storage_unlock();
out:
rcu_read_unlock();
migrate_enable();
rcu_migrate_enable();
}

static void *bpf_pid_task_storage_lookup_elem(struct bpf_map *map, void *key)
Expand Down
4 changes: 2 additions & 2 deletions kernel/bpf/cgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ bpf_prog_run_array_cg(const struct cgroup_bpf *cgrp,
u32 func_ret;

run_ctx.retval = retval;
migrate_disable();
rcu_migrate_disable();
rcu_read_lock();
array = rcu_dereference(cgrp->effective[atype]);
item = &array->items[0];
Expand All @@ -89,7 +89,7 @@ bpf_prog_run_array_cg(const struct cgroup_bpf *cgrp,
}
bpf_reset_run_ctx(old_run_ctx);
rcu_read_unlock();
migrate_enable();
rcu_migrate_enable();
return run_ctx.retval;
}

Expand Down
12 changes: 6 additions & 6 deletions kernel/bpf/trampoline.c
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ static u64 notrace __bpf_prog_enter_recur(struct bpf_prog *prog, struct bpf_tram
__acquires(RCU)
{
rcu_read_lock();
migrate_disable();
rcu_migrate_disable();

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

Expand Down Expand Up @@ -949,7 +949,7 @@ static void notrace __bpf_prog_exit_recur(struct bpf_prog *prog, u64 start,

update_prog_stats(prog, start);
this_cpu_dec(*(prog->active));
migrate_enable();
rcu_migrate_enable();
rcu_read_unlock();
}

Expand All @@ -961,7 +961,7 @@ static u64 notrace __bpf_prog_enter_lsm_cgroup(struct bpf_prog *prog,
* programs, not the shims.
*/
rcu_read_lock();
migrate_disable();
rcu_migrate_disable();

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

Expand All @@ -974,7 +974,7 @@ static void notrace __bpf_prog_exit_lsm_cgroup(struct bpf_prog *prog, u64 start,
{
bpf_reset_run_ctx(run_ctx->saved_run_ctx);

migrate_enable();
rcu_migrate_enable();
rcu_read_unlock();
}

Expand Down Expand Up @@ -1034,7 +1034,7 @@ static u64 notrace __bpf_prog_enter(struct bpf_prog *prog,
__acquires(RCU)
{
rcu_read_lock();
migrate_disable();
rcu_migrate_disable();

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

Expand All @@ -1048,7 +1048,7 @@ static void notrace __bpf_prog_exit(struct bpf_prog *prog, u64 start,
bpf_reset_run_ctx(run_ctx->saved_run_ctx);

update_prog_stats(prog, start);
migrate_enable();
rcu_migrate_enable();
rcu_read_unlock();
}

Expand Down
Loading