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 X-Spam-Level: X-Spam-Status: No, score=-17.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8BB93C64E8A for ; Tue, 1 Dec 2020 10:27:13 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (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 035D1207FF for ; Tue, 1 Dec 2020 10:27:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="IYeytg0f"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="pRfS83SC" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 035D1207FF Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject: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=juy4gD+khsMJYddWv9d8uioNH4lPNl2Er06oqojKR4M=; b=IYeytg0fER4aQkyYyN5FK4w5E rjsXqtFB9s+oawCpTJTo9QjzAUhmvfxXymRc0mHznybAb9RO2cJ0IQX31qC6mHmfr81ZnDIDdYK9+ A9m2F+6H0eBcd9eub1ak32PCEO7BAetEXKgmNOOch7kwJ7khaIYsQuEoryFHU+SxMnJPGmSbhuN62 fHSy/UKKq7Bd8fp+Z15lXknicsOE+Ck0HYcM47+aTGNsRlOaLN9Z1PcFXRidn20giqUyENjNLGiYA yqF+lXZkoUZLtYFhFOMiV/uzd8+oyuTYNq7rShfOP3zPtCWSsBtyiUumShHj1K0FYFLVXLL2ieMng WZ5v1CQOg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kk2r2-0005PA-VQ; Tue, 01 Dec 2020 10:25:53 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kk2jr-0001LR-Q1 for linux-arm-kernel@lists.infradead.org; Tue, 01 Dec 2020 10:18:33 +0000 Received: from willie-the-truck (236.31.169.217.in-addr.arpa [217.169.31.236]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8161C20770; Tue, 1 Dec 2020 10:18:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1606817905; bh=W6jlMe+K75QYDjHcjh8/5+Dk9y+mHxLaAbJkg1XPDlQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=pRfS83SCUFPeZjIbDqQh7bQzM6RKSAiK951lxbvrrQltxKge7wesugnopwf8veCIL U3wZNcIZbkQ6HMPjgrkZM6Mxyw/149PtvtsDzRZe+HVl5/x0jOrWp3HZXUatgyv6aw D2CMxXvfg4hapjYsi8pbgjfKJirm6aAph84fIg4g= Date: Tue, 1 Dec 2020 10:18:19 +0000 From: Will Deacon To: Sami Tolvanen Subject: Re: [PATCH v2 2/2] arm64: scs: use vmapped IRQ and SDEI shadow stacks Message-ID: <20201201101819.GA26471@willie-the-truck> References: <20201124195940.27061-1-samitolvanen@google.com> <20201124195940.27061-3-samitolvanen@google.com> <20201130114940.GB24563@willie-the-truck> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201201_051829_681245_0F3EF2BD X-CRM114-Status: GOOD ( 26.88 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Kees Cook , Ard Biesheuvel , Catalin Marinas , LKML , James Morse , linux-arm-kernel 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 30, 2020 at 01:13:07PM -0800, Sami Tolvanen wrote: > On Mon, Nov 30, 2020 at 3:49 AM Will Deacon wrote: > > > > On Tue, Nov 24, 2020 at 11:59:40AM -0800, Sami Tolvanen wrote: > > > Use scs_alloc() to allocate also IRQ and SDEI shadow stacks instead of > > > using statically allocated stacks. > > > > > > Signed-off-by: Sami Tolvanen > > > --- > > > arch/arm64/kernel/Makefile | 1 - > > > arch/arm64/kernel/entry.S | 6 ++-- > > > arch/arm64/kernel/irq.c | 19 ++++++++++ > > > arch/arm64/kernel/scs.c | 16 --------- > > > arch/arm64/kernel/sdei.c | 71 +++++++++++++++++++++++++++++++------- > > > include/linux/scs.h | 4 --- > > > 6 files changed, 81 insertions(+), 36 deletions(-) > > > delete mode 100644 arch/arm64/kernel/scs.c > > > > [...] > > > > > @@ -70,18 +97,40 @@ static int _init_sdei_stack(unsigned long * __percpu *ptr, int cpu) > > > return 0; > > > } > > > > > > +static int _init_sdei_scs(unsigned long * __percpu *ptr, int cpu) > > > +{ > > > + void *s; > > > + > > > + s = scs_alloc(cpu_to_node(cpu)); > > > + if (!s) > > > + return -ENOMEM; > > > + per_cpu(*ptr, cpu) = s; > > > + > > > + return 0; > > > +} > > > + > > > static int init_sdei_stacks(void) > > > { > > > int cpu; > > > int err = 0; > > > > > > for_each_possible_cpu(cpu) { > > > - err = _init_sdei_stack(&sdei_stack_normal_ptr, cpu); > > > - if (err) > > > - break; > > > - err = _init_sdei_stack(&sdei_stack_critical_ptr, cpu); > > > - if (err) > > > - break; > > > + if (IS_ENABLED(CONFIG_VMAP_STACK)) { > > > + err = _init_sdei_stack(&sdei_stack_normal_ptr, cpu); > > > + if (err) > > > + break; > > > + err = _init_sdei_stack(&sdei_stack_critical_ptr, cpu); > > > + if (err) > > > + break; > > > + } > > > + if (IS_ENABLED(CONFIG_SHADOW_CALL_STACK)) { > > > + err = _init_sdei_scs(&sdei_shadow_call_stack_normal_ptr, cpu); > > > + if (err) > > > + break; > > > + err = _init_sdei_scs(&sdei_shadow_call_stack_critical_ptr, cpu); > > > + if (err) > > > + break; > > > > This looks ok to me, but I think it would be better to follow the same > > approach as you have for the IRQ stacks and instead have a separate > > init_sdei_scs() function (similarly for the free() path), which means > > you can simply the IS_ENABLED() checks too. > > OK, I can change this in v3. It makes error handling in > sdei_arch_get_entry_point() a bit more awkward though. We'll need > something like this: > > if (IS_ENABLED(CONFIG_VMAP_STACK)) { > if (init_sdei_stacks()) > return 0; > } > > if (IS_ENABLED(CONFIG_SHADOW_CALL_STACK)) { > if (init_sdei_scs()) { > if (IS_ENABLED(CONFIG_VMAP_STACK)) > free_sdei_stacks(); > return 0; > } Can you push the IS_ENABLED() checks into their respective functions? Then you can do something like: if (init_sdei_stacks()) return 0; if (init_sdei_scs()) goto out_free_stacks; ... out_free_stacks: free_sdei_stacks(); return 0; Will _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel