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 645A0EB64D9 for ; Sun, 2 Jul 2023 19:45:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232730AbjGBTpi (ORCPT ); Sun, 2 Jul 2023 15:45:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232382AbjGBToR (ORCPT ); Sun, 2 Jul 2023 15:44:17 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 824A530E9; Sun, 2 Jul 2023 12:42:22 -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 1E7ED60DD8; Sun, 2 Jul 2023 19:42:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5551DC433C7; Sun, 2 Jul 2023 19:41:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1688326919; bh=2To/3OutwuyyzXNuw5tPzVrpnakJP+Ykc9RSFUTFj4k=; h=From:To:Cc:Subject:Date:From; b=Cezqfyc8rwdzBuBrDzZbvs22LHI1PQ71n4kLWUo4xZrqmvlRflaQr7StUOBpl16p0 2ErsNVMBWRDYd43U8iBOomQ/ILCN69y4lcuX3jjq694vWbA6hlcLsosFwl2Wc93Tyz 5xMg+1alVTzQeyzIjlUEgOL43kIitSs8HLxykL85H4OZsCMS6lJ3z4uRjwHx2581CX rArdbdAQOwVH2qlZQQWZ5qo9vfumwqw6VpuraG5vV+/8LMO/KiKpY91cN6OhswpYej VnUf+5lhMqOgj3RHImHCvE9XR3EwGgcOP/Jf6K2kaeLKW1ZS2Je2GInp8Wn4mT/UN1 jS+EaAHS35KQg== 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 5.10 1/7] cpu/hotplug: Reset task stack state in _cpu_up() Date: Sun, 2 Jul 2023 15:41:50 -0400 Message-Id: <20230702194156.1778977-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 5.10.186 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 008b50da22246..705d330600485 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -553,12 +553,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. @@ -1274,6 +1268,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