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 5E538606A322 for ; Sat, 5 Dec 2026 01:29:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=Vk5jvQiE Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E8D9A10E250; Sat, 5 Dec 2026 01:29:15 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) by gabe.freedesktop.org (Postfix) with ESMTPS id A4A8510E116; Sat, 5 Dec 2026 01:29:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796434150; x=1827970150; h=from:date:to:cc:subject:in-reply-to:message-id: references:mime-version; bh=tiQe5XkepN0r1kZlo2cv72tYjTIGQhdLN7O/QGzJeDs=; b=Vk5jvQiEmgUChFrKV2ZfszcLgM9UDdxRIi/OQB2nL8+9dAcZjPZNaSUl Cprv3m7auzfFSERoRz8K5mACOkmgIHQlSe0jkC6nSKpMv7y+0lxGx9Ju8 TPrMRNLPJP23/VHCp0AyJqJ5RkyclQ2QcDLnQ1XCPeC+m/8i5iGBbZSqm qe1LCrFIsMmzBVEHmIylMfoF5wrEm7ppxUJ59BsglO+XJshfC98b+5ADd 5iueYPi+jQAbXl9kleFzHpaTLfoIXo4OWYjHujaj5raMgTTauk1goCS4Y cA0dczLTsuAtBdjCuTwHIpMIfc1NyIXdkFB+Q8B8SOYsFxGXiD0v0phYJ w==; X-CSE-ConnectionGUID: 9vLcs0F9SVGletFoXSte+g== X-CSE-MsgGUID: PEh1UdeQRiaghVgUTImGRw== X-IronPort-AV: E=McAfee;i="6800,10657,11986"; a="5330577" X-IronPort-AV: E=Sophos;i="6.29,79,1794902400"; d="scan'208";a="5330577" Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2026 17:29:10 -0800 X-CSE-ConnectionGUID: K3Olu85JQB6toTuscyfvsA== X-CSE-MsgGUID: QItGEBpFSnqbz+BNzyqdXw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.29,79,1794902400"; d="scan'208";a="14469493" Received: from ijarvine-mobl1.ger.corp.intel.com (HELO localhost) ([10.245.245.47]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2026 17:29:07 -0800 From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Date: Sat, 5 Dec 2026 03:29:03 +0200 (EET) To: sashiko-reviews@lists.linux.dev cc: 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 Subject: Re: [PATCH v2 09/16] PCI: Do not release resources with children in pci_release_resource() In-Reply-To: Message-ID: <9ee27603-b691-ad50-c69b-04018e09970d@linux.intel.com> References: <20261205003957.3304-1-ilpo.jarvinen@linux.intel.com> <20261205003957.3304-10-ilpo.jarvinen@linux.intel.com> X-Archived-By: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="8323328-1730058943-1796434143=:1171" X-BeenThere: intel-xe@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Xe graphics driver List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Intel-xe" X-Spam-Status: No, score=-14.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,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 This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --8323328-1730058943-1796434143=:1171 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: QUOTED-PRINTABLE On Sat, 5 Dec 2026, sashiko-bot@kernel.org wrote: > 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 > -- >=20 > commit ed0359ff94feed20c50628f709669e28b10a5020 > Author: Ilpo J=C3=A4rvinen >=20 > > 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, an= d > > 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 >=20 > [Severity: Low] > This looks like a bug fix for pci_release_resource() detaching resources > that still have children. Should this include: >=20 > Fixes: 8bb705e3e79d ("PCI: Add pci_resize_resource() for resizing BARs"= ) >=20 > [ ... ] >=20 > > 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= resno) > > =09if (!res->parent) > > =09=09return 0; > > =20 > > -=09pci_info(dev, "%s %pR: releasing\n", res_name, res); > > - > > -=09ret =3D release_resource(res); > > -=09if (ret) > > +=09ret =3D release_leaf_resource(res); >=20 > [Severity: Medium] > Now that pci_release_resource() can return -EBUSY, does > __assign_resources_sorted() need to handle a release failure too? >=20 > Its fallback path ignores the return value and leaves dev_res on head, > save_head, and realloc_head: >=20 > drivers/pci/setup-bus.c:__assign_resources_sorted() { > =09... > =09/* Release assigned resource */ > =09list_for_each_entry(dev_res, head, list) { > =09=09res =3D dev_res->res; > =09=09dev =3D dev_res->dev; >=20 > =09=09pci_release_resource(dev, pci_resource_num(dev, res)); > =09=09pci_dev_res_restore(dev_res); > =09} > =09... > } >=20 > 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: >=20 > 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_resourc= es() > 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 >=20 > 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. >=20 > If a firmware address is available, pci_revert_fw_address() can also muta= te > res->start and res->end without resource_lock while res is still linked i= n > the tree. Removing dev_res from head, save_head, and realloc_head when > pci_release_resource() fails would avoid this. >=20 > > +=09if (ret) { > > +=09=09pci_info(dev, "%s %pR: can't release; contains resources in use\= n", > > +=09=09=09 res_name, res); > > =09=09return ret; > > +=09} >=20 > [Severity: Low] > Should this distinguish -EINVAL from -EBUSY? >=20 > res->parent is checked without resource_lock, so if res is detached befor= e > 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. Neither of the problems is in the scope for this series, see the cover=20 letter for details (which sashiko clearly failed to do :-( ). --=20 i. --8323328-1730058943-1796434143=:1171--