From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CC95DEB64DA for ; Sun, 2 Jul 2023 19:43:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231962AbjGBTna (ORCPT ); Sun, 2 Jul 2023 15:43:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229884AbjGBTmu (ORCPT ); Sun, 2 Jul 2023 15:42:50 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4CB911BF1; Sun, 2 Jul 2023 12:41:54 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 9274060D2D; Sun, 2 Jul 2023 19:41:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EE13BC433C8; Sun, 2 Jul 2023 19:41:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1688326881; bh=kaoYMXcUH68T+EDSqSVY6VFp9oPaeA+5qF1WqfhvIV8=; h=From:To:Cc:Subject:Date:From; b=qo1Gdz3c8cdskgSer9xV9p4Z3EOTJM8WKJhEkxIegsCigLi+ITmOS4662uqFkYGha lxei8nRZpVW01PGu7Co0yZs+XHVUnlrP1F/nT5mdnc/sjxPrKxcDUgXB7NuZCbloFV Vey8/hXZHlqn45tchc8Fdy2y3sqUW1As/4LG3fuh8ug4juTxPU57QwSv5lvIxH1qED PxVqTpFRn94oRUJoThIt1xyxqNVexoQl4iSmOsM9JBjDV8q0+APLrPlpC3QceaLg4e hwbzURRn8k/S0aTL5pb0oqG4zi9qTspira99yv+qlXgZZ59A8UL/CWYMPRO8+hS6N7 cRGgX+htjbwVg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: David Woodhouse , Thomas Gleixner , Peter Zijlstra , Mark Rutland , Michael Kelley , Oleksandr Natalenko , Helge Deller , "Guilherme G . Piccoli" , Sasha Levin Subject: [PATCH AUTOSEL 6.1 01/12] cpu/hotplug: Reset task stack state in _cpu_up() Date: Sun, 2 Jul 2023 15:41:06 -0400 Message-Id: <20230702194118.1777794-1-sashal@kernel.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.1.37 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: David Woodhouse [ Upstream commit 6d712b9b3a58018259fb40ddd498d1f7dfa1f4ec ] Commit dce1ca0525bf ("sched/scs: Reset task stack state in bringup_cpu()") ensured that the shadow call stack and KASAN poisoning were removed from a CPU's stack each time that CPU is brought up, not just once. This is not incorrect. However, with parallel bringup the idle thread setup will happen at a different step. As a consequence the cleanup in bringup_cpu() would be too late. Move the SCS/KASAN cleanup to the generic _cpu_up() function instead, which already ensures that the new CPU's stack is available, purely to allow for early failure. This occurs when the CPU to be brought up is in the CPUHP_OFFLINE state, which should correctly do the cleanup any time the CPU has been taken down to the point where such is needed. Signed-off-by: David Woodhouse Signed-off-by: Thomas Gleixner Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Mark Rutland Tested-by: Mark Rutland Tested-by: Michael Kelley Tested-by: Oleksandr Natalenko Tested-by: Helge Deller # parisc Tested-by: Guilherme G. Piccoli # Steam Deck Link: https://lore.kernel.org/r/20230512205257.027075560@linutronix.de Signed-off-by: Sasha Levin --- kernel/cpu.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/kernel/cpu.c b/kernel/cpu.c index 98a7a7b1471b7..dbf1e572f6e7d 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -591,12 +591,6 @@ static int bringup_cpu(unsigned int cpu) struct task_struct *idle = idle_thread_get(cpu); int ret; - /* - * Reset stale stack state from the last time this CPU was online. - */ - scs_task_reset(idle); - kasan_unpoison_task_stack(idle); - /* * Some architectures have to walk the irq descriptors to * setup the vector space for the cpu which comes online. @@ -1383,6 +1377,12 @@ static int _cpu_up(unsigned int cpu, int tasks_frozen, enum cpuhp_state target) ret = PTR_ERR(idle); goto out; } + + /* + * Reset stale stack state from the last time this CPU was online. + */ + scs_task_reset(idle); + kasan_unpoison_task_stack(idle); } cpuhp_tasks_frozen = tasks_frozen; -- 2.39.2