Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp2285358pxb; Sun, 30 Jan 2022 10:44:03 -0800 (PST) X-Google-Smtp-Source: ABdhPJwEsl4UjISsKCp2MMZ5HAoMyfimqRKxx6Tuyz7dKFd+tvjL3iLJbMtsC00SQn0QvHfKQVZP X-Received: by 2002:a17:902:ce81:: with SMTP id f1mr18027295plg.32.1643568242921; Sun, 30 Jan 2022 10:44:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643568242; cv=none; d=google.com; s=arc-20160816; b=AbtbT7yW5E1VExUAqXJRKSfphuIf/GO3wVd3Qjln304P/LfQMTP6N1ayIYL0nlVvPO L16/s1qTYyiNR5WYL5eQ+vH5Z+h2CYBBx9HOnQe5Tzz+wRoE2qyhAYVAIUfugYG+2xEh oXGnRXV36NjY0ClX6n1um71ApMTsYPjdxmXWSfAKao35FvyvBSjI9BmHClZx9kFEA8ga tjC3X0l2z/UUSKUs8COOD03ljuI3vWthwl/ANRBbbZLsQIiKykaP/wD5u2vICEHiVUau Qpz9E2l3rmd00fINfdMuf9di2RjH/R5YiVmxwNnZMxUN88vvHqMQDG4mBwfX1cwtXCab 5xGQ== 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=tE/bIeYBEJfNdJfWdxZyv6qoycU+hvmNhDISILgrWGQ=; b=Wbwl4ID2s1ec9V2GtyBptxns+l32u1JWCcqZQJ/tANM3wElKutmE/8mQDcnQiSS1nL eK2HJ8P7ofhj9cGMiNOdQWdneSt3eUhX4IbY8DDAcTlhmX+Rzx+llqm7T/SquslmxMXk hpkBHqeg3PV++7RQN7eam/K5CWiWMP82mF8V1E6sYbHge8x3ih1ZXn8Cs8kduDpfIvFB oI931QS1nwGZPmDyrEaKAXGC+EagiG9skBJ2N3fiMUkW1Ba5yraDt4OIuFkyMKZlcUpF FR3Q23HChNbqAqfLxxJPW8PL70P41UUXKm12nzUV+1OescDk1ZPjjY/Io6n7UVxzk+jI lp/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="hfnsg/b/"; 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 w63si5111537pgd.879.2022.01.30.10.43.37; Sun, 30 Jan 2022 10:44:02 -0800 (PST) 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="hfnsg/b/"; 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 S230314AbiA1I5W (ORCPT + 99 others); Fri, 28 Jan 2022 03:57:22 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:41558 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229847AbiA1I5U (ORCPT ); Fri, 28 Jan 2022 03:57:20 -0500 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 440B961DB4; Fri, 28 Jan 2022 08:57:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A508EC340E0; Fri, 28 Jan 2022 08:57:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1643360239; bh=eA0GRKE5jNFxledJDISs9E2n145awy0LOLWI3Kj0OCw=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=hfnsg/b/fnzfO7W3HdljYTzrlb2uSKZmWuNmXxQxBjBzTF4/87QiwUfhBOrUqcQ9o VqEpBVJ/09By38KslCaSZifpWNtzGRrqT45RbhqLwii/m0Ve4CMGsEk1YGj62kQ88y Te0x0ARTckdiSvT1Be6JX4lYnidxJvX3ceXUi/Csn+xeebovSgHtaiqQF0+pzCyf+5 zT4AgmPr6dH0hYgSdc8kPg6pYsU7P877Gkc1fdKVjATVVBfFesDB/1L9PQ480J5MrB xfL5EjeMNo1drRYV1uYTG0Iqr8bmMqj7aljAsGvNS/gNE0I9zjBy0Us89b2NHJGt69 9Y5CvGzyJFhgg== 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 1nDN4H-003lDg-8T; Fri, 28 Jan 2022 08:57:17 +0000 Date: Fri, 28 Jan 2022 08:57:16 +0000 Message-ID: <87r18s5jbn.wl-maz@kernel.org> From: Marc Zyngier To: Bjorn Helgaas Cc: "qizhong.cheng" , Ryder Lee , Jianjun Wang , Lorenzo Pieralisi , Krzysztof =?UTF-8?B?V2lsY3p5xYRz?= =?UTF-8?B?a2k=?= , Bjorn Helgaas , linux-pci@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, chuanjia.liu@mediatek.com, Srikanth Thokala , Pratyush Anand , Thomas Petazzoni , Pali =?UTF-8?B?Um9ow6Fy?= Subject: Re: [PATCH] PCI: mediatek: Change MSI interrupt processing sequence In-Reply-To: <20220127212100.GA102267@bhelgaas> References: <20220127212100.GA102267@bhelgaas> 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: helgaas@kernel.org, qizhong.cheng@mediatek.com, ryder.lee@mediatek.com, jianjun.wang@mediatek.com, lorenzo.pieralisi@arm.com, kw@linux.com, bhelgaas@google.com, linux-pci@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, chuanjia.liu@mediatek.com, srikanth.thokala@intel.com, pratyush.anand@gmail.com, thomas.petazzoni@bootlin.com, pali@kernel.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 27 Jan 2022 21:21:00 +0000, Bjorn Helgaas wrote: > > [+cc Srikanth, Pratyush, Thomas, Pali, Ryder, Jianjun] > > On Wed, Jan 26, 2022 at 11:37:58AM +0800, qizhong.cheng wrote: > > On Tue, 2022-01-25 at 17:21 +0000, Marc Zyngier wrote: > > > On 2022-01-25 16:57, Bjorn Helgaas wrote: > > > > On Sun, Jan 23, 2022 at 11:33:06AM +0800, qizhong cheng wrote: > > > > > As an edge-triggered interrupts, its interrupt status should > > > > > be cleared before dispatch to the handler of device. > > > > > > > > I'm not an IRQ expert, but the reasoning that "we should clear > > > > the MSI interrupt status before dispatching the handler because > > > > MSI is an edge-triggered interrupt" doesn't seem completely > > > > convincing because your code will now look like this: > > > > > > > > /* Clear the INTx */ > > > > writel(1 << bit, port->base + PCIE_INT_STATUS); > > > > generic_handle_domain_irq(port->irq_domain, bit - INTX_SHIFT); > > > > ... > > > > > > > > /* Clear MSI interrupt status */ > > > > writel(MSI_STATUS, port->base + PCIE_INT_STATUS); > > > > generic_handle_domain_irq(port->inner_domain, bit); > > > > > > > > You clear interrupt status before dispatching the handler for > > > > *both* level-triggered INTx interrupts and edge-triggered MSI > > > > interrupts. > > > > > > > > So it doesn't seem that simply being edge-triggered is the > > > > critical factor here. > > > > > > This is the usual problem with these half-baked implementations. > > > The signalling to the primary interrupt controller is level, as > > > they take a multitude of input and (crucially) latch the MSI > > > edges. Effectively, this is an edge-to-level converter, with all > > > the problems that this creates. > > > > > > By clearing the status *after* the handling, you lose edges that > > > have been received and coalesced after the read of the status > > > register. By clearing it *before*, you are acknowledging the > > > interrupts early, and allowing them to be coalesced independently > > > of the ones that have been received earlier. > > > > > > This is however mostly an educated guess. Someone with access to > > > the TRM should verify this. > > > > Yes, as Maz said, we save the edge-interrupt status so that it > > becomes a level-interrupt. This is similar to an edge-to-level > > converter, so we need to clear it *before*. We found this problem > > through a lot of experiments and tested this patch. > > I thought there might be other host controllers with similar design, > so I looked at all the other drivers and tried to figure out whether > any others had similar problems. > > The ones below look suspicious to me because they all clear some sort > of status register *after* handling an MSI. Can you guys take a look > and make sure they are working correctly? > > keembay_pcie_msi_irq_handler > status = readl(pcie->apb_base + PCIE_REGS_INTERRUPT_STATUS) > if (status & MSI_CTRL_INT) > dw_handle_msi_irq > generic_handle_domain_irq > writel(status, pcie->apb_base + PCIE_REGS_INTERRUPT_STATUS) > > spear13xx_pcie_irq_handler > status = readl(&app_reg->int_sts) > if (status & MSI_CTRL_INT) > dw_handle_msi_irq > generic_handle_domain_irq > writel(status, &app_reg->int_clr) I think these two are fine. The top level interrupt is only a level signal that the is something to process. The only thing that is unclear is what the effect of writing to that status register if MSIs are pending at that point. A sane implementation would just ignore the write. The actual processing is done in dw_handle_msi_irq(), reading the PCIE_MSI_INTR0_STATUS register. This same register is then used to Ack the interrupt, one bit at a time, as interrupts are handled (see dw_pci_bottom_ack). Ack taking place before the handling, it makes it safe for edge delivery. > > advk_pcie_handle_int > isr0_status = advk_readl(pcie, PCIE_ISR0_REG) > if (isr0_status & PCIE_ISR0_MSI_INT_PENDING) > advk_pcie_handle_msi > advk_readl(pcie, PCIE_MSI_STATUS_REG) > advk_writel(pcie, BIT(msi_idx), PCIE_MSI_STATUS_REG) > generic_handle_irq > advk_writel(pcie, PCIE_ISR0_MSI_INT_PENDING, PCIE_ISR0_REG) Same thing, I guess. It is just that the Ack has been open-coded. > > mtk_pcie_irq_handler > status = readl_relaxed(pcie->base + PCIE_INT_STATUS_REG) > for_each_set_bit_from(irq_bit, &status, ...) > mtk_pcie_msi_handler > generic_handle_domain_irq > writel_relaxed(BIT(irq_bit), pcie->base + PCIE_INT_STATUS_REG) Similar thing. The PCIE_MSI_SET_STATUS register is read first, and then written back in the ack callback. M. -- Without deviation from the norm, progress is not possible.