mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-07-04 19:17:34 +00:00
dm: combine VM creating and ioreq shared page setup
This patch depends on a vhm patch merged, "vhm: setup ioreq shared buf in IC_CREATE_VM ioctl". We intend to combine VM creating and ioreq shared page setup into one step. For compatibility issue, we need follow the patch dependency to merge accordingly. This patch also drops vm_open/vm_close which will be intergrated into vm_create/vm_destroy. Tracked-On: #1330 Signed-off-by: Shuo Liu <shuo.a.liu@intel.com> Acked-by: Yu Wang <yu1.wang@intel.com>
This commit is contained in:
parent
94513ab724
commit
56992c7373
@ -652,28 +652,6 @@ num_vcpus_allowed(struct vmctx *ctx)
|
||||
return VM_MAXCPU;
|
||||
}
|
||||
|
||||
static struct vmctx *
|
||||
do_open(const char *vmname)
|
||||
{
|
||||
struct vmctx *ctx;
|
||||
int error;
|
||||
|
||||
error = vm_create(vmname);
|
||||
if (error) {
|
||||
perror("vm_create");
|
||||
exit(1);
|
||||
|
||||
}
|
||||
|
||||
ctx = vm_open(vmname);
|
||||
if (ctx == NULL) {
|
||||
perror("vm_open");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return ctx;
|
||||
}
|
||||
|
||||
static void
|
||||
sig_handler_term(int signo)
|
||||
{
|
||||
@ -901,12 +879,11 @@ main(int argc, char *argv[])
|
||||
vmname = argv[0];
|
||||
|
||||
for (;;) {
|
||||
ctx = do_open(vmname);
|
||||
|
||||
/* set IOReq buffer page */
|
||||
error = vm_set_shared_io_page(ctx, (unsigned long)vhm_req_buf);
|
||||
if (error)
|
||||
goto fail;
|
||||
ctx = vm_create(vmname, (unsigned long)vhm_req_buf);
|
||||
if (!ctx) {
|
||||
perror("vm_open");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (guest_ncpus < 1) {
|
||||
fprintf(stderr, "Invalid guest vCPUs (%d)\n",
|
||||
@ -997,7 +974,6 @@ main(int argc, char *argv[])
|
||||
mevent_deinit();
|
||||
vm_unsetup_memory(ctx);
|
||||
vm_destroy(ctx);
|
||||
vm_close(ctx);
|
||||
_ctx = 0;
|
||||
|
||||
vm_set_suspend_mode(VM_SUSPEND_NONE);
|
||||
@ -1011,6 +987,5 @@ mevent_fail:
|
||||
vm_unsetup_memory(ctx);
|
||||
fail:
|
||||
vm_destroy(ctx);
|
||||
vm_close(ctx);
|
||||
exit(0);
|
||||
}
|
||||
|
@ -58,13 +58,6 @@
|
||||
#define SUPPORT_VHM_API_VERSION_MAJOR 1
|
||||
#define SUPPORT_VHM_API_VERSION_MINOR 0
|
||||
|
||||
int
|
||||
vm_create(const char *name)
|
||||
{
|
||||
/* TODO: specific part for vm create */
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
check_api(int fd)
|
||||
{
|
||||
@ -92,7 +85,7 @@ check_api(int fd)
|
||||
static int devfd = -1;
|
||||
|
||||
struct vmctx *
|
||||
vm_open(const char *name)
|
||||
vm_create(const char *name, uint64_t req_buf)
|
||||
{
|
||||
struct vmctx *ctx;
|
||||
struct acrn_create_vm create_vm;
|
||||
@ -138,6 +131,7 @@ vm_open(const char *name)
|
||||
else
|
||||
create_vm.vm_flag &= (~SECURE_WORLD_ENABLED);
|
||||
|
||||
create_vm.req_buf = req_buf;
|
||||
while (retry > 0) {
|
||||
error = ioctl(ctx->fd, IC_CREATE_VM, &create_vm);
|
||||
if (error == 0)
|
||||
@ -160,33 +154,6 @@ err:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
vm_close(struct vmctx *ctx)
|
||||
{
|
||||
if (!ctx)
|
||||
return;
|
||||
|
||||
close(ctx->fd);
|
||||
free(ctx);
|
||||
devfd = -1;
|
||||
}
|
||||
|
||||
int
|
||||
vm_set_shared_io_page(struct vmctx *ctx, uint64_t page_vma)
|
||||
{
|
||||
int error;
|
||||
|
||||
error = ioctl(ctx->fd, IC_SET_IOREQ_BUFFER, page_vma);
|
||||
|
||||
if (error) {
|
||||
fprintf(stderr, "failed to setup shared io page create VM %s\n",
|
||||
ctx->name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
vm_create_ioreq_client(struct vmctx *ctx)
|
||||
{
|
||||
@ -239,8 +206,13 @@ vm_notify_request_done(struct vmctx *ctx, int vcpu)
|
||||
void
|
||||
vm_destroy(struct vmctx *ctx)
|
||||
{
|
||||
if (ctx)
|
||||
if (!ctx)
|
||||
return;
|
||||
|
||||
ioctl(ctx->fd, IC_DESTROY_VM, NULL);
|
||||
close(ctx->fd);
|
||||
free(ctx);
|
||||
devfd = -1;
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -250,8 +250,10 @@ struct acrn_create_vm {
|
||||
*/
|
||||
uint64_t vm_flag;
|
||||
|
||||
uint64_t req_buf;
|
||||
|
||||
/** Reserved for future use*/
|
||||
uint8_t reserved2[24];
|
||||
uint8_t reserved2[16];
|
||||
} __aligned(8);
|
||||
|
||||
/**
|
||||
|
@ -96,13 +96,10 @@ struct vm_isa_irq {
|
||||
*/
|
||||
void *vm_create_devmem(struct vmctx *ctx, int segid, const char *name,
|
||||
size_t len);
|
||||
int vm_create(const char *name);
|
||||
int vm_get_device_fd(struct vmctx *ctx);
|
||||
struct vmctx *vm_open(const char *name);
|
||||
void vm_close(struct vmctx *ctx);
|
||||
struct vmctx *vm_create(const char *name, uint64_t req_buf);
|
||||
void vm_pause(struct vmctx *ctx);
|
||||
void vm_reset(struct vmctx *ctx);
|
||||
int vm_set_shared_io_page(struct vmctx *ctx, uint64_t page_vma);
|
||||
int vm_create_ioreq_client(struct vmctx *ctx);
|
||||
int vm_destroy_ioreq_client(struct vmctx *ctx);
|
||||
int vm_attach_ioreq_client(struct vmctx *ctx);
|
||||
|
Loading…
Reference in New Issue
Block a user