public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v5 0/6] PCI: VF resizable BAR
@ 2025-03-12 22:59 Michał Winiarski
  2025-03-12 22:59 ` [PATCH v5 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-03-12 22:59 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,

No major logic changes since v4, just a few tweaks to docs, commit
messages and function naming.

v4 can be found here:
https://lore.kernel.org/linux-pci/20241025215038.3125626-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ł

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                 | 155 +++++++++++++++++++++++++++---
 drivers/pci/pci.c                 |  10 +-
 drivers/pci/pci.h                 |  28 ++++++
 drivers/pci/setup-bus.c           |   3 +-
 drivers/pci/setup-res.c           |  35 ++++++-
 include/linux/pci.h               |   6 ++
 include/uapi/linux/pci_regs.h     |   1 +
 9 files changed, 243 insertions(+), 18 deletions(-)

-- 
2.48.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v5 1/6] PCI/IOV: Restore VF resizable BAR state after reset
  2025-03-12 22:59 [PATCH v5 0/6] PCI: VF resizable BAR Michał Winiarski
@ 2025-03-12 22:59 ` Michał Winiarski
  2025-03-13  9:45   ` Ilpo Järvinen
  2025-03-12 22:59 ` [PATCH v5 2/6] PCI: Add a helper to convert between VF BAR number and IOV resource Michał Winiarski
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 12+ messages in thread
From: Michał Winiarski @ 2025-03-12 22:59 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.

Add the capability ID and restore it as a part of IOV state.

