From: "Michał Winiarski" <michal.winiarski@intel.com>
To: Bjorn Helgaas <bhelgaas@google.com>, <linux-pci@vger.kernel.org>,
<linux-kernel@vger.kernel.org>
Cc: intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
"Christian König" <christian.koenig@amd.com>,
"Krzysztof Wilczyński" <kw@linux.com>,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
"Rodrigo Vivi" <rodrigo.vivi@intel.com>,
"Michal Wajdeczko" <michal.wajdeczko@intel.com>,
"Lucas De Marchi" <lucas.demarchi@intel.com>,
"Thomas Hellström" <thomas.hellstrom@linux.intel.com>,
"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
"Maxime Ripard" <mripard@kernel.org>,
"Thomas Zimmermann" <tzimmermann@suse.de>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>,
"Matt Roper" <matthew.d.roper@intel.com>,
"Michał Winiarski" <michal.winiarski@intel.com>
Subject: [PATCH v10 4/5] PCI/IOV: Check that VF BAR fits within the reservation
Date: Wed, 2 Jul 2025 11:35:21 +0200 [thread overview]
Message-ID: <20250702093522.518099-5-michal.winiarski@intel.com> (raw)
In-Reply-To: <20250702093522.518099-1-michal.winiarski@intel.com>
When the resource representing VF MMIO BAR reservation is created, its
size is always large enough to accommodate the BAR of all SR-IOV Virtual
Functions that can potentially be created (total VFs). If for whatever
reason it's not possible to accommodate all VFs - the resource is not
assigned and no VFs can be created.
An upcoming change will allow VF BAR size to be modified by drivers at
a later point in time, which means that the check for resource
assignment is no longer sufficient.
Add an additional check that verifies that VF BAR for all enabled VFs
fits within the underlying reservation resource.
Signed-off-by: Michał Winiarski <michal.winiarski@intel.com>
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
drivers/pci/iov.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c
index 852424cf2ae15..f34173c70b32a 100644
--- a/drivers/pci/iov.c
+++ b/drivers/pci/iov.c
@@ -668,9 +668,12 @@ static int sriov_enable(struct pci_dev *dev, int nr_virtfn)
nres = 0;
for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) {
int idx = pci_resource_num_from_vf_bar(i);
+ resource_size_t vf_bar_sz = pci_iov_resource_size(dev, idx);
bars |= (1 << idx);
res = &dev->resource[idx];
+ if (vf_bar_sz * nr_virtfn > resource_size(res))
+ continue;
if (res->parent)
nres++;
}
--
2.49.0
next prev parent reply other threads:[~2025-07-02 9:36 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-02 9:35 [PATCH v10 0/5] PCI: VF resizable BAR Michał Winiarski
2025-07-02 9:35 ` [PATCH v10 1/5] PCI/IOV: Restore VF resizable BAR state after reset Michał Winiarski
2025-07-02 9:35 ` [PATCH v10 2/5] PCI: Add a helper to convert between VF BAR number and IOV resource Michał Winiarski
2025-07-02 9:35 ` [PATCH v10 3/5] PCI: Allow IOV resources to be resized in pci_resize_resource() Michał Winiarski
2025-07-02 9:35 ` Michał Winiarski [this message]
2025-07-02 9:35 ` [PATCH v10 5/5] PCI: Allow drivers to control VF BAR size Michał Winiarski
2025-07-14 9:39 ` [PATCH v10 0/5] PCI: VF resizable BAR Michał Winiarski
2025-07-14 20:05 ` Bjorn Helgaas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250702093522.518099-5-michal.winiarski@intel.com \
--to=michal.winiarski@intel.com \
--cc=airlied@gmail.com \
--cc=bhelgaas@google.com \
--cc=christian.koenig@amd.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=intel-xe@lists.freedesktop.org \
--cc=kw@linux.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=lucas.demarchi@intel.com \
--cc=maarten.lankhorst@linux.intel.com \
--cc=matthew.d.roper@intel.com \
--cc=michal.wajdeczko@intel.com \
--cc=mripard@kernel.org \
--cc=rodrigo.vivi@intel.com \
--cc=simona@ffwll.ch \
--cc=thomas.hellstrom@linux.intel.com \
--cc=tzimmermann@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®