vhost: move memory registration functions to vhost_compat.c

This change will allow us to move other DPDK specific functions
to rte_vhost_compat.c, such as session callbacks which are
the only consumers of these memory management functions.

Change-Id: Ieb7b3f08ddf2e7cf04ecf18e8af4ad04124ccfea
Signed-off-by: Vitaliy Mysak <vitaliy.mysak@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/470458
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
Vitaliy Mysak 2019-10-03 17:25:29 +02:00 committed by Tomasz Zawadzki
parent 3f7e2ba18e
commit 0a089121f6
3 changed files with 63 additions and 56 deletions

View File

@ -47,6 +47,63 @@
#include "vhost_internal.h"
#include "spdk_internal/vhost_user.h"
#include "spdk_internal/memory.h"
void
vhost_session_mem_register(struct rte_vhost_memory *mem)
{
struct rte_vhost_mem_region *region;
uint32_t i;
uint64_t previous_start = UINT64_MAX;
for (i = 0; i < mem->nregions; i++) {
uint64_t start, end, len;
region = &mem->regions[i];
start = FLOOR_2MB(region->mmap_addr);
end = CEIL_2MB(region->mmap_addr + region->mmap_size);
if (start == previous_start) {
start += (size_t) VALUE_2MB;
}
previous_start = start;
len = end - start;
SPDK_INFOLOG(SPDK_LOG_VHOST, "Registering VM memory for vtophys translation - 0x%jx len:0x%jx\n",
start, len);
if (spdk_mem_register((void *)start, len) != 0) {
SPDK_WARNLOG("Failed to register memory region %"PRIu32". Future vtophys translation might fail.\n",
i);
continue;
}
}
}
void
vhost_session_mem_unregister(struct rte_vhost_memory *mem)
{
struct rte_vhost_mem_region *region;
uint32_t i;
uint64_t previous_start = UINT64_MAX;
for (i = 0; i < mem->nregions; i++) {
uint64_t start, end, len;
region = &mem->regions[i];
start = FLOOR_2MB(region->mmap_addr);
end = CEIL_2MB(region->mmap_addr + region->mmap_size);
if (start == previous_start) {
start += (size_t) VALUE_2MB;
}
previous_start = start;
len = end - start;
if (spdk_vtophys((void *) start, NULL) == SPDK_VTOPHYS_ERROR) {
continue; /* region has not been registered */
}
if (spdk_mem_unregister((void *)start, len) != 0) {
assert(false);
}
}
}
static int
new_connection(int vid)

View File

@ -524,62 +524,6 @@ vhost_session_find_by_vid(int vid)
return NULL;
}
static void
vhost_session_mem_register(struct rte_vhost_memory *mem)
{
struct rte_vhost_mem_region *region;
uint32_t i;
uint64_t previous_start = UINT64_MAX;
for (i = 0; i < mem->nregions; i++) {
uint64_t start, end, len;
region = &mem->regions[i];
start = FLOOR_2MB(region->mmap_addr);
end = CEIL_2MB(region->mmap_addr + region->mmap_size);
if (start == previous_start) {
start += (size_t) VALUE_2MB;
}
previous_start = start;
len = end - start;
SPDK_INFOLOG(SPDK_LOG_VHOST, "Registering VM memory for vtophys translation - 0x%jx len:0x%jx\n",
start, len);
if (spdk_mem_register((void *)start, len) != 0) {
SPDK_WARNLOG("Failed to register memory region %"PRIu32". Future vtophys translation might fail.\n",
i);
continue;
}
}
}
static void
vhost_session_mem_unregister(struct rte_vhost_memory *mem)
{
struct rte_vhost_mem_region *region;
uint32_t i;
uint64_t previous_start = UINT64_MAX;
for (i = 0; i < mem->nregions; i++) {
uint64_t start, end, len;
region = &mem->regions[i];
start = FLOOR_2MB(region->mmap_addr);
end = CEIL_2MB(region->mmap_addr + region->mmap_size);
if (start == previous_start) {
start += (size_t) VALUE_2MB;
}
previous_start = start;
len = end - start;
if (spdk_vtophys((void *) start, NULL) == SPDK_VTOPHYS_ERROR) {
continue; /* region has not been registered */
}
if (spdk_mem_unregister((void *)start, len) != 0) {
assert(false);
}
}
}
struct spdk_vhost_dev *
spdk_vhost_dev_next(struct spdk_vhost_dev *vdev)
{

View File

@ -330,6 +330,12 @@ int vhost_set_config_cb(int vid, uint8_t *config, uint32_t offset,
uint32_t size, uint32_t flags)
#endif
/*
* Memory registration functions used in start/stop device callbacks
*/
void vhost_session_mem_register(struct rte_vhost_memory *mem);
void vhost_session_mem_unregister(struct rte_vhost_memory *mem);
/*
* Call a function for each session of the provided vhost device.
* The function will be called one-by-one on each session's thread.