See PCIe r4.0, sec 9.3.7.4.

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             | 29 ++++++++++++++++++++++++++++-
 include/uapi/linux/pci_regs.h |  1 +
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c
index 121540f57d4bf..eb4d33eacacb8 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>
@@ -868,6 +869,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 = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_VF_REBAR);
+	if (!pos)
+		return;
+
+	pci_read_config_dword(dev, pos + PCI_REBAR_CTRL, &ctrl);
+	nbars = FIELD_GET(PCI_REBAR_CTRL_NBAR_MASK, ctrl);
+
+	for (i = 0; i < nbars; i++, pos += 8) {
+		int bar_idx, size;
+
+		pci_read_config_dword(dev, pos + PCI_REBAR_CTRL, &ctrl);
+		bar_idx = FIELD_GET(PCI_REBAR_CTRL_BAR_IDX, ctrl);
+		size = pci_rebar_bytes_to_size(dev->sriov->barsz[bar_idx]);
+		ctrl &= ~PCI_REBAR_CTRL_BAR_SIZE;
+		ctrl |= FIELD_PREP(PCI_REBAR_CTRL_BAR_SIZE, size);
+		pci_write_config_dword(dev, pos + PCI_REBAR_CTRL, ctrl);
+	}
+}
+
 static void sriov_restore_state(struct pci_dev *dev)
 {
 	int i;
@@ -1027,8 +1052,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/include/uapi/linux/pci_regs.h b/include/uapi/linux/pci_regs.h
index 3c2558b98d225..aadd483c47d6f 100644
--- a/include/uapi/linux/pci_regs.h
+++ b/include/uapi/linux/pci_regs.h
@@ -744,6 +744,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 */
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v5 2/6] PCI: Add a helper to convert between VF BAR number and IOV resource
  2025-03-12 22:59 [PATCH v5 0/6] PCI: VF resizable BAR Michał Winiarski
  2025-03-12 22:59 ` [PATCH v5 1/6] PCI/IOV: Restore VF resizable BAR state after reset Michał Winiarski
@ 2025-03-12 22:59 ` Michał Winiarski
  2025-03-12 22:59 ` [PATCH v5 3/6] PCI: Allow IOV resources to be resized in pci_resize_resource() Michał Winiarski
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 12+ messages in thread
From: Michał Winiarski @ 2025-03-12 22:59 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>
---
 drivers/pci/iov.c       | 22 ++++++++++++----------
 drivers/pci/pci.h       | 19 +++++++++++++++++++
 drivers/pci/setup-bus.c |  3 ++-
 3 files changed, 33 insertions(+), 11 deletions(-)

diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c
index eb4d33eacacb8..23c741e9ede89 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)
@@ -322,12 +322,13 @@ 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];
+		res = &dev->resource[pci_resource_num_from_vf_bar(i)];
 		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,
+					     pci_resource_num_from_vf_bar(i));
 		resource_set_range(&virtfn->resource[i],
 				   res->start + size * id, size);
 		rc = request_resource(res, &virtfn->resource[i]);
@@ -624,8 +625,8 @@ 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];
+		bars |= (1 << pci_resource_num_from_vf_bar(i));
+		res = &dev->resource[pci_resource_num_from_vf_bar(i)];
 		if (res->parent)
 			nres++;
 	}
@@ -791,8 +792,9 @@ 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);
+		res = &dev->resource[pci_resource_num_from_vf_bar(i)];
+		res_name = pci_resource_name(dev,
+					     pci_resource_num_from_vf_bar(i));
 
 		/*
 		 * If it is already FIXED, don't change it, something
@@ -850,7 +852,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;
 	}
 
@@ -912,7 +914,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);
@@ -978,7 +980,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 4e2ac06db3c47..e3cd9b8f9b734 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -659,6 +659,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
@@ -683,6 +692,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 58f28e4e24b31..384d53be3a5e7 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];
+		struct resource *r =
+			&dev->resource[pci_resource_num_from_vf_bar(i)];
 		struct pci_bus_region region;
 
 		/* Not assigned or rejected by kernel? */
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v5 3/6] PCI: Allow IOV resources to be resized in pci_resize_resource()
  2025-03-12 22:59 [PATCH v5 0/6] PCI: VF resizable BAR Michał Winiarski
  2025-03-12 22:59 ` [PATCH v5 1/6] PCI/IOV: Restore VF resizable BAR state after reset Michał Winiarski
  2025-03-12 22:59 ` [PATCH v5 2/6] PCI: Add a helper to convert between VF BAR number and IOV resource Michał Winiarski
@ 2025-03-12 22:59 ` Michał Winiarski
  2025-03-13  9:56   ` Ilpo Järvinen
  2025-03-12 22:59 ` [PATCH v5 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-03-12 22:59 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 structures are very similar, which means we can reuse most of the
implementation.

Extend the pci_resize_resource() function to accept IOV resources.

See PCIe r4.0, sec 9.3.7.4.

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 23c741e9ede89..7cc17e898cea7 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 72ac91e359aaf..e6a986ad24d61 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -3731,8 +3731,16 @@ static int pci_rebar_find_pos(struct pci_dev *pdev, int bar)
 {
 	unsigned int pos, nbars, i;
 	u32 ctrl;
+	int cap;
 
-	pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_REBAR);
+	if (pci_resource_is_iov(bar)) {
+		cap = PCI_EXT_CAP_ID_VF_REBAR;
+		bar = pci_resource_num_to_vf_bar(bar);
+	} else {
+		cap = PCI_EXT_CAP_ID_REBAR;
+	}
+
+	pos = pci_find_ext_capability(pdev, cap);
 	if (!pos)
 		return -ENOTSUPP;
 
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index e3cd9b8f9b734..af41f6c24451f 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -655,6 +655,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;
@@ -688,6 +691,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..6cce3e19f22b0 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 = dev->resource + 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.48.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v5 4/6] PCI/IOV: Check that VF BAR fits within the reservation
  2025-03-12 22:59 [PATCH v5 0/6] PCI: VF resizable BAR Michał Winiarski
                   ` (2 preceding siblings ...)
  2025-03-12 22:59 ` [PATCH v5 3/6] PCI: Allow IOV resources to be resized in pci_resize_resource() Michał Winiarski
