Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp6860705rwb; Mon, 5 Dec 2022 19:50:48 -0800 (PST) X-Google-Smtp-Source: AA0mqf4wxOPwNpCdwvVTJZRp1YaZVzz3JAI7OVvrB0dfFwOEDx3SgMwmpV3wH/Ur/su01sIdiwMj X-Received: by 2002:a17:906:94c1:b0:7c0:68c8:19db with SMTP id d1-20020a17090694c100b007c068c819dbmr30976670ejy.485.1670298648511; Mon, 05 Dec 2022 19:50:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670298648; cv=none; d=google.com; s=arc-20160816; b=sZSLI4wcwB/M9bm57B4tb0Hcp4WLe5XJYvY9kbZiMmJRD5+sDpMRAF1wMmFwV1lgs1 4jAzAY7S/TOrWJJDj/PjNLv5F56MaI0ouzBDESCsNlPvAo/BtjNDfBGoDHEJ6L4vFo7R eMklXi8MZPmRFYaKKPyXoUE+Tb4pFw5stw8qCnD/3bc43WC+JahXLb+GEVryVHXOGsVl d5RoeYmNI8nh/8e+q760K2iIgJOmbgdePaaUSC8tbMEP9zhU7hpujYDmA0cU2Am8JyUw lZIVt8iD7ADnNRooqmw9Sqj1jDMwJQGhkSTW0mRxMHJQGP4h8I4YWnDNcDC5NhIFC2BM O6ww== 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=fuR8wEe0Qxx+ronQoWcBR+loWTFwlLJK4pa+nqETegc=; b=SIkG8672waZZM9ce78dgjb8dB1w2bMfUYQWZska/lZAlzTXqeZxMkIyFakHXH7taYA 7kqEpFfccgrPP03f4ZWDKRH1hqAJvZaHdnL42IIquVxRadHAUjfxFyn72AfE3Rs8OFYf AUoAUrBrLx2yDASEJiZxMgvrmC/Vp+2PQwkLB6JJzfSRQK1Rj5aOb6Sv4WJkiafGmt/Y Ahhsd1Cg5jgbmsCKlzZoSiV7UdUbRf0H1V2nNv0LZjoABUlHMRDZe5GqX/kpv5ZVVJ6i ByN1UvdgWeVRhocib8pgROJyI500NoTfpffHObH0HH1PSszqiGK5Anls+T0NhBZ2Ny6i 2Pew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=vLH2LVEk; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id rh16-20020a17090720f000b007c080b02137si10823921ejb.932.2022.12.05.19.50.29; Mon, 05 Dec 2022 19:50:48 -0800 (PST) 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=@kernel.org header.s=k20201202 header.b=vLH2LVEk; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233499AbiLFDbP (ORCPT + 79 others); Mon, 5 Dec 2022 22:31:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231756AbiLFDbM (ORCPT ); Mon, 5 Dec 2022 22:31:12 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB03E2529D; Mon, 5 Dec 2022 19:31:11 -0800 (PST) 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 66E0161544; Tue, 6 Dec 2022 03:31:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BEA1EC4314C; Tue, 6 Dec 2022 03:31:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1670297470; bh=WTSRU6KLdB/pQeJp68FTfceCK6cjixmp3Lyduir0Gs4=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=vLH2LVEkHwJsBPC1GJMcIr41vD1EW94svc9hSWdIdm1ftg7csd8xM57DLRGB0lZNh BVNYRTeDp8xBod7ZnBTDHfMU6oZN22cABGRjp7sbYFX5NAqRPileMx3tJY+3+ghror NYng5uDND0otXNHw6hQ6ifHJFBdlPbkhb3cekluzKy5VyXB8lxcyVb+DtcKC5ZOfx5 TBc7e+8BmE3YdcEIxNuhUiCjndrg8MoC3tNj973km5xC6TfzyHLQpYjt12rc4wRbpN KOCiC9CSsNCyy2+jc7fMy6ngpb22AY0hoHtcsB4lDl32O4SzC+ta9nW2LAum0cmQst Lz3B4qSAt95tQ== Received: by mail-ej1-f52.google.com with SMTP id x22so3070033ejs.11; Mon, 05 Dec 2022 19:31:10 -0800 (PST) X-Gm-Message-State: ANoB5pk9hVHgjyiwq+DExM7yFX+e03F9SJDCMwCEpeh9JgPIwRwkvpr3 TPjiy1R0nFR/fyLxOYiyY1O+JWEnfDUHpf+UAKE= X-Received: by 2002:a17:906:1e4a:b0:78d:3505:6f3e with SMTP id i10-20020a1709061e4a00b0078d35056f3emr69420048ejj.611.1670297468584; Mon, 05 Dec 2022 19:31:08 -0800 (PST) MIME-Version: 1.0 References: <20221109064937.3643993-3-guoren@kernel.org> In-Reply-To: From: Guo Ren Date: Tue, 6 Dec 2022 11:30:56 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 2/2] riscv: stacktrace: Make walk_stackframe cross pt_regs frame To: Palmer Dabbelt Cc: anup@brainfault.org, Paul Walmsley , Conor Dooley , heiko@sntech.de, peterz@infradead.org, Arnd Bergmann , linux-arch@vger.kernel.org, keescook@chromium.org, paulmck@kernel.org, frederic@kernel.org, nsaenzju@redhat.com, changbin.du@intel.com, vincent.chen@sifive.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, guoren@linux.alibaba.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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 On Tue, Dec 6, 2022 at 10:59 AM Palmer Dabbelt wrote: > > On Tue, 08 Nov 2022 22:49:37 PST (-0800), guoren@kernel.org wrote: > > From: Guo Ren > > > > The current walk_stackframe with FRAME_POINTER would stop unwinding at > > ret_from_exception: > > BUG: sleeping function called from invalid context at kernel/locking/rwsem.c:1518 > > in_atomic(): 0, irqs_disabled(): 1, non_block: 0, pid: 1, name: init > > CPU: 0 PID: 1 Comm: init Not tainted 5.10.113-00021-g15c15974895c-dirty #192 > > Call Trace: > > [] walk_stackframe+0x0/0xee > > [] show_stack+0x32/0x4a > > [] dump_stack_lvl+0x72/0x8e > > [] dump_stack+0x14/0x1c > > [] ___might_sleep+0x12e/0x138 > > [] __might_sleep+0x10/0x18 > > [] down_read+0x22/0xa4 > > [] do_page_fault+0xb0/0x2fe > > [] ret_from_exception+0x0/0xc > > > > The optimization would help walk_stackframe cross the pt_regs frame and > > get more backtrace of debug info: > > BUG: sleeping function called from invalid context at kernel/locking/rwsem.c:1518 > > in_atomic(): 0, irqs_disabled(): 1, non_block: 0, pid: 1, name: init > > CPU: 0 PID: 1 Comm: init Not tainted 5.10.113-00021-g15c15974895c-dirty #192 > > Call Trace: > > [] walk_stackframe+0x0/0xee > > [] show_stack+0x32/0x4a > > [] dump_stack_lvl+0x72/0x8e > > [] dump_stack+0x14/0x1c > > [] ___might_sleep+0x12e/0x138 > > [] __might_sleep+0x10/0x18 > > [] down_read+0x22/0xa4 > > [] do_page_fault+0xb0/0x2fe > > [] ret_from_exception+0x0/0xc > > [] riscv_intc_irq+0x1a/0x72 > > [] ret_from_exception+0x0/0xc > > [] vma_link+0x54/0x160 > > [] mmap_region+0x2cc/0x4d0 > > [] do_mmap+0x2d8/0x3ac > > [] vm_mmap_pgoff+0x70/0xb8 > > [] vm_mmap+0x2a/0x36 > > [] elf_map+0x72/0x84 > > [] load_elf_binary+0x69a/0xec8 > > [] bprm_execve+0x246/0x53a > > [] kernel_execve+0xe8/0x124 > > [] run_init_process+0xfa/0x10c > > [] try_to_run_init_process+0x12/0x3c > > [] kernel_init+0xb4/0xf8 > > [] ret_from_exception+0x0/0xc > > > > Here is the error injection test code for the above output: > > drivers/irqchip/irq-riscv-intc.c: > > static asmlinkage void riscv_intc_irq(struct pt_regs *regs) > > { > > unsigned long cause = regs->cause & ~CAUSE_IRQ_FLAG; > > + u32 tmp; __get_user(tmp, (u32 *)0); > > > > Signed-off-by: Guo Ren > > Signed-off-by: Guo Ren > > Cc: Palmer Dabbelt > > Cc: Changbin Du > > --- > > arch/riscv/kernel/entry.S | 2 +- > > arch/riscv/kernel/stacktrace.c | 9 +++++++++ > > 2 files changed, 10 insertions(+), 1 deletion(-) > > > > diff --git a/arch/riscv/kernel/entry.S b/arch/riscv/kernel/entry.S > > index b9eda3fcbd6d..329cf51fcd4d 100644 > > --- a/arch/riscv/kernel/entry.S > > +++ b/arch/riscv/kernel/entry.S > > @@ -248,7 +248,7 @@ ret_from_syscall_rejected: > > andi t0, t0, _TIF_SYSCALL_WORK > > bnez t0, handle_syscall_trace_exit > > > > -ret_from_exception: > > +ENTRY(ret_from_exception) > > This at least needs an END(), but it should also be converted over to Yes, I missed END() here. > some non-function entry flavor. I converted it over to > SYM_CODE_START_NOALIGN(), with the cooresponding SYM_CODE_END(), and put > it on for-next. Is that also for ret_from_fork & __switch_to? > > > REG_L s0, PT_STATUS(sp) > > csrc CSR_STATUS, SR_IE > > #ifdef CONFIG_TRACE_IRQFLAGS > > diff --git a/arch/riscv/kernel/stacktrace.c b/arch/riscv/kernel/stacktrace.c > > index bcfe9eb55f80..75c8dd64fc48 100644 > > --- a/arch/riscv/kernel/stacktrace.c > > +++ b/arch/riscv/kernel/stacktrace.c > > @@ -16,6 +16,8 @@ > > > > #ifdef CONFIG_FRAME_POINTER > > > > +extern asmlinkage void ret_from_exception(void); > > + > > void notrace walk_stackframe(struct task_struct *task, struct pt_regs *regs, > > bool (*fn)(void *, unsigned long), void *arg) > > { > > @@ -59,6 +61,13 @@ void notrace walk_stackframe(struct task_struct *task, struct pt_regs *regs, > > fp = frame->fp; > > pc = ftrace_graph_ret_addr(current, NULL, frame->ra, > > &frame->ra); > > + if (pc == (unsigned long)ret_from_exception) { > > + if (unlikely(!__kernel_text_address(pc) || !fn(arg, pc))) > > + break; > > + > > + pc = ((struct pt_regs *)sp)->epc; > > + fp = ((struct pt_regs *)sp)->s0; > > + } > > } > > > > } -- Best Regards Guo Ren