Re: [PATCH bpf-next 1/4] rcu: factor out migrate_enable_rcu and migrate_disable_rcu

From: Menglong Dong

Date: Wed Oct 15 2025 - 04:41:17 EST


On 2025/10/14 22:59, Alexei Starovoitov wrote:
> On Tue, Oct 14, 2025 at 4:27 AM Menglong Dong <menglong8.dong@xxxxxxxxx> wrote:
> >
> > Factor out migrate_enable_rcu/migrate_disable_rcu from
> > rcu_read_lock_dont_migrate/rcu_read_unlock_migrate.
> >
> > These functions will be used in the following patches.
> >
> > It's a little weird to define them in rcupdate.h. Maybe we should move
> > them to sched.h?
> >
> > Signed-off-by: Menglong Dong <dongml2@xxxxxxxxxxxxxxx>
> > ---
> > include/linux/rcupdate.h | 20 +++++++++++++++++---
> > 1 file changed, 17 insertions(+), 3 deletions(-)
> >
> > diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
> > index c5b30054cd01..43626ccc07e2 100644
> > --- a/include/linux/rcupdate.h
> > +++ b/include/linux/rcupdate.h
> > @@ -988,18 +988,32 @@ static inline notrace void rcu_read_unlock_sched_notrace(void)
> > preempt_enable_notrace();
> > }
> >
> > -static __always_inline void rcu_read_lock_dont_migrate(void)
> > +/* This can only be used with rcu_read_lock held */
> > +static inline void migrate_enable_rcu(void)
> > +{
> > + WARN_ON_ONCE(!rcu_read_lock_held());
> > + if (IS_ENABLED(CONFIG_PREEMPT_RCU))
> > + migrate_enable();
> > +}
> > +
> > +/* This can only be used with rcu_read_lock held */
> > +static inline void migrate_disable_rcu(void)
> > {
> > + WARN_ON_ONCE(!rcu_read_lock_held());
> > if (IS_ENABLED(CONFIG_PREEMPT_RCU))
> > migrate_disable();
> > +}
> > +
> > +static __always_inline void rcu_read_lock_dont_migrate(void)
> > +{
> > rcu_read_lock();
> > + migrate_disable_rcu();
> > }
> >
> > static inline void rcu_read_unlock_migrate(void)
> > {
> > + migrate_enable_rcu();
> > rcu_read_unlock();
> > - if (IS_ENABLED(CONFIG_PREEMPT_RCU))
> > - migrate_enable();
> > }
>
> Sorry. I don't like any of it. It obfuscates the code
> without adding any benefits.

It has a slight performance improving for some BPF type, such as
SK_SKB, SK_MSG.

Hmm, after we make migrate_disable() inline, the performance
improving here is extremely slight. And you are right, it do obfuscate
the code :/

Thanks!
Menglong Dong

>
> pw-bot: cr
>
>