From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=192.198.163.11 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796434151; b=TkSA//2g9wz1oUK7JdgqpCZiz3thoKWjWkco1j2EmJvEjJYPmabGdar4i4QKaUHo83Cx 6GQzZjJmkKziXB+MXcPz1dy4zKmRg69D8WVzkQ1uctVY2hLAEJgLyc6mSSiDHO1zPVSS1 OuMMiQ3azEbI7y1sR5rBEygErISFKqotEW0sJBjkOvbFBUS6V+W9rcTM/9GMwSORuVRYy hHy74D23bYXkpP17KHwQ6dfDUqxfichhLXTJjLQmyGBy28dX0UBPgOzN76MzGpXVDUTWI Nd6TpjknmSDnOwuFktOu2Uy070PZD+yD5ZKssrYhvGf4mIZFuEdBWubCQoaYm7XcAIg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796434151; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:From:Date:To:cc: Subject:In-Reply-To:Message-ID:References:MIME-Version:Content-Type; bh=tiQe5XkepN0r1kZlo2cv72tYjTIGQhdLN7O/QGzJeDs=; b=RQHaZy9Y3Vesn/St0nak/QoMax4ms7iaOtYMiC6baCy9IrB7E2aoCyuaHdGjjKvlKSj5 K6CMSjX0B2JrgxVPLRTsCUNFZoNg1KdQu/f58qk6JeMHgsTeQAlMeCQKNrbpJQouwqM5/ eEkWaPpDqy2NRm6sOf2FyNepRyAkaCWTV60nQtSBFEjCsTDB7OnwDSm/WYfgVbEUKvCzP mepmrzjen7yRkjV9KcWMOVjFUeS/OLkwVRn1LXgoy6VVmlXUucJPr8aJTP8M9ZGvxRCc6 CZYL3e0fjvgb21plKMAq9oqBLbIf6gR+zMIqQzlQ5ez0Pq7vhHT1Vn20Xb6DNkvNaBw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=l2ecws4x; arc=none smtp.remote-ip=192.198.163.11 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DBA85606A32C for ; Sat, 5 Dec 2026 01:29:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DBA85606A32C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com 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=l2ecws4x DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796434151; x=1827970151; h=from:date:to:cc:subject:in-reply-to:message-id: references:mime-version; bh=tiQe5XkepN0r1kZlo2cv72tYjTIGQhdLN7O/QGzJeDs=; b=l2ecws4xvIGtj/NYBq4ZRQx6GYcOTRA6QHXuQ7Dto6aHlkp0TGQkbCuI 9IApYebLgDnALX1y8I8OFnfsZ895ux4rd9pe9nbOyPU70oyCFn5E91vau UFvD/K288laLQiyPk45EwHc3vS0LobA0oPcE0iWx8wgv7tiOhtQzf3rlz cq7w3w2/sVkMzX3FX1GFYRD5z2D5iiuBqga7tHaRBW5Yqo9FKBtXWm1Rp K+vPa+ktjoVKiL/3F2LW8clGYiFTSj6F2glQ/xBeq/NMQS2i6Amhoothq Gx2XSawffAeBUnJd20AQSlm1XCAKW9pf8yJF6vKJJXiBx50HOhMnpN8ad w==; X-CSE-ConnectionGUID: ivOHHS6OSriTZdtzLkUjNQ== X-CSE-MsgGUID: jeEqEdiuRo+B+IsJr0rJnA== X-IronPort-AV: E=McAfee;i="6800,10657,11986"; a="5330575" X-IronPort-AV: E=Sophos;i="6.29,79,1794902400"; d="scan'208";a="5330575" 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-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="8323328-1730058943-1796434143=:1171" 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--