From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6441F606A322 for ; Sat, 5 Dec 2026 01:11:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=RbBwXA0E Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id EDFD8113234; Sat, 5 Dec 2026 01:11:50 +0000 (UTC) Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2404110E567; Sat, 5 Dec 2026 01:11:44 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 51750601C7; Sat, 5 Dec 2026 01:11:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C73BE1F0092B; Sat, 5 Dec 2026 01:11:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796433103; bh=SH5WvpbUUp386vGbNjEbtJEGFALquH0tjzAzEuoyxiI=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=RbBwXA0EdG++JkwChFUEgax5ATPPW51xjmk7R5ErXawczHca5CAh0+ic+o6gWSuZ8 XWQa05DnHKuZigzkJb2pADX+kk/q6lGeuc+xraySbTyD4xD2DQPiHYtaepCLPvWuhh E7AxA+lISwxw+bOVaQM4hqavQvc1Wj23lb9rD+D7gQw2fUVkOa0SJ6UmTiiFxz2us0 sZyG6xHV6yikNtyT6vYyK4uWwuj0gCo8c0zW3g4+UriG6D/kWzNyuZPEeiIbRVqJJL znF4TToYhWeGnd1Xuc6DwG+FAPjzlsa4du3l4AUAYmW0G7pZs+JoAgJVpAwJdM9BYa TFrs3oetZ0A5A== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v2 16/16] PCI: Release only PCI resources when releasing a resource tree To: =?utf-8?b?SWxwbyBKw6RydmluZW4=?= , dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, intel-xe@lists.freedesktop.org, linux-pci@vger.kernel.org In-Reply-To: <20261205003957.3304-17-ilpo.jarvinen@linux.intel.com> References: <20261205003957.3304-1-ilpo.jarvinen@linux.intel.com> <20261205003957.3304-17-ilpo.jarvinen@linux.intel.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 01:11:42 +0000 X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: sashiko-reviews@lists.linux.dev Sender: "Intel-gfx" X-Spam-Status: No, score=-11.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 X-Archived-By: Thank you for your contribution! Sashiko AI review found 4 potential issues to consider: - [Medium] PCI: BAR resize rollback fails on IORESOURCE_PCI_FIXED resources - [Medium] PCI: pci_release_resource_tree() walks bus->devices without pci_bus_sem - [Medium] PCI: pci_release_resource_tree() calls pci_info() under resource_lock - [Low] PCI: pci_bridge_release_resources() discards -EBUSY causing repeated rescans -- commit b918bf89459fc478f5ebfe229a3a0bbeb92b6ca2 Author: Ilpo J=C3=A4rvinen PCI: Release only PCI resources when releasing a resource tree This commit adds pci_release_resource_tree() to check and release only PCI resources underneath a bridge window under resource_lock, and switches pci_bridge_release_resources() and BAR resize rollback to use it. Link: https://lore.kernel.org/linux-pci/20260727193714.598562-1-anthony.pig= hin@nokia.com/ > diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c > index 033f5fab7cc06..e14066c6aa8d8 100644 > --- a/drivers/pci/setup-bus.c > +++ b/drivers/pci/setup-bus.c > @@ -1666,10 +1666,7 @@ static void pci_bridge_release_resources(struct pc= i_bus *bus, > =20 > idx =3D pci_resource_num(dev, b_win); > =20 > - /* If there are children, release them all */ > - release_child_resources(b_win); > - > - ret =3D pci_release_resource(dev, idx); > + ret =3D pci_release_resource_tree(dev, idx); > if (ret) > return; [Severity: Low] Should pci_bridge_release_resources() propagate the -EBUSY failure instead of discarding ret? When a descendant is pinned, pci_release_resource_tree() leaves b_win assigned, so every ancestor bridge in pci_bus_release_bridge_resources(..., whole_subtree) re-walks the same unreleased branch under resource_lock and repeats the same pci_info() message. Because b_win stays assigned, each remaining failed resource on that bus in pci_prepare_next_assign_round() and each retry round in pci_assign_unassigned_root_bus_resources() then repeats those rescans and duplicate logs. [ ... ] > @@ -2472,8 +2469,7 @@ int pci_do_resource_release_and_resize(struct pci_d= ev *pdev, int resno, int size > if (!resource_assigned(res)) > continue; > =20 > - release_child_resources(res); > - pci_release_resource(dev, i); > + pci_release_resource_tree(dev, i); > } > =20 > /* Restore parents before their children */ > @@ -2483,6 +2479,10 @@ int pci_do_resource_release_and_resize(struct pci_= dev *pdev, int resno, int size > =20 > i =3D pci_resource_num(dev, res); > =20 > + /* All saved resources were released once before the resize */ > + if (WARN_ON_ONCE(resource_assigned(res))) > + continue; > + > pci_dev_res_restore(dev_res); > =20 > if (pci_claim_resource(dev, i)) [Severity: Medium] Can BAR resize rollback fail here when an IORESOURCE_PCI_FIXED resource shares the resized bridge window? Before resizing, pci_do_resource_release_and_resize() releases pdev's BARs with pci_release_resource(), which allows releasing IORESOURCE_PCI_FIXED resources. During the failed resize attempt, __pci_bus_assign_resources_one() -> pdev_assign_fixed_resources() re-claims that fixed BAR (or claims a sibling's fixed resource inside a moved window). On rollback, pci_can_release_resource_tree() rejects fixed resources and ancestor windows containing them, so pci_release_resource_tree() returns -EBUSY. The restore loop then hits WARN_ON_ONCE(resource_assigned(res)) and skips restoring the window, stranding other BARs if the window moved. Also, releasing an IORESOURCE_PCI_FIXED BAR via pci_release_resource() befo= re the resize can unpin its parent bridge window even on a successful resize. > diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c > index 82efd4a76c153..848d05fbe76fe 100644 > --- a/drivers/pci/setup-res.c > +++ b/drivers/pci/setup-res.c > @@ -502,6 +502,113 @@ int pci_release_resource(struct pci_dev *dev, int r= esno) [ ... ] > + if (bus) { > + pci_bus_for_each_window_resource(bus, res, child, r) { > + pci_children++; > + if (!pci_can_release_resource_tree(child, r)) > + return false; > + } > + } [Severity: Medium] Is it safe to walk bus->devices here and in __pci_release_resource_tree() without holding pci_bus_sem? CPU0 CPU1 pci_host_probe() ... pci_bridge_release_resources() pci_release_resource_tree() write_lock(&resource_lock) remove_store() ... pci_destroy_dev() down_write(&pci_bus_sem) list_del(&dev->bus_list) up_write(&pci_bus_sem) pci_bus_next_window_dev() reads dev->bus_list <-- LIST_POISON1 / use-after-free pci_do_resource_release_and_resize() holds down_read(&pci_bus_sem), but pci_bridge_release_resources() does not, and callers like pci_host_probe() or acpi_pci_root_add() reach it without pci_rescan_remove_lock either (SR-IOV probe/remove paths also mutate bus->devices under pci_bus_sem). pci_destroy_dev() unlinks dev->bus_list before acquiring resource_lock in pci_free_resources(), so resource_lock does not prevent list corruption or use-after-free. Asserting lockdep_assert_held(&pci_bus_sem) here and taking down_read(&pci_bus_sem) in pci_bridge_release_resources() fixes it. [ ... ] > +static void __pci_release_resource_tree(struct pci_dev *dev, > + struct resource *res) > +{ > + int resno =3D pci_resource_num(dev, res); > + struct pci_bus *bus =3D dev->subordinate; > + struct pci_dev *child; > + struct resource *r; > + > + lockdep_assert_held_write(&resource_lock); > + > + if (bus) { > + pci_bus_for_each_window_resource(bus, res, child, r) > + __pci_release_resource_tree(child, r); > + } > + > + if (release_resource_locked(res)) { > + const char *res_name =3D pci_resource_name(dev, resno); > + > + pci_dbg(dev, "%s %pR: can't release\n", res_name, res); > + return; > + } > + > + pci_resource_post_release(dev, resno); > +} [ ... ] > +int pci_release_resource_tree(struct pci_dev *dev, int resno) > +{ > + struct resource *res =3D pci_resource_n(dev, resno); > + > + guard(write_lock)(&resource_lock); > + > + if (!resource_assigned(res)) > + return 0; > + > + if (!pci_can_release_resource_tree(dev, res)) > + return -EBUSY; > + > + __pci_release_resource_tree(dev, res); > + > + return 0; > +} [Severity: Medium] Can holding write_lock(&resource_lock) across the pci_info() calls in pci_resource_post_release() and pci_can_release_resource_tree() stall other CPUs on slow consoles? At default console_loglevel, LOGLEVEL_INFO messages flush synchronously on legacy framebuffer or serial consoles via console_unlock(), holding the spinning resource_lock with preemption disabled for tens to hundreds of milliseconds while other CPUs spin in ioremap() or /proc/iomem. Previously, release_child_resources() only logged at KERN_DEBUG under resource_lock and pci_release_resource() called pci_info() after dropping it. Also, unlike pci_can_release_resource_tree(), __pci_release_resource_tree() does not check res->child before entering pci_bus_for_each_window_resource(= ), scanning subordinate devices even when res has no children. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261205003957.3304= -1-ilpo.jarvinen@linux.intel.com?part=3D16