Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp530916lqb; Wed, 29 May 2024 03:17:39 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXLIMgoOPCL3EowmDPXXCbayZamqgSgAL/StqCMol+SRzDfXddcVZypJlH5W2SpMsunCw2Cw2iHoyyTciZ2CrbjrWTD4uT/pUVS2yMaNA== X-Google-Smtp-Source: AGHT+IHu7Uy9Tz3jog6gJl9jEPKxzGKk878uSO/a/huZ3OSqqieO3KSjE3LjuGFf7m8fCz3cqKxN X-Received: by 2002:a05:622a:386:b0:439:b456:25b6 with SMTP id d75a77b69052e-43fe128de41mr28790231cf.30.1716977859617; Wed, 29 May 2024 03:17:39 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716977859; cv=pass; d=google.com; s=arc-20160816; b=U9mj2+hQDaf0MydngaT7/CPkHSTtgYUE8BTT+wwtoD191fWEuFoUhFfTcn1JOKvBh+ MtEkAfORn6T01stzTT8Bd7dzlnsh8ZwoD8rJxVKzic70LLXMNjNkOV0fJ/XLGdmzitw3 YAyW0toc6+akZFrhIB+ixFksEtVldmFypiAIud7R9K4WKJfaeyBZ2X8jkog76X/NFeEd rk3ZWR9LWp7mN23KwGwTvP/PbR0kEWxR5hVzV2nRJA8ldpUz/wcuSwYIt+lfOeSumGsb 0rA9o2YW9cD6bWWpacNsUQU3MrMaGXEhnbI0iw6ItIZ8LjEGzJgF1Unp5afaCfMsdxrb 6TQA== 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=yaPEJ9XT+XQdecfVTDIRiBCYJgWPcXhInCwaGbIaH5Q=; fh=DpL/A12wv94Rb5Ge2+9EqyrqPeBmrjLqLcffy70tFe8=; b=Ldpbkk3hRROzpJEkin0o2W57GX4gGok53S5fO59LS+BmpgxICG5cpcMU43o74r3/BL 1U1uii9J9fM3ohKXSHfG4mTTcx9urSBhcwb0Keo46lYqc+f13zE9NrC0KL91hhH8AmOA IyXoRe2XNLnSpGQSpazwlKbPv1OBLsb0NY8gHFdOv8Wu1Ny358UGp3MvLxxZfTvCAGvp 2z5F1NNA+fvl6IIYte4OF63aLKoBzQBldWkIQ0Gle6tqNFa8CPX4eUvBvXRFBP35EOHK JjuUpGP412zUs9Yaq4/4sA4XjfsbkDWfQzbkxYKiyPC2n1UDURqtaq+LDUJGaiq3B9WB ocBg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=HGCOPdKi; arc=pass (i=1 spf=pass spfdomain=ventanamicro.com dkim=pass dkdomain=ventanamicro.com); spf=pass (google.com: domain of linux-kernel+bounces-193943-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-193943-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id d75a77b69052e-43fb18ea890si106853211cf.739.2024.05.29.03.17.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 03:17:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-193943-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=HGCOPdKi; arc=pass (i=1 spf=pass spfdomain=ventanamicro.com dkim=pass dkdomain=ventanamicro.com); spf=pass (google.com: domain of linux-kernel+bounces-193943-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-193943-linux.lists.archive=gmail.com@vger.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 2F72D1C21282 for ; Wed, 29 May 2024 10:17:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 95B5C17A938; Wed, 29 May 2024 10:16:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="HGCOPdKi" Received: from mail-lj1-f177.google.com (mail-lj1-f177.google.com [209.85.208.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B9D64169AD0 for ; Wed, 29 May 2024 10:16:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716977809; cv=none; b=HJ8i2dBBeaIp0Sgkpl4fwCvPeJkIphJvBObgiqt3mO4SJlTiszhAjcOKSXroCtCGx7f+Od9GydRdSVuDTpw7EHpwXDB/XDSfv9/CjWRQQf8H/BcFR1Wn+skmvZ29htvaNMddxbpHkePKg7HUt6lYmPXaRtRhWkca5SN5vLnyfhM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716977809; c=relaxed/simple; bh=Un9KNK5u5FZjSBVujiSdk6VsC13UknTllPZuVQefjyI=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=SmS2CfepqOBNancqgkncWutYAs36vikNRN+8M6G7FMjhj7Tx3pPi/4u8ZV6uC7+jvn3gqjt2HjmTyKtxWxMEAARbmXSodf7dhiDSd8ggHcAmwy0lnnFPa/hOFxAxt9uR1gID7Nw1bad9c3VshSMuyBUeBmMUwPSBmHRB7lLfsd4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com; spf=pass smtp.mailfrom=ventanamicro.com; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b=HGCOPdKi; arc=none smtp.client-ip=209.85.208.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ventanamicro.com Received: by mail-lj1-f177.google.com with SMTP id 38308e7fff4ca-2e95a60454fso20536271fa.1 for ; Wed, 29 May 2024 03:16:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1716977805; x=1717582605; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=yaPEJ9XT+XQdecfVTDIRiBCYJgWPcXhInCwaGbIaH5Q=; b=HGCOPdKiZKChi5IVVlWkrG/xbbEw/j/2uSliZDafkaVjUjznoyha31U5Di7dJjliwS 4CWveeAwI8z/hM+1Vif2rS4GW/9BXbHxUYd21SHiUZUEtn3/PWpBD84NjP2uWkitsSjT pmEgI6robzRh2FsNBzMRkEZkkB9hODprhB7lIkNP+DRvW059qkNyHsuxserzsZRTyta2 JuWLul9EbkZLIs4PQlObzJGqbN+01ArRPIrw+IoRlKpYgqy2pinkvSc56+2ERDVOsnN8 xDj/cH+fTz1cmeFUk4Qpq//9kBjJgQOifAU80L/dcaitJ1oJUVncWfS+a13K9ArvrXD7 jlIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716977805; x=1717582605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yaPEJ9XT+XQdecfVTDIRiBCYJgWPcXhInCwaGbIaH5Q=; b=ZjjWOkQwPXOZYXNKlxUICJAC+QCDAfHddkQW40kQskB3G3BlKwjN5gccscn7WCUyvX i1uUgWjSScG0AeL1JB0sMFhFrSZDch2T6K7nRXmbsoAGW6TVVIlEKE4gD1vWPsSTog5z KOXPpmoz5zbis0TXDwIsy7cUAu0e5F09W+MyF8gWppOqU15QWxyRrMPEplw1R9KpU5g5 D3EM6afonfyZVKWCvBqscpAdcoFabgZUM4jgaJq1XllzBPxUNjcWXvJCHR0xrOgregES LGYLoBFn7hlGV2BG14jOimLb+NK8Puu40ZbhNj32jGFM0WeWBp8MUIF0GP7Bp+Cl0mDT bfxw== X-Forwarded-Encrypted: i=1; AJvYcCVWocPFYucNzgf1Gh4LstQQjmaRA3QZpnMf8Op2ArAUjWLFBdTgPp9CrBuqZEiNc7Q5JcAisEYPRWgqCHzFvKXTfq2nkYktcCo2iHki X-Gm-Message-State: AOJu0YzU/yuXkTA4Sk6sY8kP37/a2rI+YO+Prha2z7+BzBjTMQiygW4t yaUf6Vh3BqcDMR+2rdRf/tPmQh4/nlfSUDx/K2UYd6cTpXwsX94orTQ+ntdK9lIKTk4kQ4nxPBq FqjFHEjH9dhbfe+SCgY3O1GYF0ZF2XeroTaaXVQ== X-Received: by 2002:a2e:7c08:0:b0:2e3:7f19:7072 with SMTP id 38308e7fff4ca-2e95b1dc4damr91784301fa.28.1716977804566; Wed, 29 May 2024 03:16:44 -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> In-Reply-To: <86bk4pm8j1.wl-maz@kernel.org> From: Anup Patel Date: Wed, 29 May 2024 15:46:30 +0530 Message-ID: Subject: Re: [PATCH] of: property: Fix fw_devlink handling of interrupt-map To: Marc Zyngier 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, May 29, 2024 at 12:03=E2=80=AFPM Marc Zyngier wrot= e: > > 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 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 interr= upt-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_interrupt_map= (struct 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 interr= upt > > > + * specifier and a phandle. That's the bare minimum we can ex= pect. > > > + */ > > > + 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= (struct device_node *np, > > > if (!index) > > > return sup_args.np; > > > > > > - of_node_put(sup_args.np); > > > + /* > > > + * Account for the full parent unit interrupt specifi= er > > > + * (address cells, interrupt cells, and phandle). > > > + */ > > > + 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_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. > > > > > 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. 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. In the RISC-V world, there have been quite a few QEMU releases where the generated DT node of the interrupt controller does not have the "#address-cells" property. This patch breaks the kernel for all such QEMU releases. I think we should align the implementation in parse_interrupt_map() with of_irq_parse_raw() and use of_property_read_u32() instead of of_bus_n_addr_cells(). Regards, Anup > > > > > The below change on top of this patch worked for me. > > > > 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; > > > > 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", &padd= rcells)) > > + 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. > > -- > Without deviation from the norm, progress is not possible.