Skip to contentSkip to conversation

virtio_pci: use common helper to configure SR-IOV

PATCH In review Max Gurtovoy 5 participants 9 messages Sep 28, 2022 – Oct 12, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 virtio_pci: use common helper to configure SR-IOV

This is instead of re-writing the same logic in virtio driver.

---
 drivers/virtio/virtio_pci_common.c | 15 +--------------
 1 file changed, 1 insertion(+), 14 deletions(-)
drivers/virtio/virtio_pci_common.c +1 -14
index ad258a9d3b9f..67d3970e57f2 100644
@@ -607,7 +607,6 @@ static int virtio_pci_sriov_configure(struct pci_dev *pci_dev, int num_vfs)
 {
 	struct virtio_pci_device *vp_dev = pci_get_drvdata(pci_dev);
 	struct virtio_device *vdev = &vp_dev->vdev;
-	int ret;
 
 	if (!(vdev->config->get_status(vdev) & VIRTIO_CONFIG_S_DRIVER_OK))
 		return -EBUSY;
@@ -615,19 +614,7 @@ static int virtio_pci_sriov_configure(struct pci_dev *pci_dev, int num_vfs)
 	if (!__virtio_test_bit(vdev, VIRTIO_F_SR_IOV))
 		return -EINVAL;
 
-	if (pci_vfs_assigned(pci_dev))
-		return -EPERM;
-
-	if (num_vfs == 0) {
-		pci_disable_sriov(pci_dev);
-		return 0;
-	}
-
-	ret = pci_enable_sriov(pci_dev, num_vfs);
-	if (ret < 0)
-		return ret;
-
-	return num_vfs;
+	return pci_sriov_configure_simple(pci_dev, num_vfs);
 }
 
 static struct pci_driver virtio_pci_driver = {
Signature · 1 line
2.18.1
Acked-by on v1 1/1
#2 lore raw
In reply to Max Gurtovoy
Quoted 4 lines · Max Gurtovoy

This is instead of re-writing the same logic in virtio driver.

Quoted 38 lines
---
 drivers/virtio/virtio_pci_common.c | 15 +--------------
 1 file changed, 1 insertion(+), 14 deletions(-)
drivers/virtio/virtio_pci_common.c +1 -15
index ad258a9d3b9f..67d3970e57f2 100644
@@ -607,7 +607,6 @@ static int virtio_pci_sriov_configure(struct pci_dev *pci_dev, int num_vfs)
 {
        struct virtio_pci_device *vp_dev = pci_get_drvdata(pci_dev);
        struct virtio_device *vdev = &vp_dev->vdev;
-       int ret;
 
        if (!(vdev->config->get_status(vdev) & VIRTIO_CONFIG_S_DRIVER_OK))
                return -EBUSY;
@@ -615,19 +614,7 @@ static int virtio_pci_sriov_configure(struct pci_dev *pci_dev, int num_vfs)
        if (!__virtio_test_bit(vdev, VIRTIO_F_SR_IOV))
                return -EINVAL;
 
-       if (pci_vfs_assigned(pci_dev))
-               return -EPERM;
-
-       if (num_vfs == 0) {
-               pci_disable_sriov(pci_dev);
-               return 0;
-       }
-
-       ret = pci_enable_sriov(pci_dev, num_vfs);
-       if (ret < 0)
-               return ret;
-
-       return num_vfs;
+       return pci_sriov_configure_simple(pci_dev, num_vfs);
 }
 
 static struct pci_driver virtio_pci_driver = {
--
Quoted 2 lines

2.18.1

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#3 lore raw
In reply to Max Gurtovoy
Quoted 3 lines · Max Gurtovoy

This is instead of re-writing the same logic in virtio driver.

Dropped this as it caused build failures:

https://lore.kernel.org/r/202210080424.gSmuYfb0-lkp%40intel.com

Quoted 39 lines
---
 drivers/virtio/virtio_pci_common.c | 15 +--------------
 1 file changed, 1 insertion(+), 14 deletions(-)
drivers/virtio/virtio_pci_common.c +1 -14
index ad258a9d3b9f..67d3970e57f2 100644
@@ -607,7 +607,6 @@ static int virtio_pci_sriov_configure(struct pci_dev *pci_dev, int num_vfs)
 {
 	struct virtio_pci_device *vp_dev = pci_get_drvdata(pci_dev);
 	struct virtio_device *vdev = &vp_dev->vdev;
-	int ret;
 
 	if (!(vdev->config->get_status(vdev) & VIRTIO_CONFIG_S_DRIVER_OK))
 		return -EBUSY;
@@ -615,19 +614,7 @@ static int virtio_pci_sriov_configure(struct pci_dev *pci_dev, int num_vfs)
 	if (!__virtio_test_bit(vdev, VIRTIO_F_SR_IOV))
 		return -EINVAL;
 
-	if (pci_vfs_assigned(pci_dev))
-		return -EPERM;
-
-	if (num_vfs == 0) {
-		pci_disable_sriov(pci_dev);
-		return 0;
-	}
-
-	ret = pci_enable_sriov(pci_dev, num_vfs);
-	if (ret < 0)
-		return ret;
-
-	return num_vfs;
+	return pci_sriov_configure_simple(pci_dev, num_vfs);
 }
 
 static struct pci_driver virtio_pci_driver = {
Signature · 1 line
2.18.1
#4 lore raw
Quoted 7 lines · Michael S. Tsirkin
Quoted 3 lines · Max Gurtovoy

This is instead of re-writing the same logic in virtio driver.

Dropped this as it caused build failures:

https://lore.kernel.org/r/202210080424.gSmuYfb0-lkp%40intel.com

maybe you can re-run it with:

drivers/virtio/Makefile +0 -0
index 8e98d24917cc..b383326a20e2 100644
@@ -5,10 +5,11 @@ obj-$(CONFIG_VIRTIO_PCI_LIB) += virtio_pci_modern_dev.o

 obj-$(CONFIG_VIRTIO_PCI_LIB_LEGACY) += virtio_pci_legacy_dev.o obj-$(CONFIG_VIRTIO_MMIO) += virtio_mmio.o obj-$(CONFIG_VIRTIO_PCI) += virtio_pci.o
-virtio_pci-y := virtio_pci_modern.o virtio_pci_common.o -virtio_pci-$(CONFIG_VIRTIO_PCI_LEGACY) += virtio_pci_legacy.o obj-$(CONFIG_VIRTIO_BALLOON) += virtio_balloon.o obj-$(CONFIG_VIRTIO_INPUT) += virtio_input.o obj-$(CONFIG_VIRTIO_VDPA) += virtio_vdpa.o obj-$(CONFIG_VIRTIO_MEM) += virtio_mem.o obj-$(CONFIG_VIRTIO_DMA_SHARED_BUFFER) += virtio_dma_buf.o
+
+virtio_pci-$(CONFIG_VIRTIO_PCI) := virtio_pci_modern.o virtio_pci_common.o +virtio_pci-$(CONFIG_VIRTIO_PCI_LEGACY) += virtio_pci_legacy.o

Quoted 40 lines
Quoted 40 lines
---
  drivers/virtio/virtio_pci_common.c | 15 +--------------
  1 file changed, 1 insertion(+), 14 deletions(-)
drivers/virtio/virtio_pci_common.c +1 -14
index ad258a9d3b9f..67d3970e57f2 100644
@@ -607,7 +607,6 @@ static int virtio_pci_sriov_configure(struct pci_dev *pci_dev, int num_vfs)
  {
  	struct virtio_pci_device *vp_dev = pci_get_drvdata(pci_dev);
  	struct virtio_device *vdev = &vp_dev->vdev;
-	int ret;
 
  	if (!(vdev->config->get_status(vdev) & VIRTIO_CONFIG_S_DRIVER_OK))
  		return -EBUSY;
@@ -615,19 +614,7 @@ static int virtio_pci_sriov_configure(struct pci_dev *pci_dev, int num_vfs)
  	if (!__virtio_test_bit(vdev, VIRTIO_F_SR_IOV))
  		return -EINVAL;
 
-	if (pci_vfs_assigned(pci_dev))
-		return -EPERM;
-
-	if (num_vfs == 0) {
-		pci_disable_sriov(pci_dev);
-		return 0;
-	}
-
-	ret = pci_enable_sriov(pci_dev, num_vfs);
-	if (ret < 0)
-		return ret;
-
-	return num_vfs;
+	return pci_sriov_configure_simple(pci_dev, num_vfs);
  }
 
  static struct pci_driver virtio_pci_driver = {
Signature · 1 line
2.18.1
#5 lore raw
Quoted 29 lines · Max Gurtovoy
Quoted 7 lines · Michael S. Tsirkin
Quoted 3 lines · Max Gurtovoy

This is instead of re-writing the same logic in virtio driver.

Dropped this as it caused build failures:

https://lore.kernel.org/r/202210080424.gSmuYfb0-lkp%40intel.com

maybe you can re-run it with:

drivers/virtio/Makefile +0 -0
index 8e98d24917cc..b383326a20e2 100644
@@ -5,10 +5,11 @@ obj-$(CONFIG_VIRTIO_PCI_LIB) += virtio_pci_modern_dev.o

 obj-$(CONFIG_VIRTIO_PCI_LIB_LEGACY) += virtio_pci_legacy_dev.o obj-$(CONFIG_VIRTIO_MMIO) += virtio_mmio.o obj-$(CONFIG_VIRTIO_PCI) += virtio_pci.o

drivers/virtio/Makefile +0 -2
-virtio_pci-y := virtio_pci_modern.o virtio_pci_common.o
-virtio_pci-$(CONFIG_VIRTIO_PCI_LEGACY) += virtio_pci_legacy.o

 obj-$(CONFIG_VIRTIO_BALLOON) += virtio_balloon.o obj-$(CONFIG_VIRTIO_INPUT) += virtio_input.o obj-$(CONFIG_VIRTIO_VDPA) += virtio_vdpa.o obj-$(CONFIG_VIRTIO_MEM) += virtio_mem.o obj-$(CONFIG_VIRTIO_DMA_SHARED_BUFFER) += virtio_dma_buf.o

drivers/virtio/Makefile +2 -0
+
+virtio_pci-$(CONFIG_VIRTIO_PCI) := virtio_pci_modern.o 
Quoted 3 lines

virtio_pci_common.o +virtio_pci-$(CONFIG_VIRTIO_PCI_LEGACY) += virtio_pci_legacy.o

Now I saw that CONFIG_PCI_IOV is not set in the error log so the bellow should fix it:

include/linux/pci.h +0 -0
index 060af91bafcd..c519220e8ff8 100644
@@ -2228,7 +2228,10 @@ static inline int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 numvfs)

 { return 0; }
 static inline int pci_sriov_get_totalvfs(struct pci_dev *dev)
 { return 0; }
-#define pci_sriov_configure_simple     NULL
+static inline int pci_sriov_configure_simple(struct pci_dev *dev, int nr_virtfn) +{
+       return -ENOSYS;
+}
 static inline resource_size_t pci_iov_resource_size(struct pci_dev *dev, int resno) { return 0; }
 static inline void pci_vf_drivers_autoprobe(struct pci_dev *dev, bool probe) { }

Bjorn,

WDYT about the above ?

should I send it to the pci subsystem list ?

Quoted 40 lines
Quoted 40 lines
Quoted 40 lines

---
  drivers/virtio/virtio_pci_common.c | 15 +--------------

  1 file changed, 1 insertion(+), 14 deletions(-)
drivers/virtio/virtio_pci_common.c +1 -13
index ad258a9d3b9f..67d3970e57f2 100644
@@ -607,7 +607,6 @@ static int virtio_pci_sriov_configure(struct 
 pci_dev *pci_dev, int num_vfs)
   {
       struct virtio_pci_device *vp_dev = pci_get_drvdata(pci_dev);
       struct virtio_device *vdev = &vp_dev->vdev;
-    int ret;
         if (!(vdev->config->get_status(vdev) & VIRTIO_CONFIG_S_DRIVER_OK))
           return -EBUSY;
@@ -615,19 +614,7 @@ static int virtio_pci_sriov_configure(struct 
 pci_dev *pci_dev, int num_vfs)
       if (!__virtio_test_bit(vdev, VIRTIO_F_SR_IOV))
           return -EINVAL;
   -    if (pci_vfs_assigned(pci_dev))
-        return -EPERM;
-
-    if (num_vfs == 0) {
-        pci_disable_sriov(pci_dev);
-        return 0;
-    }
-
-    ret = pci_enable_sriov(pci_dev, num_vfs);
-    if (ret < 0)
-        return ret;
-
-    return num_vfs;
+    return pci_sriov_configure_simple(pci_dev, num_vfs);
   }
     static struct pci_driver virtio_pci_driver = {
Signature · 1 line
2.18.1
maintainer
#6 lore raw
Quoted 60 lines · Max Gurtovoy
Quoted 29 lines · Max Gurtovoy
Quoted 7 lines · Michael S. Tsirkin
Quoted 3 lines · Max Gurtovoy

This is instead of re-writing the same logic in virtio driver.

Dropped this as it caused build failures:

https://lore.kernel.org/r/202210080424.gSmuYfb0-lkp%40intel.com

maybe you can re-run it with:

drivers/virtio/Makefile +2 -2
index 8e98d24917cc..b383326a20e2 100644
@@ -5,10 +5,11 @@ obj-$(CONFIG_VIRTIO_PCI_LIB) += virtio_pci_modern_dev.o
 obj-$(CONFIG_VIRTIO_PCI_LIB_LEGACY) += virtio_pci_legacy_dev.o
 obj-$(CONFIG_VIRTIO_MMIO) += virtio_mmio.o
 obj-$(CONFIG_VIRTIO_PCI) += virtio_pci.o
-virtio_pci-y := virtio_pci_modern.o virtio_pci_common.o
-virtio_pci-$(CONFIG_VIRTIO_PCI_LEGACY) += virtio_pci_legacy.o
 obj-$(CONFIG_VIRTIO_BALLOON) += virtio_balloon.o
 obj-$(CONFIG_VIRTIO_INPUT) += virtio_input.o
 obj-$(CONFIG_VIRTIO_VDPA) += virtio_vdpa.o
 obj-$(CONFIG_VIRTIO_MEM) += virtio_mem.o
 obj-$(CONFIG_VIRTIO_DMA_SHARED_BUFFER) += virtio_dma_buf.o
+
+virtio_pci-$(CONFIG_VIRTIO_PCI) := virtio_pci_modern.o
Quoted 3 lines

virtio_pci_common.o +virtio_pci-$(CONFIG_VIRTIO_PCI_LEGACY) += virtio_pci_legacy.o

Now I saw that CONFIG_PCI_IOV is not set in the error log so the bellow should fix it:

include/linux/pci.h +4 -1
index 060af91bafcd..c519220e8ff8 100644
@@ -2228,7 +2228,10 @@ static inline int pci_sriov_set_totalvfs(struct
 pci_dev *dev, u16 numvfs)
  { return 0; }
  static inline int pci_sriov_get_totalvfs(struct pci_dev *dev)
  { return 0; }
-#define pci_sriov_configure_simple     NULL
+static inline int pci_sriov_configure_simple(struct pci_dev *dev, int
 nr_virtfn)
+{
+       return -ENOSYS;
+}
  static inline resource_size_t pci_iov_resource_size(struct pci_dev

*dev, int resno)
{ return 0; }
static inline void pci_vf_drivers_autoprobe(struct pci_dev *dev, bool
probe) { }

Quoted 5 lines

Bjorn,

WDYT about the above ?

should I send it to the pci subsystem list ?

Yes. I don't apply things that haven't appeared on [email protected].
_______________________________________________
Virtualization mailing list [email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#7 lore raw
Quoted 57 lines · Bjorn Helgaas
Quoted 56 lines · Max Gurtovoy
Quoted 27 lines · Max Gurtovoy
Quoted 7 lines · Michael S. Tsirkin
Quoted 3 lines · Max Gurtovoy

This is instead of re-writing the same logic in virtio driver.

Dropped this as it caused build failures:

https://lore.kernel.org/r/202210080424.gSmuYfb0-lkp%40intel.com

maybe you can re-run it with:

drivers/virtio/Makefile +2 -2
index 8e98d24917cc..b383326a20e2 100644
@@ -5,10 +5,11 @@ obj-$(CONFIG_VIRTIO_PCI_LIB) += virtio_pci_modern_dev.o
  obj-$(CONFIG_VIRTIO_PCI_LIB_LEGACY) += virtio_pci_legacy_dev.o
  obj-$(CONFIG_VIRTIO_MMIO) += virtio_mmio.o
  obj-$(CONFIG_VIRTIO_PCI) += virtio_pci.o
-virtio_pci-y := virtio_pci_modern.o virtio_pci_common.o
-virtio_pci-$(CONFIG_VIRTIO_PCI_LEGACY) += virtio_pci_legacy.o
  obj-$(CONFIG_VIRTIO_BALLOON) += virtio_balloon.o
  obj-$(CONFIG_VIRTIO_INPUT) += virtio_input.o
  obj-$(CONFIG_VIRTIO_VDPA) += virtio_vdpa.o
  obj-$(CONFIG_VIRTIO_MEM) += virtio_mem.o
  obj-$(CONFIG_VIRTIO_DMA_SHARED_BUFFER) += virtio_dma_buf.o
+
+virtio_pci-$(CONFIG_VIRTIO_PCI) := virtio_pci_modern.o
Quoted 3 lines

virtio_pci_common.o +virtio_pci-$(CONFIG_VIRTIO_PCI_LEGACY) += virtio_pci_legacy.o

Now I saw that CONFIG_PCI_IOV is not set in the error log so the bellow should fix it:

include/linux/pci.h +4 -1
index 060af91bafcd..c519220e8ff8 100644
@@ -2228,7 +2228,10 @@ static inline int pci_sriov_set_totalvfs(struct
 pci_dev *dev, u16 numvfs)
   { return 0; }
   static inline int pci_sriov_get_totalvfs(struct pci_dev *dev)
   { return 0; }
-#define pci_sriov_configure_simple     NULL
+static inline int pci_sriov_configure_simple(struct pci_dev *dev, int
 nr_virtfn)
+{
+       return -ENOSYS;
+}
   static inline resource_size_t pci_iov_resource_size(struct pci_dev

*dev, int resno)
{ return 0; }
static inline void pci_vf_drivers_autoprobe(struct pci_dev *dev, bool
probe) { }

Quoted 6 lines
Quoted 5 lines

Bjorn,

WDYT about the above ?

should I send it to the pci subsystem list ?

Yes. I don't apply things that haven't appeared on [email protected].

Sure.

MST,

can you confirm the above fixes the build errors before I sent the v2 ?

#8 lore raw
Quoted 63 lines · Max Gurtovoy
Quoted 61 lines · Bjorn Helgaas
Quoted 60 lines · Max Gurtovoy
Quoted 27 lines · Max Gurtovoy
Quoted 7 lines · Michael S. Tsirkin
Quoted 3 lines · Max Gurtovoy

This is instead of re-writing the same logic in virtio driver.

Dropped this as it caused build failures:

https://lore.kernel.org/r/202210080424.gSmuYfb0-lkp%40intel.com

maybe you can re-run it with:

drivers/virtio/Makefile +2 -2
index 8e98d24917cc..b383326a20e2 100644
@@ -5,10 +5,11 @@ obj-$(CONFIG_VIRTIO_PCI_LIB) += virtio_pci_modern_dev.o
  obj-$(CONFIG_VIRTIO_PCI_LIB_LEGACY) += virtio_pci_legacy_dev.o
  obj-$(CONFIG_VIRTIO_MMIO) += virtio_mmio.o
  obj-$(CONFIG_VIRTIO_PCI) += virtio_pci.o
-virtio_pci-y := virtio_pci_modern.o virtio_pci_common.o
-virtio_pci-$(CONFIG_VIRTIO_PCI_LEGACY) += virtio_pci_legacy.o
  obj-$(CONFIG_VIRTIO_BALLOON) += virtio_balloon.o
  obj-$(CONFIG_VIRTIO_INPUT) += virtio_input.o
  obj-$(CONFIG_VIRTIO_VDPA) += virtio_vdpa.o
  obj-$(CONFIG_VIRTIO_MEM) += virtio_mem.o
  obj-$(CONFIG_VIRTIO_DMA_SHARED_BUFFER) += virtio_dma_buf.o
+
+virtio_pci-$(CONFIG_VIRTIO_PCI) := virtio_pci_modern.o
Quoted 3 lines

virtio_pci_common.o +virtio_pci-$(CONFIG_VIRTIO_PCI_LEGACY) += virtio_pci_legacy.o

Now I saw that CONFIG_PCI_IOV is not set in the error log so the bellow should fix it:

include/linux/pci.h +4 -1
index 060af91bafcd..c519220e8ff8 100644
@@ -2228,7 +2228,10 @@ static inline int pci_sriov_set_totalvfs(struct
 pci_dev *dev, u16 numvfs)
   { return 0; }
   static inline int pci_sriov_get_totalvfs(struct pci_dev *dev)
   { return 0; }
-#define pci_sriov_configure_simple     NULL
+static inline int pci_sriov_configure_simple(struct pci_dev *dev, int
 nr_virtfn)
+{
+       return -ENOSYS;
+}
   static inline resource_size_t pci_iov_resource_size(struct pci_dev

*dev, int resno)
{ return 0; }
static inline void pci_vf_drivers_autoprobe(struct pci_dev *dev, bool
probe) { }

Bjorn,

WDYT about the above ?

Quoted 8 lines
Quoted 2 lines
Quoted 1 line

should I send it to the pci subsystem list ?

Yes. I don't apply things that haven't appeared on [email protected].

Sure.

MST,

can you confirm the above fixes the build errors before I sent the v2 ?

Max, please just use the lkp test, it's not hard.

Signature · 1 line
MST