Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp445867lqb; Tue, 28 May 2024 23:34:06 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVuBoDh7HYN8sm51q6BWTwvdbda82KVaANeSN4kNvYsNN7Vzumi0SvWq/OfuzhT6MhEPAqv5iOy4faUtCcHszcJqxXlJ5lEtFmH+QV89g== X-Google-Smtp-Source: AGHT+IGZ/sxy3qjpNk/SrI3Kksew7lAa114n+ielTGDi85WKM5Ch1iy0g0VAw72kXdx5dsatKBld X-Received: by 2002:a17:907:9715:b0:a62:c77c:b7ab with SMTP id a640c23a62f3a-a62c77cb8c2mr813594366b.51.1716964446374; Tue, 28 May 2024 23:34:06 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716964446; cv=pass; d=google.com; s=arc-20160816; b=DAZi350qdF+lsaY/1B1Pt096dnzNVbdYbN9Mtp9OfmuN9oiRASsc21IehZ7uY/yxI8 E68M86u0SdGvkZtx8Rf+NpKUrjkaltq4WeU9K/caaALH/MKny4jijf/uTsJ1pK9T3/kE 770Bj5lpeWPuhihxWVPCBDLzw16nx8NZzsMuHOmCjM2TYx84UWWWIwDi7/cvsqtb9XK4 Y4s2exglr0hdDcfqS+RDkKlTb2YRnHyyVmQr2Qhu03ZwyDzY+qAViHNk6UD48OJhcdHs QnIJcpJU3m+PK+3RBairMFlCQv7UtM9QZn5QlpauEPbSNt86Zb5vkdD6frv2/T8YiLR3 cf/A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding: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=yHJ5sEFCcNwm7rpCSXVbX9DdocsWxIJJAbFUYVTSA98=; fh=vM6X/2iVJ/nTV7scBtqzBhrRH0FLTaCmRVj+vLEamk0=; b=og/MVag3CIJz/7G2EgHMIulIreYkv6sPAYuV45+s8LYiO9XinaiU29Oj8XWVHi/2a4 St5MR8byztxQgKYCw7y3+/lCRJIhhqKt2lgD7oGIbVAwSGwAgyMDnSAh3Ix5XfUAJvvD TYFAsQbYxnZf9L2+HafVs6doMQRh0nI7STXiBsJSwcLTPsIEVQnzH+ARhIIi248GCR3b plW8UuZ0nHb4GrCU0gcHOAQ/d9xYHfAfajzWKyO2zfy1j8dceUQ+mC+sdbZyEG7EVVqT VldFbCKKx2xXhgIO1unDznwX5+7nD8wg2VPgNIT6cuZLeFbIIk1N3YFzCwtXedJsldo1 YoSA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="tVpSvj/O"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-193519-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-193519-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a626cdd3ee4si582175666b.1032.2024.05.28.23.34.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 23:34:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-193519-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="tVpSvj/O"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-193519-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-193519-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 am.mirrors.kernel.org (Postfix) with ESMTPS id C9ADF1F25A4B for ; Wed, 29 May 2024 06:34:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4390715CD71; Wed, 29 May 2024 06:33:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="tVpSvj/O" 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 530FE46453; Wed, 29 May 2024 06:33:56 +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=1716964437; cv=none; b=VLQorfdTKSOl2M2MWeaEFHqiERRYoEb9YkrmcCopfcZevSgbtwxsjfQYm+bmXlDUHWjpWZiMDqcwml3Z72L5jhsDkex/v3LPsli6fIP/2rVwG7HPW1VvIQJbtTCwSXxa4NfTSBtYMNsSFVfWp4YaIm9zlMavtB/OoZ/CaeTAptM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716964437; c=relaxed/simple; bh=fxXSALfm/c/HrxXm8QMdN0iSEYCmwD7QCKfdmRnr0XQ=; h=Date:Message-ID:From:To:Cc:Subject:In-Reply-To:References: MIME-Version:Content-Type; b=faWqiJMtfVSTMoMFzjcMOWP/UMqNatacGRWEPGx7/S4sHu+TVgBwtgxuD4FlA9jptE9wVvY5eCHugmQplHXGUEUJbxTmwb/tVYkFluAFV1JykWxKEirkvL/KhAO4cO9fusSaZz+eUedzYFotSYZdvUrL4ToFfrQRREN6zMzCx7U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tVpSvj/O; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id C598EC2BD10; Wed, 29 May 2024 06:33:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716964436; bh=fxXSALfm/c/HrxXm8QMdN0iSEYCmwD7QCKfdmRnr0XQ=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=tVpSvj/OVQ62qQPEyMQsW3zn89J5ul/51rrXGCGOJHaEr/csM+IwYCN5+qhCh+ThC DvtCSVC03Xz1TK4K8ExhZ3hXQQ5G2I13SeNE8ZYDBzQV/W+EL/zfsISpOIVk77bDqo Ak/WIGBHNqxLxkah0IDOtbVUVV9uR/vmnR4RbcKWWlwXGbHXOWMUhwqlbKigHNAfVd U5jMbbmQeKA5z0a2uIvD6IGD+upkjilFHUWGxyvIdKRw1hpmnouhmZlwh1vYhBLXH8 BpczrsRIz2rFv1Kj8W0iqu8p0RPjNkY0USjjIG9PJHzwzwc1vE+ahJCQ4bcn2Frjjt CF8bgdn/dHGTg== 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 1sCCsk-00GVxc-Hn; Wed, 29 May 2024 07:33:54 +0100 Date: Wed, 29 May 2024 07:33:54 +0100 Message-ID: <86bk4pm8j1.wl-maz@kernel.org> From: Marc Zyngier To: Anup Patel Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-riscv@lists.infradead.org, Saravana Kannan , Rob Herring Subject: Re: [PATCH] of: property: Fix fw_devlink handling of interrupt-map In-Reply-To: References: <20240528164132.2451685-1-maz@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/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=UTF-8 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: apatel@ventanamicro.com, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-riscv@lists.infradead.org, saravanak@google.com, robh@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 Wed, 29 May 2024 06:15:52 +0100, Anup Patel wrote: >=20 > On Tue, May 28, 2024 at 10:11=E2=80=AFPM Marc Zyngier wr= ote: > > > > Commit d976c6f4b32c ("of: property: Add fw_devlink support for > > interrupt-map property") tried to do what it says on the tin, > > but failed on a couple of points: > > > > - it confuses bytes and cells. Not a huge deal, except when it > > comes to pointer arithmetic > > > > - it doesn't really handle anything but interrupt-maps that have > > their parent #address-cells set to 0 > > > > The combinations of the two leads to some serious fun on my M1 > > box, with plenty of WARN-ON() firing all over the shop, and > > amusing values being generated for interrupt specifiers. > > > > Address both issues so that I can boot my machines again. > > > > Fixes: d976c6f4b32c ("of: property: Add fw_devlink support for interrup= t-map property") > > Signed-off-by: Marc Zyngier > > Cc: Anup Patel > > Cc: Saravana Kannan > > Cc: Rob Herring (Arm) >=20 > Thanks for the fix patch but unfortunately it breaks for RISC-V. >=20 > > --- > > drivers/of/property.c | 16 ++++++++++++++-- > > 1 file changed, 14 insertions(+), 2 deletions(-) > > > > diff --git a/drivers/of/property.c b/drivers/of/property.c > > index 1c83e68f805b..9adebc63bea9 100644 > > --- a/drivers/of/property.c > > +++ b/drivers/of/property.c > > @@ -1322,7 +1322,13 @@ static struct device_node *parse_interrupt_map(s= truct device_node *np, > > addrcells =3D of_bus_n_addr_cells(np); > > > > imap =3D of_get_property(np, "interrupt-map", &imaplen); > > - if (!imap || imaplen <=3D (addrcells + intcells)) > > + imaplen /=3D sizeof(*imap); > > + > > + /* > > + * Check that we have enough runway for the child unit interrupt > > + * specifier and a phandle. That's the bare minimum we can expe= ct. > > + */ > > + if (!imap || imaplen <=3D (addrcells + intcells + 1)) > > return NULL; > > imap_end =3D imap + imaplen; > > > > @@ -1346,8 +1352,14 @@ static struct device_node *parse_interrupt_map(s= truct device_node *np, > > if (!index) > > return sup_args.np; > > > > - of_node_put(sup_args.np); > > + /* > > + * Account for the full parent unit interrupt specifier > > + * (address cells, interrupt cells, and phandle). > > + */ > > + imap +=3D of_bus_n_addr_cells(sup_args.np); >=20 > This breaks for RISC-V because we don't have "#address-cells" > property in interrupt controller DT node and of_bus_n_addr_cells() > retrieves "#address-cells" from the parent of interrupt controller. That's a feature, not a bug. #address-cells, AFAICT, applies to all child nodes until you set it otherwise. >=20 > The of_irq_parse_raw() looks for "#address-cells" property > in the interrupt controller DT node only so we should do a > similar thing here as well. This looks more like a of_irq_parse_raw() bug than anything else. >=20 > The below change on top of this patch worked for me. >=20 > diff --git a/drivers/of/property.c b/drivers/of/property.c > index 9adebc63bea9..f54da2989ea9 100644 > --- a/drivers/of/property.c > +++ b/drivers/of/property.c > @@ -1308,7 +1308,7 @@ static struct device_node > *parse_interrupt_map(struct device_node *np, > { > const __be32 *imap, *imap_end, *addr; > struct of_phandle_args sup_args; > - u32 addrcells, intcells; > + u32 addrcells, intcells, paddrcells; > int i, imaplen; >=20 > if (!IS_ENABLED(CONFIG_OF_IRQ)) > @@ -1356,7 +1356,8 @@ static struct device_node > *parse_interrupt_map(struct device_node *np, > * Account for the full parent unit interrupt specifier > * (address cells, interrupt cells, and phandle). > */ > - imap +=3D of_bus_n_addr_cells(sup_args.np); > + if (!of_property_read_u32(sup_args.np, "#address-cells", &paddrc= ells)) > + imap +=3D paddrcells; This looks wrong to me for the reason I outlined above: you need to look for a valid #address-cells all along the parent chain, not just in the interrupt-controller node. M. --=20 Without deviation from the norm, progress is not possible.