Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp4064147rdb; Thu, 28 Dec 2023 08:57:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IHsM1VsW0cve4IG/MOx+K8Kh/UroVqXhL6CaOb8QFxHDej4kPIPoYMP8yGMBAbaUr14s+7G X-Received: by 2002:a17:906:208:b0:a26:88f4:7192 with SMTP id 8-20020a170906020800b00a2688f47192mr4362695ejd.34.1703782668486; Thu, 28 Dec 2023 08:57:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703782668; cv=none; d=google.com; s=arc-20160816; b=m9W79zIVIeG5MOeg5R1mAtFXKvls4AhYCNiwhoKSCmAj+rb60LSVB8HTSmXM5W07Uz Y4XIm4KipzgW2QMP/FDvpGA45J1SV1+dWl71Y95RQ6Vz7pgz7xt3DAWtbb+1X4ngx+Nz 9OVswShD6i9UpLvxFQ9iKVnd8NsURLq7kUfJMvayOj7sqUnubbLT/0PpfPXuPh/kzt42 EQFoq8m5yoonwWukTbApDJ/d8Edk6Ni82mEvCXZOEtUYB3iCzGi5cKY5Mtx/Kw2Jb35x AEtqh6rmkkBaZ01RiN4BFhmo9ZsB+v5mVcCw4IiEJJWZwizlxKzBb6f2T1l5bHKWhToh FdgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=gwEOFxbI2yDL2y6iq/2YGqhZ0x0H2WQKRKiCddsl91o=; fh=vws1ojMgn7Xtcq0W2UEGXR6D8J/YV6XONd4X+QA+ojA=; b=zIlu3VPGa7dsBL+rVpuQlyaR6Xh5pu4y7bxTf16FUCgYP1an/2mqtQC+7ZOAsq0QDx 5GdDsKZdASDD8gx5KAnyJX+C90AQbul78VkCSxtS8lXqErZC9/LaSQGgS917zxW1Uoi8 roUP0mAxTFU87aqWJk3zkUbsPNMcSLtqNNlrSRpUt2sUqv+yL7iTZYQL1V73MRCNAeNa AzVmOKOOdK8z5fr7KPIJgtkVX8hHbMVzCLlV17uMhCsScaI4UErAnk9oHdxTj3ray1S4 6xPwjLkEt7bhvO3LFAMcnQo9gyLHfWPod3EEiEYFm+8iWiFqTxcHOmXgChUzBdk2s3+A HQng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=AlQ3hn6V; spf=pass (google.com: domain of linux-kernel+bounces-12788-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12788-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id l22-20020a170906415600b00a231f444914si7092480ejk.412.2023.12.28.08.57.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Dec 2023 08:57:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-12788-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=AlQ3hn6V; spf=pass (google.com: domain of linux-kernel+bounces-12788-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12788-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 410A21F227D1 for ; Thu, 28 Dec 2023 16:57:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9C061F51C; Thu, 28 Dec 2023 16:57:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="AlQ3hn6V" X-Original-To: linux-kernel@vger.kernel.org Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BF584101C8; Thu, 28 Dec 2023 16:57:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1703782654; x=1735318654; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=LCe+OPVf6ypAOTjFWig95nNeJVsgngMAJh/hD3RJ254=; b=AlQ3hn6VQyZT+Yt+YqQ76HGZTBfE3/Qcf9XZViby66JOy81i7qPJ6L4S Ghe4qMMNl+z+9pV0xAxrLSFNvzu+MjOqah77U2u0cdARDWOu841CX/3DB 4uJPxBDi1b+wfBeYKO5ysY6ToW/CnWg9aoAr1Xvdgh+UgPanBB2KsNXin 7Ceqnr+w+5Plt43Y3AemSaDXiQCkUyQibZrOkkOfREbtul7TitYEtvz3q oWDsi3PMPtzzBr3Gkzcqbk0+WCdjJOb6hwL1OCEd1bfazxqODxFLdEVnZ HWuuhytGXPvNNCXq1uC2dIWmrHefTYFIzGfzf30eA+cl6ljSnNMNiFjlo Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10937"; a="399349946" X-IronPort-AV: E=Sophos;i="6.04,312,1695711600"; d="scan'208";a="399349946" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Dec 2023 08:57:34 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10937"; a="728356748" X-IronPort-AV: E=Sophos;i="6.04,312,1695711600"; d="scan'208";a="728356748" Received: from ijarvine-desk1.ger.corp.intel.com (HELO localhost) ([10.94.250.171]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Dec 2023 08:57:28 -0800 From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= To: linux-pci@vger.kernel.org, Bjorn Helgaas , Lorenzo Pieralisi , Rob Herring , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Igor Mammedov , Lukas Wunner , Mika Westerberg , Andy Shevchenko , "Rafael J . Wysocki" , Jesse Barnes , Yinghai Lu , linux-kernel@vger.kernel.org Cc: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Subject: [PATCH v2 1/7] PCI: Fix resource double counting on remove & rescan Date: Thu, 28 Dec 2023 18:57:01 +0200 Message-Id: <20231228165707.3447-2-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20231228165707.3447-1-ilpo.jarvinen@linux.intel.com> References: <20231228165707.3447-1-ilpo.jarvinen@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit pbus_size_mem() keeps the size of the optional resources in children_add_size. When calculating the PCI bridge window size, calculate_memsize() lower bounds size by old_size before adding children_add_size and performing the window size alignment. This results in double counting for the resources in children_add_size because old_size may be based on the previous size of the bridge window after it has already included children_add_size (that is, size1 in pbus_size_mem() from an earlier invocation of that function). As a result, on repeated remove of the bus & rescan cycles the resource size keeps increasing when children_add_size is non-zero as can be seen from this extract: iomem0: 23fffd00000-23fffdfffff : PCI Bus 0000:03 iomem1: 20000000000-200001fffff : PCI Bus 0000:03 iomem2: 20000000000-200002fffff : PCI Bus 0000:03 iomem3: 20000000000-200003fffff : PCI Bus 0000:03 iomem4: 20000000000-200004fffff : PCI Bus 0000:03 Solve the double counting by moving old_size check later in calculate_memsize() so that children_add_size is already accounted for. After the patch, the bridge window retains its size as expected: iomem0: 23fffd00000-23fffdfffff : PCI Bus 0000:03 iomem1: 20000000000-200000fffff : PCI Bus 0000:03 iomem2: 20000000000-200000fffff : PCI Bus 0000:03 Fixes: a4ac9fea016f ("PCI : Calculate right add_size") Signed-off-by: Ilpo Järvinen --- drivers/pci/setup-bus.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index fd74f1c99dba..e3e6ff8854a7 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -820,11 +820,9 @@ static resource_size_t calculate_memsize(resource_size_t size, size = min_size; if (old_size == 1) old_size = 0; - if (size < old_size) - size = old_size; - size = ALIGN(max(size, add_size) + children_add_size, align); - return size; + size = max(size, add_size) + children_add_size; + return ALIGN(max(size, old_size), align); } resource_size_t __weak pcibios_window_alignment(struct pci_bus *bus, -- 2.30.2