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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 859E9C4332F for ; Fri, 9 Dec 2022 14:37:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229550AbiLIOht (ORCPT ); Fri, 9 Dec 2022 09:37:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229815AbiLIOhs (ORCPT ); Fri, 9 Dec 2022 09:37:48 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id AF4B7B482 for ; Fri, 9 Dec 2022 06:37:45 -0800 (PST) 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 3913323A; Fri, 9 Dec 2022 06:37:52 -0800 (PST) Received: from FVFF77S0Q05N (unknown [10.57.41.252]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 782673F73D; Fri, 9 Dec 2022 06:37:44 -0800 (PST) Date: Fri, 9 Dec 2022 14:37:41 +0000 From: Mark Rutland To: Ard Biesheuvel Cc: linux-arm-kernel@lists.infradead.org, linux-efi@vger.kernel.org, will@kernel.org, catalin.marinas@arm.com Subject: Re: [PATCH] arm64: efi: Account for the EFI runtime stack in stack unwinder Message-ID: References: <20221209133414.3330761-1-ardb@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221209133414.3330761-1-ardb@kernel.org> Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org On Fri, Dec 09, 2022 at 02:34:14PM +0100, Ard Biesheuvel wrote: > 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)) Unless you're overwriting task_struct::stack (which seems scary to me), that doesn't look right; on_task_stack() checks whether a given base + size is on the stack allocated for the task (i.e. task_struct::stack + THREAD_SIZE), not the stack the task is currently using. I would expect this to be something like: #define current_in_efi() \ (!preemptible() && spin_is_locked(&efi_rt_lock) && \ stackinfo_on_stack(stackinfo_get_efi(), current_stack_pointer, 1)) ... or an inline function given this is sufficiently painful as a macro. ... unless I've confused myself? FWIW, the patch belows looks good to me! Mark. > 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 = { > -- > 2.35.1 > 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 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 E9DD2C4332F for ; Fri, 9 Dec 2022 14:38:43 +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: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=zC5l3Lo5MlwfpQyMpCWvjuLzgV7OeH5zSgPRml9wNjU=; b=QBy71vvrd+3tIQ 5K7E0N67pcYs2rOVdtrQemI8DWw5JzoIPrZSELpLvaD0RDoq71t6C1uEjXqIXgqddyo6nHAL98AAa 5wU8NQ2FcttciW8pTcPlyqkqoefP94jjz458VAvNRP9C0xDpMHILKJy32uyZUkW2d4fRjiFNWSmOn o/uT9jafxwqGe6rH6SMHvFdhXQLQvomefjmQjsIAXdG/KbGfVFQzMRbVUK0rovgQ5q/FyYRMNJXdT rNn/wAMHlCBoRfhRVR9LaEhLPw/biTxQn22/xRsVOW1wpkNuog6prmMQpZF9gJJQZ021Bxc2s7N+h MPX2cQHNTuOXnhnicdcQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1p3eVc-008VG5-DF; Fri, 09 Dec 2022 14:37:52 +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 1p3eVY-008VEQ-B3 for linux-arm-kernel@lists.infradead.org; Fri, 09 Dec 2022 14:37:50 +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 3913323A; Fri, 9 Dec 2022 06:37:52 -0800 (PST) Received: from FVFF77S0Q05N (unknown [10.57.41.252]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 782673F73D; Fri, 9 Dec 2022 06:37:44 -0800 (PST) Date: Fri, 9 Dec 2022 14:37:41 +0000 From: Mark Rutland To: Ard Biesheuvel Cc: linux-arm-kernel@lists.infradead.org, linux-efi@vger.kernel.org, will@kernel.org, catalin.marinas@arm.com Subject: Re: [PATCH] arm64: efi: Account for the EFI runtime stack in stack unwinder Message-ID: References: <20221209133414.3330761-1-ardb@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20221209133414.3330761-1-ardb@kernel.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221209_063748_498707_E481DF46 X-CRM114-Status: GOOD ( 24.81 ) 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 Fri, Dec 09, 2022 at 02:34:14PM +0100, Ard Biesheuvel wrote: > 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)) Unless you're overwriting task_struct::stack (which seems scary to me), that doesn't look right; on_task_stack() checks whether a given base + size is on the stack allocated for the task (i.e. task_struct::stack + THREAD_SIZE), not the stack the task is currently using. I would expect this to be something like: #define current_in_efi() \ (!preemptible() && spin_is_locked(&efi_rt_lock) && \ stackinfo_on_stack(stackinfo_get_efi(), current_stack_pointer, 1)) ... or an inline function given this is sufficiently painful as a macro. ... unless I've confused myself? FWIW, the patch belows looks good to me! Mark. > 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 = { > -- > 2.35.1 > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel