LKML Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] psi: simplify cgroup_move_task
@ 2018-11-03 18:33 Olof Johansson
  2018-11-06  0:29 ` Andrew Morton
  2018-11-06 16:55 ` Johannes Weiner
  0 siblings, 2 replies; 3+ messages in thread
From: Olof Johansson @ 2018-11-03 18:33 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Johannes Weiner, Ingo Molnar, Peter Zijlstra, linux-kernel,
	kernel-team, Olof Johansson

The existing code triggered an invalid warning about 'rq' possibly being
used uninitialized. Instead of doing the silly warning suppression by
initializa it to NULL, refactor the code to bail out early instead.

Warning was:

kernel/sched/psi.c: In function ‘cgroup_move_task’:
kernel/sched/psi.c:639:13: warning: ‘rq’ may be used uninitialized in this function [-Wmaybe-uninitialized]

Fixes: 2ce7135adc9ad ("psi: cgroup support")
Cc: Johannes Weiner <hannes@cmpxchg.org>
Signed-off-by: Olof Johansson <olof@lixom.net>
---
 kernel/sched/psi.c | 43 ++++++++++++++++++++++---------------------
 1 file changed, 22 insertions(+), 21 deletions(-)

diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c
index 7cdecfc010af..3d7355d7c3e3 100644
--- a/kernel/sched/psi.c
+++ b/kernel/sched/psi.c
@@ -633,38 +633,39 @@ void psi_cgroup_free(struct cgroup *cgroup)
  */
 void cgroup_move_task(struct task_struct *task, struct css_set *to)
 {
-	bool move_psi = !psi_disabled;
 	unsigned int task_flags = 0;
 	struct rq_flags rf;
 	struct rq *rq;
 
-	if (move_psi) {
-		rq = task_rq_lock(task, &rf);
+	if (psi_disabled) {
+		/*
+		 * Lame to do this here, but the scheduler cannot be locked
+		 * from the outside, so we move cgroups from inside sched/.
+		 */
+		rcu_assign_pointer(task->cgroups, to);
+		return;
+	}
 
-		if (task_on_rq_queued(task))
-			task_flags = TSK_RUNNING;
-		else if (task->in_iowait)
-			task_flags = TSK_IOWAIT;
+	rq = task_rq_lock(task, &rf);
 
-		if (task->flags & PF_MEMSTALL)
-			task_flags |= TSK_MEMSTALL;
+	if (task_on_rq_queued(task))
+		task_flags = TSK_RUNNING;
+	else if (task->in_iowait)
+		task_flags = TSK_IOWAIT;
 
-		if (task_flags)
-			psi_task_change(task, task_flags, 0);
-	}
+	if (task->flags & PF_MEMSTALL)
+		task_flags |= TSK_MEMSTALL;
 
-	/*
-	 * Lame to do this here, but the scheduler cannot be locked
-	 * from the outside, so we move cgroups from inside sched/.
-	 */
+	if (task_flags)
+		psi_task_change(task, task_flags, 0);
+
+	/* See comment above */
 	rcu_assign_pointer(task->cgroups, to);
 
-	if (move_psi) {
-		if (task_flags)
-			psi_task_change(task, 0, task_flags);
+	if (task_flags)
+		psi_task_change(task, 0, task_flags);
 
-		task_rq_unlock(rq, task, &rf);
-	}
+	task_rq_unlock(rq, task, &rf);
 }
 #endif /* CONFIG_CGROUPS */
 
-- 
2.11.0


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

* Re: [PATCH] psi: simplify cgroup_move_task
  2018-11-03 18:33 [PATCH] psi: simplify cgroup_move_task Olof Johansson
@ 2018-11-06  0:29 ` Andrew Morton
  2018-11-06 16:55 ` Johannes Weiner
  1 sibling, 0 replies; 3+ messages in thread
From: Andrew Morton @ 2018-11-06  0:29 UTC (permalink / raw)
  To: Olof Johansson
  Cc: Johannes Weiner, Ingo Molnar, Peter Zijlstra, linux-kernel, kernel-team

