numam-spdk/lib/env_dpdk
Darek Stojaczyk a33e0943b0 memory: forbid registering a memory region more than once
Removed the reference count from the registrations map.

Although technically supported, registering a single memory
region more than once had a lot of unhandled cases and could
easily lead to a segfault.

RDMA maps require all memory to be unregistered in the same
chunks the memory was registered, which is often impossible
to achieve if a region was registered more than once:

1. register region    0x0 - 0x3 -> it gets mapped to
                                   a single ibv_mr
2. register region    0x1 - 0x2 -> nothing happens, this region
                                   is already registered
3. unregister region  0x0 - 0x3 -> 0x0-0x1 gets unregistered as
                                   one region. 0x2-0x3 gets
                                   unregistered as another
                                   (leading to segfault in the
                                   the current RDMA implementation)

The problem is that the last two regions share the same ibv_mr,
which SPDK tries to free twice. The second free causes a segfault.
vtophys map handles this case by registering each 2MB chunk
separately, but this solution cannot be applied for RDMA, as
NICs put a limitation (~2048) on the number of regions registered.

Another option is to keep a refcount of each ibv_mr allocated,
and free it only when the entire region was unregistered from the
SPDK mem map. This is however very tricky and RDMAmojo mentions
that freeing a memory buffer before unregistering its ibv_mr
may lead to a segfault.

Change-Id: I545c56e24ffa55bda211dea22aeb8a55d9631fe5
Signed-off-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-on: https://review.gerrithub.io/426085
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
2018-10-11 18:59:11 +00:00
..
env_internal.h env_dpdk: track PCI devices internally for vtophys 2018-04-02 14:03:05 -04:00
env.c env: Fix spdk_ring creation and access. 2018-09-20 21:51:55 +00:00
env.mk crypto: Build QAT module when crypto is enabled 2018-09-28 20:21:49 +00:00
init.c env/dpdk: do not clean up DPDK 18.05 shared files 2018-09-28 18:34:55 +00:00
Makefile env: add pci_virtio.c 2017-09-26 14:28:24 -04:00
memory.c memory: forbid registering a memory region more than once 2018-10-11 18:59:11 +00:00
pci_ioat.c env: register PMDs on associated first probe 2017-03-06 12:44:34 -07:00
pci_nvme.c dpdk/pci: support DPDK 18.08 write combined PCI resources 2018-08-15 17:43:30 +00:00
pci_virtio.c dpdk/pci: support DPDK 18.08 write combined PCI resources 2018-08-15 17:43:30 +00:00
pci.c env: remove deprecated spdk_pci_get_device() 2018-05-10 19:40:22 +00:00
threads.c env/dpdk: add security checks to spdk_env_get_socket_id() 2018-09-10 17:23:39 +00:00
vtophys.c env_dpdk: spdk_mem_map_translate informs user of translation size. 2018-09-26 20:57:57 +00:00