Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp494577imw; Fri, 15 Jul 2022 07:17:52 -0700 (PDT) X-Google-Smtp-Source: AGRyM1ve6dxhgxs1ak1/Zezvs08BQNUdAZNRWBoAW3I4l3yqmVTo2rMfrCQjOOpKw4yIW6+RXOus X-Received: by 2002:a17:906:d550:b0:726:2b34:2fd6 with SMTP id cr16-20020a170906d55000b007262b342fd6mr13885206ejc.311.1657894672185; Fri, 15 Jul 2022 07:17:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657894672; cv=none; d=google.com; s=arc-20160816; b=m3PejZ/mb3FcRxhLj2UyYcDJpx2n2oVP7s+4OP0fQswPuGiNtIvueju48Xk3SlBTl4 4sH3FLFsWVxPWn9PrzlrM0QdoYFMS6uBt1dvYlG8XdanQgd07GXAm+CUvustg15aGDnj aMEy4EEDmeOKdeNvoRj9wuWP3u/pqBQFH3G4EaG7/vMelP4QV6ydO0b5x7wFT0sMTNFc +Bu0k31SuS7C17Hz6hfY/L0TstEIma4h7ICtPqqWw+jWCplx5k6VI/8WWFV62pBpOUds AJqg0p+iUB7biSgnFFjEq5OoimB0DwATXVeyGsmE41AtHNpqjuyX8/tpYBLIKZNNpbQp oI6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=wcsiyFdNFlbE2rwHs7o7QvxeNqnz8T+pUXB7pzwL5zw=; b=HZoMpn2fuPObJDWaMNHTFhomF1fArD/eRj+6ipSk7wmhfIqdjb4ZOs0V3wi/X2phXA jSU5R2Ygb7Jr2bRxWZ6gfEuuDNRvmgYyuN0S3LnGptcmUlJ5e+0m14l3X/6HzXZVHqvf hHilefO7GAnTic+LnGprQancR5RYLolYOduAM2GBFYI5DDEAkpUJ5BE5Ux1bMzSoTaQw jm+iFTv3No7VucYDttud/9DOu3BUv/ATD+EyCxuQBDVoWLij0fL8qvODGAMMOnns7jvl o+tCl+XtoMiL2SvhXJP9F5Ves/TZfx0nYS3CU00LPJJMl4ZUr3YEvczJIKGDsNAEjjwZ Z1tQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=HtL3JWOJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g14-20020a1709065d0e00b007276779b9dfsi4804538ejt.599.2022.07.15.07.17.26; Fri, 15 Jul 2022 07:17:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=HtL3JWOJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231966AbiGON7a (ORCPT + 99 others); Fri, 15 Jul 2022 09:59:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235006AbiGON7S (ORCPT ); Fri, 15 Jul 2022 09:59:18 -0400 Received: from mail-oa1-x2d.google.com (mail-oa1-x2d.google.com [IPv6:2001:4860:4864:20::2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF1C32AF0 for ; Fri, 15 Jul 2022 06:59:16 -0700 (PDT) Received: by mail-oa1-x2d.google.com with SMTP id 586e51a60fabf-fe023ab520so6268695fac.10 for ; Fri, 15 Jul 2022 06:59:16 -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=wcsiyFdNFlbE2rwHs7o7QvxeNqnz8T+pUXB7pzwL5zw=; b=HtL3JWOJOghzPqgLPB7YqHgA2lckvHP41fn/FCQZM8i011Y+6JWlkGM9nBv8NJvuya I+4qWfkE6/iIRdKoOTEJQ6YpTJYPyfVT4+xw/CWNNl/vAUd1m2YgEI1q4EOP97BaRoRQ QyRM1pUwmCrI9FMKqk2ZD5mJFuzkR7MAD2/nQLpMwcz5yR7Y0NjqEiZADEcyN46BHxe7 PHD+44GBS1HVr+jboVL3Egb7fMAz64mWyw92QlwNCKeIXr43kiIRWxrbrghl8NQcFCJH Wdsw+7VIQmesZZcJHDxuZdoBMNQ9zSIozirctEKwX6C7rhLkSHrs2ZSR1XJqxtFeuWyz HlqA== 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=wcsiyFdNFlbE2rwHs7o7QvxeNqnz8T+pUXB7pzwL5zw=; b=ZJxBS+K6Ao0zbT4rXZ4hdv2+br+mz4fTK+40XjKEXLgSuiGqr8GLtBQw9rU0dsMdkB pTYibAW+R1sCvCXnVWaWlRkA6kaJHdltHfBWKv+xGeq30frCC41pTakg1APnS0lFGyvs VhvEKwZFgz+smslsnbJqJ0rCciqLG9dKzXUJCPjsI+X1zDYQrj9KlLwsrvqK7V2/NUxN dnVfY86r3xju0kngO4tD4xZ3ZYJlQmZw6Z8M8YZvYSN7cUER0k3+NxYS2MotrZN7Wy4n 5R5XNf4ND4Rh2ckIf879KoPi/+Fi2svuhwFjaxSw0awPN9zZMZIFKNfosRRJu9VE9hZd XDRg== X-Gm-Message-State: AJIora8l+NNyqkJ9D0udvAzdeQnzGyJlYbk9x4vqG5IyLrV/5UL0/Zhi piWlAAmNJrUm6CNzlAVGOWYHSJSoROXexmauG9L82w== X-Received: by 2002:a05:6871:890:b0:10b:f3eb:b45d with SMTP id r16-20020a056871089000b0010bf3ebb45dmr7916926oaq.294.1657893555927; Fri, 15 Jul 2022 06:59:15 -0700 (PDT) MIME-Version: 1.0 References: <20220715061027.1612149-1-kaleshsingh@google.com> <20220715061027.1612149-4-kaleshsingh@google.com> In-Reply-To: <20220715061027.1612149-4-kaleshsingh@google.com> From: Fuad Tabba Date: Fri, 15 Jul 2022 14:58:40 +0100 Message-ID: Subject: Re: [PATCH v4 03/18] arm64: stacktrace: Factor out unwind_next_common() 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 Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_FILL_THIS_FORM_SHORT,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Kalesh, On Fri, Jul 15, 2022 at 7:11 AM Kalesh Singh wrote: > > Move common unwind_next logic to stacktrace/common.h. This allows > reusing the code in the implementation the nVHE hypervisor stack > unwinder, later in this series. > > Signed-off-by: Kalesh Singh Reviewed-by: Fuad Tabba Thanks, /fuad > --- > arch/arm64/include/asm/stacktrace/common.h | 50 ++++++++++++++++++++++ > arch/arm64/kernel/stacktrace.c | 41 ++---------------- > 2 files changed, 54 insertions(+), 37 deletions(-) > > diff --git a/arch/arm64/include/asm/stacktrace/common.h b/arch/arm64/include/asm/stacktrace/common.h > index f58b786460d3..0c5cbfdb56b5 100644 > --- a/arch/arm64/include/asm/stacktrace/common.h > +++ b/arch/arm64/include/asm/stacktrace/common.h > @@ -65,6 +65,10 @@ struct unwind_state { > static inline bool on_overflow_stack(unsigned long sp, unsigned long size, > struct stack_info *info); > > +static inline bool on_accessible_stack(const struct task_struct *tsk, > + unsigned long sp, unsigned long size, > + struct stack_info *info); > + > 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) > @@ -120,4 +124,50 @@ static inline void unwind_init_common(struct unwind_state *state, > state->prev_type = STACK_TYPE_UNKNOWN; > } > > +static inline int unwind_next_common(struct unwind_state *state, > + struct stack_info *info) > +{ > + struct task_struct *tsk = state->task; > + unsigned long fp = state->fp; > + > + if (fp & 0x7) > + return -EINVAL; > + > + if (!on_accessible_stack(tsk, fp, 16, info)) > + return -EINVAL; > + > + if (test_bit(info->type, state->stacks_done)) > + return -EINVAL; > + > + /* > + * As stacks grow downward, any valid record on the same stack must be > + * at a strictly higher address than the prior record. > + * > + * Stacks can nest in several valid orders, e.g. > + * > + * TASK -> IRQ -> OVERFLOW -> SDEI_NORMAL > + * TASK -> SDEI_NORMAL -> SDEI_CRITICAL -> OVERFLOW > + * > + * ... but the nesting itself is strict. Once we transition from one > + * stack to another, it's never valid to unwind back to that first > + * stack. > + */ > + if (info->type == state->prev_type) { > + if (fp <= state->prev_fp) > + return -EINVAL; > + } else { > + __set_bit(state->prev_type, state->stacks_done); > + } > + > + /* > + * Record this frame record's values and location. The prev_fp and > + * prev_type are only meaningful to the next unwind_next() invocation. > + */ > + state->fp = READ_ONCE(*(unsigned long *)(fp)); > + state->pc = READ_ONCE(*(unsigned long *)(fp + 8)); > + state->prev_fp = fp; > + state->prev_type = info->type; > + > + return 0; > +} > #endif /* __ASM_STACKTRACE_COMMON_H */ > diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c > index 94a5dd2ab8fd..834851939364 100644 > --- a/arch/arm64/kernel/stacktrace.c > +++ b/arch/arm64/kernel/stacktrace.c > @@ -81,48 +81,15 @@ static int notrace unwind_next(struct unwind_state *state) > struct task_struct *tsk = state->task; > unsigned long fp = state->fp; > struct stack_info info; > + int err; > > /* Final frame; nothing to unwind */ > if (fp == (unsigned long)task_pt_regs(tsk)->stackframe) > return -ENOENT; > > - if (fp & 0x7) > - return -EINVAL; > - > - if (!on_accessible_stack(tsk, fp, 16, &info)) > - return -EINVAL; > - > - if (test_bit(info.type, state->stacks_done)) > - return -EINVAL; > - > - /* > - * As stacks grow downward, any valid record on the same stack must be > - * at a strictly higher address than the prior record. > - * > - * Stacks can nest in several valid orders, e.g. > - * > - * TASK -> IRQ -> OVERFLOW -> SDEI_NORMAL > - * TASK -> SDEI_NORMAL -> SDEI_CRITICAL -> OVERFLOW > - * > - * ... but the nesting itself is strict. Once we transition from one > - * stack to another, it's never valid to unwind back to that first > - * stack. > - */ > - if (info.type == state->prev_type) { > - if (fp <= state->prev_fp) > - return -EINVAL; > - } else { > - __set_bit(state->prev_type, state->stacks_done); > - } > - > - /* > - * Record this frame record's values and location. The prev_fp and > - * prev_type are only meaningful to the next unwind_next() invocation. > - */ > - state->fp = READ_ONCE(*(unsigned long *)(fp)); > - state->pc = READ_ONCE(*(unsigned long *)(fp + 8)); > - state->prev_fp = fp; > - state->prev_type = info.type; > + err = unwind_next_common(state, &info); > + if (err) > + return err; > > state->pc = ptrauth_strip_insn_pac(state->pc); > > -- > 2.37.0.170.g444d1eabd0-goog >