* [PATCH v7 0/6] PCI: VF resizable BAR
@ 2025-04-02 14:11 Michał Winiarski
2025-04-02 14:11 ` [PATCH v7 1/6] PCI/IOV: Restore VF resizable BAR state after reset Michał Winiarski
` (5 more replies)
0 siblings, 6 replies; 12+ messages in thread
From: Michał Winiarski @ 2025-04-02 14:11 UTC (permalink / raw)
To: linux-pci, intel-xe, dri-devel, linux-kernel, Bjorn Helgaas,
Christian König, Krzysztof Wilczyński,
Ilpo Järvinen
Cc: Rodrigo Vivi, Michal Wajdeczko, Lucas De Marchi,
Thomas Hellström, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, Matt Roper,
Michał Winiarski
Hi,
Another revision after the feedback from Ilpo.
Few tweaks here and there, the biggest change is the removal of the
loop in pci_iov_vf_bar_get_sizes().
v6 can be found here:
https://lore.kernel.org/linux-pci/20250320110854.3866284-1-michal.winiarski@intel.com/
For regular BAR, drivers can use pci_resize_resource to resize it to the
desired size provided that it is supported by the hardware, which the
driver can query using pci_rebar_get_possible_sizes.
This series expands the API to work with IOV BAR as well.
It also adds the additional API for drivers to change the VF BAR size
without resizing the entire underlying reservation (within the original
resource boundary).
Thanks,
-Michał
v6 -> v7:
- Eliminate the loop in pci_iov_vf_bar_get_sizes() (Ilpo)
- Use helper variable for indexes (Ilpo)
- Kerneldoc formatting (Ilpo)
- Refer to latest PCI spec (Ilpo)
- Commit message wording (Ilpo)
v5 -> v6:
- Rebased on latest pci/next
- Cache the VF resizable BAR capability position to avoid multiple
lookups (Ilpo)
- Use pci_resource_n helper (Ilpo)
v4 -> v5:
- Rename pci_resource_to/from_iov helpers and add WARN if called without
CONFIG_PCI_IOV (Ilpo)
- Reword kerneldoc for pci_iov_vf_bar_get_sizes (Bjorn)
- Reword commit message for VF BAR size check, extract the additional
size check to separate conditional (Bjorn)
v3 -> v4:
- Change the approach to extending the BAR (Christian)
- Tidy the commit messages, use 80 line limit where necessary (Bjorn)
- Add kerneldocs to exported functions (Bjorn)
- Add pci_resource_to_iov() / pci_resource_from_iov() helpers (Ilpo)
- Use FIELD_GET(), tidy whitespace (Ilpo)
v2 -> v3:
- Extract introducing pci_resource_is_iov to separate commit and
use it elsewhere in PCI subsystem (Christian)
- Extract restoring VF rebar state to separate commit (Christian)
- Reorganize memory decoding check (Christian)
- Don't use dev_WARN (Ilpo)
- Fix build without CONFIG_PCI_IOV (CI)
v1 -> v2:
- Add pci_iov_resource_extend() and usage in Xe driver
- Reduce the number of ifdefs (Christian)
- Drop patch 2/2 from v1 (Christian)
- Add a helper to avoid upsetting static analysis tools (Krzysztof)
Michał Winiarski (6):
PCI/IOV: Restore VF resizable BAR state after reset
PCI: Add a helper to convert between VF BAR number and IOV resource
PCI: Allow IOV resources to be resized in pci_resize_resource()
PCI/IOV: Check that VF BAR fits within the reservation
PCI: Allow drivers to control VF BAR size
drm/xe/pf: Set VF LMEM BAR size
drivers/gpu/drm/xe/regs/xe_bars.h | 1 +
drivers/gpu/drm/xe/xe_pci_sriov.c | 22 +++++
drivers/pci/iov.c | 149 +++++++++++++++++++++++++++---
drivers/pci/pci.c | 10 +-
drivers/pci/pci.h | 29 ++++++
drivers/pci/setup-bus.c | 3 +-
drivers/pci/setup-res.c | 35 ++++++-
include/linux/pci.h | 6 ++
include/uapi/linux/pci_regs.h | 9 ++
9 files changed, 246 insertions(+), 18 deletions(-)
--
2.49.0
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v7 1/6] PCI/IOV: Restore VF resizable BAR state after reset
2025-04-02 14:11 [PATCH v7 0/6] PCI: VF resizable BAR Michał Winiarski
@ 2025-04-02 14:11 ` Michał Winiarski
2025-04-02 14:11 ` [PATCH v7 2/6] PCI: Add a helper to convert between VF BAR number and IOV resource Michał Winiarski
` (4 subsequent siblings)
5 siblings, 0 replies; 12+ messages in thread
From: Michał Winiarski @ 2025-04-02 14:11 UTC (permalink / raw)
To: linux-pci, intel-xe, dri-devel, linux-kernel, Bjorn Helgaas,
Christian König, Krzysztof Wilczyński,
Ilpo Järvinen
Cc: Rodrigo Vivi, Michal Wajdeczko, Lucas De Marchi,
Thomas Hellström, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, Matt Roper,
Michał Winiarski
Similar to regular resizable BAR, VF BAR can also be resized, e.g. by
the system firmware or the PCI subsystem itself.
The capability layout is the same as PCI_EXT_CAP_ID_REBAR.
Add the capability ID and restore it as a part of IOV state.
See PCIe r6.2, sec 7.8.7.
Signed-off-by: Michał Winiarski <michal.winiarski@intel.com>
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
---
drivers/pci/iov.c | 30 +++++++++++++++++++++++++++++-
drivers/pci/pci.h | 1 +
include/uapi/linux/pci_regs.h | 9 +++++++++
3 files changed, 39 insertions(+), 1 deletion(-)
diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c
index 10693b5d7eb66..8bdc0829f847b 100644
--- a/drivers/pci/iov.c
+++ b/drivers/pci/iov.c
@@ -7,6 +7,7 @@
* Copyright (C) 2009 Intel Corporation, Yu Zhao <yu.zhao@intel.com>
*/
+#include <linux/bitfield.h>
#include <linux/pci.h>
#include <linux/slab.h>
#include <linux/export.h>
@@ -850,6 +851,7 @@ static int sriov_init(struct pci_dev *dev, int pos)
pci_read_config_byte(dev, pos + PCI_SRIOV_FUNC_LINK, &iov->link);
if (pci_pcie_type(dev) == PCI_EXP_TYPE_RC_END)
iov->link = PCI_DEVFN(PCI_SLOT(dev->devfn), iov->link);
+ iov->vf_rebar_cap = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_VF_REBAR);
if (pdev)
iov->dev = pci_dev_get(pdev);
@@ -888,6 +890,30 @@ static void sriov_release(struct pci_dev *dev)
dev->sriov = NULL;
}
+static void sriov_restore_vf_rebar_state(struct pci_dev *dev)
+{
+ unsigned int pos, nbars, i;
+ u32 ctrl;
+
+ pos = dev->sriov->vf_rebar_cap;
+ if (!pos)
+ return;
+
+ pci_read_config_dword(dev, pos + PCI_VF_REBAR_CTRL, &ctrl);
+ nbars = FIELD_GET(PCI_VF_REBAR_CTRL_NBAR_MASK, ctrl);
+
+ for (i = 0; i < nbars; i++, pos += 8) {
+ int bar_idx, size;
+
+ pci_read_config_dword(dev, pos + PCI_VF_REBAR_CTRL, &ctrl);
+ bar_idx = FIELD_GET(PCI_VF_REBAR_CTRL_BAR_IDX, ctrl);
+ size = pci_rebar_bytes_to_size(dev->sriov->barsz[bar_idx]);
+ ctrl &= ~PCI_VF_REBAR_CTRL_BAR_SIZE;
+ ctrl |= FIELD_PREP(PCI_VF_REBAR_CTRL_BAR_SIZE, size);
+ pci_write_config_dword(dev, pos + PCI_VF_REBAR_CTRL, ctrl);
+ }
+}
+
static void sriov_restore_state(struct pci_dev *dev)
{
int i;
@@ -1047,8 +1073,10 @@ resource_size_t pci_sriov_resource_alignment(struct pci_dev *dev, int resno)
*/
void pci_restore_iov_state(struct pci_dev *dev)
{
- if (dev->is_physfn)
+ if (dev->is_physfn) {
+ sriov_restore_vf_rebar_state(dev);
sriov_restore_state(dev);
+ }
}
/**
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index b81e99cd4b62a..adc54bb2c8b34 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -482,6 +482,7 @@ struct pci_sriov {
u16 subsystem_vendor; /* VF subsystem vendor */
u16 subsystem_device; /* VF subsystem device */
resource_size_t barsz[PCI_SRIOV_NUM_BARS]; /* VF BAR size */
+ u16 vf_rebar_cap; /* VF Resizable BAR capability offset */
bool drivers_autoprobe; /* Auto probing of VFs by driver */
};
diff --git a/include/uapi/linux/pci_regs.h b/include/uapi/linux/pci_regs.h
index ba326710f9c8b..b2d5f3ac79ae9 100644
--- a/include/uapi/linux/pci_regs.h
+++ b/include/uapi/linux/pci_regs.h
@@ -745,6 +745,7 @@
#define PCI_EXT_CAP_ID_L1SS 0x1E /* L1 PM Substates */
#define PCI_EXT_CAP_ID_PTM 0x1F /* Precision Time Measurement */
#define PCI_EXT_CAP_ID_DVSEC 0x23 /* Designated Vendor-Specific */
+#define PCI_EXT_CAP_ID_VF_REBAR 0x24 /* VF Resizable BAR */
#define PCI_EXT_CAP_ID_DLF 0x25 /* Data Link Feature */
#define PCI_EXT_CAP_ID_PL_16GT 0x26 /* Physical Layer 16.0 GT/s */
#define PCI_EXT_CAP_ID_NPEM 0x29 /* Native PCIe Enclosure Management */
@@ -1140,6 +1141,14 @@
#define PCI_DVSEC_HEADER2 0x8 /* Designated Vendor-Specific Header2 */
#define PCI_DVSEC_HEADER2_ID(x) ((x) & 0xffff)
+/* VF Resizable BARs, same layout as PCI_REBAR */
+#define PCI_VF_REBAR_CAP PCI_REBAR_CAP
+#define PCI_VF_REBAR_CAP_SIZES PCI_REBAR_CAP_SIZES
+#define PCI_VF_REBAR_CTRL PCI_REBAR_CTRL
+#define PCI_VF_REBAR_CTRL_BAR_IDX PCI_REBAR_CTRL_BAR_IDX
+#define PCI_VF_REBAR_CTRL_NBAR_MASK PCI_REBAR_CTRL_NBAR_MASK
+#define PCI_VF_REBAR_CTRL_BAR_SIZE PCI_REBAR_CTRL_BAR_SIZE
+
/* Data Link Feature */
#define PCI_DLF_CAP 0x04 /* Capabilities Register */
#define PCI_DLF_EXCHANGE_ENABLE 0x80000000 /* Data Link Feature Exchange Enable */
--
2.49.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v7 2/6] PCI: Add a helper to convert between VF BAR number and IOV resource
2025-04-02 14:11 [PATCH v7 0/6] PCI: VF resizable BAR Michał Winiarski
2025-04-02 14:11 ` [PATCH v7 1/6] PCI/IOV: Restore VF resizable BAR state after reset Michał Winiarski
@ 2025-04-02 14:11 ` Michał Winiarski
2025-04-03 9:24 ` Ilpo Järvinen
2025-04-02 14:11 ` [PATCH v7 3/6] PCI: Allow IOV resources to be resized in pci_resize_resource() Michał Winiarski
` (3 subsequent siblings)
5 siblings, 1 reply; 12+ messages in thread
From: Michał Winiarski @ 2025-04-02 14:11 UTC (permalink / raw)
To: linux-pci, intel-xe, dri-devel, linux-kernel, Bjorn Helgaas,
Christian König, Krzysztof Wilczyński,
Ilpo Järvinen
Cc: Rodrigo Vivi, Michal Wajdeczko, Lucas De Marchi,
Thomas Hellström, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, Matt Roper,
Michał Winiarski
There are multiple places where conversions between IOV resources and
corresponding VF BAR numbers are done.
Extract the logic to pci_resource_num_from_vf_bar() and
pci_resource_num_to_vf_bar() helpers.
Suggested-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Michał Winiarski <michal.winiarski@intel.com>
Acked-by: Christian König <christian.koenig@amd.com>
---
drivers/pci/iov.c | 26 ++++++++++++++++----------
drivers/pci/pci.h | 19 +++++++++++++++++++
drivers/pci/setup-bus.c | 3 ++-
3 files changed, 37 insertions(+), 11 deletions(-)
diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c
index 8bdc0829f847b..3d5da055c3dc1 100644
--- a/drivers/pci/iov.c
+++ b/drivers/pci/iov.c
@@ -151,7 +151,7 @@ resource_size_t pci_iov_resource_size(struct pci_dev *dev, int resno)
if (!dev->is_physfn)
return 0;
- return dev->sriov->barsz[resno - PCI_IOV_RESOURCES];
+ return dev->sriov->barsz[pci_resource_num_to_vf_bar(resno)];
}
static void pci_read_vf_config_common(struct pci_dev *virtfn)
@@ -342,12 +342,14 @@ int pci_iov_add_virtfn(struct pci_dev *dev, int id)
virtfn->multifunction = 0;
for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) {
- res = &dev->resource[i + PCI_IOV_RESOURCES];
+ int idx = pci_resource_num_from_vf_bar(i);
+
+ res = &dev->resource[idx];
if (!res->parent)
continue;
virtfn->resource[i].name = pci_name(virtfn);
virtfn->resource[i].flags = res->flags;
- size = pci_iov_resource_size(dev, i + PCI_IOV_RESOURCES);
+ size = pci_iov_resource_size(dev, idx);
resource_set_range(&virtfn->resource[i],
res->start + size * id, size);
rc = request_resource(res, &virtfn->resource[i]);
@@ -644,8 +646,10 @@ static int sriov_enable(struct pci_dev *dev, int nr_virtfn)
nres = 0;
for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) {
- bars |= (1 << (i + PCI_IOV_RESOURCES));
- res = &dev->resource[i + PCI_IOV_RESOURCES];
+ int idx = pci_resource_num_from_vf_bar(i);
+
+ bars |= (1 << idx);
+ res = &dev->resource[idx];
if (res->parent)
nres++;
}
@@ -811,8 +815,10 @@ static int sriov_init(struct pci_dev *dev, int pos)
nres = 0;
for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) {
- res = &dev->resource[i + PCI_IOV_RESOURCES];
- res_name = pci_resource_name(dev, i + PCI_IOV_RESOURCES);
+ int idx = pci_resource_num_from_vf_bar(i);
+
+ res = &dev->resource[idx];
+ res_name = pci_resource_name(dev, idx);
/*
* If it is already FIXED, don't change it, something
@@ -871,7 +877,7 @@ static int sriov_init(struct pci_dev *dev, int pos)
dev->is_physfn = 0;
failed:
for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) {
- res = &dev->resource[i + PCI_IOV_RESOURCES];
+ res = &dev->resource[pci_resource_num_from_vf_bar(i)];
res->flags = 0;
}
@@ -933,7 +939,7 @@ static void sriov_restore_state(struct pci_dev *dev)
pci_write_config_word(dev, iov->pos + PCI_SRIOV_CTRL, ctrl);
for (i = 0; i < PCI_SRIOV_NUM_BARS; i++)
- pci_update_resource(dev, i + PCI_IOV_RESOURCES);
+ pci_update_resource(dev, pci_resource_num_from_vf_bar(i));
pci_write_config_dword(dev, iov->pos + PCI_SRIOV_SYS_PGSIZE, iov->pgsz);
pci_iov_set_numvfs(dev, iov->num_VFs);
@@ -999,7 +1005,7 @@ void pci_iov_update_resource(struct pci_dev *dev, int resno)
{
struct pci_sriov *iov = dev->is_physfn ? dev->sriov : NULL;
struct resource *res = pci_resource_n(dev, resno);
- int vf_bar = resno - PCI_IOV_RESOURCES;
+ int vf_bar = pci_resource_num_to_vf_bar(resno);
struct pci_bus_region region;
u16 cmd;
u32 new;
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index adc54bb2c8b34..f44840ee3c327 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -693,6 +693,15 @@ static inline bool pci_resource_is_iov(int resno)
{
return resno >= PCI_IOV_RESOURCES && resno <= PCI_IOV_RESOURCE_END;
}
+static inline int pci_resource_num_from_vf_bar(int resno)
+{
+ return resno + PCI_IOV_RESOURCES;
+}
+
+static inline int pci_resource_num_to_vf_bar(int resno)
+{
+ return resno - PCI_IOV_RESOURCES;
+}
extern const struct attribute_group sriov_pf_dev_attr_group;
extern const struct attribute_group sriov_vf_dev_attr_group;
#else
@@ -717,6 +726,16 @@ static inline bool pci_resource_is_iov(int resno)
{
return false;
}
+static inline int pci_resource_num_from_vf_bar(int resno)
+{
+ WARN_ON_ONCE(1);
+ return -ENODEV;
+}
+static inline int pci_resource_num_to_vf_bar(int resno)
+{
+ WARN_ON_ONCE(1);
+ return -ENODEV;
+}
#endif /* CONFIG_PCI_IOV */
#ifdef CONFIG_PCIE_TPH
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 54d6f4fa3ce16..281121449fc0b 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -1885,7 +1885,8 @@ static int iov_resources_unassigned(struct pci_dev *dev, void *data)
bool *unassigned = data;
for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) {
- struct resource *r = &dev->resource[i + PCI_IOV_RESOURCES];
+ int idx = pci_resource_num_from_vf_bar(i);
+ struct resource *r = &dev->resource[idx];
struct pci_bus_region region;
/* Not assigned or rejected by kernel? */
--
2.49.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v7 3/6] PCI: Allow IOV resources to be resized in pci_resize_resource()
2025-04-02 14:11 [PATCH v7 0/6] PCI: VF resizable BAR Michał Winiarski
2025-04-02 14:11 ` [PATCH v7 1/6] PCI/IOV: Restore VF resizable BAR state after reset Michał Winiarski
2025-04-02 14:11 ` [PATCH v7 2/6] PCI: Add a helper to convert between VF BAR number and IOV resource Michał Winiarski
@ 2025-04-02 14:11 ` Michał Winiarski
2025-04-03 9:45 ` Ilpo Järvinen
2025-04-02 14:11 ` [PATCH v7 4/6] PCI/IOV: Check that VF BAR fits within the reservation Michał Winiarski
` (2 subsequent siblings)
5 siblings, 1 reply; 12+ messages in thread
From: Michał Winiarski @ 2025-04-02 14:11 UTC (permalink / raw)
To: linux-pci, intel-xe, dri-devel, linux-kernel, Bjorn Helgaas,
Christian König, Krzysztof Wilczyński,
Ilpo Järvinen
Cc: Rodrigo Vivi, Michal Wajdeczko, Lucas De Marchi,
Thomas Hellström, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, Matt Roper,
Michał Winiarski
Similar to regular resizable BAR, VF BAR can also be resized.
The capability layout is the same as PCI_EXT_CAP_ID_REBAR, which means
we can reuse most of the implementation, the only difference being
resource size calculation (which is multiplied by total VFs) and memory
decoding (which is controlled by a separate VF MSE field in SR-IOV cap).
Extend the pci_resize_resource() function to accept IOV resources.
See PCIe r6.2, sec 7.8.7.
Signed-off-by: Michał Winiarski <michal.winiarski@intel.com>
---
drivers/pci/iov.c | 21 +++++++++++++++++++++
drivers/pci/pci.c | 10 +++++++++-
drivers/pci/pci.h | 9 +++++++++
drivers/pci/setup-res.c | 35 ++++++++++++++++++++++++++++++-----
4 files changed, 69 insertions(+), 6 deletions(-)
diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c
index 3d5da055c3dc1..fee99e15a943f 100644
--- a/drivers/pci/iov.c
+++ b/drivers/pci/iov.c
@@ -154,6 +154,27 @@ resource_size_t pci_iov_resource_size(struct pci_dev *dev, int resno)
return dev->sriov->barsz[pci_resource_num_to_vf_bar(resno)];
}
+void pci_iov_resource_set_size(struct pci_dev *dev, int resno,
+ resource_size_t size)
+{
+ if (!pci_resource_is_iov(resno)) {
+ pci_warn(dev, "%s is not an IOV resource\n",
+ pci_resource_name(dev, resno));
+ return;
+ }
+
+ dev->sriov->barsz[pci_resource_num_to_vf_bar(resno)] = size;
+}
+
+bool pci_iov_is_memory_decoding_enabled(struct pci_dev *dev)
+{
+ u16 cmd;
+
+ pci_read_config_word(dev, dev->sriov->pos + PCI_SRIOV_CTRL, &cmd);
+
+ return cmd & PCI_SRIOV_CTRL_MSE;
+}
+
static void pci_read_vf_config_common(struct pci_dev *virtfn)
{
struct pci_dev *physfn = virtfn->physfn;
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 4d7c9f64ea24e..6878e3b1e3fcf 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -3745,7 +3745,15 @@ static int pci_rebar_find_pos(struct pci_dev *pdev, int bar)
unsigned int pos, nbars, i;
u32 ctrl;
- pos = pdev->rebar_cap;
+ if (pci_resource_is_iov(bar)) {
+ if (!pdev->physfn)
+ return -ENOTSUPP;
+ pos = pdev->sriov->vf_rebar_cap;
+ bar = pci_resource_num_to_vf_bar(bar);
+ } else {
+ pos = pdev->rebar_cap;
+ }
+
if (!pos)
return -ENOTSUPP;
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index f44840ee3c327..643cd8c737f66 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -689,6 +689,9 @@ void pci_iov_update_resource(struct pci_dev *dev, int resno);
resource_size_t pci_sriov_resource_alignment(struct pci_dev *dev, int resno);
void pci_restore_iov_state(struct pci_dev *dev);
int pci_iov_bus_range(struct pci_bus *bus);
+void pci_iov_resource_set_size(struct pci_dev *dev, int resno,
+ resource_size_t size);
+bool pci_iov_is_memory_decoding_enabled(struct pci_dev *dev);
static inline bool pci_resource_is_iov(int resno)
{
return resno >= PCI_IOV_RESOURCES && resno <= PCI_IOV_RESOURCE_END;
@@ -722,6 +725,12 @@ static inline int pci_iov_bus_range(struct pci_bus *bus)
{
return 0;
}
+static inline void pci_iov_resource_set_size(struct pci_dev *dev, int resno,
+ resource_size_t size) { }
+static inline bool pci_iov_is_memory_decoding_enabled(struct pci_dev *dev)
+{
+ return false;
+}
static inline bool pci_resource_is_iov(int resno)
{
return false;
diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c
index c6657cdd06f67..d2b3ed51e8804 100644
--- a/drivers/pci/setup-res.c
+++ b/drivers/pci/setup-res.c
@@ -423,13 +423,39 @@ void pci_release_resource(struct pci_dev *dev, int resno)
}
EXPORT_SYMBOL(pci_release_resource);
+static bool pci_resize_is_memory_decoding_enabled(struct pci_dev *dev,
+ int resno)
+{
+ u16 cmd;
+
+ if (pci_resource_is_iov(resno))
+ return pci_iov_is_memory_decoding_enabled(dev);
+
+ pci_read_config_word(dev, PCI_COMMAND, &cmd);
+
+ return cmd & PCI_COMMAND_MEMORY;
+}
+
+static void pci_resize_resource_set_size(struct pci_dev *dev, int resno,
+ int size)
+{
+ resource_size_t res_size = pci_rebar_size_to_bytes(size);
+ struct resource *res = pci_resource_n(dev, resno);
+
+ if (!pci_resource_is_iov(resno)) {
+ resource_set_size(res, res_size);
+ } else {
+ resource_set_size(res, res_size * pci_sriov_get_totalvfs(dev));
+ pci_iov_resource_set_size(dev, resno, res_size);
+ }
+}
+
int pci_resize_resource(struct pci_dev *dev, int resno, int size)
{
struct resource *res = pci_resource_n(dev, resno);
struct pci_host_bridge *host;
int old, ret;
u32 sizes;
- u16 cmd;
/* Check if we must preserve the firmware's resource assignment */
host = pci_find_host_bridge(dev->bus);
@@ -440,8 +466,7 @@ int pci_resize_resource(struct pci_dev *dev, int resno, int size)
if (!(res->flags & IORESOURCE_UNSET))
return -EBUSY;
- pci_read_config_word(dev, PCI_COMMAND, &cmd);
- if (cmd & PCI_COMMAND_MEMORY)
+ if (pci_resize_is_memory_decoding_enabled(dev, resno))
return -EBUSY;
sizes = pci_rebar_get_possible_sizes(dev, resno);
@@ -459,7 +484,7 @@ int pci_resize_resource(struct pci_dev *dev, int resno, int size)
if (ret)
return ret;
- resource_set_size(res, pci_rebar_size_to_bytes(size));
+ pci_resize_resource_set_size(dev, resno, size);
/* Check if the new config works by trying to assign everything. */
if (dev->bus->self) {
@@ -471,7 +496,7 @@ int pci_resize_resource(struct pci_dev *dev, int resno, int size)
error_resize:
pci_rebar_set_size(dev, resno, old);
- resource_set_size(res, pci_rebar_size_to_bytes(old));
+ pci_resize_resource_set_size(dev, resno, old);
return ret;
}
EXPORT_SYMBOL(pci_resize_resource);
--
2.49.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v7 4/6] PCI/IOV: Check that VF BAR fits within the reservation
2025-04-02 14:11 [PATCH v7 0/6] PCI: VF resizable BAR Michał Winiarski
` (2 preceding siblings ...)
2025-04-02 14:11 ` [PATCH v7 3/6] PCI: Allow IOV resources to be resized in pci_resize_resource() Michał Winiarski
@ 2025-04-02 14:11 ` Michał Winiarski
2025-04-03 9:54 ` Ilpo Järvinen
2025-04-02 14:11 ` [PATCH v7 5/6] PCI: Allow drivers to control VF BAR size Michał Winiarski
2025-04-02 14:11 ` [PATCH v7 6/6] drm/xe/pf: Set VF LMEM " Michał Winiarski
5 siblings, 1 reply; 12+ messages in thread
From: Michał Winiarski @ 2025-04-02 14:11 UTC (permalink / raw)
To: linux-pci, intel-xe, dri-devel, linux-kernel, Bjorn Helgaas,
Christian König, Krzysztof Wilczyński,
Ilpo Järvinen
Cc: Rodrigo Vivi, Michal Wajdeczko, Lucas De Marchi,
Thomas Hellström, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, Matt Roper,
Michał Winiarski
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>
---
drivers/pci/iov.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c
index fee99e15a943f..2fafbd6a998f0 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
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v7 5/6] PCI: Allow drivers to control VF BAR size
2025-04-02 14:11 [PATCH v7 0/6] PCI: VF resizable BAR Michał Winiarski
` (3 preceding siblings ...)
2025-04-02 14:11 ` [PATCH v7 4/6] PCI/IOV: Check that VF BAR fits within the reservation Michał Winiarski
@ 2025-04-02 14:11 ` Michał Winiarski
2025-04-03 10:20 ` Ilpo Järvinen
2025-04-02 14:11 ` [PATCH v7 6/6] drm/xe/pf: Set VF LMEM " Michał Winiarski
5 siblings, 1 reply; 12+ messages in thread
From: Michał Winiarski @ 2025-04-02 14:11 UTC (permalink / raw)
To: linux-pci, intel-xe, dri-devel, linux-kernel, Bjorn Helgaas,
Christian König, Krzysztof Wilczyński,
Ilpo Järvinen
Cc: Rodrigo Vivi, Michal Wajdeczko, Lucas De Marchi,
Thomas Hellström, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, Matt Roper,
Michał Winiarski
Drivers could leverage the fact that the VF BAR MMIO reservation is
created for total number of VFs supported by the device by resizing the
BAR to larger size when smaller number of VFs is enabled.
Add a pci_iov_vf_bar_set_size() function to control the size and a
pci_iov_vf_bar_get_sizes() helper to get the VF BAR sizes that will
allow up to num_vfs to be successfully enabled with the current
underlying reservation size.
Signed-off-by: Michał Winiarski <michal.winiarski@intel.com>
---
drivers/pci/iov.c | 69 +++++++++++++++++++++++++++++++++++++++++++++
include/linux/pci.h | 6 ++++
2 files changed, 75 insertions(+)
diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c
index 2fafbd6a998f0..8a62049b56b41 100644
--- a/drivers/pci/iov.c
+++ b/drivers/pci/iov.c
@@ -1313,3 +1313,72 @@ int pci_sriov_configure_simple(struct pci_dev *dev, int nr_virtfn)
return nr_virtfn;
}
EXPORT_SYMBOL_GPL(pci_sriov_configure_simple);
+
+/**
+ * pci_iov_vf_bar_set_size - set a new size for a VF BAR
+ * @dev: the PCI device
+ * @resno: the resource number
+ * @size: new size as defined in the spec (0=1MB, 31=128TB)
+ *
+ * Set the new size of a VF BAR that supports VF resizable BAR capability.
+ * Unlike pci_resize_resource(), this does not cause the resource that
+ * reserves the MMIO space (originally up to total_VFs) to be resized, which
+ * means that following calls to pci_enable_sriov() can fail if the resources
+ * no longer fit.
+ *
+ * Return: 0 on success, or negative on failure.
+ */
+int pci_iov_vf_bar_set_size(struct pci_dev *dev, int resno, int size)
+{
+ int ret;
+ u32 sizes;
+
+ if (!pci_resource_is_iov(resno))
+ return -EINVAL;
+
+ if (pci_iov_is_memory_decoding_enabled(dev))
+ return -EBUSY;
+
+ sizes = pci_rebar_get_possible_sizes(dev, resno);
+ if (!sizes)
+ return -ENOTSUPP;
+
+ if (!(sizes & BIT(size)))
+ return -EINVAL;
+
+ ret = pci_rebar_set_size(dev, resno, size);
+ if (ret)
+ return ret;
+
+ pci_iov_resource_set_size(dev, resno, pci_rebar_size_to_bytes(size));
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(pci_iov_vf_bar_set_size);
+
+/**
+ * pci_iov_vf_bar_get_sizes - get VF BAR sizes allowing to create up to num_vfs
+ * @dev: the PCI device
+ * @resno: the resource number
+ * @num_vfs: number of VFs
+ *
+ * Get the sizes of a VF resizable BAR that can accommodate @num_vfs within
+ * the currently assigned size of the resource @resno.
+ *
+ * Return: A bitmask of sizes in format defined in the spec (bit 0=1MB,
+ * bit 31=128TB).
+ */
+u32 pci_iov_vf_bar_get_sizes(struct pci_dev *dev, int resno, int num_vfs)
+{
+ resource_size_t vf_len = pci_resource_len(dev, resno);
+ u32 sizes;
+
+ if (!num_vfs)
+ return 0;
+
+ do_div(vf_len, num_vfs);
+ sizes = (roundup_pow_of_two(vf_len + 1) - 1) >> ilog2(SZ_1M);
+
+ return sizes & pci_rebar_get_possible_sizes(dev, resno);
+}
+EXPORT_SYMBOL_GPL(pci_iov_vf_bar_get_sizes);
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 0e8e3fd77e967..c8708f3749757 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -2389,6 +2389,8 @@ int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 numvfs);
int pci_sriov_get_totalvfs(struct pci_dev *dev);
int pci_sriov_configure_simple(struct pci_dev *dev, int nr_virtfn);
resource_size_t pci_iov_resource_size(struct pci_dev *dev, int resno);
+int pci_iov_vf_bar_set_size(struct pci_dev *dev, int resno, int size);
+u32 pci_iov_vf_bar_get_sizes(struct pci_dev *dev, int resno, int num_vfs);
void pci_vf_drivers_autoprobe(struct pci_dev *dev, bool probe);
/* Arch may override these (weak) */
@@ -2441,6 +2443,10 @@ static inline int pci_sriov_get_totalvfs(struct pci_dev *dev)
#define pci_sriov_configure_simple NULL
static inline resource_size_t pci_iov_resource_size(struct pci_dev *dev, int resno)
{ return 0; }
+static inline int pci_iov_vf_bar_set_size(struct pci_dev *dev, int resno, int size)
+{ return -ENODEV; }
+static inline u32 pci_iov_vf_bar_get_sizes(struct pci_dev *dev, int resno, int num_vfs)
+{ return 0; }
static inline void pci_vf_drivers_autoprobe(struct pci_dev *dev, bool probe) { }
#endif
--
2.49.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v7 6/6] drm/xe/pf: Set VF LMEM BAR size
2025-04-02 14:11 [PATCH v7 0/6] PCI: VF resizable BAR Michał Winiarski
` (4 preceding siblings ...)
2025-04-02 14:11 ` [PATCH v7 5/6] PCI: Allow drivers to control VF BAR size Michał Winiarski
@ 2025-04-02 14:11 ` Michał Winiarski
5 siblings, 0 replies; 12+ messages in thread
From: Michał Winiarski @ 2025-04-02 14:11 UTC (permalink / raw)
To: linux-pci, intel-xe, dri-devel, linux-kernel, Bjorn Helgaas,
Christian König, Krzysztof Wilczyński,
Ilpo Järvinen
Cc: Rodrigo Vivi, Michal Wajdeczko, Lucas De Marchi,
Thomas Hellström, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, Matt Roper,
Michał Winiarski
LMEM is partitioned between multiple VFs and we expect that the more
VFs we have, the less LMEM is assigned to each VF.
This means that we can achieve full LMEM BAR access without the need to
attempt full VF LMEM BAR resize via pci_resize_resource().
Always try to set the largest possible BAR size that allows to fit the
number of enabled VFs and inform the user in case the resize attempt is
not successful.
Signed-off-by: Michał Winiarski <michal.winiarski@intel.com>
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
drivers/gpu/drm/xe/regs/xe_bars.h | 1 +
drivers/gpu/drm/xe/xe_pci_sriov.c | 22 ++++++++++++++++++++++
2 files changed, 23 insertions(+)
diff --git a/drivers/gpu/drm/xe/regs/xe_bars.h b/drivers/gpu/drm/xe/regs/xe_bars.h
index ce05b6ae832f1..880140d6ccdca 100644
--- a/drivers/gpu/drm/xe/regs/xe_bars.h
+++ b/drivers/gpu/drm/xe/regs/xe_bars.h
@@ -7,5 +7,6 @@
#define GTTMMADR_BAR 0 /* MMIO + GTT */
#define LMEM_BAR 2 /* VRAM */
+#define VF_LMEM_BAR 9 /* VF VRAM */
#endif
diff --git a/drivers/gpu/drm/xe/xe_pci_sriov.c b/drivers/gpu/drm/xe/xe_pci_sriov.c
index 09ee8a06fe2ed..4be566331ee15 100644
--- a/drivers/gpu/drm/xe/xe_pci_sriov.c
+++ b/drivers/gpu/drm/xe/xe_pci_sriov.c
@@ -3,6 +3,10 @@
* Copyright © 2023-2024 Intel Corporation
*/
+#include <linux/bitops.h>
+#include <linux/pci.h>
+
+#include "regs/xe_bars.h"
#include "xe_assert.h"
#include "xe_device.h"
#include "xe_gt_sriov_pf_config.h"
@@ -111,6 +115,18 @@ static void pf_link_vfs(struct xe_device *xe, int num_vfs)
}
}
+static int resize_vf_vram_bar(struct xe_device *xe, int num_vfs)
+{
+ struct pci_dev *pdev = to_pci_dev(xe->drm.dev);
+ u32 sizes;
+
+ sizes = pci_iov_vf_bar_get_sizes(pdev, VF_LMEM_BAR, num_vfs);
+ if (!sizes)
+ return 0;
+
+ return pci_iov_vf_bar_set_size(pdev, VF_LMEM_BAR, __fls(sizes));
+}
+
static int pf_enable_vfs(struct xe_device *xe, int num_vfs)
{
struct pci_dev *pdev = to_pci_dev(xe->drm.dev);
@@ -137,6 +153,12 @@ static int pf_enable_vfs(struct xe_device *xe, int num_vfs)
if (err < 0)
goto failed;
+ if (IS_DGFX(xe)) {
+ err = resize_vf_vram_bar(xe, num_vfs);
+ if (err)
+ xe_sriov_info(xe, "Failed to set VF LMEM BAR size: %d\n", err);
+ }
+
err = pci_enable_sriov(pdev, num_vfs);
if (err < 0)
goto failed;
--
2.49.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH v7 2/6] PCI: Add a helper to convert between VF BAR number and IOV resource
2025-04-02 14:11 ` [PATCH v7 2/6] PCI: Add a helper to convert between VF BAR number and IOV resource Michał Winiarski
@ 2025-04-03 9:24 ` Ilpo Järvinen
0 siblings, 0 replies; 12+ messages in thread
From: Ilpo Järvinen @ 2025-04-03 9:24 UTC (permalink / raw)
To: Michał Winiarski
Cc: linux-pci, intel-xe, dri-devel, LKML, Bjorn Helgaas,
Christian König, Krzysztof Wilczyński, Rodrigo Vivi,
Michal Wajdeczko, Lucas De Marchi, Thomas Hellström,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, Matt Roper
[-- Attachment #1: Type: text/plain, Size: 5655 bytes --]
On Wed, 2 Apr 2025, Michał Winiarski wrote:
> There are multiple places where conversions between IOV resources and
> corresponding VF BAR numbers are done.
>
> Extract the logic to pci_resource_num_from_vf_bar() and
> pci_resource_num_to_vf_bar() helpers.
>
> Suggested-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
> Signed-off-by: Michał Winiarski <michal.winiarski@intel.com>
> Acked-by: Christian König <christian.koenig@amd.com>
> ---
> drivers/pci/iov.c | 26 ++++++++++++++++----------
> drivers/pci/pci.h | 19 +++++++++++++++++++
> drivers/pci/setup-bus.c | 3 ++-
> 3 files changed, 37 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c
> index 8bdc0829f847b..3d5da055c3dc1 100644
> --- a/drivers/pci/iov.c
> +++ b/drivers/pci/iov.c
> @@ -151,7 +151,7 @@ resource_size_t pci_iov_resource_size(struct pci_dev *dev, int resno)
> if (!dev->is_physfn)
> return 0;
>
> - return dev->sriov->barsz[resno - PCI_IOV_RESOURCES];
> + return dev->sriov->barsz[pci_resource_num_to_vf_bar(resno)];
> }
>
> static void pci_read_vf_config_common(struct pci_dev *virtfn)
> @@ -342,12 +342,14 @@ int pci_iov_add_virtfn(struct pci_dev *dev, int id)
> virtfn->multifunction = 0;
>
> for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) {
> - res = &dev->resource[i + PCI_IOV_RESOURCES];
> + int idx = pci_resource_num_from_vf_bar(i);
> +
> + res = &dev->resource[idx];
> if (!res->parent)
> continue;
> virtfn->resource[i].name = pci_name(virtfn);
> virtfn->resource[i].flags = res->flags;
> - size = pci_iov_resource_size(dev, i + PCI_IOV_RESOURCES);
> + size = pci_iov_resource_size(dev, idx);
> resource_set_range(&virtfn->resource[i],
> res->start + size * id, size);
> rc = request_resource(res, &virtfn->resource[i]);
> @@ -644,8 +646,10 @@ static int sriov_enable(struct pci_dev *dev, int nr_virtfn)
>
> nres = 0;
> for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) {
> - bars |= (1 << (i + PCI_IOV_RESOURCES));
> - res = &dev->resource[i + PCI_IOV_RESOURCES];
> + int idx = pci_resource_num_from_vf_bar(i);
> +
> + bars |= (1 << idx);
> + res = &dev->resource[idx];
> if (res->parent)
> nres++;
> }
> @@ -811,8 +815,10 @@ static int sriov_init(struct pci_dev *dev, int pos)
>
> nres = 0;
> for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) {
> - res = &dev->resource[i + PCI_IOV_RESOURCES];
> - res_name = pci_resource_name(dev, i + PCI_IOV_RESOURCES);
> + int idx = pci_resource_num_from_vf_bar(i);
> +
> + res = &dev->resource[idx];
> + res_name = pci_resource_name(dev, idx);
>
> /*
> * If it is already FIXED, don't change it, something
> @@ -871,7 +877,7 @@ static int sriov_init(struct pci_dev *dev, int pos)
> dev->is_physfn = 0;
> failed:
> for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) {
> - res = &dev->resource[i + PCI_IOV_RESOURCES];
> + res = &dev->resource[pci_resource_num_from_vf_bar(i)];
> res->flags = 0;
> }
>
> @@ -933,7 +939,7 @@ static void sriov_restore_state(struct pci_dev *dev)
> pci_write_config_word(dev, iov->pos + PCI_SRIOV_CTRL, ctrl);
>
> for (i = 0; i < PCI_SRIOV_NUM_BARS; i++)
> - pci_update_resource(dev, i + PCI_IOV_RESOURCES);
> + pci_update_resource(dev, pci_resource_num_from_vf_bar(i));
>
> pci_write_config_dword(dev, iov->pos + PCI_SRIOV_SYS_PGSIZE, iov->pgsz);
> pci_iov_set_numvfs(dev, iov->num_VFs);
> @@ -999,7 +1005,7 @@ void pci_iov_update_resource(struct pci_dev *dev, int resno)
> {
> struct pci_sriov *iov = dev->is_physfn ? dev->sriov : NULL;
> struct resource *res = pci_resource_n(dev, resno);
> - int vf_bar = resno - PCI_IOV_RESOURCES;
> + int vf_bar = pci_resource_num_to_vf_bar(resno);
> struct pci_bus_region region;
> u16 cmd;
> u32 new;
> diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
> index adc54bb2c8b34..f44840ee3c327 100644
> --- a/drivers/pci/pci.h
> +++ b/drivers/pci/pci.h
> @@ -693,6 +693,15 @@ static inline bool pci_resource_is_iov(int resno)
> {
> return resno >= PCI_IOV_RESOURCES && resno <= PCI_IOV_RESOURCE_END;
> }
> +static inline int pci_resource_num_from_vf_bar(int resno)
> +{
> + return resno + PCI_IOV_RESOURCES;
> +}
> +
> +static inline int pci_resource_num_to_vf_bar(int resno)
> +{
> + return resno - PCI_IOV_RESOURCES;
> +}
> extern const struct attribute_group sriov_pf_dev_attr_group;
> extern const struct attribute_group sriov_vf_dev_attr_group;
> #else
> @@ -717,6 +726,16 @@ static inline bool pci_resource_is_iov(int resno)
> {
> return false;
> }
> +static inline int pci_resource_num_from_vf_bar(int resno)
> +{
> + WARN_ON_ONCE(1);
> + return -ENODEV;
> +}
> +static inline int pci_resource_num_to_vf_bar(int resno)
> +{
> + WARN_ON_ONCE(1);
> + return -ENODEV;
> +}
> #endif /* CONFIG_PCI_IOV */
>
> #ifdef CONFIG_PCIE_TPH
> diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
> index 54d6f4fa3ce16..281121449fc0b 100644
> --- a/drivers/pci/setup-bus.c
> +++ b/drivers/pci/setup-bus.c
> @@ -1885,7 +1885,8 @@ static int iov_resources_unassigned(struct pci_dev *dev, void *data)
> bool *unassigned = data;
>
> for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) {
> - struct resource *r = &dev->resource[i + PCI_IOV_RESOURCES];
> + int idx = pci_resource_num_from_vf_bar(i);
> + struct resource *r = &dev->resource[idx];
> struct pci_bus_region region;
>
> /* Not assigned or rejected by kernel? */
>
Thanks, looks more readable now.
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
--
i.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v7 3/6] PCI: Allow IOV resources to be resized in pci_resize_resource()
2025-04-02 14:11 ` [PATCH v7 3/6] PCI: Allow IOV resources to be resized in pci_resize_resource() Michał Winiarski
@ 2025-04-03 9:45 ` Ilpo Järvinen
0 siblings, 0 replies; 12+ messages in thread
From: Ilpo Järvinen @ 2025-04-03 9:45 UTC (permalink / raw)
To: Michał Winiarski
Cc: linux-pci, intel-xe, dri-devel, LKML, Bjorn Helgaas,
Christian König, Krzysztof Wilczyński, Rodrigo Vivi,
Michal Wajdeczko, Lucas De Marchi, Thomas Hellström,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, Matt Roper
[-- Attachment #1: Type: text/plain, Size: 6167 bytes --]
On Wed, 2 Apr 2025, Michał Winiarski wrote:
> Similar to regular resizable BAR, VF BAR can also be resized.
>
> The capability layout is the same as PCI_EXT_CAP_ID_REBAR, which means
> we can reuse most of the implementation, the only difference being
> resource size calculation (which is multiplied by total VFs) and memory
> decoding (which is controlled by a separate VF MSE field in SR-IOV cap).
>
> Extend the pci_resize_resource() function to accept IOV resources.
>
> See PCIe r6.2, sec 7.8.7.
>
> Signed-off-by: Michał Winiarski <michal.winiarski@intel.com>
> ---
> drivers/pci/iov.c | 21 +++++++++++++++++++++
> drivers/pci/pci.c | 10 +++++++++-
> drivers/pci/pci.h | 9 +++++++++
> drivers/pci/setup-res.c | 35 ++++++++++++++++++++++++++++++-----
> 4 files changed, 69 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c
> index 3d5da055c3dc1..fee99e15a943f 100644
> --- a/drivers/pci/iov.c
> +++ b/drivers/pci/iov.c
> @@ -154,6 +154,27 @@ resource_size_t pci_iov_resource_size(struct pci_dev *dev, int resno)
> return dev->sriov->barsz[pci_resource_num_to_vf_bar(resno)];
> }
>
> +void pci_iov_resource_set_size(struct pci_dev *dev, int resno,
> + resource_size_t size)
> +{
> + if (!pci_resource_is_iov(resno)) {
> + pci_warn(dev, "%s is not an IOV resource\n",
> + pci_resource_name(dev, resno));
> + return;
> + }
> +
> + dev->sriov->barsz[pci_resource_num_to_vf_bar(resno)] = size;
> +}
> +
> +bool pci_iov_is_memory_decoding_enabled(struct pci_dev *dev)
> +{
> + u16 cmd;
> +
> + pci_read_config_word(dev, dev->sriov->pos + PCI_SRIOV_CTRL, &cmd);
> +
> + return cmd & PCI_SRIOV_CTRL_MSE;
> +}
> +
> static void pci_read_vf_config_common(struct pci_dev *virtfn)
> {
> struct pci_dev *physfn = virtfn->physfn;
> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> index 4d7c9f64ea24e..6878e3b1e3fcf 100644
> --- a/drivers/pci/pci.c
> +++ b/drivers/pci/pci.c
> @@ -3745,7 +3745,15 @@ static int pci_rebar_find_pos(struct pci_dev *pdev, int bar)
> unsigned int pos, nbars, i;
> u32 ctrl;
>
> - pos = pdev->rebar_cap;
> + if (pci_resource_is_iov(bar)) {
> + if (!pdev->physfn)
> + return -ENOTSUPP;
> + pos = pdev->sriov->vf_rebar_cap;
> + bar = pci_resource_num_to_vf_bar(bar);
> + } else {
> + pos = pdev->rebar_cap;
> + }
> +
> if (!pos)
> return -ENOTSUPP;
>
> diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
> index f44840ee3c327..643cd8c737f66 100644
> --- a/drivers/pci/pci.h
> +++ b/drivers/pci/pci.h
> @@ -689,6 +689,9 @@ void pci_iov_update_resource(struct pci_dev *dev, int resno);
> resource_size_t pci_sriov_resource_alignment(struct pci_dev *dev, int resno);
> void pci_restore_iov_state(struct pci_dev *dev);
> int pci_iov_bus_range(struct pci_bus *bus);
> +void pci_iov_resource_set_size(struct pci_dev *dev, int resno,
> + resource_size_t size);
> +bool pci_iov_is_memory_decoding_enabled(struct pci_dev *dev);
> static inline bool pci_resource_is_iov(int resno)
> {
> return resno >= PCI_IOV_RESOURCES && resno <= PCI_IOV_RESOURCE_END;
> @@ -722,6 +725,12 @@ static inline int pci_iov_bus_range(struct pci_bus *bus)
> {
> return 0;
> }
> +static inline void pci_iov_resource_set_size(struct pci_dev *dev, int resno,
> + resource_size_t size) { }
> +static inline bool pci_iov_is_memory_decoding_enabled(struct pci_dev *dev)
> +{
> + return false;
> +}
> static inline bool pci_resource_is_iov(int resno)
> {
> return false;
> diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c
> index c6657cdd06f67..d2b3ed51e8804 100644
> --- a/drivers/pci/setup-res.c
> +++ b/drivers/pci/setup-res.c
> @@ -423,13 +423,39 @@ void pci_release_resource(struct pci_dev *dev, int resno)
> }
> EXPORT_SYMBOL(pci_release_resource);
>
> +static bool pci_resize_is_memory_decoding_enabled(struct pci_dev *dev,
> + int resno)
> +{
> + u16 cmd;
> +
> + if (pci_resource_is_iov(resno))
> + return pci_iov_is_memory_decoding_enabled(dev);
> +
> + pci_read_config_word(dev, PCI_COMMAND, &cmd);
> +
> + return cmd & PCI_COMMAND_MEMORY;
> +}
> +
> +static void pci_resize_resource_set_size(struct pci_dev *dev, int resno,
> + int size)
> +{
> + resource_size_t res_size = pci_rebar_size_to_bytes(size);
> + struct resource *res = pci_resource_n(dev, resno);
> +
> + if (!pci_resource_is_iov(resno)) {
> + resource_set_size(res, res_size);
> + } else {
> + resource_set_size(res, res_size * pci_sriov_get_totalvfs(dev));
> + pci_iov_resource_set_size(dev, resno, res_size);
> + }
> +}
> +
> int pci_resize_resource(struct pci_dev *dev, int resno, int size)
> {
> struct resource *res = pci_resource_n(dev, resno);
> struct pci_host_bridge *host;
> int old, ret;
> u32 sizes;
> - u16 cmd;
>
> /* Check if we must preserve the firmware's resource assignment */
> host = pci_find_host_bridge(dev->bus);
> @@ -440,8 +466,7 @@ int pci_resize_resource(struct pci_dev *dev, int resno, int size)
> if (!(res->flags & IORESOURCE_UNSET))
> return -EBUSY;
>
> - pci_read_config_word(dev, PCI_COMMAND, &cmd);
> - if (cmd & PCI_COMMAND_MEMORY)
> + if (pci_resize_is_memory_decoding_enabled(dev, resno))
> return -EBUSY;
>
> sizes = pci_rebar_get_possible_sizes(dev, resno);
> @@ -459,7 +484,7 @@ int pci_resize_resource(struct pci_dev *dev, int resno, int size)
> if (ret)
> return ret;
>
> - resource_set_size(res, pci_rebar_size_to_bytes(size));
> + pci_resize_resource_set_size(dev, resno, size);
>
> /* Check if the new config works by trying to assign everything. */
> if (dev->bus->self) {
> @@ -471,7 +496,7 @@ int pci_resize_resource(struct pci_dev *dev, int resno, int size)
>
> error_resize:
> pci_rebar_set_size(dev, resno, old);
> - resource_set_size(res, pci_rebar_size_to_bytes(old));
> + pci_resize_resource_set_size(dev, resno, old);
> return ret;
> }
> EXPORT_SYMBOL(pci_resize_resource);
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
--
i.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v7 4/6] PCI/IOV: Check that VF BAR fits within the reservation
2025-04-02 14:11 ` [PATCH v7 4/6] PCI/IOV: Check that VF BAR fits within the reservation Michał Winiarski
@ 2025-04-03 9:54 ` Ilpo Järvinen
0 siblings, 0 replies; 12+ messages in thread
From: Ilpo Järvinen @ 2025-04-03 9:54 UTC (permalink / raw)
To: Michał Winiarski
Cc: linux-pci, intel-xe, dri-devel, LKML, Bjorn Helgaas,
Christian König, Krzysztof Wilczyński, Rodrigo Vivi,
Michal Wajdeczko, Lucas De Marchi, Thomas Hellström,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, Matt Roper
[-- Attachment #1: Type: text/plain, Size: 1517 bytes --]
On Wed, 2 Apr 2025, Michał Winiarski wrote:
> 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>
> ---
> drivers/pci/iov.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c
> index fee99e15a943f..2fafbd6a998f0 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++;
> }
>
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
--
i.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v7 5/6] PCI: Allow drivers to control VF BAR size
2025-04-02 14:11 ` [PATCH v7 5/6] PCI: Allow drivers to control VF BAR size Michał Winiarski
@ 2025-04-03 10:20 ` Ilpo Järvinen
2025-05-26 21:54 ` Michał Winiarski
0 siblings, 1 reply; 12+ messages in thread
From: Ilpo Järvinen @ 2025-04-03 10:20 UTC (permalink / raw)
To: Michał Winiarski
Cc: linux-pci, intel-xe, dri-devel, LKML, Bjorn Helgaas,
Christian König, Krzysztof Wilczyński, Rodrigo Vivi,
Michal Wajdeczko, Lucas De Marchi, Thomas Hellström,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, Matt Roper
[-- Attachment #1: Type: text/plain, Size: 5670 bytes --]
On Wed, 2 Apr 2025, Michał Winiarski wrote:
> Drivers could leverage the fact that the VF BAR MMIO reservation is
> created for total number of VFs supported by the device by resizing the
> BAR to larger size when smaller number of VFs is enabled.
>
> Add a pci_iov_vf_bar_set_size() function to control the size and a
> pci_iov_vf_bar_get_sizes() helper to get the VF BAR sizes that will
> allow up to num_vfs to be successfully enabled with the current
> underlying reservation size.
>
> Signed-off-by: Michał Winiarski <michal.winiarski@intel.com>
> ---
> drivers/pci/iov.c | 69 +++++++++++++++++++++++++++++++++++++++++++++
> include/linux/pci.h | 6 ++++
> 2 files changed, 75 insertions(+)
>
> diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c
> index 2fafbd6a998f0..8a62049b56b41 100644
> --- a/drivers/pci/iov.c
> +++ b/drivers/pci/iov.c
> @@ -1313,3 +1313,72 @@ int pci_sriov_configure_simple(struct pci_dev *dev, int nr_virtfn)
> return nr_virtfn;
> }
> EXPORT_SYMBOL_GPL(pci_sriov_configure_simple);
> +
> +/**
> + * pci_iov_vf_bar_set_size - set a new size for a VF BAR
> + * @dev: the PCI device
> + * @resno: the resource number
> + * @size: new size as defined in the spec (0=1MB, 31=128TB)
> + *
> + * Set the new size of a VF BAR that supports VF resizable BAR capability.
> + * Unlike pci_resize_resource(), this does not cause the resource that
> + * reserves the MMIO space (originally up to total_VFs) to be resized, which
> + * means that following calls to pci_enable_sriov() can fail if the resources
> + * no longer fit.
> + *
> + * Return: 0 on success, or negative on failure.
> + */
> +int pci_iov_vf_bar_set_size(struct pci_dev *dev, int resno, int size)
> +{
> + int ret;
> + u32 sizes;
Please reverse the order of these variables.
> +
> + if (!pci_resource_is_iov(resno))
> + return -EINVAL;
> +
> + if (pci_iov_is_memory_decoding_enabled(dev))
> + return -EBUSY;
> +
> + sizes = pci_rebar_get_possible_sizes(dev, resno);
> + if (!sizes)
> + return -ENOTSUPP;
> +
> + if (!(sizes & BIT(size)))
Add include for BIT().
Although adding a helper like this would be helpful for multiple callers:
@@ -3780,6 +3780,88 @@ u32 pci_rebar_get_possible_sizes(struct pci_dev *pdev, int bar)
}
EXPORT_SYMBOL(pci_rebar_get_possible_sizes);
+/**
+ * pci_rebar_size_supported - check if size is supported for a resizable BAR
+ * @pdev: PCI device
+ * @bar: BAR to check
+ * @size: size as defined in the spec (0=1MB, 31=128TB)
+ *
+ * Return: %0 if @size is supported for @bar,
+ * %-EINVAL if @size is not supported,
+ * %-ENOTSUPP if @bar is not resizable.
+ */
+int pci_rebar_size_supported(struct pci_dev *pdev, int bar, int size)
+{
+ u64 sizes;
+
+ sizes = pci_rebar_get_possible_sizes(pdev, bar);
+ if (!sizes)
+ return -ENOTSUPP;
+
+ return BIT(size) & sizes ? 0 : -EINVAL;
+}
+EXPORT_SYMBOL_GPL(pci_rebar_size_supported);
(Yes, I've some rebar helpers pending so this is extract from that.)
> + return -EINVAL;
> +
> + ret = pci_rebar_set_size(dev, resno, size);
> + if (ret)
> + return ret;
> +
> + pci_iov_resource_set_size(dev, resno, pci_rebar_size_to_bytes(size));
> +
> + return 0;
> +}
> +EXPORT_SYMBOL_GPL(pci_iov_vf_bar_set_size);
> +
> +/**
> + * pci_iov_vf_bar_get_sizes - get VF BAR sizes allowing to create up to num_vfs
> + * @dev: the PCI device
> + * @resno: the resource number
> + * @num_vfs: number of VFs
> + *
> + * Get the sizes of a VF resizable BAR that can accommodate @num_vfs within
> + * the currently assigned size of the resource @resno.
> + *
> + * Return: A bitmask of sizes in format defined in the spec (bit 0=1MB,
> + * bit 31=128TB).
> + */
> +u32 pci_iov_vf_bar_get_sizes(struct pci_dev *dev, int resno, int num_vfs)
> +{
> + resource_size_t vf_len = pci_resource_len(dev, resno);
> + u32 sizes;
> +
> + if (!num_vfs)
> + return 0;
> +
> + do_div(vf_len, num_vfs);
Add include for do_div().
> + sizes = (roundup_pow_of_two(vf_len + 1) - 1) >> ilog2(SZ_1M);
Doesn't resource_size() already do that + 1 so why is a second one needed
here?
Add include for ilog() and SZ_*.
> +
> + return sizes & pci_rebar_get_possible_sizes(dev, resno);
> +}
> +EXPORT_SYMBOL_GPL(pci_iov_vf_bar_get_sizes);
> diff --git a/include/linux/pci.h b/include/linux/pci.h
> index 0e8e3fd77e967..c8708f3749757 100644
> --- a/include/linux/pci.h
> +++ b/include/linux/pci.h
> @@ -2389,6 +2389,8 @@ int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 numvfs);
> int pci_sriov_get_totalvfs(struct pci_dev *dev);
> int pci_sriov_configure_simple(struct pci_dev *dev, int nr_virtfn);
> resource_size_t pci_iov_resource_size(struct pci_dev *dev, int resno);
> +int pci_iov_vf_bar_set_size(struct pci_dev *dev, int resno, int size);
> +u32 pci_iov_vf_bar_get_sizes(struct pci_dev *dev, int resno, int num_vfs);
> void pci_vf_drivers_autoprobe(struct pci_dev *dev, bool probe);
>
> /* Arch may override these (weak) */
> @@ -2441,6 +2443,10 @@ static inline int pci_sriov_get_totalvfs(struct pci_dev *dev)
> #define pci_sriov_configure_simple NULL
> static inline resource_size_t pci_iov_resource_size(struct pci_dev *dev, int resno)
> { return 0; }
> +static inline int pci_iov_vf_bar_set_size(struct pci_dev *dev, int resno, int size)
> +{ return -ENODEV; }
> +static inline u32 pci_iov_vf_bar_get_sizes(struct pci_dev *dev, int resno, int num_vfs)
> +{ return 0; }
> static inline void pci_vf_drivers_autoprobe(struct pci_dev *dev, bool probe) { }
> #endif
>
>
--
i.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v7 5/6] PCI: Allow drivers to control VF BAR size
2025-04-03 10:20 ` Ilpo Järvinen
@ 2025-05-26 21:54 ` Michał Winiarski
0 siblings, 0 replies; 12+ messages in thread
From: Michał Winiarski @ 2025-05-26 21:54 UTC (permalink / raw)
To: Ilpo Järvinen
Cc: linux-pci, intel-xe, dri-devel, LKML, Bjorn Helgaas,
Christian König, Krzysztof Wilczyński, Rodrigo Vivi,
Michal Wajdeczko, Lucas De Marchi, Thomas Hellström,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, Matt Roper
On Thu, Apr 03, 2025 at 01:20:58PM +0300, Ilpo Järvinen wrote:
> On Wed, 2 Apr 2025, Michał Winiarski wrote:
>
> > Drivers could leverage the fact that the VF BAR MMIO reservation is
> > created for total number of VFs supported by the device by resizing the
> > BAR to larger size when smaller number of VFs is enabled.
> >
> > Add a pci_iov_vf_bar_set_size() function to control the size and a
> > pci_iov_vf_bar_get_sizes() helper to get the VF BAR sizes that will
> > allow up to num_vfs to be successfully enabled with the current
> > underlying reservation size.
> >
> > Signed-off-by: Michał Winiarski <michal.winiarski@intel.com>
> > ---
> > drivers/pci/iov.c | 69 +++++++++++++++++++++++++++++++++++++++++++++
> > include/linux/pci.h | 6 ++++
> > 2 files changed, 75 insertions(+)
> >
> > diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c
> > index 2fafbd6a998f0..8a62049b56b41 100644
> > --- a/drivers/pci/iov.c
> > +++ b/drivers/pci/iov.c
> > @@ -1313,3 +1313,72 @@ int pci_sriov_configure_simple(struct pci_dev *dev, int nr_virtfn)
> > return nr_virtfn;
> > }
> > EXPORT_SYMBOL_GPL(pci_sriov_configure_simple);
> > +
> > +/**
> > + * pci_iov_vf_bar_set_size - set a new size for a VF BAR
> > + * @dev: the PCI device
> > + * @resno: the resource number
> > + * @size: new size as defined in the spec (0=1MB, 31=128TB)
> > + *
> > + * Set the new size of a VF BAR that supports VF resizable BAR capability.
> > + * Unlike pci_resize_resource(), this does not cause the resource that
> > + * reserves the MMIO space (originally up to total_VFs) to be resized, which
> > + * means that following calls to pci_enable_sriov() can fail if the resources
> > + * no longer fit.
> > + *
> > + * Return: 0 on success, or negative on failure.
> > + */
> > +int pci_iov_vf_bar_set_size(struct pci_dev *dev, int resno, int size)
> > +{
> > + int ret;
> > + u32 sizes;
Hi,
I thought this series was already ready to be merged, but now I just
went back through the review comments for v7 and realized that I missed
this email and never applied the changes you requested.
Sorry for the delay.
> Please reverse the order of these variables.
Ok.
>
> > +
> > + if (!pci_resource_is_iov(resno))
> > + return -EINVAL;
> > +
> > + if (pci_iov_is_memory_decoding_enabled(dev))
> > + return -EBUSY;
> > +
> > + sizes = pci_rebar_get_possible_sizes(dev, resno);
> > + if (!sizes)
> > + return -ENOTSUPP;
> > +
> > + if (!(sizes & BIT(size)))
>
> Add include for BIT().
>
> Although adding a helper like this would be helpful for multiple callers:
>
> @@ -3780,6 +3780,88 @@ u32 pci_rebar_get_possible_sizes(struct pci_dev *pdev, int bar)
> }
> EXPORT_SYMBOL(pci_rebar_get_possible_sizes);
>
> +/**
> + * pci_rebar_size_supported - check if size is supported for a resizable BAR
> + * @pdev: PCI device
> + * @bar: BAR to check
> + * @size: size as defined in the spec (0=1MB, 31=128TB)
> + *
> + * Return: %0 if @size is supported for @bar,
> + * %-EINVAL if @size is not supported,
> + * %-ENOTSUPP if @bar is not resizable.
> + */
> +int pci_rebar_size_supported(struct pci_dev *pdev, int bar, int size)
> +{
> + u64 sizes;
> +
> + sizes = pci_rebar_get_possible_sizes(pdev, bar);
> + if (!sizes)
> + return -ENOTSUPP;
> +
> + return BIT(size) & sizes ? 0 : -EINVAL;
> +}
> +EXPORT_SYMBOL_GPL(pci_rebar_size_supported);
>
> (Yes, I've some rebar helpers pending so this is extract from that.)
Added include for BIT(). I'll wait for your series with helpers :)
>
> > + return -EINVAL;
> > +
> > + ret = pci_rebar_set_size(dev, resno, size);
> > + if (ret)
> > + return ret;
> > +
> > + pci_iov_resource_set_size(dev, resno, pci_rebar_size_to_bytes(size));
> > +
> > + return 0;
> > +}
> > +EXPORT_SYMBOL_GPL(pci_iov_vf_bar_set_size);
> > +
> > +/**
> > + * pci_iov_vf_bar_get_sizes - get VF BAR sizes allowing to create up to num_vfs
> > + * @dev: the PCI device
> > + * @resno: the resource number
> > + * @num_vfs: number of VFs
> > + *
> > + * Get the sizes of a VF resizable BAR that can accommodate @num_vfs within
> > + * the currently assigned size of the resource @resno.
> > + *
> > + * Return: A bitmask of sizes in format defined in the spec (bit 0=1MB,
> > + * bit 31=128TB).
> > + */
> > +u32 pci_iov_vf_bar_get_sizes(struct pci_dev *dev, int resno, int num_vfs)
> > +{
> > + resource_size_t vf_len = pci_resource_len(dev, resno);
> > + u32 sizes;
> > +
> > + if (!num_vfs)
> > + return 0;
> > +
> > + do_div(vf_len, num_vfs);
>
> Add include for do_div().
Ok.
>
> > + sizes = (roundup_pow_of_two(vf_len + 1) - 1) >> ilog2(SZ_1M);
>
> Doesn't resource_size() already do that + 1 so why is a second one needed
> here?
It's not about resource_size() doing + 1 for the resource length, it's
needed because roundup_pow_of_two() is not rounding up to the next power
of two if the input is already a power of two. So we need to add 1 to
ensure that we get the next size up to make the math with bitmap
representing BAR sizes work correctly.
>
> Add include for ilog() and SZ_*.
Ok.
Thanks,
-Michał
>
> > +
> > + return sizes & pci_rebar_get_possible_sizes(dev, resno);
> > +}
> > +EXPORT_SYMBOL_GPL(pci_iov_vf_bar_get_sizes);
> > diff --git a/include/linux/pci.h b/include/linux/pci.h
> > index 0e8e3fd77e967..c8708f3749757 100644
> > --- a/include/linux/pci.h
> > +++ b/include/linux/pci.h
> > @@ -2389,6 +2389,8 @@ int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 numvfs);
> > int pci_sriov_get_totalvfs(struct pci_dev *dev);
> > int pci_sriov_configure_simple(struct pci_dev *dev, int nr_virtfn);
> > resource_size_t pci_iov_resource_size(struct pci_dev *dev, int resno);
> > +int pci_iov_vf_bar_set_size(struct pci_dev *dev, int resno, int size);
> > +u32 pci_iov_vf_bar_get_sizes(struct pci_dev *dev, int resno, int num_vfs);
> > void pci_vf_drivers_autoprobe(struct pci_dev *dev, bool probe);
> >
> > /* Arch may override these (weak) */
> > @@ -2441,6 +2443,10 @@ static inline int pci_sriov_get_totalvfs(struct pci_dev *dev)
> > #define pci_sriov_configure_simple NULL
> > static inline resource_size_t pci_iov_resource_size(struct pci_dev *dev, int resno)
> > { return 0; }
> > +static inline int pci_iov_vf_bar_set_size(struct pci_dev *dev, int resno, int size)
> > +{ return -ENODEV; }
> > +static inline u32 pci_iov_vf_bar_get_sizes(struct pci_dev *dev, int resno, int num_vfs)
> > +{ return 0; }
> > static inline void pci_vf_drivers_autoprobe(struct pci_dev *dev, bool probe) { }
> > #endif
> >
> >
>
> --
> i.
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2025-05-26 21:54 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-02 14:11 [PATCH v7 0/6] PCI: VF resizable BAR Michał Winiarski
2025-04-02 14:11 ` [PATCH v7 1/6] PCI/IOV: Restore VF resizable BAR state after reset Michał Winiarski
2025-04-02 14:11 ` [PATCH v7 2/6] PCI: Add a helper to convert between VF BAR number and IOV resource Michał Winiarski
2025-04-03 9:24 ` Ilpo Järvinen
2025-04-02 14:11 ` [PATCH v7 3/6] PCI: Allow IOV resources to be resized in pci_resize_resource() Michał Winiarski
2025-04-03 9:45 ` Ilpo Järvinen
2025-04-02 14:11 ` [PATCH v7 4/6] PCI/IOV: Check that VF BAR fits within the reservation Michał Winiarski
2025-04-03 9:54 ` Ilpo Järvinen
2025-04-02 14:11 ` [PATCH v7 5/6] PCI: Allow drivers to control VF BAR size Michał Winiarski
2025-04-03 10:20 ` Ilpo Järvinen
2025-05-26 21:54 ` Michał Winiarski
2025-04-02 14:11 ` [PATCH v7 6/6] drm/xe/pf: Set VF LMEM " Michał Winiarski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox