From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A1866CCD193 for ; Tue, 14 Oct 2025 17:12:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:MIME-Version: References:In-Reply-To:Subject:Cc:To:From:Message-ID:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=ZDbqcyy++B1euioUD3Ql+oqjIl6l5PHIe4SI0jwIuuE=; b=10PCFdGykpnLUVPxb9mh1s2dB3 tjDSStjVCEWYexLjI00mWx+GXX91OO76a0BiRhTEIIOivbZfxyVtcuDby12scP0+k6RfnnlAAXM/P 5SOaHFfp92qnFAQgTXQRQoh6bl6lAit0jADOZ3GCVeUe9AYxp7I/VlvNtiNh9FXw489uK03NtZiZk N2P/Bxz/4RQGMP+K9MeKpnrc/keSHgtrmVpQUMZXnXI4BZheqkCpm3SU3vin6qPxi2I29TgEp2DLo lpewYn28Qms5lb7nfepxWd9wIl10lnr65jl4hEDsJZbShx5MTwwke9HQ77j/FBeQKpovrRv8pfX4X nGSmrRbg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1v8iZT-0000000H40m-0RBm; Tue, 14 Oct 2025 17:12:23 +0000 Received: from sea.source.kernel.org ([172.234.252.31]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1v8iZR-0000000H409-0p37 for linux-arm-kernel@lists.infradead.org; Tue, 14 Oct 2025 17:12:22 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id 55F6A40869; Tue, 14 Oct 2025 17:12:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0F517C4CEE7; Tue, 14 Oct 2025 17:12:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1760461939; bh=gUQLj+zrhbIXqImMpcwbt9bYrEb+FWMkhQNFTbc7ep0=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=kJ0SEbtrirjPrgwEKqk+LXVr9DF5kZmPFkeMtMt8UIPY+AeK5G4QzrZkd7hdHbhXN Hr83y0BeFfrjyUpA8q3LZXnDigrPHd9IkWyEkeLF4ipOEuwSORfVhjlLYk1M0xGYxR Rs0shzhHXJV9GmfyGyCogRSZRG570XMbb53SkzKW6QlZl+bXlXma4JvFtNI4eQ2819 OHGDJnkXeVmeSPFIeTuFp0NSJGlCY61WYGRDUiSoKwPH85ax9S5yzo1ENb9QJqrVIQ SfjOiyiHdMh1yRcRG+czeOMwRYenW0e+4TbeZjdU64OAvGq/30Ze7m/eGEt59GHDUf Dm/LvYsiEDneQ== Received: from 82-132-238-238.dab.02.net ([82.132.238.238] helo=lobster-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1v8iZM-0000000Dwp9-2kHH; Tue, 14 Oct 2025 17:12:17 +0000 Date: Tue, 14 Oct 2025 18:12:11 +0100 Message-ID: <87ecr5xv9w.wl-maz@kernel.org> From: Marc Zyngier To: Lorenzo Pieralisi Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-pci@vger.kernel.org, Sascha Bischoff , Thomas Gleixner , Rob Herring , Frank Li , Scott Branden , Bjorn Helgaas , Ray Jui , Manivannan Sadhasivam , Krzysztof =?UTF-8?B?V2lsY3p5xYRza2k=?= Subject: Re: [PATCH v2 4/4] irqchip/gic-its: Rework platform MSI deviceID detection In-Reply-To: <20251014095845.1310624-5-lpieralisi@kernel.org> References: <20251014095845.1310624-1-lpieralisi@kernel.org> <20251014095845.1310624-5-lpieralisi@kernel.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/30.1 (aarch64-unknown-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: 82.132.238.238 X-SA-Exim-Rcpt-To: lpieralisi@kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-pci@vger.kernel.org, sascha.bischoff@arm.com, tglx@linutronix.de, robh@kernel.org, Frank.Li@nxp.com, sbranden@broadcom.com, bhelgaas@google.com, rjui@broadcom.com, mani@kernel.org, kwilczynski@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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20251014_101221_301365_546A2E76 X-CRM114-Status: GOOD ( 34.50 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Tue, 14 Oct 2025 10:58:45 +0100, Lorenzo Pieralisi wrote: > > Current code retrieving platform devices MSI devID in the GIC ITS MSI > parent helpers suffers from some minor issues: > > - It leaks a struct device_node reference > - It triggers an excessive WARN_ON on wrong of_phandle_args count detection Well, if your DT is that rotten, maybe you actually deserve some console spamming, don't you think? > - It is duplicated between GICv3 and GICv5 for no good reason > - It does not use the OF phandle iterator code that simplifies > the msi-parent property parsing > > Implement a helper function that addresses the full set of issues in one go > by consolidating GIC v3 and v5 code and converting the msi-parent parsing > loop to the more modern OF phandle iterator API, fixing the > struct device_node reference leak in the process. > > Signed-off-by: Lorenzo Pieralisi > Cc: Sascha Bischoff > Cc: Thomas Gleixner > Cc: Rob Herring > Cc: Frank Li > Cc: Marc Zyngier > --- > drivers/irqchip/irq-gic-its-msi-parent.c | 98 ++++++++---------------- > 1 file changed, 33 insertions(+), 65 deletions(-) > > diff --git a/drivers/irqchip/irq-gic-its-msi-parent.c b/drivers/irqchip/irq-gic-its-msi-parent.c > index eb1473f1448a..a65f762b7dd4 100644 > --- a/drivers/irqchip/irq-gic-its-msi-parent.c > +++ b/drivers/irqchip/irq-gic-its-msi-parent.c > @@ -142,83 +142,51 @@ static int its_v5_pci_msi_prepare(struct irq_domain *domain, struct device *dev, > #define its_v5_pci_msi_prepare NULL > #endif /* !CONFIG_PCI_MSI */ > > -static int of_pmsi_get_dev_id(struct irq_domain *domain, struct device *dev, > - u32 *dev_id) > +static int __of_pmsi_get_dev_id(struct irq_domain *domain, struct device *dev, u32 *dev_id, > + phys_addr_t *pa, bool is_v5) > { > - int ret, index = 0; > + struct of_phandle_iterator it; > + uint32_t args; Use u32, this is not userspace-visible (the OF code will cope). And move it to where it matters instead of having such a wide scope. > + int ret; > > /* Suck the DeviceID out of the msi-parent property */ > - do { > - struct of_phandle_args args; > + of_for_each_phandle(&it, ret, dev->of_node, "msi-parent", "#msi-cells", -1) { > + /* GICv5 ITS domain matches the MSI controller node parent */ > + struct device_node *np __free(device_node) = is_v5 ? of_get_parent(it.node) > + : of_node_get(it.node); > > - ret = of_parse_phandle_with_args(dev->of_node, > - "msi-parent", "#msi-cells", > - index, &args); > - if (args.np == irq_domain_get_of_node(domain)) { > - if (WARN_ON(args.args_count != 1)) > - return -EINVAL; > - *dev_id = args.args[0]; > - break; > + if (np == irq_domain_get_of_node(domain)) { > + if (of_phandle_iterator_args(&it, &args, 1) != 1) { > + dev_warn(dev, "Bogus msi-parent property\n"); > + ret = -EINVAL; > + } > + > + if (!ret && is_v5) > + ret = its_translate_frame_address(it.node, pa); Why do you need this is_v5 hack, since the only case were you pass a pointer to get the translate register address is for v5? > + > + if (!ret) > + *dev_id = args; > + > + of_node_put(it.node); > + return ret; > } > - index++; > - } while (!ret); > - > - if (ret) { > - struct device_node *np = NULL; > - > - ret = of_map_id(dev->of_node, dev->id, "msi-map", "msi-map-mask", &np, dev_id); > - if (np) > - of_node_put(np); > } > > - return ret; > + struct device_node *msi_ctrl __free(device_node) = NULL; > + > + return of_map_id(dev->of_node, dev->id, "msi-map", "msi-map-mask", &msi_ctrl, dev_id); > +} > + > +static int of_pmsi_get_dev_id(struct irq_domain *domain, struct device *dev, > + u32 *dev_id) > +{ > + return __of_pmsi_get_dev_id(domain, dev, dev_id, NULL, false); > } At this stage, we really don't need these on-liners, as they only obfuscate the logic. Just use the main helper directly. Something like the hack below. M. diff --git a/drivers/irqchip/irq-gic-its-msi-parent.c b/drivers/irqchip/irq-gic-its-msi-parent.c index a65f762b7dd4d..7c82fd152655e 100644 --- a/drivers/irqchip/irq-gic-its-msi-parent.c +++ b/drivers/irqchip/irq-gic-its-msi-parent.c @@ -142,26 +142,27 @@ static int its_v5_pci_msi_prepare(struct irq_domain *domain, struct device *dev, #define its_v5_pci_msi_prepare NULL #endif /* !CONFIG_PCI_MSI */ -static int __of_pmsi_get_dev_id(struct irq_domain *domain, struct device *dev, u32 *dev_id, - phys_addr_t *pa, bool is_v5) +static int of_pmsi_get_msi_info(struct irq_domain *domain, struct device *dev, u32 *dev_id, + phys_addr_t *pa) { struct of_phandle_iterator it; - uint32_t args; int ret; /* Suck the DeviceID out of the msi-parent property */ of_for_each_phandle(&it, ret, dev->of_node, "msi-parent", "#msi-cells", -1) { /* GICv5 ITS domain matches the MSI controller node parent */ - struct device_node *np __free(device_node) = is_v5 ? of_get_parent(it.node) + struct device_node *np __free(device_node) = pa ? of_get_parent(it.node) : of_node_get(it.node); if (np == irq_domain_get_of_node(domain)) { + u32 args; + if (of_phandle_iterator_args(&it, &args, 1) != 1) { dev_warn(dev, "Bogus msi-parent property\n"); ret = -EINVAL; } - if (!ret && is_v5) + if (!ret && pa) ret = its_translate_frame_address(it.node, pa); if (!ret) @@ -177,18 +178,6 @@ static int __of_pmsi_get_dev_id(struct irq_domain *domain, struct device *dev, u return of_map_id(dev->of_node, dev->id, "msi-map", "msi-map-mask", &msi_ctrl, dev_id); } -static int of_pmsi_get_dev_id(struct irq_domain *domain, struct device *dev, - u32 *dev_id) -{ - return __of_pmsi_get_dev_id(domain, dev, dev_id, NULL, false); -} - -static int of_v5_pmsi_get_msi_info(struct irq_domain *domain, struct device *dev, - u32 *dev_id, phys_addr_t *pa) -{ - return __of_pmsi_get_dev_id(domain, dev, dev_id, pa, true); -} - int __weak iort_pmsi_get_dev_id(struct device *dev, u32 *dev_id) { return -1; @@ -202,7 +191,7 @@ static int its_pmsi_prepare(struct irq_domain *domain, struct device *dev, int ret; if (dev->of_node) - ret = of_pmsi_get_dev_id(domain->parent, dev, &dev_id); + ret = of_pmsi_get_msi_info(domain->parent, dev, &dev_id, NULL); else ret = iort_pmsi_get_dev_id(dev, &dev_id); if (ret) @@ -230,7 +219,7 @@ static int its_v5_pmsi_prepare(struct irq_domain *domain, struct device *dev, if (!dev->of_node) return -ENODEV; - ret = of_v5_pmsi_get_msi_info(domain->parent, dev, &dev_id, &pa); + ret = of_pmsi_get_msi_info(domain->parent, dev, &dev_id, &pa); if (ret) return ret; -- Jazz isn't dead. It just smells funny.