From patchwork Mon Oct 23 08:29:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xu Lu X-Patchwork-Id: 156738 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1151248vqx; Mon, 23 Oct 2023 01:31:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF1WaGipcmJF0trCqsRegxEqMUB/4yHF4raRwL2yj8nRKWWVy6EoRb0ciwdBPruHJd8Ccn5 X-Received: by 2002:a05:6870:3893:b0:1ea:29a:861e with SMTP id y19-20020a056870389300b001ea029a861emr9078743oan.12.1698049894464; Mon, 23 Oct 2023 01:31:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698049894; cv=none; d=google.com; s=arc-20160816; b=Ks3qksOGkyxIIoWuP/a0QsJrD0M70U1oxtBTNa3/PNIo2KCHUsdSI2hbz9LxJdHmB8 eGD9nXa0QXvyUXtHWpEZDZ1FDRIjKEUOkX0gi0vFNrkx7pC2eNn3Vsr5UthLz3Mo1JQN VpAkqT+7rl4x5sSdVWc9eU7Zdztb7Hr06sI1U5/KZZqgplzHrseWshPv1OW2p8QMZHBh CI9hOgAKIEA7HREu23LiVUTATdQGJarxsB4zh3fv+lpRf86A3WuY04yrz4KhVg/AMt6S IhOcdFGN3+VMOOiFyiQhLxe6Y1E+nt4/83fuGE6XjUkjCxBEZXbwFaodKQ+cWOgEaOgz mKGg== 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=KDj8p8VlOUWmt6ePZtJj52Ju7p2Y1636xaXynBRmH4M=; fh=O4eOVhHjKTyaSORSQqoF+Vv6GYDagG+8LotEUwhRqvg=; b=B96dK7fHG5sESjTcPRsqd+g0YZSxrEMD5Z++WiTBO/8eS6csAQZUbWfSvTVIsadpGl BfdadHdu4XbY1CENrhexow1kwCmLkthdVLviwRx5LAUTUEYHvTh6/XAh2EUuKV1XgrVk nti/mBfuWmzYl6mZrTkzZJ5ljeyN6O6fUhfUTc9I1VubCs/Qvi6olAHD4uJgudvXWbKa WP2uMwB8QO8NlDTsdNw0EfwZxsj/CUZoKfWJpuNSgxJ5Ee/K/dYVA7+IU4b03VjgGNRB LAR6WUoWI86t/BIVUwzcns+HDkXU+89YR0uywsJu42jPZw4PwtW0l6+rV9bP3tcb233D d8bw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=ESLob1Ub; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id b14-20020a63714e000000b00573fc592e9dsi5680804pgn.848.2023.10.23.01.31.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 01:31:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=ESLob1Ub; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (Postfix) with ESMTP id D20CE809B6CA; Mon, 23 Oct 2023 01:30:58 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232982AbjJWIar (ORCPT + 26 others); Mon, 23 Oct 2023 04:30:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37678 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233202AbjJWIaa (ORCPT ); Mon, 23 Oct 2023 04:30:30 -0400 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F43CD7D for ; Mon, 23 Oct 2023 01:30:04 -0700 (PDT) Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1c8a1541232so25448305ad.0 for ; Mon, 23 Oct 2023 01:30:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1698049801; x=1698654601; 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=KDj8p8VlOUWmt6ePZtJj52Ju7p2Y1636xaXynBRmH4M=; b=ESLob1UbjBeQXWmATGlGDVFX/ccJq/psY6rKeSPpA5LQihEo8YeLQ2FFAjwkd+VUaw IwAVoLM51QGFiGje6BpmxP4gHZBXyYZ2HFrQmWyiTYJZx9PvHYex7AMKKesIGwi4JDrK HLwT2vhrf1ognNZ/vRWda4g56Ide3aPgJMiaStUTt/Q3Id5T7hWGmqDfFg+QOGxtDj3B IynOaUV03m2vtY943kZctQ/GfLjxWUAU4aUe51V/NxQNhsHTlr2aSk50s+bZjTAIUPDk 2J1izRBehLaBLMV4cfZLxWX6682m6qDZ/gtd3LmkUHEFXeP3MYy66gTS5bFWL8cvBxYl M3Og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698049801; x=1698654601; 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=KDj8p8VlOUWmt6ePZtJj52Ju7p2Y1636xaXynBRmH4M=; b=umF16mmFxUbnA0UdABWz3UOgj2BQ9nANr0CaEpRxMeMGWoaKUbqvl+OLz8uDXKHwHM /wJ20truLDvLbREgfKIdTIC+SKj6bhbzZkubMS6hayGkw1I5SBIE90+U4h69/Ue7zwaR RgYYMpcrdpP9TVWiCNRr/k2orsyjv0ajjTMRY5mZizzqiY3aop4/OkocVThoW3hMhKOH pvQA4Ivj5ddPYmrsdVsFKdFvUYVA/eHevJLymjZocGTBeFMDlxRuSBN/lYnejt0NARLl Lh4/oVA2llQvKG3/gk/olSzG+Vc/kxl2qfGT5xPt1uhcC4T91/ZO7zBBbomaNfytuiYT OQuA== X-Gm-Message-State: AOJu0YxWkKGr27je7VEH/XpUbcBiMWfKl/AcVaXR1d6rJHV6c4RxV15t +XXc2g4xvvXdtiw7dXOf+posUQ== X-Received: by 2002:a17:902:c602:b0:1c8:7822:e5c3 with SMTP id r2-20020a170902c60200b001c87822e5c3mr7531739plr.47.1698049800869; Mon, 23 Oct 2023 01:30:00 -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.29.55 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 23 Oct 2023 01:30:00 -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 07/12] riscv: Handle pseudo NMI in arch irq handler Date: Mon, 23 Oct 2023 16:29:06 +0800 Message-Id: <20231023082911.23242-8-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=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email 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 (fry.vger.email [0.0.0.0]); Mon, 23 Oct 2023 01:30:58 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780534366511967385 X-GMAIL-MSGID: 1780534366511967385 This commit handles pseudo NMI in arch irq handler. We enter NMI context before handling NMI and keeps all interrupts disabled during NMI handling to avoid interrupt nesting. Signed-off-by: Xu Lu Signed-off-by: Hangjing Li --- drivers/irqchip/irq-riscv-intc.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/drivers/irqchip/irq-riscv-intc.c b/drivers/irqchip/irq-riscv-intc.c index 83a0a744fce6..c672c0c64d5d 100644 --- a/drivers/irqchip/irq-riscv-intc.c +++ b/drivers/irqchip/irq-riscv-intc.c @@ -20,6 +20,26 @@ static struct irq_domain *intc_domain; +#ifdef CONFIG_RISCV_PSEUDO_NMI + +static asmlinkage void riscv_intc_irq(struct pt_regs *regs) +{ + unsigned long cause = regs->cause & ~CAUSE_IRQ_FLAG; + + if (unlikely(cause >= BITS_PER_LONG)) + panic("unexpected interrupt cause"); + + if (is_nmi(cause)) { + nmi_enter(); + generic_handle_domain_nmi(intc_domain, cause); + nmi_exit(); + } else { + generic_handle_domain_irq(intc_domain, cause); + } +} + +#else /* CONFIG_RISCV_PSEUDO_NMI */ + static asmlinkage void riscv_intc_irq(struct pt_regs *regs) { unsigned long cause = regs->cause & ~CAUSE_IRQ_FLAG; @@ -30,6 +50,8 @@ static asmlinkage void riscv_intc_irq(struct pt_regs *regs) generic_handle_domain_irq(intc_domain, cause); } +#endif /* CONFIG_RISCV_PSEUDO_NMI */ + /* * On RISC-V systems local interrupts are masked or unmasked by writing * the SIE (Supervisor Interrupt Enable) CSR. As CSRs can only be written