lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aN_7iDbWQq3HXvd3@gpd4>
Date: Fri, 3 Oct 2025 18:36:24 +0200
From: Andrea Righi <arighi@...dia.com>
To: Steven Rostedt <rostedt@...dmis.org>
Cc: LKML <linux-kernel@...r.kernel.org>,
	Peter Zijlstra <peterz@...radead.org>,
	Ingo Molnar <mingo@...nel.org>, Juri Lelli <juri.lelli@...hat.com>,
	Vincent Guittot <vincent.guittot@...aro.org>,
	Waiman Long <longman@...hat.com>, Tejun Heo <tj@...nel.org>,
	Johannes Weiner <hannes@...xchg.org>,
	Michal Koutný <mkoutny@...e.com>,
	Julia Lawall <Julia.Lawall@...ia.fr>,
	"Luis Claudio R. Goncalves" <lgoncalv@...hat.com>,
	Joseph Salisbury <joseph.salisbury@...cle.com>
Subject: Re: [PATCH] sched: cgroup: Move task_can_attach() to cpuset.c

Hi Steven,

On Fri, Oct 03, 2025 at 12:14:21PM -0400, Steven Rostedt wrote:
> From: Steven Rostedt <rostedt@...dmis.org>
> 
> At our monthly stable meeting, we were talking about documenting non
> static functions and randomly picked a function to look at. That was
> task_can_attach(). It was then noticed that it's only used by
> cgroup/cpuset.c and nothing else. It's a simple function that doesn't
> reference anything unique to sched/core.c, hence there's no reason that
> function should be there.
> 
> Move it to cgroup/cpuset.c as that's the only place it is used. Also make
> it a static inline as it is so small.
> 
> Signed-off-by: Steven Rostedt (Google) <rostedt@...dmis.org>

Nice cleanup. :)

Apparently it became that small with commit 2ef269ef1ac00 ("cgroup/cpuset:
Free DL BW in case can_attach() fails"), maybe we can mention that in the
commit message?

> ---
>  include/linux/sched.h  |  1 -
>  kernel/cgroup/cpuset.c | 19 +++++++++++++++++++
>  kernel/sched/core.c    | 19 -------------------
>  3 files changed, 19 insertions(+), 20 deletions(-)
> 
> diff --git a/include/linux/sched.h b/include/linux/sched.h
> index e4ce0a76831e..4ee4fa973eda 100644
> --- a/include/linux/sched.h
> +++ b/include/linux/sched.h
> @@ -1849,7 +1849,6 @@ current_restore_flags(unsigned long orig_flags, unsigned long flags)
>  }
>  
>  extern int cpuset_cpumask_can_shrink(const struct cpumask *cur, const struct cpumask *trial);
> -extern int task_can_attach(struct task_struct *p);
>  extern int dl_bw_alloc(int cpu, u64 dl_bw);
>  extern void dl_bw_free(int cpu, u64 dl_bw);
>  
> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
> index 27adb04df675..21fe872803e8 100644
> --- a/kernel/cgroup/cpuset.c
> +++ b/kernel/cgroup/cpuset.c
> @@ -3009,6 +3009,25 @@ static void reset_migrate_dl_data(struct cpuset *cs)
>  	cs->sum_migrate_dl_bw = 0;
>  }
>  
> +static inline int task_can_attach(struct task_struct *p)
> +{
> +	int ret = 0;
> +
> +	/*
> +	 * Kthreads which disallow setaffinity shouldn't be moved
> +	 * to a new cpuset; we don't want to change their CPU
> +	 * affinity and isolating such threads by their set of
> +	 * allowed nodes is unnecessary.  Thus, cpusets are not
> +	 * applicable for such threads.  This prevents checking for
> +	 * success of set_cpus_allowed_ptr() on all attached tasks
> +	 * before cpus_mask may be changed.
> +	 */
> +	if (p->flags & PF_NO_SETAFFINITY)
> +		ret = -EINVAL;
> +
> +	return ret;

As we're cleaning up, we could just return -EINVAL and 0 directly and get
rid of that ret variable.

> +}
> +
>  /* Called by cgroups to determine if a cpuset is usable; cpuset_mutex held */
>  static int cpuset_can_attach(struct cgroup_taskset *tset)
>  {
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index ccba6fc3c3fe..a195c4b25475 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -8070,25 +8070,6 @@ int cpuset_cpumask_can_shrink(const struct cpumask *cur,
>  	return ret;
>  }
>  
> -int task_can_attach(struct task_struct *p)
> -{
> -	int ret = 0;
> -
> -	/*
> -	 * Kthreads which disallow setaffinity shouldn't be moved
> -	 * to a new cpuset; we don't want to change their CPU
> -	 * affinity and isolating such threads by their set of
> -	 * allowed nodes is unnecessary.  Thus, cpusets are not
> -	 * applicable for such threads.  This prevents checking for
> -	 * success of set_cpus_allowed_ptr() on all attached tasks
> -	 * before cpus_mask may be changed.
> -	 */
> -	if (p->flags & PF_NO_SETAFFINITY)
> -		ret = -EINVAL;
> -
> -	return ret;
> -}
> -
>  bool sched_smp_initialized __read_mostly;
>  
>  #ifdef CONFIG_NUMA_BALANCING
> -- 
> 2.50.1
> 

Thanks,
-Andrea

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