Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions arch/lkl/include/uapi/asm/host_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ enum lkl_prot {
* protection
* @munmap - unmap previously mapped memory
*
* @shmem_init - initialize host shared memory for MMU physical memory
* @shmem_mmap - map host shared memory into address space
* @shmem_cleanup - cleanup host shared memory resources
*
* @pci_ops - pointer to PCI host operations
*/
struct lkl_host_operations {
Expand Down Expand Up @@ -199,6 +203,7 @@ struct lkl_host_operations {
void (*shmem_init)(unsigned long size);
void *(*shmem_mmap)(void *addr, unsigned long pg_off, unsigned long size,
enum lkl_prot prot);
void (*shmem_cleanup)(void);

struct lkl_dev_pci_ops *pci_ops;
};
Expand Down
4 changes: 4 additions & 0 deletions arch/lkl/mm/bootmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,8 @@ void free_mem(void)
lkl_ops->page_free(_memory_start, mem_size);
else
lkl_ops->mem_free(_memory_start);
#ifdef CONFIG_MMU
if (lkl_ops->shmem_cleanup)
lkl_ops->shmem_cleanup();
#endif
}
10 changes: 10 additions & 0 deletions tools/lkl/lib/posix-host.c
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,7 @@ static void shmem_init(unsigned long size)
snprintf(lkl_shmem_id, sizeof(lkl_shmem_id), "/lkl_phys_mem_%d", getpid());
shared_mem_fd = shm_open(lkl_shmem_id, O_RDWR | O_CREAT, rwx);
assert(shared_mem_fd >= 0);
assert(shm_unlink(lkl_shmem_id) == 0);
shared_mem_size = size;
assert(ftruncate(shared_mem_fd, shared_mem_size) == 0);
}
Expand All @@ -546,6 +547,14 @@ static void *lkl_shmem_mmap(void *addr, unsigned long pg_off,
return NULL;
return ret;
}

static void shmem_cleanup(void)
{
if (shared_mem_fd >= 0) {
close(shared_mem_fd);
shared_mem_fd = -1;
}
}
#endif // LKL_HOST_CONFIG_MMU

static void *posix_malloc(unsigned long size)
Expand Down Expand Up @@ -611,6 +620,7 @@ struct lkl_host_operations lkl_host_ops = {
#ifdef LKL_HOST_CONFIG_MMU
.shmem_init = shmem_init,
.shmem_mmap = lkl_shmem_mmap,
.shmem_cleanup = shmem_cleanup,
#endif
#ifdef LKL_HOST_CONFIG_VFIO_PCI
.pci_ops = &vfio_pci_ops,
Expand Down
Loading