From patchwork Fri Dec 9 13:34:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 13069557 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 9F9B8C4332F for ; Fri, 9 Dec 2022 13:35:17 +0000 (UTC) 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:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=4uwn2g3HrRSuM8/u02dCUIcZA/wDMMDttnQSnxuLM7w=; b=J1pWcIQU2jd7mX 6wrbxerDHbYx6EQjwSYgdvTBdcpCGFuRchk1fE45Jm73nmIhDdMrnuoF8zcA6hxZO070GF/5c2DmM EtEHf+9IZ11DVnT9XN6nTqNGvzQH/4IAUCjg1k/FYgZVc3LMaoWq96QAoPXL4BgbcqijuppZDsZMJ i+HWjBm34VradQynQVySKdnuaY8AzFjt4eR9hU4UMbCg5Tm/XC5a1zRkkhPqVzsVyfefBGFPZwPbV hM5nkATykooFIY+EwzXqFj+fR1rWibNAQueLbiOHV+SvG1jlLaBc+2IaO/1neSgPDvvKDCvcanUZT 9m5WrbrQGNS9IVFnMIWg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1p3dWD-007x5k-39; Fri, 09 Dec 2022 13:34:25 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1p3dW9-007x5C-NO for linux-arm-kernel@lists.infradead.org; Fri, 09 Dec 2022 13:34:23 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4B62362254; Fri, 9 Dec 2022 13:34:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5EE33C433D2; Fri, 9 Dec 2022 13:34:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1670592860; bh=3C7oNDWScP0BNZiXI605o9QpBTHk0+kuskw3IH8ZZ6M=; h=From:To:Cc:Subject:Date:From; b=BqqpUfgd6zdSRayNElijFnCS9ec0Z1gwVU9LCvETy6Wqokj2ChSvlAhmHjSLxtOEO rqSgL58ULANeHJY2MTmcs2ofhuOOgLkpWv4Dr+RmOLYaS6zNOfKcLhOnvyTuLrsw4C pHsV+lFtzF70KyuCmQkqJHuLYKHoeq5lyOHFYK6nGDPhruo6G68HLA+vidMbE1u/l3 0Ydu1TPt7GCJcWYZtcCXqeYOdAHgZdVX5SE+9pNqFX4nZuOMKYZzHptH/oDimHn/Rf oYFURVTl7e2Mg084D4AUIT8Cy/JgGYPCIr/iq4IDMBbNvR/wz0R84ykLy8hnmoFd8o 8mYB1kAHft4/A== From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: linux-efi@vger.kernel.org, mark.rutland@arm.com, will@kernel.org, catalin.marinas@arm.com, Ard Biesheuvel Subject: [PATCH] arm64: efi: Account for the EFI runtime stack in stack unwinder Date: Fri, 9 Dec 2022 14:34:14 +0100 Message-Id: <20221209133414.3330761-1-ardb@kernel.org> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3138; i=ardb@kernel.org; h=from:subject; bh=3C7oNDWScP0BNZiXI605o9QpBTHk0+kuskw3IH8ZZ6M=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBjkzlVnrH9hiukEfDjj/XBQU4U2xMCHZpsqpevf3ET bw7nAreJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCY5M5VQAKCRDDTyI5ktmPJCWPC/ 4sRAbLUI/NLvEhJjONdnQY0Jb+WSwBbNLAdrQgZ82n/KIjQSRQ9DRUimyR4KpixrNTpPhWcQpg0ek6 ALs4JVqJp+QVnCm0BzIhtVEfdHg8vDajDwLLRA4KawOV42T2YhbYBuYeCa5MQeflCgKFlGae45FPjN 6NGQ/7oB01FGiIAgNVrtW1CCK90JQjcFOKLqSbJrCqf+mJbdPRmrUKz1Ys96Wx7zfKEiHdqT8D649k zQ5Un5eM/WBfbTmueI1eDFaW8uun3naJcS1VyF5eGGHCvsgttAQqPa1Gai9g3n7wcCzy2RRqZ8+dsc 8qWDgGmbnlc/MUmfmxqun4qFbcmKrc2GnwJtrfHczuA0wxf0dt/2rbRlRn2OO6xLst5um1S/RL3uiZ e1tyz4CqIjXXQaHh7GYUAYCIQ1pxxDb5XE1uZe/dejNFo4JUXhFH9hFXhCm0C6OVtMoL/m9LXtpZJx OmENhF6HZRtHd9Oloxaz3xgW2aIZKWiO1u4KPHeas7z1A= X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221209_053421_855524_120ED829 X-CRM114-Status: GOOD ( 14.22 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The EFI runtime services run from a dedicated stack now, and so the stack unwinder needs to be informed about this. Signed-off-by: Ard Biesheuvel --- I realised while looking into this that comparing current_work() against efi_rts_work.work is not sufficient to decide whether current is running EFI code, given that the ACPI subsystem will call efi_call_virt_pointer() directly. So instead, we can check whether the stashed thread stack pointer value matches current's thread stack if the EFI runtime stack is currently in use: #define current_in_efi() \ (!preemptible() && spin_is_locked(&efi_rt_lock) && \ on_task_stack(current, efi_rt_stack_top[-1], 1)) but this will be folded into the preceding patch, which I am not reproducing here. arch/arm64/include/asm/stacktrace.h | 15 +++++++++++++++ arch/arm64/kernel/stacktrace.c | 12 ++++++++++++ 2 files changed, 27 insertions(+) diff --git a/arch/arm64/include/asm/stacktrace.h b/arch/arm64/include/asm/stacktrace.h index 5a0edb064ea478bb..327cdcfcb1db0ad5 100644 --- a/arch/arm64/include/asm/stacktrace.h +++ b/arch/arm64/include/asm/stacktrace.h @@ -104,4 +104,19 @@ static inline struct stack_info stackinfo_get_sdei_critical(void) #define stackinfo_get_sdei_critical() stackinfo_get_unknown() #endif +#ifdef CONFIG_EFI +extern u64 *efi_rt_stack_top; + +static inline struct stack_info stackinfo_get_efi(void) +{ + unsigned long high = (u64)efi_rt_stack_top; + unsigned long low = high - THREAD_SIZE; + + return (struct stack_info) { + .low = low, + .high = high, + }; +} +#endif + #endif /* __ASM_STACKTRACE_H */ diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c index 634279b3b03d1b07..ee9fd2018cd75ed2 100644 --- a/arch/arm64/kernel/stacktrace.c +++ b/arch/arm64/kernel/stacktrace.c @@ -5,6 +5,7 @@ * Copyright (C) 2012 ARM Ltd. */ #include +#include #include #include #include @@ -12,6 +13,7 @@ #include #include +#include #include #include #include @@ -186,6 +188,13 @@ void show_stack(struct task_struct *tsk, unsigned long *sp, const char *loglvl) : stackinfo_get_unknown(); \ }) +#define STACKINFO_EFI \ + ({ \ + ((task == current) && current_in_efi()) \ + ? stackinfo_get_efi() \ + : stackinfo_get_unknown(); \ + }) + noinline notrace void arch_stack_walk(stack_trace_consume_fn consume_entry, void *cookie, struct task_struct *task, struct pt_regs *regs) @@ -199,6 +208,9 @@ noinline notrace void arch_stack_walk(stack_trace_consume_fn consume_entry, #if defined(CONFIG_VMAP_STACK) && defined(CONFIG_ARM_SDE_INTERFACE) STACKINFO_SDEI(normal), STACKINFO_SDEI(critical), +#endif +#ifdef CONFIG_EFI + STACKINFO_EFI, #endif }; struct unwind_state state = {