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 A3222C433EF for ; Fri, 15 Jul 2022 14:00:11 +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:Cc:To:Subject:Message-ID:Date:From: In-Reply-To:References:MIME-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=823h7Bqd4Z3dnEWJMYYpClLuA7dIqJhwVNjf64nDvGM=; b=ki8gialicfVWjK O3onZLRGbLZN0ld+ia+ZlBbKBWzJNw8VB1X/ApF3ROGAXmun9+3l3yMPSd4tkLXvaWiOTVpA2aL48 5CLaz6LPL682d3K9iCVYwaONuoamXEQ6oWWPL7fiNjJ9iPJk9EKxoCuVoNMmhsTCoLbwHpTkH8w+U pYPCM7fbQk7E/VjbdR63rBykVrWF7oGlR29NrsOhykUipgbN6o87fcyIsETmADB0cRJdR9Wu/ygtj YDnGGN9tlNpvRrHqDKBPOwjM/w76nm/UO6siL75z46H10Y6lHhrbG+msXZkUGrnFnlDLhvK5PEZca sMWIS3cWMtQZ0WCvWh/A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oCLqV-007RF5-Tt; Fri, 15 Jul 2022 13:59:08 +0000 Received: from mail-oi1-x231.google.com ([2607:f8b0:4864:20::231]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oCLqT-007RDy-6u for linux-arm-kernel@lists.infradead.org; Fri, 15 Jul 2022 13:59:07 +0000 Received: by mail-oi1-x231.google.com with SMTP id p132so6133878oif.9 for ; Fri, 15 Jul 2022 06:59:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=QvY29V/GM0mH1NqPcwS/Tuc0R9fYJIruV6sTb6TXI7Q=; b=TQgLEenxazdws7SAjjHTqasunR2EnCav01e3+lfRmImyX7Zc86iZpGxN3bx0wKUnp1 QOeThI79bl1YWoFSH8X87Thc9NYgF2i/BbtuDAexxa0jepJ/VUYg5vmAdiSlm50EJZ9R +9zne5LBxOxEdxi2tgJ4p72cbEUhuiqmLyKz4zeTTm46gi5kywSEMsi0wniUFgmkX3oh n25rRcB/vgjjNNH2jDOnUIbT7vAJGfpgbJnQqE16ZWlZzJgPfKZC91lhhNqxGobbUnFC greNyvFlAviZffzNpY2wxPSPOwsbxoOGjkMc++yBEIa9jD7BINdr4g+2XPLmUvEXXxGd 3E2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=QvY29V/GM0mH1NqPcwS/Tuc0R9fYJIruV6sTb6TXI7Q=; b=2bQ9s08D+7eZzfzX7eX316Gi8kWxjIbYQulz1iVfXylSYQzH7uu0sor/l/oT5eomLf ahJxIYtUHdBD+LRMsIbChoqy7QI0cQq/CHv40HZxSWo1ZpVVHY5pBp0r6NPeUOv+SmMB YSEtu33D75BWHHmba67ScF2JBbRQ3KKuPTe/B8MFrN/jl/SscfNoiwpCUnMGJstL7gKK vIr6iQbALr7gOnorX+mYgY08mpx3SUvpAmo2HV1YsES8WPQDQaqIGX62E5xCl8Li2Ey6 wzDZAWvVuzNi3zmqgEeTMELMMklduo1++H3pR8VKc44rbuNqnqBkznZMojmU2c/vu40A scGg== X-Gm-Message-State: AJIora9dR4I9kVXgXZtYSGYMMaV+V2vc2WXgSOm4f4NRcNjogegngvyy +NDvB8cjlDPrqo1AXtT01MtCqTvq/IcFZn/VM3KL5Q== X-Google-Smtp-Source: AGRyM1vxgZjKkuDI5/wzHx61/ekf3zJdK1KuYe2+bO8Nmwp5DWyBuh0+xl9Yf7quQUx7gopiDiGvDXqpKG8WcMJK8es= X-Received: by 2002:a05:6808:1182:b0:32d:a9d3:4e0 with SMTP id j2-20020a056808118200b0032da9d304e0mr9681619oil.146.1657893543854; Fri, 15 Jul 2022 06:59:03 -0700 (PDT) MIME-Version: 1.0 References: <20220715061027.1612149-1-kaleshsingh@google.com> <20220715061027.1612149-2-kaleshsingh@google.com> In-Reply-To: <20220715061027.1612149-2-kaleshsingh@google.com> From: Fuad Tabba Date: Fri, 15 Jul 2022 14:58:27 +0100 Message-ID: Subject: Re: [PATCH v4 01/18] arm64: stacktrace: Add shared header for common stack unwinding code To: Kalesh Singh Cc: maz@kernel.org, mark.rutland@arm.com, broonie@kernel.org, madvenka@linux.microsoft.com, will@kernel.org, qperret@google.com, james.morse@arm.com, alexandru.elisei@arm.com, suzuki.poulose@arm.com, catalin.marinas@arm.com, andreyknvl@gmail.com, russell.king@oracle.com, vincenzo.frascino@arm.com, mhiramat@kernel.org, ast@kernel.org, drjones@redhat.com, wangkefeng.wang@huawei.com, elver@google.com, keirf@google.com, yuzenghui@huawei.com, ardb@kernel.org, oupton@google.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, android-mm@google.com, kernel-team@android.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220715_065905_291130_3304220E X-CRM114-Status: GOOD ( 33.71 ) 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 Hi Kalesh, On Fri, Jul 15, 2022 at 7:10 AM Kalesh Singh wrote: > > In order to reuse the arm64 stack unwinding logic for the nVHE > hypervisor stack, move the common code to a shared header > (arch/arm64/include/asm/stacktrace/common.h). > > The nVHE hypervisor cannot safely link against kernel code, so we > make use of the shared header to avoid duplicated logic later in > this series. > > Signed-off-by: Kalesh Singh > --- Reviewed-by: Fuad Tabba Thanks, /fuad > arch/arm64/include/asm/stacktrace.h | 35 +------ > arch/arm64/include/asm/stacktrace/common.h | 105 +++++++++++++++++++++ > arch/arm64/kernel/stacktrace.c | 57 ----------- > 3 files changed, 106 insertions(+), 91 deletions(-) > create mode 100644 arch/arm64/include/asm/stacktrace/common.h > > diff --git a/arch/arm64/include/asm/stacktrace.h b/arch/arm64/include/asm/stacktrace.h > index aec9315bf156..79f455b37c84 100644 > --- a/arch/arm64/include/asm/stacktrace.h > +++ b/arch/arm64/include/asm/stacktrace.h > @@ -8,52 +8,19 @@ > #include > #include > #include > -#include > #include > > #include > #include > #include > > -enum stack_type { > - STACK_TYPE_UNKNOWN, > - STACK_TYPE_TASK, > - STACK_TYPE_IRQ, > - STACK_TYPE_OVERFLOW, > - STACK_TYPE_SDEI_NORMAL, > - STACK_TYPE_SDEI_CRITICAL, > - __NR_STACK_TYPES > -}; > - > -struct stack_info { > - unsigned long low; > - unsigned long high; > - enum stack_type type; > -}; > +#include > > extern void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk, > const char *loglvl); > > DECLARE_PER_CPU(unsigned long *, irq_stack_ptr); > > -static inline bool on_stack(unsigned long sp, unsigned long size, > - unsigned long low, unsigned long high, > - enum stack_type type, struct stack_info *info) > -{ > - if (!low) > - return false; > - > - if (sp < low || sp + size < sp || sp + size > high) > - return false; > - > - if (info) { > - info->low = low; > - info->high = high; > - info->type = type; > - } > - return true; > -} > - > static inline bool on_irq_stack(unsigned long sp, unsigned long size, > struct stack_info *info) > { > diff --git a/arch/arm64/include/asm/stacktrace/common.h b/arch/arm64/include/asm/stacktrace/common.h > new file mode 100644 > index 000000000000..64ae4f6b06fe > --- /dev/null > +++ b/arch/arm64/include/asm/stacktrace/common.h > @@ -0,0 +1,105 @@ > +/* SPDX-License-Identifier: GPL-2.0-only */ > +/* > + * Common arm64 stack unwinder code. > + * > + * Copyright (C) 2012 ARM Ltd. > + */ > +#ifndef __ASM_STACKTRACE_COMMON_H > +#define __ASM_STACKTRACE_COMMON_H > + > +#include > +#include > +#include > + > +enum stack_type { > + STACK_TYPE_UNKNOWN, > + STACK_TYPE_TASK, > + STACK_TYPE_IRQ, > + STACK_TYPE_OVERFLOW, > + STACK_TYPE_SDEI_NORMAL, > + STACK_TYPE_SDEI_CRITICAL, > + __NR_STACK_TYPES > +}; > + > +struct stack_info { > + unsigned long low; > + unsigned long high; > + enum stack_type type; > +}; > + > +/* > + * A snapshot of a frame record or fp/lr register values, along with some > + * accounting information necessary for robust unwinding. > + * > + * @fp: The fp value in the frame record (or the real fp) > + * @pc: The lr value in the frame record (or the real lr) > + * > + * @stacks_done: Stacks which have been entirely unwound, for which it is no > + * longer valid to unwind to. > + * > + * @prev_fp: The fp that pointed to this frame record, or a synthetic value > + * of 0. This is used to ensure that within a stack, each > + * subsequent frame record is at an increasing address. > + * @prev_type: The type of stack this frame record was on, or a synthetic > + * value of STACK_TYPE_UNKNOWN. This is used to detect a > + * transition from one stack to another. > + * > + * @kr_cur: When KRETPROBES is selected, holds the kretprobe instance > + * associated with the most recently encountered replacement lr > + * value. > + * > + * @task: The task being unwound. > + */ > +struct unwind_state { > + unsigned long fp; > + unsigned long pc; > + DECLARE_BITMAP(stacks_done, __NR_STACK_TYPES); > + unsigned long prev_fp; > + enum stack_type prev_type; > +#ifdef CONFIG_KRETPROBES > + struct llist_node *kr_cur; > +#endif > + struct task_struct *task; > +}; > + > +static inline bool on_stack(unsigned long sp, unsigned long size, > + unsigned long low, unsigned long high, > + enum stack_type type, struct stack_info *info) > +{ > + if (!low) > + return false; > + > + if (sp < low || sp + size < sp || sp + size > high) > + return false; > + > + if (info) { > + info->low = low; > + info->high = high; > + info->type = type; > + } > + return true; > +} > + > +static inline void unwind_init_common(struct unwind_state *state, > + struct task_struct *task) > +{ > + state->task = task; > +#ifdef CONFIG_KRETPROBES > + state->kr_cur = NULL; > +#endif > + > + /* > + * Prime the first unwind. > + * > + * In unwind_next() we'll check that the FP points to a valid stack, > + * which can't be STACK_TYPE_UNKNOWN, and the first unwind will be > + * treated as a transition to whichever stack that happens to be. The > + * prev_fp value won't be used, but we set it to 0 such that it is > + * definitely not an accessible stack address. > + */ > + bitmap_zero(state->stacks_done, __NR_STACK_TYPES); > + state->prev_fp = 0; > + state->prev_type = STACK_TYPE_UNKNOWN; > +} > + > +#endif /* __ASM_STACKTRACE_COMMON_H */ > diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c > index fcaa151b81f1..94a5dd2ab8fd 100644 > --- a/arch/arm64/kernel/stacktrace.c > +++ b/arch/arm64/kernel/stacktrace.c > @@ -18,63 +18,6 @@ > #include > #include > > -/* > - * A snapshot of a frame record or fp/lr register values, along with some > - * accounting information necessary for robust unwinding. > - * > - * @fp: The fp value in the frame record (or the real fp) > - * @pc: The lr value in the frame record (or the real lr) > - * > - * @stacks_done: Stacks which have been entirely unwound, for which it is no > - * longer valid to unwind to. > - * > - * @prev_fp: The fp that pointed to this frame record, or a synthetic value > - * of 0. This is used to ensure that within a stack, each > - * subsequent frame record is at an increasing address. > - * @prev_type: The type of stack this frame record was on, or a synthetic > - * value of STACK_TYPE_UNKNOWN. This is used to detect a > - * transition from one stack to another. > - * > - * @kr_cur: When KRETPROBES is selected, holds the kretprobe instance > - * associated with the most recently encountered replacement lr > - * value. > - * > - * @task: The task being unwound. > - */ > -struct unwind_state { > - unsigned long fp; > - unsigned long pc; > - DECLARE_BITMAP(stacks_done, __NR_STACK_TYPES); > - unsigned long prev_fp; > - enum stack_type prev_type; > -#ifdef CONFIG_KRETPROBES > - struct llist_node *kr_cur; > -#endif > - struct task_struct *task; > -}; > - > -static void unwind_init_common(struct unwind_state *state, > - struct task_struct *task) > -{ > - state->task = task; > -#ifdef CONFIG_KRETPROBES > - state->kr_cur = NULL; > -#endif > - > - /* > - * Prime the first unwind. > - * > - * In unwind_next() we'll check that the FP points to a valid stack, > - * which can't be STACK_TYPE_UNKNOWN, and the first unwind will be > - * treated as a transition to whichever stack that happens to be. The > - * prev_fp value won't be used, but we set it to 0 such that it is > - * definitely not an accessible stack address. > - */ > - bitmap_zero(state->stacks_done, __NR_STACK_TYPES); > - state->prev_fp = 0; > - state->prev_type = STACK_TYPE_UNKNOWN; > -} > - > /* > * Start an unwind from a pt_regs. > * > -- > 2.37.0.170.g444d1eabd0-goog > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel