From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=192.198.163.8 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796431331; b=JyHb9qykhLFILMhedkUrWdHGVjDNodRj2I7TA3PPCL5xRWXccgd16DE0v8nj/Oehlwo4 yXaElk7wjn4VtcOgE+JHNByUAqaO3R2DGpFeJqwpKUM91nkvNWeYyWFDGLwKqgFMQuZgB dnt1o0l+uy1ULQv5hqiV67PAqFswktt3vL8f+awW/X0NgwTzRnB4u0F5TndPMQlyz7JrT mevhvqkvezDFvNbMOvjBnryiotk4JH+tpLKQTJ+wVGMSSNb7BJsmRhK1bs7Jjt6zxt8bf mlpstv7MlkDAt0ODces5nREFbC+yF/8hvh82dJhJWBOT+FQN7m0JfG8T6b9U7lIoSAg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796431331; 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:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Type:Content-Transfer-Encoding; bh=AgTyWKyyP1oH8x4aSrM88lwflLTeqtzuDG+bYY05jFg=; b=hVqGI/hGJKqgFVTlElBax2SaD8XSKgBJieKkz/ngLTNa1zEaYrx2M1z4Gw4Uwn6Hqh+4 z/lGIJfx1zO99SksyBxM6YBjFukA4L9veN/VsfkD8oryE4Fagz62PaZd8/COppItQhsTf TJ64ZcgMJnBtJ7d714Fs+sgWZdfiTmB5L1cJg9C3EU470Hcy3uZzGFYH/edQ2oxbSP4/h M59KFyv928u1lK8AtMolOe2O8yqma24QJ0Hb0aJ/6SsiBHaacZ/zmIF8cpd4BEDyozlhJ GGGSPNwO33lsok/nMGogQlSe3M1KIQZezazH8gGHb7YZgtu7CQKRQzLreUAHkJ46ocg== 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=YjsGdl3G; arc=none smtp.remote-ip=192.198.163.8 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) (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 BD468606A32C; Sat, 5 Dec 2026 00:42:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org BD468606A32C 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=YjsGdl3G DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796431330; x=1827967330; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=AgTyWKyyP1oH8x4aSrM88lwflLTeqtzuDG+bYY05jFg=; b=YjsGdl3GF6kGGdpNUNp8nnUpiCEKAi1k4zvIhSUhm2M13dEevAjsCGO9 FdIOK6Jac3a7IjYOyKGLMJizWsaHlhA0LCUP5ASOOF1Il4iiAhkkUNe5z BerbKrui/lbpFUlnCc0/xrjl9IGHnQXlHfVOOnnWJlX6YgR8rbrhRATLU Cs3EY9TwlqoNv6OQ2DkMc1Qe9h6MGkUUBf/QtgEto1daK4lhfkS3Diiw4 VBcEPhQmyM/74X4xREpOMY0cZPdd460EQPQZQ+BQ1gkJ0pdKJHkbrmcuf PMK6SEx028OeOF0tqbXm2fjIr+vqM2rYnQuL0+XLR8bki9GS6yrk8c3Kt g==; X-CSE-ConnectionGUID: sPKJeIjHS5GnSHvjTO0Lrw== X-CSE-MsgGUID: fwUOMPVaSqmEx78jf4JKzg== X-IronPort-AV: E=McAfee;i="6800,10657,11986"; a="5308014" X-IronPort-AV: E=Sophos;i="6.29,79,1794902400"; d="scan'208";a="5308014" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2026 16:42:10 -0800 X-CSE-ConnectionGUID: uaGTojRJQiWLm3rMrVPofw== X-CSE-MsgGUID: Ty4kNOgSRQm5GsvdOvyJoA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.29,79,1794902400"; d="scan'208";a="14412148" 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 16:42:02 -0800 From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= To: Bjorn Helgaas , Lorenzo Pieralisi , Rob Herring , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Alex Deucher , =?UTF-8?q?Christian=20K=C3=B6nig?= , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , Matthew Brost , =?UTF-8?q?Thomas=20Hellstr=C3=B6m?= , =?UTF-8?q?Micha=C5=82=20Winiarski?= , =?UTF-8?q?Ville=20Syrj=C3=A4l=C3=A4?= , David Airlie , Simona Vetter , dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, intel-xe@lists.freedesktop.org, Anthony Pighin , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Cc: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Subject: [PATCH v2 09/16] PCI: Do not release resources with children in pci_release_resource() Date: Sat, 5 Dec 2026 02:39:44 +0200 Message-ID: <20261205003957.3304-10-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261205003957.3304-1-ilpo.jarvinen@linux.intel.com> References: <20261205003957.3304-1-ilpo.jarvinen@linux.intel.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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ärvinen --- drivers/pci/setup-bus.c | 10 ++++++++-- drivers/pci/setup-res.c | 12 ++++++++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index cf062a9ac9a9..033f5fab7cc0 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -2330,7 +2330,8 @@ static int pbus_reassign_bridge_resources(struct pci_bus *bus, struct resource * if (ret) return ret; - pci_release_resource(bridge, i); + if (pci_release_resource(bridge, i)) + pci_dev_res_remove_from_list(saved, res); } else { const char *res_name = pci_resource_name(bridge, i); @@ -2412,7 +2413,12 @@ int pci_do_resource_release_and_resize(struct pci_dev *pdev, int resno, int size goto restore; continue; } - pci_release_resource(pdev, i); + ret = pci_release_resource(pdev, i); + if (ret) { + pci_dev_res_remove_from_list(&saved, r); + if (i == resno) + goto restore; + } } ret = pci_rebar_set_size(pdev, resno, size); diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c index 376f09630a4a..1317d645a178 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) if (!res->parent) return 0; - pci_info(dev, "%s %pR: releasing\n", res_name, res); - - ret = release_resource(res); - if (ret) + ret = release_leaf_resource(res); + if (ret) { + pci_info(dev, "%s %pR: can't release; contains resources in use\n", + res_name, res); return ret; + } + + pci_info(dev, "%s %pR: released\n", res_name, res); + res->end = resource_size(res) - 1; res->start = 0; res->flags |= IORESOURCE_UNSET; -- 2.47.3