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 9E597EB64DA for ; Sun, 2 Jul 2023 19:43:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232140AbjGBTnh (ORCPT ); Sun, 2 Jul 2023 15:43:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231779AbjGBTmw (ORCPT ); Sun, 2 Jul 2023 15:42:52 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5568019B2; Sun, 2 Jul 2023 12:41:56 -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 48F8F60C8E; Sun, 2 Jul 2023 19:40:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8A5CDC433C7; Sun, 2 Jul 2023 19:40:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1688326856; bh=HMTZTFH8s1sjSLwgQdmysxVEBfsNNOe004+DhT05PLE=; h=From:To:Cc:Subject:Date:From; b=fSCHM0VxVy02PbmqXbu8GStctwwIfdnczyDUwkPT3O51oyAz/dsqaU0rbnPPEQdY7 nmUiCIxaXUVKyNBmiPGiJY63y2SlAz9yUMNSbVyPONg4b3aWqlRMdIXJvraY664Ie5 H/ejtcry1YULI88Hls3iIvdo2/o6i4Kp4TBsFpYjKG/vgtJ8CxxisQypD3egwOwVQ8 VeBhPMs7AyTKCL4KNTmdyJnQQlpRQs4KQFeNnkJpuOkKS2auKVjd3aZx+NboabAQRa 87lLQyxtrIK+ahW8roJd3u25oWxsgjU8hSridLHRMAm3QhXRT5yJRsu60TCFpAo9JN iM+i4uV5qMG/g== 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.3 01/14] cpu/hotplug: Reset task stack state in _cpu_up() Date: Sun, 2 Jul 2023 15:40:40 -0400 Message-Id: <20230702194053.1777356-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.3.11 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 6c0a92ca6bb59..43e0a77f21e81 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