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

Simple explicit tss, gdt, and stack tear down.

(Code before relied on free ept to free memory. But
this could be confusing and hard to debug in the future...)
parent a6130165
......@@ -189,6 +189,10 @@ int lcd_arch_ept_unset(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 combining ept walk and unset.
*/
int lcd_arch_ept_unmap_gpa(struct lcd_arch *vcpu, u64 gpa);
/**
* Simple routine combinding ept walk and get.
*/
......
......@@ -1051,6 +1051,27 @@ int lcd_arch_ept_map_gpa_to_hpa(struct lcd_arch *vcpu, u64 gpa, u64 hpa,
return 0;
}
int lcd_arch_ept_unmap_gpa(struct lcd_arch *vcpu, u64 gpa)
{
int ret;
lcd_arch_epte_t *ept_entry;
/*
* Walk ept
*/
ret = lcd_arch_ept_walk(vcpu, gpa, create, &ept_entry);
if (ret)
return ret;
/*
* Unset
*/
lcd_arch_ept_unset(ept_entry);
return 0;
}
int lcd_arch_ept_gpa_to_hpa(struct lcd_arch *vcpu, u64 gpa, u64 *hpa_out)
{
int ret;
......@@ -1883,6 +1904,18 @@ fail:
return ret;
}
/**
* Unmaps gdt in ept, and frees memory.
*/
static void vmx_destroy_gdt(struct lcd_arch *vcpu)
{
free_page((u64)vcpu->gdt);
if (lcd_arch_ept_unmap_gpa(vcpu, LCD_ARCH_GDTR_BASE)) {
printk(KERN_ERR "vmx_destroy_gdt: error unmapping gdt\n");
}
vcpu->gdt = NULL;
}
/**
* Allocates tss and sets minimal number of fields needed.
*
......@@ -1952,6 +1985,18 @@ fail:
return ret;
}
/**
* Unmaps tss and frees memory.
*/
static void vmx_destroy_tss(struct lcd_arch *vcpu)
{
free_page((u64)vcpu->tss);
if (lcd_arch_ept_unmap_gpa(vcpu, LCD_ARCH_TSS_BASE)) {
printk(KERN_ERR "vmx_destroy_tss: error unmapping tss\n");
}
vcpu->tss = NULL;
}
/**
* Allocates and maps stack / utcb. Initializes
* stack pointer.
......@@ -2002,6 +2047,18 @@ fail:
return ret;
}
/**
* Unmaps stack and frees memory.
*/
static void vmx_destroy_stack(struct lcd_arch *vcpu)
{
free_page((u64)vcpu->utcb);
if (lcd_arch_ept_unmap_gpa(vcpu, LCD_ARCH_UTCB)) {
printk(KERN_ERR "vmx_destroy_stack: error unmapping tss\n");
}
vcpu->utcb = NULL;
}
/**
* Reserves a vpid and sets it in the vcpu.
*/
......@@ -2105,12 +2162,10 @@ struct lcd_arch* lcd_arch_create(void)
return vcpu;
fail_stack:
vmx_destroy_tss(vcpu);
fail_tss:
vmx_destroy_gdt(vcpu);
fail_gdt:
/*
* free ept will free gdt, tss, and stack, since they
* are mapped in ept
*/
vmx_free_ept(vcpu);
fail_ept:
vmx_free_vpid(vcpu);
......@@ -2154,7 +2209,10 @@ void lcd_arch_destroy(struct lcd_arch *vcpu)
*/
vmx_free_vpid(vcpu);
vmx_free_vmcs(vcpu->vmcs);
vmx_free_ept(vcpu); /* auto frees gdt, tss, utcb */
vmx_destroy_gdt(vcpu);
vmx_destroy_tss(vcpu);
vmx_destroy_stack(vcpu);
vmx_free_ept(vcpu);
kfree(vcpu);
}
......
......@@ -123,7 +123,7 @@ static int lcd_mm_gpa_map_range(struct lcd *lcd, u64 gpa_start, u64 hpa_start,
*
* Must be called before mapping any gva's.
*/
int lcd_mm_gva_init(struct lcd *lcd, u64 gv_paging_mem_gpa_start,
static int lcd_mm_gva_init(struct lcd *lcd, u64 gv_paging_mem_gpa_start,
u64 gv_paging_mem_end)
{
u64 root;
......@@ -179,7 +179,7 @@ int lcd_mm_gva_init(struct lcd *lcd, u64 gv_paging_mem_gpa_start,
*
* Note! Call lcd_mm_gva_init before mapping any gva's.
*/
int lcd_mm_gva_map_range(struct lcd *lcd, u64 gva_start, u64 gpa_start,
static int lcd_mm_gva_map_range(struct lcd *lcd, u64 gva_start, u64 gpa_start,
u64 npages)
{
/* unimplemented */
......
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