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 7FA8FC4332F for ; Sun, 4 Dec 2022 21:22:13 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1FC168564A; Sun, 4 Dec 2022 22:20:16 +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="ZMJVzjJx"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 063B68564A; Sun, 4 Dec 2022 22:20:14 +0100 (CET) Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) (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 BCE31856CF for ; Sun, 4 Dec 2022 22:20:06 +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-x32f.google.com with SMTP id ay14-20020a05600c1e0e00b003cf6ab34b61so10465222wmb.2 for ; Sun, 04 Dec 2022 13:20:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; 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=4gjPubHE5jA9f5XUhzIVhZ7XhTqP9PzvVlS9DYQuJE4=; b=ZMJVzjJxuZjxc85GFFUoYjym40gJ7Jcx1ZkLrt85+yXyyi638G43yHSBZZgaN+6KKv Il6m8pCYPgsUPV2KHetBRf47tC8DJqWcEBeCxejIaoe3r6nqMT+a3Gj0neq9i8swkNF+ BxTwlaDl/VM10mVmr+uR7D1FZooe8kC6I0yR45uKB86GD8wU/0E93Se9+oGunaXDM0/U mcTed0jmEuMOCHZImVagg7dHb8ZPbHunocPCa1gp5qNkhxTEyQKCMfulpXQDPc7IZscU vOV/Nt7s7M5hEn9HrvApuot4VXeFV1ANkUp0UBgEz2qkkfTt3MHiknxn5/N48kFGRJTI 39ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=4gjPubHE5jA9f5XUhzIVhZ7XhTqP9PzvVlS9DYQuJE4=; b=SXV5/5ADknIGOqGaqKvXbruzw1zPs125OabJOfOkkmeo45nGsnoJXTng6u6YqdZhpQ zFaOjiHopoqjGVyTX2xjdNdfQ9+Q0cEOijbSHZ3sRe6RsxzF38W6WBO6D7hhOiZl/Lgl 6P7xhZn4Nfic+2w2OVL7I+LSiNfhK6bYxmwT3WIkk+Sy9KYQqKLvYjrEchymUhe6hs9V T+TjU+ji/txFShx6zB1c6yNvhce6YwdSfV8s5lYWnJgc51RwOrkpKAR24ParfkZnJdB0 eI6Ybud7kaQmTLrDVm2G5MgEfHHO8x+JltOW89IQwu0irbbFLoqpdZgzF9XLmLJ5K4zz Q58Q== X-Gm-Message-State: ANoB5plAlneCDj0fg3NV5vo0+pbnGeBPUyoCGLioRwshudDwzYFB5o7K 2IBVGrwHhNjllYkS6ZmdB3yVpg== X-Google-Smtp-Source: AA0mqf7C7KEcnpGqCA6IfjtI/oKfyS97k5QHc/JbEFobCdud+rekqM3scQazflhq0uBkm5e3CY1asg== X-Received: by 2002:a05:600c:1685:b0:3d0:a743:b81f with SMTP id k5-20020a05600c168500b003d0a743b81fmr3920835wmn.171.1670188806171; Sun, 04 Dec 2022 13:20:06 -0800 (PST) Received: from google.com (203.75.199.104.bc.googleusercontent.com. [104.199.75.203]) by smtp.gmail.com with ESMTPSA id e18-20020a5d4e92000000b0024206ed539fsm12390714wru.66.2022.12.04.13.20.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Dec 2022 13:20:05 -0800 (PST) Date: Sun, 4 Dec 2022 21:20:01 +0000 From: =?utf-8?Q?Pierre-Cl=C3=A9ment?= Tosi To: sean@geanix.com Cc: 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: <20221204212001.n7oj4vpzvvphbp34@google.com> References: <20220519164830.3934669-1-ptosi@google.com> <20221202203837.Horde.7pO1k2m_09erXpnxnJnVFn5@webmail.your-server.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20221202203837.Horde.7pO1k2m_09erXpnxnJnVFn5@webmail.your-server.de> 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.6 at phobos.denx.de X-Virus-Status: Clean 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 Decompiling the resulting u-boot.dtb shows pci { compatible = "pci-x86"; u-boot,dm-pre-reloc; }; 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? 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