Commit a64b8301 authored by Charlie Jacobsen's avatar Charlie Jacobsen Committed by Vikram Narayanan

Starting simple regression test code, to save debugging time.

Successful build and insmod on emulab, but errors when trying
to create lcd (perhaps errors mapping in ept). Regression tests
should help and save debugging time in future.
parent f34be85a
......@@ -180,6 +180,10 @@ u64 lcd_arch_ept_hpa(lcd_arch_epte_t *epte);
*/
int lcd_arch_ept_map_gpa_to_hpa(struct lcd_arch *vcpu, u64 gpa, u64 hpa,
int create, int overwrite);
/**
* Simple routine combinding ept walk and get.
*/
int lcd_arch_ept_gpa_to_hpa(struct lcd_arch *vcpu, u64 gpa, u64 *hpa_out);
/*
* GDT Layout
......
/**
* Regression tests for lcd arch code.
*
* Included in lcd-domains-arch.c and
* ran last in lcd_arch_init.
*/
static int test01(void)
{
struct lcd_arch_vmcs *vmcs;
vmcs = vmx_alloc_vmcs(raw_smp_processor_id());
if (!vmcs) {
printk(KERN_ERR "lcd arch: test01 failed\n");
return -1;
}
vmx_free_vmcs(vmcs);
return 0;
}
static int test02(void)
{
struct lcd_arch *lcd;
lcd = (struct lcd_arch *)kmalloc(sizeof(*lcd), GFP_KERNEL);
if (!lcd) {
printk(KERN_ERR "lcd arch : test02 failed to alloc lcd\n");
goto fail_alloc;
}
if (vmx_allocate_vpid(lcd)) {
printk(KERN_ERR "lcd arch : test02 vpid alloc failed\n");
goto fail;
}
if (lcd->vpid != 1) {
printk(KERN_ERR "lcd arch : test02 actual vpid = %d\n",
lcd->vpid);
goto fail_free;
}
if (vmx_allocate_vpid(lcd)) {
printk(KERN_ERR "lcd arch : test02 2nd vpid alloc failed\n");
goto fail;
}
if (lcd->vpid != 1) {
printk(KERN_ERR "lcd arch : test02 2nd actual vpid = %d\n",
lcd->vpid);
goto fail_free;
}
kfree(lcd);
return 0;
fail_free:
vmx_free_vpid(lcd);
fail:
kfree(lcd);
fail_alloc:
return -1;
}
static int test03(void)
{
struct lcd_arch *lcd;
int i;
char *buf;
lcd = (struct lcd_arch *)kmalloc(sizeof(*lcd), GFP_KERNEL);
if (!lcd) {
printk(KERN_ERR "lcd arch : test03 failed to alloc lcd\n");
goto fail_alloc;
}
if (vmx_init_ept(lcd)) {
printk(KERN_ERR "lcd arch : test03 ept init failed\n");
goto fail;
}
buf = (char *)__va(lcd->ept.root_hpa);
for (i = 0; i < PAGE_SIZE; i++) {
if (buf[i]) {
printk(KERN_ERR "lcd arch : test03 nonzero in ept\n");
goto fail_mem;
}
}
vmx_free_ept(lcd);
kfree(lcd);
return 0;
fail_mem:
vmx_free_ept(lcd);
fail:
kfree(lcd);
fail_alloc:
return -1;
}
static int test04(void)
{
struct lcd_arch *lcd;
u64 hpa;
lcd = (struct lcd_arch *)kmalloc(sizeof(*lcd), GFP_KERNEL);
if (!lcd) {
printk(KERN_ERR "lcd arch : test04 failed to alloc lcd\n");
goto fail_alloc;
}
if (vmx_init_ept(lcd)) {
printk(KERN_ERR "lcd arch : test04 ept init failed\n");
goto fail_ept;
}
if (vmx_init_gdt(lcd)) {
printk(KERN_ERR "lcd arch : test04 gdt init failed\n");
goto fail_gdt;
}
if (lcd_arch_ept_gpa_to_hpa(lcd, LCD_ARCH_GDT_BASE, &hpa)) {
printk(KERN_ERR "lcd arch : test04 lookup failed\n");
goto fail_lookup;
}
if (hpa != __pa(lcd->gdt)) {
printk(KERN_ERR "lcd arch : test04 unexpected gdt addr\n");
goto fail_lookup;
}
vmx_free_ept(lcd); /* frees gdt */
kfree(lcd);
return 0;
fail_lookup:
fail_gdt:
vmx_free_ept(lcd);
fail_ept:
kfree(lcd);
fail_alloc:
return -1;
}
static void lcd_arch_tests(void)
{
if (test01())
return;
if (test02())
return;
if (test03())
return;
if (test04())
return;
return;
}
......@@ -777,6 +777,9 @@ static int setup_vmcs_config(struct vmx_vmcs_config *vmcs_conf)
/* VMX INIT / EXIT -------------------------------------------------- */
/* for debugging */
#include "lcd-domains-arch-tests.c"
int lcd_arch_init(void)
{
int ret;
......@@ -854,6 +857,11 @@ int lcd_arch_init(void)
goto failed2;
}
/*
* Run tests
*/
lcd_arch_tests();
return 0;
failed2:
......@@ -1011,6 +1019,26 @@ int lcd_arch_ept_map_gpa_to_hpa(struct lcd_arch *vcpu, u64 gpa, u64 hpa,
return 0;
}
int lcd_arch_ept_gpa_to_hpa(struct lcd_arch *vcpu, u64 gpa, u64 *hpa_out)
{
int ret;
lcd_arch_epte_t *ept_entry;
/*
* Walk ept
*/
ret = lcd_arch_ept_walk(vcpu, gpa, create, &ept_entry);
if (ret)
return ret;
/*
* Map the guest physical addr to the host physical addr.
*/
*hpa = lcd_arch_ept_hpa(ept_entry);
return 0;
}
/**
* Recursively frees all present entries in dir at level, and
* the page containing the dir.
......@@ -2051,9 +2079,7 @@ void lcd_arch_destroy(struct lcd_arch *vcpu)
*/
vmx_free_vpid(vcpu);
vmx_free_vmcs(vcpu->vmcs);
free_page((u64)vcpu->gdt);
free_page((u64)vcpu->tss);
free_page((u64)vcpu->utcb);
vmx_free_ept(vcpu); /* auto frees gdt, tss, utcb */
kfree(vcpu);
}
......@@ -2509,3 +2535,4 @@ EXPORT_SYMBOL(lcd_arch_ept_walk);
EXPORT_SYMBOL(lcd_arch_ept_set);
EXPORT_SYMBOL(lcd_arch_ept_hpa);
EXPORT_SYMBOL(lcd_arch_ept_map_gpa_to_hpa);
EXPORT_SYMBOL(lcd_arch_ept_gpa_to_hpa);
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