public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
* Re: Patch "sched_ext: Fix missing rq lock in scx_bpf_cpuperf_set()" has been added to the 6.14-stable tree
       [not found] <20250518103528.1830160-1-sashal@kernel.org>
@ 2025-05-18 15:03 ` Andrea Righi
  2025-05-20  8:51   ` Greg KH
  0 siblings, 1 reply; 2+ messages in thread
From: Andrea Righi @ 2025-05-18 15:03 UTC (permalink / raw)
  To: stable
  Cc: stable-commits, Tejun Heo, David Vernet, Changwoo Min,
	Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
	Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
	Valentin Schneider

Hi,

On Sun, May 18, 2025 at 06:35:28AM -0400, Sasha Levin wrote:
> This is a note to let you know that I've just added the patch titled
> 
>     sched_ext: Fix missing rq lock in scx_bpf_cpuperf_set()
> 
> to the 6.14-stable tree which can be found at:
>     http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
> 
> The filename of the patch is:
>      sched_ext-fix-missing-rq-lock-in-scx_bpf_cpuperf_set.patch
> and it can be found in the queue-6.14 subdirectory.
> 
> If you, or anyone else, feels it should not be added to the stable tree,
> please let <stable@vger.kernel.org> know about it.

This requires upstream commit 18853ba782bef ("sched_ext: Track currently
locked rq").

Thanks,
-Andrea

> 
> 
> 
> commit e0dd90f92931fd4040aee0bf75b348a402464821
> Author: Andrea Righi <arighi@nvidia.com>
> Date:   Tue Apr 22 10:26:33 2025 +0200
> 
>     sched_ext: Fix missing rq lock in scx_bpf_cpuperf_set()
>     
>     [ Upstream commit a11d6784d7316a6c77ca9f14fb1a698ebbb3c1fb ]
>     
>     scx_bpf_cpuperf_set() can be used to set a performance target level on
>     any CPU. However, it doesn't correctly acquire the corresponding rq
>     lock, which may lead to unsafe behavior and trigger the following
>     warning, due to the lockdep_assert_rq_held() check:
>     
>     [   51.713737] WARNING: CPU: 3 PID: 3899 at kernel/sched/sched.h:1512 scx_bpf_cpuperf_set+0x1a0/0x1e0
>     ...
>     [   51.713836] Call trace:
>     [   51.713837]  scx_bpf_cpuperf_set+0x1a0/0x1e0 (P)
>     [   51.713839]  bpf_prog_62d35beb9301601f_bpfland_init+0x168/0x440
>     [   51.713841]  bpf__sched_ext_ops_init+0x54/0x8c
>     [   51.713843]  scx_ops_enable.constprop.0+0x2c0/0x10f0
>     [   51.713845]  bpf_scx_reg+0x18/0x30
>     [   51.713847]  bpf_struct_ops_link_create+0x154/0x1b0
>     [   51.713849]  __sys_bpf+0x1934/0x22a0
>     
>     Fix by properly acquiring the rq lock when possible or raising an error
>     if we try to operate on a CPU that is not the one currently locked.
>     
>     Fixes: d86adb4fc0655 ("sched_ext: Add cpuperf support")
>     Signed-off-by: Andrea Righi <arighi@nvidia.com>
>     Acked-by: Changwoo Min <changwoo@igalia.com>
>     Signed-off-by: Tejun Heo <tj@kernel.org>
>     Signed-off-by: Sasha Levin <sashal@kernel.org>
> 
> diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c
> index 77cdff0d9f348..0067f540a3f0f 100644
> --- a/kernel/sched/ext.c
> +++ b/kernel/sched/ext.c
> @@ -7459,13 +7459,32 @@ __bpf_kfunc void scx_bpf_cpuperf_set(s32 cpu, u32 perf)
>  	}
>  
>  	if (ops_cpu_valid(cpu, NULL)) {
> -		struct rq *rq = cpu_rq(cpu);
> +		struct rq *rq = cpu_rq(cpu), *locked_rq = scx_locked_rq();
> +		struct rq_flags rf;
> +
> +		/*
> +		 * When called with an rq lock held, restrict the operation
> +		 * to the corresponding CPU to prevent ABBA deadlocks.
> +		 */
> +		if (locked_rq && rq != locked_rq) {
> +			scx_ops_error("Invalid target CPU %d", cpu);
> +			return;
> +		}
> +
> +		/*
> +		 * If no rq lock is held, allow to operate on any CPU by
> +		 * acquiring the corresponding rq lock.
> +		 */
> +		if (!locked_rq) {
> +			rq_lock_irqsave(rq, &rf);
> +			update_rq_clock(rq);
> +		}
>  
>  		rq->scx.cpuperf_target = perf;
> +		cpufreq_update_util(rq, 0);
>  
> -		rcu_read_lock_sched_notrace();
> -		cpufreq_update_util(cpu_rq(cpu), 0);
> -		rcu_read_unlock_sched_notrace();
> +		if (!locked_rq)
> +			rq_unlock_irqrestore(rq, &rf);
>  	}
>  }
>  

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Patch "sched_ext: Fix missing rq lock in scx_bpf_cpuperf_set()" has been added to the 6.14-stable tree
  2025-05-18 15:03 ` Patch "sched_ext: Fix missing rq lock in scx_bpf_cpuperf_set()" has been added to the 6.14-stable tree Andrea Righi
@ 2025-05-20  8:51   ` Greg KH
  0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2025-05-20  8:51 UTC (permalink / raw)
  To: Andrea Righi
  Cc: stable, stable-commits, Tejun Heo, David Vernet, Changwoo Min,
	Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
	Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
	Valentin Schneider

On Sun, May 18, 2025 at 05:03:14PM +0200, Andrea Righi wrote:
> Hi,
> 
> On Sun, May 18, 2025 at 06:35:28AM -0400, Sasha Levin wrote:
> > This is a note to let you know that I've just added the patch titled
> > 
> >     sched_ext: Fix missing rq lock in scx_bpf_cpuperf_set()
> > 
> > to the 6.14-stable tree which can be found at:
> >     http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
> > 
> > The filename of the patch is:
> >      sched_ext-fix-missing-rq-lock-in-scx_bpf_cpuperf_set.patch
> > and it can be found in the queue-6.14 subdirectory.
> > 
> > If you, or anyone else, feels it should not be added to the stable tree,
> > please let <stable@vger.kernel.org> know about it.
> 
> This requires upstream commit 18853ba782bef ("sched_ext: Track currently
> locked rq").

Thanks, I've dropped this from both queues now.

greg k-h

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-05-20  8:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20250518103528.1830160-1-sashal@kernel.org>
2025-05-18 15:03 ` Patch "sched_ext: Fix missing rq lock in scx_bpf_cpuperf_set()" has been added to the 6.14-stable tree Andrea Righi
2025-05-20  8:51   ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox