Commit 5c5080d9 authored by Charles Jacobsen's avatar Charles Jacobsen Committed by Vikram Narayanan

Starting to adjust Anton's stack trace code for new design.

Going to take a bit more work because the struct module is no
longer directly available on the host side, so starting a new branch ...
parent c4fc9f87
......@@ -285,10 +285,6 @@ enum lcd_arch_status {
*/
int lcd_arch_ept_walk(struct lcd_arch *lcd, gpa_t a, int create,
lcd_arch_epte_t **epte_out);
int lcd_arch_ept_gpa_to_hva(struct lcd_arch *lcd, unsigned long gva,
unsigned long *hva_out);
/**
* Set the guest physical => host physical mapping in the ept entry.
*/
......@@ -348,6 +344,20 @@ int lcd_arch_ept_unmap_range(struct lcd_arch *lcd, gpa_t ga_start,
* Simple routine combinding ept walk and get.
*/
int lcd_arch_ept_gpa_to_hpa(struct lcd_arch *lcd, gpa_t ga, hpa_t *ha_out);
/**
* Translate guest physical address to host virtual.
*/
static inline int lcd_arch_ept_gpa_to_hva(struct lcd_arch *lcd, gpa_t gpa,
hva_t *hva_out)
{
hpa_t hpa;
int ret;
ret = lcd_arch_ept_gpa_to_hpa(lcd, gpa, &hpa);
if (ret)
return ret;
*hva_out = hpa2hva(hpa);
return 0;
}
/**
* Set the lcd's program counter to the guest virtual address
* a.
......@@ -358,7 +368,7 @@ int lcd_arch_set_pc(struct lcd_arch *lcd_arch, gva_t a);
*/
static inline u64 lcd_arch_get_pc(struct lcd_arch *lcd)
{
return lcd->regs[LCD_ARCH_REGS_RIP];
return lcd->regs.rip;
}
/**
* Set the lcd's stack pointer to the guest virtual address
......@@ -381,23 +391,23 @@ static inline u64 lcd_arch_get_syscall_num(struct lcd_arch *lcd)
}
static inline u64 lcd_arch_get_syscall_arg0(struct lcd_arch *lcd)
{
return lcd->regs[LCD_ARCH_REGS_R8];
return lcd->regs.r8;
}
static inline u64 lcd_arch_get_syscall_arg1(struct lcd_arch *lcd)
{
return lcd->regs[LCD_ARCH_REGS_R9];
return lcd->regs.r9;
}
static inline u64 lcd_arch_get_syscall_arg2(struct lcd_arch *lcd)
{
return lcd->regs[LCD_ARCH_REGS_R10];
return lcd->regs.r10;
}
static inline u64 lcd_arch_get_syscall_arg3(struct lcd_arch *lcd)
{
return lcd->regs[LCD_ARCH_REGS_R11];
return lcd->regs.r11;
}
static inline u64 lcd_arch_get_syscall_arg4(struct lcd_arch *lcd)
{
return lcd->regs[LCD_ARCH_REGS_R12];
return lcd->regs.r12;
}
static inline void lcd_arch_set_syscall_ret(struct lcd_arch *lcd, u64 val)
{
......
......@@ -2852,8 +2852,8 @@ static void __noclone vmx_enter(struct lcd_arch *lcd_arch)
clear_non_root();
lcd_arch->regs[LCD_ARCH_REGS_RIP] = vmcs_readl(GUEST_RIP);
lcd_arch->regs[LCD_ARCH_REGS_RSP] = vmcs_readl(GUEST_RSP);
lcd_arch->regs.rip = vmcs_readl(GUEST_RIP);
lcd_arch->regs.rsp = vmcs_readl(GUEST_RSP);
if (unlikely(lcd_arch->fail)) {
/*
......
......@@ -248,6 +248,18 @@
#define LCD_KERNEL_MODULE_REGION_GV_ADDR \
(__gva(LCD_VIRT_BASE + LCD_KERNEL_MODULE_REGION_OFFSET))
/* CONVERSION MACROS -------------------------------------------------- */
static inline gva_t isolated_lcd_gpa2gva(gpa_t gpa)
{
return __gva(LCD_VIRT_BASE + (gpa_val(gpa) - LCD_PHYS_BASE));
}
static inline gpa_t isolated_lcd_gva2gpa(gva_t gva)
{
return __gpa(LCD_PHYS_BASE + (gva_val(gva) - LCD_VIRT_BASE));
}
/* ASSERTIONS -------------------------------------------------- */
......
......@@ -448,12 +448,12 @@ void lcd_unvolunteer_vmalloc_mem(cptr_t vmalloc_mem)
gpa_t lcd_gva2gpa(gva_t gva)
{
return __gpa(LCD_PHYS_BASE + (gva_val(gva) - LCD_VIRT_BASE));
return isolated_lcd_gva2gpa(gva);
}
gva_t lcd_gpa2gva(gpa_t gpa)
{
return __gva(LCD_VIRT_BASE + (gpa_val(gpa) - LCD_PHYS_BASE));
return isolated_lcd_gpa2gva(gpa);
}
/* INIT/EXIT -------------------------------------------------- */
......
......@@ -26,13 +26,14 @@
#include <linux/module.h>
#include <linux/kallsyms.h>
#include <asm/lcd-domains.h>
#include <asm/lcd_domains/main.h>
#include <liblcd/address_spaces.h>
static int debug_stack_lines = 20;
#define _p(_x) ((void *)(unsigned long)(_x))
#define stack_words_per_line 4
#define ESP_BEFORE_EXCEPTION(regs) ((unsigned long *)regs->rsp)
#define ESP_BEFORE_EXCEPTION(regs) ((unsigned long)regs->rsp)
#if 0
......@@ -117,15 +118,6 @@ static void show_guest_stack(struct vcpu *v, const struct cpu_user_regs *regs)
#endif
/*
* * Identify which stack page the stack pointer is on. Returns an index
* * as per the comment above.
* */
static inline unsigned int get_stack_page(unsigned long sp)
{
return (sp & (LCD_STACK_SIZE-1)) >> PAGE_SHIFT;
}
/*
* Notes for get_stack_trace_bottom() and get_stack_dump_bottom()
*
......@@ -321,27 +313,41 @@ static void show_trace(struct lcd_arch *lcd, const struct cpu_user_regs *regs)
}
void show_stack(struct lcd_arch *lcd, const struct cpu_user_regs *regs)
void lcd_show_stack(struct lcd_arch *lcd, const struct cpu_user_regs *regs)
{
unsigned long *stack = ESP_BEFORE_EXCEPTION(regs), *stack_bottom, stack_hva, data;
/*
* In order to handle async cactus stacks, the stack bottom is
* always taken to be %rsp - wordsize.
*/
gva_t stack_gva = __gva((unsigned long)regs->rsp);
gpa_t stack_gpa;
hva_t stack_hva;
gva_t stack_bottom_gva = __gva(gva_val(stack) - sizeof(unsigned long));
unsigned long data;
int i, ret;
printk("LCD stack trace from "__OP"sp=%p:\n ", stack);
stack_bottom = _p(get_stack_dump_bottom(regs->rsp));
printk("LCD stack trace from "__OP"sp=0x%lx:\n ", gva_val(stack));
for ( i = 0; i < (debug_stack_lines*stack_words_per_line) &&
(stack <= stack_bottom); i++ )
(gva_val(stack_gva) <= gva_val(stack_bottom_gva)); i++ )
{
if ( (i != 0) && ((i % stack_words_per_line) == 0) )
printk("\n ");
ret = lcd_arch_ept_gpa_to_hva(lcd, (unsigned long) stack, &stack_hva);
/*
* Resolve gva ==> gpa
*/
stack_gpa = isolated_lcd_gva2gpa(stack_gva);
/*
* Resolve gpa ==> hva so we can read the memory there
*/
ret = lcd_arch_ept_gpa_to_hva(lcd, stack_gpa, &stack_hva);
if (ret) {
LCD_ARCH_ERR("Failed to resolve guest stack gpa into hpa\n");
return;
};
LCD_ARCH_ERR("Failed to resolve guest stack gpa into hpa\n");
return;
}
/*
*
//printk("hva_stack:%p, stack:%p\n", (unsigned long *)stack_hva, stack);
......@@ -449,10 +455,11 @@ void lcd_show_registers(const struct cpu_user_regs *regs)
}
void lcd_show_execution_state(struct lcd_arch *lcd, const struct cpu_user_regs *regs)
void lcd_show_execution_state(struct lcd_arch *lcd,
const struct cpu_user_regs *regs)
{
lcd_show_registers(regs);
show_stack(lcd, regs);
lcd_show_stack(lcd, regs);
}
#if 0
......@@ -490,13 +497,3 @@ void vcpu_show_execution_state(struct vcpu *v)
//
// return trapnr < ARRAY_SIZE(strings) ? strings[trapnr] : "???";
//}
/*
* Local variables:
* mode: C
* c-file-style: "BSD"
* c-basic-offset: 4
* tab-width: 4
* indent-tabs-mode: nil
* End:
*/
......@@ -25,8 +25,7 @@ static int boot_main(void)
/*
* Create a new lcd
*/
ret = lcd_create_module_lcd(&lcd,
LCD_DIR("bug"),
ret = lcd_create_module_lcd(LCD_DIR("bug/lcd"),
"lcd_test_mod_bug_lcd",
LCD_CPTR_NULL, &mi);
if (ret) {
......
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