@ 2025-03-12 22:59 ` Michał Winiarski
  2025-03-12 22:59 ` [PATCH v5 5/6] PCI: Allow drivers to control VF BAR size Michał Winiarski
  2025-03-12 22:59 ` [PATCH v5 6/6] drm/xe/pf: Set VF LMEM " Michał Winiarski
  5 siblings, 0 replies; 12+ messages in thread
From: Michał Winiarski @ 2025-03-12 22:59 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 it's not possible to accommodate all VFs - the resource is not
assigned and no VFs can be created.

The following patch 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 | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c
index 7cc17e898cea7..d6d63083884e6 100644
--- a/drivers/pci/iov.c
+++ b/drivers/pci/iov.c
@@ -646,8 +646,13 @@ static int sriov_enable(struct pci_dev *dev, int nr_virtfn)
 
 	nres = 0;
 	for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) {
+		resource_size_t vf_bar_sz =
+			pci_iov_resource_size(dev,
+					      pci_resource_num_from_vf_bar(i));
 		bars |= (1 << pci_resource_num_from_vf_bar(i));
 		res = &dev->resource[pci_resource_num_from_vf_bar(i)];
+		if (vf_bar_sz * nr_virtfn > resource_size(res))
+			continue;
 		if (res->parent)
 			nres++;
 	}
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v5 5/6] PCI: Allow drivers to control VF BAR size
  2025-03-12 22:59 [PATCH v5 0/6] PCI: VF resizable BAR Michał Winiarski
                   ` (3 preceding siblings ...)
  2025-03-12 22:59 ` [PATCH v5 4/6] PCI/IOV: Check that VF BAR fits within the reservation Michał Winiarski
@ 2025-03-12 22:59 ` Michał Winiarski
  2025-03-12 22:59 ` [PATCH v5 6/6] drm/xe/pf: Set VF LMEM " Michał Winiarski
  5 siblings, 0 replies; 12+ messages in thread
From: Michał Winiarski @ 2025-03-12 22:59 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   | 78 +++++++++++++++++++++++++++++++++++++++++++++
 include/linux/pci.h |  6 ++++
 2 files changed, 84 insertions(+)

diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c
index d6d63083884e6..76846df2a26d8 100644
--- a/drivers/pci/iov.c
+++ b/drivers/pci/iov.c
@@ -1290,3 +1290,81 @@ 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.
+ *
+ * Returns 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 be accommodated within the
+ * resource that reserves the MMIO space if num_vfs are enabled.
+ *
+ * Returns 0 if BAR isn't resizable, otherwise returns a bitmask 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 size;
+	u32 sizes;
+	int i;
+
+	sizes = pci_rebar_get_possible_sizes(dev, resno);
+	if (!sizes)
+		return 0;
+
+	while (sizes > 0) {
+		i = __fls(sizes);
+		size = pci_rebar_size_to_bytes(i);
+
+		if (size * num_vfs <= pci_resource_len(dev, resno))
+			break;
+
+		sizes &= ~BIT(i);
+	}
+
+	return sizes;
+}
+EXPORT_SYMBOL_GPL(pci_iov_vf_bar_get_sizes);
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 7192b9d78d7e3..76de900c652f8 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -2393,6 +2393,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) */
@@ -2445,6 +2447,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.48.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v5 6/6] drm/xe/pf: Set VF LMEM BAR size
  2025-03-12 22:59 [PATCH v5 0/6] PCI: VF resizable BAR Michał Winiarski
                   ` (4 preceding siblings ...)
  2025-03-12 22:59 ` [PATCH v5 5/6] PCI: Allow drivers to control VF BAR size Michał Winiarski
@ 2025-03-12 22:59 ` Michał Winiarski
  5 siblings, 0 replies; 12+ messages in thread
From: Michał Winiarski @ 2025-03-12 22:59 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 set the largest possible BAR size that allows to fit the number
of enabled VFs.

Signed-off-by: Michał Winiarski <michal.winiarski@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 aaceee748287e..57cdeb41ef1d9 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"
@@ -62,6 +66,18 @@ static void pf_reset_vfs(struct xe_device *xe, unsigned int num_vfs)
 			xe_gt_sriov_pf_control_trigger_flr(gt, n);
 }
 
