From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 2539D189502; Tue, 30 Jul 2024 16:18:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722356304; cv=none; b=nfbRzwSJ1AdTq+ICppkiFRtlLrs60Y9UVnmB2VysN/FNaP3K/wTo1mQtNPrm+slyYUL/daI0aoX9Q/pGdIUpqUlnvZKBl0TzbVYV5ArWeujEK4CJylOa2p75SqQrOdVaWeESK4yTZbIfsgO9EFs738ZmOhV3nn1gCZ9ntXw1k/M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722356304; c=relaxed/simple; bh=bOmxK+LvRR/HZkb4omGd8zK2AAFJSO0wIitwICyER00=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DD0SFgIDpdSnGY98xXuuTmhoJtN3mrNSLsdTfcjsTS7K1ROUJ3gk1lX/Mcs+VQNKvtwTsNI9STWqO/1Uvh/itF5hRllnaUxZls5iLbQ7UTO+xs5T6xrwUX8pjYVSKkY7GazZr48XlrQQBX7biCt4o2sE0F1hNuIFwO3lMvylcJ0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=GJWONIf3; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="GJWONIf3" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8C048C32782; Tue, 30 Jul 2024 16:18:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1722356304; bh=bOmxK+LvRR/HZkb4omGd8zK2AAFJSO0wIitwICyER00=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GJWONIf3bkCm4kBXYtPDPgH4DyPxT71YHZV4LqNS0Et2vk6CViirX0J/GU5WDCbaq 6tGiq9O0Us0UwZfstAji0sGAnNU77RChj6+37s0V1UsNh7jDxAOClDYf6s0d6m1yEg lxBP4youl+aIVk/khHOhMfqj6CVdVFGO1VES4PKU= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Lidong Wang , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Bjorn Helgaas , Mika Westerberg , Sasha Levin Subject: [PATCH 6.1 177/440] PCI: Fix resource double counting on remove & rescan Date: Tue, 30 Jul 2024 17:46:50 +0200 Message-ID: <20240730151622.785837557@linuxfoundation.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240730151615.753688326@linuxfoundation.org> References: <20240730151615.753688326@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ilpo Järvinen [ Upstream commit 903534fa7d30214d8ba840ab1cd9e917e0c88e41 ] 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 # 1MiB iomem1: 20000000000-200001fffff : PCI Bus 0000:03 # 2MiB iomem2: 20000000000-200002fffff : PCI Bus 0000:03 # 3MiB iomem3: 20000000000-200003fffff : PCI Bus 0000:03 # 4MiB iomem4: 20000000000-200004fffff : PCI Bus 0000:03 # 5MiB 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 # 1MiB iomem1: 20000000000-200000fffff : PCI Bus 0000:03 # 1MiB iomem2: 20000000000-200000fffff : PCI Bus 0000:03 # 1MiB Fixes: a4ac9fea016f ("PCI : Calculate right add_size") Link: https://lore.kernel.org/r/20240507102523.57320-2-ilpo.jarvinen@linux.intel.com Tested-by: Lidong Wang Signed-off-by: Ilpo Järvinen Signed-off-by: Bjorn Helgaas Reviewed-by: Mika Westerberg Signed-off-by: Sasha Levin --- 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 c690572b10ce7..b8cb990044fb2 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -824,11 +824,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.43.0