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 701DD606A322 for ; Sat, 5 Dec 2026 01:04:26 +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=QL8zkBsF Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id F30BA1131DA; Sat, 5 Dec 2026 01:04:20 +0000 (UTC) Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9BBE010ED24; Sat, 5 Dec 2026 01:04:14 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 83FAB43217; Sat, 5 Dec 2026 01:04:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 306C61F0092B; Sat, 5 Dec 2026 01:04:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796432654; bh=NGPYu0e6vRAH8Bdea5wQxjoIn1u7mwhX9qhUQiZo4vo=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=QL8zkBsFqDK5VdfmKwIqCtnjedXVSoHygi2aO3KmxBx2JPjwmETtfyo0vi+zAyLUC pd1hOFwtyVeODpHzfMtQG0LQ5UrhlJWib2JaqqWrQvqaBerJUPBSMYu+NBrFA2kzS9 5jkeDIMPPONrY4EaYXPmcDIPFlXLXL2shLeg/uhBbd94GMCyu+WgPL/fFbVkV/KMVN ANDitO77COt9/+WkbsrYikO65ZfHkCOQUJXkHAsHzUaKgQnOWgGVqKjvLpangEk0BS opIZ57WpxKQY9kfQ9qwK63aH1kfLnWKu0E+OiZGR3HDL7uOAJmabg+usxwTlHw2LDS W2JPjC71eQQmg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v2 09/16] PCI: Do not release resources with children in pci_release_resource() 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-10-ilpo.jarvinen@linux.intel.com> References: <20261205003957.3304-1-ilpo.jarvinen@linux.intel.com> <20261205003957.3304-10-ilpo.jarvinen@linux.intel.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 01:04:13 +0000 X-BeenThere: amd-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion list for AMD gfx List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: sashiko-reviews@lists.linux.dev Sender: "amd-gfx" X-Spam-Status: No, score=-16.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=ham 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 3 potential issues to consider: - [Medium] PCI: unchecked pci_release_resource() failure in __assign_resources_sorted() - [Low] PCI: pci_release_resource() misreports -EINVAL as busy on parent TOCTOU race - [Low] PCI: missing Fixes trailer for pci_release_resource() bug fix -- commit ed0359ff94feed20c50628f709669e28b10a5020 Author: Ilpo J=C3=A4rvinen > PCI: Do not release resources with children in pci_release_resource() > > pci_release_resource() releases the resource using release_resource() > which detaches the resource from the resource tree together with its > descendants. The descendants remain attached to the released resource > and keep their addresses. Once the resource is assigned elsewhere, the > descendants may end up outside of their parent, corrupting the resource > tree. > > None of the callers wants that. pbus_reassign_bridge_resources() only > releases bridge windows that have no children. The BAR resize rollback > releases the children before releasing the resource itself. The BARs > released before BAR resize, however, are released even if they contain > regions requested by a driver, and the resize may then move such a BAR > from underneath those regions. > > Use release_leaf_resource() in pci_release_resource() to return -EBUSY > if the resource has children. Remove a BAR that cannot be released from > the saved resources so that the BAR resize rollback leaves it alone, and > fail BAR resize if it is the resized BAR. > > pbus_reassign_bridge_resources() checks for children without holding > resource_lock, so a child may still appear before the release. Remove > such a bridge window from the saved resources too so that the rollback > does not release the resources underneath it. > > As the release can now fail, log both outcomes. > > Signed-off-by: Ilpo J=C3=A4rvinen [Severity: Low] This looks like a bug fix for pci_release_resource() detaching resources that still have children. Should this include: Fixes: 8bb705e3e79d ("PCI: Add pci_resize_resource() for resizing BARs") [ ... ] > diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c > index 376f09630a4ab..1317d645a178a 100644 > --- a/drivers/pci/setup-res.c > +++ b/drivers/pci/setup-res.c > @@ -472,11 +472,15 @@ int pci_release_resource(struct pci_dev *dev, int r= esno) > if (!res->parent) > return 0; > =20 > - pci_info(dev, "%s %pR: releasing\n", res_name, res); > - > - ret =3D release_resource(res); > - if (ret) > + ret =3D release_leaf_resource(res); [Severity: Medium] Now that pci_release_resource() can return -EBUSY, does __assign_resources_sorted() need to handle a release failure too? Its fallback path ignores the return value and leaves dev_res on head, save_head, and realloc_head: drivers/pci/setup-bus.c:__assign_resources_sorted() { ... /* Release assigned resource */ list_for_each_entry(dev_res, head, list) { res =3D dev_res->res; dev =3D dev_res->dev; pci_release_resource(dev, pci_resource_num(dev, res)); pci_dev_res_restore(dev_res); } ... } Because pci_do_resource_release_and_resize() only holds a read lock on pci_bus_sem, a concurrent bus rescan can insert a child into a newly assigned bridge window before that fallback loop runs: CPU0 CPU1 pci_do_resource_release_and_resize() down_read(&pci_bus_sem) ... __assign_resources_sorted() assign_requested_resources_sorted() /* assigns bridge window res, * another resource fails */ pci_rescan_bus() pci_assign_unassigned_bus_resources= () down_read(&pci_bus_sem) ... allocate_resource() /* inserts child under res */ pci_release_resource(...) <-- -EBUSY, ignored pci_dev_res_restore(dev_res) <-- WARN_ON_ONCE(resource_assigned(res)) assign_requested_resources_sorted() pci_assign_resource(...) <-- sets IORESOURCE_UNSET on live res When release fails, res stays in the resource tree and hits WARN_ON_ONCE(resource_assigned(res)) in pci_dev_res_restore(). The retry then calls pci_assign_resource(), which sets IORESOURCE_UNSET before reallocate_resource() fails with -EBUSY, leaving the live window marked IORESOURCE_UNSET. If a firmware address is available, pci_revert_fw_address() can also mutate res->start and res->end without resource_lock while res is still linked in the tree. Removing dev_res from head, save_head, and realloc_head when pci_release_resource() fails would avoid this. > + if (ret) { > + pci_info(dev, "%s %pR: can't release; contains resources in use\n", > + res_name, res); > return ret; > + } [Severity: Low] Should this distinguish -EINVAL from -EBUSY? res->parent is checked without resource_lock, so if res is detached before release_leaf_resource() acquires the lock, __release_resource() returns -EINVAL instead of -EBUSY. pci_release_resource() then logs that res contains resources in use and returns -EINVAL rather than 0, causing pci_do_resource_release_and_resize() to drop it from saved and abort the resize if it is the resized BAR. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261205003957.3304= -1-ilpo.jarvinen@linux.intel.com?part=3D9