Commit 0f6ce597 authored by Charles Jacobsen's avatar Charles Jacobsen Committed by Vikram Narayanan

Switched to a kmem cache for allocating lcd_arch's.

Was getting bad load/store msr addresses for vm exits.
Properly detected by the lcd_arch_check code.

In struct lcd_arch, the msr_autoload fields were not
word aligned in some instances (see requirement
in Intel SDM V3 26.2.1.2). Even with compiler align
attributes, if we use kmalloc, proper alignment is
not guaranteed - we can allocate a struct lcd_arch
on the wrong byte and it throws off the alignment
of the entire struct.

kmem cache allows specifying alignment. Appears to be
working correctly.
parent 3c46c2ca
...@@ -49,6 +49,8 @@ extern const unsigned long vmx_return; ...@@ -49,6 +49,8 @@ extern const unsigned long vmx_return;
/* SHARED / PERCPU VARS -------------------------------------------------- */ /* SHARED / PERCPU VARS -------------------------------------------------- */
static struct kmem_cache *vcpu_cache;
static struct vmx_vmcs_config vmcs_config; static struct vmx_vmcs_config vmcs_config;
static struct vmx_capability vmx_capability; static struct vmx_capability vmx_capability;
...@@ -882,6 +884,19 @@ int lcd_arch_init(void) ...@@ -882,6 +884,19 @@ int lcd_arch_init(void)
goto failed2; goto failed2;
} }
/*
* Init vcpu cache
*/
vcpu_cache = kmem_cache_create("lcd_arch_vcpu",
sizeof(struct lcd_arch),
__alignof__(struct lcd_arch),
0, NULL);
if (!vcpu_cache) {
printk(KERN_ERR "lcd_vmx: failed to set up kmem cache\n");
ret = -ENOMEM;
goto failed3;
}
/* /*
* Run tests * Run tests
*/ */
...@@ -889,6 +904,7 @@ int lcd_arch_init(void) ...@@ -889,6 +904,7 @@ int lcd_arch_init(void)
return 0; return 0;
failed3:
failed2: failed2:
on_each_cpu(vmx_disable, NULL, 1); on_each_cpu(vmx_disable, NULL, 1);
failed1: failed1:
...@@ -902,6 +918,7 @@ void lcd_arch_exit(void) ...@@ -902,6 +918,7 @@ void lcd_arch_exit(void)
on_each_cpu(vmx_disable, NULL, 1); on_each_cpu(vmx_disable, NULL, 1);
vmx_free_vmxon_areas(); vmx_free_vmxon_areas();
free_page((unsigned long)msr_bitmap); free_page((unsigned long)msr_bitmap);
kmem_cache_destroy(vcpu_cache);
} }
/* VMX EPT -------------------------------------------------- */ /* VMX EPT -------------------------------------------------- */
...@@ -2367,7 +2384,7 @@ struct lcd_arch* lcd_arch_create(void) ...@@ -2367,7 +2384,7 @@ struct lcd_arch* lcd_arch_create(void)
/* /*
* Alloc lcd_arch * Alloc lcd_arch
*/ */
vcpu = kmalloc(sizeof(*vcpu), GFP_KERNEL); vcpu = kmem_cache_alloc(vcpu_cache, GFP_KERNEL);
if (!vcpu) { if (!vcpu) {
printk(KERN_ERR "lcd arch create: failed to alloc lcd\n"); printk(KERN_ERR "lcd arch create: failed to alloc lcd\n");
goto fail_vcpu; goto fail_vcpu;
...@@ -2442,7 +2459,7 @@ fail_ept: ...@@ -2442,7 +2459,7 @@ fail_ept:
fail_vpid: fail_vpid:
vmx_free_vmcs(vcpu->vmcs); vmx_free_vmcs(vcpu->vmcs);
fail_vmcs: fail_vmcs:
kfree(vcpu); kmem_cache_free(vcpu_cache, vcpu);
fail_vcpu: fail_vcpu:
return NULL; return NULL;
} }
...@@ -2483,7 +2500,7 @@ void lcd_arch_destroy(struct lcd_arch *vcpu) ...@@ -2483,7 +2500,7 @@ void lcd_arch_destroy(struct lcd_arch *vcpu)
vmx_destroy_tss(vcpu); vmx_destroy_tss(vcpu);
vmx_destroy_stack(vcpu); vmx_destroy_stack(vcpu);
vmx_free_ept(vcpu); vmx_free_ept(vcpu);
kfree(vcpu); kmem_cache_free(vcpu_cache, vcpu);
} }
/* VMX EXIT HANDLING -------------------------------------------------- */ /* VMX EXIT HANDLING -------------------------------------------------- */
......
...@@ -1720,7 +1720,8 @@ void lcd_destroy_as_module(struct task_struct *t, char *module_name) ...@@ -1720,7 +1720,8 @@ void lcd_destroy_as_module(struct task_struct *t, char *module_name)
* Tell kthread to stop, and delete the module when it's done. * Tell kthread to stop, and delete the module when it's done.
*/ */
ret = kthread_stop(t); ret = kthread_stop(t);
LCD_ERR("kthread retval = %d", ret); if (ret)
LCD_ERR("kthread retval = %d", ret);
mutex_lock(&module_mutex); mutex_lock(&module_mutex);
m = find_module(module_name); m = find_module(module_name);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment