diff --git a/proto/hypervisor.c b/proto/hypervisor.c index 12d2061c26d4e5860a54a1a49177f0cecd001e9b..ad75f00e77df1757058aa7380aca0ceda615d01b 100644 --- a/proto/hypervisor.c +++ b/proto/hypervisor.c @@ -17,9 +17,7 @@ #include "vmm/vmm.h" #include "vmx/vmx.h" -#define NULL ((void *)0) - -#define NB_VCPUS 1 +#define NB_VCPUS 4 /*asm ( assembler template*/ /* : output operands (optional)*/ @@ -45,7 +43,7 @@ static int my_init(void) { int ret_err; - if ((ret_err = init_vmm(&ctx, 1)) != 0) { + if ((ret_err = init_vmm(&ctx, NB_VCPUS)) != 0) { pr_err("VMM initialization has failed\n"); return ret_err; } @@ -72,6 +70,8 @@ static int my_init(void) { } for (unsigned long i = 0; i < ctx.vcpu_count; i++) { + set_cpus_allowed_ptr(current, cpumask_of(i)); + DEBUG_FMT("CURRENT CPU = %d\n", smp_processor_id()); if ((ret_err = kvm_cpu_vmxon(__pa(&ctx.vcpu_table[i]))) != 0) { pr_err("Failed to execute `vmxon` on vCPU[%lu]\n", i); destroy_vmm(&ctx); @@ -85,13 +85,17 @@ static int my_init(void) { } static void my_exit(void) { - pr_info("Executing VMXOFF\n"); - /*__asm__ volatile("vmxoff");*/ int vmxoff; - if ((vmxoff = kvm_cpu_vmxoff()) != 0) { - pr_err("Failed to execute VMXOFF\n"); - return; + for (unsigned long i = 0; i < ctx.vcpu_count; i++) { + set_cpus_allowed_ptr(current, cpumask_of(i)); + DEBUG_FMT("CURRENT CPU = %d\n", smp_processor_id()); + + pr_info("[-] Executing VMXOFF on vCPU[%lu]\n", i); + if ((vmxoff = kvm_cpu_vmxoff()) != 0) { + pr_err("Failed to execute VMXOFF\n"); + return; + } } pr_info("[*] Freeing VMM ctx\n"); diff --git a/proto/vmm/vmm.c b/proto/vmm/vmm.c index 7e63d0c70e59326e5ea901e32f8cb2a75ede88d9..b515fd6c5c9c484182d85b7f774998680186302a 100644 --- a/proto/vmm/vmm.c +++ b/proto/vmm/vmm.c @@ -1,8 +1,9 @@ #include "vmm.h" #include "../debug/debug.h" +#include "linux/cpumask.h" #include "linux/gfp_types.h" +#include "linux/sched.h" #include "linux/slab.h" -#include "linux/smp.h" int init_vmm(struct vmm_t *ctx, unsigned long vcpu_count) { if (!ctx) { @@ -19,40 +20,27 @@ int init_vmm(struct vmm_t *ctx, unsigned long vcpu_count) { ctx->vcpu_count = vcpu_count; - int proc_id = smp_processor_id(); - int ret = init_vcpu(&ctx->vcpu_table[proc_id], proc_id); + for (unsigned long i = 0; i < ctx->vcpu_count; i++) { + /*NOTE: need to study the function below*/ + set_cpus_allowed_ptr(current, cpumask_of(i)); + DEBUG_FMT("CURRENT CPU = %d\n", smp_processor_id()); - if (ret != 0) { - destroy_vmm(ctx); - DEBUG_FMT("vCPU[%d] initialization has failed\n", proc_id); - return ret; - } + int ret = init_vcpu(&ctx->vcpu_table[i], i); - 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)); + if (ret != 0) { + destroy_vmm(ctx); + DEBUG_FMT("vCPU[%lu] initialization has failed\n", i); + return ret; + } - DEBUG_FMT("vCPU[%d]'s VMCS rev id: 0x%x\n", proc_id, - ctx->vcpu_table[proc_id].vmxon->vmcs_rev_id); + 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)); - /*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);*/ - /*}*/ + DEBUG_FMT("vCPU[%lu]'s VMCS rev id: 0x%x\n", i, + ctx->vcpu_table[i].vmxon->vmcs_rev_id); + } return 0; }