* [RFC PATCH V2] virtio_pci: Add SR-IOV support
@ 2018-02-22 17:52 Mark Rustad
2018-02-22 18:26 ` Christoph Hellwig
2018-02-25 15:20 ` [virtio-dev] " Yan Vugenfirer
0 siblings, 2 replies; 5+ messages in thread
From: Mark Rustad @ 2018-02-22 17:52 UTC (permalink / raw)
To: virtio-dev, netdev, linux-kernel, linux-pci
Cc: dan.daly, alex.williamson, MRustad, alexander.duyck, mst
Hardware-realized virtio-pci devices can implement SR-IOV, so this
patch enables its use. The device in question is an upcoming Intel
NIC that implements both a virtio-net PF and virtio-net VFs. These
are hardware realizations of what has been up to now been a software
interface.
The device in question has the following 4-part PCI IDs:
PF: device: 1af4 vendor: 1041 subvendor: 8086 subdevice: 15fe
VF: device: 1af4 vendor: 1041 subvendor: 8086 subdevice: 05fe
The patch needs no check for device ID, because the callback will
never be made for devices that do not assert the capability or
when run on a platform incapable of SR-IOV.
One reason for this patch is because the hardware requires the
vendor ID of a VF to be the same as the vendor ID of the PF that
created it. So it seemed logical to simply have a fully-functioning
virtio-net PF create the VFs. This patch makes that possible.
Signed-off-by: Mark Rustad <mark.d.rustad@intel.com>
Reviewed-by: Alexander Duyck <alexander.h.duyck@intel.com>
---
Changes in V2:
- Simplified logic from previous version, removed added driver variable
- Disable SR-IOV on driver removal excapt when VFs are assigned
- Sent as RFC to virtio-dev, linux-pci, netdev, lkml and others
---
drivers/virtio/virtio_pci_common.c | 47 ++++++++++++++++++++++++++++++++++++
1 file changed, 47 insertions(+)
diff --git a/drivers/virtio/virtio_pci_common.c b/drivers/virtio/virtio_pci_common.c
index 48d4d1cf1cb6..78b53ffc4cee 100644
--- a/drivers/virtio/virtio_pci_common.c
+++ b/drivers/virtio/virtio_pci_common.c
@@ -572,6 +572,47 @@ static int virtio_pci_probe(struct pci_dev *pci_dev,
return rc;
}
+#ifdef CONFIG_PCI_IOV
+static int virtio_pci_sriov_disable(struct pci_dev *pci_dev)
+{
+ /* If vfs are assigned we cannot shut down SR-IOV without causing
+ * issues, so just leave the hardware available.
+ */
+ if (pci_vfs_assigned(pci_dev)) {
+ dev_warn(&pci_dev->dev,
+ "Unloading driver while VFs are assigned - VFs will not be deallocated\n");
+ return -EPERM;
+ }
+ pci_disable_sriov(pci_dev);
+ return 0;
+}
+
+static int virtio_pci_sriov_enable(struct pci_dev *pci_dev, int num_vfs)
+{
+ int rc = 0;
+
+ if (pci_num_vf(pci_dev))
+ return -EINVAL;
+
+ rc = pci_enable_sriov(pci_dev, num_vfs);
+ if (rc) {
+ dev_warn(&pci_dev->dev, "Failed to enable PCI sriov: %d\n", rc);
+ return rc;
+ }
+ dev_info(&pci_dev->dev, "SR-IOV enabled with %d VFs\n", num_vfs);
+ return num_vfs;
+}
+
+static int virtio_pci_sriov_configure(struct pci_dev *dev, int num_vfs)
+{
+ if (num_vfs)
+ return virtio_pci_sriov_enable(dev, num_vfs);
+ if (!pci_num_vf(dev))
+ return -EINVAL;
+ return virtio_pci_sriov_disable(dev);
+}
+#endif /* CONFIG_PCI_IOV */
+
static void virtio_pci_remove(struct pci_dev *pci_dev)
{
struct virtio_pci_device *vp_dev = pci_get_drvdata(pci_dev);
@@ -584,6 +625,9 @@ static void virtio_pci_remove(struct pci_dev *pci_dev)
else
virtio_pci_modern_remove(vp_dev);
+#ifdef CONFIG_PCI_IOV
+ virtio_pci_sriov_disable(pci_dev);
+#endif
pci_disable_device(pci_dev);
put_device(dev);
}
@@ -596,6 +640,9 @@ static void virtio_pci_remove(struct pci_dev *pci_dev)
#ifdef CONFIG_PM_SLEEP
.driver.pm = &virtio_pci_pm_ops,
#endif
+#ifdef CONFIG_PCI_IOV
+ .sriov_configure = virtio_pci_sriov_configure,
+#endif
};
module_pci_driver(virtio_pci_driver);
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [RFC PATCH V2] virtio_pci: Add SR-IOV support
2018-02-22 17:52 [RFC PATCH V2] virtio_pci: Add SR-IOV support Mark Rustad
@ 2018-02-22 18:26 ` Christoph Hellwig
2018-02-22 22:07 ` Rustad, Mark D
2018-02-25 15:20 ` [virtio-dev] " Yan Vugenfirer
1 sibling, 1 reply; 5+ messages in thread
From: Christoph Hellwig @ 2018-02-22 18:26 UTC (permalink / raw)
To: Mark Rustad
Cc: virtio-dev, netdev, linux-kernel, linux-pci, dan.daly,
alex.williamson, MRustad, alexander.duyck, mst
Can we move this into common code as a a generic_sriov_configure
helper? Nothing is really virtio specific, and it seems like
some other drivers could also use it, e.g. ena or nvme.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [RFC PATCH V2] virtio_pci: Add SR-IOV support
2018-02-22 18:26 ` Christoph Hellwig
@ 2018-02-22 22:07 ` Rustad, Mark D
0 siblings, 0 replies; 5+ messages in thread
From: Rustad, Mark D @ 2018-02-22 22:07 UTC (permalink / raw)
To: Christoph Hellwig
Cc: virtio-dev, netdev, linux-kernel, linux-pci, Daly, Dan,
alex.williamson, MRustad, alexander.duyck, mst
> On Feb 22, 2018, at 10:26 AM, Christoph Hellwig <hch@infradead.org> wrote:
>
> Can we move this into common code as a a generic_sriov_configure
> helper? Nothing is really virtio specific, and it seems like
> some other drivers could also use it, e.g. ena or nvme.
That seems like a good idea to me, especially if PCI developers concur.
--
Mark Rustad, Networking Division, Intel Corporation
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [virtio-dev] [RFC PATCH V2] virtio_pci: Add SR-IOV support
2018-02-22 17:52 [RFC PATCH V2] virtio_pci: Add SR-IOV support Mark Rustad
2018-02-22 18:26 ` Christoph Hellwig
@ 2018-02-25 15:20 ` Yan Vugenfirer
2018-02-25 21:03 ` Mark D Rustad
1 sibling, 1 reply; 5+ messages in thread
From: Yan Vugenfirer @ 2018-02-25 15:20 UTC (permalink / raw)
To: Mark Rustad
Cc: virtio-dev, netdev, linux-kernel, linux-pci, dan.daly,
alex.williamson, MRustad, alexander.duyck, mst
> On 22 Feb 2018, at 19:52, Mark Rustad <mark.d.rustad@intel.com> wrote:
>
> Hardware-realized virtio-pci devices can implement SR-IOV, so this
> patch enables its use. The device in question is an upcoming Intel
> NIC that implements both a virtio-net PF and virtio-net VFs. These
> are hardware realizations of what has been up to now been a software
> interface.
>
> The device in question has the following 4-part PCI IDs:
>
> PF: device: 1af4 vendor: 1041 subvendor: 8086 subdevice: 15fe
> VF: device: 1af4 vendor: 1041 subvendor: 8086 subdevice: 05fe
Small mistake in the commit message. Red Hat (Qumranet) vendor ID is 1af4, virtio-net device ID is 1041.
Should be:
PF: vendor: 1af4 device: 1041 subvendor: 8086 subdevice: 15fe
VF: vendor: 1af4 device: 1041 subvendor: 8086 subdevice: 05fe
Best regards,
Yan.
>
> The patch needs no check for device ID, because the callback will
> never be made for devices that do not assert the capability or
> when run on a platform incapable of SR-IOV.
>
> One reason for this patch is because the hardware requires the
> vendor ID of a VF to be the same as the vendor ID of the PF that
> created it. So it seemed logical to simply have a fully-functioning
> virtio-net PF create the VFs. This patch makes that possible.
>
> Signed-off-by: Mark Rustad <mark.d.rustad@intel.com>
> Reviewed-by: Alexander Duyck <alexander.h.duyck@intel.com>
> ---
> Changes in V2:
> - Simplified logic from previous version, removed added driver variable
> - Disable SR-IOV on driver removal excapt when VFs are assigned
> - Sent as RFC to virtio-dev, linux-pci, netdev, lkml and others
> ---
> drivers/virtio/virtio_pci_common.c | 47 ++++++++++++++++++++++++++++++++++++
> 1 file changed, 47 insertions(+)
>
> diff --git a/drivers/virtio/virtio_pci_common.c b/drivers/virtio/virtio_pci_common.c
> index 48d4d1cf1cb6..78b53ffc4cee 100644
> --- a/drivers/virtio/virtio_pci_common.c
> +++ b/drivers/virtio/virtio_pci_common.c
> @@ -572,6 +572,47 @@ static int virtio_pci_probe(struct pci_dev *pci_dev,
> return rc;
> }
>
> +#ifdef CONFIG_PCI_IOV
> +static int virtio_pci_sriov_disable(struct pci_dev *pci_dev)
> +{
> + /* If vfs are assigned we cannot shut down SR-IOV without causing
> + * issues, so just leave the hardware available.
> + */
> + if (pci_vfs_assigned(pci_dev)) {
> + dev_warn(&pci_dev->dev,
> + "Unloading driver while VFs are assigned - VFs will not be deallocated\n");
> + return -EPERM;
> + }
> + pci_disable_sriov(pci_dev);
> + return 0;
> +}
> +
> +static int virtio_pci_sriov_enable(struct pci_dev *pci_dev, int num_vfs)
> +{
> + int rc = 0;
> +
> + if (pci_num_vf(pci_dev))
> + return -EINVAL;
> +
> + rc = pci_enable_sriov(pci_dev, num_vfs);
> + if (rc) {
> + dev_warn(&pci_dev->dev, "Failed to enable PCI sriov: %d\n", rc);
> + return rc;
> + }
> + dev_info(&pci_dev->dev, "SR-IOV enabled with %d VFs\n", num_vfs);
> + return num_vfs;
> +}
> +
> +static int virtio_pci_sriov_configure(struct pci_dev *dev, int num_vfs)
> +{
> + if (num_vfs)
> + return virtio_pci_sriov_enable(dev, num_vfs);
> + if (!pci_num_vf(dev))
> + return -EINVAL;
> + return virtio_pci_sriov_disable(dev);
> +}
> +#endif /* CONFIG_PCI_IOV */
> +
> static void virtio_pci_remove(struct pci_dev *pci_dev)
> {
> struct virtio_pci_device *vp_dev = pci_get_drvdata(pci_dev);
> @@ -584,6 +625,9 @@ static void virtio_pci_remove(struct pci_dev *pci_dev)
> else
> virtio_pci_modern_remove(vp_dev);
>
> +#ifdef CONFIG_PCI_IOV
> + virtio_pci_sriov_disable(pci_dev);
> +#endif
> pci_disable_device(pci_dev);
> put_device(dev);
> }
> @@ -596,6 +640,9 @@ static void virtio_pci_remove(struct pci_dev *pci_dev)
> #ifdef CONFIG_PM_SLEEP
> .driver.pm = &virtio_pci_pm_ops,
> #endif
> +#ifdef CONFIG_PCI_IOV
> + .sriov_configure = virtio_pci_sriov_configure,
> +#endif
> };
>
> module_pci_driver(virtio_pci_driver);
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: virtio-dev-unsubscribe@lists.oasis-open.org
> For additional commands, e-mail: virtio-dev-help@lists.oasis-open.org
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [virtio-dev] [RFC PATCH V2] virtio_pci: Add SR-IOV support
2018-02-25 15:20 ` [virtio-dev] " Yan Vugenfirer
@ 2018-02-25 21:03 ` Mark D Rustad
0 siblings, 0 replies; 5+ messages in thread
From: Mark D Rustad @ 2018-02-25 21:03 UTC (permalink / raw)
To: Yan Vugenfirer
Cc: Mark Rustad, virtio-dev, netdev, linux-kernel, linux-pci,
dan.daly, alex.williamson, alexander.duyck, mst
[-- Attachment #1: Type: text/plain, Size: 534 bytes --]
> On Feb 25, 2018, at 7:20 AM, Yan Vugenfirer <yvugenfi@redhat.com> wrote:
>
> Small mistake in the commit message. Red Hat (Qumranet) vendor ID is 1af4, virtio-net device ID is 1041.
> Should be:
> PF: vendor: 1af4 device: 1041 subvendor: 8086 subdevice: 15fe
> VF: vendor: 1af4 device: 1041 subvendor: 8086 subdevice: 05fe
You are so right. I will fix it before I send the updated patch that provides the generic helper that Christoph suggested. Thanks for catching my mislabeling.
--
Mark Rustad, MRustad@gmail.com
[-- Attachment #2: Message signed with OpenPGP --]
[-- Type: application/pgp-signature, Size: 873 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2018-02-25 21:03 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-22 17:52 [RFC PATCH V2] virtio_pci: Add SR-IOV support Mark Rustad
2018-02-22 18:26 ` Christoph Hellwig
2018-02-22 22:07 ` Rustad, Mark D
2018-02-25 15:20 ` [virtio-dev] " Yan Vugenfirer
2018-02-25 21:03 ` Mark D Rustad
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).