+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);
@@ -88,6 +104,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.48.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH v5 1/6] PCI/IOV: Restore VF resizable BAR state after reset
  2025-03-12 22:59 ` [PATCH v5 1/6] PCI/IOV: Restore VF resizable BAR state after reset Michał Winiarski
@ 2025-03-13  9:45   ` Ilpo Järvinen
  2025-03-13  9:50     ` Ilpo Järvinen
  0 siblings, 1 reply; 12+ messages in thread
From: Ilpo Järvinen @ 2025-03-13  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: 3155 bytes --]

On Wed, 12 Mar 2025, Michał Winiarski wrote:

> Similar to regular resizable BAR, VF BAR can also be resized, e.g. by
> the system firmware or the PCI subsystem itself.
> 
> Add the capability ID and restore it as a part of IOV state.
> 
> See PCIe r4.0, sec 9.3.7.4.
> 
> 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             | 29 ++++++++++++++++++++++++++++-
>  include/uapi/linux/pci_regs.h |  1 +
>  2 files changed, 29 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c
> index 121540f57d4bf..eb4d33eacacb8 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>
> @@ -868,6 +869,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 = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_VF_REBAR);
> +	if (!pos)
> +		return;

FYI, the commit f7c9bb759161 ("PCI: Cache offset of Resizable BAR 
capability") which is currently in pci/enumeration makes this simpler.

> +	pci_read_config_dword(dev, pos + PCI_REBAR_CTRL, &ctrl);
> +	nbars = FIELD_GET(PCI_REBAR_CTRL_NBAR_MASK, ctrl);
> +
> +	for (i = 0; i < nbars; i++, pos += 8) {
> +		int bar_idx, size;
> +
> +		pci_read_config_dword(dev, pos + PCI_REBAR_CTRL, &ctrl);
> +		bar_idx = FIELD_GET(PCI_REBAR_CTRL_BAR_IDX, ctrl);
> +		size = pci_rebar_bytes_to_size(dev->sriov->barsz[bar_idx]);
> +		ctrl &= ~PCI_REBAR_CTRL_BAR_SIZE;
> +		ctrl |= FIELD_PREP(PCI_REBAR_CTRL_BAR_SIZE, size);
> +		pci_write_config_dword(dev, pos + PCI_REBAR_CTRL, ctrl);
> +	}
> +}
> +
>  static void sriov_restore_state(struct pci_dev *dev)
>  {
>  	int i;
> @@ -1027,8 +1052,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/include/uapi/linux/pci_regs.h b/include/uapi/linux/pci_regs.h
> index 3c2558b98d225..aadd483c47d6f 100644
> --- a/include/uapi/linux/pci_regs.h
> +++ b/include/uapi/linux/pci_regs.h
> @@ -744,6 +744,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 */
> 

-- 
 i.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v5 1/6] PCI/IOV: Restore VF resizable BAR state after reset
  2025-03-13  9:45   ` Ilpo Järvinen
@ 2025-03-13  9:50     ` Ilpo Järvinen
  2025-03-17 11:21       ` Michał Winiarski
  0 siblings, 1 reply; 12+ messages in thread
From: Ilpo Järvinen @ 2025-03-13  9:50 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: 3587 bytes --]

On Thu, 13 Mar 2025, Ilpo Järvinen wrote:

