From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 13ABAC432C3 for ; Wed, 13 Nov 2019 16:51:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8C60D206CC for ; Wed, 13 Nov 2019 16:51:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728630AbfKMQvE (ORCPT ); Wed, 13 Nov 2019 11:51:04 -0500 Received: from ale.deltatee.com ([207.54.116.67]:38646 "EHLO ale.deltatee.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726755AbfKMQvC (ORCPT ); Wed, 13 Nov 2019 11:51:02 -0500 Received: from s0106ac1f6bb1ecac.cg.shawcable.net ([70.73.163.230] helo=[192.168.11.155]) by ale.deltatee.com with esmtpsa (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1iUvr5-0004JU-OS; Wed, 13 Nov 2019 09:50:56 -0700 To: Nicholas Johnson , "linux-kernel@vger.kernel.org" Cc: "linux-pci@vger.kernel.org" , "bhelgaas@google.com" , "mika.westerberg@linux.intel.com" , "corbet@lwn.net" , "benh@kernel.crashing.org" References: From: Logan Gunthorpe Message-ID: <7f824f5f-ee0f-0591-9170-1433c0813857@deltatee.com> Date: Wed, 13 Nov 2019 09:50:50 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-SA-Exim-Connect-IP: 70.73.163.230 X-SA-Exim-Rcpt-To: benh@kernel.crashing.org, corbet@lwn.net, mika.westerberg@linux.intel.com, bhelgaas@google.com, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, nicholas.johnson-opensource@outlook.com.au X-SA-Exim-Mail-From: logang@deltatee.com Subject: Re: [PATCH v3 1/1] PCI: Fix bug resulting in double hpmemsize being assigned to MMIO window X-SA-Exim-Version: 4.2.1 (built Wed, 08 May 2019 21:11:16 +0000) X-SA-Exim-Scanned: Yes (on ale.deltatee.com) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2019-11-13 8:25 a.m., Nicholas Johnson wrote: > Currently, the kernel can sometimes assign the MMIO_PREF window > additional size into the MMIO window, resulting in extra MMIO additional > size, despite the MMIO_PREF additional size being assigned successfully > into the MMIO_PREF window. > > This happens if in the first pass, the MMIO_PREF succeeds but the MMIO > fails. In the next pass, because MMIO_PREF is already assigned, the > attempt to assign MMIO_PREF returns an error code instead of success > (nothing more to do, already allocated). Hence, the size which is > actually allocated, but thought to have failed, is placed in the MMIO > window. > > Example of problem (more context can be found in the bug report URL): > > Mainline kernel: > pci 0000:06:01.0: BAR 14: assigned [mem 0x90100000-0xa00fffff] = 256M > pci 0000:06:04.0: BAR 14: assigned [mem 0xa0200000-0xb01fffff] = 256M > > Patched kernel: > pci 0000:06:01.0: BAR 14: assigned [mem 0x90100000-0x980fffff] = 128M > pci 0000:06:04.0: BAR 14: assigned [mem 0x98200000-0xa01fffff] = 128M > > This was using pci=realloc,hpmemsize=128M,nocrs - on the same machine > with the same configuration, with a Ubuntu mainline kernel and a kernel > patched with this patch. > > The bug results in the MMIO_PREF being added to the MMIO window, which > means doubling if MMIO_PREF size = MMIO size. With a large MMIO_PREF, > the MMIO window will likely fail to be assigned altogether due to lack > of 32-bit address space. > > Change find_free_bus_resource() to do the following: > - Return first unassigned resource of the correct type. > - If none of the above, return first assigned resource of the correct type. > - If none of the above, return NULL. > > Returning an assigned resource of the correct type allows the caller to > distinguish between already assigned and no resource of the correct type. > > Rename find_free_bus_resource to find_bus_resource_of_type(). > > Add checks in pbus_size_io() and pbus_size_mem() to return success if > resource returned from find_free_bus_resource() is already allocated. > > This avoids pbus_size_io() and pbus_size_mem() returning error code to > __pci_bus_size_bridges() when a resource has been successfully assigned > in a previous pass. This fixes the existing behaviour where space for a > resource could be reserved multiple times in different parent bridge > windows. > > Link: https://lore.kernel.org/lkml/20190531171216.20532-2-logang@deltatee.com/T/#u > Link: https://bugzilla.kernel.org/show_bug.cgi?id=203243 > > Reported-by: Kit Chow > Reported-by: Nicholas Johnson > Signed-off-by: Nicholas Johnson > Reviewed-by: Mika Westerberg You can add mine as well: Reviewed-by: Logan Gunthorpe Thanks, Logan