Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1999455pxb; Mon, 11 Oct 2021 18:31:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzpCusOgqV5yQZ60XCPRjjLo3+8SyCZoXqF6bLTHuV2GRTJn6zpoguUHKjN8kxC6QKMSAeW X-Received: by 2002:a17:906:5051:: with SMTP id e17mr29875490ejk.481.1634002291633; Mon, 11 Oct 2021 18:31:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634002291; cv=none; d=google.com; s=arc-20160816; b=fZ3zodAvB+80nHE9f2X0pM2mHfXLrhfOXT4ayL/vje+j1MAK/ATVpBzVMLV5C+Mj6H i19OM/JcUxRwl/B9HVK/8AtLx3bBUT/4nW6o6vXRS5NkfTMhg/uHwShWdKwrZbxTRNN1 lsKDVXQYusotIFI6Ejr+j6sZFRuJEBJDO8S5omlCOncCSb1EocUvk6jst3v66jiQDvFC km3mjP+m0kb0ikJCMb/GGXsVlJKLJXOI1oED82s6Z2AmjmUyIcSnGsSPnUx82kgwTKRO rWjKQkNqUjL4F4X7pDwsA1hU6REa+rfTWeycv39q7UkFBLvt4qjFvULXo36tFGa/c1y4 UQ7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=0EQO+yVToe/IEz8LeEEWY+9soclzJIKIe/GK95Cfahg=; b=H1iYhEB7LTxp/r6WpPJEzm+jFIp/+BwAUQ3nc3Ucnvm6GlckZa4VrKBeJnYwAMqjHT 9TLr1kda7Hi6Xb0x2pvEyr6G1Au/ZNAUAE9RRAFgC/WiGw9QTMoeyJUn4EgrOj+qPMpZ Sw6uN5tNj78X6SbQOuIrTGY0UCQGAzWXZ1ebfxXeaw85Cii5wWnV7i5bNcJJ9kCN3fvS Bx8KTBLIQ8WNDTah1JiWExb1mjBonAbbqmcbvugcGHAKJu+CnMDhSJxKuqY6YP/O/D55 7hPWzOAYp7xvCw9T8kcU93bzhfL3ad6eVSUv/KtIHrsz02I5gOOxmGSi5RZnKlwF/Hn+ QCdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="iB8MZy/9"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ds7si5111405ejc.362.2021.10.11.18.30.49; Mon, 11 Oct 2021 18:31:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="iB8MZy/9"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234408AbhJLBYy (ORCPT + 99 others); Mon, 11 Oct 2021 21:24:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:57244 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232148AbhJLBYx (ORCPT ); Mon, 11 Oct 2021 21:24:53 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id ED35160F22 for ; Tue, 12 Oct 2021 01:22:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1634001773; bh=XM2NRJccgxND7m0Mlqsxadwo2rATHdUUDllqG1KrA20=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=iB8MZy/9A0LoAM9ynq8J8Hrn1v6AGyqG9D4Lub376hhcU1NzWLltcMAC5COselTCO HlNZJzNCk4mJdETBmTjXgCVCq9JTgJ5e+nGAF3diTdYNXRqyKptSo2MeiKdo81YTd6 DMnMOlJSGw3BE9mYC076qiQwKfEFp3OHaZY93kW+oryKcLj3dr4/h8C8rgEVNG60h9 lfWbXk9jJhpqPur16JvRSkpKEI6j7W3uQLaxGGbjruoOeLSdSXsMps0oIOyELRRGoD 18BRpmKOblQT7QMntWaQjbUctgjMXRmiJUNsntCKA1QwoLCLRtPigUXWn0K+MinpeK jtVm9Lbr5rBhA== Received: by mail-vk1-f179.google.com with SMTP id x207so8696877vke.2 for ; Mon, 11 Oct 2021 18:22:52 -0700 (PDT) X-Gm-Message-State: AOAM532koAMw5ggnggOS17G16NYIQTR0wyuFRsauXLuzYJD3K0gIphKr zZUTq3sfZpORweU2LOHO6jcpGI940pDXh9dfScQ= X-Received: by 2002:a67:ca1c:: with SMTP id z28mr27488752vsk.11.1634001772006; Mon, 11 Oct 2021 18:22:52 -0700 (PDT) MIME-Version: 1.0 References: <20211011132431.2792797-1-guoren@kernel.org> In-Reply-To: From: Guo Ren Date: Tue, 12 Oct 2021 09:22:40 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 1/2] irqchip/sifive-plic: Fix duplicate mask/unmask for claim/complete To: Anup Patel Cc: Atish Patra , Marc Zyngier , Thomas Gleixner , Palmer Dabbelt , "linux-kernel@vger.kernel.org List" , linux-riscv , Guo Ren Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Oct 11, 2021 at 11:02 PM Anup Patel wrote: > > On Mon, Oct 11, 2021 at 6:54 PM wrote: > > > > From: Guo Ren > > > > PLIC only has enable-registers not mask/unmask registers. Mixing > > mask/unmask with irq_eoi is wrong, because readl(claim) could mask > > This is an incorrect assumption about readl(claim). When SW does > read(claim) the HW updates internal state that IRQ has been claimed. > The HW can still get same (already claimed) IRQ again before > writel(claim) which will be delivered after writel(claim). Our hw would mask IRQ with readl(claim), so it's unnecessary for our board. I agree some hardware won't mask IRQ after readl(claim), so I put DT-bool to control it. > > > irq by hardware. We only need mask/unmask to fixup the hardware > > which couldn't claim + mask correctly. > > The handle_fasteoi_irq() only calls unmask_irq() mostly when the > underlying IRQ is threaded. Is there any other case ? When in handle_fasteoi_irq ONESHOT path, it will call: if (desc->istate & IRQS_ONESHOT) mask_irq(desc); mask_irq->plic_irq_mask->"write 0 to PRIORITY & ENABLE_BASE-bit" In this IRQ context, it wouldn't call unmask_irq with cond_unmask_eoi_irq when in IRQCHIP_EOI_THREADED. Then the path would writel(hwirq, claim) with irq disabled. static void cond_unmask_eoi_irq(struct irq_desc *desc, struct irq_chip *chip) { ... } else if (!(chip->flags & IRQCHIP_EOI_THREADED)) { chip->irq_eoi(&desc->irq_data); } When IRQ is disabled in c9xx, writel(hwirq, claim) would be invalid and cause a blocking irq bug. > > Another fact is that all irqchip drivers using handle_fasteoi_irq() > implement irq_mask/unmask(). C9xx needn't call mask&unmask after readl(claim), because: 1. If hw supports readl(claim) with acquiring irq then the mask/unmask is unnecessary and causes performance problems. 2. When in IRQS_ONESHOT & IRQCHIP_EOI_THREADED path, unnecessary mask operation would cause a blocking irq bug. > > Regards, > Anup > > > > > If hardware supports claim + mask, it would cause unnecessary > > mask/umak operations. > > > > Signed-off-by: Guo Ren > > Cc: Thomas Gleixner > > Cc: Marc Zyngier > > Cc: Palmer Dabbelt > > Cc: Anup Patel > > Cc: Atish Patra > > --- > > drivers/irqchip/irq-sifive-plic.c | 16 ++++++++++++---- > > 1 file changed, 12 insertions(+), 4 deletions(-) > > > > diff --git a/drivers/irqchip/irq-sifive-plic.c b/drivers/irqchip/irq-sifive-plic.c > > index cf74cfa82045..0fa46912f452 100644 > > --- a/drivers/irqchip/irq-sifive-plic.c > > +++ b/drivers/irqchip/irq-sifive-plic.c > > @@ -64,6 +64,7 @@ struct plic_priv { > > struct cpumask lmask; > > struct irq_domain *irqdomain; > > void __iomem *regs; > > + bool claim_mask_support; > > }; > > > > struct plic_handler { > > @@ -111,7 +112,7 @@ 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) > > { > > struct cpumask amask; > > unsigned int cpu; > > @@ -125,7 +126,7 @@ static void plic_irq_unmask(struct irq_data *d) > > plic_irq_toggle(cpumask_of(cpu), d, 1); > > } > > > > -static void plic_irq_mask(struct irq_data *d) > > +static void plic_irq_disable(struct irq_data *d) > > { > > struct plic_priv *priv = irq_data_get_irq_chip_data(d); > > > > @@ -168,8 +169,8 @@ static void plic_irq_eoi(struct irq_data *d) > > > > static struct irq_chip plic_chip = { > > .name = "SiFive PLIC", > > - .irq_mask = plic_irq_mask, > > - .irq_unmask = plic_irq_unmask, > > + .irq_enable = plic_irq_enable, > > + .irq_disable = plic_irq_disable, > > .irq_eoi = plic_irq_eoi, > > #ifdef CONFIG_SMP > > .irq_set_affinity = plic_set_affinity, > > @@ -181,6 +182,11 @@ static int plic_irqdomain_map(struct irq_domain *d, unsigned int irq, > > { > > struct plic_priv *priv = d->host_data; > > > > + if (!priv->claim_mask_support) { > > + plic_chip.irq_mask = plic_irq_disable; > > + plic_chip.irq_unmask = plic_irq_enable; > > + } > > + > > irq_domain_set_info(d, irq, hwirq, &plic_chip, d->host_data, > > handle_fasteoi_irq, NULL, NULL); > > irq_set_noprobe(irq); > > @@ -298,6 +304,8 @@ static int __init plic_init(struct device_node *node, > > if (WARN_ON(!nr_contexts)) > > goto out_iounmap; > > > > + priv->claim_mask_support = of_property_read_bool(node, "claim-mask-support"); > > + > > error = -ENOMEM; > > priv->irqdomain = irq_domain_add_linear(node, nr_irqs + 1, > > &plic_irqdomain_ops, priv); > > -- > > 2.25.1 > > -- Best Regards Guo Ren ML: https://lore.kernel.org/linux-csky/