Re: [PATCH] sched_ext: Fix is_bpf_migration_disabled() false negative on non-PREEMPT_RCU
From: Kuba Piecuch
Date: Thu Apr 02 2026 - 10:20:10 EST
Hi Changwoo,
On Thu Apr 2, 2026 at 2:31 AM UTC, Changwoo Min wrote:
...
> static bool is_bpf_migration_disabled(const struct task_struct *p)
> {
> - if (p->migration_disabled == 1)
> - return p != current;
> - else
> - return p->migration_disabled;
> + if (p->migration_disabled == 1) {
> + if (IS_ENABLED(CONFIG_PREEMPT_RCU))
> + return p != current;
> + return true;
> + }
> + return p->migration_disabled;
> }
The fix looks correct, but the logic looks somewhat convoluted. How about
something like this:
static bool is_bpf_migration_disabled(const struct task_struct *p)
{
- if (p->migration_disabled == 1)
- return p != current;
- else
- return p->migration_disabled;
+ if (IS_ENABLED(CONFIG_PREEMPT_RCU) &&
+ p == current &&
+ !WARN_ON_ONCE(!p->migration_disabled)) {
+ return p->migration_disabled - 1;
+ }
+ return p->migration_disabled;
}
My thinking here is: if CONFIG_PREEMPT_RCU is enabled and we're current,
subtract 1 from p->migration_disabled to account for the BPF prologue.
Otherwise just return p->migration_disabled. I've also thrown in a WARN_ON_ONCE
to help catch potential bugs if the assumption about the BPF prologue ever
changes.
Thanks,
Kuba