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 963B4C433FE for ; Fri, 30 Sep 2022 12:28:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230318AbiI3M2R (ORCPT ); Fri, 30 Sep 2022 08:28:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229646AbiI3M2O (ORCPT ); Fri, 30 Sep 2022 08:28:14 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5FDF154448; Fri, 30 Sep 2022 05:28:12 -0700 (PDT) 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 8450AB828AC; Fri, 30 Sep 2022 12:28:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3C4C7C433C1; Fri, 30 Sep 2022 12:28:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1664540890; bh=/4ALUwugj3Gl5x22JbGPmpfNQMZMiRVYjPgXy1gPB00=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=oeFdDAQgFqpzjqRJzGKF+vIiAZAHQfulVNWlmMVMwAHj2u0REi2V5iu9vb+qElzKT smZrXJfoLoerUKwI6og+0fc/EjVTTODG1591hPIpDkikZvUpPaVj/BHp1Bda0a2eSq Vrop+6cUrjHCLuQUNPsgF89atHJ3Xw3EsjWe2aPQQ6QnHzGXHOzz0DwMtFarkV5Ffu 2lJDgkB8X4mJIkGikek60Vgtfa+EyCu2PYNZ4xLnAHle7QO/6Mml7YhbCglGFG+UGt at/il5U5MH5iJK/SaXq/h4hBq7kjdKoNBk+Q00f6GeKNzPxR4cODtau9f+C0ffPdb8 t/beZj1K1hwtA== Received: by mail-oi1-f171.google.com with SMTP id w13so4561778oiw.8; Fri, 30 Sep 2022 05:28:10 -0700 (PDT) X-Gm-Message-State: ACrzQf0t0DMHVQYLuHPLYUzLA+tEURZPCwsS8S5KeP9buglPcpfqH+GJ WJnvK7soL7lBkLxMY3b2WRBDrqhhOYVHbIqxlic= X-Google-Smtp-Source: AMsMyM7AkR4koVBLJ1BpYLj3z3e6TpYzy4iDz1E5xTYn5b1jVTvl8sCipeZ/PTuVCPUM2xxKtW4Q4YOmg6NnPRJ2Hp4= X-Received: by 2002:a05:6808:151f:b0:350:1b5e:2380 with SMTP id u31-20020a056808151f00b003501b5e2380mr9157731oiw.112.1664540889350; Fri, 30 Sep 2022 05:28:09 -0700 (PDT) MIME-Version: 1.0 References: <20220918155246.1203293-1-guoren@kernel.org> <20220918155246.1203293-7-guoren@kernel.org> In-Reply-To: From: Guo Ren Date: Fri, 30 Sep 2022 20:27:57 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH V5 06/11] entry: Prevent DEBUG_PREEMPT warning To: Peter Zijlstra Cc: arnd@arndb.de, palmer@rivosinc.com, tglx@linutronix.de, luto@kernel.org, conor.dooley@microchip.com, heiko@sntech.de, jszhang@kernel.org, lazyparser@gmail.com, falcon@tinylab.org, chenhuacai@kernel.org, apatel@ventanamicro.com, atishp@atishpatra.org, palmer@dabbelt.com, paul.walmsley@sifive.com, mark.rutland@arm.com, zouyipeng@huawei.com, bigeasy@linutronix.de, David.Laight@aculab.com, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, Guo Ren Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 20, 2022 at 9:45 AM Guo Ren wrote: > > On Mon, Sep 19, 2022 at 7:59 PM Peter Zijlstra wrote: > > > > On Sun, Sep 18, 2022 at 11:52:41AM -0400, guoren@kernel.org wrote: > > > From: Guo Ren > > > > > > When DEBUG_PREEMPT=y, > > > exit_to_user_mode_prepare > > > ->tick_nohz_user_enter_prepare > > > ->tick_nohz_full_cpu(smp_processor_id()) > > > ->smp_processor_id() > > > ->debug_smp_processor_id() > > > ->check preempt_count() then: > > > > > > [ 5.717610] BUG: using smp_processor_id() in preemptible [00000000] > > > code: S20urandom/94 > > > [ 5.718111] caller is debug_smp_processor_id+0x24/0x38 > > > [ 5.718417] CPU: 1 PID: 94 Comm: S20urandom Not tainted > > > 6.0.0-rc3-00010-gfd0a0d619c63-dirty #238 > > > [ 5.718886] Hardware name: riscv-virtio,qemu (DT) > > > [ 5.719136] Call Trace: > > > [ 5.719281] [] dump_backtrace+0x2c/0x3c > > > [ 5.719566] [] show_stack+0x44/0x5c > > > [ 5.720023] [] dump_stack_lvl+0x74/0xa4 > > > [ 5.720557] [] dump_stack+0x1c/0x2c > > > [ 5.721033] [] > > > check_preemption_disabled+0x104/0x108 > > > [ 5.721538] [] debug_smp_processor_id+0x24/0x38 > > > [ 5.722001] [] exit_to_user_mode_prepare+0x48/0x178 > > > [ 5.722355] [] irqentry_exit_to_user_mode+0x18/0x30 > > > [ 5.722685] [] irqentry_exit+0x64/0xa4 > > > [ 5.722953] [] do_page_fault+0x1d8/0x544 > > > [ 5.723291] [] ret_from_exception+0x0/0xb8 > > > > > > (Above is found in riscv platform with generic_entry) > > > > > > The smp_processor_id() needs irqs disable or preempt_disable, so use > > > preempt dis/in protecting the tick_nohz_user_enter_prepare(). > > > > > > Signed-off-by: Guo Ren > > > Signed-off-by: Guo Ren > > > --- > > > kernel/entry/common.c | 2 ++ > > > 1 file changed, 2 insertions(+) > > > > > > diff --git a/kernel/entry/common.c b/kernel/entry/common.c > > > index 063068a9ea9b..36e4cd50531c 100644 > > > --- a/kernel/entry/common.c > > > +++ b/kernel/entry/common.c > > > @@ -194,8 +194,10 @@ static void exit_to_user_mode_prepare(struct pt_regs *regs) > > > > > > lockdep_assert_irqs_disabled(); > > > > Observe ^^^^ > Thanks! I would enable PROVE_LOCKING for test. It's my bug in page_fault, here is the solution: @@ -358,6 +358,8 @@ asmlinkage void noinstr do_page_fault(struct pt_regs *regs) __do_page_fault(regs); + local_irq_disable(); + irqentry_exit(regs, state); } NOKPROBE_SYMBOL(do_page_fault); > > > > > > > > > + preempt_disable(); > > > /* Flush pending rcuog wakeup before the last need_resched() check */ > > > tick_nohz_user_enter_prepare(); > > > + preempt_enable(); > > > > This makes no sense; if IRQs are disabled, check_preemption_disabled() > > should bail early per: > > > > if (irqs_disabled()) > > goto out; > Ditto. > > > -- > Best Regards > Guo Ren -- Best Regards Guo Ren 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 EF65DC433FE for ; Fri, 30 Sep 2022 12:28:24 +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=jmJ6ivMEP8WBaK5zroWmdvsl0nSh3stF72uWAOfUHUI=; b=xiP2LD+RdAxxgA K3nnc8eRNvI2741F7rXinWzBbCzxRNZqlMS/Gt6vB2bYdamXUiZZ1u8Mjuef1b1wi3SUUxV3cWvgK PzxBuaa00bIAw6s1gi0cqbYtYel7QWZBqKzI0gvDHDQRQg3ijjyN4Gb0J1fR462X6ClhvcZJlwu89 ENv+J43dS5V/lSlJYteTxvwTOi9pfwTslQT+FSwmm1bAOnOX9MDAkL1ch8BpeKPgZn/Xw8TTjX1YX rP0/Iq6VCaOIfWU4+DTxYXHZZHbPWgn6SIeYfGAlhz8BVFRhxYUX0Tsn+w+4oUpvS9New4Qtn2qEl FMxwJzMYMuyeYGZr7BpA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oeF7p-0099nA-P8; Fri, 30 Sep 2022 12:28:17 +0000 Received: from ams.source.kernel.org ([145.40.68.75]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oeF7m-0099la-7P for linux-riscv@lists.infradead.org; Fri, 30 Sep 2022 12:28:15 +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 ams.source.kernel.org (Postfix) with ESMTPS id D0127B828B2 for ; Fri, 30 Sep 2022 12:28:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6AA11C43148 for ; Fri, 30 Sep 2022 12:28:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1664540890; bh=/4ALUwugj3Gl5x22JbGPmpfNQMZMiRVYjPgXy1gPB00=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=oeFdDAQgFqpzjqRJzGKF+vIiAZAHQfulVNWlmMVMwAHj2u0REi2V5iu9vb+qElzKT smZrXJfoLoerUKwI6og+0fc/EjVTTODG1591hPIpDkikZvUpPaVj/BHp1Bda0a2eSq Vrop+6cUrjHCLuQUNPsgF89atHJ3Xw3EsjWe2aPQQ6QnHzGXHOzz0DwMtFarkV5Ffu 2lJDgkB8X4mJIkGikek60Vgtfa+EyCu2PYNZ4xLnAHle7QO/6Mml7YhbCglGFG+UGt at/il5U5MH5iJK/SaXq/h4hBq7kjdKoNBk+Q00f6GeKNzPxR4cODtau9f+C0ffPdb8 t/beZj1K1hwtA== Received: by mail-oi1-f177.google.com with SMTP id j188so4603808oih.0 for ; Fri, 30 Sep 2022 05:28:10 -0700 (PDT) X-Gm-Message-State: ACrzQf37Xl1Dy9HAKg6gV4yR0gMtbjGsGhiGaNRNC8/nPRHE3NYk8bpI i2SHilQ9q3RcloCz7wi6u/BbYQBocLOjJtD5Z2g= X-Google-Smtp-Source: AMsMyM7AkR4koVBLJ1BpYLj3z3e6TpYzy4iDz1E5xTYn5b1jVTvl8sCipeZ/PTuVCPUM2xxKtW4Q4YOmg6NnPRJ2Hp4= X-Received: by 2002:a05:6808:151f:b0:350:1b5e:2380 with SMTP id u31-20020a056808151f00b003501b5e2380mr9157731oiw.112.1664540889350; Fri, 30 Sep 2022 05:28:09 -0700 (PDT) MIME-Version: 1.0 References: <20220918155246.1203293-1-guoren@kernel.org> <20220918155246.1203293-7-guoren@kernel.org> In-Reply-To: From: Guo Ren Date: Fri, 30 Sep 2022 20:27:57 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH V5 06/11] entry: Prevent DEBUG_PREEMPT warning To: Peter Zijlstra Cc: arnd@arndb.de, palmer@rivosinc.com, tglx@linutronix.de, luto@kernel.org, conor.dooley@microchip.com, heiko@sntech.de, jszhang@kernel.org, lazyparser@gmail.com, falcon@tinylab.org, chenhuacai@kernel.org, apatel@ventanamicro.com, atishp@atishpatra.org, palmer@dabbelt.com, paul.walmsley@sifive.com, mark.rutland@arm.com, zouyipeng@huawei.com, bigeasy@linutronix.de, David.Laight@aculab.com, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, Guo Ren X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220930_052814_590432_CA688B62 X-CRM114-Status: GOOD ( 23.49 ) 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 Tue, Sep 20, 2022 at 9:45 AM Guo Ren wrote: > > On Mon, Sep 19, 2022 at 7:59 PM Peter Zijlstra wrote: > > > > On Sun, Sep 18, 2022 at 11:52:41AM -0400, guoren@kernel.org wrote: > > > From: Guo Ren > > > > > > When DEBUG_PREEMPT=y, > > > exit_to_user_mode_prepare > > > ->tick_nohz_user_enter_prepare > > > ->tick_nohz_full_cpu(smp_processor_id()) > > > ->smp_processor_id() > > > ->debug_smp_processor_id() > > > ->check preempt_count() then: > > > > > > [ 5.717610] BUG: using smp_processor_id() in preemptible [00000000] > > > code: S20urandom/94 > > > [ 5.718111] caller is debug_smp_processor_id+0x24/0x38 > > > [ 5.718417] CPU: 1 PID: 94 Comm: S20urandom Not tainted > > > 6.0.0-rc3-00010-gfd0a0d619c63-dirty #238 > > > [ 5.718886] Hardware name: riscv-virtio,qemu (DT) > > > [ 5.719136] Call Trace: > > > [ 5.719281] [] dump_backtrace+0x2c/0x3c > > > [ 5.719566] [] show_stack+0x44/0x5c > > > [ 5.720023] [] dump_stack_lvl+0x74/0xa4 > > > [ 5.720557] [] dump_stack+0x1c/0x2c > > > [ 5.721033] [] > > > check_preemption_disabled+0x104/0x108 > > > [ 5.721538] [] debug_smp_processor_id+0x24/0x38 > > > [ 5.722001] [] exit_to_user_mode_prepare+0x48/0x178 > > > [ 5.722355] [] irqentry_exit_to_user_mode+0x18/0x30 > > > [ 5.722685] [] irqentry_exit+0x64/0xa4 > > > [ 5.722953] [] do_page_fault+0x1d8/0x544 > > > [ 5.723291] [] ret_from_exception+0x0/0xb8 > > > > > > (Above is found in riscv platform with generic_entry) > > > > > > The smp_processor_id() needs irqs disable or preempt_disable, so use > > > preempt dis/in protecting the tick_nohz_user_enter_prepare(). > > > > > > Signed-off-by: Guo Ren > > > Signed-off-by: Guo Ren > > > --- > > > kernel/entry/common.c | 2 ++ > > > 1 file changed, 2 insertions(+) > > > > > > diff --git a/kernel/entry/common.c b/kernel/entry/common.c > > > index 063068a9ea9b..36e4cd50531c 100644 > > > --- a/kernel/entry/common.c > > > +++ b/kernel/entry/common.c > > > @@ -194,8 +194,10 @@ static void exit_to_user_mode_prepare(struct pt_regs *regs) > > > > > > lockdep_assert_irqs_disabled(); > > > > Observe ^^^^ > Thanks! I would enable PROVE_LOCKING for test. It's my bug in page_fault, here is the solution: @@ -358,6 +358,8 @@ asmlinkage void noinstr do_page_fault(struct pt_regs *regs) __do_page_fault(regs); + local_irq_disable(); + irqentry_exit(regs, state); } NOKPROBE_SYMBOL(do_page_fault); > > > > > > > > > + preempt_disable(); > > > /* Flush pending rcuog wakeup before the last need_resched() check */ > > > tick_nohz_user_enter_prepare(); > > > + preempt_enable(); > > > > This makes no sense; if IRQs are disabled, check_preemption_disabled() > > should bail early per: > > > > if (irqs_disabled()) > > goto out; > Ditto. > > > -- > Best Regards > Guo Ren -- Best Regards Guo Ren _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv