add vDPA sample driver
cover add vDPA sample driver
This patch set has dependency on the vhost lib patch:
http://dpdk.org/dev/patchwork/patch/34872/
This patch set shows a reference sample of making vDPA device driver , this driver uses a QEMU-emulated virtio-net PCI device as vDPA device, and make it serve as a backend for a virtio-net pci device in nested VM.
The key driver ops implemented are:
* vdpa_virtio_eng_init
Mapping virtio pci device with VFIO into userspace, and read device capability and intialize internal data.
* vdpa_virtio_eng_uninit
Release the mapped device.
* vdpa_virtio_info_query
Device capability reporting, e.g. queue number, features.
* vdpa_virtio_dev_config
With the guest virtio information provideed by vhost lib, this function configures device and IOMMU to set up vhost datapath, which includes: Rx/Tx vring, VFIO interrupt, kick relay.
* vdpa_virtio_dev_close
Unset the stuff that are configured previously by dev_conf.
This driver requires the virtio device supports VIRTIO_F_IOMMU_PLATFORM , because the buffer address written in desc is IOVA.
Because vDPA driver needs to set up MSI-X vector to interrupt the guest, only vfio-pci is supported currently.
Below are setup steps for your reference:
1. Make sure your kernnel vhost module and QEMU support vIOMMU.
- OS: CentOS 7.4
- QEMU: 2.10.1
- Guest OS: CentOS 7.2
- Nested VM OS: CentOS 7.2
2. enable VT-x feature for vCPU in VM.
modprobe kvm_intel nested=1
3. Start a VM with a virtio-net-pci device. ./qemu-2.10.1/x86_64-softmmu/qemu-system-x86_64 -enable-kvm -cpu host \
<snip>
-machine q35 \
-device intel-iommu \
-netdev tap,id=mytap,ifname=vdpa,vhostforce=on \
-device virtio-net-pci,netdev=mytap,mac=00:aa:bb:cc:dd:ee,\
disable-modern=off,disable-legacy=on,iommu_platform=on \
4. Bind VFIO-pci to virtio_net_pci device
a) login to VM;
b) modprobe vfio-pci
c) rmmod vfio_iommu_type1
d) modprobe vfio_iommu_type1 allow_unsafe_interrupts=1
e) ./usertools/dpdk-devbind.py -b vfio-pci 00:03.0
5. Start vdpa sample
./examples/vdpa/build/vdpa -c 0x2 -n 4 --socket-mem 1024 --no-pci \
--vdev "net_vdpa_virtio_pci0,bdf=0000:00:03.0" -- --bdf 0000:00:03.0 \
--iface /tmp/vhost-user- --devcnt 1 --queue 16. Start nested VM ./qemu-2.10.1/x86_64-softmmu/qemu-system-x86_64 -cpu host -enable-kvm \
<snip>
-mem-prealloc \
-chardev socket,id=char0,path=/tmp/vhost-user-0 \
-netdev type=vhost-user,id=vdpa,chardev=char0,vhostforce \
-device virtio-net-pci,netdev=vdpa,mac=00:aa:bb:cc:dd:ee \
7. Login the nested VM, and verify the virtio in nested VM can communicate with tap device on host.
Xiao Wang (3):
bus/pci: expose API for vDPA net/vdpa_virtio_pci: introduce vdpa sample driver examples/vdpa: add a new sample for vdpa
config/common_base | 6 + config/common_linuxapp | 1 + drivers/bus/pci/Makefile | 1 + drivers/bus/pci/linux/pci.c | 10 +- drivers/bus/pci/linux/pci_init.h | 22 +- drivers/bus/pci/linux/pci_vfio.c | 5 +- drivers/bus/pci/rte_bus_pci_version.map | 13 + drivers/net/Makefile | 1 + drivers/net/vdpa_virtio_pci/Makefile | 31 + .../net/vdpa_virtio_pci/rte_eth_vdpa_virtio_pci.c | 1527 ++++++++++++++++++++ .../rte_vdpa_virtio_pci_version.map | 4 + examples/vdpa/Makefile | 32 + examples/vdpa/main.c | 387 +++++ mk/rte.app.mk | 1 + 14 files changed, 2030 insertions(+), 11 deletions(-) create mode 100644 drivers/net/vdpa_virtio_pci/Makefile create mode 100644 drivers/net/vdpa_virtio_pci/rte_eth_vdpa_virtio_pci.c create mode 100644 drivers/net/vdpa_virtio_pci/rte_vdpa_virtio_pci_version.map create mode 100644 examples/vdpa/Makefile create mode 100644 examples/vdpa/main.c
Signature · 1 line
2.15.1
PATCH 1/3 bus/pci: expose API for vDPA
Some existing PCI APIs are helpful for vDPA device setup, expose them for the later driver patch.
--- drivers/bus/pci/Makefile | 1 + drivers/bus/pci/linux/pci.c | 10 +++------- drivers/bus/pci/linux/pci_init.h | 22 +++++++++++++++++++++- drivers/bus/pci/linux/pci_vfio.c | 5 ++--- drivers/bus/pci/rte_bus_pci_version.map | 13 +++++++++++++ 5 files changed, 40 insertions(+), 11 deletions(-)
drivers/bus/pci/Makefile +1 -0
@@ -45,6 +45,7 @@ ifneq ($(CONFIG_RTE_EXEC_ENV_BSDAPP),) SYSTEM := bsd endif +CFLAGS += -DALLOW_EXPERIMENTAL_API CFLAGS += -I$(RTE_SDK)/drivers/bus/pci/$(SYSTEM) CFLAGS += -I$(RTE_SDK)/lib/librte_eal/common CFLAGS += -I$(RTE_SDK)/lib/librte_eal/$(SYSTEM)app/eal
drivers/bus/pci/linux/pci.c +3 -7
@@ -32,7 +32,7 @@extern struct rte_pci_bus rte_pci_bus; -static int +int pci_get_kernel_driver_by_path (const char *filename,char *dri_name) {int count;
@@ -168,8 +168,7 @@ pci_parse_one_sysfs_resource(char *line, size_t len, uint64_t *phys_addr,return 0 ; } -/* parse the "resource" sysfs file */ -static int +int pci_parse_sysfs_resource (const char *filename,struct rte_pci_device *dev) {FILE *f;
@@ -372,10 +371,7 @@ pci_update_device(const struct rte_pci_addr *addr)return pci_scan_one (filename, addr); } -/* -* split up a pci address into its constituent parts. -*/ -static int +int parse_pci_addr_format (const char *buf,int bufsize,struct rte_pci_addr *addr) {/* first split on ':' */
drivers/bus/pci/linux/pci_init.h +21 -1
@@ -6,6 +6,7 @@#define EAL_PCI_INIT_H_ #include <rte_vfio.h> +#include <stdbool.h> /** IO resource type: */ #define IORESOURCE_IO 0x00000100
@@ -15,7 +16,7 @@* Helper function to map PCI resources right after hugepages in virtual memory */ extern void *pci_map_addr; -void *pci_find_max_end_va (void ); +void *__rte_experimental pci_find_max_end_va(void);/* parse one line of the "resource" sysfs file (note that the 'line' * string is modified)
@@ -83,6 +84,25 @@ int pci_vfio_unmap_resource(struct rte_pci_device *dev);int pci_vfio_is_enabled (void ); +/* parse sysfs file path */ +int __rte_experimental +pci_get_kernel_driver_by_path (const char *filename,char *dri_name); + +/* parse the "resource" sysfs file */ +int __rte_experimental +pci_parse_sysfs_resource (const char *filename,struct rte_pci_device *dev); + +/* split up a pci address into its constituent parts */ +int __rte_experimental +parse_pci_addr_format (const char *buf,int bufsize,struct rte_pci_addr *addr); + +/* get PCI BAR info for MSI-X interrupts */ +int __rte_experimental +pci_vfio_get_msix_bar (int fd,struct pci_msix_table *msix_table); + +/* enable DMA and reset device */ +int __rte_experimental +pci_rte_vfio_setup_device (struct rte_pci_device *dev,int vfio_dev_fd);#endif #endif /* EAL_PCI_INIT_H_ */
drivers/bus/pci/linux/pci_vfio.c +2 -3
@@ -59,8 +59,7 @@ pci_vfio_write_config(const struct rte_intr_handle *intr_handle, VFIO_GET_REGION_ADDR(VFIO_PCI_CONFIG_REGION_INDEX) + offs); } -/* get PCI BAR number where MSI-X interrupts are */ -static int +int pci_vfio_get_msix_bar (int fd,struct pci_msix_table *msix_table) {int ret;
@@ -295,7 +294,7 @@ pci_vfio_is_ioport_bar(int vfio_dev_fd, int bar_index)return (ioport_bar &PCI_BASE_ADDRESS_SPACE_IO ) !=0 ; } -static int +int pci_rte_vfio_setup_device (struct rte_pci_device *dev,int vfio_dev_fd) {if (pci_vfio_setup_interrupts (dev, vfio_dev_fd) !=0 ) {
drivers/bus/pci/rte_bus_pci_version.map +13 -0
@@ -16,3 +16,16 @@ DPDK_17.11 { local: *; }; + +EXPERIMENTAL { + global: + + pci_map_addr; + pci_find_max_end_va; + pci_get_kernel_driver_by_path; + pci_parse_sysfs_resource; + pci_vfio_get_msix_bar; + pci_rte_vfio_setup_device; + parse_pci_addr_format; + +} DPDK_17.11;
Signature · 1 line
2.15.1
PATCH 2/3 net/vdpa_virtio_pci: introduce vdpa sample driver
In reply to Xiao WangThis driver is a reference sample of making vDPA device driver based on vhost lib, this driver uses a standard virtio-net PCI device as vDPA device, it can serve as a backend for a virtio-net pci device in nested VM.
The key driver ops implemented are:
* vdpa_virtio_eng_init
Mapping virtio pci device with VFIO into userspace, and read device capability and intialize internal data.
* vdpa_virtio_eng_uninit
Release the mapped device.
* vdpa_virtio_info_query
Device capability reporting, e.g. queue number, features.
* vdpa_virtio_dev_config
With the guest virtio information provideed by vhost lib, this function configures device and IOMMU to set up vhost datapath, which includes: Rx/Tx vring, VFIO interrupt, kick relay.
* vdpa_virtio_dev_close
Unset the stuff that are configured previously by dev_conf.
This driver requires the virtio device supports VIRTIO_F_IOMMU_PLATFORM , because the buffer address written in desc is IOVA.
Because vDPA driver needs to set up MSI-X vector to interrupt the guest, only vfio-pci is supported currently.
--- config/common_base | 6 + config/common_linuxapp | 1 + drivers/net/Makefile | 1 + drivers/net/vdpa_virtio_pci/Makefile | 31 + .../net/vdpa_virtio_pci/rte_eth_vdpa_virtio_pci.c | 1527 ++++++++++++++++++++ .../rte_vdpa_virtio_pci_version.map | 4 + mk/rte.app.mk | 1 + 7 files changed, 1571 insertions(+) create mode 100644 drivers/net/vdpa_virtio_pci/Makefile create mode 100644 drivers/net/vdpa_virtio_pci/rte_eth_vdpa_virtio_pci.c create mode 100644 drivers/net/vdpa_virtio_pci/rte_vdpa_virtio_pci_version.map
config/common_base +6 -0
@@ -791,6 +791,12 @@ CONFIG_RTE_LIBRTE_VHOST_DEBUG=n # CONFIG_RTE_LIBRTE_PMD_VHOST=n +# +# Compile VDPA VIRTIO PCI driver +# To compile, CONFIG_RTE_LIBRTE_VHOST should be enabled. +# +CONFIG_RTE_LIBRTE_VDPA_VIRTIO_PCI=n + # # Compile the test application #
config/common_linuxapp +1 -0
@@ -15,6 +15,7 @@ CONFIG_RTE_LIBRTE_PMD_KNI=y CONFIG_RTE_LIBRTE_VHOST=y CONFIG_RTE_LIBRTE_VHOST_NUMA=y CONFIG_RTE_LIBRTE_PMD_VHOST=y +CONFIG_RTE_LIBRTE_VDPA_VIRTIO_PCI=y CONFIG_RTE_LIBRTE_PMD_AF_PACKET=y CONFIG_RTE_LIBRTE_PMD_TAP=y CONFIG_RTE_LIBRTE_AVP_PMD=y
drivers/net/Makefile +1 -0
@@ -53,6 +53,7 @@ endif # $(CONFIG_RTE_LIBRTE_SCHED) ifeq ($(CONFIG_RTE_LIBRTE_VHOST),y) DIRS-$(CONFIG_RTE_LIBRTE_PMD_VHOST) += vhost +DIRS-$(CONFIG_RTE_LIBRTE_VDPA_VIRTIO_PCI) += vdpa_virtio_pci endif # $(CONFIG_RTE_LIBRTE_VHOST) ifeq ($(CONFIG_RTE_LIBRTE_MRVL_PMD),y)
drivers/net/vdpa_virtio_pci/Makefile new file +31 -0
@@ -0,0 +1,31 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2018 Intel Corporation + +include $(RTE_SDK)/mk/rte.vars.mk + +# +# library name +# +LIB = librte_vdpa_virtio_pci.a + +LDLIBS += -lpthread +LDLIBS += -lrte_eal -lrte_mempool -lrte_pci +LDLIBS += -lrte_ethdev -lrte_net -lrte_kvargs -lrte_vhost +LDLIBS += -lrte_bus_vdev -lrte_bus_pci + +CFLAGS += -O3 +CFLAGS += $(WERROR_FLAGS) +CFLAGS += -I$(RTE_SDK)/lib/librte_eal/linuxapp/eal +CFLAGS += -I$(RTE_SDK)/drivers/bus/pci/linux +CFLAGS += -DALLOW_EXPERIMENTAL_API + +EXPORT_MAP := rte_vdpa_virtio_pci_version.map + +LIBABIVER := 1 + +# +# all source are stored in SRCS-y +# +SRCS-$(CONFIG_RTE_LIBRTE_PMD_VHOST) += rte_eth_vdpa_virtio_pci.c + +include $(RTE_SDK)/mk/rte.lib.mk
drivers/net/vdpa_virtio_pci/rte_eth_vdpa_virtio_pci.c new file +1527 -0
1,527 lines not on this page · raw message
drivers/net/vdpa_virtio_pci/rte_vdpa_virtio_pci_version.map new file +4 -0
@@ -0,0 +1,4 @@ +EXPERIMENTAL { + + local: *; +};
mk/rte.app.mk +1 -0
@@ -171,6 +171,7 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_VDEV_NETVSC_PMD) += -lrte_pmd_vdev_netvsc _LDLIBS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD) += -lrte_pmd_virtio ifeq ($(CONFIG_RTE_LIBRTE_VHOST),y) _LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_VHOST) += -lrte_pmd_vhost +_LDLIBS-$(CONFIG_RTE_LIBRTE_VDPA_VIRTIO_PCI) += -lrte_vdpa_virtio_pci endif # $(CONFIG_RTE_LIBRTE_VHOST) _LDLIBS-$(CONFIG_RTE_LIBRTE_VMXNET3_PMD) += -lrte_pmd_vmxnet3_uio
Signature · 1 line
2.15.1
Re: [PATCH 2/3] net/vdpa_virtio_pci: introduce vdpa sample driver
Hi Xiao,
Quoted 41 lines · Xiao Wang
This driver is a reference sample of making vDPA device driver based on vhost lib, this driver uses a standard virtio-net PCI device as vDPA device, it can serve as a backend for a virtio-net pci device in nested VM.
The key driver ops implemented are:
*
vdpa_virtio_eng_init
Mapping virtio pci device with VFIO into userspace, and read device capability and intialize internal data.*
vdpa_virtio_eng_uninit
Release the mapped device.*
vdpa_virtio_info_query
Device capability reporting, e.g. queue number, features.*
vdpa_virtio_dev_config
With the guest virtio information provideed by vhost lib, this function configures device and IOMMU to set up vhost datapath, which includes: Rx/Tx vring, VFIO interrupt, kick relay.*
vdpa_virtio_dev_close
Unset the stuff that are configured previously bydev_conf.This driver requires the virtio device supports
VIRTIO_F_IOMMU_PLATFORM, because the buffer address written in desc is IOVA.Because vDPA driver needs to set up MSI-X vector to interrupt the guest, only vfio-pci is supported currently.
Signed-off-by Xiao Wang<[email protected]>--- config/common_base | 6 + config/common_linuxapp | 1 + drivers/net/Makefile | 1 + drivers/net/vdpa_virtio_pci/Makefile | 31 + .../net/vdpa_virtio_pci/rte_eth_vdpa_virtio_pci.c | 1527 ++++++++++++++++++++ .../rte_vdpa_virtio_pci_version.map | 4 + mk/rte.app.mk | 1 + 7 files changed, 1571 insertions(+)
Quoted 3 lines
create mode 100644
drivers/net/vdpa_virtio_pci/Makefile
create mode 100644drivers/net/vdpa_virtio_pci/rte_eth_vdpa_virtio_pci.ccreate mode 100644drivers/net/vdpa_virtio_pci/rte_vdpa_virtio_pci_version.map
Is there a specific constraint that makes you expose PCI functions and duplicate a lot of vfio code into the driver?
Wouldn't it be better (if possible) to use RTE_PMD_REGISTER_PCI() & co. to benefit from all the existing infrastructure?
Maxime
Re: [PATCH 2/3] net/vdpa_virtio_pci: introduce vdpa sample driver
Hi Maxime,
Quoted 57 lines
-----Original Message-----
From: Maxime Coquelin [mailto:[email protected]]
Sent: Tuesday, February 6, 2018 10:24 PM
To: Wang, Xiao W <[email protected]>; [email protected]
Cc: Tan, Jianfeng <[email protected]>; Bie, Tiwei <[email protected]>; [email protected]; Liang, Cunming <[email protected]>; Daly, Dan <[email protected]>; Wang, Zhihong <[email protected]>
Subject: Re: [PATCH 2/3]net/vdpa_virtio_pci: introduce vdpa sample driverHi Xiao,
Quoted 31 lines · Xiao Wang
This driver is a reference sample of making vDPA device driver based on vhost lib, this driver uses a standard virtio-net PCI device as vDPA device, it can serve as a backend for a virtio-net pci device in nested VM.
The key driver ops implemented are:
*
vdpa_virtio_eng_init
Mapping virtio pci device with VFIO into userspace, and read device capability and intialize internal data.*
vdpa_virtio_eng_uninit
Release the mapped device.*
vdpa_virtio_info_query
Device capability reporting, e.g. queue number, features.*
vdpa_virtio_dev_config
With the guest virtio information provideed by vhost lib, this function configures device and IOMMU to set up vhost datapath, which includes: Rx/Tx vring, VFIO interrupt, kick relay.*
vdpa_virtio_dev_close
Unset the stuff that are configured previously bydev_conf.This driver requires the virtio device supports
VIRTIO_F_IOMMU_PLATFORM, because the buffer address written in desc is IOVA.Because vDPA driver needs to set up MSI-X vector to interrupt the guest, only vfio-pci is supported currently.
Quoted 7 lines
Signed-off-by Xiao Wang<[email protected]>--- config/common_base | 6 + config/common_linuxapp | 1 + drivers/net/Makefile | 1 + drivers/net/vdpa_virtio_pci/Makefile | 31 + .../net/vdpa_virtio_pci/rte_eth_vdpa_virtio_pci.c | 1527++++++++++++++++++++
Quoted 6 lines
.../rte_vdpa_virtio_pci_version.map | 4 + mk/rte.app.mk | 1 + 7 files changed, 1571 insertions(+)create mode 100644
drivers/net/vdpa_virtio_pci/Makefilecreate mode 100644drivers/net/vdpa_virtio_pci/rte_eth_vdpa_virtio_pci.ccreate mode 100644
Quoted 4 lines
drivers/net/vdpa_virtio_pci/rte_vdpa_virtio_pci_version.mapIs there a specific constraint that makes you expose PCI functions and duplicate a lot of vfio code into the driver?
The existing vfio code doesn't fit VDPA well, this vDPA driver needs to program IOMMU for a vDPA device with a VM's memory table.
While the eal/vfio uses a struct vfio_cfg to takes all regular devices and add them to a single vfio_container, and program IOMMU with DPDK process's memory table.
This driver doing PCI VFIO initialization itself can avoid affecting the global vfio_cfg structure.
Quoted 3 lines
Wouldn't it be better (if possible) to use
RTE_PMD_REGISTER_PCI()& co. to benefit from all the existing infrastructure?
RTE_PMD_REGISTER_PCI() & co will make this driver as PCI driver (physical device), then this will conflict with the virtio_pmd. So I make vDPA device driver as a vdev driver.
Quoted 2 lines
Maxime
Thanks for the comments,
Xiao
Re: [PATCH 2/3] net/vdpa_virtio_pci: introduce vdpa sample driver
Hi Xiao,
Quoted 61 lines · Xiao W
Hi Maxime,
Quoted 59 lines
-----Original Message-----
From: Maxime Coquelin [mailto:[email protected]]
Sent: Tuesday, February 6, 2018 10:24 PM
To: Wang, Xiao W <[email protected]>; [email protected]
Cc: Tan, Jianfeng <[email protected]>; Bie, Tiwei <[email protected]>; [email protected]; Liang, Cunming <[email protected]>; Daly, Dan <[email protected]>; Wang, Zhihong <[email protected]>
Subject: Re: [PATCH 2/3]net/vdpa_virtio_pci: introduce vdpa sample driverHi Xiao,
Quoted 31 lines · Xiao Wang
This driver is a reference sample of making vDPA device driver based on vhost lib, this driver uses a standard virtio-net PCI device as vDPA device, it can serve as a backend for a virtio-net pci device in nested VM.
The key driver ops implemented are:
*
vdpa_virtio_eng_init
Mapping virtio pci device with VFIO into userspace, and read device capability and intialize internal data.*
vdpa_virtio_eng_uninit
Release the mapped device.*
vdpa_virtio_info_query
Device capability reporting, e.g. queue number, features.*
vdpa_virtio_dev_config
With the guest virtio information provideed by vhost lib, this function configures device and IOMMU to set up vhost datapath, which includes: Rx/Tx vring, VFIO interrupt, kick relay.*
vdpa_virtio_dev_close
Unset the stuff that are configured previously bydev_conf.This driver requires the virtio device supports
VIRTIO_F_IOMMU_PLATFORM, because the buffer address written in desc is IOVA.Because vDPA driver needs to set up MSI-X vector to interrupt the guest, only vfio-pci is supported currently.
Quoted 7 lines
Signed-off-by Xiao Wang<[email protected]>--- config/common_base | 6 + config/common_linuxapp | 1 + drivers/net/Makefile | 1 + drivers/net/vdpa_virtio_pci/Makefile | 31 + .../net/vdpa_virtio_pci/rte_eth_vdpa_virtio_pci.c | 1527++++++++++++++++++++
Quoted 6 lines
.../rte_vdpa_virtio_pci_version.map | 4 + mk/rte.app.mk | 1 + 7 files changed, 1571 insertions(+)create mode 100644
drivers/net/vdpa_virtio_pci/Makefilecreate mode 100644drivers/net/vdpa_virtio_pci/rte_eth_vdpa_virtio_pci.ccreate mode 100644
drivers/net/vdpa_virtio_pci/rte_vdpa_virtio_pci_version.map
Quoted 7 lines
Quoted 2 lines
Is there a specific constraint that makes you expose PCI functions and duplicate a lot of vfio code into the driver?
The existing vfio code doesn't fit VDPA well, this vDPA driver needs to program IOMMU for a vDPA device with a VM's memory table.
While the eal/vfio uses a structvfio_cfgto takes all regular devices and add them to a singlevfio_container, and program IOMMU with DPDK process's memory table.This driver doing PCI VFIO initialization itself can avoid affecting the global
vfio_cfgstructure.
Ok, I get it.
So I think what you have to do is to extend eal/vfio for this case. Or at least, have a vdpa layer to perform this, else every offload driver will have to duplicate the code.
Quoted 6 lines
Quoted 3 lines
Wouldn't it be better (if possible) to use
RTE_PMD_REGISTER_PCI()& co. to benefit from all the existing infrastructure?
RTE_PMD_REGISTER_PCI()& co will make this driver as PCI driver (physical device), then this will conflict with thevirtio_pmd. So I make vDPA device driver as a vdev driver.
Yes, but it is a PCI device, not a virtual device. You have to extend the EAL to support this new class of devices/drivers. Think of it as in kernel when a NIC device can be either binded to its NIC driver, VFIO or UIO.
If I look at patch 3, you have to set --no-pci, or at least I think to blacklist the Virtio device.
I wonder if real vDPA cards will support either vDPA mode or or behave like a regular NIC, like the Virtio case in your example.
If this is the case, maybe the vDPA code for a NIC could be in the same driver as the "NIC" mode.
A new struct rte_pci_driver driver flag could be introduced to specify that the driver supports vDPA.
Then, in EAL arguments, if a vhost vdev specifies it wants Virtio device at PCI addr 00:01:00 as offload, the PCI layer could probe this device in "vdpa" mode.
Also, I don't know if this will be possible with real vDPA cards, but we could have the application doing packet switching between vhost-user vdev and the Virtio device. And at some point, at runtime, switch into vDPA mode. This use-case would be much easier to implement if vDPA relied on existing PCI layer.
I may be not very clear, don't hesitate to ask questions. But generally, I think vDPA has to fit in existing DPDK architecture, and not try to live outside of it.
Thanks,
Maxime
Quoted 6 lines
Quoted 2 lines
Maxime
Thanks for the comments,
Xiao
Re: [PATCH 2/3] net/vdpa_virtio_pci: introduce vdpa sample driver
Hi Maxime,
Quoted 85 lines
-----Original Message-----
From: Maxime Coquelin [mailto:[email protected]]
Sent: Thursday, February 8, 2018 5:09 PM
To: Wang, Xiao W <[email protected]>; [email protected]
Cc: Tan, Jianfeng <[email protected]>; Bie, Tiwei <[email protected]>; [email protected]; Liang, Cunming <[email protected]>; Daly, Dan <[email protected]>; Wang, Zhihong <[email protected]>
Subject: Re: [PATCH 2/3]net/vdpa_virtio_pci: introduce vdpa sample driverHi Xiao,
Quoted 7 lines · Xiao W
Hi Maxime,
Quoted 5 lines
-----Original Message-----
From: Maxime Coquelin [mailto:[email protected]]
Sent: Tuesday, February 6, 2018 10:24 PM
To: Wang, Xiao W <[email protected]>; [email protected]
Cc: Tan, Jianfeng <[email protected]>; Bie, TiweiQuoted 29 lines
Quoted 29 lines
[email protected]; Liang, Cunming <[email protected]>; Daly, Dan <[email protected]>; Wang, Zhihong <[email protected]>
Subject: Re: [PATCH 2/3]net/vdpa_virtio_pci: introduce vdpa sample driverHi Xiao,
Quoted 22 lines · Xiao Wang
This driver is a reference sample of making vDPA device driver based on vhost lib, this driver uses a standard virtio-net PCI device as vDPA device, it can serve as a backend for a virtio-net pci device in nested VM.
The key driver ops implemented are:
*
vdpa_virtio_eng_init
Mapping virtio pci device with VFIO into userspace, and read device capability and intialize internal data.*
vdpa_virtio_eng_uninit
Release the mapped device.*
vdpa_virtio_info_query
Device capability reporting, e.g. queue number, features.*
vdpa_virtio_dev_config
With the guest virtio information provideed by vhost lib, this function configures device and IOMMU to set up vhost datapath, which includes: Rx/Tx vring, VFIO interrupt, kick relay.Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
*
vdpa_virtio_dev_close
Unset the stuff that are configured previously bydev_conf.This driver requires the virtio device supports
VIRTIO_F_IOMMU_PLATFORMQuoted 12 lines
Quoted 12 lines
Quoted 12 lines
, because the buffer address written in desc is IOVA.
Because vDPA driver needs to set up MSI-X vector to interrupt the guest, only vfio-pci is supported currently.
Signed-off-by Xiao Wang<[email protected]>--- config/common_base | 6 + config/common_linuxapp | 1 + drivers/net/Makefile | 1 + drivers/net/vdpa_virtio_pci/Makefile | 31 + .../net/vdpa_virtio_pci/rte_eth_vdpa_virtio_pci.c | 1527Quoted 6 lines
Quoted 6 lines
++++++++++++++++++++
Quoted 5 lines
.../rte_vdpa_virtio_pci_version.map | 4 + mk/rte.app.mk | 1 + 7 files changed, 1571 insertions(+)create mode 100644
drivers/net/vdpa_virtio_pci/Makefilecreate mode 100644
drivers/net/vdpa_virtio_pci/rte_eth_vdpa_virtio_pci.cQuoted 7 lines
Quoted 5 lines
Quoted 1 line
create mode 100644
drivers/net/vdpa_virtio_pci/rte_vdpa_virtio_pci_version.mapIs there a specific constraint that makes you expose PCI functions and duplicate a lot of vfio code into the driver?
The existing vfio code doesn't fit VDPA well, this vDPA driver needs to
program IOMMU for a vDPA device with a VM's memory table.
Quoted 1 line
While the eal/vfio uses a struct
vfio_cfgto takes all regular devices and addthem to a single
vfio_container, and program IOMMU with DPDK process's memory table.Quoted 1 line
Quoted 7 lines
Quoted 1 line
This driver doing PCI VFIO initialization itself can avoid affecting the global
vfio_cfgstructure.Ok, I get it.
So I think what you have to do is to extend eal/vfio for this case. Or at least, have a vdpa layer to perform this, else every offload driver will have to duplicate the code.
I think I need to extend eal/vfio to provide container based APIs, such as creating container, vfio group fd binding with container, DMAR programming, etc.
Quoted 17 lines
Quoted 6 lines
Quoted 4 lines
Wouldn't it be better (if possible) to use
RTE_PMD_REGISTER_PCI()& co. to benefit from all the existing infrastructure?
RTE_PMD_REGISTER_PCI()& co will make this driver as PCI driver (physicaldevice), then this will conflict with the
virtio_pmd.Quoted 1 line
So I make vDPA device driver as a vdev driver.
Yes, but it is a PCI device, not a virtual device. You have to extend the EAL to support this new class of devices/drivers. Think of it as in kernel when a NIC device can be either binded to its NIC driver, VFIO or UIO.
If I look at patch 3, you have to set --no-pci, or at least I think to blacklist the Virtio device.
Quoted 9 lines
I wonder if real vDPA cards will support either vDPA mode or or behave like a regular NIC, like the Virtio case in your example.
If this is the case, maybe the vDPA code for a NIC could be in the same driver as the "NIC" mode.
A new structrte_pci_driverdriver flag could be introduced to specify that the driver supports vDPA.
Then, in EAL arguments, if a vhost vdev specifies it wants Virtio device at PCI addr 00:01:00 as offload, the PCI layer could probe this device in "vdpa" mode.
Considering that we could have a pool of vDPA devices, we need to have a port supporting port representor, it defines control domain to which these vDPA devices belong to, we can have a vdev port for this purpose and this vdev helps to register vDPA ports by port-representor library (patch submitted).
+------+
| vdev |
+---+ |------|
|app|--register representor port-->|broker|-->add port with vDPA device 0/1/2...
+---+ +------+I plan to submit vdpa driver patch for a real vDPA card, that card will have different sub device_id/vendor_id, so we won't have conflict issue on that driver.
Quoted 6 lines
Also, I don't know if this will be possible with real vDPA cards, but we could have the application doing packet switching between vhost-user vdev and the Virtio device. And at some point, at runtime, switch into vDPA mode. This use-case would be much easier to implement if vDPA relied on existing PCI layer.
In vDPA mode, each vhost-user datapath is performed by a vDPA device,
If switchover to normal SW packet switching, it will be typically many vhost-user ports and one uplink port.
Thanks,
Xiao
Quoted 13 lines
I may be not very clear, don't hesitate to ask questions. But generally, I think vDPA has to fit in existing DPDK architecture, and not try to live outside of it.
Thanks,
MaximeQuoted 6 lines
Quoted 2 lines
Maxime
Thanks for the comments,
Xiao
PATCH 3/3 examples/vdpa: add a new sample for vdpa
In reply to Xiao WangThis patch adds a sample which creates vhost-user socket based on vdpa driver. vdpa driver can help to set up vhost datapath so this app doesn't need to spend a dedicated worker thread on vhost enqueue/dequeue operations.
Below are setup steps for your reference:
1. Make sure your kernnel vhost module and QEMU support vIOMMU.
- OS: CentOS 7.4
- QEMU: 2.10.1
- Guest OS: CentOS 7.2
- Nested VM OS: CentOS 7.2
2. enable VT-x feature for vCPU in VM.
modprobe kvm_intel nested=1
3. Start a VM with a virtio-net-pci device. ./qemu-2.10.1/x86_64-softmmu/qemu-system-x86_64 -enable-kvm -cpu host \
<snip>
-machine q35 \
-device intel-iommu \
-netdev tap,id=mytap,ifname=vdpa,vhostforce=on \
-device virtio-net-pci,netdev=mytap,mac=00:aa:bb:cc:dd:ee,\
disable-modern=off,disable-legacy=on,iommu_platform=on \
4. Bind VFIO-pci to virtio_net_pci device
a) login to VM;
b) modprobe vfio-pci
c) rmmod vfio_iommu_type1
d) modprobe vfio_iommu_type1 allow_unsafe_interrupts=1
e) ./usertools/dpdk-devbind.py -b vfio-pci 00:03.0
5. Start vdpa sample
./examples/vdpa/build/vdpa -c 0x2 -n 4 --socket-mem 1024 --no-pci \
--vdev "net_vdpa_virtio_pci0,bdf=0000:00:03.0" -- --bdf 0000:00:03.0 \
--iface /tmp/vhost-user- --devcnt 1 --queue 16. Start nested VM ./qemu-2.10.1/x86_64-softmmu/qemu-system-x86_64 -cpu host -enable-kvm \
<snip>
-mem-prealloc \
-chardev socket,id=char0,path=/tmp/vhost-user-0 \
-netdev type=vhost-user,id=vdpa,chardev=char0,vhostforce \
-device virtio-net-pci,netdev=vdpa,mac=00:aa:bb:cc:dd:ee \
7. Login the nested VM, and verify the virtio in nested VM can communicate with tap device on the host.
--- examples/vdpa/Makefile | 32 ++++ examples/vdpa/main.c | 387 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 419 insertions(+) create mode 100644 examples/vdpa/Makefile create mode 100644 examples/vdpa/main.c
examples/vdpa/Makefile new file +32 -0
@@ -0,0 +1,32 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2018 Intel Corporation + +ifeq ($(RTE_SDK),) +$(error "Please define RTE_SDK environment variable") +endif + +# Default target, can be overridden by command line or environment +RTE_TARGET ?= x86_64-native-linuxapp-gcc + +include $(RTE_SDK)/mk/rte.vars.mk + +ifneq ($(CONFIG_RTE_EXEC_ENV),"linuxapp") +$(info This application can only operate in a linuxapp environment, \ +please change the definition of the RTE_TARGET environment variable) +all: +else + +# binary name +APP = vdpa + +# all source are stored in SRCS-y +SRCS-y := main.c + +CFLAGS += -O2 -D_FILE_OFFSET_BITS=64 +CFLAGS += $(WERROR_FLAGS) +CFLAGS += -D_GNU_SOURCE +CFLAGS += -DALLOW_EXPERIMENTAL_API + +include $(RTE_SDK)/mk/rte.extapp.mk + +endif
examples/vdpa/main.c new file +387 -0
387 lines not on this page · raw message
Signature · 1 line
2.15.1