From nobody Sat Jun 13 20:02:00 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.18]) (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 A6E764A2E08; Tue, 5 May 2026 17:00:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778000435; cv=none; b=r+v0DGSmQWrorqvaNso7n4wgAwt4wi0qRo+CAd5cbOS3ln42VkK8G+ypZlDpKw/rxoKmlC+qljwyNHKci5bP9PO4UuYpJUZ2jZVF8toj67vKypL2K3+w3XY0hd5DiLrTXfrAN6FKgpVW6PFJjahzKJeO+sFFgkOr2KqVD2N/ceg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778000435; c=relaxed/simple; bh=PloGYEOPDQl1zTi9kp545zgPmv+ZW+lkNa+P1IMTbzM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ig/JBpJYVG2NVSy4TOfdKA2L6xfrLvQ/Z9qZiOMl6C4UZg13xEdLWR9jNh0QCdBqhAJUdBj5pa3MdmubvzL+FxaoMrjlJKddClZ+xir/A0ZQr5WLQJ/sPavZ2vqUcFDZXDlR09Tg5Zu2P5YH7uyqWuyCPec31yyglQSUUULMQgk= 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=aL6XfDf+; arc=none smtp.client-ip=198.175.65.18 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="aL6XfDf+" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1778000434; x=1809536434; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=PloGYEOPDQl1zTi9kp545zgPmv+ZW+lkNa+P1IMTbzM=; b=aL6XfDf+CQ/bSOh8jDYh1nCIlAC07EuwCCKpJIcZYJErGwapnOfBoiXm 37ysPYGr6+y6Z4jBfDX3vVXXjE10zTxDYxn2H0kuy+Iwm8qdbOP3kGB8A 2s4HH0Pg7L3A6OTNQ8I9N2GxcEaSaLC/6iowtkKfeMy/GAVgg8fYQQ4C2 qCoBETbrlXZEIdqGQFslIvBz+kEBavTD566JUgAORuD8MahjoXtVsZhbs Ju94+R1c7TTMzN/cWJ5+6X95IwXZYbsMlUTybJ80ADSFDtTM2GFX9kHyA gu9phgzXK7qwtZluxq7priADQWAU22lArX/pQv0srVv+xYLRq0AkHmgzI g==; X-CSE-ConnectionGUID: edJ58YBdRtOq9bq0E4CnDA== X-CSE-MsgGUID: cCqI7nzXRra525huotx59w== X-IronPort-AV: E=McAfee;i="6800,10657,11777"; a="78902137" X-IronPort-AV: E=Sophos;i="6.23,217,1770624000"; d="scan'208";a="78902137" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 May 2026 10:00:33 -0700 X-CSE-ConnectionGUID: WFWcPKCjQhidUjPuJX89ag== X-CSE-MsgGUID: W2Y0jcunRO2J22Aqiw9x4w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,217,1770624000"; d="scan'208";a="259539792" Received: from soc-5cg43972f8.clients.intel.com (HELO localhost) ([172.28.182.189]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 May 2026 10:00:30 -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, Marcin Bernatowicz Subject: [PATCH 1/3] PCI/IOV: Remember initial VF BAR sizes Date: Tue, 5 May 2026 19:00:08 +0200 Message-ID: <20260505170010.3414074-2-marcin.bernatowicz@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260505170010.3414074-1-marcin.bernatowicz@linux.intel.com> References: <20260505170010.3414074-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 30ca4535fc36..19f4dca4eec1 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 19660d068fb7..441ef5b4ddc2 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -670,7 +670,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 Sat Jun 13 20:02:00 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.19]) (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 B31A63DE441; Tue, 5 May 2026 17:00:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778000442; cv=none; b=q5ML1bYmxNvPVPMk2Z4bSRC/9PWtdFhgtpNuybuMmqJoH0tcUG+3VJLQ7Nc/72tZYU3lB8nT8hAumVLx4W46W7MtHGwoUVeLcGwr+xSNirwPVvdZv4+xb8gmqB01vN96q39FcKdpn3iDO46ejzuLxfMw48Ktuqn99SvER83jYjw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778000442; c=relaxed/simple; bh=yEy2Ni19fXAThxGH9F+EJAuKJTAgVsdxGGryKTOpxZc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=J6PnJHhRtOThg/tQUTHfTKeU3JpdU7/6mtMBc1HMWdbHS2i/CmvxdSN6sXPeNwtdxGmLw/BK0zJcAd7MRD6B6S84SPVRRYPsZN/BPxvVYMeSxyrW6QdtttRz/RyoNhEYFfWXaP7Uvh39HoeWvOgx2+N5AA0a8Ku1W5HMzMNKmaM= 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=Y/VseuhH; arc=none smtp.client-ip=192.198.163.19 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="Y/VseuhH" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1778000441; x=1809536441; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yEy2Ni19fXAThxGH9F+EJAuKJTAgVsdxGGryKTOpxZc=; b=Y/VseuhHhEkLZBjbixcLRqTQat1JdkSO6YhEKml8X9BFNhkc9EYZPyqj DOTJu4LjQ3l6ABNbAW0bez0jaiuTmg3lii3NJpsb1JmQsHdrh1iRfjL7D IYTl1DYRD8Xeqb4YMPpTBJKiib5bvJnRTbcqbfKD/f903C1DXq/iFBlHF cCIjMu8E9FwS2xcRPcpNnl9r4OF5HqijX966lRHReXlzeCH9TmE+ys7Pe DTo/SqXUnUM/55cgLj8BkDIPfRKCRID6Km8z08SSN6bu1KYW+VGqQZv3I ZthXE6OfxzaMC3DT4ZPpFMO7D3mnqzYaZlsUF2mI4ck45uGvvkmIRm/kf g==; X-CSE-ConnectionGUID: DMsnFlNgTyWAOabqQc5eIg== X-CSE-MsgGUID: Ilu6K8tMTvO+83uhdVHltg== X-IronPort-AV: E=McAfee;i="6800,10657,11777"; a="77900541" X-IronPort-AV: E=Sophos;i="6.23,217,1770624000"; d="scan'208";a="77900541" Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 May 2026 10:00:40 -0700 X-CSE-ConnectionGUID: UKPVYKjcTr61A44PIk3MYg== X-CSE-MsgGUID: 41p1iy0vSHO5/xEQShGXTw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,217,1770624000"; d="scan'208";a="259211464" Received: from soc-5cg43972f8.clients.intel.com (HELO localhost) ([172.28.182.189]) by fmviesa002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 May 2026 10:00:37 -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, Marcin Bernatowicz Subject: [PATCH 2/3] PCI/IOV: Restore initial VF ReBAR sizes on SR-IOV disable/failure Date: Tue, 5 May 2026 19:00:09 +0200 Message-ID: <20260505170010.3414074-3-marcin.bernatowicz@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260505170010.3414074-1-marcin.bernatowicz@linux.intel.com> References: <20260505170010.3414074-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. 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 | 61 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 54 insertions(+), 7 deletions(-) diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c index 19f4dca4eec1..42b935265b3c 100644 --- a/drivers/pci/iov.c +++ b/drivers/pci/iov.c @@ -646,6 +646,40 @@ 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; + int i; + + if (!iov || !iov->vf_rebar_cap) + 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; @@ -687,36 +721,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 +798,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 +837,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 Sat Jun 13 20:02:00 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.19]) (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 2B542492195; Tue, 5 May 2026 17:00:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778000456; cv=none; b=hVpP6z21AGqvSUU8W+nta5jF9KyS/E/E3iCUt3PBXvtQjKrVBnH+ovR4WDS8EVB7oz8/RRYfGW9d9kcJudoaxZsl2yEPtysNqM5vPbagNRrBoZfndrOjzwcbFNqzaaDrQRiTs3/wB/ZJbeVg2XX8I0fLMGCJBFXZ1TG53P8U96Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778000456; c=relaxed/simple; bh=okVOvgMCxSHoJPtegYQ6LZ+tfsRvJYRXGSCdZrkPhto=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JGbGo0EFcc6se46MW/VZ+ZMg/Ua5KtzWEzZFVu0gnux+hsS/wRJNgmlPXxP7mNghXRN/tEAS7wXOYW0LgijdN6E1C6Fp/SptEpcgkhd8Oe4QDpgqtj/j11YuOlxtUg7iDZbDYjJdjZ+TO1yq0611uJuAT1m6R1pGDSXyxRlKRF0= 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=nfp46g39; arc=none smtp.client-ip=192.198.163.19 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="nfp46g39" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1778000455; x=1809536455; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=okVOvgMCxSHoJPtegYQ6LZ+tfsRvJYRXGSCdZrkPhto=; b=nfp46g39wlvJts0/9d55+3FKx+0sfwA2vzFP003hhbZcK67cq+uF+ywV tinWW4YGqgXGeXKZ3dy8/5R9IzXWqxvrZxUZ0KcVB/h1kBtxVATm9XJLv yncRtycviaIMHOK1kwL+YYCIuSIQ9GQqd6+yQ1BkMMbfVb+ZoIpkeTWeH 4MsEts+mTjC4LiN7ZxpWKvG0BRfafaUuulgzev43TMPRXjPZgyqbpjhbC VZlzLonsvoxNe0CfCl1DMh9E7Jp9xcqJcWqzF4KE2dPGisoEe209UdyUD zrNPHv6cGVktrajqvSaGdtvZjPiI9x5By37K3TAkvMxqBMFkGB/3/p3CD Q==; X-CSE-ConnectionGUID: NnZHVmqvRBWRK/540r5aFA== X-CSE-MsgGUID: I5xTxPOeQUy3Y8HnGdwhEw== X-IronPort-AV: E=McAfee;i="6800,10657,11777"; a="77900557" X-IronPort-AV: E=Sophos;i="6.23,217,1770624000"; d="scan'208";a="77900557" Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 May 2026 10:00:46 -0700 X-CSE-ConnectionGUID: dAGCgkHvS4OVuSEubfOTFQ== X-CSE-MsgGUID: 5sltCDfjT9O/rjMBlKNOzw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,217,1770624000"; d="scan'208";a="259211534" Received: from soc-5cg43972f8.clients.intel.com (HELO localhost) ([172.28.182.189]) by fmviesa002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 May 2026 10:00:43 -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, Marcin Bernatowicz Subject: [PATCH 3/3] PCI/IOV: Restore initial VF ReBAR sizes on PF release Date: Tue, 5 May 2026 19:00:10 +0200 Message-ID: <20260505170010.3414074-4-marcin.bernatowicz@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260505170010.3414074-1-marcin.bernatowicz@linux.intel.com> References: <20260505170010.3414074-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 unbound while VF BARs were resized but SR-IOV was never enabled (or was already disabled). On the next bind, sriov_init() re-reads the SR-IOV capability and captures the current (inflated) BAR registers as the new initial sizes in iov->barsz_orig[]. The restore logic becomes a no-op for that boot and the kernel may reserve MMIO for the inflated VF aperture multiplied by TotalVFs. Restore the initial sizes from sriov_release() as well. At this point num_VFs is 0 (BUG_ON enforces it) and VF Memory Space is therefore disabled, satisfying the precondition of pci_iov_vf_bar_set_size(). Signed-off-by: Marcin Bernatowicz --- drivers/pci/iov.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c index 42b935265b3c..d9e745e23add 100644 --- a/drivers/pci/iov.c +++ b/drivers/pci/iov.c @@ -969,6 +969,8 @@ static void sriov_release(struct pci_dev *dev) { BUG_ON(dev->sriov->num_VFs); =20 + sriov_restore_vf_rebar_initial_sizes(dev); + if (dev !=3D dev->sriov->dev) pci_dev_put(dev->sriov->dev); =20 --=20 2.43.0