mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-06-20 12:42:54 +00:00
hugetlb: add ept map memseg support
adding API vm_map_memseg_vma() which using ioctl IC_SET_MEMSEG call into VHM for futher mem(ept) mapping, based on user vma information. Signed-off-by: Jason Chen CJ <jason.cj.chen@intel.com> Acked-by: Xu, Anthony <anthony.xu@intel.com>
This commit is contained in:
parent
4cad694be2
commit
25ef14edac
@ -487,6 +487,18 @@ int hugetlb_setup_memory(struct vmctx *ctx)
|
|||||||
}
|
}
|
||||||
printf("total_size 0x%lx\n\n", total_size);
|
printf("total_size 0x%lx\n\n", total_size);
|
||||||
|
|
||||||
|
/* map ept for lowmem*/
|
||||||
|
if (vm_map_memseg_vma(ctx, ctx->lowmem, 0,
|
||||||
|
(uint64_t)ctx->baseaddr, PROT_ALL) < 0)
|
||||||
|
goto err;
|
||||||
|
|
||||||
|
/* map ept for highmem*/
|
||||||
|
if (ctx->highmem > 0) {
|
||||||
|
if (vm_map_memseg_vma(ctx, ctx->highmem, 4 * GB,
|
||||||
|
(uint64_t)(ctx->baseaddr + 4 * GB), PROT_ALL) < 0)
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
err:
|
err:
|
||||||
|
@ -68,9 +68,6 @@
|
|||||||
*/
|
*/
|
||||||
#define VM_MMAP_GUARD_SIZE (4 * MB)
|
#define VM_MMAP_GUARD_SIZE (4 * MB)
|
||||||
|
|
||||||
#define PROT_RW (PROT_READ | PROT_WRITE)
|
|
||||||
#define PROT_ALL (PROT_READ | PROT_WRITE | PROT_EXEC)
|
|
||||||
|
|
||||||
#define SUPPORT_VHM_API_VERSION_MAJOR 1
|
#define SUPPORT_VHM_API_VERSION_MAJOR 1
|
||||||
#define SUPPORT_VHM_API_VERSION_MINOR 0
|
#define SUPPORT_VHM_API_VERSION_MINOR 0
|
||||||
|
|
||||||
@ -317,6 +314,22 @@ vm_get_memflags(struct vmctx *ctx)
|
|||||||
return ctx->memflags;
|
return ctx->memflags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
vm_map_memseg_vma(struct vmctx *ctx, size_t len, vm_paddr_t gpa,
|
||||||
|
uint64_t vma, int prot)
|
||||||
|
{
|
||||||
|
struct vm_memmap memmap;
|
||||||
|
|
||||||
|
bzero(&memmap, sizeof(struct vm_memmap));
|
||||||
|
memmap.type = VM_SYSMEM;
|
||||||
|
memmap.using_vma = 1;
|
||||||
|
memmap.vma_base = vma;
|
||||||
|
memmap.len = len;
|
||||||
|
memmap.gpa = gpa;
|
||||||
|
memmap.prot = prot;
|
||||||
|
return ioctl(ctx->fd, IC_SET_MEMSEG, &memmap);
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
vm_alloc_set_memseg(struct vmctx *ctx, int segid, size_t len,
|
vm_alloc_set_memseg(struct vmctx *ctx, int segid, size_t len,
|
||||||
vm_paddr_t gpa, int prot, char *base, char **ptr)
|
vm_paddr_t gpa, int prot, char *base, char **ptr)
|
||||||
|
@ -121,19 +121,30 @@ struct vm_memseg {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* struct vm_memmap - EPT memory mapping info for guest
|
* struct vm_memmap - EPT memory mapping info for guest
|
||||||
*
|
|
||||||
* @type: memory mapping type
|
|
||||||
* @gpa: guest physical start address of memory mapping
|
|
||||||
* @hpa: host physical start address of memory
|
|
||||||
* @len: the length of memory range mapped
|
|
||||||
* @prot: memory mapping attribute
|
|
||||||
*/
|
*/
|
||||||
struct vm_memmap {
|
struct vm_memmap {
|
||||||
|
/** @type: memory mapping type */
|
||||||
uint32_t type;
|
uint32_t type;
|
||||||
uint32_t reserved;
|
/** @using_vma: using vma_base to get vm0_gpa,
|
||||||
|
* only for type == VM_SYSTEM
|
||||||
|
*/
|
||||||
|
uint32_t using_vma;
|
||||||
|
/** @gpa: user OS guest physical start address of memory mapping */
|
||||||
uint64_t gpa;
|
uint64_t gpa;
|
||||||
uint64_t hpa; /* only for type == VM_MMIO */
|
/** union */
|
||||||
|
union {
|
||||||
|
/** @hpa: host physical start address of memory,
|
||||||
|
* only for type == VM_MMIO
|
||||||
|
*/
|
||||||
|
uint64_t hpa;
|
||||||
|
/** @vma_base: service OS user virtual start address of
|
||||||
|
* memory, only for type == VM_SYSMEM && using_vma == true
|
||||||
|
*/
|
||||||
|
uint64_t vma_base;
|
||||||
|
};
|
||||||
|
/** @len: the length of memory range mapped */
|
||||||
uint64_t len; /* mmap length */
|
uint64_t len; /* mmap length */
|
||||||
|
/** @prot: memory mapping attribute */
|
||||||
uint32_t prot; /* RWX */
|
uint32_t prot; /* RWX */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -89,6 +89,9 @@ enum vm_mmap_style {
|
|||||||
|
|
||||||
#define VM_MEMSEG_NAME(m) ((m)->name[0] != '\0' ? (m)->name : NULL)
|
#define VM_MEMSEG_NAME(m) ((m)->name[0] != '\0' ? (m)->name : NULL)
|
||||||
|
|
||||||
|
#define PROT_RW (PROT_READ | PROT_WRITE)
|
||||||
|
#define PROT_ALL (PROT_READ | PROT_WRITE | PROT_EXEC)
|
||||||
|
|
||||||
struct vm_lapic_msi {
|
struct vm_lapic_msi {
|
||||||
uint64_t msg;
|
uint64_t msg;
|
||||||
uint64_t addr;
|
uint64_t addr;
|
||||||
@ -120,6 +123,8 @@ void vm_set_suspend_mode(enum vm_suspend_how how);
|
|||||||
int vm_get_suspend_mode(void);
|
int vm_get_suspend_mode(void);
|
||||||
void vm_destroy(struct vmctx *ctx);
|
void vm_destroy(struct vmctx *ctx);
|
||||||
int vm_parse_memsize(const char *optarg, size_t *memsize);
|
int vm_parse_memsize(const char *optarg, size_t *memsize);
|
||||||
|
int vm_map_memseg_vma(struct vmctx *ctx, size_t len, vm_paddr_t gpa,
|
||||||
|
uint64_t vma, int prot);
|
||||||
int vm_setup_memory(struct vmctx *ctx, size_t len, enum vm_mmap_style s);
|
int vm_setup_memory(struct vmctx *ctx, size_t len, enum vm_mmap_style s);
|
||||||
void vm_unsetup_memory(struct vmctx *ctx);
|
void vm_unsetup_memory(struct vmctx *ctx);
|
||||||
bool check_hugetlb_support(void);
|
bool check_hugetlb_support(void);
|
||||||
|
Loading…
Reference in New Issue
Block a user