Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp91162lqb; Tue, 28 May 2024 09:36:24 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVgBNGqmB7AYPBcOmv0NhHE1enyPTeEAl/DinwC1ecOpskHb21BCpZSS1BbMw1rydSyVZedOC76vvcdruspENMoEkQkPJyAgxp77hO33g== X-Google-Smtp-Source: AGHT+IE9skv6In/uB0vvRUusyPTAC8FKQI/Al9RCulfeH1EnShHCCj99Myh2FhEYu6kt3Z/H/mjV X-Received: by 2002:a05:620a:a19:b0:790:f843:db57 with SMTP id af79cd13be357-794ab0f8b0bmr1326363185a.58.1716914184678; Tue, 28 May 2024 09:36:24 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716914184; cv=pass; d=google.com; s=arc-20160816; b=rlqmpc3C6Ta9QJMn6J0X1hUgx43NTd6MpGLMFIwi4UJco9FC57IdmVfrCXmjfQ7YlT NC1ISU637Kf4LsjIaPJh10sC2YUHbAU0ByeAAuL/aO6IR+ckhBxCsZVCQf3rewRcZCeL hAQHTaFVC0OW0I/nVS07Z3861M6UVbwSIM2MIAAicLyEFMKUE4toMZt1iVRk+7Rqmyyu 36ZD/V6i8KmjLchkKY7jaDxAF0CdX4Z6UrDZ88tAOhYL/vqO4t9+LKChtPAS2l3ZbDhT JFxb+c6cj1EDSFxelE9+jCbgWm6YZZ1xr7Z76de6heyzjbVrQou9WSMYzu39a7UgaAuF ckBQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :user-agent:references:in-reply-to:subject:cc:to:from:message-id :date:dkim-signature; bh=kZoQ+JrWmvsZAKNYY6JmH+sRBrhtFf76CJMIJ9naT9k=; fh=GYLX6/jX0KdsmTqUqTFxfBFTGJpaSXoT/AQni1BWsDg=; b=cZiZteJrjPGwj/6pCBEZXhsg/1qeCGcjk9PbPW8ocmDA0Wyywjh/pQ6iP5yhHuB890 S1ZWHNS2eVunWJlf50t+uq/rurJP2nX+b8Zb8+PZgNRwHa99x0PD3+Pb1pc6+7ie4Qir bqCau6Q2qvvydDHxYCaXVgOxSHV3fPC5SihHuBk7a2HbXmP8ifH/fAMkIsNr5PI80fcY VnSTbxgo2IB9RKjKq47gWeyv03aLywi1LqRK5061cl3fT8WpKNOanESwVesCvBLfDj/u nVwciSMbCHKBKwoGU4WvPxEtVDmMnvMvxwH1bkgu4xQDsYVQX2NXOoz3bMliPP90bZ57 pCqQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=to9eUQna; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-192760-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-192760-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id af79cd13be357-794abd141d7si1168621785a.278.2024.05.28.09.36.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 09:36:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-192760-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=to9eUQna; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-192760-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-192760-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 5AD051C22983 for ; Tue, 28 May 2024 16:36:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DA6FD172BC1; Tue, 28 May 2024 16:36:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="to9eUQna" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D49E3F9D6; Tue, 28 May 2024 16:36:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716914177; cv=none; b=llyLSHZF3zG/lcmEOgrbf6HywGnJGrlCPyHS5+gOUdvA7t3HTsFcgxY79WEH4I9JXN60Uwn1MPQ7K768bDPp/883GUYA8kUknlLAFJUz4pSezdvHGV6LwWzqRSOprm6EA+7UbpgWsqIksXav8kgMDQ7+yFaF38EIU4rIsgORd7s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716914177; c=relaxed/simple; bh=NuefzrUj9FO/t6wc3pR2TCeJn0nDqx9DSuM502grMnQ=; h=Date:Message-ID:From:To:Cc:Subject:In-Reply-To:References: MIME-Version:Content-Type; b=rRAudfS+efjJ9IkVpT9/10vZneEXEFTgC5Jdjzxw45kf7VeOM4WNZDCkmAQ/m5dj9o/qDejxw6VVkYWF2/hyJUWAoU5lEkIkPoLjB1mFvsreFMYdRfM93N4ZDF5J+SGhHviof7hNLKS4yeKCN26rCaSGHaBa/+a2ZLR3yQtat6g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=to9eUQna; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4BBF4C3277B; Tue, 28 May 2024 16:36:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716914177; bh=NuefzrUj9FO/t6wc3pR2TCeJn0nDqx9DSuM502grMnQ=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=to9eUQnaJbyB7NCzJ2G4rbqeNYs95A7m70tx9yOFS+k39aec+WOxXgptyeEFQ9uIV PBt5BTLemlb5fAei1Sh+nhoO4t2l4X/AZnerO88r0qBjBI68FlKOWAoInpfg1nBivx dGKkV2d+D4Dwf+exD/Wn3qPLgzxjnLLZlFu3en8GHPagFjuW2tFsL+7u2GiA/3D/ZL FnXeRLtkz4FVYOH0kLVoOKKZuPkN2ZxX2bvLk87+LryQQxoiNuO9qc2ja4uRPYL2k7 F/KsXvNzc4kX+h4zWwx4yx9ZN2zU6e9wH/nMACyNnKlWxWfhZS/lyk1aQF2olZQ983 s3xGwztL+4Rrw== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1sBzo6-00GNJS-Sr; Tue, 28 May 2024 17:36:15 +0100 Date: Tue, 28 May 2024 17:36:14 +0100 Message-ID: <86ed9lnbb5.wl-maz@kernel.org> From: Marc Zyngier To: Anup Patel Cc: Rob Herring , Saravana Kannan , Palmer Dabbelt , Paul Walmsley , Atish Patra , Andrew Jones , Sunil V L , Anup Patel , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Subject: Re: [PATCH v4] of: property: Add fw_devlink support for interrupt-map property In-Reply-To: <20240509120820.1430587-1-apatel@ventanamicro.com> References: <20240509120820.1430587-1-apatel@ventanamicro.com> 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/29.2 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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: apatel@ventanamicro.com, robh@kernel.org, saravanak@google.com, palmer@dabbelt.com, paul.walmsley@sifive.com, atishp@atishpatra.org, ajones@ventanamicro.com, sunilvl@ventanamicro.com, anup@brainfault.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@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 On Thu, 09 May 2024 13:08:20 +0100, Anup Patel wrote: > > Some of the PCI host controllers (such as generic PCI host controller) > use "interrupt-map" DT property to describe the mapping between PCI > endpoints and PCI interrupt pins. This is the only case where the > interrupts are not described in DT. > > Currently, there is no fw_devlink created based on "interrupt-map" > DT property so interrupt controller is not guaranteed to be probed > before the PCI host controller. This affects every platform where > both PCI host controller and interrupt controllers are probed as > regular platform devices. > > This creates fw_devlink between consumers (PCI host controller) and > supplier (interrupt controller) based on "interrupt-map" DT property. > > Signed-off-by: Anup Patel > Reviewed-by: Saravana Kannan > --- > Changes since v3: > - Added a comment about of_irq_parse_raw() > - Removed redundant NULL assignments to sup_args.np > Changes since v2: > - No need for a loop to find #interrupt-cells property value > - Fix node de-reference leak when index is greater than number > of entries in interrupt-map property > Changes since v1: > - Updated commit description based on Rob's suggestion > - Use of_irq_parse_raw() for parsing interrupt-map DT property This patch breaks badly on my M1 Mini, with a continuous stream of boot time warnings lasting about 100 seconds: [ 97.832335] ------------[ cut here ]------------ [ 97.836955] /soc/pcie@690000000/pci@2,0 interrupt-map failed, using interrupt-controller [ 97.845072] WARNING: CPU: 0 PID: 1 at drivers/of/irq.c:277 of_irq_parse_raw+0x620/0x730 [ 97.853087] Modules linked in: [ 97.856139] CPU: 0 PID: 1 Comm: swapper/0 Tainted: G W 6.10.0-rc1 #2915 [ 97.864163] Hardware name: Apple Mac mini (M1, 2020) (DT) [ 97.869570] pstate: 61400009 (nZCv daif +PAN -UAO -TCO +DIT -SSBS BTYPE=--) [ 97.876546] pc : of_irq_parse_raw+0x620/0x730 [ 97.880907] lr : of_irq_parse_raw+0x620/0x730 [ 97.885267] sp : ffffc000800538a0 [ 97.888581] x29: ffffc000800538a0 x28: 0000000000000000 x27: ffffffffff5ffc68 [ 97.895732] x26: ffffc000800539a4 x25: ffffffffff5ffbbc x24: ffffc00080053a48 [ 97.902883] x23: ffffe3ff73284e68 x22: ffffb7889aede6d0 x21: ffffe3ff735f9320 [ 97.910034] x20: ffffc00080053964 x19: ffffb7889aede6d0 x18: ffffffffffffffff [ 97.917185] x17: 7075727265746e69 x16: 20676e697375202c x15: 64656c6961662070 [ 97.924336] x14: 616d2d7470757272 x13: 72656c6c6f72746e x12: 6f632d7470757272 [ 97.931487] x11: 65746e6920676e69 x10: ffffe3ff740bcb68 x9 : ffffe3ff72335b38 [ 97.938639] x8 : 00000001000028a4 x7 : ffffe3ff740afc08 x6 : 00000000000038a4 [ 97.945789] x5 : 00000000000067b0 x4 : c0000001000028a4 x3 : 0000000000000000 [ 97.952940] x2 : 0000000000000000 x1 : 0000000000000000 x0 : ffffb784c16ade00 [ 97.960092] Call trace: [ 97.962534] of_irq_parse_raw+0x620/0x730 [ 97.966545] parse_interrupt_map+0xfc/0x188 [ 97.970731] of_fwnode_add_links+0x170/0x1e0 [ 97.975004] fw_devlink_parse_fwtree+0x44/0x98 [ 97.979452] fw_devlink_parse_fwtree+0x6c/0x98 [ 97.983899] fw_devlink_parse_fwtree+0x6c/0x98 [ 97.988347] device_add+0x610/0x6a8 [ 97.991836] of_device_add+0x4c/0x70 [ 97.995411] of_platform_device_create_pdata+0xa0/0x160 [ 98.000644] of_platform_bus_create+0x184/0x370 [ 98.005178] of_platform_populate+0x68/0x160 [ 98.009451] of_platform_default_populate_init+0xf4/0x118 [ 98.014859] do_one_initcall+0x4c/0x320 [ 98.018695] do_initcalls+0xf4/0x1d8 [ 98.022271] kernel_init_freeable+0x12c/0x280 [ 98.026632] kernel_init+0x2c/0x1f8 [ 98.030120] ret_from_fork+0x10/0x20 [ 98.033696] ---[ end trace 0000000000000000 ]--- which comes from 10a20b34d735f ("of/irq: Don't ignore interrupt-controller when interrupt-map failed"). Each of the 3 PCIe ports are described as such: port02: pci@2,0 { device_type = "pci"; reg = <0x1000 0x0 0x0 0x0 0x0>; reset-gpios = <&pinctrl_ap 33 GPIO_ACTIVE_LOW>; #address-cells = <3>; #size-cells = <2>; ranges; interrupt-controller; #interrupt-cells = <1>; interrupt-map-mask = <0 0 0 7>; interrupt-map = <0 0 0 1 &port02 0 0 0 0>, <0 0 0 2 &port02 0 0 0 1>, <0 0 0 3 &port02 0 0 0 2>, <0 0 0 4 &port02 0 0 0 3>; status = "disabled"; }; and get probed *972 times*, which seem... excessive, given that there are only 4 entries per port. > --- > drivers/of/property.c | 52 +++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 52 insertions(+) > > diff --git a/drivers/of/property.c b/drivers/of/property.c > index a6358ee99b74..2d749a18b037 100644 > --- a/drivers/of/property.c > +++ b/drivers/of/property.c > @@ -1311,6 +1311,57 @@ static struct device_node *parse_interrupts(struct device_node *np, > return of_irq_parse_one(np, index, &sup_args) ? NULL : sup_args.np; > } > > +static struct device_node *parse_interrupt_map(struct device_node *np, > + const char *prop_name, int index) > +{ > + const __be32 *imap, *imap_end, *addr; > + struct of_phandle_args sup_args; > + u32 addrcells, intcells; > + int i, imaplen; > + > + if (!IS_ENABLED(CONFIG_OF_IRQ)) > + return NULL; > + > + if (strcmp(prop_name, "interrupt-map")) > + return NULL; > + > + if (of_property_read_u32(np, "#interrupt-cells", &intcells)) > + return NULL; > + addrcells = of_bus_n_addr_cells(np); > + > + imap = of_get_property(np, "interrupt-map", &imaplen); > + if (!imap || imaplen <= (addrcells + intcells)) This is "interesting". You compare a number of *bytes* with a number of cells. Only off by a factor of 4... Also, you need a minimum of one extra cell to hold the phandle, and a yet unknown number of cells for whatever follows the phandle. > + return NULL; > + imap_end = imap + imaplen; Same problem, with pointer arithmetic this time. > + > + while (imap < imap_end) { > + addr = imap; > + imap += addrcells; > + > + sup_args.np = np; > + sup_args.args_count = intcells; > + for (i = 0; i < intcells; i++) > + sup_args.args[i] = be32_to_cpu(imap[i]); > + imap += intcells; > + > + /* > + * Upon success, the function of_irq_parse_raw() returns > + * interrupt controller DT node pointer in sup_args.np. > + */ > + if (of_irq_parse_raw(addr, &sup_args)) > + return NULL; > + > + if (!index) > + return sup_args.np; > + > + of_node_put(sup_args.np); > + imap += sup_args.args_count + 1; This really doesn't map (pun intended) to the way the interrupt-map entries are built. You need to account for the parent address size as well. I'll post a patch fixing both issues. M. -- Without deviation from the norm, progress is not possible.