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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BFDB1C433EF for ; Mon, 15 Nov 2021 14:10:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A75FA61C4F for ; Mon, 15 Nov 2021 14:10:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232102AbhKOONm (ORCPT ); Mon, 15 Nov 2021 09:13:42 -0500 Received: from foss.arm.com ([217.140.110.172]:55770 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232060AbhKOOM0 (ORCPT ); Mon, 15 Nov 2021 09:12:26 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1AE136D; Mon, 15 Nov 2021 06:09:31 -0800 (PST) Received: from FVFF77S0Q05N.cambridge.arm.com (FVFF77S0Q05N.cambridge.arm.com [10.1.26.128]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id CD2813F766; Mon, 15 Nov 2021 06:09:29 -0800 (PST) Date: Mon, 15 Nov 2021 14:09:27 +0000 From: Mark Rutland To: Valentin Schneider Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, catalin.marinas@arm.com, dvyukov@google.com, peterz@infradead.org, quic_qiancai@quicinc.com, will@kernel.org, woodylin@google.com Subject: Re: [PATCH] Reset task stack state in bringup_cpu() Message-ID: References: <20211115113310.35693-1-mark.rutland@arm.com> <87pmr1r4vl.mognet@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87pmr1r4vl.mognet@arm.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Nov 15, 2021 at 12:16:14PM +0000, Valentin Schneider wrote: > > Hi Mark, > > Thanks for tackling this and glueing the pieces back together. LGTM, though > I couldn't stop myself from playing changelog police - I also have a > question/comment wrt the BP. I'll go fix the various typos for v2; replies to the more substantial comments below. > On 15/11/21 11:33, Mark Rutland wrote: > > To hot unplug a CPU, the idle task on that CPU calls a few layers of C > > code before finally leaving the kernel. When KASAN is in use, poisoned > > shadow is left around for each of the active stack frames, and when > > shadow call stacks are in use. When shadow call stacks are in use the > > task's SCS SP is left pointing at an arbitrary point within the task's > > shadow call stack. > > Fix both of these consistently and more robustly by resetting the SCS SP > > and KASAN shadow immediately before we online a CPU. > Reviewed-by: Valentin Schneider Thanks! > > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > > index 3c9b0fda64ac..76f9deeaa942 100644 > > --- a/kernel/sched/core.c > > +++ b/kernel/sched/core.c > > @@ -8619,9 +8619,6 @@ void __init init_idle(struct task_struct *idle, int cpu) > > idle->flags |= PF_IDLE | PF_KTHREAD | PF_NO_SETAFFINITY; > > kthread_set_per_cpu(idle, cpu); > > > > - scs_task_reset(idle); > > - kasan_unpoison_task_stack(idle); > > - > > So those are no longer invoked for the BP during bootup (via sched_init()); > that looks OK for KASAN per: > > e1b77c92981a ("sched/kasan: remove stale KASAN poison after hotplug") > > I didn't find any explicit commit for SCS but from the looks of > arm64/include/asm/thread_info.h we seem to be initializing things > correctly, so IIUC the removed hunk wasn't actually necessary for the BP's > first boot. Correct. For the init task: * The KASAN shadow starts out empty, and there's no poison to remove. * The saved SCS SP is initialized statically as part of INIT_THREAD_INFO(), via INIT_SCS(). ... so that requires no special care. For every task created thereafter (including idle threads): * dup_task_struct() allocates the new task's stack via alloc_thread_stack_node(), which either explicitly removes KASAN poison from the shadow of a cached stack, or acquires a stack via __vmalloc_node_range(), whose shadow starts out empty. * dup_task_struct() calls scs_prepare() which allocates the task's shadow stack and initializes the SCS SP for the task. The idle threads get created via fork_idle(), which calls copy_process() (and therefore dup_task_struct) to allocate the idle thread, then calls init_idle() on the result. Thanks Mark. 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F1F2CC433EF for ; Mon, 15 Nov 2021 14:11:17 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C1FE461B3D for ; Mon, 15 Nov 2021 14:11:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org C1FE461B3D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=QgTbRBNzykA3LqyElerp4qRO4ywz5BpNn2rdqpYRb9c=; b=f1mGe8ud+0rnBP VixGvidct3EtIcMVaoCR1ZTf1nZPR4NAPBU6TPdBlV+vxsD20KXQPZxQerDv8/HY3RI5pX181p3dE EwSzatsesIXoRqPumKUMn/eNdzdVsXY8seTCSZZaykxeKX0OyAOESJHkNa1rcCmqY2l/ORu/4CBul 6JzdboDedZ6ZX7iwsjbD41FBVth970CCq+xYXTJYtoVTLzGUuRCekzB83/3AeuIhS5a5hTT4933YP drHg2xPFjWWT0JwXJD/y7TlnXyPJsiTFxGAcrtw/9RbEN57z4PAjsHITFm7MxoeT95IhdYPpPkpED BYwgrFpfLKRzXfQzpaDA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mmcfv-00Foll-Ry; Mon, 15 Nov 2021 14:09:35 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mmcfs-00Fol1-F6 for linux-arm-kernel@lists.infradead.org; Mon, 15 Nov 2021 14:09:33 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1AE136D; Mon, 15 Nov 2021 06:09:31 -0800 (PST) Received: from FVFF77S0Q05N.cambridge.arm.com (FVFF77S0Q05N.cambridge.arm.com [10.1.26.128]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id CD2813F766; Mon, 15 Nov 2021 06:09:29 -0800 (PST) Date: Mon, 15 Nov 2021 14:09:27 +0000 From: Mark Rutland To: Valentin Schneider Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, catalin.marinas@arm.com, dvyukov@google.com, peterz@infradead.org, quic_qiancai@quicinc.com, will@kernel.org, woodylin@google.com Subject: Re: [PATCH] Reset task stack state in bringup_cpu() Message-ID: References: <20211115113310.35693-1-mark.rutland@arm.com> <87pmr1r4vl.mognet@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <87pmr1r4vl.mognet@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211115_060932_578441_DFE5E24F X-CRM114-Status: GOOD ( 24.00 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, Nov 15, 2021 at 12:16:14PM +0000, Valentin Schneider wrote: > > Hi Mark, > > Thanks for tackling this and glueing the pieces back together. LGTM, though > I couldn't stop myself from playing changelog police - I also have a > question/comment wrt the BP. I'll go fix the various typos for v2; replies to the more substantial comments below. > On 15/11/21 11:33, Mark Rutland wrote: > > To hot unplug a CPU, the idle task on that CPU calls a few layers of C > > code before finally leaving the kernel. When KASAN is in use, poisoned > > shadow is left around for each of the active stack frames, and when > > shadow call stacks are in use. When shadow call stacks are in use the > > task's SCS SP is left pointing at an arbitrary point within the task's > > shadow call stack. > > Fix both of these consistently and more robustly by resetting the SCS SP > > and KASAN shadow immediately before we online a CPU. > Reviewed-by: Valentin Schneider Thanks! > > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > > index 3c9b0fda64ac..76f9deeaa942 100644 > > --- a/kernel/sched/core.c > > +++ b/kernel/sched/core.c > > @@ -8619,9 +8619,6 @@ void __init init_idle(struct task_struct *idle, int cpu) > > idle->flags |= PF_IDLE | PF_KTHREAD | PF_NO_SETAFFINITY; > > kthread_set_per_cpu(idle, cpu); > > > > - scs_task_reset(idle); > > - kasan_unpoison_task_stack(idle); > > - > > So those are no longer invoked for the BP during bootup (via sched_init()); > that looks OK for KASAN per: > > e1b77c92981a ("sched/kasan: remove stale KASAN poison after hotplug") > > I didn't find any explicit commit for SCS but from the looks of > arm64/include/asm/thread_info.h we seem to be initializing things > correctly, so IIUC the removed hunk wasn't actually necessary for the BP's > first boot. Correct. For the init task: * The KASAN shadow starts out empty, and there's no poison to remove. * The saved SCS SP is initialized statically as part of INIT_THREAD_INFO(), via INIT_SCS(). ... so that requires no special care. For every task created thereafter (including idle threads): * dup_task_struct() allocates the new task's stack via alloc_thread_stack_node(), which either explicitly removes KASAN poison from the shadow of a cached stack, or acquires a stack via __vmalloc_node_range(), whose shadow starts out empty. * dup_task_struct() calls scs_prepare() which allocates the task's shadow stack and initializes the SCS SP for the task. The idle threads get created via fork_idle(), which calls copy_process() (and therefore dup_task_struct) to allocate the idle thread, then calls init_idle() on the result. Thanks Mark. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel