41 #include <sys/types.h> 42 #include <sys/mount.h> 44 #include <sys/fcntl.h> 46 #include <linux/vfio.h> 62 uword lo_offset, hi_offset;
86 hi_offset = lo_offset + n_bytes - 1;
100 for (i = 0; i <
vec_len (to_free); i++)
105 return lo_offset != ~0 ? pr->
heap + lo_offset : 0;
119 const char fn[] =
"/dev/vfio/vfio";
120 char buff[
sizeof (fn)] = { 0 };
122 if (readlink ((
char *) path_name, buff,
sizeof (fn)) + 1 !=
sizeof (fn))
125 if (strncmp (fn, buff,
sizeof (fn)))
135 struct vfio_iommu_type1_dma_map dma_map = { 0 };
146 if (ioctl (fd, VFIO_GET_API_VERSION) != VFIO_API_VERSION)
149 if (ioctl (fd, VFIO_CHECK_EXTENSION, VFIO_TYPE1_IOMMU) == 0)
152 dma_map.argsz =
sizeof (
struct vfio_iommu_type1_dma_map);
153 dma_map.flags = VFIO_DMA_MAP_FLAG_READ | VFIO_DMA_MAP_FLAG_WRITE;
160 if (ioctl (fd, VFIO_IOMMU_MAP_DMA, &dma_map) != 0)
182 if ((pr - vpm->
regions) >= 256)
193 if ((flags & VLIB_PHYSMEM_F_FAKE) == 0)
219 if ((flags & VLIB_PHYSMEM_F_FAKE) == 0)
222 for (i = 0; i < pr->
n_pages; i++)
227 if (numa_node != node)
229 clib_warning (
"physmem page for region \'%s\' allocated on the" 230 " wrong numa node (requested %u actual %u)",
255 memset (pr, 0,
sizeof (*pr));
302 vlib_cli_output (vm,
"index %u name '%s' page-size %uKB num-pages %d " 303 "numa-node %u fd %d\n",
304 pr->index, pr->name, (1 << (pr->log2_page_size -10)),
305 pr->n_pages, pr->numa_node, pr->fd);
307 vlib_cli_output (vm,
" %U", format_mheap, pr->heap, 1);
309 vlib_cli_output (vm,
" no heap\n");
317 .path =
"show physmem",
318 .short_help =
"Show physical memory allocation",
#define CLIB_MEM_VM_F_HUGETLB
#define vec_foreach_index(var, v)
Iterate over vector indices.
sll srl srl sll sra u16x4 i
#define VLIB_PHYSMEM_F_INIT_MHEAP
void(* os_physmem_region_free)(struct vlib_main_t *vm, vlib_physmem_region_index_t idx)
vlib_physmem_main_t physmem_main
#define CLIB_MEM_VM_F_NUMA_PREFER
void * addr
Pointer to allocated memory, set on successful allocation.
static clib_error_t * unix_physmem_region_alloc(vlib_main_t *vm, char *name, u32 size, u8 numa_node, u32 flags, vlib_physmem_region_index_t *idx)
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
static clib_error_t * scan_vfio_fd(void *arg, u8 *path_name, u8 *file_name)
int numa_node
numa node preference.
#define MHEAP_FLAG_THREAD_SAFE
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
static void * unix_physmem_alloc_aligned(vlib_main_t *vm, vlib_physmem_region_index_t idx, uword n_bytes, uword alignment)
static int vfio_container_fd
clib_error_t * clib_mem_vm_ext_alloc(clib_mem_vm_alloc_t *a)
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
void(* os_physmem_free)(struct vlib_main_t *vm, vlib_physmem_region_index_t idx, void *x)
#define MHEAP_FLAG_DISABLE_VM
char * name
Name for memory allocation, set by caller.
void *(* os_physmem_alloc_aligned)(struct vlib_main_t *vm, vlib_physmem_region_index_t idx, uword n_bytes, uword alignment)
#define clib_error_return(e, args...)
uword size
Allocation size, set by caller.
static uword pointer_to_uword(const void *p)
static vlib_physmem_region_t * vlib_physmem_get_region(vlib_main_t *vm, u8 index)
#define CLIB_MEM_VM_F_SHARED
int fd
File desriptor, set on successful allocation if CLIB_MEM_VM_F_SHARED is set.
#define clib_error_return_unix(e, args...)
#define pool_put(P, E)
Free an object E in pool P.
#define CLIB_MEM_VM_F_NUMA_FORCE
void * mheap_get_aligned(void *v, uword n_user_data_bytes, uword align, uword align_offset, uword *offset_return)
#define vec_free(V)
Free vector's memory (no header).
#define clib_warning(format, args...)
u32 flags
vm allocation flags: CLIB_MEM_VM_F_SHARED: request shared memory, file destiptor will be provided o...
#define VLIB_CLI_COMMAND(x,...)
void * mheap_alloc_with_flags(void *memory, uword memory_size, uword flags)
#define CLIB_MEM_VM_F_HUGETLB_PREALLOC
static clib_error_t * unix_physmem_region_iommu_register(vlib_physmem_region_t *pr)
static void unix_physmem_free(vlib_main_t *vm, vlib_physmem_region_index_t idx, void *x)
#define clib_error_report(e)
vlib_physmem_region_index_t index
static clib_error_t * show_physmem(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
void mheap_put(void *v, uword uoffset)
static void unix_physmem_region_free(vlib_main_t *vm, vlib_physmem_region_index_t idx)
clib_error_t * foreach_directory_file(char *dir_name, clib_error_t *(*f)(void *arg, u8 *path_name, u8 *file_name), void *arg, int scan_dirs)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
u64 * clib_mem_vm_get_paddr(void *mem, int log2_page_size, int n_pages)
#define VLIB_PHYSMEM_F_FAKE
clib_error_t * unix_physmem_init(vlib_main_t *vm)
static long move_pages(int pid, unsigned long count, void **pages, const int *nodes, int *status, int flags)
#define CLIB_CACHE_LINE_BYTES
clib_error_t *(* os_physmem_region_alloc)(struct vlib_main_t *vm, char *name, u32 size, u8 numa_node, u32 flags, vlib_physmem_region_index_t *idx)
u8 vlib_physmem_region_index_t
vlib_physmem_region_t * regions