{"id":2221662,"url":"http://patchwork.ozlabs.org/api/patches/2221662/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-pci/patch/20260410052918.5556-2-gloveless@jqluv.com/","project":{"id":28,"url":"http://patchwork.ozlabs.org/api/projects/28/?format=json","name":"Linux PCI development","link_name":"linux-pci","list_id":"linux-pci.vger.kernel.org","list_email":"linux-pci@vger.kernel.org","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20260410052918.5556-2-gloveless@jqluv.com>","list_archive_url":null,"date":"2026-04-10T05:26:02","name":"[v2] PCI: release empty sibling bridge windows during rebar expansion","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"a4719216f4eab14b591a1e1b7e151d335debcc3e","submitter":{"id":93094,"url":"http://patchwork.ozlabs.org/api/people/93094/?format=json","name":"Geramy Loveless","email":"gloveless@jqluv.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/linux-pci/patch/20260410052918.5556-2-gloveless@jqluv.com/mbox/","series":[{"id":499396,"url":"http://patchwork.ozlabs.org/api/series/499396/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-pci/list/?series=499396","date":"2026-04-10T05:26:02","name":"[v2] PCI: release empty sibling bridge windows during rebar expansion","version":2,"mbox":"http://patchwork.ozlabs.org/series/499396/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2221662/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2221662/checks/","tags":{},"related":[],"headers":{"Return-Path":"\n <linux-pci+bounces-52260-incoming=patchwork.ozlabs.org@vger.kernel.org>","X-Original-To":["incoming@patchwork.ozlabs.org","linux-pci@vger.kernel.org"],"Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=jqluv-com.20251104.gappssmtp.com\n header.i=@jqluv-com.20251104.gappssmtp.com header.a=rsa-sha256\n header.s=20251104 header.b=w32qjMo3;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=2600:3c0a:e001:db::12fc:5321; helo=sea.lore.kernel.org;\n envelope-from=linux-pci+bounces-52260-incoming=patchwork.ozlabs.org@vger.kernel.org;\n receiver=patchwork.ozlabs.org)","smtp.subspace.kernel.org;\n\tdkim=pass (2048-bit key) header.d=jqluv-com.20251104.gappssmtp.com\n header.i=@jqluv-com.20251104.gappssmtp.com header.b=\"w32qjMo3\"","smtp.subspace.kernel.org;\n arc=none smtp.client-ip=74.125.82.44","smtp.subspace.kernel.org;\n dmarc=none (p=none dis=none) header.from=jqluv.com","smtp.subspace.kernel.org;\n spf=none smtp.mailfrom=jqluv.com"],"Received":["from sea.lore.kernel.org (sea.lore.kernel.org\n [IPv6:2600:3c0a:e001:db::12fc:5321])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fsQQF4y4Xz1yCv\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 10 Apr 2026 15:31:17 +1000 (AEST)","from smtp.subspace.kernel.org (conduit.subspace.kernel.org\n [100.90.174.1])\n\tby sea.lore.kernel.org (Postfix) with ESMTP id 5A08D300B06F\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 10 Apr 2026 05:30:57 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id BDE0130E838;\n\tFri, 10 Apr 2026 05:30:56 +0000 (UTC)","from mail-dl1-f44.google.com (mail-dl1-f44.google.com\n [74.125.82.44])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))\n\t(No client certificate requested)\n\tby smtp.subspace.kernel.org (Postfix) with ESMTPS id 0903C20010A\n\tfor <linux-pci@vger.kernel.org>; Fri, 10 Apr 2026 05:30:54 +0000 (UTC)","by mail-dl1-f44.google.com with SMTP id\n a92af1059eb24-128e4d0cc48so8967658c88.1\n        for <linux-pci@vger.kernel.org>; Thu, 09 Apr 2026 22:30:54 -0700 (PDT)","from geramyl-MS-S1-MAX.. ([2601:201:8080:e5c0:4e7a:601e:5f03:c2a7])\n        by smtp.gmail.com with ESMTPSA id\n 5a478bee46e88-2d561bde68bsm2796529eec.17.2026.04.09.22.30.53\n        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n        Thu, 09 Apr 2026 22:30:53 -0700 (PDT)"],"ARC-Seal":"i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1775799056; cv=none;\n b=PcBvNhhfN2z5fk6BZw/C/uCuBCVVRhUWejNqpIYKe7zqq7x0EXoHVMtEMsVDzPzXUN0F/g66PBwvLjRm6E1QsydXTPwWfeS74uAI116c5owuegWu0pJ3D3x/1bvtPC5ROhq4+o0L4QBCgJGh6BuTOzVVazeYz0cldwNiJuaCl8I=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1775799056; c=relaxed/simple;\n\tbh=XkuetcQHM3A7I1YGHrZfr42BJ3/QhNVvyt7EGlGJdmA=;\n\th=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:\n\t MIME-Version:Content-Type;\n b=h8so2aIbuhMVndUwLNbiNJ+LKcSwCykmta0il8AAUR2HnoWOhTbW7A4Z3ehz4DM8HylJessP4uUcIricl/A7MTzOlXGwBCWnLhnAwL+cqaD5PkQ/mQ+BUvPzUBZe7LkLzeszk670r41xk+p6iAB+8Vial9SsNsPUINHeRRfqFVU=","ARC-Authentication-Results":"i=1; smtp.subspace.kernel.org;\n dmarc=none (p=none dis=none) header.from=jqluv.com;\n spf=none smtp.mailfrom=jqluv.com;\n dkim=pass (2048-bit key) header.d=jqluv-com.20251104.gappssmtp.com\n header.i=@jqluv-com.20251104.gappssmtp.com header.b=w32qjMo3;\n arc=none smtp.client-ip=74.125.82.44","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=jqluv-com.20251104.gappssmtp.com; s=20251104; t=1775799054;\n x=1776403854; darn=vger.kernel.org;\n        h=content-transfer-encoding:mime-version:references:in-reply-to\n         :message-id:date:subject:cc:to:from:from:to:cc:subject:date\n         :message-id:reply-to;\n        bh=INYeksj8U+IbdS6ka7WkcvOr+zbRscbIhjwqU/8dvac=;\n        b=w32qjMo3HbcgwPKmjllo1z8M9OMff9C+2APrG/NgHTp7SmwR1b7hxjyNpQoLbTLS1f\n         cIBEOjyV7CfcE5DgfgV52o0wnAqBT0Pgj55+sjUklky1AtSle8olJkDuGuhl5KYoq2wL\n         eXDPfC8liALW0qehTafQhia3c8I/rYLajQQwe+BnJdXNWR7tFDbB/2vgN3KjVp7uc8oi\n         9PCT18ZtmmGxMvHLtVbV4VfNYmGEe+3y3csXbsFuCaQig2D4a5xjmdRrp+CWGJYcib/6\n         Qb0WTucJnL+iSiU9sN4rwqlfLrxj0cp49pbKiuPoUqjBDLKxFjJEi7qzyL2RT1SjEaOL\n         /2mA==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=1e100.net; s=20251104; t=1775799054; x=1776403854;\n        h=content-transfer-encoding:mime-version:references:in-reply-to\n         :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from\n         :to:cc:subject:date:message-id:reply-to;\n        bh=INYeksj8U+IbdS6ka7WkcvOr+zbRscbIhjwqU/8dvac=;\n        b=WXQb6AoO4IDoPtzxHpeRx+7OybJoso5ErimddD0H1pHBlUbwyNzRVnhn4le1SFdesn\n         AYCnAcGpmO4DYV8T6KZrh2c36/MhWj9+4FiDJGzcBcU4w7CoWI2S6jwizyo9Y2p8VpKH\n         cKC5qV4R5jRFoeOR1I4d5PUCxmh9tHfg4jUE8JKYSFShficKbs/C6LZszrP1kxPwYab8\n         i9q9P2wPPfDsT3jxwY0iRnpTPdjrEP3nnkJ1AO4dS47CEGrZimE3rKBKB0lAalgE6srP\n         Do/6NQlhzl1vFjzgVOCdAeNdQ0jTaBfbmS9kBM/afVgyq9VWZwiBfSkmzulz4GKC3e+d\n         ympg==","X-Forwarded-Encrypted":"i=1;\n AJvYcCXNoYbHF/9yKm6QksnFD+owGviuqPkNLW+neMk1+R1tjZwD7+DchwnyZbkflK7JBApMl0UjvcJ3U2k=@vger.kernel.org","X-Gm-Message-State":"AOJu0YwnH5llP84/fjXne9Tkoqim6X+BhYcpDpBmQ9HmUxR/eipOO4ep\n\toBeYJ2BwgTCQrD1VwhkME6jvv4O67VB5T9Fs+KEJOnnOKBxuN7KDQ3pUSJiY7q6rta8=","X-Gm-Gg":"AeBDievlPXTtq8KHceTo/2kSTUU6b9PXBysFWMud0TB//MY3SvnsUBv0w7AYHghQeGQ\n\tH2GxEcIwUMTvG7+zb/Ck6YvuPUPsvx1uwuDCuvbdugWObw3CLSfrs9OjFxLMBaJBtZ5o3z3adNm\n\tBFDFFLov3fW2ZzBetdOI9OHQPtugxlhU0MwoCf9VLuencbjx9JLthA6CUk5TsXmOYJeDel4l7AC\n\toUoST9FulXVmR8DTTLsfUEknyuK6pPOzoyUHBspEOajFMCyRmYu0NW1W6MHlxny2pAyDrcs+4EQ\n\t65KS8yV/dccOQS3U6h4YS1j1K07e+iz6GEDqIJXSRMBvFm1wqT/Y2G1kV6fJlm12GbKkzqafzbX\n\tqBvl88ZA5pg4+rHVG/tAAc4RW3reC1MWkUXefVsng7pGGqZNVMoRcYh/3Vjn49q/SGa+nwRn5bD\n\tznIWSoA2fRwPYO+Ycp5eUFHVan7DFhNOhLyCxU","X-Received":"by 2002:a05:7300:ed0f:b0:2c5:50fe:c78f with SMTP id\n 5a478bee46e88-2d587c85e31mr1047023eec.12.1775799053874;\n        Thu, 09 Apr 2026 22:30:53 -0700 (PDT)","From":"Geramy Loveless <gloveless@jqluv.com>","To":"ilpo.jarvinen@linux.intel.com","Cc":"Geramy Loveless <gloveless@jqluv.com>,\n\tlinux-pci@vger.kernel.org,\n\tcristi@ieee.org","Subject":"[PATCH v2] PCI: release empty sibling bridge windows during rebar\n expansion","Date":"Thu,  9 Apr 2026 22:26:02 -0700","Message-ID":"<20260410052918.5556-2-gloveless@jqluv.com>","X-Mailer":"git-send-email 2.43.0","In-Reply-To":"<29a5ee31baf8be7d07617beea016c3f6d03934bf.camel@ieee.org>","References":"<29a5ee31baf8be7d07617beea016c3f6d03934bf.camel@ieee.org>","Precedence":"bulk","X-Mailing-List":"linux-pci@vger.kernel.org","List-Id":"<linux-pci.vger.kernel.org>","List-Subscribe":"<mailto:linux-pci+subscribe@vger.kernel.org>","List-Unsubscribe":"<mailto:linux-pci+unsubscribe@vger.kernel.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=UTF-8","Content-Transfer-Encoding":"8bit"},"content":"When pbus_reassign_bridge_resources() walks up the bridge hierarchy\nto expand a window (e.g. for resizable BAR), it refuses to release\nany bridge window that has children.  This prevents BAR resize on\ndevices behind multi-port PCIe switches (such as Thunderbolt docks)\nwhere empty sibling downstream ports hold small reservations that\nblock the parent bridge window from being freed and re-sized.\n\nAdd pci_bus_subtree_empty() to check whether a bus subtree contains\nany assigned device BARs, and pci_bus_release_empty_bridges() to\nrelease bridge window resources of empty sibling bridges, saving\nthem to the rollback list so failures can be properly unwound.\n\nIn pbus_reassign_bridge_resources(), call pci_bus_release_empty_bridges()\nbefore checking res->child, so empty sibling windows are cleared first\nand the parent window can then be released and grown.\n\nUses PCI bus/device iterators rather than walking the raw resource\ntree, which avoids issues with stale sibling pointers after resource\nrelease.\n\nSuggested-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>\nSigned-off-by: Geramy Loveless <gloveless@jqluv.com>\n---\n drivers/pci/setup-bus.c | 99 ++++++++++++++++++++++++++++++++++++++++-\n 1 file changed, 97 insertions(+), 2 deletions(-)","diff":"diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c\nindex 4cf120ebe5a..7a182cd7e4d 100644\n--- a/drivers/pci/setup-bus.c\n+++ b/drivers/pci/setup-bus.c\n@@ -2292,6 +2292,94 @@ void pci_assign_unassigned_bridge_resources(struct pci_dev *bridge)\n }\n EXPORT_SYMBOL_GPL(pci_assign_unassigned_bridge_resources);\n \n+/*\n+ * pci_bus_subtree_empty - Check whether a bus subtree has any assigned\n+ * non-bridge device resources.\n+ * @bus: PCI bus to check\n+ *\n+ * Returns true if no device on @bus or its descendant buses has any\n+ * assigned BARs (bridge window resources are not considered).\n+ */\n+static bool pci_bus_subtree_empty(struct pci_bus *bus)\n+{\n+\tstruct pci_dev *dev;\n+\n+\tlist_for_each_entry(dev, &bus->devices, bus_list) {\n+\t\tstruct resource *r;\n+\t\tunsigned int i;\n+\n+\t\tpci_dev_for_each_resource(dev, r, i) {\n+\t\t\tif (i >= PCI_BRIDGE_RESOURCES)\n+\t\t\t\tbreak;\n+\t\t\tif (resource_assigned(r))\n+\t\t\t\treturn false;\n+\t\t}\n+\n+\t\tif (dev->subordinate &&\n+\t\t    !pci_bus_subtree_empty(dev->subordinate))\n+\t\t\treturn false;\n+\t}\n+\n+\treturn true;\n+}\n+\n+/*\n+ * pci_bus_release_empty_bridges - Release bridge window resources of\n+ * empty sibling bridges so the parent window can be freed and re-sized.\n+ * @bus: PCI bus whose child bridges to scan\n+ * @b_win: Parent bridge window resource; only children of this window\n+ *         are released\n+ * @saved: List to save released resources for rollback\n+ *\n+ * For each PCI-to-PCI bridge on @bus whose subtree is empty (no assigned\n+ * device BARs), releases bridge window resources that are children of\n+ * @b_win, saving them for rollback via @saved.\n+ *\n+ * Returns 0 on success, negative errno on failure.\n+ */\n+static int pci_bus_release_empty_bridges(struct pci_bus *bus,\n+\t\t\t\t\t struct resource *b_win,\n+\t\t\t\t\t struct list_head *saved)\n+{\n+\tstruct pci_dev *dev;\n+\n+\tlist_for_each_entry(dev, &bus->devices, bus_list) {\n+\t\tstruct resource *r;\n+\t\tunsigned int i;\n+\n+\t\tif (!dev->subordinate)\n+\t\t\tcontinue;\n+\n+\t\tif ((dev->class >> 8) != PCI_CLASS_BRIDGE_PCI)\n+\t\t\tcontinue;\n+\n+\t\tif (!pci_bus_subtree_empty(dev->subordinate))\n+\t\t\tcontinue;\n+\n+\t\tpci_dev_for_each_resource(dev, r, i) {\n+\t\t\tint ret;\n+\n+\t\t\tif (!pci_resource_is_bridge_win(i))\n+\t\t\t\tcontinue;\n+\n+\t\t\tif (!resource_assigned(r))\n+\t\t\t\tcontinue;\n+\n+\t\t\tif (r->parent != b_win)\n+\t\t\t\tcontinue;\n+\n+\t\t\tret = pci_dev_res_add_to_list(saved, dev, r, 0, 0);\n+\t\t\tif (ret)\n+\t\t\t\treturn ret;\n+\n+\t\t\trelease_child_resources(r);\n+\t\t\tpci_release_resource(dev, i);\n+\t\t}\n+\t}\n+\n+\treturn 0;\n+}\n+\n /*\n  * Walk to the root bus, find the bridge window relevant for @res and\n  * release it when possible. If the bridge window contains assigned\n@@ -2316,7 +2404,14 @@ static int pbus_reassign_bridge_resources(struct pci_bus *bus, struct resource *\n \n \t\ti = pci_resource_num(bridge, res);\n \n-\t\t/* Ignore BARs which are still in use */\n+\t\t/* Release empty sibling bridge windows first */\n+\t\tif (bridge->subordinate) {\n+\t\t\tret = pci_bus_release_empty_bridges(\n+\t\t\t\t\tbridge->subordinate, res, saved);\n+\t\t\tif (ret)\n+\t\t\t\treturn ret;\n+\t\t}\n+\n \t\tif (!res->child) {\n \t\t\tret = pci_dev_res_add_to_list(saved, bridge, res, 0, 0);\n \t\t\tif (ret)\n@@ -2327,7 +2422,7 @@ static int pbus_reassign_bridge_resources(struct pci_bus *bus, struct resource *\n \t\t\tconst char *res_name = pci_resource_name(bridge, i);\n \n \t\t\tpci_warn(bridge,\n-\t\t\t\t \"%s %pR: was not released (still contains assigned resources)\\n\",\n+\t\t\t\t \"%s %pR: not released, active children present\\n\",\n \t\t\t\t res_name, res);\n \t\t}\n \n","prefixes":["v2"]}