Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp27925188rwd; Tue, 4 Jul 2023 09:46:53 -0700 (PDT) X-Google-Smtp-Source: APBJJlHpV8ev+ycnOVu3L3VdqFWlMTEzdWeVghXGVGAgyzejJNk1ccRtBiqJDfPehMw0qLLU9jVq X-Received: by 2002:a05:6358:c684:b0:134:5667:a16c with SMTP id fe4-20020a056358c68400b001345667a16cmr8406302rwb.32.1688489213327; Tue, 04 Jul 2023 09:46:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688489213; cv=none; d=google.com; s=arc-20160816; b=O6BWiPBlw4thakZLjiX2WSi/VAkPBhBrFV6TWCYHdU5+uBGlqeGfezmKhqoJCSd6NL gpso2veQ8TGU9pWan/F+2mfHcv2aWjFLPEBKB9/MlnPMMyO/DNWnjKDbMOckxn9ZpKdH OjGQPrzpotoY+31x7y0bySwRTyE0Z5f6IgFp4Rg0NWoPXMAoB2tAxgvGNNccafYSU7Zk tGGVaK86eylhpX2jlXAm/9GSmPmIWFKotnQqV9ONDYFZDjYYPTQ8rxcJ/YaXeEQe0h31 OmBaCcjbQVF2qEpMYwO5qhEr+3JqognCxDaL5ywX3pZJOMZfX4NnZAteCPdtZBlktwWx oHGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=rt0Sgef/0mx0ZYOvMVPEM6yNpv3ovZQ+3Nf5gB6MWzc=; fh=bEpOEOOsE4VTcurRJBYP8Xh9lgQjlQAEB8wGc/ip6E4=; b=jL/mLpfb6KV+igMS/iqwqdIpSJXXoNhsCbSj2hYE6Ch36tkhtftmHsWc9JUsrNz0JV FhI0brVYhqoUHDRm5Onf03CRCtiIFe/nLs1431I7xL8mNP+X8MWsyWtyf/00JsJIUqJ8 KuKu9sE4mdpv1cUn8fParmtHCz3UCH8uQtcCx+M5PePnwN7PuuPfasT8PQOujMsJmohZ pKKs6P9CtwnQ4Lpoer8lcu3UP7jZDukW5YrttA10vFi7tbuEbwEcETF4VIxWILdB2oYD 4ICABPhVcUHdHkRDtd7qPD+cH4lEja4kc2uXQWenv4Ib7vV7G1ilvIq7Fei3W8TmjvAT JVnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=rBDJ16SW; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 198-20020a6300cf000000b0055acc7f8085si19629015pga.367.2023.07.04.09.46.36; Tue, 04 Jul 2023 09:46:53 -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=@infradead.org header.s=casper.20170209 header.b=rBDJ16SW; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231540AbjGDQkh (ORCPT + 99 others); Tue, 4 Jul 2023 12:40:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230452AbjGDQkf (ORCPT ); Tue, 4 Jul 2023 12:40:35 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58CF810D8; Tue, 4 Jul 2023 09:40:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=rt0Sgef/0mx0ZYOvMVPEM6yNpv3ovZQ+3Nf5gB6MWzc=; b=rBDJ16SWf0Ay6zMTwd7f3d6kAy qL6gCNlEfMBkK0U+jU0qBzOfVEhTXG/Jv0AuHH3G28F0sguOTd83Pszb1jR+PaLG5s56Umax07fky V+iLFsLcxqEwkx3CI+pXhlpUSnVO+D96+/aU9xo4KoKnlqy9OpOKBBhZC+Vpw6TFOGUgslA1GZTkZ SBEi2TSZLYKwyfiKoMzYJyrNhynZiXZMtVBtouqBeRApWVW9F5b6hYk8oICgkC4wCyIR5RqJ6hssZ ZWjQWEW9UvhulmSJ8hJiipJeZ+BV+g0ahag6kXdsU0gmmWJLGcd55LQxknsw7phyM1cb1bgZs3jD+ /FUXh9nA==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1qGj4R-009J9Z-4f; Tue, 04 Jul 2023 16:40:07 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 270993002E1; Tue, 4 Jul 2023 18:40:04 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 081F120292D0E; Tue, 4 Jul 2023 18:40:04 +0200 (CEST) Date: Tue, 4 Jul 2023 18:40:03 +0200 From: Peter Zijlstra To: guoren@kernel.org 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, mark.rutland@arm.com, bjorn@kernel.org, palmer@dabbelt.com, bjorn@rivosinc.com, daniel.thompson@linaro.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, stable@vger.kernel.org, Guo Ren Subject: Re: [PATCH] riscv: entry: Fixup do_trap_break from kernel side Message-ID: <20230704164003.GB83892@hirez.programming.kicks-ass.net> References: <20230702025708.784106-1-guoren@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230702025708.784106-1-guoren@kernel.org> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 Sat, Jul 01, 2023 at 10:57:07PM -0400, guoren@kernel.org wrote: > From: Guo Ren > > The irqentry_nmi_enter/exit would force the current context into in_interrupt. > That would trigger the kernel to dead panic, but the kdb still needs "ebreak" to > debug the kernel. > > Move irqentry_nmi_enter/exit to exception_enter/exit could correct handle_break > of the kernel side. This doesn't explain much if anything :/ I'm confused (probably because I don't know RISC-V very well), what's EBREAK and how does it happen? Specifically, if EBREAK can happen inside an local_irq_disable() region, then the below change is actively wrong. Any exception/interrupt that can happen while local_irq_disable() must be treated like an NMI. If that makes kdb unhappy, fix kdb. > Fixes: f0bddf50586d ("riscv: entry: Convert to generic entry") > Reported-by: Daniel Thompson > Signed-off-by: Guo Ren > Signed-off-by: Guo Ren > Cc: stable@vger.kernel.org > --- > arch/riscv/kernel/traps.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/arch/riscv/kernel/traps.c b/arch/riscv/kernel/traps.c > index efc6b649985a..ed0eb9452f9e 100644 > --- a/arch/riscv/kernel/traps.c > +++ b/arch/riscv/kernel/traps.c > @@ -18,6 +18,7 @@ > #include > #include > #include > +#include > > #include > #include > @@ -257,11 +258,11 @@ asmlinkage __visible __trap_section void do_trap_break(struct pt_regs *regs) > > irqentry_exit_to_user_mode(regs); > } else { > - irqentry_state_t state = irqentry_nmi_enter(regs); > + enum ctx_state prev_state = exception_enter(); > > handle_break(regs); > > - irqentry_nmi_exit(regs, state); > + exception_exit(prev_state); > } > } > > -- > 2.36.1 >