On Sat,  3 Nov 2018 11:33:39 -0700 Olof Johansson <olof@lixom.net> wrote:

> The existing code triggered an invalid warning about 'rq' possibly being
> used uninitialized. Instead of doing the silly warning suppression by
> initializa it to NULL, refactor the code to bail out early instead.
> 
> Warning was:
> 
> kernel/sched/psi.c: In function ‘cgroup_move_task’:
> kernel/sched/psi.c:639:13: warning: ‘rq’ may be used uninitialized in this function [-Wmaybe-uninitialized]
> 
> --- a/kernel/sched/psi.c
> +++ b/kernel/sched/psi.c
> @@ -633,38 +633,39 @@ void psi_cgroup_free(struct cgroup *cgroup)
>   */
>  void cgroup_move_task(struct task_struct *task, struct css_set *to)
>  {
> -	bool move_psi = !psi_disabled;
>  	unsigned int task_flags = 0;
>  	struct rq_flags rf;
>  	struct rq *rq;
>  
> -	if (move_psi) {
> -		rq = task_rq_lock(task, &rf);
> +	if (psi_disabled) {
> +		/*
> +		 * Lame to do this here, but the scheduler cannot be locked
> +		 * from the outside, so we move cgroups from inside sched/.
> +		 */
> +		rcu_assign_pointer(task->cgroups, to);
> +		return;
> +	}

Fair enough.

Surprisingly this doesn't increase psi.o text size.


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

* Re: [PATCH] psi: simplify cgroup_move_task
  2018-11-03 18:33 [PATCH] psi: simplify cgroup_move_task Olof Johansson
  2018-11-06  0:29 ` Andrew Morton
@ 2018-11-06 16:55 ` Johannes Weiner
  1 sibling, 0 replies; 3+ messages in thread
From: Johannes Weiner @ 2018-11-06 16:55 UTC (permalink / raw)
  To: Olof Johansson
  Cc: Andrew Morton, Ingo Molnar, Peter Zijlstra, linux-kernel, kernel-team

On Sat, Nov 03, 2018 at 11:33:39AM -0700, Olof Johansson wrote:
> The existing code triggered an invalid warning about 'rq' possibly being
> used uninitialized. Instead of doing the silly warning suppression by
> initializa it to NULL, refactor the code to bail out early instead.
> 
> Warning was:
> 
> kernel/sched/psi.c: In function ‘cgroup_move_task’:
> kernel/sched/psi.c:639:13: warning: ‘rq’ may be used uninitialized in this function [-Wmaybe-uninitialized]
> 
> Fixes: 2ce7135adc9ad ("psi: cgroup support")
> Cc: Johannes Weiner <hannes@cmpxchg.org>
> Signed-off-by: Olof Johansson <olof@lixom.net>

Acked-by: Johannes Weiner <hannes@cmpxchg.org>

Thanks Olof!

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

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-03 18:33 [PATCH] psi: simplify cgroup_move_task Olof Johansson
2018-11-06  0:29 ` Andrew Morton
2018-11-06 16:55 ` Johannes Weiner

LKML Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/lkml/0 lkml/git/0.git
	git clone --mirror https://lore.kernel.org/lkml/1 lkml/git/1.git
	git clone --mirror https://lore.kernel.org/lkml/2 lkml/git/2.git
	git clone --mirror https://lore.kernel.org/lkml/3 lkml/git/3.git
	git clone --mirror https://lore.kernel.org/lkml/4 lkml/git/4.git
	git clone --mirror https://lore.kernel.org/lkml/5 lkml/git/5.git
	git clone --mirror https://lore.kernel.org/lkml/6 lkml/git/6.git
	git clone --mirror https://lore.kernel.org/lkml/7 lkml/git/7.git
	git clone --mirror https://lore.kernel.org/lkml/8 lkml/git/8.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 lkml lkml/ https://lore.kernel.org/lkml \
		linux-kernel@vger.kernel.org
	public-inbox-index lkml

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-kernel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git