> On Wed, 12 Mar 2025, Michał Winiarski wrote:
> 
> > Similar to regular resizable BAR, VF BAR can also be resized, e.g. by
> > the system firmware or the PCI subsystem itself.
> > 
> > Add the capability ID and restore it as a part of IOV state.
> > 
> > See PCIe r4.0, sec 9.3.7.4.
> > 
> > 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             | 29 ++++++++++++++++++++++++++++-
> >  include/uapi/linux/pci_regs.h |  1 +
> >  2 files changed, 29 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c
> > index 121540f57d4bf..eb4d33eacacb8 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>
> > @@ -868,6 +869,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 = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_VF_REBAR);
> > +	if (!pos)
> > +		return;
> 
> FYI, the commit f7c9bb759161 ("PCI: Cache offset of Resizable BAR 
> capability") which is currently in pci/enumeration makes this simpler.

I'm sorry, I realized it's not the same capability but you should do 
similar thing for VF rebar capability as caching the value of 
pci_find_ext_capability() avoids some slowness during save/restore.

-- 
 i.

> > +	pci_read_config_dword(dev, pos + PCI_REBAR_CTRL, &ctrl);
> > +	nbars = FIELD_GET(PCI_REBAR_CTRL_NBAR_MASK, ctrl);
> > +
> > +	for (i = 0; i < nbars; i++, pos += 8) {
> > +		int bar_idx, size;
> > +
> > +		pci_read_config_dword(dev, pos + PCI_REBAR_CTRL, &ctrl);
> > +		bar_idx = FIELD_GET(PCI_REBAR_CTRL_BAR_IDX, ctrl);
> > +		size = pci_rebar_bytes_to_size(dev->sriov->barsz[bar_idx]);
> > +		ctrl &= ~PCI_REBAR_CTRL_BAR_SIZE;
> > +		ctrl |= FIELD_PREP(PCI_REBAR_CTRL_BAR_SIZE, size);
> > +		pci_write_config_dword(dev, pos + PCI_REBAR_CTRL, ctrl);
> > +	}
> > +}
> > +
> >  static void sriov_restore_state(struct pci_dev *dev)
> >  {
> >  	int i;
> > @@ -1027,8 +1052,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/include/uapi/linux/pci_regs.h b/include/uapi/linux/pci_regs.h
> > index 3c2558b98d225..aadd483c47d6f 100644
> > --- a/include/uapi/linux/pci_regs.h
> > +++ b/include/uapi/linux/pci_regs.h
> > @@ -744,6 +744,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 */
> > 
> 
> 

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v5 3/6] PCI: Allow IOV resources to be resized in pci_resize_resource()
  2025-03-12 22:59 ` [PATCH v5 3/6] PCI: Allow IOV resources to be resized in pci_resize_resource() Michał Winiarski
@ 2025-03-13  9:56   ` Ilpo Järvinen
  2025-03-17 11:30     ` Michał Winiarski
  0 siblings, 1 reply; 12+ messages in thread
From: Ilpo Järvinen @ 2025-03-13  9:56 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: 6104 bytes --]

On Wed, 12 Mar 2025, Michał Winiarski wrote:

> Similar to regular resizable BAR, VF BAR can also be resized.
> 
> The structures are very similar, which means we can reuse most of the
> implementation.
> 
> Extend the pci_resize_resource() function to accept IOV resources.
> 
> See PCIe r4.0, sec 9.3.7.4.
> 
> 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 23c741e9ede89..7cc17e898cea7 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 72ac91e359aaf..e6a986ad24d61 100644
> --- a/drivers/pci/pci.c
> +++ b/drivers/pci/pci.c
> @@ -3731,8 +3731,16 @@ static int pci_rebar_find_pos(struct pci_dev *pdev, int bar)
>  {
>  	unsigned int pos, nbars, i;
>  	u32 ctrl;
> +	int cap;
>  
> -	pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_REBAR);
> +	if (pci_resource_is_iov(bar)) {
> +		cap = PCI_EXT_CAP_ID_VF_REBAR;
> +		bar = pci_resource_num_to_vf_bar(bar);
> +	} else {
> +		cap = PCI_EXT_CAP_ID_REBAR;
> +	}

Use the cached values here.

> +
> +	pos = pci_find_ext_capability(pdev, cap);
>  	if (!pos)
>  		return -ENOTSUPP;
>  
> diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
> index e3cd9b8f9b734..af41f6c24451f 100644
> --- a/drivers/pci/pci.h
> +++ b/drivers/pci/pci.h
> @@ -655,6 +655,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;
> @@ -688,6 +691,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..6cce3e19f22b0 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 = dev->resource + resno;

pci_resource_n()

> +
> +	if (!pci_resource_is_iov(resno)) {
> +		resource_set_size(res, res_size);
> +	} else {
> +		resource_set_size(res, res_size * pci_sriov_get_totalvfs(dev));

Should this too be done in pci_iov_resource_set_size()? Why is it being 
done here?

> +		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);
> 

-- 
 i.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v5 1/6] PCI/IOV: Restore VF resizable BAR state after reset
  2025-03-13  9:50     ` Ilpo Järvinen
