Skip to content

Commit ba0cb7b

Browse files
committed
Fix devdax_open_ipc_handle() and devdax_close_ipc_handle()
devdax_open_ipc_handle() has to use the path and the size of the remote /dev/dax got from the IPC handle and not the local one. devdax_open_ipc_handle() has to use also the memory protection got from the IPC handle, so let's add the memory protection to the IPC handle. MMap only part of devdax Signed-off-by: Lukasz Dorau <[email protected]>
1 parent 9a13745 commit ba0cb7b

File tree

1 file changed

+23
-49
lines changed

1 file changed

+23
-49
lines changed

src/provider/provider_devdax_memory.c

Lines changed: 23 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -369,9 +369,10 @@ static umf_result_t devdax_allocation_merge(void *provider, void *lowPtr,
369369
}
370370

371371
typedef struct devdax_ipc_data_t {
372-
char dd_path[PATH_MAX]; // path to the /dev/dax
373-
size_t dd_size; // size of the /dev/dax
374-
size_t offset; // offset of the data
372+
char path[PATH_MAX]; // path to the /dev/dax
373+
unsigned protection; // combination of OS-specific memory protection flags
374+
size_t offset; // offset of the data
375+
size_t length; // length of the data
375376
} devdax_ipc_data_t;
376377

377378
static umf_result_t devdax_get_ipc_handle_size(void *provider, size_t *size) {
@@ -386,8 +387,6 @@ static umf_result_t devdax_get_ipc_handle_size(void *provider, size_t *size) {
386387

387388
static umf_result_t devdax_get_ipc_handle(void *provider, const void *ptr,
388389
size_t size, void *providerIpcData) {
389-
(void)size; // unused
390-
391390
if (provider == NULL || ptr == NULL || providerIpcData == NULL) {
392391
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
393392
}
@@ -396,11 +395,12 @@ static umf_result_t devdax_get_ipc_handle(void *provider, const void *ptr,
396395
(devdax_memory_provider_t *)provider;
397396

398397
devdax_ipc_data_t *devdax_ipc_data = (devdax_ipc_data_t *)providerIpcData;
398+
strncpy(devdax_ipc_data->path, devdax_provider->path, PATH_MAX - 1);
399+
devdax_ipc_data->path[PATH_MAX - 1] = '\0';
400+
devdax_ipc_data->protection = devdax_provider->protection;
399401
devdax_ipc_data->offset =
400402
(size_t)((uintptr_t)ptr - (uintptr_t)devdax_provider->base);
401-
strncpy(devdax_ipc_data->dd_path, devdax_provider->path, PATH_MAX - 1);
402-
devdax_ipc_data->dd_path[PATH_MAX - 1] = '\0';
403-
devdax_ipc_data->dd_size = devdax_provider->size;
403+
devdax_ipc_data->length = size;
404404

405405
return UMF_RESULT_SUCCESS;
406406
}
@@ -416,16 +416,9 @@ static umf_result_t devdax_put_ipc_handle(void *provider,
416416
devdax_ipc_data_t *devdax_ipc_data = (devdax_ipc_data_t *)providerIpcData;
417417

418418
// verify the path of the /dev/dax
419-
if (strncmp(devdax_ipc_data->dd_path, devdax_provider->path, PATH_MAX)) {
419+
if (strncmp(devdax_ipc_data->path, devdax_provider->path, PATH_MAX)) {
420420
LOG_ERR("devdax path mismatch (local: %s, ipc: %s)",
421-
devdax_provider->path, devdax_ipc_data->dd_path);
422-
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
423-
}
424-
425-
// verify the size of the /dev/dax
426-
if (devdax_ipc_data->dd_size != devdax_provider->size) {
427-
LOG_ERR("devdax size mismatch (local: %zu, ipc: %zu)",
428-
devdax_provider->size, devdax_ipc_data->dd_size);
421+
devdax_provider->path, devdax_ipc_data->path);
429422
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
430423
}
431424

@@ -438,56 +431,40 @@ static umf_result_t devdax_open_ipc_handle(void *provider,
438431
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
439432
}
440433

441-
devdax_memory_provider_t *devdax_provider =
442-
(devdax_memory_provider_t *)provider;
443434
devdax_ipc_data_t *devdax_ipc_data = (devdax_ipc_data_t *)providerIpcData;
444435

445-
// verify it is the same devdax - first verify the path
446-
if (strncmp(devdax_ipc_data->dd_path, devdax_provider->path, PATH_MAX)) {
447-
LOG_ERR("devdax path mismatch (local: %s, ipc: %s)",
448-
devdax_provider->path, devdax_ipc_data->dd_path);
449-
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
450-
}
451-
452-
// verify the size of the /dev/dax
453-
if (devdax_ipc_data->dd_size != devdax_provider->size) {
454-
LOG_ERR("devdax size mismatch (local: %zu, ipc: %zu)",
455-
devdax_provider->size, devdax_ipc_data->dd_size);
456-
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
457-
}
458-
459436
umf_result_t ret = UMF_RESULT_SUCCESS;
460-
int fd = utils_devdax_open(devdax_provider->path);
437+
int fd = utils_devdax_open(devdax_ipc_data->path);
461438
if (fd == -1) {
462-
LOG_PERR("opening a devdax (%s) failed", devdax_provider->path);
439+
LOG_PERR("opening the devdax (%s) failed", devdax_ipc_data->path);
463440
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
464441
}
465442

466443
unsigned map_sync_flag = 0;
467444
utils_translate_mem_visibility_flag(UMF_MEM_MAP_SYNC, &map_sync_flag);
468445

469446
// mmap /dev/dax with the MAP_SYNC xor MAP_SHARED flag (if MAP_SYNC fails)
470-
char *base = utils_mmap_file(NULL, devdax_provider->size,
471-
devdax_provider->protection, map_sync_flag, fd,
472-
0 /* offset */);
473-
if (base == NULL) {
447+
char *addr = utils_mmap_file(NULL, devdax_ipc_data->length,
448+
devdax_ipc_data->protection, map_sync_flag, fd,
449+
devdax_ipc_data->offset);
450+
if (addr == NULL) {
474451
devdax_store_last_native_error(UMF_DEVDAX_RESULT_ERROR_ALLOC_FAILED,
475452
errno);
476453
LOG_PERR("devdax mapping failed (path: %s, size: %zu, protection: %i, "
477-
"fd: %i)",
478-
devdax_provider->path, devdax_provider->size,
479-
devdax_provider->protection, fd);
454+
"fd: %i, offset: %zu)",
455+
devdax_ipc_data->path, devdax_ipc_data->length,
456+
devdax_ipc_data->protection, fd, devdax_ipc_data->offset);
480457
ret = UMF_RESULT_ERROR_MEMORY_PROVIDER_SPECIFIC;
481458
}
482459

483460
LOG_DEBUG("devdax mapped (path: %s, size: %zu, protection: %i, fd: %i, "
484461
"offset: %zu)",
485-
devdax_provider->path, devdax_provider->size,
486-
devdax_provider->protection, fd, devdax_ipc_data->offset);
462+
devdax_ipc_data->path, devdax_ipc_data->length,
463+
devdax_ipc_data->protection, fd, devdax_ipc_data->offset);
487464

488465
(void)utils_close_fd(fd);
489466

490-
*ptr = base + devdax_ipc_data->offset;
467+
*ptr = addr;
491468

492469
return ret;
493470
}
@@ -498,11 +475,8 @@ static umf_result_t devdax_close_ipc_handle(void *provider, void *ptr,
498475
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
499476
}
500477

501-
devdax_memory_provider_t *devdax_provider =
502-
(devdax_memory_provider_t *)provider;
503-
504478
errno = 0;
505-
int ret = utils_munmap(devdax_provider->base, devdax_provider->size);
479+
int ret = utils_munmap(ptr, size);
506480
// ignore error when size == 0
507481
if (ret && (size > 0)) {
508482
devdax_store_last_native_error(UMF_DEVDAX_RESULT_ERROR_FREE_FAILED,

0 commit comments

Comments
 (0)