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

Fixed build errors, module init tools.

Getting nasty runtime bugs though.
parent 20006364
......@@ -431,19 +431,13 @@ int lcd_arch_set_sp(struct lcd_arch_thread *t, gva_t a);
int lcd_arch_set_gva_root(struct lcd_arch_thread *t, gpa_t a);
#if 0
/*
* Accessor Macro for syscalls
* ===========================
*/
#define LCD_ARCH_GET_SYSCALL_NUM(vcpu) (vcpu->regs[LCD_ARCH_REGS_RAX])
/*
* Accessor Macro for utcb
* =======================
*/
#define LCD_ARCH_GET_UTCB(vcpu) (vcpu->utcb);
#define LCD_ARCH_GET_SYSCALL_NUM(t) (t->regs[LCD_ARCH_REGS_RAX])
#if 0
/*
* Accessor Macros for IPC
* =======================
......
......@@ -945,9 +945,6 @@ void lcd_arch_exit(void)
kmem_cache_destroy(lcd_arch_thread_cache);
}
module_init(lcd_arch_init);
module_exit(lcd_arch_exit);
/* VMX EPT -------------------------------------------------- */
/**
......@@ -4349,6 +4346,7 @@ EXPORT_SYMBOL(lcd_arch_ept_walk);
EXPORT_SYMBOL(lcd_arch_ept_set);
EXPORT_SYMBOL(lcd_arch_ept_unset);
EXPORT_SYMBOL(lcd_arch_ept_unmap);
EXPORT_SYMBOL(lcd_arch_ept_unmap2);
EXPORT_SYMBOL(lcd_arch_ept_unmap_range);
EXPORT_SYMBOL(lcd_arch_ept_hpa);
EXPORT_SYMBOL(lcd_arch_ept_map);
......
......@@ -120,12 +120,17 @@ struct lcd {
* The module mapped in the lcd
*/
struct module *module;
/*
* The arch-dependent parts of the lcd (e.g., the ept)
*/
struct lcd_arch *lcd_arch;
/*
* List of contained lcd_threads
*/
struct {
struct list_head list;
struct mutex lock;
unsigned int count;
} lcd_threads;
/*
* Guest virtual paging
......
......@@ -15,11 +15,11 @@
#include <net/net_namespace.h>
#include <linux/sched/rt.h>
#ifdef CONFIG_LCD_PROTOTYPE
#define INIT_LCD(tsk) \
.lcd = NULL,
#ifdef CONFIG_HAVE_LCD
#include <lcd-domains/lcd-domains.h>
#define INIT_LCD_THREAD .lcd_thread = NULL,
#else
#define INIT_LCD
#define INIT_LCD_THREAD
#endif
#ifdef CONFIG_SMP
......@@ -254,7 +254,7 @@ extern struct task_group root_task_group;
}, \
.thread_group = LIST_HEAD_INIT(tsk.thread_group), \
.thread_node = LIST_HEAD_INIT(init_signals.thread_head), \
INIT_LCD \
INIT_LCD_THREAD \
INIT_IDS \
INIT_PERF_EVENTS(tsk) \
INIT_TRACE_IRQFLAGS \
......
......@@ -28,6 +28,7 @@
#include <errno.h>
#include <asm/unistd.h>
#include <temp/include/linux/lcd-domains.h>
#include <sys/ioctl.h>
#include "util.h"
#include "testing.h"
......
......@@ -110,7 +110,7 @@ static int lcd_mm_gfp(struct lcd *lcd, gpa_t gpa, hva_t *hva_out)
/*
* Allocate a host physical page
*/
hva = __hva(__get_zeroed_page(GFP_KERNEL));
hva = __hva(get_zeroed_page(GFP_KERNEL));
if (!hva_val(hva)) {
LCD_ERR("no host mem");
ret = -ENOMEM;
......@@ -166,20 +166,21 @@ static void lcd_mm_free_page(struct lcd *lcd, gpa_t gpa)
*/
static int lcd_mm_alloc_gv_page(struct lcd *lcd, gpa_t *gpa_out, hva_t *hva_out)
{
int ret;
gpa_t gpa;
hva_t hva;
/*
* Check counter
*/
if (lcd->counter >= LCD_PAGING_MEM_SIZE) {
if (lcd->gv_paging.counter >= LCD_PAGING_MEM_SIZE) {
LCD_ERR("exhausted guest virtual paging mem");
ret -ENOMEM;
ret = -ENOMEM;
goto fail1;
}
/*
* Allocate a host page
*/
gpa = __gpa(lcd->counter * PAGE_SIZE);
gpa = __gpa(lcd->gv_paging.counter * PAGE_SIZE);
ret = lcd_mm_gfp(lcd, gpa, &hva);
if (ret) {
LCD_ERR("getting free page");
......@@ -188,7 +189,7 @@ static int lcd_mm_alloc_gv_page(struct lcd *lcd, gpa_t *gpa_out, hva_t *hva_out)
/*
* Bump counter etc.
*/
lcd->counter += PAGE_SIZE;
lcd->gv_paging.counter += PAGE_SIZE;
*gpa_out = gpa;
*hva_out = hva;
......@@ -237,7 +238,9 @@ static int lcd_mm_pt_destroy(struct lcd *lcd, pmd_t *pmd_entry)
hpa_t hpa;
int ret;
pte_t* pt;
#if LCD_DEBUG
int i;
#endif
/*
* Get hpa of page table, using gpa stored in pmd_entry.
......@@ -846,11 +849,8 @@ static int lcd_mm_gva_unmap_range(struct lcd *lcd, gva_t gva_start,
static int lcd_vmalloc_walk(struct lcd *lcd, hva_t hva, unsigned long size,
int (*cb)(struct lcd *, hpa_t, hva_t))
{
int r;
int ret;
hpa_t hpa;
hva_t hva;
gpa_t gpa;
gva_t gva;
unsigned long mapped;
mapped = 0;
......@@ -871,6 +871,7 @@ static int lcd_vmalloc_walk(struct lcd *lcd, hva_t hva, unsigned long size,
mapped += PAGE_SIZE;
hva = hva_add(hva, PAGE_SIZE);
}
return 0;
}
/**
......@@ -905,34 +906,6 @@ static int lcd_module_map_page(struct lcd *lcd, hpa_t hpa, hva_t hva)
return 0;
}
/**
* Callback used with vmalloc walk to unmap module pages. Assumes mapping
* used in lcd_module_map_page!
*/
static int lcd_module_unmap_page(struct lcd *lcd, hpa_t hpa, hva_t hva)
{
int ret;
gpa_t gpa;
gva_t gva;
gva = __gva(hva_val(hva));
gpa = __gpa(gva_val(gva));
/*
* Unmap in ept
*/
ret = lcd_arch_ept_unmap(lcd->lcd_arch, gpa);
if (ret) {
LCD_ERR("error unmapping gpa in ept");
return ret;
}
ret = lcd_mm_gva_unmap(lcd, gva);
if (ret) {
LCD_ERR("error unmapping gva in gv");
return ret;
}
return 0;
}
/* LCD CREATE / DESTROY -------------------------------------------------- */
/**
......@@ -1042,10 +1015,9 @@ fail1:
return ret;
}
static struct lcd* __lcd_create(void)
static struct lcd * __lcd_create(void)
{
struct lcd *lcd;
int r;
/*
* Alloc lcd data structure
*
......@@ -1129,6 +1101,7 @@ fail1:
void lcd_destroy(struct lcd *lcd)
{
int ret;
/*
* Assume we have no running lcd_thread's ...
*
......@@ -1164,6 +1137,7 @@ static int lcd_setup_initial_thread(struct lcd *lcd);
int lcd_create(char *module_name, struct lcd **out)
{
int ret;
struct lcd *lcd;
/*
......@@ -1172,6 +1146,7 @@ int lcd_create(char *module_name, struct lcd **out)
lcd = __lcd_create();
if (!lcd) {
LCD_ERR("failed to init lcd");
ret = -EIO;
goto fail1;
}
/*
......@@ -1203,6 +1178,8 @@ int lcd_create(char *module_name, struct lcd **out)
*out = lcd;
return 0;
fail4:
fail3:
fail2:
lcd_destroy(lcd);
......@@ -1212,11 +1189,11 @@ fail1:
/* LCD THREAD EXECUTION -------------------------------------------------- */
static int lcd_handle_syscall(struct lcd *lcd)
static int lcd_handle_syscall(struct lcd_thread *t)
{
int syscall_id;
syscall_id = LCD_ARCH_GET_SYSCALL_NUM(lcd->lcd_arch);
syscall_id = LCD_ARCH_GET_SYSCALL_NUM(t->lcd_arch_thread);
LCD_MSG("got syscall %d", syscall_id);
switch (syscall_id) {
......@@ -1270,21 +1247,16 @@ out:
return ret;
}
static int lcd_kthread_should_stop(struct lcd_thread *t)
{
return kthread_should_stop(t->kthread);
}
static lcd_kthread_main(void *data) /* data is NULL */
static int lcd_kthread_main(void *data) /* data is NULL */
{
int ret;
struct lcd_thread *current_lcd_thread;
current_lcd_thread = current()->lcd_thread;
current_lcd_thread = current->lcd_thread;
/*
* Set my status as running
*/
current_lcd_thread->status = LCD_STATUS_RUNNING;
current_lcd_thread->status = LCD_THREAD_RUNNING;
/*
* Enter run loop, check after each iteration if we should stop
*
......@@ -1294,7 +1266,7 @@ static lcd_kthread_main(void *data) /* data is NULL */
*/
for (;;) {
ret = lcd_kthread_run_once(current_lcd_thread);
if (ret || lcd_kthread_should_stop(current_lcd_thread))
if (ret || kthread_should_stop())
return ret; /* to microkernel via kthread_stop */
}
......@@ -1307,8 +1279,8 @@ int lcd_thread_start(struct lcd_thread *t)
* Set lcd's status to runnable, and wake up the kthread (will
* start running lcd_kthread_main).
*/
t->status = LCD_STATUS_RUNNABLE;
wake_up_process(t);
t->status = LCD_THREAD_RUNNABLE;
wake_up_process(t->kthread);
return 0;
}
......@@ -1334,7 +1306,7 @@ int lcd_thread_kill(struct lcd_thread *t)
LCD_ERR("interrupted, skipping list removal ...");
goto finally;
}
list_del(&t->lcd_threads, &t->lcd->lcd_threads.list);
list_del(&t->lcd_threads);
mutex_unlock(&t->lcd->lcd_threads.lock);
finally:
......@@ -1368,7 +1340,7 @@ finally:
static int lcd_add_thread(struct lcd *lcd, gva_t pc, gva_t stack_gva,
gpa_t stack_gpa, struct lcd_thread **out)
{
struct lcd_arch_thread* t;
struct lcd_thread* t;
hpa_t stack_hpa;
hva_t stack_hva;
int ret;
......@@ -1407,7 +1379,7 @@ static int lcd_add_thread(struct lcd *lcd, gva_t pc, gva_t stack_gva,
* Set up utcb (at bottom of stack -- masking off lower bits)
*/
t->utcb = hva2va(stack_hva);
t->utcb &= PAGE_MASK;
t->utcb = (void *)(((u64)t->utcb) & PAGE_MASK);
/*
* Alloc corresponding lcd_arch_thread
*/
......@@ -1447,7 +1419,8 @@ static int lcd_add_thread(struct lcd *lcd, gva_t pc, gva_t stack_gva,
* Create a kernel thread (won't run till we wake it up)
*/
t->kthread = kthread_create(lcd_kthread_main, NULL,
"lcd:%s/%d", lcd->name, lcd->tcount);
"lcd:%s/%d", lcd->name,
lcd->lcd_threads.count++);
if (!t->kthread) {
LCD_ERR("failed to create kthread");
goto fail8;
......@@ -1473,7 +1446,7 @@ fail3:
goto fail2;
}
list_del(&t->lcd_threads, &lcd->lcd_threads.list);
list_del(&t->lcd_threads);
mutex_unlock(&lcd->lcd_threads.lock);
fail2:
......@@ -1485,16 +1458,17 @@ fail0:
static int lcd_setup_initial_thread(struct lcd *lcd)
{
struct lcd_thread *t;
struct lcd_thread *t = NULL;
hva_t stack_page;
gpa_t stack_page_gpa;
gpa_t stack_ptr_gpa;
int ret;
/*
* Allocate a page for the initial thread's stack/utcb
*
* Zero it out to prevent leakage of host data
*/
stack_page = __hva(__get_zeroed_page(GFP_KERNEL));
stack_page = __hva(get_zeroed_page(GFP_KERNEL));
if (!hva_val(stack_page)) {
LCD_ERR("alloc initial thread stack page");
ret = -ENOMEM;
......@@ -1514,8 +1488,8 @@ static int lcd_setup_initial_thread(struct lcd *lcd)
ret = lcd_arch_ept_map(lcd->lcd_arch,
stack_page_gpa,
hva2hpa(stack_page),
0,
1);
1,
0);
if (ret) {
LCD_ERR("failed to map stack in guest physical");
goto fail2;
......@@ -1535,7 +1509,7 @@ static int lcd_setup_initial_thread(struct lcd *lcd)
* code is a bit redundant, but it asserts this fact.
*/
ret = lcd_add_thread(lcd,
__gva(hva_val(__hva(lcd->module->module_init))),
__gva(hva_val(va2hva(lcd->module->module_init))),
__gva(gpa_val(stack_ptr_gpa)),
stack_ptr_gpa,
&t);
......@@ -1657,9 +1631,10 @@ static void __exit lcd_exit(void)
module_init(lcd_init);
module_exit(lcd_exit);
EXPORT_SYMBOL(lcd_create_as_module);
EXPORT_SYMBOL(lcd_run_as_module);
EXPORT_SYMBOL(lcd_destroy_as_module);
EXPORT_SYMBOL(lcd_create);
EXPORT_SYMBOL(lcd_destroy);
EXPORT_SYMBOL(lcd_thread_start);
EXPORT_SYMBOL(lcd_thread_kill);
/* DEBUGGING ---------------------------------------- */
......
......@@ -10,7 +10,7 @@
static int test01(void)
{
struct lcd *lcd;
int ret;
int ret = 0;
lcd = __lcd_create();
if (!lcd) {
......@@ -30,7 +30,7 @@ fail:
static int test02(void)
{
struct lcd *lcd;
int ret;
int ret = 0;
gpa_t gpa;
hva_t hva;
pmd_t *pmd_entry;
......@@ -106,7 +106,7 @@ fail1:
static int test03(void)
{
struct lcd *lcd;
int ret;
int ret = 0;
gpa_t gpa;
hva_t hva;
pud_t *pud_entry;
......@@ -135,7 +135,7 @@ static int test03(void)
* Populate 5th entry in pmd to point to a (bogus) page table at
* gpa 0x1234000UL.
*/
pmd = (pmd_t *)hva2va(hpa);
pmd = (pmd_t *)hva2va(hva);
set_pmd_gpa(pmd + 4, __gpa(0x1234000UL));
/*
......@@ -183,7 +183,7 @@ fail1:
static int test04(void)
{
struct lcd *lcd;
int ret;
int ret = 0;
gpa_t gpa;
hva_t hva;
pgd_t *pgd_entry;
......@@ -260,11 +260,11 @@ fail1:
static int test05(void)
{
struct lcd *lcd;
int ret;
int ret = 0;
gpa_t gpa;
lcd = __lcd_create();
if (ret) {
if (!lcd) {
LCD_ERR("failed to create lcd");
goto fail1;
}
......@@ -295,12 +295,14 @@ static int test05(void)
if (gpa_val(gpa) != 0x5678000UL) {
LCD_ERR("got phys addr %lx\n", gpa_val(gpa));
ret = -1;
goto fail5;
}
ret = lcd_mm_gva_unmap(lcd, __gva(0x1234000UL));
if (ret) {
LCD_ERR("failed to unmap");
ret = -1;
goto fail6;
}
......@@ -321,11 +323,9 @@ fail1:
static int test06(void)
{
struct lcd *lcd;
int ret;
int ret = 0;
pgd_t *pgd_entry1;
pgd_t *pgd_entry2;
gpa_t gpa1;
gpa_t gpa2;
lcd = __lcd_create();
if (!lcd) {
......@@ -365,13 +365,6 @@ static int test06(void)
goto fail5;
}
if (gpa_val(gpa1) != gpa_val(gpa2)) {
LCD_ERR("two diff gpa's: first = %lx, second %lx\n",
gpa_val(gpa1), gpa_val(gpa2));
ret = -1;
goto fail5;
}
ret = 0;
goto done;
......@@ -408,7 +401,7 @@ static int test07_help(struct lcd *lcd, unsigned long base)
static int test07(void)
{
struct lcd *lcd;
int ret;
int ret = 0;
unsigned long base;
lcd = __lcd_create();
......@@ -456,13 +449,13 @@ static int test07(void)
*/
base = 0;
if (test09_help(lcd, base))
if (test07_help(lcd, base))
goto fail6;
base = 1 << 30;
if (test09_help(lcd, base))
if (test07_help(lcd, base))
goto fail6;
base = 1UL << 39;
if (test09_help(lcd, base))
if (test07_help(lcd, base))
goto fail6;
ret = 0;
......@@ -485,13 +478,13 @@ fail1:
static int test08(void)
{
struct lcd *lcd;
int r;
int ret;
/*
* lcd-module-load-test.c is in virt/lcd-domains/
*/
ret = lcd_create(&lcd);
ret = lcd_create("lcd_module_load_test", &lcd);
if (ret) {
LCD_ERR("creating lcd");
goto fail1;
......
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