Skip to content
Snippets Groups Projects
Commit 6f3597ac authored by iliya.saroukha's avatar iliya.saroukha
Browse files

feat: switching to specific cpus using the set_cpus_allowed_ptr func

parent 64d02a09
No related branches found
No related tags found
No related merge requests found
......@@ -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");
......
#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;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment