Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp763712lqb; Wed, 29 May 2024 09:47:18 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXxeggBxBKX6XCI3nIdSNPtpgmL3u981EQqJEpjAJUnFPRxZBSV0L7ioV0s/GAkZ3RV1PEbjtbGqvafgy/cTZWpidW6Vn2lCtG0KbwR0A== X-Google-Smtp-Source: AGHT+IEGCJcYsV8rd3GB1p0E18+KEc2yb+fdIM8u2p2YXanLeY6lk/MK1NjylgkYhpmc5YF+uzxD X-Received: by 2002:a17:906:916:b0:a59:dba0:1544 with SMTP id a640c23a62f3a-a642d7d88a3mr226464366b.31.1717001237806; Wed, 29 May 2024 09:47:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717001237; cv=pass; d=google.com; s=arc-20160816; b=vcHmZEsML9kBlSjJkJ+FT3bWGI0n2YlY49tt+rSjrqwc8CZBVXr1LqyON0ybpRv6c6 v9Z0FgHBpjMlXg9PO1cYvZd+b8RJl2BoSuYTHf1Nw57KkLdbVXqIqy5FYVzS5+1ppwcA s6kR4RdJbVugnddCg68acchYcEw6xTo0ApCvfpqOTpxYA7vFdvLVqOZbJquE071cbLT0 HBJvsZt1Utd+PDr7e2Pm+cxpMwiIP93rCvSjLZptXjnrVAtiPupdyREBYOKVjNbdBM8h 4W26dtfrL2H+6FHv74X0EgHTeWp8oFfn2c1V0ytPrOfgwMIDhuGwF21/ZXWK6KXrWQvl 5W7Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=bqQDI24QfvvcliZkW5CkxAcx9sSg+/Uu0uSfrpKBGIw=; fh=P5A+qXUbxEafB5m0rmTYVAmErikq8cVHHEv2m3XN1Dw=; b=DVAYNzWg9Xv48jejTJuYUmP4C9Zq3JG8myTfqxMJ7LWa0zVPRTX5P2ZWeAsC9jIeri 39N0/ArEcQoTGOoTB5cXI2LSplr0rPj4ASx9XtUvtE4BkgzX7gntNp7Tl0PPz6oZVG/O lpOI2scmOB49l5aOpoavDMHZnzMz9LDVhJSiTm+QCi6Dl5nLw+2bYsMsUAHdvcNAKSK6 cncyUUS2lKWYvsbkK3wxmiNONzey5qi+/krH+Gq/RZh7IGWiNGvmHVJDR5Fl32Dm87U4 F2/ATIN9KDoN+pZzyA+rihAdZ0XB/nRRrfEbQYFRUzBKqn38C+c1rO9tIl9WgzC7isML k+Cw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=aCkNXUfP; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-194488-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-194488-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-a626cd932casi638090166b.811.2024.05.29.09.47.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 09:47:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-194488-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=aCkNXUfP; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-194488-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-194488-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 5DFB51F24964 for ; Wed, 29 May 2024 16:47:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 64485184138; Wed, 29 May 2024 16:47:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="aCkNXUfP" 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 5A5A11836DB; Wed, 29 May 2024 16:47:10 +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=1717001230; cv=none; b=MJzTBufvlzhIWJdmvgHdy+g1yC5yEB3ohOhmC02oieo/EGtvIkKZUaxgVGqYKQkrM04EI612Qfqnh+KPZCbdggM8RTxoexN5fwMwt6RtHvP3vdUZWI76ACA432SMXNGq5AM2V29HmgGal3M//o0uJtkyliwkfs4VjK5wnKMcaRk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717001230; c=relaxed/simple; bh=n7ShnOOdeIWlPrL1n4Qs6VgIfCSCN6l/akX1/ZK9iYo=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=RWONw/aPYv53ktZdz0KOhV/Abib4IwBhimTgT+lWwJheh7QkiBeP9QpZhCBcaPy+SHklsH5AeuqJhNbcOW6VC/U4FUh41cCnsmN7h+Bv3DXBXfX6KABOKBGBBCs4VnoDL/mdmKSFrBWHRXijA0pXokXNF2z08jG5TybhA+AGqns= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aCkNXUfP; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id E3B9CC2BD10; Wed, 29 May 2024 16:47:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717001229; bh=n7ShnOOdeIWlPrL1n4Qs6VgIfCSCN6l/akX1/ZK9iYo=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=aCkNXUfPlo3EhRbLwsDwFyRATwLVLUxUtj5wd3U/saK9gL5LhRqc4OABpaV61v8zT ubUpa9SCgvaGflDHtcC8oDphpTExJvrdJ+lTHVVkOBGjvb5RCZRBTEAnMVwE2kM7ky DL1TWkTid2Dw77FzPEK/ULvttmd3G6bb8U0Msa1QzIR43ZEhnhfPlO7fYqttmVEd1X m0kx6PFCQ9hiWY6dGLVwi+TVW0JGQ7hNUH2kXCA1V7vf7fIbrl1+r+ZGIFsLdtL5Hp TM1sj/29jL/UZBxiuz4r8M6mtqA0FkvfVZTUdoUobAUeaoBZMayRftrVGZolSbCs1v Lq91EPR1iUUOA== Received: by mail-lf1-f43.google.com with SMTP id 2adb3069b0e04-52b78ef397bso191000e87.0; Wed, 29 May 2024 09:47:09 -0700 (PDT) X-Forwarded-Encrypted: i=1; AJvYcCWKjWdIYunNS7nq+gyVDdD3nNA0iBHzuF1LjW8twFBt5nBmD8jUYptFgw5PQdlFENT/OdiiO2+YtfQTINqnuZgkUgU6Sj2my+vJSbh/xWfZEw2Imx2Rz04NwMVArbLlZM4lXQ/JWgAriQ== X-Gm-Message-State: AOJu0YyDBjgHbfDbw8FWTZmQYAwTcI194Q8zQmNgEQxp84MiTIT1K/9s GQOaXVJUBDuMbZDTLVTXvOvoZlKPOSCr/2t0bz3R+oLVIzC8SVseGyJX+Qn9nwBJahtJU2qvb9i xszD6KDrpFmUS+8jTFMLGb4tPyg== X-Received: by 2002:ac2:5a08:0:b0:52a:7742:4593 with SMTP id 2adb3069b0e04-52a78c36684mr864211e87.25.1717001228317; Wed, 29 May 2024 09:47:08 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240528164132.2451685-1-maz@kernel.org> <86bk4pm8j1.wl-maz@kernel.org> <86a5k8nbh1.wl-maz@kernel.org> In-Reply-To: From: Rob Herring Date: Wed, 29 May 2024 11:46:55 -0500 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] of: property: Fix fw_devlink handling of interrupt-map To: Anup Patel Cc: Marc Zyngier , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-riscv@lists.infradead.org, Saravana Kannan Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, May 29, 2024 at 8:51=E2=80=AFAM Rob Herring wrote= : > > On Wed, May 29, 2024 at 6:28=E2=80=AFAM Anup Patel wrote: > > > > On Wed, May 29, 2024 at 4:15=E2=80=AFPM Marc Zyngier w= rote: > > > > > > On Wed, 29 May 2024 11:16:30 +0100, > > > Anup Patel wrote: > > > > > > > > On Wed, May 29, 2024 at 12:03=E2=80=AFPM Marc Zyngier wrote: > > > > > > > > > > On Wed, 29 May 2024 06:15:52 +0100, > > > > > Anup Patel wrote: > > > > > > > > > > > > On Tue, May 28, 2024 at 10:11=E2=80=AFPM Marc Zyngier wrote: > > > > > > > > > > > > > > Commit d976c6f4b32c ("of: property: Add fw_devlink support fo= r > > > > > > > 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 i= t > > > > > > > comes to pointer arithmetic > > > > > > > > > > > > > > - it doesn't really handle anything but interrupt-maps that h= ave > > > > > > > their parent #address-cells set to 0 > > > > > > > > > > > > > > The combinations of the two leads to some serious fun on my M= 1 > > > > > > > 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 fo= r interrupt-map property") > > > > > > > Signed-off-by: Marc Zyngier > > > > > > > Cc: Anup Patel > > > > > > > Cc: Saravana Kannan > > > > > > > Cc: Rob Herring (Arm) > > > > > > > > > > > > Thanks for the fix patch but unfortunately it breaks for RISC-V= . > > > > > > > > > > > > > --- > > > > > > > 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_inter= rupt_map(struct device_node *np, > > > > > > > addrcells =3D of_bus_n_addr_cells(np); > > > > > > > > > > > > > > imap =3D of_get_property(np, "interrupt-map", &imaple= n); > > > > > > > - if (!imap || imaplen <=3D (addrcells + intcells)) > > > > > > > + imaplen /=3D sizeof(*imap); > > > > > > > + > > > > > > > + /* > > > > > > > + * Check that we have enough runway for the child uni= t interrupt > > > > > > > + * specifier and a phandle. That's the bare minimum w= e can expect. > > > > > > > + */ > > > > > > > + if (!imap || imaplen <=3D (addrcells + intcells + 1)) > > > > > > > return NULL; > > > > > > > imap_end =3D imap + imaplen; > > > > > > > > > > > > > > @@ -1346,8 +1352,14 @@ static struct device_node *parse_inter= rupt_map(struct 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 phand= le). > > > > > > > + */ > > > > > > > + imap +=3D of_bus_n_addr_cells(sup_args.np); > > > > > > > > > > > > This breaks for RISC-V because we don't have "#address-cells" > > > > > > property in interrupt controller DT node and of_bus_n_addr_cell= s() > > > > > > retrieves "#address-cells" from the parent of interrupt control= ler. > > > > > > > > > > That's a feature, not a bug. #address-cells, AFAICT, applies to a= ll > > > > > child nodes until you set it otherwise. > > > > > > > > > > > > > > > > > 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. > > > > > > > > If we change of_irq_parse_raw() to use of_bus_n_addr_cells() > > > > then it would still break for RISC-V. > > > > > > I'm not trying to "fix" riscv. I'm merely outlining that you are > > > relying on both broken DTs and a buggy OS. > > > > > > > > > > > Using of_bus_n_addr_cells() over here forces interrupt controller > > > > DT nodes to have a "#address-cells" DT property. There are many > > > > interrupt controller (e.g. RISC-V PLIC or RISC-V APLIC) where the > > > > DT bindings don't require "#address-cells" DT property and existing > > > > DTS files with such interrupt controllers don't have it either. > > > > > > It forces you to set #address-cells *if you rely on a different > > > value in a child node*. It's not like the semantics are new. > > > > We don't have child nodes under the interrupt controller DT node > > (for both RISC-V PLIC and APLIC) so we certainly don't require the > > "#address-cells" property in the interrupt controller DT node. > > interrupt controller nodes which are referred to by interrupt-map > require #address-cells. Period. Child nodes or not. Now that I've re-read the code, the kernel will treat missing #address-cells in the interrupt parent as 0. Looking in the parent nodes for #address-cells only happens for the input address (i.e. the address before the phandle). IOW, the first use of_bus_n_addr_cells() was correct, but the 2nd use is not correct. That's not great, but that's how this code passed down on stone tablets works... As I commented on v1 of the original patch. I don't like parsing interrupt-map in 2 places. It leads to problems exactly as this thread has shown. The duplication was reduced some, but is still more than I'd like. So I'm looking at how to refactor of_irq_parse_raw() to make it work for what's needed here. Maybe I'll have a fix quickly. If not, I'm going to revert the original commit. Rob