Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp213829iob; Mon, 2 May 2022 17:25:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzcCjbxch+T4XvesNiS1kU8hre0N/aWbspTjFQmtwOGxQotpQ9FRVtXfeY+HcoPlWHReZcZ X-Received: by 2002:a17:90b:3a8d:b0:1dc:3040:f02d with SMTP id om13-20020a17090b3a8d00b001dc3040f02dmr1891484pjb.230.1651537509315; Mon, 02 May 2022 17:25:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651537509; cv=none; d=google.com; s=arc-20160816; b=VE76cjAFiohyfQ3XG9x6W6OAjIhGSrpMGtAJt+ClzUhqPrTdf0FGyOiHtpS86CIUYx E6O3xJVIU8NwuKkXI7ortsJQpOErqzcAGo+fXzbGIHS6Ii8oNp1LSUkLVELQ/5J47GQV P5OjKYppC5CmOXztE9Lu20JYFn2Q1sXrquDZK/oMk1rP7ryhc/UzY3+z4pbh/gqBFXdv UqQdW6N5RgSsfMy3ChRTCBxZ+u6gQsATpYARuZ6658/Mw6C1o8ChKVmEhnxgkka4X/Oa N51C0u9M9RKo42p5vP1JygxtT1WnNHKvrjuMI96wz1Vcf6RcI4dNMDPMIlvhBrI8Ty1w poHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:in-reply-to :subject:cc:to:from:message-id:date:dkim-signature; bh=de1RCXipgXalbiJBti/wBN+qBkskhsw3kDC00742Gjk=; b=cJRz/hClR3jhV5+xUzIAl98aaj8xfQQffHAISXZYB/sK8UTeg9Ft4rl0a1CHexO6eu ttRIPa2R7IYxpK4TDXqvvvmWQK09ZdcSPheqZpSU05CflavMdE/c1jLXyqC0d6qx8N/B RcO9PHvt1ey+vZ7k1nj8klbrtnp/ch14VFmtjxcJnD4BmtKAks8Jp0vD2ysCh0a4dKmF 4Egk3/r2oW4ibXoH4VMfz+56SfiHXNBZmSHqg0gQHXAooUu58aM13OANBbNnK+eCA9sl 6zyj3RK4xxVy4aaoNWUrVgqj2IVw5SjikcXXdXtfzF3zBLujO/ULTl4/TY0vrWbaST5I Niag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UGI7S8FN; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id 31-20020a630a1f000000b003abadb1ec47si14796019pgk.616.2022.05.02.17.25.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 May 2022 17:25:09 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UGI7S8FN; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7ED153969C; Mon, 2 May 2022 17:20:42 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379731AbiD2RnQ (ORCPT + 99 others); Fri, 29 Apr 2022 13:43:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379210AbiD2RnO (ORCPT ); Fri, 29 Apr 2022 13:43:14 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E211D0831 for ; Fri, 29 Apr 2022 10:39:55 -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 dfw.source.kernel.org (Postfix) with ESMTPS id B5979623E9 for ; Fri, 29 Apr 2022 17:39:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 170D0C385A7; Fri, 29 Apr 2022 17:39:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1651253994; bh=HC9TdVLo9keVPG6iukg9qEk+kO7QXIdsNKSS4mzp4X8=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=UGI7S8FNgdtcOXLEqKlU1tl5scm27Cx1qHZBOAOHmyGD+yaUU9lZjMPT70K4xzebr /Dhy05YI0+gGeWUjvdZk3AaGGAp9EY75hmiBqCBpwjZAGGg1W3EQULqCV2oSPoU22M K9MpWGNmFq67Oy2qofL2bZQ+pZyfUg0URG+d3bCW1eiq4QfQyYWwrEngS0YnxCmen7 uZv9JUwwUhUSLEcq7g0wrCZPUvzSHjMjj3PD8JLhJHNRQwFd5SdWwj6eQrGc9Vt9jJ bP/M6kHI51qwfPO1xpMxRDmx2HmG+XrnKbkGh+maNzJpmty0yF5fidNtV0FFnjuptr fMTM5eHhFjoIA== Received: from sofa.misterjones.org ([185.219.108.64] helo=why.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nkUat-00809D-JJ; Fri, 29 Apr 2022 18:39:51 +0100 Date: Fri, 29 Apr 2022 18:39:51 +0100 Message-ID: <87pmkz94bc.wl-maz@kernel.org> From: Marc Zyngier To: Daniel Thompson Cc: Thomas Gleixner , Catalin Marinas , Will Deacon , Ard Biesheuvel , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] irqchip/exiu: Fix acknowledgment of edge triggered interrupts In-Reply-To: <20220429165314.2343705-1-daniel.thompson@linaro.org> References: <20220429165314.2343705-1-daniel.thompson@linaro.org> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: daniel.thompson@linaro.org, tglx@linutronix.de, catalin.marinas@arm.com, will@kernel.org, ardb@kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 Fri, 29 Apr 2022 17:53:14 +0100, Daniel Thompson wrote: > > Currently the EXIU uses the fasteoi interrupt flow that is configured by > it's parent (irq-gic-v3.c). With this flow the only chance to clear the > interrupt request happens during .irq_eoi() and (obviously) this happens > after the interrupt handler has run. EXIU requires edge triggered > interrupts to be acked prior to interrupt handling. Without this we > risk incorrect interrupt dismissal when a new interrupt is delivered > after the handler reads and acknowledges the peripheral but before the > irq_eoi() takes place. > > Fix this by clearing the interrupt request from .irq_ack() if we are > configured for edge triggered interrupts. This requires adopting the > fasteoi-ack flow instead of the fasteoi to ensure the ack gets called. > > These changes have been tested using the power button on a > Developerbox/SC2A11 combined with some hackery in gpio-keys so I can > play with the different trigger mode (and an mdelay(500) so I can > can check what happens on a double click in both modes. > > Fixes: 706cffc1b912 ("irqchip/exiu: Add support for Socionext Synquacer EXIU controller") > Signed-off-by: Daniel Thompson > --- > > Notes: > Changes in v2: > > * Switch to dynamic selection of handle_fasteoi_irq and > handle_fasteoi_ack_irq and reintroduce exiu_irq_eoi() since we need > that for level triggered interrupts (Ard B). > * Above changes mean we are no longer using sun6i NMI code as a > template to tidy up the description accordingly. > > arch/arm64/Kconfig.platforms | 1 + > drivers/irqchip/irq-sni-exiu.c | 33 +++++++++++++++++++++++++++++---- > 2 files changed, 30 insertions(+), 4 deletions(-) > > diff --git a/arch/arm64/Kconfig.platforms b/arch/arm64/Kconfig.platforms > index 30b123cde02c..aaeaf57c8222 100644 > --- a/arch/arm64/Kconfig.platforms > +++ b/arch/arm64/Kconfig.platforms > @@ -253,6 +253,7 @@ config ARCH_INTEL_SOCFPGA > > config ARCH_SYNQUACER > bool "Socionext SynQuacer SoC Family" > + select IRQ_FASTEOI_HIERARCHY_HANDLERS > > config ARCH_TEGRA > bool "NVIDIA Tegra SoC Family" > diff --git a/drivers/irqchip/irq-sni-exiu.c b/drivers/irqchip/irq-sni-exiu.c > index abd011fcecf4..651a82dead01 100644 > --- a/drivers/irqchip/irq-sni-exiu.c > +++ b/drivers/irqchip/irq-sni-exiu.c > @@ -37,11 +37,20 @@ struct exiu_irq_data { > u32 spi_base; > }; > > -static void exiu_irq_eoi(struct irq_data *d) > +static void exiu_irq_ack(struct irq_data *d) > { > struct exiu_irq_data *data = irq_data_get_irq_chip_data(d); > > writel(BIT(d->hwirq), data->base + EIREQCLR); > +} > + > +static void exiu_irq_eoi(struct irq_data *d) > +{ > + struct exiu_irq_data *data = irq_data_get_irq_chip_data(d); > + u32 edge_triggered = readl_relaxed(data->base + EIEDG); I expect this to be pretty expensive. Why not directly check the state flags with irqd_is_level_type()? > + > + if (!(edge_triggered & BIT(d->hwirq))) > + writel(BIT(d->hwirq), data->base + EIREQCLR); Is this write even needed for a level interrupt? Or does the register always behave as a latch irrespective of the trigger? > irq_chip_eoi_parent(d); > } > > @@ -91,10 +100,13 @@ static int exiu_irq_set_type(struct irq_data *d, unsigned int type) > writel_relaxed(val, data->base + EILVL); > > val = readl_relaxed(data->base + EIEDG); > - if (type == IRQ_TYPE_LEVEL_LOW || type == IRQ_TYPE_LEVEL_HIGH) > + if (type == IRQ_TYPE_LEVEL_LOW || type == IRQ_TYPE_LEVEL_HIGH) { > val &= ~BIT(d->hwirq); > - else > + irq_set_handler_locked(d, handle_fasteoi_irq); > + } else { > val |= BIT(d->hwirq); > + irq_set_handler_locked(d, handle_fasteoi_ack_irq); > + } > writel_relaxed(val, data->base + EIEDG); > > writel_relaxed(BIT(d->hwirq), data->base + EIREQCLR); > @@ -104,6 +116,7 @@ static int exiu_irq_set_type(struct irq_data *d, unsigned int type) > > static struct irq_chip exiu_irq_chip = { > .name = "EXIU", > + .irq_ack = exiu_irq_ack, > .irq_eoi = exiu_irq_eoi, > .irq_enable = exiu_irq_enable, > .irq_mask = exiu_irq_mask, > @@ -148,6 +161,8 @@ static int exiu_domain_alloc(struct irq_domain *dom, unsigned int virq, > struct irq_fwspec parent_fwspec; > struct exiu_irq_data *info = dom->host_data; > irq_hw_number_t hwirq; > + int i, ret; > + u32 edge_triggered; > > parent_fwspec = *fwspec; > if (is_of_node(dom->parent->fwnode)) { > @@ -165,7 +180,17 @@ static int exiu_domain_alloc(struct irq_domain *dom, unsigned int virq, > irq_domain_set_hwirq_and_chip(dom, virq, hwirq, &exiu_irq_chip, info); > > parent_fwspec.fwnode = dom->parent->fwnode; > - return irq_domain_alloc_irqs_parent(dom, virq, nr_irqs, &parent_fwspec); > + ret = irq_domain_alloc_irqs_parent(dom, virq, nr_irqs, &parent_fwspec); > + if (ret) > + return ret; > + > + edge_triggered = readl_relaxed(info->base + EIEDG); > + for (i = 0; i < nr_irqs; i++) > + irq_set_handler(virq + i, edge_triggered & BIT(i) ? > + handle_fasteoi_ack_irq : > + handle_fasteoi_irq); > + > + return 0; Why do you need this at allocation time? I would have expected the trigger configuration to be enough. Thanks, M. -- Without deviation from the norm, progress is not possible.