diff --git a/proto/vmm/vmm.c b/proto/vmm/vmm.c new file mode 100644 index 0000000000000000000000000000000000000000..7e63d0c70e59326e5ea901e32f8cb2a75ede88d9 --- /dev/null +++ b/proto/vmm/vmm.c @@ -0,0 +1,68 @@ +#include "vmm.h" +#include "../debug/debug.h" +#include "linux/gfp_types.h" +#include "linux/slab.h" +#include "linux/smp.h" + +int init_vmm(struct vmm_t *ctx, unsigned long vcpu_count) { + if (!ctx) { + DEBUG_FMT("VMM context wasn't properly allocated!\n") + return -EFAULT; + } + + ctx->vcpu_table = kzalloc(vcpu_count * sizeof(struct vcpu_t), GFP_KERNEL); + + if (!ctx->vcpu_table) { + DEBUG_FMT("Allocation for the vcpu table has failed\n"); + return -ENOMEM; + } + + ctx->vcpu_count = vcpu_count; + + int proc_id = smp_processor_id(); + int ret = init_vcpu(&ctx->vcpu_table[proc_id], proc_id); + + if (ret != 0) { + destroy_vmm(ctx); + DEBUG_FMT("vCPU[%d] initialization has failed\n", proc_id); + return ret; + } + + DEBUG_FMT("VA of vCPU[%d]'s VMXON region: 0x%px\n", proc_id, + ctx->vcpu_table[proc_id].vmxon); + DEBUG_FMT("PA of vCPU[%d]'s VMXON region: 0x%lx\n", proc_id, + __pa(ctx->vcpu_table[proc_id].vmxon)); + + DEBUG_FMT("vCPU[%d]'s VMCS rev id: 0x%x\n", proc_id, + ctx->vcpu_table[proc_id].vmxon->vmcs_rev_id); + + /*for (unsigned long i = 0; i < ctx->vcpu_count; i++) {*/ + /* int ret = init_vcpu(&ctx->vcpu_table[i], );*/ + /**/ + /* if (ret != 0) {*/ + /* destroy_vmm(ctx);*/ + /* DEBUG_FMT("vCPU[%lu] initialization has failed\n", i);*/ + /* return ret;*/ + /* }*/ + /**/ + /* DEBUG_FMT("VA of vCPU[%lu]'s VMXON region: 0x%px\n", i,*/ + /* ctx->vcpu_table[i].vmxon);*/ + /* DEBUG_FMT("PA of vCPU[%lu]'s VMXON region: 0x%lx\n", i,*/ + /* __pa(ctx->vcpu_table[i].vmxon));*/ + /**/ + /* DEBUG_FMT("vCPU[%lu]'s VMCS rev id: 0x%x\n", i,*/ + /* ctx->vcpu_table[i].vmxon->vmcs_rev_id);*/ + /*}*/ + + return 0; +} + +void destroy_vmm(struct vmm_t *ctx) { + for (unsigned long i = 0; i < ctx->vcpu_count; i++) { + destroy_vcpu(&ctx->vcpu_table[i]); + } + + kfree(ctx->vcpu_table); + /*BUG: prolly won't change the pointer itself */ + ctx->vcpu_table = NULL; +} diff --git a/proto/vmm/vmm.h b/proto/vmm/vmm.h new file mode 100644 index 0000000000000000000000000000000000000000..ecdc58370201665e87db30c3f8b8650334594a11 --- /dev/null +++ b/proto/vmm/vmm.h @@ -0,0 +1,12 @@ +#include "../vcpu/vcpu.h" + +struct vmm_t { + /*vcpu_table has to be freed!*/ + struct vcpu_t *vcpu_table; + unsigned long vcpu_count; + char stack[1 << 12]; +}; + +int init_vmm(struct vmm_t *ctx, unsigned long vcpu_count); + +void destroy_vmm(struct vmm_t *ctx);