{"id":2233105,"url":"http://patchwork.ozlabs.org/api/1.2/patches/2233105/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-pci/patch/20260505170010.3414074-3-marcin.bernatowicz@linux.intel.com/","project":{"id":28,"url":"http://patchwork.ozlabs.org/api/1.2/projects/28/?format=json","name":"Linux PCI development","link_name":"linux-pci","list_id":"linux-pci.vger.kernel.org","list_email":"linux-pci@vger.kernel.org","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20260505170010.3414074-3-marcin.bernatowicz@linux.intel.com>","list_archive_url":null,"date":"2026-05-05T17:00:09","name":"[2/3] PCI/IOV: Restore initial VF ReBAR sizes on SR-IOV disable/failure","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"9274c450c067bfe576441eb61e6f2df20e81cb47","submitter":{"id":93334,"url":"http://patchwork.ozlabs.org/api/1.2/people/93334/?format=json","name":"Marcin Bernatowicz","email":"marcin.bernatowicz@linux.intel.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/linux-pci/patch/20260505170010.3414074-3-marcin.bernatowicz@linux.intel.com/mbox/","series":[{"id":502868,"url":"http://patchwork.ozlabs.org/api/1.2/series/502868/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-pci/list/?series=502868","date":"2026-05-05T17:00:08","name":"PCI/IOV: Restore initial VF BAR sizing after VF ReBAR","version":1,"mbox":"http://patchwork.ozlabs.org/series/502868/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2233105/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2233105/checks/","tags":{},"related":[],"headers":{"Return-Path":"\n <linux-pci+bounces-53760-incoming=patchwork.ozlabs.org@vger.kernel.org>","X-Original-To":["incoming@patchwork.ozlabs.org","linux-pci@vger.kernel.org"],"Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256\n header.s=Intel header.b=Y/VseuhH;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=172.105.105.114; helo=tor.lore.kernel.org;\n envelope-from=linux-pci+bounces-53760-incoming=patchwork.ozlabs.org@vger.kernel.org;\n receiver=patchwork.ozlabs.org)","smtp.subspace.kernel.org;\n\tdkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com\n header.b=\"Y/VseuhH\"","smtp.subspace.kernel.org;\n arc=none smtp.client-ip=192.198.163.19","smtp.subspace.kernel.org;\n dmarc=pass (p=none dis=none) header.from=linux.intel.com","smtp.subspace.kernel.org;\n spf=pass smtp.mailfrom=linux.intel.com"],"Received":["from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g94Zk5NPZz1yJ0\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 06 May 2026 03:02:54 +1000 (AEST)","from smtp.subspace.kernel.org (conduit.subspace.kernel.org\n [100.90.174.1])\n\tby tor.lore.kernel.org (Postfix) with ESMTP id 4229C3067B0D\n\tfor <incoming@patchwork.ozlabs.org>; Tue,  5 May 2026 17:00:44 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id 3A6BE49252C;\n\tTue,  5 May 2026 17:00:42 +0000 (UTC)","from mgamail.intel.com (mgamail.intel.com [192.198.163.19])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby smtp.subspace.kernel.org (Postfix) with ESMTPS id B31A63DE441;\n\tTue,  5 May 2026 17:00:40 +0000 (UTC)","from fmviesa002.fm.intel.com ([10.60.135.142])\n  by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;\n 05 May 2026 10:00:40 -0700","from soc-5cg43972f8.clients.intel.com (HELO localhost)\n ([172.28.182.189])\n  by fmviesa002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;\n 05 May 2026 10:00:37 -0700"],"ARC-Seal":"i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1778000442; cv=none;\n b=q5ML1bYmxNvPVPMk2Z4bSRC/9PWtdFhgtpNuybuMmqJoH0tcUG+3VJLQ7Nc/72tZYU3lB8nT8hAumVLx4W46W7MtHGwoUVeLcGwr+xSNirwPVvdZv4+xb8gmqB01vN96q39FcKdpn3iDO46ejzuLxfMw48Ktuqn99SvER83jYjw=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1778000442; c=relaxed/simple;\n\tbh=yEy2Ni19fXAThxGH9F+EJAuKJTAgVsdxGGryKTOpxZc=;\n\th=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:\n\t MIME-Version;\n b=J6PnJHhRtOThg/tQUTHfTKeU3JpdU7/6mtMBc1HMWdbHS2i/CmvxdSN6sXPeNwtdxGmLw/BK0zJcAd7MRD6B6S84SPVRRYPsZN/BPxvVYMeSxyrW6QdtttRz/RyoNhEYFfWXaP7Uvh39HoeWvOgx2+N5AA0a8Ku1W5HMzMNKmaM=","ARC-Authentication-Results":"i=1; smtp.subspace.kernel.org;\n dmarc=pass (p=none dis=none) header.from=linux.intel.com;\n spf=pass smtp.mailfrom=linux.intel.com;\n dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com\n header.b=Y/VseuhH; arc=none smtp.client-ip=192.198.163.19","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple;\n  d=intel.com; i=@intel.com; q=dns/txt; s=Intel;\n  t=1778000441; x=1809536441;\n  h=from:to:cc:subject:date:message-id:in-reply-to:\n   references:mime-version:content-transfer-encoding;\n  bh=yEy2Ni19fXAThxGH9F+EJAuKJTAgVsdxGGryKTOpxZc=;\n  b=Y/VseuhHhEkLZBjbixcLRqTQat1JdkSO6YhEKml8X9BFNhkc9EYZPyqj\n   DOTJu4LjQ3l6ABNbAW0bez0jaiuTmg3lii3NJpsb1JmQsHdrh1iRfjL7D\n   IYTl1DYRD8Xeqb4YMPpTBJKiib5bvJnRTbcqbfKD/f903C1DXq/iFBlHF\n   cCIjMu8E9FwS2xcRPcpNnl9r4OF5HqijX966lRHReXlzeCH9TmE+ys7Pe\n   DTo/SqXUnUM/55cgLj8BkDIPfRKCRID6Km8z08SSN6bu1KYW+VGqQZv3I\n   ZthXE6OfxzaMC3DT4ZPpFMO7D3mnqzYaZlsUF2mI4ck45uGvvkmIRm/kf\n   g==;","X-CSE-ConnectionGUID":["DMsnFlNgTyWAOabqQc5eIg==","UKPVYKjcTr61A44PIk3MYg=="],"X-CSE-MsgGUID":["Ilu6K8tMTvO+83uhdVHltg==","41p1iy0vSHO5/xEQShGXTw=="],"X-IronPort-AV":["E=McAfee;i=\"6800,10657,11777\"; a=\"77900541\"","E=Sophos;i=\"6.23,217,1770624000\";\n   d=\"scan'208\";a=\"77900541\"","E=Sophos;i=\"6.23,217,1770624000\";\n   d=\"scan'208\";a=\"259211464\""],"X-ExtLoop1":"1","From":"Marcin Bernatowicz <marcin.bernatowicz@linux.intel.com>","To":"Bjorn Helgaas <bhelgaas@google.com>,\n\tlinux-pci@vger.kernel.org,\n\tlinux-kernel@vger.kernel.org","Cc":"Michal Wajdeczko <michal.wajdeczko@intel.com>, =?utf-8?q?Micha=C5=82_Win?=\n\t=?utf-8?q?iarski?= <michal.winiarski@intel.com>, =?utf-8?q?Ilpo_J=C3=A4rvin?=\n\t=?utf-8?q?en?= <ilpo.jarvinen@linux.intel.com>, =?utf-8?q?Krzysztof_Wilczy?=\n\t=?utf-8?q?=C5=84ski?= <kwilczynski@kernel.org>, =?utf-8?q?Thomas_Hellstr?=\n\t=?utf-8?q?=C3=B6m?= <thomas.hellstrom@linux.intel.com>,\n Rodrigo Vivi <rodrigo.vivi@intel.com>, intel-xe@lists.freedesktop.org,\n Marcin Bernatowicz <marcin.bernatowicz@linux.intel.com>","Subject":"[PATCH 2/3] PCI/IOV: Restore initial VF ReBAR sizes on SR-IOV\n 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-pci@vger.kernel.org","List-Id":"<linux-pci.vger.kernel.org>","List-Subscribe":"<mailto:linux-pci+subscribe@vger.kernel.org>","List-Unsubscribe":"<mailto:linux-pci+unsubscribe@vger.kernel.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit"},"content":"PF drivers can resize a VF BAR via pci_iov_vf_bar_set_size(). The new\nsize persists in config space. A subsequent reprobe/unplug-rescan may\nthen cause the PCI core to reserve MMIO based on the inflated VF BAR\nregisters in the SR-IOV capability, often multiplied by TotalVFs.\nOn platforms with tight apertures, later SR-IOV enable can fail due to\nlack of space.\n\nRestore the initial VF BAR sizes saved at SR-IOV init time when SR-IOV\nis disabled and when SR-IOV enable fails. Restore is only performed\nwhen VF Memory Space is disabled, which is the precondition of\npci_iov_vf_bar_set_size() and is true at all the new call sites.\n\nNote: this changes user-visible behavior for drivers that rely on the\nresized VF BAR persisting across an enable/disable cycle. After this\nchange drivers must call pci_iov_vf_bar_set_size() before each\npci_enable_sriov() if a non-default size is desired.\n\nCloses: https://gitlab.freedesktop.org/drm/xe/kernel/-/issues/5937\nSigned-off-by: Marcin Bernatowicz <marcin.bernatowicz@linux.intel.com>\n---\n drivers/pci/iov.c | 61 +++++++++++++++++++++++++++++++++++++++++------\n 1 file changed, 54 insertions(+), 7 deletions(-)","diff":"diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c\nindex 19f4dca4eec1..42b935265b3c 100644\n--- a/drivers/pci/iov.c\n+++ b/drivers/pci/iov.c\n@@ -646,6 +646,40 @@ static int sriov_add_vfs(struct pci_dev *dev, u16 num_vfs)\n \treturn rc;\n }\n \n+static void sriov_restore_vf_rebar_initial_sizes(struct pci_dev *dev)\n+{\n+\tstruct pci_sriov *iov = dev->sriov;\n+\tint i;\n+\n+\tif (!iov || !iov->vf_rebar_cap)\n+\t\treturn;\n+\n+\tfor (i = 0; i < PCI_SRIOV_NUM_BARS; i++) {\n+\t\tint resno = pci_resource_num_from_vf_bar(i);\n+\t\tresource_size_t orig_sz = iov->barsz_orig[i];\n+\t\tresource_size_t cur_sz = iov->barsz[i];\n+\t\tint size, cur, rc;\n+\n+\t\tif (!orig_sz || cur_sz == orig_sz)\n+\t\t\tcontinue;\n+\n+\t\tsize = pci_rebar_bytes_to_size(orig_sz);\n+\t\trc = pci_iov_vf_bar_set_size(dev, resno, size);\n+\t\tif (!rc)\n+\t\t\tcontinue;\n+\n+\t\tpci_warn(dev, \"failed to restore %s size %#llx -> %#llx: %d\\n\",\n+\t\t\t pci_resource_name(dev, resno),\n+\t\t\t (unsigned long long)cur_sz,\n+\t\t\t (unsigned long long)orig_sz, rc);\n+\n+\t\t/* Re-sync in-memory size with what hardware actually has. */\n+\t\tcur = pci_rebar_get_current_size(dev, resno);\n+\t\tif (cur >= 0)\n+\t\t\tiov->barsz[i] = pci_rebar_size_to_bytes(cur);\n+\t}\n+}\n+\n static int sriov_enable(struct pci_dev *dev, int nr_virtfn)\n {\n \tint rc;\n@@ -687,36 +721,42 @@ static int sriov_enable(struct pci_dev *dev, int nr_virtfn)\n \t}\n \tif (nres != iov->nres) {\n \t\tpci_err(dev, \"not enough MMIO resources for SR-IOV\\n\");\n-\t\treturn -ENOMEM;\n+\t\trc = -ENOMEM;\n+\t\tgoto err_restore;\n \t}\n \n \tbus = pci_iov_virtfn_bus(dev, nr_virtfn - 1);\n \tif (bus > dev->bus->busn_res.end) {\n \t\tpci_err(dev, \"can't enable %d VFs (bus %02x out of range of %pR)\\n\",\n \t\t\tnr_virtfn, bus, &dev->bus->busn_res);\n-\t\treturn -ENOMEM;\n+\t\trc = -ENOMEM;\n+\t\tgoto err_restore;\n \t}\n \n \tif (pci_enable_resources(dev, bars)) {\n \t\tpci_err(dev, \"SR-IOV: IOV BARS not allocated\\n\");\n-\t\treturn -ENOMEM;\n+\t\trc = -ENOMEM;\n+\t\tgoto err_restore;\n \t}\n \n \tif (iov->link != dev->devfn) {\n \t\tpdev = pci_get_slot(dev->bus, iov->link);\n-\t\tif (!pdev)\n-\t\t\treturn -ENODEV;\n+\t\tif (!pdev) {\n+\t\t\trc = -ENODEV;\n+\t\t\tgoto err_restore;\n+\t\t}\n \n \t\tif (!pdev->is_physfn) {\n \t\t\tpci_dev_put(pdev);\n-\t\t\treturn -ENOSYS;\n+\t\t\trc = -ENOSYS;\n+\t\t\tgoto err_restore;\n \t\t}\n \n \t\trc = sysfs_create_link(&dev->dev.kobj,\n \t\t\t\t\t&pdev->dev.kobj, \"dep_link\");\n \t\tpci_dev_put(pdev);\n \t\tif (rc)\n-\t\t\treturn rc;\n+\t\t\tgoto err_restore;\n \t}\n \n \tiov->initial_VFs = initial;\n@@ -758,6 +798,12 @@ static int sriov_enable(struct pci_dev *dev, int nr_virtfn)\n \t\tsysfs_remove_link(&dev->dev.kobj, \"dep_link\");\n \n \tpci_iov_set_numvfs(dev, 0);\n+\tsriov_restore_vf_rebar_initial_sizes(dev);\n+\treturn rc;\n+\n+err_restore:\n+\t/* pcibios_sriov_enable() was not called on these early-exit paths. */\n+\tsriov_restore_vf_rebar_initial_sizes(dev);\n \treturn rc;\n }\n \n@@ -791,6 +837,7 @@ static void sriov_disable(struct pci_dev *dev)\n \n \tiov->num_VFs = 0;\n \tpci_iov_set_numvfs(dev, 0);\n+\tsriov_restore_vf_rebar_initial_sizes(dev);\n }\n \n static int sriov_init(struct pci_dev *dev, int pos)\n","prefixes":["2/3"]}