On Thu, Jan 13, 2022 at 4:49 PM Kenny Yu <kennyyu@xxxxxx> wrote: > > The next patch adds the ability to create sleepable bpf iterator programs. > This changes `bpf_iter_run_prog` to use the appropriate synchronization for > sleepable bpf programs. With sleepable bpf iterator programs, we can no > longer use `rcu_read_lock()` and must use `rcu_read_lock_trace()` instead > to protect the bpf program. > > Signed-off-by: Kenny Yu <kennyyu@xxxxxx> > --- > kernel/bpf/bpf_iter.c | 16 +++++++++++++--- > 1 file changed, 13 insertions(+), 3 deletions(-) > > diff --git a/kernel/bpf/bpf_iter.c b/kernel/bpf/bpf_iter.c > index b7aef5b3416d..d814ca6454af 100644 > --- a/kernel/bpf/bpf_iter.c > +++ b/kernel/bpf/bpf_iter.c > @@ -5,6 +5,7 @@ > #include <linux/anon_inodes.h> > #include <linux/filter.h> > #include <linux/bpf.h> > +#include <linux/rcupdate_trace.h> > > struct bpf_iter_target_info { > struct list_head list; > @@ -684,11 +685,20 @@ int bpf_iter_run_prog(struct bpf_prog *prog, void *ctx) > { > int ret; > > - rcu_read_lock(); > - migrate_disable(); > + if (prog->aux->sleepable) { > + rcu_read_lock_trace(); Pretty cool that a single 'if' is all that is needed to enable sleepable iterators. Maybe combine under one 'if' ? if (prog->aux->sleepable) { lock_trace migr_dis might_fault bpf_prog_run migr_en unlock_trace } else { lock migr_dis bpf_prog_run migr_end unlock } Would it be easier to read?