From patchwork Wed Sep 26 13:56:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Thierry X-Patchwork-Id: 10616039 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 06D48913 for ; Wed, 26 Sep 2018 14:01:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E9C0F2B045 for ; Wed, 26 Sep 2018 14:01:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B1F202B137; Wed, 26 Sep 2018 14:01:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 980612B0ED for ; Wed, 26 Sep 2018 14:01:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=nIMw9aiq1D7rxjDgWUSlzw6YFdptRC7RHzmo+lHdtKU=; b=HzyZ9uHiB9NzenW/N0zJOXRZNT tVeq2UYSYWrK/n4TAG5nySs/KJYMiQyduOX9/Ab9fEYshDypvGFoN90PNoE4EyXyBLED8yHQbtPmB +ungPZ/DyOEQY2wnN2cDqSkBbYbps+MPJzmHZEDHJfJFfAZ9ssx1Zd3thoGSJ9yPji/CaSS3DvdAb 8iOerWGguMb/v/YV902HhPIeJSeEIQlfI+o34lx1Es6WHcKVjcONexXB+oY7g6Sxt5X8HrY7379Q+ G6LZVHICKTSKrxUSOIaAC+DqxGZP0RQEEwngA0FINwTF9n/o3KmZzAEt4G542yEAMxQjxb4mSBzqV DtJSU2Wg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1g5ANu-0001un-H7; Wed, 26 Sep 2018 14:01:46 +0000 Received: from foss.arm.com ([217.140.101.70]) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1g5AJM-00076X-LF for linux-arm-kernel@lists.infradead.org; Wed, 26 Sep 2018 13:57:42 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0084C15BE; Wed, 26 Sep 2018 06:56:34 -0700 (PDT) Received: from e112298-lin.Emea.Arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 7D8D73F5B3; Wed, 26 Sep 2018 06:56:32 -0700 (PDT) From: Julien Thierry To: linux-arm-kernel@lists.infradead.org Subject: [PATCH 2/7] arm64: sdei: Always use sdei stack for sdei events Date: Wed, 26 Sep 2018 14:56:19 +0100 Message-Id: <1537970184-44348-3-git-send-email-julien.thierry@arm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1537970184-44348-1-git-send-email-julien.thierry@arm.com> References: <1537970184-44348-1-git-send-email-julien.thierry@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180926_065704_739396_594BED5B X-CRM114-Status: GOOD ( 16.66 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Julien Thierry , marc.zyngier@arm.com, catalin.marinas@arm.com, will.deacon@arm.com, christoffer.dall@arm.com, james.morse@arm.com, Dave.Martin@arm.com MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP SDEI events can occur at any point, including when the stack pointer is not aligned. SP could be modified to respect alignment 16-byte alignement, but there is a need to deal with code using SP as scratch register. Always reserve the SDEI stacks to handle its events. Since stack allocation relies on VMAPed stacks, lets make SDEI depend on VMAP_STACK. Signed-off-by: Julien Thierry --- arch/arm64/include/asm/sdei.h | 2 -- arch/arm64/kernel/entry.S | 2 -- arch/arm64/kernel/sdei.c | 23 ++++++++--------------- drivers/firmware/Kconfig | 1 + 4 files changed, 9 insertions(+), 19 deletions(-) diff --git a/arch/arm64/include/asm/sdei.h b/arch/arm64/include/asm/sdei.h index ffe47d7..149dffe 100644 --- a/arch/arm64/include/asm/sdei.h +++ b/arch/arm64/include/asm/sdei.h @@ -46,8 +46,6 @@ asmlinkage unsigned long __sdei_handler(struct pt_regs *regs, static inline bool on_sdei_stack(unsigned long sp, struct stack_info *info) { - if (!IS_ENABLED(CONFIG_VMAP_STACK)) - return false; if (!IS_ENABLED(CONFIG_ARM_SDE_INTERFACE)) return false; if (in_nmi()) diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S index 09dbea22..fc5842b 100644 --- a/arch/arm64/kernel/entry.S +++ b/arch/arm64/kernel/entry.S @@ -1187,7 +1187,6 @@ ENTRY(__sdei_asm_handler) mov x19, x1 -#ifdef CONFIG_VMAP_STACK /* * entry.S may have been using sp as a scratch register, find whether * this is a normal or critical event and switch to the appropriate @@ -1201,7 +1200,6 @@ ENTRY(__sdei_asm_handler) 2: mov x6, #SDEI_STACK_SIZE add x5, x5, x6 mov sp, x5 -#endif /* * We may have interrupted userspace, or a guest, or exit-from or diff --git a/arch/arm64/kernel/sdei.c b/arch/arm64/kernel/sdei.c index 5ba4465..2e2fb0b 100644 --- a/arch/arm64/kernel/sdei.c +++ b/arch/arm64/kernel/sdei.c @@ -20,21 +20,16 @@ unsigned long sdei_exit_mode; /* - * VMAP'd stacks checking for stack overflow on exception using sp as a scratch - * register, meaning SDEI has to switch to its own stack. We need two stacks as - * a critical event may interrupt a normal event that has just taken a - * synchronous exception, and is using sp as scratch register. For a critical - * event interrupting a normal event, we can't reliably tell if we were on the - * sdei stack. + * SDEI events could occur at a time where SP_EL1 is misaligned or invalid, a + * solution is to give SDEI its own stack. We need two stacks as a critical + * event may interrupt a normal event that has just taken a synchronous + * exception, and is using sp as scratch register. For a critical event + * interrupting a normal event, we can't reliably tell if we were on the sdei + * stack. * For now, we allocate stacks when the driver is probed. */ -DECLARE_PER_CPU(unsigned long *, sdei_stack_normal_ptr); -DECLARE_PER_CPU(unsigned long *, sdei_stack_critical_ptr); - -#ifdef CONFIG_VMAP_STACK DEFINE_PER_CPU(unsigned long *, sdei_stack_normal_ptr); DEFINE_PER_CPU(unsigned long *, sdei_stack_critical_ptr); -#endif static void _free_sdei_stack(unsigned long * __percpu *ptr, int cpu) { @@ -150,10 +145,8 @@ unsigned long sdei_arch_get_entry_point(int conduit) return 0; } - if (IS_ENABLED(CONFIG_VMAP_STACK)) { - if (init_sdei_stacks()) - return 0; - } + if (init_sdei_stacks()) + return 0; sdei_exit_mode = (conduit == CONDUIT_HVC) ? SDEI_EXIT_HVC : SDEI_EXIT_SMC; diff --git a/drivers/firmware/Kconfig b/drivers/firmware/Kconfig index 6e83880..c63df31 100644 --- a/drivers/firmware/Kconfig +++ b/drivers/firmware/Kconfig @@ -85,6 +85,7 @@ config ARM_SCPI_POWER_DOMAIN config ARM_SDE_INTERFACE bool "ARM Software Delegated Exception Interface (SDEI)" depends on ARM64 + depends on VMAP_STACK help The Software Delegated Exception Interface (SDEI) is an ARM standard for registering callbacks from the platform firmware