hw/pvrdma: PVRDMA device implementation
v9 cover hw/pvrdma: PVRDMA device implementation
V8 -> V9:
- Addressed Dotan's Barak (offline) comments:
- use g_malloc instead of malloc
- re-arrange structs for better padding
- some cosmetic changes
- do not try to fetch CQE when CQ is going down
- init state of QP changed to RESET
- modify poll_cq
- add fix to qkey handling so now qkey=0 is also supported
- add validation to gid_index
- fix memory leak with ah_key ref
- Addressed Eduardo Habkost comments:
- Add the mem-backed-ram "share" option to qemu-options.hx.
- Rebased on latest master
V7 -> V8:
- Addressed Michael S. Tsirkin comments:
- fail to init the pvrdma device if target page size is different from the host size, or if the guest RAM is not backed by memory and shared.
- Update documentation to include a note on huge memory regions registration and remove not needed info.
- Removed "pci/shpc: Move function to generic header file" since it appears in latest maintainer pull request
- Rebased on master
V6 -> V7:
- Addressed Philippe Mathieu-Daudé comments
- modified pow2roundup32 signature
- added his RB tag (thanks)
- Addressed Corenlia Huck comments:
- Compiled the pvrdma for all archs and not only x86/arm (thanks)
- Fixed typo in documentation
- Rebased on latest master
V5 -> V6:
- Found a ppc machine and solved ppc compilation issues
- Tried to fix the s390x issue (still looking of a machine)
V4 -> V5:
- Fixed (at least tried to) compilation issues
V3 -> V4:
- Fixed documentation (added more impl details)
- Fixed compilation errors discovered by patchew.
- Addressed Michael S. Tsirkin comments:
- Removed unnecessary typedefs and replace them with macros in VMware header files, together with explanations.
- Moved more code from vmw specific to rdma generic code.
- Added page size limitations to the documentation.
V2 -> V3:
- Addressed Michael S. Tsirkin and Philippe Mathieu-Daudé comments:
- Moved the device to hw/rdma
- Addressed Michael S. Tsirkin comments:
- Split the code into generic (hw/rdma) and VMWare specific (hw/rdma/vmw)
- Added more details to documentation - VMware guest-host protocol.
- Remove mad processing
- limited the memory the Guest can pin.
- Addressed Philippe Mathieu-Daudé comment:
- s/roundup_pow_of_two/pow2roundup32 and move it to qemu/host-utils.h
- Added Shamit Rabinovici's review to documentation
- Rebased to latest master
RFC -> V2:
- Full implementation of the pvrdma device
- Backend is an ibdevice interface, no need for the KDBR module
General description
===================
PVRDMA is the QEMU implementation of VMware's paravirtualized RDMA device. It works with its Linux Kernel driver AS IS, no need for any special guest modifications.
While it complies with the VMware device, it can also communicate with bare metal RDMA-enabled machines and does not require an RDMA HCA in the host, it can work with Soft-RoCE (rxe).
It does not require the whole guest RAM to be pinned allowing memory over-commit and, even if not implemented yet, migration support will be possible with some HW assistance.
Design
======
- Follows the behavior of VMware's pvrdma device, however is not tightly coupled with it and most of the code can be reused if we decide to continue to a Virtio based RDMA device.
- It exposes 3 BARs:
BAR 0 - MSIX, utilize 3 vectors for command ring, async events and
completions
BAR 1 - Configuration of registers
BAR 2 - UAR, used to pass HW commands from driver.
- The device performs internal management of the RDMA resources (PDs, CQs, QPs, ...), meaning the objects are not directly coupled to a physical RDMA device resources.
The pvrdma backend is an ibdevice interface that can be exposed either by a Soft-RoCE(rxe) device on machines with no RDMA device, or an HCA SRIOV function(VF/PF).
Note that ibdevice interfaces can't be shared between pvrdma devices, each one requiring a separate instance (rxe or SRIOV VF).
Tests and performance
=====================
Tested with SoftRoCE backend (rxe)/Mellanox ConnectX3, and Mellanox ConnectX4 HCAs with:
- VMs in the same host
- VMs in different hosts
- VMs to bare metal.
The best performance achieved with ConnectX HCAs and buffer size bigger than 1MB which was the line rate ~ 50Gb/s.
The conclusion is that using the PVRDMA device there are no actual performance penalties compared to bare metal for big enough buffers (which is quite common when using RDMA), while allowing memory overcommit.
Marcel Apfelbaum (3):
mem: add share parameter to memory-backend-ram
docs: add pvrdma device documentation.
MAINTAINERS: add entry for hw/rdma
Yuval Shaia (1):
pvrdma: initial implementation
MAINTAINERS | 8 + Makefile.objs | 2 + backends/hostmem-file.c | 25 +- backends/hostmem-ram.c | 4 +- backends/hostmem.c | 21 ++ configure | 9 +- docs/pvrdma.txt | 255 +++++++++++++ exec.c | 26 +- hw/Makefile.objs | 1 + hw/rdma/Makefile.objs | 6 + hw/rdma/rdma_backend.c | 818 ++++++++++++++++++++++++++++++++++++++++++ hw/rdma/rdma_backend.h | 99 +++++ hw/rdma/rdma_backend_defs.h | 62 ++++ hw/rdma/rdma_rm.c | 544 ++++++++++++++++++++++++++++ hw/rdma/rdma_rm.h | 69 ++++ hw/rdma/rdma_rm_defs.h | 104 ++++++ hw/rdma/rdma_utils.c | 52 +++ hw/rdma/rdma_utils.h | 43 +++ hw/rdma/trace-events | 5 + hw/rdma/vmw/pvrdma.h | 122 +++++++ hw/rdma/vmw/pvrdma_cmd.c | 656 +++++++++++++++++++++++++++++++++ hw/rdma/vmw/pvrdma_dev_api.h | 602 +++++++++++++++++++++++++++++++ hw/rdma/vmw/pvrdma_dev_ring.c | 140 ++++++++ hw/rdma/vmw/pvrdma_dev_ring.h | 42 +++ hw/rdma/vmw/pvrdma_ib_verbs.h | 433 ++++++++++++++++++++++ hw/rdma/vmw/pvrdma_main.c | 653 +++++++++++++++++++++++++++++++++ hw/rdma/vmw/pvrdma_qp_ops.c | 212 +++++++++++ hw/rdma/vmw/pvrdma_qp_ops.h | 27 ++ hw/rdma/vmw/pvrdma_ring.h | 134 +++++++ hw/rdma/vmw/trace-events | 5 + hw/rdma/vmw/vmw_pvrdma-abi.h | 311 ++++++++++++++++ include/exec/memory.h | 23 ++ include/exec/ram_addr.h | 3 +- include/hw/pci/pci_ids.h | 3 + include/qemu/osdep.h | 2 +- include/sysemu/hostmem.h | 2 +- include/sysemu/kvm.h | 2 +- memory.c | 16 +- qemu-options.hx | 10 +- target/s390x/kvm.c | 4 +- util/oslib-posix.c | 4 +- util/oslib-win32.c | 2 +- 42 files changed, 5507 insertions(+), 54 deletions(-) create mode 100644 docs/pvrdma.txt create mode 100644 hw/rdma/Makefile.objs create mode 100644 hw/rdma/rdma_backend.c create mode 100644 hw/rdma/rdma_backend.h create mode 100644 hw/rdma/rdma_backend_defs.h create mode 100644 hw/rdma/rdma_rm.c create mode 100644 hw/rdma/rdma_rm.h create mode 100644 hw/rdma/rdma_rm_defs.h create mode 100644 hw/rdma/rdma_utils.c create mode 100644 hw/rdma/rdma_utils.h create mode 100644 hw/rdma/trace-events create mode 100644 hw/rdma/vmw/pvrdma.h create mode 100644 hw/rdma/vmw/pvrdma_cmd.c create mode 100644 hw/rdma/vmw/pvrdma_dev_api.h create mode 100644 hw/rdma/vmw/pvrdma_dev_ring.c create mode 100644 hw/rdma/vmw/pvrdma_dev_ring.h create mode 100644 hw/rdma/vmw/pvrdma_ib_verbs.h create mode 100644 hw/rdma/vmw/pvrdma_main.c create mode 100644 hw/rdma/vmw/pvrdma_qp_ops.c create mode 100644 hw/rdma/vmw/pvrdma_qp_ops.h create mode 100644 hw/rdma/vmw/pvrdma_ring.h create mode 100644 hw/rdma/vmw/trace-events create mode 100644 hw/rdma/vmw/vmw_pvrdma-abi.h
Signature · 1 line
2.13.5
PATCH v9 1/4 mem: add share parameter to memory-backend-ram
Currently only file backed memory backend can be created with a "share" flag in order to allow sharing guest RAM with other processes in the host.
Add the "share" flag also to RAM Memory Backend
in order to allow remapping parts of the guest RAM to different host virtual addresses. This is needed by the RDMA devices in order to remap non-contiguous QEMU virtual addresses to a contiguous virtual address range.
Moved the "share" flag to the Host Memory base class, modified phys_mem_alloc to include the new parameter and a new interface memory_region_init_ram_shared_nomigrate.
There are no functional changes if the new flag is not used.
--- backends/hostmem-file.c | 25 +------------------------ backends/hostmem-ram.c | 4 ++-- backends/hostmem.c | 21 +++++++++++++++++++++ exec.c | 26 +++++++++++++++----------- include/exec/memory.h | 23 +++++++++++++++++++++++ include/exec/ram_addr.h | 3 ++- include/qemu/osdep.h | 2 +- include/sysemu/hostmem.h | 2 +- include/sysemu/kvm.h | 2 +- memory.c | 16 +++++++++++++--- qemu-options.hx | 10 +++++++++- target/s390x/kvm.c | 4 ++-- util/oslib-posix.c | 4 ++-- util/oslib-win32.c | 2 +- 14 files changed, 94 insertions(+), 50 deletions(-)
backends/hostmem-file.c +1 -24
@@ -31,7 +31,6 @@ typedef struct HostMemoryBackendFile HostMemoryBackendFile;struct HostMemoryBackendFile {HostMemoryBackend parent_obj; -bool share;bool discard_data;char *mem_path;uint64_t align;
@@ -59,7 +58,7 @@ file_backend_memory_alloc(HostMemoryBackend *backend, Error **errp) path =object_get_canonical_path (OBJECT (backend));memory_region_init_ram_from_file (&backend->mr,OBJECT (backend), path, - backend->size, fb->align, fb->share, + backend->size, fb->align, backend->share, fb->mem_path, errp);g_free (path); }
@@ -86,25 +85,6 @@ static void set_mem_path(Object *o, const char *str, Error **errp) fb->mem_path =g_strdup (str); } -static bool file_memory_backend_get_share (Object *o,Error **errp) -{ -HostMemoryBackendFile *fb =MEMORY_BACKEND_FILE (o); - -return fb->share; -} - -static void file_memory_backend_set_share (Object *o,bool value,Error **errp) -{ -HostMemoryBackend *backend =MEMORY_BACKEND (o); -HostMemoryBackendFile *fb =MEMORY_BACKEND_FILE (o); - -if (host_memory_backend_mr_inited (backend)) { -error_setg (errp,"cannot change property value" ); -return ; - } - fb->share = value; -} -static bool file_memory_backend_get_discard_data (Object *o,Error **errp) {return MEMORY_BACKEND_FILE (o)->discard_data;
@@ -171,9 +151,6 @@ file_backend_class_init(ObjectClass *oc, void *data) bc->alloc = file_backend_memory_alloc; oc->unparent = file_backend_unparent; -object_class_property_add_bool (oc,"share" , - file_memory_backend_get_share, file_memory_backend_set_share, - &error_abort);object_class_property_add_bool (oc,"discard-data" , file_memory_backend_get_discard_data, file_memory_backend_set_discard_data, &error_abort);
backends/hostmem-ram.c +2 -2
@@ -28,8 +28,8 @@ ram_backend_memory_alloc(HostMemoryBackend *backend, Error **errp) } path =object_get_canonical_path_component (OBJECT (backend)); -memory_region_init_ram_nomigrate (&backend->mr,OBJECT (backend), path, - backend->size, errp); +memory_region_init_ram_shared_nomigrate (&backend->mr,OBJECT (backend), path, + backend->size, backend->share, errp);g_free (path); }
backends/hostmem.c +21 -0
@@ -369,6 +369,24 @@ static void set_id(Object *o, const char *str, Error **errp) backend->id =g_strdup (str); } +static bool host_memory_backend_get_share (Object *o,Error **errp) +{ +HostMemoryBackend *backend =MEMORY_BACKEND (o); + +return backend->share; +} + +static void host_memory_backend_set_share (Object *o,bool value,Error **errp) +{ +HostMemoryBackend *backend =MEMORY_BACKEND (o); + +if (host_memory_backend_mr_inited (backend)) { +error_setg (errp,"cannot change property value" ); +return ; + } + backend->share = value; +} +static void host_memory_backend_class_init (ObjectClass *oc,void *data) {
@@ -399,6 +417,9 @@ host_memory_backend_class_init(ObjectClass *oc, void *data) host_memory_backend_get_policy, host_memory_backend_set_policy, &error_abort);object_class_property_add_str (oc,"id" , get_id, set_id, &error_abort); +object_class_property_add_bool (oc,"share" , + host_memory_backend_get_share, host_memory_backend_set_share, + &error_abort); }static void host_memory_backend_finalize (Object *o)
exec.c +15 -11
@@ -1285,7 +1285,7 @@ static int subpage_register (subpage_t *mmio, uint32_t start, uint32_t end, uint16_t section);static subpage_t *subpage_init (FlatView *fv,hwaddr base); -static void *(*phys_mem_alloc)(size_t size,uint64_t *align) = +static void *(*phys_mem_alloc)(size_t size,uint64_t *align,bool shared) = qemu_anon_ram_alloc;/*
@@ -1293,7 +1293,7 @@ static void *(*phys_mem_alloc)(size_t size, uint64_t *align) =* Accelerators with unusual needs may need this. Hopefully, we can * get rid of it eventually. */ -void phys_mem_set_alloc (void *(*alloc)(size_t ,uint64_t *align)) +void phys_mem_set_alloc (void *(*alloc)(size_t ,uint64_t *align,bool shared)) { phys_mem_alloc = alloc; }
@@ -1921,7 +1921,7 @@ static void dirty_memory_extend(ram_addr_t old_ram_size, } } -static void ram_block_add (RAMBlock *new_block,Error **errp) +static void ram_block_add (RAMBlock *new_block,Error **errp,bool shared) {RAMBlock *block;RAMBlock *last_block =NULL ;
@@ -1944,7 +1944,7 @@ static void ram_block_add(RAMBlock *new_block, Error **errp) } }else { new_block->host =phys_mem_alloc (new_block->max_length, - &new_block->mr->align); + &new_block->mr->align, shared);if (!new_block->host) { error_setg_errno(errp, errno, "cannot set up guest memory '%s'",
@@ -2049,7 +2049,7 @@ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr,return NULL ; } -ram_block_add (new_block, &local_err); +ram_block_add (new_block, &local_err, share);if (local_err) {g_free (new_block);error_propagate (errp, local_err);
@@ -2091,7 +2091,7 @@ RAMBlock *qemu_ram_alloc_internal(ram_addr_t size, ram_addr_t max_size,void (*resized)(const char *,uint64_t length,void *host), - void *host, bool resizeable, + void *host, bool resizeable, bool share, MemoryRegion *mr, Error **errp) { RAMBlock *new_block;
@@ -2114,7 +2114,7 @@ RAMBlock *qemu_ram_alloc_internal(ram_addr_t size, ram_addr_t max_size,if (resizeable) { new_block->flags |=RAM_RESIZEABLE ; } -ram_block_add (new_block, &local_err); +ram_block_add (new_block, &local_err, share);if (local_err) {g_free (new_block);error_propagate (errp, local_err);
@@ -2126,12 +2126,15 @@ RAMBlock *qemu_ram_alloc_internal(ram_addr_t size, ram_addr_t max_size,RAMBlock *qemu_ram_alloc_from_ptr (ram_addr_t size,void *host,MemoryRegion *mr,Error **errp) { -return qemu_ram_alloc_internal (size, size,NULL , host, false, mr, errp); +return qemu_ram_alloc_internal (size, size,NULL , host, false, + false, mr, errp); } -RAMBlock *qemu_ram_alloc (ram_addr_t size,MemoryRegion *mr,Error **errp) +RAMBlock *qemu_ram_alloc (ram_addr_t size,bool share, +MemoryRegion *mr,Error **errp) { -return qemu_ram_alloc_internal (size, size,NULL ,NULL , false, mr, errp); +return qemu_ram_alloc_internal (size, size,NULL ,NULL , false, + share, mr, errp); } RAMBlock *qemu_ram_alloc_resizeable(ram_addr_t size, ram_addr_t maxsz,
@@ -2140,7 +2143,8 @@ RAMBlock *qemu_ram_alloc_resizeable(ram_addr_t size, ram_addr_t maxsz, void *host), MemoryRegion *mr, Error **errp) { - return qemu_ram_alloc_internal(size, maxsz, resized, NULL, true, mr, errp); + return qemu_ram_alloc_internal(size, maxsz, resized, NULL, true, +false ,mr ,errp ); }static void reclaim_ramblock (RAMBlock *block)
include/exec/memory.h +23 -0
@@ -428,6 +428,29 @@ void memory_region_init_ram_nomigrate(MemoryRegion *mr, Error **errp);/** +* memory_region_init_ram_shared_nomigrate: Initialize RAM memory region. +* Accesses into the region will +* modify memory directly. +* +* @mr: the #MemoryRegion to be initialized. +* @owner: the object that tracks the region's reference count +* @name: Region name, becomes part of RAMBlock name used in migration stream +* must be unique within any device +* @size: size of the region. +* @share: allow remapping RAM to different addresses +* @errp: pointer to Error*, to store an error if it happens. +* +* Note that this function is similar to memory_region_init_ram_nomigrate. +* The only difference is part of the RAM region can be remapped. +*/ +void memory_region_init_ram_shared_nomigrate (MemoryRegion *mr, +struct Object *owner, +const char *name, +uint64_t size, +bool share, +Error **errp); + +/** * memory_region_init_resizeable_ram: Initialize memory region with resizeable * RAM. Accesses into the region will * modify memory directly. Only an initial
include/exec/ram_addr.h +2 -1
@@ -80,7 +80,8 @@ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr, Error **errp);RAMBlock *qemu_ram_alloc_from_ptr (ram_addr_t size,void *host,MemoryRegion *mr,Error **errp); -RAMBlock *qemu_ram_alloc (ram_addr_t size,MemoryRegion *mr,Error **errp); +RAMBlock *qemu_ram_alloc (ram_addr_t size,bool share,MemoryRegion *mr, +Error **errp); RAMBlock *qemu_ram_alloc_resizeable(ram_addr_t size, ram_addr_t max_size, void (*resized)(const char*, uint64_t length,
include/qemu/osdep.h +1 -1
@@ -255,7 +255,7 @@ extern int daemon(int, int);int qemu_daemon (int nochdir,int noclose);void *qemu_try_memalign (size_t alignment,size_t size);void *qemu_memalign (size_t alignment,size_t size); -void *qemu_anon_ram_alloc (size_t size,uint64_t *align); +void *qemu_anon_ram_alloc (size_t size,uint64_t *align,bool shared);void qemu_vfree (void *ptr);void qemu_anon_ram_free (void *ptr,size_t size);
include/sysemu/hostmem.h +1 -1
@@ -55,7 +55,7 @@ struct HostMemoryBackend {char *id;uint64_t size;bool merge, dump; -bool prealloc, force_prealloc, is_mapped; +bool prealloc, force_prealloc, is_mapped, share;DECLARE_BITMAP (host_nodes,MAX_NODES +1 );HostMemPolicy policy;
include/sysemu/kvm.h +1 -1
@@ -248,7 +248,7 @@ int kvm_on_sigbus(int code, void *addr);/* interface with exec.c */ -void phys_mem_set_alloc (void *(*alloc)(size_t ,uint64_t *align)); +void phys_mem_set_alloc (void *(*alloc)(size_t ,uint64_t *align,bool shared));/* internal API */
memory.c +13 -3
@@ -1538,11 +1538,21 @@ void memory_region_init_ram_nomigrate(MemoryRegion *mr,uint64_t size, Error **errp) { +memory_region_init_ram_shared_nomigrate (mr ,owner ,name ,size ,false ,errp ); +} + +void memory_region_init_ram_shared_nomigrate (MemoryRegion *mr, +Object *owner, +const char *name, +uint64_t size, +bool share, +Error **errp) +{memory_region_init (mr, owner, name, size); mr->ram = true; mr->terminates = true; mr->destructor = memory_region_destructor_ram; - mr->ram_block =qemu_ram_alloc (size, mr, errp); + mr->ram_block =qemu_ram_alloc (size, share, mr, errp); mr->dirty_log_mask =tcg_enabled () ? (1 <<DIRTY_MEMORY_CODE ) :0 ; }
@@ -1653,7 +1663,7 @@ void memory_region_init_rom_nomigrate(MemoryRegion *mr, mr->readonly = true; mr->terminates = true; mr->destructor = memory_region_destructor_ram; - mr->ram_block =qemu_ram_alloc (size, mr, errp); + mr->ram_block =qemu_ram_alloc (size, false, mr, errp); mr->dirty_log_mask =tcg_enabled () ? (1 <<DIRTY_MEMORY_CODE ) :0 ; }
@@ -1672,7 +1682,7 @@ void memory_region_init_rom_device_nomigrate(MemoryRegion *mr, mr->terminates = true; mr->rom_device = true; mr->destructor = memory_region_destructor_ram; - mr->ram_block =qemu_ram_alloc (size, mr, errp); + mr->ram_block =qemu_ram_alloc (size, false, mr, errp); } void memory_region_init_iommu(void *_iommu_mr,
qemu-options.hx +9 -1
@@ -3975,6 +3975,14 @@ The @option{share} boolean option determines whether the memory region is marked as private to QEMU, or shared. The latter allows a co-operating external process to access the QEMU memory region. +The @option{share} is also required for pvrdma devices due to +limitations in the RDMA API provided by Linux. + +Setting share=on might affect the ability to configure NUMA +bindings for the memory backend under some circumstances, see +Documentation/vm/numa_memory_policy.txt on the Linux kernel +source tree for additional details. + Setting the @option{discard-data} boolean option to @var{on} indicates that file contents can be destroyed when QEMU exits, to avoid unnecessarily flushing data to the backing file. Note
@@ -4017,7 +4025,7 @@ requires an alignment different than the default one used by QEMU, eg the device DAX /dev/dax0.0 requires 2M alignment rather than 4K. In such cases, users can specify the required alignment via this option. -@item -object memory-backend-ram,id=@var{id},merge=@var{on|off},dump=@var{on|off},prealloc=@var{on|off},size=@var{size},host-nodes=@var{host-nodes},policy=@var{default|preferred|bind|interleave} +@item -object memory-backend-ram,id=@var{id},merge=@var{on|off},dump=@var{on|off},share=@var{on|off},prealloc=@var{on|off},size=@var{size},host-nodes=@var{host-nodes},policy=@var{default|preferred|bind|interleave} Creates a memory backend object, which can be used to back the guest RAM. Memory backend objects offer more control than the @option{-m} option that is
target/s390x/kvm.c +2 -2
@@ -144,7 +144,7 @@ static int cap_gs;static int active_cmma; -static void *legacy_s390_alloc (size_t size,uint64_t *align); +static void *legacy_s390_alloc (size_t size,uint64_t *align,bool shared);static int kvm_s390_query_mem_limit (uint64_t *memory_limit) {
@@ -752,7 +752,7 @@ int kvm_s390_mem_op(S390CPU *cpu, vaddr addr, uint8_t ar, void *hostbuf,* to grow. We also have to use MAP parameters that avoid * read-only mapping of guest pages. */ -static void *legacy_s390_alloc (size_t size,uint64_t *align) +static void *legacy_s390_alloc (size_t size,uint64_t *align,bool shared) {void *mem;
util/oslib-posix.c +2 -2
@@ -127,10 +127,10 @@ void *qemu_memalign(size_t alignment, size_t size) }/* alloc shared memory pages */ -void *qemu_anon_ram_alloc (size_t size,uint64_t *alignment) +void *qemu_anon_ram_alloc (size_t size,uint64_t *alignment,bool shared) {size_t align =QEMU_VMALLOC_ALIGN ; -void *ptr =qemu_ram_mmap (-1 , size, align, false); +void *ptr =qemu_ram_mmap (-1 , size, align, shared);if (ptr ==MAP_FAILED ) {return NULL ;
util/oslib-win32.c +1 -1
@@ -67,7 +67,7 @@ void *qemu_memalign(size_t alignment, size_t size)return qemu_oom_check (qemu_try_memalign (alignment, size)); } -void *qemu_anon_ram_alloc (size_t size,uint64_t *align) +void *qemu_anon_ram_alloc (size_t size,uint64_t *align,bool shared) {void *ptr;
Signature · 1 line
2.13.5
Re: [Qemu-devel] [PATCH V9 1/4] mem: add share parameter to memory-backend-ram
Quoted 10 lines · Marcel Apfelbaum
Currently only file backed memory backend can be created with a "share" flag in order to allow sharing guest RAM with other processes in the host.
Add the "share" flag also to RAM Memory Backend
in order to allow remapping parts of the guest RAM to different host virtual addresses. This is needed by the RDMA devices in order to remap non-contiguous QEMU virtual addresses to a contiguous virtual address range.
Quoted 7 lines
Moved the "share" flag to the Host Memory base class, modified
phys_mem_allocto include the new parameter and a new interfacememory_region_init_ram_shared_nomigrate.There are no functional changes if the new flag is not used.
Signed-off-by Marcel Apfelbaum <[email protected]>
Code looks correct, so:
But later can we please stop the explosion of memory_init_ram*() functions and replace them with a single function with a flags parameter?
Signature · 1 line
Eduardo
Re: [Qemu-devel] [PATCH V9 1/4] mem: add share parameter to memory-backend-ram
Hi Eduardo,
[This is a re-send, I didn't see the response
on the mailing list, sorry for the spam]
Quoted 15 lines · Eduardo Habkost
Quoted 14 lines · Marcel Apfelbaum
Currently only file backed memory backend can be created with a "share" flag in order to allow sharing guest RAM with other processes in the host.
Add the "share" flag also to RAM Memory Backend
in order to allow remapping parts of the guest RAM to different host virtual addresses. This is needed by the RDMA devices in order to remap non-contiguous QEMU virtual addresses to a contiguous virtual address range.Moved the "share" flag to the Host Memory base class, modified
phys_mem_allocto include the new parameter and a new interfacememory_region_init_ram_shared_nomigrate.
Quoted 8 lines
Quoted 3 lines
There are no functional changes if the new flag is not used.
Signed-off-by Marcel Apfelbaum <[email protected]>Code looks correct, so:
Reviewed-by Eduardo Habkost <[email protected]>
Appreciated!
Quoted 4 lines
But later can we please stop the explosion of memory_init_ram*() functions and replace them with a single function with a flags parameter?
Sounds reasonable.
Thanks,
Marcel
PATCH v9 2/4 docs: add pvrdma device documentation.
In reply to Marcel Apfelbaum--- docs/pvrdma.txt | 255 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 255 insertions(+) create mode 100644 docs/pvrdma.txt
docs/pvrdma.txt new file +255 -0
@@ -0,0 +1,255 @@ +Paravirtualized RDMA Device (PVRDMA) +==================================== + + +1. Description +=============== +PVRDMA is the QEMU implementation of VMware's paravirtualized RDMA device. +It works with its Linux Kernel driver AS IS, no need for any special guest +modifications. + +While it complies with the VMware device, it can also communicate with bare +metal RDMA-enabled machines and does not require an RDMA HCA in the host, it +can work with Soft-RoCE (rxe). + +It does not require the whole guest RAM to be pinned allowing memory +over-commit and, even if not implemented yet, migration support will be +possible with some HW assistance. + +A project presentation accompany this document: +- http://events.linuxfoundation.org/sites/events/files/slides/lpc-2017-pvrdma-marcel-apfelbaum-yuval-shaia.pdf + + + +2. Setup +======== + + +2.1 Guest setup +=============== +Fedora 27+ kernels work out of the box, older distributions +require updating the kernel to 4.14 to include the pvrdma driver. + +However the libpvrdma library needed by User Level Software is still +not available as part of the distributions, so the rdma-core library +needs to be compiled and optionally installed. + +Please follow the instructions at: + https://github.com/linux-rdma/rdma-core.git + + +2.2 Host Setup +============== +The pvrdma backend is an ibdevice interface that can be exposed +either by a Soft-RoCE(rxe) device on machines with no RDMA device, +or an HCA SRIOV function(VF/PF). +Note that ibdevice interfaces can't be shared between pvrdma devices, +each one requiring a separate instance (rxe or SRIOV VF). + + +2.2.1 Soft-RoCE backend(rxe) +=========================== +A stable version of rxe is required, Fedora 27+ or a Linux +Kernel 4.14+ is preferred. + +The rdma_rxe module is part of the Linux Kernel but not loaded by default. +Install the User Level library (librxe) following the instructions from: +https://github.com/SoftRoCE/rxe-dev/wiki/rxe-dev:-Home + +Associate an ETH interface with rxe by running: + rxe_cfg add eth0 +An rxe0 ibdevice interface will be created and can be used as pvrdma backend. + + +2.2.2 RDMA device Virtual Function backend +========================================== +Nothing special is required, the pvrdma device can work not only with +Ethernet Links, but also Infinibands Links. +All is needed is an ibdevice with an active port, for Mellanox cards +will be something like mlx5_6 which can be the backend. + + +2.2.3 QEMU setup +================ +Configure QEMU with --enable-rdma flag, installing +the required RDMA libraries. + + + +3. Usage +======== +Currently the device is working only with memory backed RAM +and it must be mark as "shared": + -m 1G \ + -object memory-backend-ram,id=mb1,size=1G,share \ + -numa node,memdev=mb1 \ + +The pvrdma device is composed of two functions: + - Function 0 is a vmxnet Ethernet Device which is redundant in Guest + but is required to pass the ibdevice GID using its MAC. + Examples: + For an rxe backend using eth0 interface it will use its mac: + -device vmxnet3,addr=<slot>.0,multifunction=on,mac=<eth0 MAC> + For an SRIOV VF, we take the Ethernet Interface exposed by it: + -device vmxnet3,multifunction=on,mac=<RoCE eth MAC> + - Function 1 is the actual device: + -device pvrdma,addr=<slot>.1,backend-dev=<ibdevice>,backend-gid-idx=<gid>,backend-port=<port> + where the ibdevice can be rxe or RDMA VF (e.g. mlx5_4) + Note: Pay special attention that the GID at backend-gid-idx matches vmxnet's MAC. + The rules of conversion are part of the RoCE spec, but since manual conversion + is not required, spotting problems is not hard: + Example: GID: fe80:0000:0000:0000:7efe:90ff:fecb:743a + MAC: 7c:fe:90:cb:74:3a + Note the difference between the first byte of the MAC and the GID. + + + +4. Implementation details +========================= + + +4.1 Overview +============ +The device acts like a proxy between the Guest Driver and the host +ibdevice interface. +On configuration path: + - For every hardware resource request (PD/QP/CQ/...) the pvrdma will request + a resource from the backend interface, maintaining a 1-1 mapping + between the guest and host. +On data path: + - Every post_send/receive received from the guest will be converted into + a post_send/receive for the backend. The buffers data will not be touched + or copied resulting in near bare-metal performance for large enough buffers. + - Completions from the backend interface will result in completions for + the pvrdma device. + + +4.2 PCI BARs +============ +PCI Bars: + BAR 0 - MSI-X + MSI-X vectors: + (0) Command - used when execution of a command is completed. + (1) Async - not in use. + (2) Completion - used when a completion event is placed in + device's CQ ring. + BAR 1 - Registers + -------------------------------------------------------- + | VERSION | DSR | CTL | REQ | ERR | ICR | IMR | MAC | + -------------------------------------------------------- + DSR - Address of driver/device shared memory used + for the command channel, used for passing: + - General info such as driver version + - Address of 'command' and 'response' + - Address of async ring + - Address of device's CQ ring + - Device capabilities + CTL - Device control operations (activate, reset etc) + IMG - Set interrupt mask + REQ - Command execution register + ERR - Operation status + + BAR 2 - UAR + --------------------------------------------------------- + | QP_NUM | SEND/RECV Flag || CQ_NUM | ARM/POLL Flag | + --------------------------------------------------------- + - Offset 0 used for QP operations (send and recv) + - Offset 4 used for CQ operations (arm and poll) + + +4.3 Major flows +=============== + +4.3.1 Create CQ +=============== + - Guest driver + - Allocates pages for CQ ring + - Creates page directory (pdir) to hold CQ ring's pages + - Initializes CQ ring + - Initializes 'Create CQ' command object (cqe, pdir etc) + - Copies the command to 'command' address + - Writes 0 into REQ register + - Device + - Reads the request object from the 'command' address + - Allocates CQ object and initialize CQ ring based on pdir + - Creates the backend CQ + - Writes operation status to ERR register + - Posts command-interrupt to guest + - Guest driver + - Reads the HW response code from ERR register + +4.3.2 Create QP +=============== + - Guest driver + - Allocates pages for send and receive rings + - Creates page directory(pdir) to hold the ring's pages + - Initializes 'Create QP' command object (max_send_wr, + send_cq_handle, recv_cq_handle, pdir etc) + - Copies the object to 'command' address + - Write 0 into REQ register + - Device + - Reads the request object from 'command' address + - Allocates the QP object and initialize + - Send and recv rings based on pdir + - Send and recv ring state + - Creates the backend QP + - Writes the operation status to ERR register + - Posts command-interrupt to guest + - Guest driver + - Reads the HW response code from ERR register + +4.3.3 Post receive +================== + - Guest driver + - Initializes a wqe and place it on recv ring + - Write to qpn|qp_recv_bit (31) to QP offset in UAR + - Device + - Extracts qpn from UAR + - Walks through the ring and does the following for each wqe + - Prepares the backend CQE context to be used when + receiving completion from backend (wr_id, op_code, emu_cq_num) + - For each sge prepares backend sge + - Calls backend's post_recv + +4.3.4 Process backend events +============================ + - Done by a dedicated thread used to process backend events; + at initialization is attached to the device and creates + the communication channel. + - Thread main loop: + - Polls for completions + - Extracts QEMU _cq_num, wr_id and op_code from context + - Writes CQE to CQ ring + - Writes CQ number to device CQ + - Sends completion-interrupt to guest + - Deallocates context + - Acks the event to backend + + + +5. Limitations +============== +- The device obviously is limited by the Guest Linux Driver features implementation + of the VMware device API. +- Memory registration mechanism requires mremap for every page in the buffer in order + to map it to a contiguous virtual address range. Since this is not the data path + it should not matter much. If the default max mr size is increased, be aware that + memory registration can take up to 0.5 seconds for 1GB of memory. +- The device requires target page size to be the same as the host page size, + otherwise it will fail to init. +- QEMU cannot map guest RAM from a file descriptor if a pvrdma device is attached, + so it can't work with huge pages. The limitation will be addressed in the future, + however QEMU allocates Guest RAM with MADV_HUGEPAGE so if there are enough huge + pages available, QEMU will use them. QEMU will fail to init if the requirements + are not met. + + + +6. Performance +============== +By design the pvrdma device exits on each post-send/receive, so for small buffers +the performance is affected; however for medium buffers it will became close to +bare metal and from 1MB buffers and up it reaches bare metal performance. +(tested with 2 VMs, the pvrdma devices connected to 2 VFs of the same device) + +All the above assumes no memory registration is done on data path.
Signature · 1 line
2.13.5
PATCH v9 3/4 pvrdma: initial implementation
In reply to Marcel ApfelbaumFrom: Yuval Shaia <[email protected]>
PVRDMA is the QEMU implementation of VMware's paravirtualized RDMA device. It works with its Linux Kernel driver AS IS, no need for any special guest modifications.
While it complies with the VMware device, it can also communicate with bare metal RDMA-enabled machines and does not require an RDMA HCA in the host, it can work with Soft-RoCE (rxe).
It does not require the whole guest RAM to be pinned allowing memory over-commit and, even if not implemented yet, migration support will be possible with some HW assistance.
--- Makefile.objs | 2 + configure | 9 +- hw/Makefile.objs | 1 + hw/rdma/Makefile.objs | 6 + hw/rdma/rdma_backend.c | 818 ++++++++++++++++++++++++++++++++++++++++++ hw/rdma/rdma_backend.h | 99 +++++ hw/rdma/rdma_backend_defs.h | 62 ++++ hw/rdma/rdma_rm.c | 544 ++++++++++++++++++++++++++++ hw/rdma/rdma_rm.h | 69 ++++ hw/rdma/rdma_rm_defs.h | 104 ++++++ hw/rdma/rdma_utils.c | 52 +++ hw/rdma/rdma_utils.h | 43 +++ hw/rdma/trace-events | 5 + hw/rdma/vmw/pvrdma.h | 122 +++++++ hw/rdma/vmw/pvrdma_cmd.c | 656 +++++++++++++++++++++++++++++++++ hw/rdma/vmw/pvrdma_dev_api.h | 602 +++++++++++++++++++++++++++++++ hw/rdma/vmw/pvrdma_dev_ring.c | 140 ++++++++ hw/rdma/vmw/pvrdma_dev_ring.h | 42 +++ hw/rdma/vmw/pvrdma_ib_verbs.h | 433 ++++++++++++++++++++++ hw/rdma/vmw/pvrdma_main.c | 653 +++++++++++++++++++++++++++++++++ hw/rdma/vmw/pvrdma_qp_ops.c | 212 +++++++++++ hw/rdma/vmw/pvrdma_qp_ops.h | 27 ++ hw/rdma/vmw/pvrdma_ring.h | 134 +++++++ hw/rdma/vmw/trace-events | 5 + hw/rdma/vmw/vmw_pvrdma-abi.h | 311 ++++++++++++++++ include/hw/pci/pci_ids.h | 3 + 26 files changed, 5150 insertions(+), 4 deletions(-) create mode 100644 hw/rdma/Makefile.objs create mode 100644 hw/rdma/rdma_backend.c create mode 100644 hw/rdma/rdma_backend.h create mode 100644 hw/rdma/rdma_backend_defs.h create mode 100644 hw/rdma/rdma_rm.c create mode 100644 hw/rdma/rdma_rm.h create mode 100644 hw/rdma/rdma_rm_defs.h create mode 100644 hw/rdma/rdma_utils.c create mode 100644 hw/rdma/rdma_utils.h create mode 100644 hw/rdma/trace-events create mode 100644 hw/rdma/vmw/pvrdma.h create mode 100644 hw/rdma/vmw/pvrdma_cmd.c create mode 100644 hw/rdma/vmw/pvrdma_dev_api.h create mode 100644 hw/rdma/vmw/pvrdma_dev_ring.c create mode 100644 hw/rdma/vmw/pvrdma_dev_ring.h create mode 100644 hw/rdma/vmw/pvrdma_ib_verbs.h create mode 100644 hw/rdma/vmw/pvrdma_main.c create mode 100644 hw/rdma/vmw/pvrdma_qp_ops.c create mode 100644 hw/rdma/vmw/pvrdma_qp_ops.h create mode 100644 hw/rdma/vmw/pvrdma_ring.h create mode 100644 hw/rdma/vmw/trace-events create mode 100644 hw/rdma/vmw/vmw_pvrdma-abi.h
Makefile.objs +2 -0
@@ -130,6 +130,8 @@ trace-events-subdirs += hw/block/dataplane trace-events-subdirs += hw/char trace-events-subdirs += hw/intc trace-events-subdirs += hw/net +trace-events-subdirs += hw/rdma +trace-events-subdirs += hw/rdma/vmw trace-events-subdirs += hw/virtio trace-events-subdirs += hw/audio trace-events-subdirs += hw/misc
configure +5 -4
@@ -1553,7 +1553,7 @@ disabled with --disable-FEATURE, default is enabled if available: kvm KVM acceleration support hax HAX acceleration support hvf Hypervisor.framework acceleration support - rdma RDMA-based migration support + rdma Enable RDMA-based migration and PVRDMA support vde support for vde network netmap support for netmap network linux-aio Linux AIO support
@@ -2881,15 +2881,16 @@ if test "$rdma" != "no" ; then #include <rdma/rdma_cma.h> int main(void) { return 0; } EOF - rdma_libs="-lrdmacm -libverbs" + rdma_libs="-lrdmacm -libverbs -libumad" if compile_prog "" "$rdma_libs" ; then rdma="yes" + libs_softmmu="$libs_softmmu $rdma_libs" else if test "$rdma" = "yes" ; then error_exit \ - " OpenFabrics librdmacm/libibverbs not present." \ + " OpenFabrics librdmacm/libibverbs/libibumad not present." \ " Your options:" \ - " (1) Fast: Install infiniband packages from your distro." \ + " (1) Fast: Install infiniband packages (devel) from your distro." \ " (2) Cleanest: Install libraries from www.openfabrics.org" \ " (3) Also: Install softiwarp if you don't have RDMA hardware" fi
hw/Makefile.objs +1 -0
@@ -18,6 +18,7 @@ devices-dirs-$(CONFIG_IPMI) += ipmi/ devices-dirs-$(CONFIG_SOFTMMU) += isa/ devices-dirs-$(CONFIG_SOFTMMU) += misc/ devices-dirs-$(CONFIG_SOFTMMU) += net/ +devices-dirs-$(CONFIG_SOFTMMU) += rdma/ devices-dirs-$(CONFIG_SOFTMMU) += nvram/ devices-dirs-$(CONFIG_SOFTMMU) += pci/ devices-dirs-$(CONFIG_PCI) += pci-bridge/ pci-host/
hw/rdma/Makefile.objs new file +6 -0
@@ -0,0 +1,6 @@ +ifeq ($(CONFIG_RDMA),y) +obj-$(CONFIG_PCI) += rdma_utils.o rdma_backend.o rdma_rm.o +obj-$(CONFIG_PCI) += vmw/pvrdma_dev_ring.o vmw/pvrdma_cmd.o \ + vmw/pvrdma_qp_ops.o vmw/pvrdma_main.o +endif +
hw/rdma/rdma_backend.c new file +818 -0
818 lines not on this page · raw message
hw/rdma/rdma_backend.h new file +99 -0
99 lines not on this page · raw message
hw/rdma/rdma_backend_defs.h new file +62 -0
62 lines not on this page · raw message
hw/rdma/rdma_rm.c new file +544 -0
544 lines not on this page · raw message
hw/rdma/rdma_rm.h new file +69 -0
69 lines not on this page · raw message
hw/rdma/rdma_rm_defs.h new file +104 -0
104 lines not on this page · raw message
hw/rdma/rdma_utils.c new file +52 -0
52 lines not on this page · raw message
hw/rdma/rdma_utils.h new file +43 -0
43 lines not on this page · raw message
hw/rdma/trace-events new file +5 -0
@@ -0,0 +1,5 @@ +# See docs/tracing.txt for syntax documentation. + +#hw/rdma/rdma_backend.c +create_ah_cache_hit(uint64_t subnet, uint64_t net_id) "subnet = 0x%lx net_id = 0x%lx" +create_ah_cache_miss(uint64_t subnet, uint64_t net_id) "subnet = 0x%lx net_id = 0x%lx"
hw/rdma/vmw/pvrdma.h new file +122 -0
122 lines not on this page · raw message
hw/rdma/vmw/pvrdma_cmd.c new file +656 -0
656 lines not on this page · raw message
hw/rdma/vmw/pvrdma_dev_api.h new file +602 -0
378 lines not on this page · raw message
hw/rdma/vmw/pvrdma_dev_ring.c new file +140 -0
140 lines not on this page · raw message
hw/rdma/vmw/pvrdma_dev_ring.h new file +42 -0
42 lines not on this page · raw message
hw/rdma/vmw/pvrdma_ib_verbs.h new file +433 -0
433 lines not on this page · raw message
hw/rdma/vmw/pvrdma_main.c new file +653 -0
653 lines not on this page · raw message
hw/rdma/vmw/pvrdma_qp_ops.c new file +212 -0
212 lines not on this page · raw message
hw/rdma/vmw/pvrdma_ring.h new file +134 -0
134 lines not on this page · raw message
hw/rdma/vmw/vmw_pvrdma-abi.h new file +311 -0
311 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.13.5
Part of the diff is not shown here. View the raw message.
Re: [Qemu-devel] [PATCH V9 3/4] pvrdma: initial implementation
From: Marcel Apfelbaum <[email protected]>
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Sent: Thursday, February 1, 2018 10:55 PM
Subject: [Qemu-devel] [PATCH V9 3/4] pvrdma: initial implementation
From: Yuval Shaia <[email protected]>
PVRDMA is the QEMU implementation of VMware's paravirtualized RDMA device. It works with its Linux Kernel driver AS IS, no need for any special guest modifications.
While it complies with the VMware device, it can also communicate with bare metal RDMA-enabled machines and does not require an RDMA HCA in the host, it can work with Soft-RoCE (rxe).
It does not require the whole guest RAM to be pinned allowing memory over-commit and, even if not implemented yet, migration support will be possible with some HW assistance.
Re: [Qemu-devel] [PATCH V9 3/4] pvrdma: initial implementation
Quoted 2 lines · Dotan Barak
Reviewed-by Dotan Barak <[email protected]>
The Mellanox review for the RDMA code is very much appreciated!
Thanks Dotan, we know you put much effort into it and the V9 re-spin quality just went up :)
Marcel
Quoted 27 lines
------------------------------------------------------------------------------------------------------------------------
*From:* Marcel Apfelbaum <[email protected]>
*To:* [email protected]
*Cc:* [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
*Sent:* Thursday, February 1, 2018 10:55 PM
*Subject:* [Qemu-devel] [PATCH V9 3/4] pvrdma: initial implementationFrom: Yuval Shaia <[email protected] <mailto:[email protected]>>
PVRDMA is the QEMU implementation of VMware's paravirtualized RDMA device. It works with its Linux Kernel driver AS IS, no need for any special guest modifications.
While it complies with the VMware device, it can also communicate with bare metal RDMA-enabled machines and does not require an RDMA HCA in the host, it can work with Soft-RoCE (rxe).
It does not require the whole guest RAM to be pinned allowing memory over-commit and, even if not implemented yet, migration support will be possible with some HW assistance.
Signed-off-by Yuval Shaia <[email protected] <mailto:[email protected]>>Signed-off-by Marcel Apfelbaum <[email protected] <mailto:[email protected]>>
PATCH v9 4/4 MAINTAINERS: add entry for hw/rdma
In reply to Marcel Apfelbaum--- MAINTAINERS | 8 ++++++++ 1 file changed, 8 insertions(+)
MAINTAINERS +8 -0
@@ -1986,6 +1986,14 @@ F: block/replication.c F: tests/test-replication.c F: docs/block-replication.txt +PVRDMA +M: Yuval Shaia <[email protected]> +M: Marcel Apfelbaum <[email protected]> +S: Maintained +F: hw/rdma/* +F: hw/rdma/vmw/* +F: docs/pvrdma.txt + Build and test automation ------------------------- Build and test automation
Signature · 1 line
2.13.5