public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: kernel test robot <oliver.sang@intel.com>, japo@linux.ibm.com
Cc: oe-lkp@lists.linux.dev, lkp@intel.com,
	linux-kernel@vger.kernel.org, x86@kernel.org,
	Juri Lelli <juri.lelli@redhat.com>, Tejun Heo <tj@kernel.org>,
	Vincent Guittot <vincent.guittot@linaro.org>,
	cgroups@vger.kernel.org, aubrey.li@linux.intel.com,
	yu.c.chen@intel.com
Subject: Re: [tip:sched/core] [sched]  b079d93796: WARNING:possible_recursive_locking_detected_migration_is_trying_to_acquire_lock:at:set_cpus_allowed_force_but_task_is_already_holding_lock:at:cpu_stopper_thread
Date: Tue, 28 Oct 2025 10:03:24 +0100	[thread overview]
Message-ID: <20251028090324.GQ4068168@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <20251027110133.GI3245006@noisy.programming.kicks-ass.net>

On Mon, Oct 27, 2025 at 12:01:33PM +0100, Peter Zijlstra wrote:

Could someone confirm this fixes the problem?

> ---
> Subject: sched: Fix the do_set_cpus_allowed() locking fix
> 
> Commit abfc01077df6 ("sched: Fix do_set_cpus_allowed() locking")
> overlooked that __balance_push_cpu_stop() calls select_fallback_rq()
> with rq->lock held. This makes that set_cpus_allowed_force() will
> recursively take rq->lock and the machine locks up.
> 
> Run select_fallback_rq() earlier, without holding rq->lock. This opens
> up a race window where a task could get migrated out from under us, but
> that is harmless, we want the task migrated.
> 
> select_fallback_rq() itself will not be subject to concurrency as it
> will be fully serialized by p->pi_lock, so there is no chance of
> set_cpus_allowed_force() getting called with different arguments and
> selecting different fallback CPUs for one task.
> 
> Fixes: abfc01077df6 ("sched: Fix do_set_cpus_allowed() locking")
> Reported-by: Jan Polensky <japo@linux.ibm.com>
> Reported-by: kernel test robot <oliver.sang@intel.com>
> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> Closes: https://lore.kernel.org/oe-lkp/202510271206.24495a68-lkp@intel.com
> ---
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index 1842285eac1e..67b5f2faab36 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -8044,18 +8044,15 @@ static int __balance_push_cpu_stop(void *arg)
>  	struct rq_flags rf;
>  	int cpu;
>  
> -	raw_spin_lock_irq(&p->pi_lock);
> -	rq_lock(rq, &rf);
> -
> -	update_rq_clock(rq);
> -
> -	if (task_rq(p) == rq && task_on_rq_queued(p)) {
> +	scoped_guard (raw_spinlock_irq, &p->pi_lock) {
>  		cpu = select_fallback_rq(rq->cpu, p);
> -		rq = __migrate_task(rq, &rf, p, cpu);
> -	}
>  
> -	rq_unlock(rq, &rf);
> -	raw_spin_unlock_irq(&p->pi_lock);
> +		rq_lock(rq, &rf);
> +		update_rq_clock(rq);
> +		if (task_rq(p) == rq && task_on_rq_queued(p))
> +			rq = __migrate_task(rq, &rf, p, cpu);
> +		rq_unlock(rq, &rf);
> +	}
>  
>  	put_task_struct(p);
>  

  reply	other threads:[~2025-10-28  9:03 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-27  5:14 [tip:sched/core] [sched] b079d93796: WARNING:possible_recursive_locking_detected_migration_is_trying_to_acquire_lock:at:set_cpus_allowed_force_but_task_is_already_holding_lock:at:cpu_stopper_thread kernel test robot
2025-10-27 11:01 ` Peter Zijlstra
2025-10-28  9:03   ` Peter Zijlstra [this message]
2025-10-28 11:29     ` Jan Polensky
2025-10-28 11:44   ` [tip: sched/core] sched: Fix the do_set_cpus_allowed() locking fix tip-bot2 for Peter Zijlstra
2025-10-28 14:10   ` tip-bot2 for Peter Zijlstra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251028090324.GQ4068168@noisy.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=aubrey.li@linux.intel.com \
    --cc=cgroups@vger.kernel.org \
    --cc=japo@linux.ibm.com \
    --cc=juri.lelli@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lkp@intel.com \
    --cc=oe-lkp@lists.linux.dev \
    --cc=oliver.sang@intel.com \
    --cc=tj@kernel.org \
    --cc=vincent.guittot@linaro.org \
    --cc=x86@kernel.org \
    --cc=yu.c.chen@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox