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 phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B13F0C6FD1C for ; Wed, 22 Mar 2023 12:48:07 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 753D285D19; Wed, 22 Mar 2023 13:48:05 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="ArBZNO3A"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D0F3F85D4C; Wed, 22 Mar 2023 13:48:01 +0100 (CET) Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 8E3D185D19 for ; Wed, 22 Mar 2023 13:47:57 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ptosi@google.com Received: by mail-wm1-x32e.google.com with SMTP id az3-20020a05600c600300b003ed2920d585so12943587wmb.2 for ; Wed, 22 Mar 2023 05:47:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1679489277; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=5N6XVguzYnCdxumP67GHz1fR6gYxVgkf7SmLxAoh5uI=; b=ArBZNO3Aj51aCfh3riLOFcPUFrZSGOCQquojuFtQvVfVMQksJaxqDQtTOsicCzz4so jT1DJ2/F8KT12e0jXKHOSQlHYieSphNbBCX58z1pqf1a+XUDCcG528VLxBKBZj3LpKON jTJgsHExwzFAEbscnHQbO7Fk6ppJACYkJ0bk++VbQvqAYSML3KfbXVFXSAEV/FtQuw2G bDMrsj6WeMV3+UMW/JNNkXDIyNTnYJIU3iu7yQrpaW92tnajfhc+0ElSeonrPTXn7pDx XD+onFiwpszWtCZIisOtkQ7WpNSqw+ET+Cad4qy3mQB1H4KDX/IeOESat4lzHBSD7em/ pt/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679489277; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=5N6XVguzYnCdxumP67GHz1fR6gYxVgkf7SmLxAoh5uI=; b=6PY7GSc8H5EAXsCFpW/w8Pjp3kAJf0KJxKwH69v2zArq06fXujt9RChJS0PTCbrAm2 b1jJgX4Lo2euwQNGHdS3uX3ajUE33I9JUpn7gRPtlrValEbb3SI4NB9YalvMh1A/h12E Jn1VehGpXtq+XBU0JFmRgawtHPbSq1QNSXhKqAkey3bjjxrnF74qXcrhBbabc6fj2gsb vsdQ9+GPXPWtKPSg208XTj1Nko5+uR/rl99ZFuMZunfXrWWHikyv+BTDYgaPeY5hJeh5 WiQ7w6hwYwQ4NtCxD4xy+kWqyF1R6Av8JcUH5QJP7cxFuUIdKnWOe/Aw7q1lT6H9n1Ek Xh+w== X-Gm-Message-State: AO0yUKXKgRGUz00b1o73BcfvXr9LelyGsnIAmmgNTbuJmtUO8yob5mVe fp09KnIDTA7Rf0+B6P8fAdWNiw== X-Google-Smtp-Source: AK7set+1HxYDXdGzZS55Xd4UO1CPGirhnAjnYPrvsf9YPdTw5t3qHsxxGtqgcO74SqAbOnS0bcGvUA== X-Received: by 2002:a7b:cbc8:0:b0:3ed:ce6f:e86e with SMTP id n8-20020a7bcbc8000000b003edce6fe86emr5622736wmi.23.1679489277000; Wed, 22 Mar 2023 05:47:57 -0700 (PDT) Received: from google.com (203.75.199.104.bc.googleusercontent.com. [104.199.75.203]) by smtp.gmail.com with ESMTPSA id u26-20020a05600c211a00b003ee097c58e3sm7861771wml.39.2023.03.22.05.47.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Mar 2023 05:47:56 -0700 (PDT) Date: Wed, 22 Mar 2023 12:47:47 +0000 From: =?utf-8?Q?Pierre-Cl=C3=A9ment?= Tosi To: Christian Gmeiner Cc: sean@geanix.com, u-boot@lists.denx.de, Bin Meng , Simon Glass , Stefan Roese , kasper@krinvent.dk Subject: Re: [PATCH] pci: Handle failed calloc in decode_regions() Message-ID: <20230322124747.bqheir4anfl6bmqp@google.com> References: <20220519164830.3934669-1-ptosi@google.com> <20221202203837.Horde.7pO1k2m_09erXpnxnJnVFn5@webmail.your-server.de> <20221204212001.n7oj4vpzvvphbp34@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Hi, On Tue, Mar 21, 2023 at 08:57:18AM +0100, Christian Gmeiner wrote: > Am So., 4. Dez. 2022 um 22:22 Uhr schrieb Pierre-Clément Tosi > : > > > > Hi, > > > > On Fri, Dec 02, 2022 at 08:38:37PM +0100, sean@geanix.com wrote: > > > > > > Quoting Pierre-Clément Tosi : > > > > > > > Add a check for calloc() failing to allocate the requested memory. > > > > > > > > Make decode_regions() return an error code. > > > > > > > > Cc: Bin Meng > > > > Cc: Simon Glass > > > > Cc: Stefan Roese > > > > Signed-off-by: Pierre-Clément Tosi > > > > --- > > > > > > Hi, > > > > > > We upgraded from v2022.04 -> v2022.10, and this PATCH breaks PCI (scsi/sata) > > > support for x86_64. > > > I have seen this in qemu, i havn't had the time to test this on real hardware. > > > > > > Steps to reproduce: > > > $ make efi-x86_payload64_defconfig && make -j32 && scripts/build-efi.sh -sPrp > > > > Breaks my use case too and is basically a revert of > https://source.denx.de/u-boot/u-boot/-/commit/f2825f6ec0bb50e7bd9376828a32212f1961f979 > In my use case we are using coreboot for different Intel SoCs with a > generic U-Boot payload. > > > Decompiling the resulting u-boot.dtb shows > > > > pci { > > compatible = "pci-x86"; > > u-boot,dm-pre-reloc; > > }; > > > > Yes.. that is what can be found here: > https://source.denx.de/u-boot/u-boot/-/blob/master/arch/x86/dts/coreboot.dts#L34 > > > > which isn't supported by the patch as we return -EINVAL when missing "ranges". > > The rationale here was that the property seemed mandatory (see [1] and [2]); was > > this a misunderstanding of potential corner cases? > > > > At the moment I would like to revert this change. > Thanks for sharing such a corner case. IMO, normal operation shouldn't rely on errors being silently skipped because return values are being blindly ignored. Instead, we could limit EINVAL to libfdt errors that aren't FDT_ERR_NOTFOUND, which would address your use-case, where "ranges" is missing from the DT node. Is your issue fixed by this patch: https://patchwork.ozlabs.org/project/uboot/patch/20230220194927.476708-8-sjg@chromium.org/ ? > > OTOH, I see that most DTS using "pci-x86" (a pseudo-device intended to act as a > > PCI bus) actually provide "ranges". In particular, a comment added by > > 0ced70a0bb7a ("x86: tpl: Add a fake PCI bus") states that > > > > The BARs are allocated statically in the device tree. > > > > So I'll let others comment on this but either: > > > > - arch/x86/dts/efi-x86_payload.dts (and a few other DTS) is missing "ranges"; or > > - pci_uclass_pre_probe() should treat UCLASS_SIMPLE_BUS differently. > > > > [1]: https://www.kernel.org/doc/Documentation/devicetree/bindings/pci/host-generic-pci.txt > > [2]: IEEE Std 1275-1994 > > > > > > > > Br, > > > /Sean > > > > > > > drivers/pci/pci-uclass.c | 15 ++++++++++----- > > > > 1 file changed, 10 insertions(+), 5 deletions(-) > > > > > > > > diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c > > > > index 970ee1adf1..2c85e78a13 100644 > > > > --- a/drivers/pci/pci-uclass.c > > > > +++ b/drivers/pci/pci-uclass.c > > > > @@ -954,7 +954,7 @@ int pci_bind_bus_devices(struct udevice *bus) > > > > return 0; > > > > } > > > > > > > > -static void decode_regions(struct pci_controller *hose, ofnode parent_node, > > > > +static int decode_regions(struct pci_controller *hose, ofnode parent_node, > > > > ofnode node) > > > > { > > > > int pci_addr_cells, addr_cells, size_cells; > > > > @@ -968,7 +968,7 @@ static void decode_regions(struct pci_controller > > > > *hose, ofnode parent_node, > > > > prop = ofnode_get_property(node, "ranges", &len); > > > > if (!prop) { > > > > debug("%s: Cannot decode regions\n", __func__); > > > > - return; > > > > + return -EINVAL; > > > > } > > > > > > > > pci_addr_cells = ofnode_read_simple_addr_cells(node); > > > > @@ -986,6 +986,8 @@ static void decode_regions(struct pci_controller > > > > *hose, ofnode parent_node, > > > > max_regions = len / cells_per_record + CONFIG_NR_DRAM_BANKS; > > > > hose->regions = (struct pci_region *) > > > > calloc(1, max_regions * sizeof(struct pci_region)); > > > > + if (!hose->regions) > > > > + return -ENOMEM; > > > > > > > > for (i = 0; i < max_regions; i++, len -= cells_per_record) { > > > > u64 pci_addr, addr, size; > > > > @@ -1053,7 +1055,7 @@ static void decode_regions(struct pci_controller > > > > *hose, ofnode parent_node, > > > > /* Add a region for our local memory */ > > > > bd = gd->bd; > > > > if (!bd) > > > > - return; > > > > + return 0; > > > > > > > > for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) { > > > > if (bd->bi_dram[i].size) { > > > > @@ -1068,7 +1070,7 @@ static void decode_regions(struct pci_controller > > > > *hose, ofnode parent_node, > > > > } > > > > } > > > > > > > > - return; > > > > + return 0; > > > > } > > > > > > > > static int pci_uclass_pre_probe(struct udevice *bus) > > > > @@ -1097,7 +1099,10 @@ static int pci_uclass_pre_probe(struct udevice *bus) > > > > /* For bridges, use the top-level PCI controller */ > > > > if (!device_is_on_pci_bus(bus)) { > > > > hose->ctlr = bus; > > > > - decode_regions(hose, dev_ofnode(bus->parent), dev_ofnode(bus)); > > > > + ret = decode_regions(hose, dev_ofnode(bus->parent), > > > > + dev_ofnode(bus)); > > > > + if (ret) > > > > + return ret; > > > > } else { > > > > struct pci_controller *parent_hose; > > > > > > > > -- > > > > 2.36.1.124.g0e6072fb45-goog > > > > > > > > > > > > > -- > > Pierre > > > > -- > greets > -- > Christian Gmeiner, MSc > > https://christian-gmeiner.info/privacypolicy Thanks -- Pierre