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 ADC70C433FE for ; Sun, 6 Feb 2022 17:33:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344384AbiBFRc7 (ORCPT ); Sun, 6 Feb 2022 12:32:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344299AbiBFRc4 (ORCPT ); Sun, 6 Feb 2022 12:32:56 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6C6EC043184 for ; Sun, 6 Feb 2022 09:32:55 -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 ams.source.kernel.org (Postfix) with ESMTPS id 0A33BB80D85 for ; Sun, 6 Feb 2022 17:32:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4B702C340E9; Sun, 6 Feb 2022 17:32:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1644168771; bh=gMzTBBMdtxGO63UBF7sMhkDOFkmpPJGG4DrBI60H7XI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ZpHsZnKDuay4orHTkL7iABQfZys5FNg9nzVBH9pWshMv7m2AbhzsUSXjrJpMT5xOR Z600e1yOGAqURhfOtuaGsUk7BSufjfeOSZ+3IW1hdzYYmNdieE7+FRajsEuzRrrrrA BAElRv7ZKCB1T1nD3mhmHYUvf3CuxapODK3fBN4wrmmGWUBM0KhLaCo3z/IeNLQFrS ZZ6t0TCpOzmoU5mxUjovXZOeIQvMgEi5V8pIRkQ/nhJOmekxHIoQj4c78dv3vURQ7T pAxfFlvWdZwo2UoWbeAhPYy9SlFU/5y5KysxAfSwsqfgKCTQUZCjp9bEDUk6qoUb2h u0tA8ieFfbQzA== Date: Mon, 7 Feb 2022 01:25:03 +0800 From: Jisheng Zhang To: Changbin Du Cc: Paul Walmsley , Palmer Dabbelt , Albert Ou , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] riscv: fix oops caused by irq on/off tracer Message-ID: References: <20220129004226.32868-1-changbin.du@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20220129004226.32868-1-changbin.du@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Jan 29, 2022 at 08:42:26AM +0800, Changbin Du wrote: > The trace_hardirqs_on/off requires at least two parent call frames. > If not, the code generated by CALLER_ADDR1 (aka. ftrace_return_address(1)) > could trigger memory access fault. > > [ 0.039615][ T0] Unable to handle kernel NULL pointer dereference at virtual address 00000000000000f8 > [ 0.041925][ T0] Oops [#1] > [ 0.042063][ T0] Modules linked in: > [ 0.042864][ T0] CPU: 0 PID: 0 Comm: swapper/0 Not tainted 5.17.0-rc1-00233-g9a20c48d1ed2 #29 > [ 0.043568][ T0] Hardware name: riscv-virtio,qemu (DT) > [ 0.044343][ T0] epc : trace_hardirqs_on+0x56/0xe2 > [ 0.044601][ T0] ra : restore_all+0x12/0x6e > [ 0.044721][ T0] epc : ffffffff80126a5c ra : ffffffff80003b94 sp : ffffffff81403db0 > [ 0.044801][ T0] gp : ffffffff8163acd8 tp : ffffffff81414880 t0 : 0000000000000020 > [ 0.044882][ T0] t1 : 0098968000000000 t2 : 0000000000000000 s0 : ffffffff81403de0 > [ 0.044967][ T0] s1 : 0000000000000000 a0 : 0000000000000001 a1 : 0000000000000100 > [ 0.045046][ T0] a2 : 0000000000000000 a3 : 0000000000000000 a4 : 0000000000000000 > [ 0.045124][ T0] a5 : 0000000000000000 a6 : 0000000000000000 a7 : 0000000054494d45 > [ 0.045210][ T0] s2 : ffffffff80003b94 s3 : ffffffff81a8f1b0 s4 : ffffffff80e27b50 > [ 0.045289][ T0] s5 : ffffffff81414880 s6 : ffffffff8160fa00 s7 : 00000000800120e8 > [ 0.045389][ T0] s8 : 0000000080013100 s9 : 000000000000007f s10: 0000000000000000 > [ 0.045474][ T0] s11: 0000000000000000 t3 : 7fffffffffffffff t4 : 0000000000000000 > [ 0.045548][ T0] t5 : 0000000000000000 t6 : ffffffff814aa368 > [ 0.045620][ T0] status: 0000000200000100 badaddr: 00000000000000f8 cause: 000000000000000d > [ 0.046402][ T0] [] restore_all+0x12/0x6e > Hi Changbin, Could you please provide the reproduce steps? It looks a bit interesting. > To fix above issue, here we add one extra level wrapper so they can be > safely called by low level entry code. > > Signed-off-by: Changbin Du > > --- > v2: fix compile warning. > --- > arch/riscv/kernel/Makefile | 2 ++ > arch/riscv/kernel/entry.S | 10 +++++----- > arch/riscv/kernel/trace_irq.c | 26 ++++++++++++++++++++++++++ > arch/riscv/kernel/trace_irq.h | 11 +++++++++++ > 4 files changed, 44 insertions(+), 5 deletions(-) > create mode 100644 arch/riscv/kernel/trace_irq.c > create mode 100644 arch/riscv/kernel/trace_irq.h > > diff --git a/arch/riscv/kernel/Makefile b/arch/riscv/kernel/Makefile > index 612556faa527..ffc87e76b1dd 100644 > --- a/arch/riscv/kernel/Makefile > +++ b/arch/riscv/kernel/Makefile > @@ -51,6 +51,8 @@ obj-$(CONFIG_MODULE_SECTIONS) += module-sections.o > obj-$(CONFIG_FUNCTION_TRACER) += mcount.o ftrace.o > obj-$(CONFIG_DYNAMIC_FTRACE) += mcount-dyn.o > > +obj-$(CONFIG_TRACE_IRQFLAGS) += trace_irq.o > + > obj-$(CONFIG_RISCV_BASE_PMU) += perf_event.o > obj-$(CONFIG_PERF_EVENTS) += perf_callchain.o > obj-$(CONFIG_HAVE_PERF_REGS) += perf_regs.o > diff --git a/arch/riscv/kernel/entry.S b/arch/riscv/kernel/entry.S > index ed29e9c8f660..d6a46ed0bf05 100644 > --- a/arch/riscv/kernel/entry.S > +++ b/arch/riscv/kernel/entry.S > @@ -108,7 +108,7 @@ _save_context: > .option pop > > #ifdef CONFIG_TRACE_IRQFLAGS > - call trace_hardirqs_off > + call __trace_hardirqs_off > #endif > > #ifdef CONFIG_CONTEXT_TRACKING > @@ -143,7 +143,7 @@ skip_context_tracking: > li t0, EXC_BREAKPOINT > beq s4, t0, 1f > #ifdef CONFIG_TRACE_IRQFLAGS > - call trace_hardirqs_on > + call __trace_hardirqs_on > #endif > csrs CSR_STATUS, SR_IE > > @@ -234,7 +234,7 @@ ret_from_exception: > REG_L s0, PT_STATUS(sp) > csrc CSR_STATUS, SR_IE > #ifdef CONFIG_TRACE_IRQFLAGS > - call trace_hardirqs_off > + call __trace_hardirqs_off > #endif > #ifdef CONFIG_RISCV_M_MODE > /* the MPP value is too large to be used as an immediate arg for addi */ > @@ -270,10 +270,10 @@ restore_all: > REG_L s1, PT_STATUS(sp) > andi t0, s1, SR_PIE > beqz t0, 1f > - call trace_hardirqs_on > + call __trace_hardirqs_on > j 2f > 1: > - call trace_hardirqs_off > + call __trace_hardirqs_off > 2: > #endif > REG_L a0, PT_STATUS(sp) > diff --git a/arch/riscv/kernel/trace_irq.c b/arch/riscv/kernel/trace_irq.c > new file mode 100644 > index 000000000000..fc194c56a35d > --- /dev/null > +++ b/arch/riscv/kernel/trace_irq.c > @@ -0,0 +1,26 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * Copyright (C) 2022 Changbin Du > + */ > + > +#include > +#include > +#include "trace_irq.h" > + > +/** > + * trace_hardirqs_on/off requires at least two parent call frames. > + * Here we add one extra level so they can be safely called by low > + * level entry code. > + */ Hmm, I believe there's elegant solution without this grue, maybe fix in stacktrace implementation or something else? > + > +void __trace_hardirqs_on(void) > +{ > + trace_hardirqs_on(); > +} > +NOKPROBE_SYMBOL(__trace_hardirqs_on); > + > +void __trace_hardirqs_off(void) > +{ > + trace_hardirqs_off(); > +} > +NOKPROBE_SYMBOL(__trace_hardirqs_off); > diff --git a/arch/riscv/kernel/trace_irq.h b/arch/riscv/kernel/trace_irq.h > new file mode 100644 > index 000000000000..99fe67377e5e > --- /dev/null > +++ b/arch/riscv/kernel/trace_irq.h > @@ -0,0 +1,11 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +/* > + * Copyright (C) 2022 Changbin Du > + */ > +#ifndef __TRACE_IRQ_H > +#define __TRACE_IRQ_H > + > +void __trace_hardirqs_on(void); > +void __trace_hardirqs_off(void); > + > +#endif /* __TRACE_IRQ_H */ > -- > 2.32.0 > > > _______________________________________________ > linux-riscv mailing list > linux-riscv@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-riscv 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 C3CBEC433F5 for ; Sun, 6 Feb 2022 17:33:14 +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=A8VhqJ1sEXSU6VJQmjCQ5fiR1XGk43AWWVEovQhq/jY=; b=oyTH8HZk3fE133 PXQ896s4e1KUUYibAEjO3QgJXuXt7DodkeeXFBQSfrY0Iq9DH3suhFSulLVJ9TA701cRVct/KL8t1 X3N3cLCK7OVD3PWTYIFnje9bkpvP7O7CWKQApKqKMlvwN1CF8oWN8CPsxKFOyj8xbtEYrQrZpcjQ0 cmjKz3SaDyjQ38Qbqk+7D/8/qD9OWprif3y3JLH/Fzv06yc3sNE7CkAa7mZsS7gRD7c4RlWMTc+f4 AOBA5fSiXlEtmZF3GmxUF8A1iKpf0tSoBEU1EUnY0wIlwfmiIUxq8Oz6th0G5DB0cXQdVQB9kpxwB HkS2dlEpwtPUsKjatiXQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nGlPE-008TGp-1P; Sun, 06 Feb 2022 17:32:56 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nGlPB-008TGV-I4 for linux-riscv@lists.infradead.org; Sun, 06 Feb 2022 17:32:55 +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 5BDA2611D6; Sun, 6 Feb 2022 17:32:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4B702C340E9; Sun, 6 Feb 2022 17:32:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1644168771; bh=gMzTBBMdtxGO63UBF7sMhkDOFkmpPJGG4DrBI60H7XI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ZpHsZnKDuay4orHTkL7iABQfZys5FNg9nzVBH9pWshMv7m2AbhzsUSXjrJpMT5xOR Z600e1yOGAqURhfOtuaGsUk7BSufjfeOSZ+3IW1hdzYYmNdieE7+FRajsEuzRrrrrA BAElRv7ZKCB1T1nD3mhmHYUvf3CuxapODK3fBN4wrmmGWUBM0KhLaCo3z/IeNLQFrS ZZ6t0TCpOzmoU5mxUjovXZOeIQvMgEi5V8pIRkQ/nhJOmekxHIoQj4c78dv3vURQ7T pAxfFlvWdZwo2UoWbeAhPYy9SlFU/5y5KysxAfSwsqfgKCTQUZCjp9bEDUk6qoUb2h u0tA8ieFfbQzA== Date: Mon, 7 Feb 2022 01:25:03 +0800 From: Jisheng Zhang To: Changbin Du Cc: Paul Walmsley , Palmer Dabbelt , Albert Ou , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] riscv: fix oops caused by irq on/off tracer Message-ID: References: <20220129004226.32868-1-changbin.du@gmail.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20220129004226.32868-1-changbin.du@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220206_093253_729261_1DA2C5FD X-CRM114-Status: GOOD ( 23.78 ) X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org On Sat, Jan 29, 2022 at 08:42:26AM +0800, Changbin Du wrote: > The trace_hardirqs_on/off requires at least two parent call frames. > If not, the code generated by CALLER_ADDR1 (aka. ftrace_return_address(1)) > could trigger memory access fault. > > [ 0.039615][ T0] Unable to handle kernel NULL pointer dereference at virtual address 00000000000000f8 > [ 0.041925][ T0] Oops [#1] > [ 0.042063][ T0] Modules linked in: > [ 0.042864][ T0] CPU: 0 PID: 0 Comm: swapper/0 Not tainted 5.17.0-rc1-00233-g9a20c48d1ed2 #29 > [ 0.043568][ T0] Hardware name: riscv-virtio,qemu (DT) > [ 0.044343][ T0] epc : trace_hardirqs_on+0x56/0xe2 > [ 0.044601][ T0] ra : restore_all+0x12/0x6e > [ 0.044721][ T0] epc : ffffffff80126a5c ra : ffffffff80003b94 sp : ffffffff81403db0 > [ 0.044801][ T0] gp : ffffffff8163acd8 tp : ffffffff81414880 t0 : 0000000000000020 > [ 0.044882][ T0] t1 : 0098968000000000 t2 : 0000000000000000 s0 : ffffffff81403de0 > [ 0.044967][ T0] s1 : 0000000000000000 a0 : 0000000000000001 a1 : 0000000000000100 > [ 0.045046][ T0] a2 : 0000000000000000 a3 : 0000000000000000 a4 : 0000000000000000 > [ 0.045124][ T0] a5 : 0000000000000000 a6 : 0000000000000000 a7 : 0000000054494d45 > [ 0.045210][ T0] s2 : ffffffff80003b94 s3 : ffffffff81a8f1b0 s4 : ffffffff80e27b50 > [ 0.045289][ T0] s5 : ffffffff81414880 s6 : ffffffff8160fa00 s7 : 00000000800120e8 > [ 0.045389][ T0] s8 : 0000000080013100 s9 : 000000000000007f s10: 0000000000000000 > [ 0.045474][ T0] s11: 0000000000000000 t3 : 7fffffffffffffff t4 : 0000000000000000 > [ 0.045548][ T0] t5 : 0000000000000000 t6 : ffffffff814aa368 > [ 0.045620][ T0] status: 0000000200000100 badaddr: 00000000000000f8 cause: 000000000000000d > [ 0.046402][ T0] [] restore_all+0x12/0x6e > Hi Changbin, Could you please provide the reproduce steps? It looks a bit interesting. > To fix above issue, here we add one extra level wrapper so they can be > safely called by low level entry code. > > Signed-off-by: Changbin Du > > --- > v2: fix compile warning. > --- > arch/riscv/kernel/Makefile | 2 ++ > arch/riscv/kernel/entry.S | 10 +++++----- > arch/riscv/kernel/trace_irq.c | 26 ++++++++++++++++++++++++++ > arch/riscv/kernel/trace_irq.h | 11 +++++++++++ > 4 files changed, 44 insertions(+), 5 deletions(-) > create mode 100644 arch/riscv/kernel/trace_irq.c > create mode 100644 arch/riscv/kernel/trace_irq.h > > diff --git a/arch/riscv/kernel/Makefile b/arch/riscv/kernel/Makefile > index 612556faa527..ffc87e76b1dd 100644 > --- a/arch/riscv/kernel/Makefile > +++ b/arch/riscv/kernel/Makefile > @@ -51,6 +51,8 @@ obj-$(CONFIG_MODULE_SECTIONS) += module-sections.o > obj-$(CONFIG_FUNCTION_TRACER) += mcount.o ftrace.o > obj-$(CONFIG_DYNAMIC_FTRACE) += mcount-dyn.o > > +obj-$(CONFIG_TRACE_IRQFLAGS) += trace_irq.o > + > obj-$(CONFIG_RISCV_BASE_PMU) += perf_event.o > obj-$(CONFIG_PERF_EVENTS) += perf_callchain.o > obj-$(CONFIG_HAVE_PERF_REGS) += perf_regs.o > diff --git a/arch/riscv/kernel/entry.S b/arch/riscv/kernel/entry.S > index ed29e9c8f660..d6a46ed0bf05 100644 > --- a/arch/riscv/kernel/entry.S > +++ b/arch/riscv/kernel/entry.S > @@ -108,7 +108,7 @@ _save_context: > .option pop > > #ifdef CONFIG_TRACE_IRQFLAGS > - call trace_hardirqs_off > + call __trace_hardirqs_off > #endif > > #ifdef CONFIG_CONTEXT_TRACKING > @@ -143,7 +143,7 @@ skip_context_tracking: > li t0, EXC_BREAKPOINT > beq s4, t0, 1f > #ifdef CONFIG_TRACE_IRQFLAGS > - call trace_hardirqs_on > + call __trace_hardirqs_on > #endif > csrs CSR_STATUS, SR_IE > > @@ -234,7 +234,7 @@ ret_from_exception: > REG_L s0, PT_STATUS(sp) > csrc CSR_STATUS, SR_IE > #ifdef CONFIG_TRACE_IRQFLAGS > - call trace_hardirqs_off > + call __trace_hardirqs_off > #endif > #ifdef CONFIG_RISCV_M_MODE > /* the MPP value is too large to be used as an immediate arg for addi */ > @@ -270,10 +270,10 @@ restore_all: > REG_L s1, PT_STATUS(sp) > andi t0, s1, SR_PIE > beqz t0, 1f > - call trace_hardirqs_on > + call __trace_hardirqs_on > j 2f > 1: > - call trace_hardirqs_off > + call __trace_hardirqs_off > 2: > #endif > REG_L a0, PT_STATUS(sp) > diff --git a/arch/riscv/kernel/trace_irq.c b/arch/riscv/kernel/trace_irq.c > new file mode 100644 > index 000000000000..fc194c56a35d > --- /dev/null > +++ b/arch/riscv/kernel/trace_irq.c > @@ -0,0 +1,26 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * Copyright (C) 2022 Changbin Du > + */ > + > +#include > +#include > +#include "trace_irq.h" > + > +/** > + * trace_hardirqs_on/off requires at least two parent call frames. > + * Here we add one extra level so they can be safely called by low > + * level entry code. > + */ Hmm, I believe there's elegant solution without this grue, maybe fix in stacktrace implementation or something else? > + > +void __trace_hardirqs_on(void) > +{ > + trace_hardirqs_on(); > +} > +NOKPROBE_SYMBOL(__trace_hardirqs_on); > + > +void __trace_hardirqs_off(void) > +{ > + trace_hardirqs_off(); > +} > +NOKPROBE_SYMBOL(__trace_hardirqs_off); > diff --git a/arch/riscv/kernel/trace_irq.h b/arch/riscv/kernel/trace_irq.h > new file mode 100644 > index 000000000000..99fe67377e5e > --- /dev/null > +++ b/arch/riscv/kernel/trace_irq.h > @@ -0,0 +1,11 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +/* > + * Copyright (C) 2022 Changbin Du > + */ > +#ifndef __TRACE_IRQ_H > +#define __TRACE_IRQ_H > + > +void __trace_hardirqs_on(void); > +void __trace_hardirqs_off(void); > + > +#endif /* __TRACE_IRQ_H */ > -- > 2.32.0 > > > _______________________________________________ > linux-riscv mailing list > linux-riscv@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-riscv _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv