Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2269010pxb; Tue, 12 Oct 2021 03:02:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy864ql6JvTpkr3R8AVx4MCIQjn7tK6frmSMFE8gjgsCAfnb5V75TMZhtGEWk+NNKYNhWYR X-Received: by 2002:a17:902:d508:b0:13f:1ecb:c7d9 with SMTP id b8-20020a170902d50800b0013f1ecbc7d9mr19598876plg.51.1634032974990; Tue, 12 Oct 2021 03:02:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634032974; cv=none; d=google.com; s=arc-20160816; b=WAlKT9FbHMoGzIzAZHyO9lN9Kovgw+u9fownJUqrCGJHjq9OwL/zqRsHf7dBf97mYd 2+jRUQDzDp18QYnM2cnKVFWouMiUNkLwFye0Gl9SukVPJDj2/hjmejbOv6P2tj0pgWDL RAbCbAxPTjx+h2FFMETAfvtGALc4sircRA0iBgmtD1vFnDxShK1fLXja+GIhxE0KQqEa okkaEbrgxApyZ0LmbD55ljsrFHcxEVG3MD5VyEdTPgVpGzFFwwT/8UyILkjPim1RvlcI 5zv+MfPyijqOK67NgQofBBbXA0NisPIfuDrtkbe1jLFUdjO6kMWj2ofesGDn1H8rvrLC BDVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from; bh=OBY68RBCJk5BjVPVQBxCBXLyKXn+1Tubjv0lpwyeOeY=; b=ytnh8yS4gQIbnOrKR85rRAwO5g4ZPEQNv8WzkDlk5ij0b70nwCrIKile1HOUoJXpXf 4KnxJtj9N6MXTeDTDlg6gHMOuESeTmKaQgzHCkagFAPYPMJgkh1BysVc6fWVmszxv8z5 9PffeOdR2MF3icP0HVUAgUW/G2a0HslLTD8BJJFXw9m/5KED6RMDe2alsq8ZQIfVylja WAFmco1vrrOSfkBURwqU3PmV0yrR6nLMU0vVzoX2dt8kF78rTHLrvQq9fRUtOlQH3Fsa KbEhKZXebLmba4N+fuBLSHRYimchpVaQkRkG4/CwwyN/IMN5bjz4MrC782rug/i41uTo gWCA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c2si14897079plg.157.2021.10.12.03.02.41; Tue, 12 Oct 2021 03:02:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235871AbhJLKCG (ORCPT + 99 others); Tue, 12 Oct 2021 06:02:06 -0400 Received: from foss.arm.com ([217.140.110.172]:60374 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235881AbhJLKCC (ORCPT ); Tue, 12 Oct 2021 06:02:02 -0400 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 1FC1C101E; Tue, 12 Oct 2021 03:00:01 -0700 (PDT) Received: from e113632-lin (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8B8323F694; Tue, 12 Oct 2021 02:59:59 -0700 (PDT) From: Valentin Schneider To: Woody Lin , Ingo Molnar , Ben Segall Cc: Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Mel Gorman , Daniel Bristot de Oliveira , linux-kernel@vger.kernel.org, Woody Lin Subject: Re: [PATCH] sched/scs: Reset the shadow stack when idle_task_exit In-Reply-To: <20211012083521.973587-1-woodylin@google.com> References: <20211012083521.973587-1-woodylin@google.com> Date: Tue, 12 Oct 2021 10:59:54 +0100 Message-ID: <87zgrek1gl.mognet@arm.com> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 12/10/21 16:35, Woody Lin wrote: > There was a 'init_idle' that resets scs sp to base, but is removed by > f1a0a376ca0c. Without the resetting, the hot-plugging implemented by > cpu_psci_cpu_boot will use the previous scs sp as new base when starting > up a CPU core, so the usage on scs page is being stacked up until > overflow. > > This only happens on idle task since __cpu_up is using idle task as the > main thread to start up a CPU core, so the overflow can be fixed by > resetting scs sp to base in 'idle_task_exit'. > Looking at init_idle() for similar issues, it looks like we might also want to re-issue kasan_unpoison_task_stack() on the idle task upon hotplug. > Fixes: f1a0a376ca0c ("sched/core: Initialize the idle task with preemption disabled") > Signed-off-by: Woody Lin > --- > kernel/sched/core.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > index 1bba4128a3e6..f21714ea3db8 100644 > --- a/kernel/sched/core.c > +++ b/kernel/sched/core.c > @@ -8795,6 +8795,7 @@ void idle_task_exit(void) > finish_arch_post_lock_switch(); > } > > + scs_task_reset(current); > /* finish_cpu(), as ran on the BP, will clean up the active_mm state */ So AIUI for SCS that works just fine - one thing I'm unclear on is how the following pops are going to work given the SP reset happens in the middle of a call stack, but AFAICT that was already the case before I messed about with init_idle(), so that must already be handled. I'm not familiar enough with KASAN to say whether that kasan_unpoison_task_stack() should rather happen upon hotplugging the CPU back (rather than on hot-unplug). If that is the case, then maybe somewhere around cpu_startup_entry() might work (and then you could bunch these two "needs to be re-run at init for the idle task" functions into a common helper). > } > > -- > 2.33.0.882.g93a45727a2-goog