dm: remove set vm memory by cma

Signed-off-by: Li, Fei1 <fei1.li@intel.com>
Acked-by: Geoffroy Van Cutsem <geoffroy.vancutsem@intel.com>
Reviewed-by: Jason Chen CJ <jason.cj.chen@intel.com>
This commit is contained in:
Li, Fei1 2018-06-29 11:01:17 +08:00 committed by lijinxia
parent 652e37e908
commit 6f097b1633
4 changed files with 4 additions and 124 deletions

View File

@ -829,7 +829,7 @@ main(int argc, char *argv[])
}
vm_set_memflags(ctx, memflags);
err = vm_setup_memory(ctx, memsize, VM_MMAP_ALL);
err = vm_setup_memory(ctx, memsize);
if (err) {
fprintf(stderr, "Unable to setup memory (%d)\n", errno);
goto fail;

View File

@ -318,59 +318,9 @@ vm_map_memseg_vma(struct vmctx *ctx, size_t len, vm_paddr_t gpa,
return ioctl(ctx->fd, IC_SET_MEMSEG, &memmap);
}
static int
vm_alloc_set_memseg(struct vmctx *ctx, int segid, size_t len,
vm_paddr_t gpa, int prot, char *base, char **ptr)
{
struct vm_memseg memseg;
struct vm_memmap memmap;
int error, flags;
if (segid == VM_MEMMAP_SYSMEM) {
bzero(&memseg, sizeof(struct vm_memseg));
memseg.len = len;
memseg.gpa = gpa;
error = ioctl(ctx->fd, IC_ALLOC_MEMSEG, &memseg);
if (error)
return error;
bzero(&memmap, sizeof(struct vm_memmap));
memmap.type = segid;
memmap.len = len;
memmap.gpa = gpa;
memmap.prot = PROT_ALL;
error = ioctl(ctx->fd, IC_SET_MEMSEG, &memmap);
if (error)
return error;
flags = MAP_SHARED | MAP_FIXED;
if ((ctx->memflags & VM_MEM_F_INCORE) == 0)
flags |= MAP_NOCORE;
/* mmap into the process address space on the host */
*ptr = mmap(base + gpa, len, PROT_RW, flags, ctx->fd, gpa);
if (*ptr == MAP_FAILED) {
*ptr = NULL;
error = -1;
}
} else
/* XXX: no VM_BOOTROM/VM_FRAMEBUFFER support*/
error = -1;
return error;
}
int
vm_setup_memory(struct vmctx *ctx, size_t memsize, enum vm_mmap_style vms)
vm_setup_memory(struct vmctx *ctx, size_t memsize)
{
size_t objsize, len;
vm_paddr_t gpa;
int prot;
char *baseaddr, *ptr;
int error, flags;
assert(vms == VM_MMAP_ALL);
/*
* If 'memsize' cannot fit entirely in the 'lowmem' segment then
* create another 'highmem' segment above 4GB for the remainder.
@ -378,66 +328,18 @@ vm_setup_memory(struct vmctx *ctx, size_t memsize, enum vm_mmap_style vms)
if (memsize > ctx->lowmem_limit) {
ctx->lowmem = ctx->lowmem_limit;
ctx->highmem = memsize - ctx->lowmem_limit;
objsize = 4*GB + ctx->highmem;
} else {
ctx->lowmem = memsize;
ctx->highmem = 0;
objsize = ctx->lowmem;
}
return hugetlb_setup_memory(ctx);
/*
* Stake out a contiguous region covering the guest physical memory
* and the adjoining guard regions.
*/
len = VM_MMAP_GUARD_SIZE + objsize + VM_MMAP_GUARD_SIZE;
flags = MAP_PRIVATE | MAP_ANON | MAP_NOCORE | MAP_ALIGNED_SUPER;
ptr = mmap(NULL, len, PROT_NONE, flags, -1, 0);
if (ptr == MAP_FAILED)
return -1;
baseaddr = ptr + VM_MMAP_GUARD_SIZE;
/* TODO: need add error handling */
/* alloc & map for lowmem */
if (ctx->lowmem > 0) {
gpa = 0;
len = ctx->lowmem;
prot = PROT_ALL;
error = vm_alloc_set_memseg(ctx, VM_MEMMAP_SYSMEM, len, gpa,
prot, baseaddr, &ctx->mmap_lowmem);
if (error)
return error;
}
/* alloc & map for highmem */
if (ctx->highmem > 0) {
gpa = 4*GB;
len = ctx->highmem;
prot = PROT_ALL;
error = vm_alloc_set_memseg(ctx, VM_MEMMAP_SYSMEM, len, gpa,
prot, baseaddr, &ctx->mmap_highmem);
if (error)
return error;
}
ctx->baseaddr = baseaddr;
return 0;
}
void
vm_unsetup_memory(struct vmctx *ctx)
{
hugetlb_unsetup_memory(ctx);
return;
if (ctx->lowmem > 0)
munmap(ctx->mmap_lowmem, ctx->lowmem);
if (ctx->highmem > 0)
munmap(ctx->mmap_highmem, ctx->highmem);
}
/*

View File

@ -90,6 +90,7 @@
/* Guest memory management */
#define IC_ID_MEM_BASE 0x40UL
/* IC_ALLOC_MEMSEG not used */
#define IC_ALLOC_MEMSEG _IC_ID(IC_ID, IC_ID_MEM_BASE + 0x00)
#define IC_SET_MEMSEG _IC_ID(IC_ID, IC_ID_MEM_BASE + 0x01)
@ -105,17 +106,6 @@
#define IC_ID_PM_BASE 0x60UL
#define IC_PM_GET_CPU_STATE _IC_ID(IC_ID, IC_ID_PM_BASE + 0x00)
/**
* struct vm_memseg - memory segment info for guest
*
* @len: length of memory segment
* @gpa: guest physical start address of memory segment
*/
struct vm_memseg {
uint64_t len;
uint64_t gpa;
};
#define VM_MEMMAP_SYSMEM 0
#define VM_MMIO 1

View File

@ -53,8 +53,6 @@ struct vmctx {
int memflags;
size_t lowmem;
size_t highmem;
char *mmap_lowmem;
char *mmap_highmem;
char *baseaddr;
char *name;
uuid_t vm_uuid;
@ -65,16 +63,6 @@ struct vmctx {
void *ioc_dev;
};
/*
* Different styles of mapping the memory assigned to a VM into the address
* space of the controlling process.
*/
enum vm_mmap_style {
VM_MMAP_NONE, /* no mapping */
VM_MMAP_ALL, /* fully and statically mapped */
VM_MMAP_SPARSE, /* mappings created on-demand */
};
/*
* 'flags' value passed to 'vm_set_memflags()'.
*/
@ -122,7 +110,7 @@ void vm_destroy(struct vmctx *ctx);
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);
void vm_unsetup_memory(struct vmctx *ctx);
bool check_hugetlb_support(void);
int hugetlb_setup_memory(struct vmctx *ctx);