On Mon, Jun 26, 2023 at 10:55 AM David Vernet <void@xxxxxxxxxxxxx> wrote: > > > > > + > > > > + migrate_disable(); > > > > + bpf_mem_cache_free_rcu(&bpf_cpumask_ma, cpumask); > > > > + migrate_enable(); > > > > > > The fact that callers have to disable migration like this in order to > > > safely free the memory feels a bit leaky. Is there any reason we can't > > > move this into bpf_mem_{cache_}free_rcu()? > > > > migrate_disable/enable() are actually not necessary here. > > We can call bpf_mem_cache_free_rcu() directly from any kfunc. > > Could you please clarify why? Can't we migrate if the kfunc is called > from a sleepable struct_ops callback? migration is disabled for all bpf progs including sleepable. > If migration is always disabled > for any kfunc then I agree these migrate_{en,dis}able() calls can be > removed. Otherwise from my reading of the code we'd race between calling > this_cpu_ptr() and the local_irq_save() in unit_free(). > > Thanks, > David > > > Explicit migrate_disable() is only necessary from syscall. > > > > I believe rcu callbacks also cannot migrate, so the existing > > code probably doesn't need them either.