Virtio-over-PCIe on non-MIC
Subsystems (3)
cover Virtio-over-PCIe on non-MIC
The Virtio-over-PCIe framework living under drivers/misc/mic/vop implements a generic framework to use virtio between two Linux systems, given shared memory and a couple of interrupts. It does not actually require the Intel MIC hardware, x86-64, or even PCIe for that matter. This patch series makes it buildable on more systems and adds a loopback driver to test it without special hardware.
Note that I don't have access to Intel MIC hardware so some testing of the patchset (especially the patch "vop: Use consistent DMA") on that platform would be appreciated, to ensure that the series does not break anything there.
Vincent Whitchurch (8):
vop: Use %z for size_t
vop: Cast pointers to uintptr_t
vop: Add definition of readq/writeq if missing
vop: Allow building on more systems
vop: vringh: Do not crash if no DMA channel
vop: Fix handling of >32 feature bits
vop: Use consistent DMA
vop: Add loopback
drivers/misc/mic/Kconfig | 14 +- drivers/misc/mic/bus/vop_bus.h | 2 + drivers/misc/mic/host/mic_boot.c | 46 ++++ drivers/misc/mic/vop/Makefile | 2 + drivers/misc/mic/vop/vop_loopback.c | 390 ++++++++++++++++++++++++++++ drivers/misc/mic/vop/vop_main.c | 36 +-- drivers/misc/mic/vop/vop_vringh.c | 151 ++++++----- 7 files changed, 549 insertions(+), 92 deletions(-) create mode 100644 drivers/misc/mic/vop/vop_loopback.c
Signature · 1 line
2.20.0
PATCH 1/8 vop: Use %z for size_t
Fixes these kind of errors on 32-bit:
drivers/misc/mic/vop/vop_vringh.c:590:3:
error: format '%lx' expects argument of type 'long unsigned int', but argument 7 has type 'size_t {aka unsigned int}' [-Werror=format=]
--- drivers/misc/mic/vop/vop_vringh.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/misc/mic/vop/vop_vringh.c +2 -2
@@ -587,7 +587,7 @@ static int vop_virtio_copy_to_user(struct vop_vdev *vdev, void __user *ubuf, err: vpdev->hw_ops->iounmap (vpdev, dbuf);dev_dbg (vop_dev (vdev), -"%s: ubuf %p dbuf %p len 0x%lx vr_idx 0x%x\n" , +"%s: ubuf %p dbuf %p len 0x%zx vr_idx 0x%x\n" , __func__, ubuf, dbuf, len, vr_idx);return err; }
@@ -670,7 +670,7 @@ static int vop_virtio_copy_from_user(struct vop_vdev *vdev, void __user *ubuf, err: vpdev->hw_ops->iounmap (vpdev, dbuf);dev_dbg (vop_dev (vdev), -"%s: ubuf %p dbuf %p len 0x%lx vr_idx 0x%x\n" , +"%s: ubuf %p dbuf %p len 0x%zx vr_idx 0x%x\n" , __func__, ubuf, dbuf, len, vr_idx);return err; }
Signature · 1 line
2.20.0
PATCH 2/8 vop: Cast pointers to uintptr_t
In reply to Vincent WhitchurchFix these on 32-bit:
vop_vringh.c:711:13: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast]
--- drivers/misc/mic/vop/vop_main.c | 8 ++++---- drivers/misc/mic/vop/vop_vringh.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-)
drivers/misc/mic/vop/vop_main.c +4 -4
@@ -497,7 +497,7 @@ static int _vop_add_device(struct mic_device_desc __iomem *d, vdev->desc = d; vdev->dc = (void __iomem *)d +_vop_aligned_desc_size (d); vdev->dnode = dnode; - vdev->vdev.priv = (void *)(u64 )dnode; + vdev->vdev.priv = (void *)(uintptr_t )dnode;init_completion (&vdev->reset_done); vdev->h2c_vdev_db = vpdev->hw_ops->next_db (vpdev);
@@ -519,7 +519,7 @@ static int _vop_add_device(struct mic_device_desc __iomem *d, offset, type); goto free_irq; } -writeq ((u64 )vdev, &vdev->dc->vdev); +writeq ((uintptr_t )vdev, &vdev->dc->vdev);dev_dbg (_vop_dev (vdev),"%s: registered vop device %u type %u vdev %p\n" , __func__, offset, type, vdev);
@@ -552,7 +552,7 @@ static void _vop_handle_config_change(struct mic_device_desc __iomem *d, {struct mic_device_ctrl __iomem *dc = (void __iomem *)d +_vop_aligned_desc_size (d); -struct _vop_vdev *vdev = (struct _vop_vdev *)readq (&dc->vdev); +struct _vop_vdev *vdev = (struct _vop_vdev *)(uintptr_t )readq (&dc->vdev);if (ioread8 (&dc->config_change) !=MIC_VIRTIO_PARAM_CONFIG_CHANGED )return ;
@@ -571,7 +571,7 @@ static int _vop_remove_device(struct mic_device_desc __iomem *d, {struct mic_device_ctrl __iomem *dc = (void __iomem *)d +_vop_aligned_desc_size (d); -struct _vop_vdev *vdev = (struct _vop_vdev *)readq (&dc->vdev); +struct _vop_vdev *vdev = (struct _vop_vdev *)(uintptr_t )readq (&dc->vdev);u8 status;int ret =-1 ;
drivers/misc/mic/vop/vop_vringh.c +2 -2
@@ -708,12 +708,12 @@ static int vop_vringh_copy(struct vop_vdev *vdev, struct vringh_kiov *iov, partlen =min (kiov->iov_len, len);if (read) ret =vop_virtio_copy_to_user (vdev, ubuf, partlen, - (u64 )kiov->iov_base, + (uintptr_t )kiov->iov_base, kiov->iov_len, vr_idx);else ret =vop_virtio_copy_from_user (vdev, ubuf, partlen, - (u64 )kiov->iov_base, + (uintptr_t )kiov->iov_base, kiov->iov_len, vr_idx);if (ret) {
Signature · 1 line
2.20.0
Re: [PATCH 2/8] vop: Cast pointers to uintptr_t
Quoted 4 lines · Vincent Whitchurch
Fix these on 32-bit:
vop_vringh.c:711:13: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast]
[]
drivers/misc/mic/vop/vop_main.c
Quoted 1 line
drivers/misc/mic/vop/vop_main.c +0
-0
[]
drivers/misc/mic/vop/vop_main.c static int _vop_add_device(struct mic_device_desc __iomem *d, · line 500
Quoted 6 lines
drivers/misc/mic/vop/vop_main.c +1
-1@@ -497,7 +497,7 @@ static int _vop_add_device(struct mic_device_desc __iomem *d, vdev->desc = d; vdev->dc = (void __iomem *)d +_vop_aligned_desc_size (d); vdev->dnode = dnode; - vdev->vdev.priv = (void *)(u64 )dnode; + vdev->vdev.priv = (void *)(uintptr_t )dnode;
trivia:
unsigned long is more commonly used in the kernel for these casts.
Greg KH
maintainerRe: [PATCH 2/8] vop: Cast pointers to uintptr_t
In reply to Vincent WhitchurchQuoted 16 lines · Vincent Whitchurch
Fix these on 32-bit:
vop_vringh.c:711:13: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast]
Signed-off-by Vincent Whitchurch <[email protected]>--- drivers/misc/mic/vop/vop_main.c | 8 ++++---- drivers/misc/mic/vop/vop_vringh.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-)drivers/misc/mic/vop/vop_main.c +0
-0
drivers/misc/mic/vop/vop_main.c static int _vop_add_device(struct mic_device_desc __iomem *d, · line 500
Quoted 5 lines
drivers/misc/mic/vop/vop_main.c +1
-1@@ -497,7 +497,7 @@ static int _vop_add_device(struct mic_device_desc __iomem *d, vdev->desc = d; vdev->dc = (void __iomem *)d +_vop_aligned_desc_size (d); vdev->dnode = dnode; - vdev->vdev.priv = (void *)(u64 )dnode; + vdev->vdev.priv = (void *)(uintptr_t )dnode;
As Joe said, use "unsigned long". uintptr_t is a userspace type, not a kernel type.
thanks,
greg k-h
PATCH 3/8 vop: Add definition of readq/writeq if missing
In reply to Vincent WhitchurchInclude <linux/io-64-nonatomic-lo-hi.h> so that readq/writeq are replaced by two readl/writel on systems that do not support them. The values read/written are pointers which will be 32-bit on 32-bit systems so the non-atomicity should not matter.
--- drivers/misc/mic/vop/vop_main.c | 1 + 1 file changed, 1 insertion(+)
drivers/misc/mic/vop/vop_main.c +1 -0
@@ -34,6 +34,7 @@#include <linux/module.h> #include <linux/sched.h> #include <linux/dma-mapping.h> +#include <linux/io-64-nonatomic-lo-hi.h> #include "vop_main.h"
Signature · 1 line
2.20.0
PATCH 4/8 vop: Allow building on more systems
In reply to Vincent WhitchurchVOP_BUS does not actually depend on 32-bit X86 or PCI. The code uses archdata.dma_ops so it can be built on ARM too.
--- drivers/misc/mic/Kconfig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/misc/mic/Kconfig +2 -2
@@ -38,7 +38,7 @@ comment "VOP Bus Driver" config VOP_BUS tristate "VOP Bus Driver" - depends on 64BIT && PCI && X86 && X86_DEV_DMA_OPS + depends on ARM || (X86 && X86_DEV_DMA_OPS) help This option is selected by any driver which registers a device or driver on the VOP Bus, such as CONFIG_INTEL_MIC_HOST
@@ -132,7 +132,7 @@ comment "VOP Driver" config VOP tristate "VOP Driver" - depends on 64BIT && PCI && X86 && VOP_BUS + depends on VOP_BUS select VHOST_RING select VIRTIO help
Signature · 1 line
2.20.0
PATCH 5/8 vop: vringh: Do not crash if no DMA channel
In reply to Vincent WhitchurchFallback gracefully if no DMA channel is provided instead of dereferencing NULL pointers.
--- drivers/misc/mic/vop/vop_vringh.c | 32 +++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-)
drivers/misc/mic/vop/vop_vringh.c +20 -12
@@ -531,12 +531,12 @@ static int vop_virtio_copy_to_user(struct vop_vdev *vdev, void __user *ubuf,void __iomem *dbuf = vpdev->hw_ops->ioremap (vpdev, daddr, len);struct vop_vringh *vvr = &vdev->vvr[vr_idx];struct vop_info *vi =dev_get_drvdata (&vpdev->dev); -size_t dma_alignment =1 << vi->dma_ch->device->copy_align; -bool x200 =is_dma_copy_aligned (vi->dma_ch->device,1 ,1 ,1 ); +size_t dma_alignment; +bool x200;size_t dma_offset, partlen;int err; -if (!VOP_USE_DMA ) { +if (!VOP_USE_DMA || !vi->dma_ch) {if (copy_to_user (ubuf, (void __force *)dbuf, len)) { err = -EFAULT ; dev_err(vop_dev(vdev), "%s %d err %d\n",
@@ -548,6 +548,9 @@ static int vop_virtio_copy_to_user(struct vop_vdev *vdev, void __user *ubuf, goto err; } + dma_alignment =1 << vi->dma_ch->device->copy_align; + x200 =is_dma_copy_aligned (vi->dma_ch->device,1 ,1 ,1 ); + dma_offset = daddr -round_down (daddr, dma_alignment); daddr -= dma_offset; len += dma_offset;
@@ -606,18 +609,23 @@ static int vop_virtio_copy_from_user(struct vop_vdev *vdev, void __user *ubuf,void __iomem *dbuf = vpdev->hw_ops->ioremap (vpdev, daddr, len);struct vop_vringh *vvr = &vdev->vvr[vr_idx];struct vop_info *vi =dev_get_drvdata (&vdev->vpdev->dev); -size_t dma_alignment =1 << vi->dma_ch->device->copy_align; -bool x200 =is_dma_copy_aligned (vi->dma_ch->device,1 ,1 ,1 ); +size_t dma_alignment; +bool x200;size_t partlen; -bool dma =VOP_USE_DMA ; +bool dma =VOP_USE_DMA && vi->dma_ch;int err =0 ; -if (daddr & (dma_alignment -1 )) { - vdev->tx_dst_unaligned += len; - dma = false; - }else if (ALIGN (len, dma_alignment) > dlen) { - vdev->tx_len_unaligned += len; - dma = false; +if (dma) { + dma_alignment =1 << vi->dma_ch->device->copy_align; + x200 =is_dma_copy_aligned (vi->dma_ch->device,1 ,1 ,1 ); + +if (daddr & (dma_alignment -1 )) { + vdev->tx_dst_unaligned += len; + dma = false; + }else if (ALIGN (len, dma_alignment) > dlen) { + vdev->tx_len_unaligned += len; + dma = false; + } }if (!dma)
Signature · 1 line
2.20.0
PATCH 6/8 vop: Fix handling of >32 feature bits
In reply to Vincent WhitchurchThis is needed, for example, for VIRTIO_F_IOMMU_PLATFORM.
--- drivers/misc/mic/vop/vop_main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/misc/mic/vop/vop_main.c +2 -2
@@ -117,7 +117,7 @@ _vop_total_desc_size(struct mic_device_desc __iomem *desc)static u64 vop_get_features (struct virtio_device *vdev) {unsigned int i, bits; -u32 features =0 ; +u64 features =0 ;struct mic_device_desc __iomem *desc =to_vopvdev (vdev)->desc;u8 __iomem *in_features =_vop_vq_features (desc);int feature_len =ioread8 (&desc->feature_len);
@@ -125,7 +125,7 @@ static u64 vop_get_features(struct virtio_device *vdev) bits =min_t (unsigned, feature_len,sizeof (vdev->features)) *8 ;for (i =0 ; i < bits; i++)if (ioread8 (&in_features[i /8 ]) & (BIT (i %8 ))) - features |=BIT (i); + features |=BIT_ULL (i);return features; }
Signature · 1 line
2.20.0
PATCH 7/8 vop: Use consistent DMA
In reply to Vincent WhitchurchThe vop code maps buffers using the streaming DMA API but never syncs them so it doesn't work on systems without cache coherence. The vrings want consistent mappings, and not streaming mappings so use that API to allocate and map buffers.
--- drivers/misc/mic/bus/vop_bus.h | 2 + drivers/misc/mic/host/mic_boot.c | 46 +++++++++++++ drivers/misc/mic/vop/vop_main.c | 23 ++----- drivers/misc/mic/vop/vop_vringh.c | 111 ++++++++++++++++-------------- 4 files changed, 114 insertions(+), 68 deletions(-)
drivers/misc/mic/bus/vop_bus.h +2 -0
@@ -86,6 +86,7 @@ struct vop_driver {* node to add/remove/configure virtio devices. * @get_dp: Get access to the virtio device page used by the self * node to add/remove/configure virtio devices. +* @get_dp_dma: Get DMA address of the virtio device page. * @send_intr: Send an interrupt to the peer node on a specified doorbell. * @ioremap: Map a buffer with the specified DMA address and length. * @iounmap: Unmap a buffer previously mapped.
@@ -103,6 +104,7 @@ struct vop_hw_ops {void (*ack_interrupt)(struct vop_device *vpdev,int num);void __iomem * (*get_remote_dp)(struct vop_device *vpdev);void * (*get_dp)(struct vop_device *vpdev); +dma_addr_t (*get_dp_dma)(struct vop_device *vpdev);void (*send_intr)(struct vop_device *vpdev,int db);void __iomem * (*ioremap)(struct vop_device *vpdev,dma_addr_t pa,size_t len);
drivers/misc/mic/host/mic_boot.c +46 -0
67 lines not on this page · raw message
drivers/misc/mic/vop/vop_main.c +6 -17
@@ -264,9 +264,8 @@ static void vop_del_vq(struct virtqueue *vq, int n)struct vring *vr = (struct vring *)(vq +1 );struct vop_device *vpdev = vdev->vpdev; -dma_unmap_single (&vpdev->dev, vdev->used[n], - vdev->used_size[n],DMA_BIDIRECTIONAL ); -free_pages ((unsigned long )vr->used,get_order (vdev->used_size[n])); +dma_free_wc (&vpdev->dev, vdev->used_size[n], vr->used, vdev->used[n]); +vring_del_virtqueue (vq); vpdev->hw_ops->iounmap (vpdev, vdev->vr[n]); vdev->vr[n] =NULL ;
@@ -346,23 +345,16 @@ static struct virtqueue *vop_find_vq(struct virtio_device *dev, vdev->used_size[index] =PAGE_ALIGN (sizeof (__u16) *3 +sizeof (struct vring_used_elem ) *le16_to_cpu (config.num)); - used = (void *)__get_free_pages (GFP_KERNEL | __GFP_ZERO, -get_order (vdev->used_size[index])); + used =dma_alloc_wc (&vpdev->dev, vdev->used_size[index], + &vdev->used[index],GFP_KERNEL | __GFP_ZERO); +if (!used) { err = -ENOMEM ;dev_err (_vop_dev (vdev),"%s %d err %d\n" , __func__, __LINE__, err); goto del_vq; } - vdev->used[index] =dma_map_single (&vpdev->dev, used, - vdev->used_size[index], -DMA_BIDIRECTIONAL ); -if (dma_mapping_error (&vpdev->dev, vdev->used[index])) { - err = -ENOMEM ; -dev_err (_vop_dev (vdev),"%s %d err %d\n" , - __func__, __LINE__, err); - goto free_used; - } +writeq (vdev->used[index], &vqconfig->used_address);/* * To reassign the used ring here we are directly accessing
@@ -376,9 +368,6 @@ static struct virtqueue *vop_find_vq(struct virtio_device *dev, vq->priv = vdev;return vq; -free_used: -free_pages ((unsigned long )used, -get_order (vdev->used_size[index])); del_vq:vring_del_virtqueue (vq); unmap:
drivers/misc/mic/vop/vop_vringh.c +60 -51
169 lines not on this page · raw message
Signature · 1 line
2.20.0
PATCH 8/8 vop: Add loopback
In reply to Vincent WhitchurchAdd a loopback driver to allow testing and evaluation of the VOP framework without special hardware. The host and the guest will run under the same kernel.
--- drivers/misc/mic/Kconfig | 10 + drivers/misc/mic/vop/Makefile | 2 + drivers/misc/mic/vop/vop_loopback.c | 390 ++++++++++++++++++++++++++++ 3 files changed, 402 insertions(+) create mode 100644 drivers/misc/mic/vop/vop_loopback.c
drivers/misc/mic/Kconfig +10 -0
@@ -149,6 +149,16 @@ config VOP OS and tools for MIC to use with this driver are available from <http://software.intel.com/en-us/mic-developer>. +config VOP_LOOPBACK + tristate "VOP loopback driver" + depends on VOP + help + This enables a loopback driver to test and evaluate the VOP + infrastructure without actual PCIe hardware. The host and the guest + sides run under the same kernel. + + If unsure, say N. + if VOP source "drivers/vhost/Kconfig.vringh" endif
drivers/misc/mic/vop/Makefile +2 -0
@@ -7,3 +7,5 @@ obj-m := vop.o vop-objs += vop_main.o vop-objs += vop_debugfs.o vop-objs += vop_vringh.o + +obj-$(CONFIG_VOP_LOOPBACK) += vop_loopback.o
drivers/misc/mic/vop/vop_loopback.c new file +390 -0
390 lines not on this page · raw message
Signature · 1 line
2.20.0
Arnd Bergmann
maintainerQuoted 11 lines · Vincent Whitchurch
The Virtio-over-PCIe framework living under
drivers/misc/mic/vopimplements a generic framework to use virtio between two Linux systems, given shared memory and a couple of interrupts. It does not actually require the Intel MIC hardware, x86-64, or even PCIe for that matter. This patch series makes it buildable on more systems and adds a loopback driver to test it without special hardware.Note that I don't have access to Intel MIC hardware so some testing of the patchset (especially the patch "vop: Use consistent DMA") on that platform would be appreciated, to ensure that the series does not break anything there.
Hi Vincent,
First of all, I think it is a very good idea to make virtio over PCIe avaialable more generally. Your patches also make sense here, they mostly fix portability bugs, so no objection there.
I think we need to take a step back though and discuss what combinations we actually do want to support. I have not actually read the whole mic/vop driver, so I don't know if this would be a good fit as a generic interface -- it may or may not be, and any other input would be helpful.
Aside from that, I should note that we have two related subsystems in the kernel: the PCIe endpoint subsystem maintained by Kishon and Lorenzo, and the NTB subsystem maintained by Jon, Dave and Allen.
In order to properly support virtio over PCIe, I would hope we can come up with a user space interface that looks the same way for configuring virtio drivers in mic, pcie-endpoint and ntb, if at all possible. Have you looked at those two subsystems?
Arnd
Quoted 8 lines · Arnd Bergmann
Quoted 7 lines · Vincent Whitchurch
The Virtio-over-PCIe framework living under
drivers/misc/mic/vopimplements a generic framework to use virtio between two Linux systems, given shared memory and a couple of interrupts. It does not actually require the Intel MIC hardware, x86-64, or even PCIe for that matter. This patch series makes it buildable on more systems and adds a loopback driver to test it without special hardware.
Quoted 8 lines
Quoted 3 lines
Note that I don't have access to Intel MIC hardware so some testing of the patchset (especially the patch "vop: Use consistent DMA") on that platform would be appreciated, to ensure that the series does not break anything there.
I think we need to take a step back though and discuss what combinations we actually do want to support. I have not actually read the whole mic/vop driver, so I don't know if this would be a good fit as a generic interface -- it may or may not be, and any other input would be helpful.
The MIC driver as a whole is uninteresting as a generic interface since it is quite tied to the Intel hardware. The VOP parts though are logically separated and have no relation to that hardware, even if the ioctls are called MIC_VIRTIO_*.
The samples/mic/mpssd/mpssd.c code handles both the boot of the MIC (sysfs) and the VOP parts (ioctls).
Quoted 8 lines
Aside from that, I should note that we have two related subsystems in the kernel: the PCIe endpoint subsystem maintained by Kishon and Lorenzo, and the NTB subsystem maintained by Jon, Dave and Allen.
In order to properly support virtio over PCIe, I would hope we can come up with a user space interface that looks the same way for configuring virtio drivers in mic, pcie-endpoint and ntb, if at all possible. Have you looked at those two subsystems?
pcie-endpoint is a generic framework that allows Linux to act as an endpoint and set up the BARs, etc. mic appears to have Intel MIC-specific code for this (pre-dating pcie-endpoint) but this is separate from the vop code. pcie-endpoint and vop do not have overlapping functionality and can be used together.
I'm not familiar with NTB, but from a quick look it seems to be tied to special hardware, and I don't see any virtio-related code there. A vop backend for NTB-backend would presumably work to allow virtio functionality there.
Arnd Bergmann
maintainerQuoted 19 lines · Vincent Whitchurch
Quoted 8 lines · Arnd Bergmann
Quoted 7 lines · Vincent Whitchurch
The Virtio-over-PCIe framework living under
drivers/misc/mic/vopimplements a generic framework to use virtio between two Linux systems, given shared memory and a couple of interrupts. It does not actually require the Intel MIC hardware, x86-64, or even PCIe for that matter. This patch series makes it buildable on more systems and adds a loopback driver to test it without special hardware.Quoted 8 lines
Quoted 3 lines
Note that I don't have access to Intel MIC hardware so some testing of the patchset (especially the patch "vop: Use consistent DMA") on that platform would be appreciated, to ensure that the series does not break anything there.
I think we need to take a step back though and discuss what combinations we actually do want to support. I have not actually read the whole mic/vop driver, so I don't know if this would be a good fit as a generic interface -- it may or may not be, and any other input would be helpful.
Quoted 7 lines
The MIC driver as a whole is uninteresting as a generic interface since it is quite tied to the Intel hardware. The VOP parts though are logically separated and have no relation to that hardware, even if the ioctls are called MIC_VIRTIO_*.
The
samples/mic/mpssd/mpssd.ccode handles both the boot of the MIC (sysfs) and the VOP parts (ioctls).
Right, I wasn't talking about the MIC driver here, just the VOP stuff. Since that comes with an ioctl interface that you want to keep using on other hardware, this still means we have to review if it is a good fit as a general-purpose API.
Quoted 9 lines
Quoted 8 lines
Aside from that, I should note that we have two related subsystems in the kernel: the PCIe endpoint subsystem maintained by Kishon and Lorenzo, and the NTB subsystem maintained by Jon, Dave and Allen.
In order to properly support virtio over PCIe, I would hope we can come up with a user space interface that looks the same way for configuring virtio drivers in mic, pcie-endpoint and ntb, if at all possible. Have you looked at those two subsystems?
Quoted 5 lines
pcie-endpoint is a generic framework that allows Linux to act as an endpoint and set up the BARs, etc. mic appears to have Intel MIC-specific code for this (pre-dating pcie-endpoint) but this is separate from the vop code. pcie-endpoint and vop do not have overlapping functionality and can be used together.
What we need to find out though is whether the combination of vop with pcie-endpoint provides a good abstraction for what users actually need when want to use e.g. a virtio-net connection on top of PCIe endpoint hardware.
Quoted 4 lines
I'm not familiar with NTB, but from a quick look it seems to be tied to special hardware, and I don't see any virtio-related code there. A vop backend for NTB-backend would presumably work to allow virtio functionality there.
Correct, and again we have to see if this is a good interface. The NTB and PCIe-endpoint interfaces have a number of differences and a number of similarities. In particular they should both be usable with virtio-style drivers, but the underlying hardware differs mainly in how it is probed by the system: an NTB is seen as a PCI device attached to two host bridges, while and endpoint is typically a platform_device on one side, but a pci_dev on the other side.
Can you describe how you expect a VOP device over NTB or PCIe-endpoint would get created, configured and used?
Is there always one master side that is responsible for creating virtio devices on it, with the slave side automatically attaching to them, or can either side create virtio devices? Is there any limit on the number of virtio devices or queues within a VOP device?
Arnd
Quoted 6 lines · Arnd Bergmann
Can you describe how you expect a VOP device over NTB or PCIe-endpoint would get created, configured and used?
Is there always one master side that is responsible for creating virtio devices on it, with the slave side automatically attaching to them, or can either side create virtio devices? Is there any limit on the number of virtio devices or queues within a VOP device?
For VOP device over NTB your configure your device using configfs on one side, and for the other side it will just show up like any other PCIe device, because it is.
Quoted 11 lines · Christoph Hellwig
Quoted 6 lines · Arnd Bergmann
Can you describe how you expect a VOP device over NTB or PCIe-endpoint would get created, configured and used?
Is there always one master side that is responsible for creating virtio devices on it, with the slave side automatically attaching to them, or can either side create virtio devices? Is there any limit on the number of virtio devices or queues within a VOP device?For VOP device over NTB your configure your device using configfs on one side, and for the other side it will just show up like any other PCIe device, because it is.
Sorry, I mean over the PCI-EP infratructure of course. NTB actually is rather hairy and complicated.
Arnd Bergmann
maintainerQuoted 10 lines · Christoph Hellwig
Quoted 8 lines · Christoph Hellwig
Quoted 6 lines · Arnd Bergmann
Can you describe how you expect a VOP device over NTB or PCIe-endpoint would get created, configured and used?
Is there always one master side that is responsible for creating virtio devices on it, with the slave side automatically attaching to them, or can either side create virtio devices? Is there any limit on the number of virtio devices or queues within a VOP device?
Quoted 6 lines
Quoted 3 lines
For VOP device over NTB your configure your device using configfs on one side, and for the other side it will just show up like any other PCIe device, because it is.
Sorry, I mean over the PCI-EP infratructure of course. NTB actually is rather hairy and complicated.
My understanding was that with virtio, we would be able to have multiple virtio devices on a single PCI-EP port, so you need a multi-step
configuration: You first set up the PCI-EP to instantiate a VOP device, which is then seen on both ends of the connection. The question is how to create a particular virtio device instance (or a set of those) inside of it.
Arnd
Quoted 10 lines · Arnd Bergmann
Correct, and again we have to see if this is a good interface. The NTB and PCIe-endpoint interfaces have a number of differences and a number of similarities. In particular they should both be usable with virtio-style drivers, but the underlying hardware differs mainly in how it is probed by the system: an NTB is seen as a PCI device attached to two host bridges, while and endpoint is typically a
platform_deviceon one side, but apci_devon the other side.Can you describe how you expect a VOP device over NTB or PCIe-endpoint would get created, configured and used?
Assuming PCIe-endpoint:
On the RC, a vop-host-backend driver (PCI driver) sets up some shared memory area which the RC and the endpoint can use to communicate the location of the MIC device descriptors and other information such as the MSI address. It implements vop callbacks to allow the vop framework to obtain the address of the MIC descriptors and send/receive interrupts to/from the guest.
On the endpoint, the PCIe endpoint driver sets up (hardcoded) BARs and memory regions as required to allow the endpoint and the root complex to access each other's memory.
On the endpoint, the vop-guest-backend, via the shared memory set up by the vop-host-backend, obtains the address of the MIC device page and the MSI address, and a method to receive vop interrupts from the host. This information is used to implement the vop callbacks allowing the vop framework to access to the MIC device page and send/receive interrupts from/to the host.
vop (despite its name) doesn't care about PCIe. The vop-guest-backend doesn't actually need to talk to the PCIe endpoint driver. The vop-guest-backend can be probed via any means, such as via a device tree on the endpoint.
On the RC, userspace opens the vop device and adds the virtio devices, which end up in the MIC device page set up by the vop-host-backend.
On the endpoint, when the vop framework (via the vop-guest-backend) sees these devices, it registers devices on the virtio bus and the virtio drivers are probed.
On the RC, userspace implements the device end of the virtio communication in userspace, using the MIC_VIRTIO_COPY_DESC ioctl. I also have patches to support vhost.
Quoted 3 lines
Is there always one master side that is responsible for creating virtio devices on it, with the slave side automatically attaching to them, or can either side create virtio devices?
Only the master can create virtio devices. The virtio drivers run on the slave.
Quoted 2 lines
Is there any limit on
the number of virtio devices or queues within a VOP device?
The virtio device information (mic_device_desc) is put into the MIC device page whose size is limited by the ABI header in include/uapi/linux/mic_ioctl.h (MIC_DP_SIZE, 4096 bytes). So the number of devices is limited by the limit of the number of device descriptors that can fit in that size. There is also a per-device limit on the number of vrings (MIC_VRING_ENTRIES) and vring entries (MIC_VRING_ENTRIES) in the ABI header.
Quoted 6 lines · Vincent Whitchurch
On the RC, a vop-host-backend driver (PCI driver) sets up some shared memory area which the RC and the endpoint can use to communicate the location of the MIC device descriptors and other information such as the MSI address. It implements vop callbacks to allow the vop framework to obtain the address of the MIC descriptors and send/receive interrupts to/from the guest.
Why would we require any work on the RC / host side? A properly setup software controlled virtio device should just show up as a normal PCIe device, and the virtio-pci device should bind to it.
Quoted 11 lines · Christoph Hellwig
Quoted 6 lines · Vincent Whitchurch
On the RC, a vop-host-backend driver (PCI driver) sets up some shared memory area which the RC and the endpoint can use to communicate the location of the MIC device descriptors and other information such as the MSI address. It implements vop callbacks to allow the vop framework to obtain the address of the MIC descriptors and send/receive interrupts to/from the guest.
Why would we require any work on the RC / host side? A properly setup software controlled virtio device should just show up as a normal PCIe device, and the virtio-pci device should bind to it.
If I understand you correctly, I think you're talking about the RC running the virtio drivers and the endpoint implementing the virtio device? This vop stuff is used for the other way around: the virtio device is implement on the RC and the endpoint runs the virtio drivers.
Quoted 4 lines · Vincent Whitchurch
If I understand you correctly, I think you're talking about the RC running the virtio drivers and the endpoint implementing the virtio device? This vop stuff is used for the other way around: the virtio device is implement on the RC and the endpoint runs the virtio drivers.
Oh. That is really weird and not that way I'd implement it..
Arnd Bergmann
maintainerQuoted 8 lines · Christoph Hellwig
Quoted 4 lines · Vincent Whitchurch
If I understand you correctly, I think you're talking about the RC running the virtio drivers and the endpoint implementing the virtio device? This vop stuff is used for the other way around: the virtio device is implement on the RC and the endpoint runs the virtio drivers.
Oh. That is really weird and not that way I'd implement it..
It does make sense to me for the very special requirements of the MIC device, which has a regular PC-style server that provides the environment for a special embedded device inside of a PCIe card, so the PCI-EP stuff is just used as a transport here going one way, and then the configuration of the devices implemented through it goes the other way, providing network connectivity and file system to the embedded machine on the PCI-EP.
This is actually very similar to a setup that I considered implementing over USB, where one might have an embedded machine (or a bunch of them on a USB hub) connected to a USB host port, and then use it in the opposite way of a regular gadget driver, by providing a virtfs over USB to the gadget with files residing on a disk on the USB host.
Apparently Vincent has the same use case that both the Intel MIC folks and I had here, so doing it like this is clearly useful. On the other hand, I agree that there are lots of other use cases that need the opposite, so we should try to come up with a design that can cover both.
An example of this might be a PCIe-endpoint device providing network connectivity to the host using a vhost-net device, which ideally just shows up as a device on the host as a virtio-net without requiring any configuration.
So for configuring this, I think it'd like to see a way to have either the PCI-EP or the PCI-host side be the one that can create virtio devices that show up on the other end. This configuration is currently done using an ioctl interface, which was probably the easiest to do for the MIC case, but for consistency with the PCI-EP framework, using configfs is probably better.
A different matter is the question of what a virtio device talks to. A lot of virtio devices are fundamentally asymmetric (9pfs, rng, block, ...), so you'd have to have the virtio device on one side, and a user space or vhost driver on the other. The VOP driver seems to assume that it's always the slave that uses virtio, while the master side (which could be on the PCI EP or PCI host for the sake of this argument) implements it in user space or otherwise. Is this a safe assumption, or can we imagine cases where this would be reversed as well?
Arnd
Arnd Bergmann
maintainerQuoted 26 lines · Vincent Whitchurch
Quoted 10 lines · Arnd Bergmann
Correct, and again we have to see if this is a good interface. The NTB and PCIe-endpoint interfaces have a number of differences and a number of similarities. In particular they should both be usable with virtio-style drivers, but the underlying hardware differs mainly in how it is probed by the system: an NTB is seen as a PCI device attached to two host bridges, while and endpoint is typically a
platform_deviceon one side, but apci_devon the other side.Can you describe how you expect a VOP device over NTB or PCIe-endpoint would get created, configured and used?
Assuming PCIe-endpoint:
On the RC, a vop-host-backend driver (PCI driver) sets up some shared memory area which the RC and the endpoint can use to communicate the location of the MIC device descriptors and other information such as the MSI address. It implements vop callbacks to allow the vop framework to obtain the address of the MIC descriptors and send/receive interrupts to/from the guest.
On the endpoint, the PCIe endpoint driver sets up (hardcoded) BARs and memory regions as required to allow the endpoint and the root complex to access each other's memory.
Quoted 6 lines
On the endpoint, the vop-guest-backend, via the shared memory set up by the vop-host-backend, obtains the address of the MIC device page and the MSI address, and a method to receive vop interrupts from the host. This information is used to implement the vop callbacks allowing the vop framework to access to the MIC device page and send/receive interrupts from/to the host.
Ok, this seems fine so far. So the vop-host-backend is a regular PCI driver that implements the VOP protocol from the host side, and it can talk to either a MIC, or another guest-backend written for the PCI-EP framework to implement the same protocol, right?
Quoted 11 lines
vop (despite its name) doesn't care about PCIe. The vop-guest-backend doesn't actually need to talk to the PCIe endpoint driver. The vop-guest-backend can be probed via any means, such as via a device tree on the endpoint.
On the RC, userspace opens the vop device and adds the virtio devices, which end up in the MIC device page set up by the vop-host-backend.
On the endpoint, when the vop framework (via the vop-guest-backend) sees these devices, it registers devices on the virtio bus and the virtio drivers are probed.
Ah, so the direction is fixed, and it's the opposite of what Christoph and I were expecting. This is probably something we need to discuss a bit. From what I understand, there is no technical requirement why it has to be this direction, right?
What I mean is that the same vop framework could work with a PCI-EP driver implementing the vop-host-backend and
a PCI driver implementing the vop-guest-backend? In order to do this, the PCI-EP configuration would need to pick whether it wants the EP to be the vop host or guest, but having more flexibility in it (letting each side add virtio devices) would be harder to do.
Quoted 3 lines
On the RC, userspace implements the device end of the virtio communication in userspace, using the
MIC_VIRTIO_COPY_DESCioctl. I also have patches to support vhost.
This is a part I don't understand yet. Does this mean that the normal operation is between a user space process on the vop-host talking to the kernel on the vop-guest?
I'm a bit worried about the ioctl interface here, as this combines the configuration side with the actual data transfer, and that seems a bit inflexible.
Quoted 6 lines
Quoted 3 lines
Is there always one master side that is responsible for creating virtio devices on it, with the slave side automatically attaching to them, or can either side create virtio devices?
Only the master can create virtio devices. The virtio drivers run on the slave.
Ok.
Quoted 10 lines
Quoted 2 lines
Is there any limit on
the number of virtio devices or queues within a VOP device?The virtio device information (
mic_device_desc) is put into the MIC device page whose size is limited by the ABI header ininclude/uapi/linux/mic_ioctl.h(MIC_DP_SIZE, 4096 bytes). So the number of devices is limited by the limit of the number of device descriptors that can fit in that size. There is also a per-device limit on the number of vrings (MIC_VRING_ENTRIES) and vring entries (MIC_VRING_ENTRIES) in the ABI header.
Ok, so you can have multiple virtio devices (e.g. a virtio-net and virtio-console) but not an arbitrary number? I suppose we can always extend it later if that becomes a problem.
Arnd
Quoted 26 lines · Arnd Bergmann
Quoted 17 lines · Vincent Whitchurch
Quoted 2 lines · Arnd Bergmann
Can you describe how you expect a VOP device over NTB or PCIe-endpoint would get created, configured and used?
Assuming PCIe-endpoint:
On the RC, a vop-host-backend driver (PCI driver) sets up some shared memory area which the RC and the endpoint can use to communicate the location of the MIC device descriptors and other information such as the MSI address. It implements vop callbacks to allow the vop framework to obtain the address of the MIC descriptors and send/receive interrupts to/from the guest.
On the endpoint, the PCIe endpoint driver sets up (hardcoded) BARs and memory regions as required to allow the endpoint and the root complex to access each other's memory.
Quoted 6 lines
On the endpoint, the vop-guest-backend, via the shared memory set up by the vop-host-backend, obtains the address of the MIC device page and the MSI address, and a method to receive vop interrupts from the host. This information is used to implement the vop callbacks allowing the vop framework to access to the MIC device page and send/receive interrupts from/to the host.
Quoted 4 lines
Ok, this seems fine so far. So the vop-host-backend is a regular PCI driver that implements the VOP protocol from the host side, and it can talk to either a MIC, or another guest-backend written for the PCI-EP framework to implement the same protocol, right?
Yes, but just to clarify: the placement of the device page and the way to communicate the location of the device page address and any other information needed by the guest-backend are hardware-specific so there is no generic vop-host-backend implementation which can talk to both a MIC and to something else.
Quoted 8 lines
Quoted 8 lines
vop (despite its name) doesn't care about PCIe. The vop-guest-backend doesn't actually need to talk to the PCIe endpoint driver. The vop-guest-backend can be probed via any means, such as via a device tree on the endpoint.
On the RC, userspace opens the vop device and adds the virtio devices, which end up in the MIC device page set up by the vop-host-backend.
Quoted 8 lines
Quoted 3 lines
On the endpoint, when the vop framework (via the vop-guest-backend) sees these devices, it registers devices on the virtio bus and the virtio drivers are probed.
Ah, so the direction is fixed, and it's the opposite of what Christoph and I were expecting. This is probably something we need to discuss a bit. From what I understand, there is no technical requirement why it has to be this direction, right?
I don't think the vop framework itself has any such requirement.
The MIC uses it in this way (see Documentation/mic/mic_overview.txt) and it also makes sense (to me, at least) if one wants to treat the endpoint like one would treat a virtualized guest.
Quoted 7 lines
What I mean is that the same vop framework could work with a PCI-EP driver implementing the vop-host-backend and
a PCI driver implementing the vop-guest-backend? In order to do this, the PCI-EP configuration would need to pick whether it wants the EP to be the vop host or guest, but having more flexibility in it (letting each side add virtio devices) would be harder to do.
Correct, this is my understanding also.
Quoted 7 lines
Quoted 3 lines
On the RC, userspace implements the device end of the virtio communication in userspace, using the
MIC_VIRTIO_COPY_DESCioctl. I also have patches to support vhost.This is a part I don't understand yet. Does this mean that the normal operation is between a user space process on the vop-host talking to the kernel on the vop-guest?
Yes. For example, the guest mounts a 9p filesystem with virtio-9p and the 9p server is implemented in a userspace process on the host. This is again similar to virtualization.
Quoted 24 lines
I'm a bit worried about the ioctl interface here, as this combines the configuration side with the actual data transfer, and that seems a bit inflexible.
Quoted 6 lines
Quoted 3 lines
Is there always one master side that is responsible for creating virtio devices on it, with the slave side automatically attaching to them, or can either side create virtio devices?
Only the master can create virtio devices. The virtio drivers run on the slave.
Ok.
Quoted 10 lines
Quoted 2 lines
Is there any limit on
the number of virtio devices or queues within a VOP device?The virtio device information (
mic_device_desc) is put into the MIC device page whose size is limited by the ABI header ininclude/uapi/linux/mic_ioctl.h(MIC_DP_SIZE, 4096 bytes). So the number of devices is limited by the limit of the number of device descriptors that can fit in that size. There is also a per-device limit on the number of vrings (MIC_VRING_ENTRIES) and vring entries (MIC_VRING_ENTRIES) in the ABI header.
Quoted 3 lines
Ok, so you can have multiple virtio devices (e.g. a virtio-net and virtio-console) but not an arbitrary number? I suppose we can always extend it later if that becomes a problem.
Yes.
Arnd Bergmann
maintainerQuoted 8 lines · Vincent Whitchurch
Quoted 6 lines · Arnd Bergmann
On Thu, Jan 17, 2019 at 4:19 PM Vincent Whitchurch
Ok, this seems fine so far. So the vop-host-backend is a regular PCI driver that implements the VOP protocol from the host side, and it can talk to either a MIC, or another guest-backend written for the PCI-EP framework to implement the same protocol, right?
Quoted 5 lines
Yes, but just to clarify: the placement of the device page and the way to communicate the location of the device page address and any other information needed by the guest-backend are hardware-specific so there is no generic vop-host-backend implementation which can talk to both a MIC and to something else.
I'm not sure I understand what is hardware specific about it. Shouldn't it be possible to define at least a vop-host-backend that could work with any guest-backend running on the PCI-EP framework?
This may have to be different from the interface used on MIC, but generally speaking that is what I expect from a PCI device.
Arnd
Quoted 3 lines · Vincent Whitchurch
On the endpoint, the PCIe endpoint driver sets up (hardcoded) BARs and memory regions as required to allow the endpoint and the root complex to access each other's memory.
This statement describes NTB hardware pretty well. In essence that's what an NTB device is: a BAR that maps to a window in other hosts memory.
Right now the entire NTB upstream software stack (ntb_transport and ntb_netdev) is specific to that ecosystem and only exposes a network device so the hosts can communicate. This code works but has some issues and was never able to perform at full PCIe line speeds (which everyone expects). So it's not clear to me if anyone is doing anything real with it. The companies that are working on NTB, that I'm aware of, have mostly done their own out-of-tree stuff.
It would be interesting to unify ntb_transport with the virtio stack because I suspect they do very similar things right now and there's a lot more devices above virtio than just a network device. However, the main problem people working on NTB face (besides performance) is trying to get multi-host working in a general and sensible way given that the hardware typically has limited BAR resources (among other limitations).
Logan
Quoted 10 lines · Vincent Whitchurch
The Virtio-over-PCIe framework living under
drivers/misc/mic/vopimplements a generic framework to use virtio between two Linux systems, given shared memory and a couple of interrupts. It does not actually require the Intel MIC hardware, x86-64, or even PCIe for that matter. This patch series makes it buildable on more systems and adds a loopback driver to test it without special hardware.Note that I don't have access to Intel MIC hardware so some testing of the patchset (especially the patch "vop: Use consistent DMA") on that platform would be appreciated, to ensure that the series does not break anything there.
So a while ago I took a look at running virtio over PCIe. I found virtio basically had two parts:
1) The protocol used to enumerate which virtio devices exist, and perhaps configure them.
2) The ring buffer protocol that actually transfers the data.
I recall that data transfer was purely based on simple shared memory and interrupts, and hence could run over PCIe (e.g. via the PCIe endpoint subsystem in the kernel) without issue.
However, the enumeration/configuration protocol requires the host to be able to do all kinds of strange things that can't possibly be emulated over PCIe; IIRC the configuration data contains "registers" that when written select the data other "registers" access. When the virtio device is exposed by a hypervisor, and all the accesses are emulated synchronously through a trap, this is easy enough to implement. However, if the two ends of this configuration parsing are on different ends of a PCIe bus, there's no way this can work.
Are you thinking of doing something different for enumeration/configuration, and just using the virtio ring buffer protocol over PCIe?
I did post asking about this quite a while back, but IIRC I didn't receive much of a response. Yes, here it is:
"virtio over SW-defined/CPU-driven PCIe endpoint"
Quoted 24 lines · Stephen Warren
Quoted 10 lines · Vincent Whitchurch
The Virtio-over-PCIe framework living under
drivers/misc/mic/vopimplements a generic framework to use virtio between two Linux systems, given shared memory and a couple of interrupts. It does not actually require the Intel MIC hardware, x86-64, or even PCIe for that matter. This patch series makes it buildable on more systems and adds a loopback driver to test it without special hardware.Note that I don't have access to Intel MIC hardware so some testing of the patchset (especially the patch "vop: Use consistent DMA") on that platform would be appreciated, to ensure that the series does not break anything there.
So a while ago I took a look at running virtio over PCIe. I found virtio basically had two parts:
1) The protocol used to enumerate which virtio devices exist, and perhaps configure them.
2) The ring buffer protocol that actually transfers the data.
I recall that data transfer was purely based on simple shared memory and interrupts, and hence could run over PCIe (e.g. via the PCIe endpoint subsystem in the kernel) without issue.
Quoted 8 lines
However, the enumeration/configuration protocol requires the host to be able to do all kinds of strange things that can't possibly be emulated over PCIe; IIRC the configuration data contains "registers" that when written select the data other "registers" access. When the virtio device is exposed by a hypervisor, and all the accesses are emulated synchronously through a trap, this is easy enough to implement. However, if the two ends of this configuration parsing are on different ends of a PCIe bus, there's no way this can work.
Correct, and that's why the MIC "Virtio-over-PCIe framework" does not try to implement the standard "Virtio Over PCI Bus". (Yes, it's confusing.)
Quoted 2 lines
Are you thinking of doing something different for enumeration/configuration, and just using the virtio ring buffer protocol over PCIe?
The mic/vop code already does this. See Documentation/mic/mic_overview.txt for some information.
Quoted 5 lines
I did post asking about this quite a while back, but IIRC I didn't receive much of a response. Yes, here it is:
"virtio over SW-defined/CPU-driven PCIe endpoint"
I came to essentialy the same conclusions before I found the MIC code.
(Your "aside" in that email about virtio doing PCIe reads instead of
writes is not solved by the MIC code, since that is how the standard virtio devices/drivers work.)
Greg KH
maintainerQuoted 11 lines · Vincent Whitchurch
The Virtio-over-PCIe framework living under
drivers/misc/mic/vopimplements a generic framework to use virtio between two Linux systems, given shared memory and a couple of interrupts. It does not actually require the Intel MIC hardware, x86-64, or even PCIe for that matter. This patch series makes it buildable on more systems and adds a loopback driver to test it without special hardware.Note that I don't have access to Intel MIC hardware so some testing of the patchset (especially the patch "vop: Use consistent DMA") on that platform would be appreciated, to ensure that the series does not break anything there.
Quoted 9 lines
Vincent Whitchurch (8):
vop: Use %z forsize_t
vop: Cast pointers touintptr_t
vop: Add definition of readq/writeq if missing
vop: Allow building on more systems
vop: vringh: Do not crash if no DMA channel
vop: Fix handling of >32 feature bits
vop: Use consistent DMA
vop: Add loopback
I applied a few of these to my tree. Feel free to rebase and fix up patch 2 and resend.
thanks,
greg k-h