From nobody Fri Oct 2 09:17:15 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.13]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 18D7937F31F; Mon, 3 Aug 2026 10:30:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785753022; cv=none; b=m4n57zE0uSdy8OmySSpolnt2RVeOy/D0w1ReZTSHPlV1XsQenFe+1j3cS9L8l988We291dVvXQQ6W/mHO/hOGhN/VYynRPFqp7Zo5+8gNa2vd7wuU1czRUWBnSlqT2FaptCQW/zDc/TDtvWIGXGebXmsAVtRNgqRx17Mb4D+BqU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785753022; c=relaxed/simple; bh=1vA3DmCTulej1f3WdCaQL3Cc5X4LwIxOBQssRhrlQtE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Xy7aTBec+9cbmoEZ2F04uaaq/UHDMebbPK8riAiqH+VpDYJEacB12V2LpXk5ZY4pxqlqm31iCTp5JMLlH7V/wxyMuyGEZjw8K6oTxIWls9Wq6oE2qqYGTmovrzmDSSm4M7+ammrczn4gsYPUX65sYzh4eSiqdOq1jS1u1gL5j5s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=UAjtenvN; arc=none smtp.client-ip=198.175.65.13 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.b="UAjtenvN" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1785753020; x=1817289020; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1vA3DmCTulej1f3WdCaQL3Cc5X4LwIxOBQssRhrlQtE=; b=UAjtenvNKlbFUJz7jiN1118SN1VTYKvLzmH6Z0nACOenfLKb0QWnYTd8 SQgY71AJhEHPEQXdmuXsIY3+R9Np7i0UEZy4oQ+AUbLPSLO6qaG1hS+BF 6OscF8WPA+c4vcXU5n1/YchnpSxM5ARGrHINZy0g/Z2KXCOamcUizQJHa pk1YK7SvDUcrgJ9npJspQnDlghMYr8rprXAEql/mJvUMeLyJSxohJGa3b z2I3Ul12S69OdV3/hqnGtcXqVYRUsek6+zifDkmenUIvUNKka61AVEjju m2PQ0VJBj84GXeWwmuSE1aPH3wnbo5g6/cR0r79Ts8eN2f+WrixiscPoN A==; X-CSE-ConnectionGUID: COrkf6Z6SXO9uz641FaaxQ== X-CSE-MsgGUID: JPrEa10WROm+A5L1L/T73Q== X-IronPort-AV: E=McAfee;i="6800,10657,11863"; a="97446125" X-IronPort-AV: E=Sophos;i="6.25,202,1779174000"; d="scan'208";a="97446125" Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Aug 2026 03:30:20 -0700 X-CSE-ConnectionGUID: kR4aR33JScG3FweUgJcKQg== X-CSE-MsgGUID: CskpuwlOQAqY0UnB0j7luA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.25,202,1779174000"; d="scan'208";a="284566513" Received: from soc-5cg43972f8.clients.intel.com (HELO localhost) ([172.28.182.68]) by fmviesa002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Aug 2026 03:30:17 -0700 From: Marcin Bernatowicz To: Bjorn Helgaas , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Michal Wajdeczko , =?UTF-8?q?Micha=C5=82=20Winiarski?= , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , =?UTF-8?q?Thomas=20Hellstr=C3=B6m?= , Rodrigo Vivi , intel-xe@lists.freedesktop.org Subject: [PATCH v2 1/3] PCI/IOV: Remember initial VF BAR sizes Date: Mon, 3 Aug 2026 12:30:05 +0200 Message-ID: <20260803103007.209625-2-marcin.bernatowicz@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260803103007.209625-1-marcin.bernatowicz@linux.intel.com> References: <20260505170010.3414074-1-marcin.bernatowicz@linux.intel.com> <20260803103007.209625-1-marcin.bernatowicz@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" SR-IOV initialization records the per-VF BAR sizes derived from the VF BAR registers in the SR-IOV capability. PF drivers may later change VF BAR sizes using VF Resizable BAR support (pci_iov_vf_bar_set_size()). Save the initial per-VF BAR sizes so later code can restore them when SR-IOV is disabled, when SR-IOV enable fails, or when the PF driver is unbound while VF BARs are still resized. The initial size is captured before the resource is multiplied by TotalVFs, so it represents one VF's BAR size as advertised by hardware. No functional change on its own. Signed-off-by: Marcin Bernatowicz --- drivers/pci/iov.c | 1 + drivers/pci/pci.h | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c index b0d24839c084..ae9309fc6dd7 100644 --- a/drivers/pci/iov.c +++ b/drivers/pci/iov.c @@ -869,6 +869,7 @@ static int sriov_init(struct pci_dev *dev, int pos) goto failed; } iov->barsz[i] =3D resource_size(res); + iov->barsz_orig[i] =3D iov->barsz[i]; resource_set_size(res, resource_size(res) * total); pci_info(dev, "%s %pR: contains BAR %d for %d VFs\n", res_name, res, i, total); diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 68b5fb675d1c..71c0d9fe5524 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -713,7 +713,8 @@ struct pci_sriov { u8 hdr_type; /* VF header type */ u16 subsystem_vendor; /* VF subsystem vendor */ u16 subsystem_device; /* VF subsystem device */ - resource_size_t barsz[PCI_SRIOV_NUM_BARS]; /* VF BAR size */ + resource_size_t barsz[PCI_SRIOV_NUM_BARS]; /* Current VF BAR size */ + resource_size_t barsz_orig[PCI_SRIOV_NUM_BARS]; /* Initial VF BAR size at= probe */ u16 vf_rebar_cap; /* VF Resizable BAR capability offset */ bool drivers_autoprobe; /* Auto probing of VFs by driver */ }; --=20 2.43.0 From nobody Fri Oct 2 09:17:15 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.13]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D2331386C0A; Mon, 3 Aug 2026 10:30:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785753026; cv=none; b=aULGzkQLYd90zwbSihz6uXQ71JHZWRBPsvCp7o81EclsuYvHh/33lFJaDUVWhjtEHZm55Ot/SnhbuKLEEE/9L69t9jslJWets+AuWqTguZt1ozHLw86em1CiLoap0CiE6SG3Bpc9jScbZP9EiNmxxcpfLV4pSaAOcEDfF532YSQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785753026; c=relaxed/simple; bh=ziAp1mnde7H3MaUN5dqlCIeSsUbwfTYMy5TP04p+19M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NcMl6HpV0MlZL7jXMxxayWI0HwbBshVZFwRg9wsSpSie/9v9gTxz/OCqUOPK/7be3nZd1ZhD2fgPsPAEhP8AQqKrSaNaAt4CmbhwFBVnby7I5vKgAS9ftpbsw48iq/Db0S8n+/bj062WuPRMQm1Mcmha2EnBzJxyUsw0oi/01k4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=bEApntbT; arc=none smtp.client-ip=198.175.65.13 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.b="bEApntbT" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1785753025; x=1817289025; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ziAp1mnde7H3MaUN5dqlCIeSsUbwfTYMy5TP04p+19M=; b=bEApntbTGFwRw31x4HjuWTFzRKde1kLWNPCLmEepdmU2t3WJr1Noyfr4 W3DvdWenavtQ4qDvJk2WN7peM2TAxViFn8RJSGhQwcAMkLXD0R23MPt2U duihdPOLULZpSALsFHlGUQ1AKtT3xEYc0aCVQl9HsxyKqPrxJjnuUKUc1 0KIR9kMLTPfLCFO4JOHhEjQNtgDkTJGt73zSD9hg8UtYzty9bWvXJ1SlU 0jl2I107b/2UmfUpbjA/fV6tZCcorKghwhocj0b8meDxA7xTUgzgKFnWF 9kco1WYTHsHxKK0kDWvj3MQ0Q7TB9uNhDM2pwuaFq46INMW2MZgXUmFd2 w==; X-CSE-ConnectionGUID: 4HFKpkhLQv+CQa06fMTpoQ== X-CSE-MsgGUID: rdugRCp4SRm98tyNOBUPjQ== X-IronPort-AV: E=McAfee;i="6800,10657,11863"; a="97446131" X-IronPort-AV: E=Sophos;i="6.25,202,1779174000"; d="scan'208";a="97446131" Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Aug 2026 03:30:25 -0700 X-CSE-ConnectionGUID: C2vhqzKSTn6uSiS+x2bXHg== X-CSE-MsgGUID: KPw2AzVvQ0GN3CztIof6xA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.25,202,1779174000"; d="scan'208";a="284566538" Received: from soc-5cg43972f8.clients.intel.com (HELO localhost) ([172.28.182.68]) by fmviesa002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Aug 2026 03:30:22 -0700 From: Marcin Bernatowicz To: Bjorn Helgaas , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Michal Wajdeczko , =?UTF-8?q?Micha=C5=82=20Winiarski?= , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , =?UTF-8?q?Thomas=20Hellstr=C3=B6m?= , Rodrigo Vivi , intel-xe@lists.freedesktop.org Subject: [PATCH v2 2/3] PCI/IOV: Restore initial VF ReBAR sizes on SR-IOV disable/failure Date: Mon, 3 Aug 2026 12:30:06 +0200 Message-ID: <20260803103007.209625-3-marcin.bernatowicz@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260803103007.209625-1-marcin.bernatowicz@linux.intel.com> References: <20260505170010.3414074-1-marcin.bernatowicz@linux.intel.com> <20260803103007.209625-1-marcin.bernatowicz@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" PF drivers can resize a VF BAR via pci_iov_vf_bar_set_size(). The new size persists in config space. A subsequent reprobe/unplug-rescan may then cause the PCI core to reserve MMIO based on the inflated VF BAR registers in the SR-IOV capability, often multiplied by TotalVFs. On platforms with tight apertures, later SR-IOV enable can fail due to lack of space. Restore the initial VF BAR sizes saved at SR-IOV init time when SR-IOV is disabled and when SR-IOV enable fails. This covers both the resource allocation failures later in sriov_enable() and the earlier validation failures that can otherwise leave a resized VF BAR in hardware while num_VFs remains zero. Restore is only performed when VF Memory Space is disabled, which is the precondition of pci_iov_vf_bar_set_size() and is true at all the new call sites. Note: this changes user-visible behavior for drivers that rely on the resized VF BAR persisting across an enable/disable cycle. After this change drivers must call pci_iov_vf_bar_set_size() before each pci_enable_sriov() if a non-default size is desired. Closes: https://gitlab.freedesktop.org/drm/xe/kernel/-/issues/5937 Signed-off-by: Marcin Bernatowicz --- drivers/pci/iov.c | 79 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 68 insertions(+), 11 deletions(-) diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c index ae9309fc6dd7..999938163ce9 100644 --- a/drivers/pci/iov.c +++ b/drivers/pci/iov.c @@ -646,6 +646,46 @@ static int sriov_add_vfs(struct pci_dev *dev, u16 num_= vfs) return rc; } =20 +static void sriov_restore_vf_rebar_initial_sizes(struct pci_dev *dev) +{ + struct pci_sriov *iov =3D dev->sriov; + u16 ctrl; + int i; + + if (!iov || !iov->vf_rebar_cap) + return; + + /* Skip if device is inaccessible (surprise-removed, D3cold). */ + pci_read_config_word(dev, iov->pos + PCI_SRIOV_CTRL, &ctrl); + if (PCI_POSSIBLE_ERROR(ctrl)) + return; + + for (i =3D 0; i < PCI_SRIOV_NUM_BARS; i++) { + int resno =3D pci_resource_num_from_vf_bar(i); + resource_size_t orig_sz =3D iov->barsz_orig[i]; + resource_size_t cur_sz =3D iov->barsz[i]; + int size, cur, rc; + + if (!orig_sz || cur_sz =3D=3D orig_sz) + continue; + + size =3D pci_rebar_bytes_to_size(orig_sz); + rc =3D pci_iov_vf_bar_set_size(dev, resno, size); + if (!rc) + continue; + + pci_warn(dev, "failed to restore %s size %#llx -> %#llx: %d\n", + pci_resource_name(dev, resno), + (unsigned long long)cur_sz, + (unsigned long long)orig_sz, rc); + + /* Re-sync in-memory size with what hardware actually has. */ + cur =3D pci_rebar_get_current_size(dev, resno); + if (cur >=3D 0) + iov->barsz[i] =3D pci_rebar_size_to_bytes(cur); + } +} + static int sriov_enable(struct pci_dev *dev, int nr_virtfn) { int rc; @@ -666,12 +706,16 @@ static int sriov_enable(struct pci_dev *dev, int nr_v= irtfn) =20 pci_read_config_word(dev, iov->pos + PCI_SRIOV_INITIAL_VF, &initial); if (initial > iov->total_VFs || - (!(iov->cap & PCI_SRIOV_CAP_VFM) && (initial !=3D iov->total_VFs))) - return -EIO; + (!(iov->cap & PCI_SRIOV_CAP_VFM) && (initial !=3D iov->total_VFs))) { + rc =3D -EIO; + goto err_restore; + } =20 if (nr_virtfn < 0 || nr_virtfn > iov->total_VFs || - (!(iov->cap & PCI_SRIOV_CAP_VFM) && (nr_virtfn > initial))) - return -EINVAL; + (!(iov->cap & PCI_SRIOV_CAP_VFM) && (nr_virtfn > initial))) { + rc =3D -EINVAL; + goto err_restore; + } =20 nres =3D 0; for (i =3D 0; i < PCI_SRIOV_NUM_BARS; i++) { @@ -687,36 +731,42 @@ static int sriov_enable(struct pci_dev *dev, int nr_v= irtfn) } if (nres !=3D iov->nres) { pci_err(dev, "not enough MMIO resources for SR-IOV\n"); - return -ENOMEM; + rc =3D -ENOMEM; + goto err_restore; } =20 bus =3D pci_iov_virtfn_bus(dev, nr_virtfn - 1); if (bus > dev->bus->busn_res.end) { pci_err(dev, "can't enable %d VFs (bus %02x out of range of %pR)\n", nr_virtfn, bus, &dev->bus->busn_res); - return -ENOMEM; + rc =3D -ENOMEM; + goto err_restore; } =20 if (pci_enable_resources(dev, bars)) { pci_err(dev, "SR-IOV: IOV BARS not allocated\n"); - return -ENOMEM; + rc =3D -ENOMEM; + goto err_restore; } =20 if (iov->link !=3D dev->devfn) { pdev =3D pci_get_slot(dev->bus, iov->link); - if (!pdev) - return -ENODEV; + if (!pdev) { + rc =3D -ENODEV; + goto err_restore; + } =20 if (!pdev->is_physfn) { pci_dev_put(pdev); - return -ENOSYS; + rc =3D -ENOSYS; + goto err_restore; } =20 rc =3D sysfs_create_link(&dev->dev.kobj, &pdev->dev.kobj, "dep_link"); pci_dev_put(pdev); if (rc) - return rc; + goto err_restore; } =20 iov->initial_VFs =3D initial; @@ -758,6 +808,12 @@ static int sriov_enable(struct pci_dev *dev, int nr_vi= rtfn) sysfs_remove_link(&dev->dev.kobj, "dep_link"); =20 pci_iov_set_numvfs(dev, 0); + sriov_restore_vf_rebar_initial_sizes(dev); + return rc; + +err_restore: + /* pcibios_sriov_enable() was not called on these early-exit paths. */ + sriov_restore_vf_rebar_initial_sizes(dev); return rc; } =20 @@ -791,6 +847,7 @@ static void sriov_disable(struct pci_dev *dev) =20 iov->num_VFs =3D 0; pci_iov_set_numvfs(dev, 0); + sriov_restore_vf_rebar_initial_sizes(dev); } =20 static int sriov_init(struct pci_dev *dev, int pos) --=20 2.43.0 From nobody Fri Oct 2 09:17:15 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B656937FF75; Mon, 3 Aug 2026 10:30:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785753034; cv=none; b=VgDjTYQZgSrAhc/wUWOJDUXoBfml/4t/GluFNhW2NUmQiUHyNOp0DSgatlxkDMS+OBqAu/LMsPh4VxYeaofhYFv3NQTT7lzfNt3SNBlVnmBONSfiJ8q/k9wAOoWwGO0u5xf0B5RfkrkWSRoacYVaB2x+xat/SU8GJuQLUs+B/HY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785753034; c=relaxed/simple; bh=Jc9ezVgCCeYzRms3oEKKtkNwbEmHiSp2OS+gnMOLnXA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cRa8ZiwJY9bGd3Krb+g+6kxEX6kvuvGcx19ALQGGEryEWJDzUlnFW4EfqGQxin7SDEIBWx/DYRZiGdAoep9N+e0PR90j+RhizaJIa4OsVyfwzyDogsf6CtyUEx9zJ2zuJXCSQZqlutH05FUGmqyXIJzkwycD51vNdE5oFQfhbBY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=SNmKYYw5; arc=none smtp.client-ip=198.175.65.9 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.b="SNmKYYw5" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1785753032; x=1817289032; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Jc9ezVgCCeYzRms3oEKKtkNwbEmHiSp2OS+gnMOLnXA=; b=SNmKYYw511vkz8NvAGdudKcUz1S6mAPs4ZzMmVBftlzvH6FEWo1yCJQv b4W2qpNYQ8wb2Q7CkIT1/mBECMrZdOXVY/PE7bBNPzlEvcAl6szPoJXvi YoRLdigv2TGT0++WelTYpx9DrHnUUKLbFeCkCjEAh5eiK40RpxMM5LTml pxinWUasIQDE4tDATl6RXPY7moberyO9yAkh9tDPBdgAOuLNtpyWQxeFY Dfp70+Yn/KsrJ4hR3WphTdfwvboig+UwTYS5iu4HYy0Hn6gFiDztLidjg 9MIfLViIgECHfT+PD0oqDqx1UPkvEnEKq2vEBwwuJRdzkfOfXfwbSJN62 w==; X-CSE-ConnectionGUID: yrhxkU0mRVikDeLkBE+NZQ== X-CSE-MsgGUID: C9PlT7LVQu2GBbw+XfRuUQ== X-IronPort-AV: E=McAfee;i="6800,10657,11863"; a="109080989" X-IronPort-AV: E=Sophos;i="6.25,202,1779174000"; d="scan'208";a="109080989" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Aug 2026 03:30:32 -0700 X-CSE-ConnectionGUID: FDbvWnJdTZar+Wh3N+v27w== X-CSE-MsgGUID: Q7t6uBkWQrG7T+EAG9uQNQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.25,202,1779174000"; d="scan'208";a="299410205" Received: from soc-5cg43972f8.clients.intel.com (HELO localhost) ([172.28.182.68]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Aug 2026 03:30:28 -0700 From: Marcin Bernatowicz To: Bjorn Helgaas , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Michal Wajdeczko , =?UTF-8?q?Micha=C5=82=20Winiarski?= , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , =?UTF-8?q?Thomas=20Hellstr=C3=B6m?= , Rodrigo Vivi , intel-xe@lists.freedesktop.org Subject: [PATCH v2 3/3] PCI/IOV: Restore initial VF ReBAR sizes on PF driver remove Date: Mon, 3 Aug 2026 12:30:07 +0200 Message-ID: <20260803103007.209625-4-marcin.bernatowicz@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260803103007.209625-1-marcin.bernatowicz@linux.intel.com> References: <20260505170010.3414074-1-marcin.bernatowicz@linux.intel.com> <20260803103007.209625-1-marcin.bernatowicz@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" sriov_disable() and sriov_enable() error paths restore the per-VF BAR sizes saved at probe time. They do not cover the case where the PF driver is detached while VF BARs were resized but SR-IOV was never enabled (or was already disabled). Restore the initial sizes from pci_iov_remove() as well. That hook runs on driver detach while the device is still live, unlike sriov_release() which runs later from the pci_dev release path. Skip the restore when the PF driver leaves SR-IOV enabled; in that case VF memory decoding is still active and pci_iov_vf_bar_set_size() cannot safely change the VF BAR size. Signed-off-by: Marcin Bernatowicz --- drivers/pci/iov.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c index 999938163ce9..3739825c84e9 100644 --- a/drivers/pci/iov.c +++ b/drivers/pci/iov.c @@ -1085,8 +1085,12 @@ void pci_iov_remove(struct pci_dev *dev) return; =20 iov->driver_max_VFs =3D iov->total_VFs; - if (iov->num_VFs) + if (iov->num_VFs) { pci_warn(dev, "driver left SR-IOV enabled after remove\n"); + return; + } + + sriov_restore_vf_rebar_initial_sizes(dev); } =20 /** --=20 2.43.0