2015-09-21 15:52:41 +00:00
|
|
|
/*-
|
|
|
|
* BSD LICENSE
|
|
|
|
*
|
2016-01-26 17:47:22 +00:00
|
|
|
* Copyright (c) Intel Corporation.
|
2015-09-21 15:52:41 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* * Neither the name of Intel Corporation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2017-05-02 18:18:25 +00:00
|
|
|
#include "spdk/stdinc.h"
|
2015-09-21 15:52:41 +00:00
|
|
|
|
2016-08-10 17:21:45 +00:00
|
|
|
#include "spdk/env.h"
|
2015-09-21 15:52:41 +00:00
|
|
|
|
|
|
|
static int
|
2015-11-02 20:48:31 +00:00
|
|
|
vtophys_negative_test(void)
|
2015-09-21 15:52:41 +00:00
|
|
|
{
|
|
|
|
void *p = NULL;
|
|
|
|
int i;
|
|
|
|
unsigned int size = 1;
|
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < 31; i++) {
|
|
|
|
p = malloc(size);
|
2017-12-07 23:23:48 +00:00
|
|
|
if (p == NULL) {
|
2015-09-21 15:52:41 +00:00
|
|
|
continue;
|
2017-12-07 23:23:48 +00:00
|
|
|
}
|
2015-09-21 15:52:41 +00:00
|
|
|
|
2016-02-08 21:17:04 +00:00
|
|
|
if (spdk_vtophys(p) != SPDK_VTOPHYS_ERROR) {
|
2015-09-21 15:52:41 +00:00
|
|
|
rc = -1;
|
|
|
|
printf("Err: VA=%p is mapped to a huge_page,\n", p);
|
|
|
|
free(p);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(p);
|
|
|
|
size = size << 1;
|
|
|
|
}
|
|
|
|
|
2016-06-22 21:57:53 +00:00
|
|
|
/* Test addresses that are not in the valid x86-64 usermode range */
|
|
|
|
|
|
|
|
if (spdk_vtophys((void *)0x0000800000000000ULL) != SPDK_VTOPHYS_ERROR) {
|
|
|
|
rc = -1;
|
|
|
|
printf("Err: kernel-mode address incorrectly allowed\n");
|
|
|
|
}
|
|
|
|
|
2017-12-07 23:23:48 +00:00
|
|
|
if (!rc) {
|
2015-09-21 15:52:41 +00:00
|
|
|
printf("vtophys_negative_test passed\n");
|
2017-12-07 23:23:48 +00:00
|
|
|
} else {
|
2015-09-21 15:52:41 +00:00
|
|
|
printf("vtophys_negative_test failed\n");
|
2017-12-07 23:23:48 +00:00
|
|
|
}
|
2015-09-21 15:52:41 +00:00
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2015-11-02 20:48:31 +00:00
|
|
|
vtophys_positive_test(void)
|
2015-09-21 15:52:41 +00:00
|
|
|
{
|
|
|
|
void *p = NULL;
|
|
|
|
int i;
|
|
|
|
unsigned int size = 1;
|
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < 31; i++) {
|
2017-05-25 18:21:30 +00:00
|
|
|
p = spdk_dma_zmalloc(size, 512, NULL);
|
2017-12-07 23:23:48 +00:00
|
|
|
if (p == NULL) {
|
2015-09-21 15:52:41 +00:00
|
|
|
continue;
|
2017-12-07 23:23:48 +00:00
|
|
|
}
|
2015-09-21 15:52:41 +00:00
|
|
|
|
2016-02-08 21:17:04 +00:00
|
|
|
if (spdk_vtophys(p) == SPDK_VTOPHYS_ERROR) {
|
2015-09-21 15:52:41 +00:00
|
|
|
rc = -1;
|
|
|
|
printf("Err: VA=%p is not mapped to a huge_page,\n", p);
|
2017-05-25 18:21:30 +00:00
|
|
|
spdk_dma_free(p);
|
2015-09-21 15:52:41 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-05-25 18:21:30 +00:00
|
|
|
spdk_dma_free(p);
|
2015-09-21 15:52:41 +00:00
|
|
|
size = size << 1;
|
|
|
|
}
|
|
|
|
|
2017-12-07 23:23:48 +00:00
|
|
|
if (!rc) {
|
2015-09-21 15:52:41 +00:00
|
|
|
printf("vtophys_positive_test passed\n");
|
2017-12-07 23:23:48 +00:00
|
|
|
} else {
|
2015-09-21 15:52:41 +00:00
|
|
|
printf("vtophys_positive_test failed\n");
|
2017-12-07 23:23:48 +00:00
|
|
|
}
|
2015-09-21 15:52:41 +00:00
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2017-08-08 10:54:37 +00:00
|
|
|
static int
|
2017-03-02 21:50:04 +00:00
|
|
|
test_map_notify(void *cb_ctx, struct spdk_mem_map *map,
|
|
|
|
enum spdk_mem_map_notify_action action,
|
|
|
|
void *vaddr, size_t size)
|
|
|
|
{
|
|
|
|
const char *action_str = "unknown";
|
|
|
|
|
|
|
|
switch (action) {
|
|
|
|
case SPDK_MEM_MAP_NOTIFY_REGISTER:
|
|
|
|
action_str = "register";
|
|
|
|
break;
|
|
|
|
case SPDK_MEM_MAP_NOTIFY_UNREGISTER:
|
|
|
|
action_str = "unregister";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("%s: %s %p-%p (%zu bytes)\n", __func__, action_str, vaddr, vaddr + size - 1, size);
|
2017-08-08 10:54:37 +00:00
|
|
|
return 0;
|
2017-03-02 21:50:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
mem_map_test(void)
|
|
|
|
{
|
|
|
|
struct spdk_mem_map *map;
|
|
|
|
uint64_t default_translation = 0xDEADBEEF0BADF00D;
|
|
|
|
|
|
|
|
map = spdk_mem_map_alloc(default_translation, test_map_notify, NULL);
|
|
|
|
if (map == NULL) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
spdk_mem_map_free(&map);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-09-21 15:52:41 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
2017-01-12 18:25:17 +00:00
|
|
|
int rc;
|
|
|
|
struct spdk_env_opts opts;
|
2015-09-21 15:52:41 +00:00
|
|
|
|
2017-01-12 18:25:17 +00:00
|
|
|
spdk_env_opts_init(&opts);
|
|
|
|
opts.name = "vtophys";
|
|
|
|
opts.core_mask = "0x1";
|
|
|
|
spdk_env_init(&opts);
|
2015-09-21 15:52:41 +00:00
|
|
|
|
|
|
|
rc = vtophys_negative_test();
|
2017-12-07 23:23:48 +00:00
|
|
|
if (rc < 0) {
|
2015-09-21 15:52:41 +00:00
|
|
|
return rc;
|
2017-12-07 23:23:48 +00:00
|
|
|
}
|
2015-09-21 15:52:41 +00:00
|
|
|
|
|
|
|
rc = vtophys_positive_test();
|
2017-12-07 23:23:48 +00:00
|
|
|
if (rc < 0) {
|
2017-03-02 21:50:04 +00:00
|
|
|
return rc;
|
2017-12-07 23:23:48 +00:00
|
|
|
}
|
2017-03-02 21:50:04 +00:00
|
|
|
|
|
|
|
rc = mem_map_test();
|
2015-09-21 15:52:41 +00:00
|
|
|
return rc;
|
|
|
|
}
|