From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=198.175.65.15 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796431240; b=qqssgToTTzr0NcCtagmyxQuI5Atk3aUizKty+zrIdtCR0YEGY9Q5AkW7JPzUjBXNsILz 4ekrU70Uy1G3DVOyLIfliO9MFGJpTBUpmX+oTxZPNcyO8f+iW75FZDamiEY0hecRwODZX kib+a9R2PzxZ8dLyo7y1fkwIuvq/lm4vs2ame0Z1YzUFoUUJS7XkTkf1OVa0yQeCPmDSb 6X2eKWzS7g2mppPCVhfbyQ/yD/5k70HuhwZFfSsswMMa1Gi/qkBoMqYAxuKV3uaIERzCY r6KuSOy167f7WV2QZPC19ybx/oKTYwIv2ov9iV2+NcpNAmAzp8e/8Xysf7LNLexP0zg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796431240; 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=QQjM7mKJog6X1ICVAwKCQlf/IDDklPYQetGccKvqLUY=; b=g3PbxfmKvTqidp5SScyjkNYQO2FPi9c8LhH41ovFZU5MnFu8nxOnwGY6l9wH0ZikxQJO Uwg2/Ht/BcNkqe4aFH4uiyJJmbb2FrQISqQB4KrbKlOqiw9UmX98RjKwcMN84HX7Qzamf NJ9NCFZ69YJqm+yWYam4oTxxQFCbRQX/klip2alxDzO2GibN6X2OHKR1ylyDxdY6EFUnP pfg5Qy8vru9+FmDajHXlpD93svsmPjcJUyph9DwDlp4wNaJLYHUZswCs0c2AoRbbbpPDf NzcF6mh79kxKt+2dOGutl34unf8SSWHciX8tr1KYdbVufg8dfrWNL8dmGTg142gEUQw== 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=SoqP7Heb; arc=none smtp.remote-ip=198.175.65.15 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.15]) (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 60AC0606A322; Sat, 5 Dec 2026 00:40:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 60AC0606A322 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=SoqP7Heb DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796431240; x=1827967240; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=QQjM7mKJog6X1ICVAwKCQlf/IDDklPYQetGccKvqLUY=; b=SoqP7HebwuaDR/NVcTykdkyBLQiWEkV+4e+2fLqSmo1BuZtRXA9xGp6m G8Owwd1FbOPtUvwuoLO1HKWhQEFOXlij2P9Uphis618I2jiifime3iFrO nZ6/zot5bgsidhb/421/ljaZDlZqgoApovmXWWIm0b8jq/SMCmk825Y4w O4s8blHliNdokejs6hYERenTI1pmaTh1DXUrpr9kq7uWqmShkRZEt/ByI Ij3F1VuVLdoNRzjbyZtVPyLQStvlFhRadBWfWfu/bTsyaKHguOGpQaams yZHIrwYOi27fJbW3Wcukf1VpUuhnbV/512A/5hxv/84NqN7ty7pYlzJ6t g==; X-CSE-ConnectionGUID: 9j1DpOZYTAqg95/qEFtbjQ== X-CSE-MsgGUID: N31/WhsKSASYlvFZj0cyMQ== X-IronPort-AV: E=McAfee;i="6800,10657,11986"; a="5424536" X-IronPort-AV: E=Sophos;i="6.29,79,1794902400"; d="scan'208";a="5424536" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2026 16:40:40 -0800 X-CSE-ConnectionGUID: RTDs4D1RQM+wjeWM3Bpz5g== X-CSE-MsgGUID: zEDh3WmETbSiB3kDa7noIw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.29,79,1794902400"; d="scan'208";a="14196673" 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:40:32 -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 , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Cc: stable@vger.kernel.org Subject: [PATCH v2 02/16] PCI: Set new BAR Size only after releasing the BARs for BAR resize Date: Sat, 5 Dec 2026 02:39:37 +0200 Message-ID: <20261205003957.3304-3-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_do_resource_release_and_resize() sets the new BAR Size before it saves and releases the BARs that share the bridge window with the BAR being resized. The BAR Size decides which bits of the Base Address Register are read-only, so the address in the resized BAR may lose its low bits right away. Saving the BARs needs memory allocations, which can fail. If that happens before the resized BAR has been saved, the BAR resize rollback restores the old BAR Size but cannot restore the address of the resized BAR, which leaves the BAR and its resource out of sync. Nothing requires setting the new BAR Size that early. Set it only after all the BARs have been saved and released, right before the resource is resized. Fixes: 337b1b566db0 ("PCI: Fix restoring BARs on BAR resize rollback path") Signed-off-by: Ilpo Järvinen Cc: stable@vger.kernel.org --- drivers/pci/setup-bus.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index b69041fbbd39..db16c8c2913d 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -2394,10 +2394,6 @@ int pci_do_resource_release_and_resize(struct pci_dev *pdev, int resno, int size if (old < 0) return old; - ret = pci_rebar_set_size(pdev, resno, size); - if (ret) - return ret; - down_read(&pci_bus_sem); pci_dev_for_each_resource(pdev, r, i) { @@ -2416,12 +2412,16 @@ int pci_do_resource_release_and_resize(struct pci_dev *pdev, int resno, int size pci_release_resource(pdev, i); } + ret = pci_rebar_set_size(pdev, resno, size); + if (ret) + goto restore; + pci_resize_resource_set_size(pdev, resno, size); if (bridge) { ret = pbus_reassign_bridge_resources(bus, res, &saved); if (ret) - goto restore; + goto restore_size; } else { /* No bridge window to adjust; let the core reassign the bus. */ pci_bus_assign_resources(bus); @@ -2429,7 +2429,7 @@ int pci_do_resource_release_and_resize(struct pci_dev *pdev, int resno, int size list_for_each_entry(dev_res, &saved, list) { if (!resource_assigned(dev_res->res)) { ret = -ENOSPC; - goto restore; + goto restore_size; } } } @@ -2439,7 +2439,7 @@ int pci_do_resource_release_and_resize(struct pci_dev *pdev, int resno, int size pci_dev_res_free_list(&saved); return ret; -restore: +restore_size: /* * Revert to the old configuration. * @@ -2449,6 +2449,7 @@ int pci_do_resource_release_and_resize(struct pci_dev *pdev, int resno, int size */ pci_rebar_set_size(pdev, resno, old); +restore: /* * Release all resources first, otherwise a resource not yet released * could block restoring another resource into its original place. -- 2.47.3