From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=198.175.65.9 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796435828; b=Pr7sNBwkKwo9UvK2KiLMpLo+RlxJuTsXlX98DRvKUCRYuUzo+SzSfHKyJ1GL5XglWopb bN1WdKHnO3EDL50wQ53YnM0Ch2zs3bZ/bHopOZHYw9WWjLd8KZeS1me+ntIrZ0DwTmQRv vAIHM6LrkHF/jkknTO9NOGts95F+u0VWlMpvfyGUEeOsOoznPjPCY62lTRTXgCgaPscKq rDx0iJAGPFl38aFFM4f8761dJzvd3btBvYvfCQ188SL027TaVxDGFqWATeDvDqF3KAPio +Og/5qw2LkrB3T/bKi3lS9nCpkyKJ8DLR/+vOMTVUNQpCh98X/FEr3rDByBc+xryHIA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796435828; 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: Content-ID; bh=aGIl5JiOUtuz87nOOfkSodam4T+N1IeSuzAVGpwJd1k=; b=UDsdmQ/IallGyueTT7PFK1K4e359c8jn56MyIELAtYP2eou4SkwGdgh+WV3kAywDH9Dy aHvcZjLfizOQTvVw+WlA3KxnMiUK+SMDTpqWy+UrQIbaVg/VGu7bBb22HruIO5f9k56X9 SXmX30Gk6ydvsn5rKHu9Ye4XfwlII7UpHtDIUQkEUAzl+LiNThAzvq09yfbEljF6O0KT5 qwvmv3/amGIW/JDZwG5dl8kxeAWsqjQ9aNVnAsjL/o3Gnj3IQ2FA7sAOe4ZigHvI+1sNQ JtJ6/Gjqe+0nZCzz+qF2zeFtBkcqRaGNS7G0SnAhtsfx3FBtVSqd906VbqOLHfyYi8Q== 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=FB3WeZ4s; arc=none smtp.remote-ip=198.175.65.9 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) (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 3A465606A322 for ; Sat, 5 Dec 2026 01:57:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3A465606A322 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=FB3WeZ4s DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796435828; x=1827971828; h=from:date:to:cc:subject:in-reply-to:message-id: references:mime-version:content-id; bh=aGIl5JiOUtuz87nOOfkSodam4T+N1IeSuzAVGpwJd1k=; b=FB3WeZ4sL0XbH4yIoEU9hp4wpOTYBBFfSd6Gpc1UHclZMx7Ihnj6nVzd ruzDQXPyuyDLrY/aSRI65Hw2LkT85ZE+BeJ7s+x8j7K8wxaOC/5pdAjPv hLAruJKbVjRjpR0oQz83vC7GSytZykpmE0hr+QqKoNq0EyWSLgxgI8RDw swyyTzAOsDbgPtnL6DK+sdc4ONF3ncb5QRR/il0vKIZAuW/DZEMcoUYyq 5hhOpkIc9H23+vrTx11hoCRKGBD64AgcRffE/8UAylh9yTcJFXM5CXw3/ jYAf3EpAO+yF7opKQ4yR4R9Y+6RLXGkf13A+uJIXOqJHCqYp8Tk+V4QFY w==; X-CSE-ConnectionGUID: a8wJ3yREQUytE+vwFZOCdg== X-CSE-MsgGUID: UDv2kA90Qby5x9R7cYyK4A== X-IronPort-AV: E=McAfee;i="6800,10657,11986"; a="5339494" X-IronPort-AV: E=Sophos;i="6.29,79,1794902400"; d="scan'208";a="5339494" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2026 17:57:07 -0800 X-CSE-ConnectionGUID: HsHYaKKISCK4H8WVVwhk1Q== X-CSE-MsgGUID: fKAchI6xS6SV6WT8H2E6Uw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.29,79,1794902400"; d="scan'208";a="14259178" 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:57:05 -0800 From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Date: Sat, 5 Dec 2026 03:57:01 +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 16/16] PCI: Release only PCI resources when releasing a resource tree In-Reply-To: Message-ID: <8d67685c-8a46-646a-d681-29cbdff69969@linux.intel.com> References: <20261205003957.3304-1-ilpo.jarvinen@linux.intel.com> <20261205003957.3304-17-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-903816228-1796435583=:1171" Content-ID: <6915e3a1-d006-1b68-9382-d0f00c165477@linux.intel.com> 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-903816228-1796435583=:1171 Content-Type: text/plain; CHARSET=ISO-8859-15 Content-Transfer-Encoding: QUOTED-PRINTABLE Content-ID: On Sat, 5 Dec 2026, sashiko-bot@kernel.org wrote: > 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 > -- >=20 > commit b918bf89459fc478f5ebfe229a3a0bbeb92b6ca2 > Author: Ilpo J=E4rvinen >=20 > PCI: Release only PCI resources when releasing a resource tree >=20 > This commit adds pci_release_resource_tree() to check and release only PC= I > resources underneath a bridge window under resource_lock, and switches > pci_bridge_release_resources() and BAR resize rollback to use it. >=20 > Link: https://lore.kernel.org/linux-pci/20260727193714.598562-1-anthony.p= ighin@nokia.com/ >=20 > > 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 = pci_bus *bus, > > =20 > > =09idx =3D pci_resource_num(dev, b_win); > > =20 > > -=09/* If there are children, release them all */ > > -=09release_child_resources(b_win); > > - > > -=09ret =3D pci_release_resource(dev, idx); > > +=09ret =3D pci_release_resource_tree(dev, idx); > > =09if (ret) > > =09=09return; >=20 > [Severity: Low] > Should pci_bridge_release_resources() propagate the -EBUSY failure instea= d > of discarding ret? >=20 > When a descendant is pinned, pci_release_resource_tree() leaves b_win > assigned, so every ancestor bridge in pci_bus_release_bridge_resources(..= =2E, > whole_subtree) re-walks the same unreleased branch under resource_lock an= d > repeats the same pci_info() message. >=20 > 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. I'll change this. > [ ... ] >=20 > > @@ -2472,8 +2469,7 @@ int pci_do_resource_release_and_resize(struct pci= _dev *pdev, int resno, int size > > =09=09if (!resource_assigned(res)) > > =09=09=09continue; > > =20 > > -=09=09release_child_resources(res); > > -=09=09pci_release_resource(dev, i); > > +=09=09pci_release_resource_tree(dev, i); > > =09} > > =20 > > =09/* Restore parents before their children */ > > @@ -2483,6 +2479,10 @@ int pci_do_resource_release_and_resize(struct pc= i_dev *pdev, int resno, int size > > =20 > > =09=09i =3D pci_resource_num(dev, res); > > =20 > > +=09=09/* All saved resources were released once before the resize */ > > +=09=09if (WARN_ON_ONCE(resource_assigned(res))) > > +=09=09=09continue; > > + > > =09=09pci_dev_res_restore(dev_res); > > =20 > > =09=09if (pci_claim_resource(dev, i)) >=20 > [Severity: Medium] > Can BAR resize rollback fail here when an IORESOURCE_PCI_FIXED resource > shares the resized bridge window? >=20 > Before resizing, pci_do_resource_release_and_resize() releases pdev's BAR= s > 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-clai= ms > that fixed BAR (or claims a sibling's fixed resource inside a moved windo= w). >=20 > On rollback, pci_can_release_resource_tree() rejects fixed resources and > ancestor windows containing them, so pci_release_resource_tree() returns > -EBUSY.=20 Fix one case, the other starts to complain. I suppose I'll just add=20 override which skips the FIXED check in case of rollback. Generally, I'd want to make FIXED resources behave pretty normally when it= =20 comes to assign/release, but so that it imposes restriction on parent window address range. But that cannot be done sensibly until after this=20 and a handful of other series I've pending... Until then, they need to pin windows. --=20 i. > The restore loop then hits WARN_ON_ONCE(resource_assigned(res)) > and skips restoring the window, stranding other BARs if the window moved. >=20 > Also, releasing an IORESOURCE_PCI_FIXED BAR via pci_release_resource() be= fore > the resize can unpin its parent bridge window even on a successful resize= =2E >=20 > > 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= resno) >=20 > [ ... ] >=20 > > +=09if (bus) { > > +=09=09pci_bus_for_each_window_resource(bus, res, child, r) { > > +=09=09=09pci_children++; > > +=09=09=09if (!pci_can_release_resource_tree(child, r)) > > +=09=09=09=09return false; > > +=09=09} > > +=09} >=20 > [Severity: Medium] > Is it safe to walk bus->devices here and in __pci_release_resource_tree() > without holding pci_bus_sem? >=20 > 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 >=20 > 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). >=20 > pci_destroy_dev() unlinks dev->bus_list before acquiring resource_lock in > pci_free_resources(), so resource_lock does not prevent list corruption o= r > 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= =2E >=20 > [ ... ] >=20 > > +static void __pci_release_resource_tree(struct pci_dev *dev, > > +=09=09=09=09=09struct resource *res) > > +{ > > +=09int resno =3D pci_resource_num(dev, res); > > +=09struct pci_bus *bus =3D dev->subordinate; > > +=09struct pci_dev *child; > > +=09struct resource *r; > > + > > +=09lockdep_assert_held_write(&resource_lock); > > + > > +=09if (bus) { > > +=09=09pci_bus_for_each_window_resource(bus, res, child, r) > > +=09=09=09__pci_release_resource_tree(child, r); > > +=09} > > + > > +=09if (release_resource_locked(res)) { > > +=09=09const char *res_name =3D pci_resource_name(dev, resno); > > + > > +=09=09pci_dbg(dev, "%s %pR: can't release\n", res_name, res); > > +=09=09return; > > +=09} > > + > > +=09pci_resource_post_release(dev, resno); > > +} >=20 > [ ... ] >=20 > > +int pci_release_resource_tree(struct pci_dev *dev, int resno) > > +{ > > +=09struct resource *res =3D pci_resource_n(dev, resno); > > + > > +=09guard(write_lock)(&resource_lock); > > + > > +=09if (!resource_assigned(res)) > > +=09=09return 0; > > + > > +=09if (!pci_can_release_resource_tree(dev, res)) > > +=09=09return -EBUSY; > > + > > +=09__pci_release_resource_tree(dev, res); > > + > > +=09return 0; > > +} >=20 > [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 oth= er > CPUs on slow consoles? >=20 > At default console_loglevel, LOGLEVEL_INFO messages flush synchronously o= n > 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. >=20 > Previously, release_child_resources() only logged at KERN_DEBUG under > resource_lock and pci_release_resource() called pci_info() after dropping > it. >=20 > Also, unlike pci_can_release_resource_tree(), __pci_release_resource_tree= () > does not check res->child before entering pci_bus_for_each_window_resourc= e(), > scanning subordinate devices even when res has no children. >=20 >=20 --8323328-903816228-1796435583=:1171--