From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796432654; b=NlUtarFTLL5WJSoIRJc6E2N4jP+bNjaRy4bmcE/6iod2TYBDvHE5CWGVUS34qvVNl8LY 8xu1MGLC1seC06EGQrgGxZc+AowUifzLct9ohFle8GvZljZPpWnL4jKlfF8+AbL+t9K1k /cm8LcskJuV22srGfOcNr2gj8NgqMnsQepueVlvk6B0MKQQHA1EKpyAnvk2til6p4pRxw SBuRs9Gx4Cha8Jsr6xcna8PA3DKnbwYPzxhCgRg0ZFK6l/K6eR766jmNErPpubDnN6Omq cEQG1jvY5E6TkH6eNJY6EwbzA9pFGFtltv0aAbrObOHtlB+C4QW4bwc705FPQvnJZvA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796432654; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=NGPYu0e6vRAH8Bdea5wQxjoIn1u7mwhX9qhUQiZo4vo=; b=lm8VzJ6t+HsFLl20ps8cVIAbAraAUT8jbznBqXcGnMWfDWoWQ/d7FMvLJ1RCuRbE+bBx kUa2pGkIZUkPLQC54DiJrsy7aZh/gVjxdi9eDi7eBaNQ30tt1F9/V2qAsC3GhCmsHUbt6 8ln/PPtJ504im1fppdkz4q3Wci//Kk6whj5ojdsbOQmPeLmu1QeMZQTR+UexSwH37GWhS Ll98Tr501dLkOFMPkRBYqUgrSWbyz0FvDHGqhCPNfplD5WAVoxAuGZg3tcJZEy9wAIiTC nSiz5R6UxeWA7ffj6W3kSoJuiH/03WzL7Us5PJby0Ynm92XvWxJPcyXtTLcZgIZqPgg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=QL8zkBsF; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8F1B6606A332 for ; Sat, 5 Dec 2026 01:04:14 +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: 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() Reply-To: sashiko-reviews@lists.linux.dev 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-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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