@ 2025-03-17 11:21       ` Michał Winiarski
  0 siblings, 0 replies; 12+ messages in thread
From: Michał Winiarski @ 2025-03-17 11:21 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, Mar 13, 2025 at 11:50:37AM +0200, Ilpo Järvinen wrote:
> On Thu, 13 Mar 2025, Ilpo Järvinen wrote:
> 
> > On Wed, 12 Mar 2025, Michał Winiarski wrote:
> > 
> > > Similar to regular resizable BAR, VF BAR can also be resized, e.g. by
> > > the system firmware or the PCI subsystem itself.
> > > 
> > > Add the capability ID and restore it as a part of IOV state.
> > > 
> > > See PCIe r4.0, sec 9.3.7.4.
> > > 
> > > 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             | 29 ++++++++++++++++++++++++++++-
> > >  include/uapi/linux/pci_regs.h |  1 +
> > >  2 files changed, 29 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c
> > > index 121540f57d4bf..eb4d33eacacb8 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>
> > > @@ -868,6 +869,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 = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_VF_REBAR);
> > > +	if (!pos)
> > > +		return;
> > 
> > FYI, the commit f7c9bb759161 ("PCI: Cache offset of Resizable BAR 
> > capability") which is currently in pci/enumeration makes this simpler.
> 
> I'm sorry, I realized it's not the same capability but you should do 
> similar thing for VF rebar capability as caching the value of 
> pci_find_ext_capability() avoids some slowness during save/restore.

The series was based on pci/resource due to other dependencies.
But yeah - point taken, I'll use caching in next revision.

Thanks,
-Michał

> 
> -- 
>  i.
> 
> > > +	pci_read_config_dword(dev, pos + PCI_REBAR_CTRL, &ctrl);
> > > +	nbars = FIELD_GET(PCI_REBAR_CTRL_NBAR_MASK, ctrl);
> > > +
> > > +	for (i = 0; i < nbars; i++, pos += 8) {
> > > +		int bar_idx, size;
> > > +
> > > +		pci_read_config_dword(dev, pos + PCI_REBAR_CTRL, &ctrl);
> > > +		bar_idx = FIELD_GET(PCI_REBAR_CTRL_BAR_IDX, ctrl);
> > > +		size = pci_rebar_bytes_to_size(dev->sriov->barsz[bar_idx]);
> > > +		ctrl &= ~PCI_REBAR_CTRL_BAR_SIZE;
> > > +		ctrl |= FIELD_PREP(PCI_REBAR_CTRL_BAR_SIZE, size);
> > > +		pci_write_config_dword(dev, pos + PCI_REBAR_CTRL, ctrl);
> > > +	}
> > > +}
> > > +
> > >  static void sriov_restore_state(struct pci_dev *dev)
> > >  {
> > >  	int i;
> > > @@ -1027,8 +1052,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/include/uapi/linux/pci_regs.h b/include/uapi/linux/pci_regs.h
> > > index 3c2558b98d225..aadd483c47d6f 100644
> > > --- a/include/uapi/linux/pci_regs.h
> > > +++ b/include/uapi/linux/pci_regs.h
> > > @@ -744,6 +744,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 */
> > > 
> > 
> > 


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v5 3/6] PCI: Allow IOV resources to be resized in pci_resize_resource()
  2025-03-13  9:56   ` Ilpo Järvinen
