All of lore.kernel.org
 help / color / mirror / Atom feed
From: Steven Price <steven.price@arm.com>
To: Peter Zijlstra <peterz@infradead.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Vincent Donnefort <vincent.donnefort@arm.com>
Cc: linux-kernel@vger.kernel.org, Baokun Li <libaokun1@huawei.com>,
	Dongli Zhang <dongli.zhang@oracle.com>,
	Randy Dunlap <rdunlap@infradead.org>,
	Valentin Schneider <valentin.schneider@arm.com>,
	Yuan ZhaoXiong <yuanzhaoxiong@baidu.com>,
	YueHaibing <yuehaibing@huawei.com>,
	Steven Price <steven.price@arm.com>,
	Dietmar Eggemann <dietmar.eggemann@arm.com>
Subject: [PATCH v2] cpu/hotplug: Set st->cpu earlier
Date: Wed, 16 Mar 2022 15:36:37 +0000	[thread overview]
Message-ID: <20220316153637.288199-1-steven.price@arm.com> (raw)

Setting the 'cpu' member of struct cpuhp_cpu_state in cpuhp_create() is
too late as other callbacks can be made before that point. In particular
if one of the earlier callbacks fails and triggers a rollback that
rollback will be done with st->cpu==0 causing CPU0 to be erroneously set
to be dying, causing the scheduler to get mightily confused and throw
its toys out of the pram.

Move the assignment earlier before any callbacks have a chance to run.

Fixes: 2ea46c6fc945 ("cpumask/hotplug: Fix cpu_dying() state tracking")
Signed-off-by: Steven Price <steven.price@arm.com>
CC: Dietmar Eggemann <dietmar.eggemann@arm.com>
---
Changes since v1[1]:

 * Added a Fixes: tag.
 * Moved the assignment to just before cpuhp_set_state() which is the
   first place it is needed.

[1]: https://lore.kernel.org/r/20220225134918.105796-1-steven.price%40arm.com

 kernel/cpu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/cpu.c b/kernel/cpu.c
index 407a2568f35e..c1324c8677cf 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -720,7 +720,6 @@ static void cpuhp_create(unsigned int cpu)
 
 	init_completion(&st->done_up);
 	init_completion(&st->done_down);
-	st->cpu = cpu;
 }
 
 static int cpuhp_should_run(unsigned int cpu)
@@ -1351,6 +1350,7 @@ static int _cpu_up(unsigned int cpu, int tasks_frozen, enum cpuhp_state target)
 
 	cpuhp_tasks_frozen = tasks_frozen;
 
+	st->cpu = cpu;
 	cpuhp_set_state(st, target);
 	/*
 	 * If the current CPU state is in the range of the AP hotplug thread,
-- 
2.25.1


             reply	other threads:[~2022-03-16 15:37 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-16 15:36 Steven Price [this message]
2022-03-22 11:38 ` [PATCH v2] cpu/hotplug: Set st->cpu earlier Vincent Donnefort
2022-03-22 15:31 ` Thomas Gleixner
2022-03-22 15:59   ` Vincent Donnefort
2022-03-22 22:58     ` Thomas Gleixner
2022-03-23 10:10       ` Steven Price
2022-03-23 10:11         ` [PATCH] cpu/hotplug: Remove the 'cpu' member of cpuhp_cpu_state Steven Price
2022-03-23 11:21         ` [PATCH v2] cpu/hotplug: Set st->cpu earlier Thomas Gleixner
2022-03-28 15:19           ` Steven Price

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=20220316153637.288199-1-steven.price@arm.com \
    --to=steven.price@arm.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=dongli.zhang@oracle.com \
    --cc=libaokun1@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=rdunlap@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=valentin.schneider@arm.com \
    --cc=vincent.donnefort@arm.com \
    --cc=yuanzhaoxiong@baidu.com \
    --cc=yuehaibing@huawei.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.