Received: by 2002:ac0:cd04:0:0:0:0:0 with SMTP id w4csp234904imn; Fri, 1 Jul 2022 13:59:53 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uOgSge40c3HLqKScL5yLtpbawTG6lK3M1xKNUCvlF1pZDVxm7zv4opkg+DnBRMkwdSlKjI X-Received: by 2002:a17:90a:b703:b0:1dd:1e2f:97d7 with SMTP id l3-20020a17090ab70300b001dd1e2f97d7mr20320337pjr.62.1656709193346; Fri, 01 Jul 2022 13:59:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656709193; cv=none; d=google.com; s=arc-20160816; b=0+K/cIgQ3kDg4UyHH+LoS/seLEOo/fUav4wQLqfw8oWsRt8+0sWWjLrmCcBUUUtqMV rNCgEB698mVsIUUQHAk82FnCyJ5e/rNcjAg2a3OK8rOu2gwQtMuWWBXbx4evhqLmiTwu cQPD6zF6jLfKnvlMjhrFP9jO0mXJFj7u/APrZpUjNvvCGWu57GpsAc/PVmxPxCGCY2qn rV1B1SjfeaXSUeZ9Se9cDwKpiHZolBDhGZxrfuYZj/POsCoZD7kpsD2CXCnkPlFLURa+ veK3ZKopQ+AFWm+9uzeX1WdQa/xbV+IYwGacZm1O2QrlEUP+Pb9HeT2G6oiAiVGG0Zf3 yzLg== 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 :feedback-id:dkim-signature:dkim-signature; bh=Hn/E8vVGaFtGaghheTN4YnxSeKObXSrHI8YMyykgXHU=; b=jETI1r1V6rIzHn/sCfLVvYK9d0+a8Ra1dgDcZFz43rfh0iUzKGZ1V8/i3Xg7MxTse+ 3xXRjILb8CnLeErkZnXQmX+szCpyF3Bn2I8ePbOPhDd5TA776vmqrFwKVXLTgAUbjnRi UFebZmDXhAIwy0qPuD0JG5GS8O4r5axkaWcPNkwaEeRcHvBrXvLxNx9lmL8vytJzzGjQ 9sOWVx4MSvxCkc+Pxr8hRVxuczGyu1PLHdysx/oHUlI/ROoXHjXb6ykVlDxWIKk/JpoD hHCi5mrISJRWDGklVYJi4iGGqT4/2LO4W15qXTyoEQ6mBZILtBgdlRNzccWhZH3GaozE zrAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sholland.org header.s=fm3 header.b="PmcsZb/p"; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=hI78zdRG; 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 je11-20020a170903264b00b00153b2d1659esi28899753plb.422.2022.07.01.13.59.42; Fri, 01 Jul 2022 13:59: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=@sholland.org header.s=fm3 header.b="PmcsZb/p"; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=hI78zdRG; 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 S230296AbiGAUYw (ORCPT + 99 others); Fri, 1 Jul 2022 16:24:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230331AbiGAUYt (ORCPT ); Fri, 1 Jul 2022 16:24:49 -0400 Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9A453526D for ; Fri, 1 Jul 2022 13:24:44 -0700 (PDT) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 3883E5C0107; Fri, 1 Jul 2022 16:24:44 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Fri, 01 Jul 2022 16:24:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sholland.org; h= cc:cc:content-transfer-encoding:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm3; t=1656707084; x=1656793484; bh=Hn /E8vVGaFtGaghheTN4YnxSeKObXSrHI8YMyykgXHU=; b=PmcsZb/petEK860oe6 B8pyMIXIBSw1U700oYzXcKQ1g+3DFomvbFIPE3FyW+ps7S1caLkegnKiloB4aKAu 5q4qu1vFslrTkahDlsNKFeNuOj73Iy2XcIVJtzaetcLCovxiF6zoCCFidFvTgLsL JIwVaGP16XZavxOnfb49CQOYOF0FfTBcSmQ64FAE87x9ROpywLNp4GnVAZUdhyt6 U2INn8AQzrofEwDQmA4k4WqHEk7on9eUu8KyIo/otOgMG/IhDAYp6xmHMUrhsSre jsCgxh8T5/QyijbK6a2sm6QoYZXowY0mOF1ooY47Jq/Oy4HuQ+o2lqAvsl6GonB4 057A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; t=1656707084; x=1656793484; bh=Hn/E8vVGaFtGa ghheTN4YnxSeKObXSrHI8YMyykgXHU=; b=hI78zdRGP/1OCUyIqcQXd2k6kbA/X 6S1QymStfx2AlsAjmGixkKApUSBF5i96livtljAXnvgM1MbHrC17FqGhZDcSS+0O r4P4WeLRbwHzw6uvhAwYWNgGGUCpvienXmrQ78WD5NrGP9SjQ0lzVAmnqGrErR+Q jlO3UcWUJZGp//oJ9n7Uk4/lzy6/yQoxejLrdWRsQtDNnpIZxWR1HSC9QD+koI2P oNSaluCCIl6YHQ1Inz7BwBKhiSSbA4A6CnJTVU8Zesf3B5nxFUK+ZG4fnjV3qa90 j0jc98W5pCyS0QHYKKt5uYDJXv///eWoG5E6zviC5YIvGmGKoSpX2fIiQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrudehfedgudeglecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefurghm uhgvlhcujfholhhlrghnugcuoehsrghmuhgvlhesshhhohhllhgrnhgurdhorhhgqeenuc ggtffrrghtthgvrhhnpedukeetueduhedtleetvefguddvvdejhfefudelgfduveeggeeh gfdufeeitdevteenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfh hrohhmpehsrghmuhgvlhesshhhohhllhgrnhgurdhorhhg X-ME-Proxy: Feedback-ID: i0ad843c9:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 1 Jul 2022 16:24:43 -0400 (EDT) From: Samuel Holland To: Thomas Gleixner , Marc Zyngier , Palmer Dabbelt , Paul Walmsley , Albert Ou Cc: Samuel Holland , linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org Subject: [PATCH v3 2/2] irqchip/sifive-plic: Separate the enable and mask operations Date: Fri, 1 Jul 2022 15:24:40 -0500 Message-Id: <20220701202440.59059-3-samuel@sholland.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220701202440.59059-1-samuel@sholland.org> References: <20220701202440.59059-1-samuel@sholland.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE 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 The PLIC has two per-IRQ checks before sending an IRQ to a hart context. First, it checks that the IRQ's priority is nonzero. Then, it checks that the enable bit is set for that combination of IRQ and context. Currently, the PLIC driver sets both the priority value and the enable bit in its (un)mask operations. However, modifying the enable bit is problematic for two reasons: 1) The enable bits are packed, so changes are not atomic and require taking a spinlock. 2) The following requirement from the PLIC spec, which explains the racy (un)mask operations in plic_irq_eoi(): If the completion ID does not match an interrupt source that is currently enabled for the target, the completion is silently ignored. Both of these problems are solved by using the priority value to mask IRQs. Each IRQ has a separate priority register, so writing the priority value is atomic. And since the enable bit remains set while an IRQ is masked, the EOI operation works normally. The enable bits are still used to control the IRQ's affinity. Signed-off-by: Samuel Holland --- Changes in v3: - Rebased on top of irqchip-next drivers/irqchip/irq-sifive-plic.c | 55 +++++++++++++++++++------------ 1 file changed, 34 insertions(+), 21 deletions(-) diff --git a/drivers/irqchip/irq-sifive-plic.c b/drivers/irqchip/irq-sifive-plic.c index 46595e607b0e..ba4938188570 100644 --- a/drivers/irqchip/irq-sifive-plic.c +++ b/drivers/irqchip/irq-sifive-plic.c @@ -108,9 +108,7 @@ static inline void plic_irq_toggle(const struct cpumask *mask, struct irq_data *d, int enable) { int cpu; - struct plic_priv *priv = irq_data_get_irq_chip_data(d); - writel(enable, priv->regs + PRIORITY_BASE + d->hwirq * PRIORITY_PER_ID); for_each_cpu(cpu, mask) { struct plic_handler *handler = per_cpu_ptr(&plic_handlers, cpu); @@ -118,16 +116,37 @@ static inline void plic_irq_toggle(const struct cpumask *mask, } } -static void plic_irq_unmask(struct irq_data *d) +static void plic_irq_enable(struct irq_data *d) { plic_irq_toggle(irq_data_get_effective_affinity_mask(d), d, 1); } -static void plic_irq_mask(struct irq_data *d) +static void plic_irq_disable(struct irq_data *d) { plic_irq_toggle(irq_data_get_effective_affinity_mask(d), d, 0); } +static void plic_irq_unmask(struct irq_data *d) +{ + struct plic_priv *priv = irq_data_get_irq_chip_data(d); + + writel(1, priv->regs + PRIORITY_BASE + d->hwirq * PRIORITY_PER_ID); +} + +static void plic_irq_mask(struct irq_data *d) +{ + struct plic_priv *priv = irq_data_get_irq_chip_data(d); + + writel(0, priv->regs + PRIORITY_BASE + d->hwirq * PRIORITY_PER_ID); +} + +static void plic_irq_eoi(struct irq_data *d) +{ + struct plic_handler *handler = this_cpu_ptr(&plic_handlers); + + writel(d->hwirq, handler->hart_base + CONTEXT_CLAIM); +} + #ifdef CONFIG_SMP static int plic_set_affinity(struct irq_data *d, const struct cpumask *mask_val, bool force) @@ -146,32 +165,21 @@ static int plic_set_affinity(struct irq_data *d, if (cpu >= nr_cpu_ids) return -EINVAL; - plic_irq_mask(d); + plic_irq_disable(d); irq_data_update_effective_affinity(d, cpumask_of(cpu)); - if (!irqd_irq_masked(d)) - plic_irq_unmask(d); + if (!irqd_irq_disabled(d)) + plic_irq_enable(d); return IRQ_SET_MASK_OK_DONE; } #endif -static void plic_irq_eoi(struct irq_data *d) -{ - struct plic_handler *handler = this_cpu_ptr(&plic_handlers); - - if (irqd_irq_masked(d)) { - plic_irq_unmask(d); - writel(d->hwirq, handler->hart_base + CONTEXT_CLAIM); - plic_irq_mask(d); - } else { - writel(d->hwirq, handler->hart_base + CONTEXT_CLAIM); - } -} - static struct irq_chip plic_edge_chip = { .name = "SiFive PLIC", + .irq_enable = plic_irq_enable, + .irq_disable = plic_irq_disable, .irq_ack = plic_irq_eoi, .irq_mask = plic_irq_mask, .irq_unmask = plic_irq_unmask, @@ -184,6 +192,8 @@ static struct irq_chip plic_edge_chip = { static struct irq_chip plic_chip = { .name = "SiFive PLIC", + .irq_enable = plic_irq_enable, + .irq_disable = plic_irq_disable, .irq_mask = plic_irq_mask, .irq_unmask = plic_irq_unmask, .irq_eoi = plic_irq_eoi, @@ -429,8 +439,11 @@ static int __init __plic_init(struct device_node *node, i * CONTEXT_ENABLE_SIZE; handler->priv = priv; done: - for (hwirq = 1; hwirq <= nr_irqs; hwirq++) + for (hwirq = 1; hwirq <= nr_irqs; hwirq++) { plic_toggle(handler, hwirq, 0); + writel(1, priv->regs + PRIORITY_BASE + + hwirq * PRIORITY_PER_ID); + } nr_handlers++; } -- 2.35.1