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 1E8D7EB64DA for ; Sun, 2 Jul 2023 19:43:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231935AbjGBTn2 (ORCPT ); Sun, 2 Jul 2023 15:43:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231879AbjGBTmu (ORCPT ); Sun, 2 Jul 2023 15:42:50 -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 6FA5C19AE; Sun, 2 Jul 2023 12:41:52 -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 B6DDF60C83; Sun, 2 Jul 2023 19:40:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 071F9C433C7; Sun, 2 Jul 2023 19:40:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1688326823; bh=b0hwjuL4g2YqB+pJNgio2I5aOeQsh9ilx/LsxiFL2NU=; h=From:To:Cc:Subject:Date:From; b=Bvmve06pC5ssYMKS9DfrrrgrpqeJ0YFBoVA4TBlrf7x6+7PikR4D9OiyXPUZqe/G4 PUUYDD7LInLLYEk7TEYIW0aEhefKbUbWy+T+dSjXUNBOjRhF6dKg10riO50V3AHvAp x37o30cYy7vCZ8Z1BfvMqZmMJVDrt9SzA+cWJ1Pk9w1xbduBdTnJh0ovMwAfC4NVUs Nq4uVyffRJHGQNo4lZ6kOzBj6gZ6YvO1lZgL6iJ0QitsHm4duesuNiVqPevpB2PCIq BClyWeCg16hmo+dfl5ijgn/+SeOLrAo1ts6t6QtuGeZz8iIXmCeEyB1hB/BfF9Sbzg Zb5OATsjSdvtA== 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.4 01/15] cpu/hotplug: Reset task stack state in _cpu_up() Date: Sun, 2 Jul 2023 15:40:06 -0400 Message-Id: <20230702194020.1776895-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.4.1 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 f4a2c5845bcbd..6c11cf2260542 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