@ 2025-03-17 11:30     ` Michał Winiarski
  0 siblings, 0 replies; 12+ messages in thread
From: Michał Winiarski @ 2025-03-17 11:30 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, Mar 13, 2025 at 11:56:07AM +0200, Ilpo Järvinen wrote:
> On Wed, 12 Mar 2025, Michał Winiarski wrote:
> 
> > Similar to regular resizable BAR, VF BAR can also be resized.
> > 
> > The structures are very similar, which means we can reuse most of the
> > implementation.
> > 
> > Extend the pci_resize_resource() function to accept IOV resources.
> > 
> > See PCIe r4.0, sec 9.3.7.4.
> > 
> > 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 23c741e9ede89..7cc17e898cea7 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 72ac91e359aaf..e6a986ad24d61 100644
> > --- a/drivers/pci/pci.c
> > +++ b/drivers/pci/pci.c
> > @@ -3731,8 +3731,16 @@ static int pci_rebar_find_pos(struct pci_dev *pdev, int bar)
> >  {
> >  	unsigned int pos, nbars, i;
> >  	u32 ctrl;
> > +	int cap;
> >  
> > -	pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_REBAR);
> > +	if (pci_resource_is_iov(bar)) {
> > +		cap = PCI_EXT_CAP_ID_VF_REBAR;
> > +		bar = pci_resource_num_to_vf_bar(bar);
> > +	} else {
> > +		cap = PCI_EXT_CAP_ID_REBAR;
> > +	}
> 
> Use the cached values here.

Ok.

> 
> > +
> > +	pos = pci_find_ext_capability(pdev, cap);
> >  	if (!pos)
> >  		return -ENOTSUPP;
> >  
> > diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
> > index e3cd9b8f9b734..af41f6c24451f 100644
> > --- a/drivers/pci/pci.h
> > +++ b/drivers/pci/pci.h
> > @@ -655,6 +655,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;
> > @@ -688,6 +691,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..6cce3e19f22b0 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 = dev->resource + resno;
> 
> pci_resource_n()

Ok.

> 
> > +
> > +	if (!pci_resource_is_iov(resno)) {
> > +		resource_set_size(res, res_size);
> > +	} else {
> > +		resource_set_size(res, res_size * pci_sriov_get_totalvfs(dev));
> 
> Should this too be done in pci_iov_resource_set_size()? Why is it being 
> done here?

pci_iov_resource_set_size is all about individual VF BAR size, not
the reservation (which at this point in always sized as BAR size
multipled by total VFs).
In patch 5/6 the helper comes handy during resize of the individual VF
BAR size independent of the original MMIO reservation.

Thanks,
-Michał

> 
> > +		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);
> > 
> 
> -- 
>  i.


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2025-03-17 11:31 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-12 22:59 [PATCH v5 0/6] PCI: VF resizable BAR Michał Winiarski
2025-03-12 22:59 ` [PATCH v5 1/6] PCI/IOV: Restore VF resizable BAR state after reset Michał Winiarski
2025-03-13  9:45   ` Ilpo Järvinen
2025-03-13  9:50     ` Ilpo Järvinen
2025-03-17 11:21       ` Michał Winiarski
2025-03-12 22:59 ` [PATCH v5 2/6] PCI: Add a helper to convert between VF BAR number and IOV resource Michał Winiarski
2025-03-12 22:59 ` [PATCH v5 3/6] PCI: Allow IOV resources to be resized in pci_resize_resource() Michał Winiarski
2025-03-13  9:56   ` Ilpo Järvinen
2025-03-17 11:30     ` Michał Winiarski
2025-03-12 22:59 ` [PATCH v5 4/6] PCI/IOV: Check that VF BAR fits within the reservation Michał Winiarski
2025-03-12 22:59 ` [PATCH v5 5/6] PCI: Allow drivers to control VF BAR size Michał Winiarski
2025-03-12 22:59 ` [PATCH v5 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