From patchwork Mon Oct 23 08:29:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xu Lu X-Patchwork-Id: 156741 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1151259vqx; Mon, 23 Oct 2023 01:31:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHtgXXdPT9uhZcfEd8XapJOpKeQfaI0MKzyE0esIJB31ayvJAH+g8ztCfAYsgCZba3MtlW5 X-Received: by 2002:a17:903:1210:b0:1c7:245a:7fea with SMTP id l16-20020a170903121000b001c7245a7feamr10724116plh.58.1698049895677; Mon, 23 Oct 2023 01:31:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698049895; cv=none; d=google.com; s=arc-20160816; b=d5BcYCfJDFXagYq5bAwMIlYbKkEwLIUn8V8hd4PosR0wEh/Yi8UjFM7QuqNyF2vqeX 7xiVjJtI5xNdkJdqZteE+S3kpxarffK1Z3ZReyoAGmiN8hHWVJ0Es5plPXCeUr+RLW0E 2tDuhzd5LH8rCSlRaoQDAmSf0QUbyvR2rwzqE+o1P9ic7I1aCEHC+xv//veKYw9++bIK MnopWWc879KglGPLh7pWgazNmP9/7efB4dsSqvmgkduXNXPr98Dny43KIjIST+6Cwx91 5YREnaHzBQ88TGa4YmNOiRoJYZ6s0NabVYSYyPdSw+9T6SDg+zTXgqFUzVcERh+Bo3wJ Gq9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=+zaYgIQbfD9rezIYpqI9laPzzTdWx+ZAuyZYYGD6lvk=; fh=O4eOVhHjKTyaSORSQqoF+Vv6GYDagG+8LotEUwhRqvg=; b=Ht3YXwQllv6PQvhWOh8/8ai/o9T0hZE6oKuNGsHQRU82mAq/hy9MlsBgDbKljUSj/7 gLmQqv3qs8gKU0ViD9OtBuBLgCkgNY448oHab6KJFlo/xwuv7p4kCoddKfetOiUOzSPQ p2+2BsCDojI1i/F7JKuC1hOkT2LTN6r4xkuIhOieWEhkiKqET5m8srqSrQRrvh/QTa6c Q67G0Auoa3lnrLbgrAi8SdUjnwaJVL44jyluea7OdVTrZKKlbD0AddTSyP5lrAmJEZNc y+KWT13PQy+OqljiPfUWJdFtrmjHOugHc9V6sP/L1fMz01YC4g4kWLL8KYDepSvAq2TI govg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=Kjd3jevJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id l20-20020a170903005400b001ca86fa1e1csi5689919pla.484.2023.10.23.01.31.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 01:31:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=Kjd3jevJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 05BDF809ABFE; Mon, 23 Oct 2023 01:31:21 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233412AbjJWIbI (ORCPT + 26 others); Mon, 23 Oct 2023 04:31:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233057AbjJWIaq (ORCPT ); Mon, 23 Oct 2023 04:30:46 -0400 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECF77D6B for ; Mon, 23 Oct 2023 01:30:18 -0700 (PDT) Received: by mail-pj1-x1031.google.com with SMTP id 98e67ed59e1d1-27d1373f631so2375943a91.1 for ; Mon, 23 Oct 2023 01:30:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1698049818; x=1698654618; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+zaYgIQbfD9rezIYpqI9laPzzTdWx+ZAuyZYYGD6lvk=; b=Kjd3jevJivPEcsw5F67N8jy0YvnVBqHR5+uIDJ+9La/cvROPJqBXHLpWV36WidC2Dt RqgxAytav/Ur5ma2mfgDfcqN6jrfiMzQxwbb8dN3lsRIktkn6tuMHhGHKADFrFeJfrOu vd6vVbV8RzC9b3Nb5A7o5+iw7fF/QxQ4sd6vym6sd+EsWiiO81QOgRu3Mfol527titTO U/mt7XTu5CiNZYWEkpb4fElOcSDDuM+n5n8UAyRv/DbiqwpaSUaSULuhBTkIqBC/Ciro gsgWWvvEGSv0OIUlxFW8VCegUd4FS9f158yDWngOMSyfvFVSgpOEiUqcizwGCh6+Tgvr U16Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698049818; x=1698654618; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+zaYgIQbfD9rezIYpqI9laPzzTdWx+ZAuyZYYGD6lvk=; b=Bc8xPho61ChO1r5kDpCTLZSReGnYFms6YVjqwM8jucDTmXdnDTDc2LkKM5uZ2rn9GU 3s+sAVDO0PfyyUypJrTdRxvAWPg3VmjVhQZYTIBeYwb1BmPUgl6/Oyk4WfLkbIECf6bg j6LCfYZckZWErH+K9VmJvPa+oSBv/ggTvAFi1cPU2X655B5D6ZQwZhdwetDmTaQIRF0I GtoJfVG30Ght9RcC8bG15Zn2d5uL43s/kieDDSQ0UyAhaiM/tNzqQ0W8b/xX8nwas135 vtxFjms9EDdpr8gWZc2EEkthRk1pvldndgIs+R5OKyT98uR9dphQx7V6O/oP93F+0xcd +HLg== X-Gm-Message-State: AOJu0YzYWyEA9iJeBwps4Y+MdrtzGXLaxDcEZvhlfwjTiXNalNYakGx4 HaPAiA1GJaufDj+AIFZW2YDZmA== X-Received: by 2002:a17:90b:3e85:b0:27d:1567:f51d with SMTP id rj5-20020a17090b3e8500b0027d1567f51dmr9084887pjb.47.1698049817843; Mon, 23 Oct 2023 01:30:17 -0700 (PDT) Received: from J9GPGXL7NT.bytedance.net ([203.208.167.147]) by smtp.gmail.com with ESMTPSA id d15-20020a170903230f00b001b8b07bc600sm5415805plh.186.2023.10.23.01.30.12 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 23 Oct 2023 01:30:17 -0700 (PDT) From: Xu Lu To: paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, tglx@linutronix.de, maz@kernel.org, anup@brainfault.org, atishp@atishpatra.org Cc: dengliang.1214@bytedance.com, liyu.yukiteru@bytedance.com, sunjiadong.lff@bytedance.com, xieyongji@bytedance.com, lihangjing@bytedance.com, chaiwen.cc@bytedance.com, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, Xu Lu Subject: [RFC 10/12] riscv: Enable NMIs during interrupt handling Date: Mon, 23 Oct 2023 16:29:09 +0800 Message-Id: <20231023082911.23242-11-luxu.kernel@bytedance.com> X-Mailer: git-send-email 2.39.3 (Apple Git-145) In-Reply-To: <20231023082911.23242-1-luxu.kernel@bytedance.com> References: <20231023082911.23242-1-luxu.kernel@bytedance.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_NONE 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 23 Oct 2023 01:31:21 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780534367508529758 X-GMAIL-MSGID: 1780534367508529758 Hardware automatically clearing SIE field of CSR_STATUS whenever thread traps into kernel by interrupt, disabling all irqs including NMIs during interrupt handling. This commit re-enable NMIs during interrupt handling by setting the SIE field in CSR_STATUS and restoring NMIs bits in CSR_IE. Normal interrupts are still disabled during interrupt handling and NMIs are also disabled during NMIs handling to avoid nesting. Signed-off-by: Xu Lu Signed-off-by: Hangjing Li Reviewed-by: Liang Deng Reviewed-by: Yu Li --- arch/riscv/kernel/traps.c | 44 +++++++++++++++++++++++--------- drivers/irqchip/irq-riscv-intc.c | 2 ++ 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/arch/riscv/kernel/traps.c b/arch/riscv/kernel/traps.c index 63d3c1417563..185743edfa09 100644 --- a/arch/riscv/kernel/traps.c +++ b/arch/riscv/kernel/traps.c @@ -356,20 +356,11 @@ asmlinkage __visible noinstr void do_page_fault(struct pt_regs *regs) } #endif -static void noinstr handle_riscv_irq(struct pt_regs *regs) +static void noinstr do_interrupt(struct pt_regs *regs) { struct pt_regs *old_regs; - irq_enter_rcu(); old_regs = set_irq_regs(regs); - handle_arch_irq(regs); - set_irq_regs(old_regs); - irq_exit_rcu(); -} - -asmlinkage void noinstr do_irq(struct pt_regs *regs) -{ - irqentry_state_t state = irqentry_enter(regs); #ifdef CONFIG_IRQ_STACKS if (on_thread_stack()) { ulong *sp = per_cpu(irq_stack_ptr, smp_processor_id()) @@ -382,7 +373,9 @@ asmlinkage void noinstr do_irq(struct pt_regs *regs) "addi s0, sp, 2*"RISCV_SZPTR "\n" "move sp, %[sp] \n" "move a0, %[regs] \n" - "call handle_riscv_irq \n" + "la t0, handle_arch_irq \n" + REG_L" t1, (t0) \n" + "jalr t1 \n" "addi sp, s0, -2*"RISCV_SZPTR"\n" REG_L" s0, (sp) \n" "addi sp, sp, "RISCV_SZPTR "\n" @@ -398,11 +391,38 @@ asmlinkage void noinstr do_irq(struct pt_regs *regs) "memory"); } else #endif - handle_riscv_irq(regs); + handle_arch_irq(regs); + set_irq_regs(old_regs); +} + +static __always_inline void __do_nmi(struct pt_regs *regs) +{ + irqentry_state_t state = irqentry_nmi_enter(regs); + + do_interrupt(regs); + + irqentry_nmi_exit(regs, state); +} + +static __always_inline void __do_irq(struct pt_regs *regs) +{ + irqentry_state_t state = irqentry_enter(regs); + + irq_enter_rcu(); + do_interrupt(regs); + irq_exit_rcu(); irqentry_exit(regs, state); } +asmlinkage void noinstr do_irq(struct pt_regs *regs) +{ + if (IS_ENABLED(CONFIG_RISCV_PSEUDO_NMI) && regs_irqs_disabled(regs)) + __do_nmi(regs); + else + __do_irq(regs); +} + #ifdef CONFIG_GENERIC_BUG int is_valid_bugaddr(unsigned long pc) { diff --git a/drivers/irqchip/irq-riscv-intc.c b/drivers/irqchip/irq-riscv-intc.c index c672c0c64d5d..80ed8606e04d 100644 --- a/drivers/irqchip/irq-riscv-intc.c +++ b/drivers/irqchip/irq-riscv-intc.c @@ -34,7 +34,9 @@ static asmlinkage void riscv_intc_irq(struct pt_regs *regs) generic_handle_domain_nmi(intc_domain, cause); nmi_exit(); } else { + enable_nmis(); generic_handle_domain_irq(intc_domain, cause); + disable_nmis(); } }