Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2936346pxb; Mon, 19 Apr 2021 18:41:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwG/nXsbpSrnI30YbCdzrL0igy/Y6Ewy9bzj7l8CsITZcU9vxA5CZVKZ4SDN7zmSjEzAepX X-Received: by 2002:a17:902:d911:b029:ea:cc53:5501 with SMTP id c17-20020a170902d911b02900eacc535501mr25934402plz.21.1618882860160; Mon, 19 Apr 2021 18:41:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618882860; cv=none; d=google.com; s=arc-20160816; b=WpBeipraOLrFCC7plHcz1b6LuVZp0XZS6lAeHQSim9qFf5AWcG/gbg3QhwrOkOmJtR wgEAM2v+p9FpmlMa/dW9rqENaIDzYz/l7ZCwUXYqK1owEUCyes0/1l1SBSCAUhu3tf/k OKx7O5SrU4NtjemrnfJLfuMeT1ZqFajuvVk63tvNim6xSIyUJQi31SepQiRPlkRRV0uk eqk0Thx2PJ8f/YLGwoirh3Kp9/Ayb7rVLcV+6B4UfhAP+7/+5fIqrrdsmvPk0JR7be2w sySvuoxfcebVplmjzMuynRqwCsMHCwIgd0Gpv8Dgp9bhPcIVFABGUbqw9p8SWSjFuYQ+ Y5bg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=4hnsU6WgBldaH5Kc/ypeWx+AWLTPQMMNvcxsiJYBBkg=; b=sYKWEAEuaSQ+YW4FiS5evN6Wp/UAmthqx7BhUWdUu/V+zxZ+/jGs1LwY70xf0QZgiA q+iFiom5r7aHxXFQYzw0El2tKw+6OM29TF0ebK2kqkjhlglwVsb8eq6mX+syBlEVrMkf qOL7/JdPrE0bMoKE77NTjZ3HoiHLl8CSSkSHZ8kAf/KtUQnibfn8zQ0bVjcKerYtIYFF d5wfA3YWGZUHa1x4tY52N0sujH3knZKvDfE74DO/8loIPMPRsplIUMvDnFlsVsIEi5ZA 08dLirV72yPK18YvWBeMOgk3voZrouSudTg8CzDmFxIpMz7Tnm0+tXaRVHAt/vhh0Ph8 aFYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=GKKZM3WH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d3si1267295pjx.137.2021.04.19.18.40.46; Mon, 19 Apr 2021 18:41:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=GKKZM3WH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230300AbhDTBk0 (ORCPT + 99 others); Mon, 19 Apr 2021 21:40:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:37092 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229672AbhDTBkY (ORCPT ); Mon, 19 Apr 2021 21:40:24 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4E0A5613B4; Tue, 20 Apr 2021 01:39:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1618882794; bh=4hnsU6WgBldaH5Kc/ypeWx+AWLTPQMMNvcxsiJYBBkg=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=GKKZM3WH2aaOJjXA0A5WX/j0yTLVn6aIouOZrGe4BSZEIgtnM8GmefhIsCcwwv7dY 7veRjisZ0dKei5rYPCwT4ui+jVsB+l2ntjpjoqtp+plBTN3osuRg0THfPJanEbEd3J 8B6AN5vrXCX8mgTa/TJ6mJn0XEpnw2z8mt8RPcpFmxw84CMuK9sBG1k/vgHZjCwkPe c+wVNKMS/Vvp/pqJHJ6f1EzuLdeq6GLyFl8EPqh/ecCSCIE2BgoK9ytRumGj/0eCVz 0ARwfRTV8hpQa1b8SHWZD11AShS0LitOlN2eIUivlkepbvFY1u25S+Oh6SCw11bs3N Av4CmukllAIow== Received: by mail-ed1-f48.google.com with SMTP id j12so17995542edy.3; Mon, 19 Apr 2021 18:39:54 -0700 (PDT) X-Gm-Message-State: AOAM530G/TRXugRczeOGkEJ1dVVvmOjvIGdcn+lrCiq/OTcpZZiyVR4r 5H+vVJ8U6zAGdohhnQcztRiFBTrkeZZSUuZqGQ== X-Received: by 2002:aa7:cd51:: with SMTP id v17mr29099818edw.137.1618882792776; Mon, 19 Apr 2021 18:39:52 -0700 (PDT) MIME-Version: 1.0 References: <20210415180050.373791-1-leobras.c@gmail.com> <7b089cd48b90f2445c7cb80da1ce8638607c46fc.camel@gmail.com> In-Reply-To: From: Rob Herring Date: Mon, 19 Apr 2021 20:39:41 -0500 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 1/1] of/pci: Add IORESOURCE_MEM_64 to resource flags for 64-bit memory addresses To: Leonardo Bras Cc: Frank Rowand , Alexey Kardashevskiy , devicetree@vger.kernel.org, "linux-kernel@vger.kernel.org" , PCI , linuxppc-dev Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Apr 19, 2021 at 7:35 PM Leonardo Bras wrote: > > On Mon, 2021-04-19 at 10:44 -0500, Rob Herring wrote: > > On Fri, Apr 16, 2021 at 3:58 PM Leonardo Bras wrote: > > > > > > Hello Rob, thanks for this feedback! > > > > > > On Thu, 2021-04-15 at 13:59 -0500, Rob Herring wrote: > > > > +PPC and PCI lists > > > > > > > > On Thu, Apr 15, 2021 at 1:01 PM Leonardo Bras wrote: > > > > > > > > > > Many other resource flag parsers already add this flag when the input > > > > > has bits 24 & 25 set, so update this one to do the same. > > > > > > > > Many others? Looks like sparc and powerpc to me. > > > > > > > > > > s390 also does that, but it look like it comes from a device-tree. > > > > I'm only looking at DT based platforms, and s390 doesn't use DT. > > Correct. > Sorry, I somehow write above the opposite of what I was thinking. > > > > > > > Those would be the > > > > ones I worry about breaking. Sparc doesn't use of/address.c so it's > > > > fine. Powerpc version of the flags code was only fixed in 2019, so I > > > > don't think powerpc will care either. > > > > > > In powerpc I reach this function with this stack, while configuring a > > > virtio-net device for a qemu/KVM pseries guest: > > > > > > pci_process_bridge_OF_ranges+0xac/0x2d4 > > > pSeries_discover_phbs+0xc4/0x158 > > > discover_phbs+0x40/0x60 > > > do_one_initcall+0x60/0x2d0 > > > kernel_init_freeable+0x308/0x3a8 > > > kernel_init+0x2c/0x168 > > > ret_from_kernel_thread+0x5c/0x70 > > > > > > For this, both MMIO32 and MMIO64 resources will have flags 0x200. > > > > Oh good, powerpc has 2 possible flags parsing functions. So in the > > above path, do we need to set PCI_BASE_ADDRESS_MEM_TYPE_64? > > > > Does pci_parse_of_flags() get called in your case? > > > > It's called in some cases, but not for the device I am debugging > (virtio-net pci@800000020000000). > > For the above device, here is an expanded stack trace: > > of_bus_pci_get_flags() (from parser->bus->get_flags()) > of_pci_range_parser_one() (from macro for_each_of_pci_range) > pci_process_bridge_OF_ranges+0xac/0x2d4 > pSeries_discover_phbs+0xc4/0x158 > discover_phbs+0x40/0x60 > do_one_initcall+0x60/0x2d0 > kernel_init_freeable+0x308/0x3a8 > kernel_init+0x2c/0x168 > ret_from_kernel_thread+0x5c/0x70 > > For other devices, I could also see the following stack trace: > ## device ethernet@8 > > pci_parse_of_flags() > of_create_pci_dev+0x7f0/0xa40 > __of_scan_bus+0x248/0x320 > pcibios_scan_phb+0x370/0x3b0 > pcibios_init+0x8c/0x12c > do_one_initcall+0x60/0x2d0 > kernel_init_freeable+0x308/0x3a8 > kernel_init+0x2c/0x168 > ret_from_kernel_thread+0x5c/0x70 > > Devices that get parsed with of_bus_pci_get_flags() appears first at > dmesg (around 0.015s in my test), while devices that get parsed by > pci_parse_of_flags() appears later (0.025s in my test). > > I am not really used to this code, but having the term "discover phbs" > in the first trace and the term "scan phb" in the second, makes me > wonder if the first trace is seen on devices that are seen/described in > the device-tree and the second trace is seen in devices not present in > the device-tree and found scanning pci bus. That was my guess as well. I think on pSeries that most PCI devices are in the DT whereas on Arm and other flattened DT (non OpenFirmware) platforms PCI devices are not in DT. Of course, for virtio devices, they would not be in DT in either case. > > > > I noticed both sparc and powerpc set PCI_BASE_ADDRESS_MEM_TYPE_64 in > > > > the flags. AFAICT, that's not set anywhere outside of arch code. So > > > > never for riscv, arm and arm64 at least. That leads me to > > > > pci_std_update_resource() which is where the PCI code sets BARs and > > > > just copies the flags in PCI_BASE_ADDRESS_MEM_MASK ignoring > > > > IORESOURCE_* flags. So it seems like 64-bit is still not handled and > > > > neither is prefetch. > > > > > > > > > > I am not sure if you mean here: > > > a) it's ok to add IORESOURCE_MEM_64 here, because it does not affect > > > anything else, or > > > b) it should be using PCI_BASE_ADDRESS_MEM_TYPE_64 > > > (or IORESOURCE_MEM_64 | PCI_BASE_ADDRESS_MEM_TYPE_64) instead, since > > > it's how it's added in powerpc/sparc, and else there is no point. > > > > I'm wondering if a) is incomplete and PCI_BASE_ADDRESS_MEM_TYPE_64 > > also needs to be set. The question is ultimately are BARs getting set > > correctly for 64-bit? It looks to me like they aren't. > > I am not used to these terms, does BAR means 'Base Address Register'? Yes. Standard PCI thing. > If so, those are the addresses stored in pci->phb->mem_resources[i] and > pci->phb->mem_offset[i], printed from enable_ddw() (which takes place a > lot after discovering the device (0.17s in my run)). > > resource #1 pci@800000020000000: start=0x200080000000 > end=0x2000ffffffff flags=0x200 desc=0x0 offset=0x200000000000 > resource #2 pci@800000020000000: start=0x210000000000 > end=0x21ffffffffff flags=0x200 desc=0x0 offset=0x0 > > The message above was printed without this patch. > With the patch, the flags for memory resource #2 gets ORed with > 0x00100000. Right, as expected. > Is it enough to know if BARs are correctly set for 64-bit? No, because AFAICT, bit 2 in the BAR would not be set. > If it's not, how can I check? Can you try 'lspci -vv' and look at the 'Region X:' lines which will say 32 or 64-bit. I *think* that should reflect what actually got written into the BARs. Rob