Commit 3710d903 authored by Charles Jacobsen's avatar Charles Jacobsen Committed by Vikram Narayanan

test-v2: Fix some allocator bugs, fix cptr cache bug.

I was using PAGE_SIZE instead of PAGE_SHIFT in some places.

Also, non-isolated code sets up the cptr cache for isolated
code; but the size of the mutex is different for each environment
(16 bytes versus 8 bytes). So, I hacked libcap to take care of
the difference (using padding).
parent 666f9dae
......@@ -56,6 +56,8 @@ LCD_BUILD_DIR=$(LCD_DOMAINS_TOP_SRC_DIR)/$(LCD_BUILD_DIR_REL)
# ------------------------------------------------------------
# CSPACE configuration
# Since non-isolated code sets up the boot cptr cache for isolated code
# you need to use the same config for both environments.
LCD_CSPACE_DEPTH_BITS=2 # depth = 4
LCD_CSPACE_CNODE_TABLE_BITS=3 # cnode tables have 8 slots
......@@ -64,7 +66,7 @@ LCD_CSPACE_CNODE_TABLE_BITS=3 # cnode tables have 8 slots
# build_all.sh does the right target sequencing
all:
scripts/build_all.sh
scripts/build_all.sh $(MAKEFLAGS)
# ------------------------------------------------------------
# Microkernel build setup
......@@ -135,7 +137,7 @@ LIBLCD_BUILD_DIRS=$(foreach dir,$(LIBLCD_DIRS),\
LIBLCD_LIBCAP=$(LIBLCD_BUILD_DIR)/libcap.install/lib/libcap.a
LIBLCD_LIBCAP_CFLAGS= \
"-DLCD_DOMAINS -I$(LCD_DOMAINS_TOP_SRC_DIR)/include -I$(LCD_DOMAINS_TOP_SRC_DIR)/config/isolated"
"-DLCD_DOMAINS -DCPTR_CACHE_LOCK_PADDING_SIZE=8 -I$(LCD_DOMAINS_TOP_SRC_DIR)/include -I$(LCD_DOMAINS_TOP_SRC_DIR)/config/isolated"
# There isn't a nice easy way to multiline this, and I want access to the
# LIBLCD_BUILD_DIR variable (so I don't want to create a separate file); so
......
......@@ -39,7 +39,7 @@ static inline int lcd_syscall_one_arg(int id, unsigned long arg0)
"movq %%rax, %0 \n\t"
: "=g" (ret)
: "g" (id), "g" (arg0)
: "rax");
: "rax", "r8");
return (int)ret;
}
......@@ -56,7 +56,7 @@ static inline int lcd_syscall_two_args(int id,
"movq %%rax, %0 \n\t"
: "=g" (ret)
: "g" (id), "g" (arg0), "g" (arg1)
: "rax");
: "rax", "r8", "r9");
return (int)ret;
}
......@@ -75,7 +75,7 @@ static inline int lcd_syscall_three_args(int id,
"movq %%rax, %0 \n\t"
: "=g" (ret)
: "g" (id), "g" (arg0), "g" (arg1), "g" (arg2)
: "rax");
: "rax", "r8", "r9", "r10");
return (int)ret;
}
......@@ -96,7 +96,7 @@ static inline int lcd_syscall_four_args(int id,
"movq %%rax, %0 \n\t"
: "=g" (ret)
: "g" (id), "g" (arg0), "g" (arg1), "g" (arg2), "g" (arg3)
: "rax");
: "rax", "r8", "r9", "r10", "r11");
return (int)ret;
}
......@@ -120,7 +120,7 @@ static inline int lcd_syscall_five_args(int id,
: "=g" (ret)
: "g" (id), "g" (arg0), "g" (arg1), "g" (arg2), "g" (arg3),
"g" (arg4)
: "rax");
: "rax", "r8", "r9", "r10", "r11", "r12");
return (int)ret;
}
......@@ -140,7 +140,7 @@ static inline int lcd_syscall_cap_grant(cptr_t lcd, cptr_t src, cptr_t dest)
cptr_val(lcd), cptr_val(src), cptr_val(dest));
}
static inline int lcd_syscall_putchar(char c)
static inline int lcd_syscall_putchar(unsigned char c)
{
return lcd_syscall_one_arg(LCD_SYSCALL_PUTCHAR, c);
}
......
......@@ -185,7 +185,7 @@ static int setup_phys_addr_space(cptr_t lcd, struct lcd_create_ctx *ctx,
m_init_link_addr, m_core_link_addr);
if (ret)
goto fail4;
return 0;
fail4: /* Just return; caller should kill new LCD and free up resources. */
......@@ -568,7 +568,6 @@ int lcd_create_module_lcd(char *mdir, char *mname, cptr_t *lcd_out,
LIBLCD_ERR("error configuring LCDs registers");
goto fail6;
}
/*
* Return context and lcd
*/
......
......@@ -58,11 +58,6 @@
lcd_exit(-1); \
} while(0)
#undef printk
#define printk(fmt, args...) do { \
lcd_printk(fmt, ##args); \
} while(0)
#undef printk_ratelimit
#define printk_ratelimit() true
......
......@@ -11,6 +11,7 @@
#include <libcap.h>
#include <lcd_domains/types.h>
#include <liblcd/console.h>
#define LCD_NUM_BOOT_CPTRS 8
......@@ -46,5 +47,30 @@ struct lcd_boot_info {
* For non-isolated code, this function returns NULL.
*/
struct lcd_boot_info * lcd_get_boot_info(void);
/**
* lcd_dump_boot_info -- Print the bits in the lcd_boot_info
*
* This is for debugging.
*/
static inline void lcd_dump_boot_info(struct lcd_boot_info *b)
{
unsigned long idx;
unsigned char *bits = (char *)b;
/*
* This isn't ideal for printing, but it needs to be useable
* before kmalloc etc. is available. (Can't alloc a string
* buffer and sprintf into it.)
*/
LIBLCD_MSG(" DUMPING lcd_boot_info bits:");
for (idx = 0; idx < sizeof(struct lcd_boot_info); idx++) {
if (idx % 10 == 0)
printk(KERN_ERR "\n ");
/* We do the hex manually because vsnprintf if used inside
* the isolated liblcd, and it outputs the data in a weird
* way. */
printk(KERN_ERR "%02x ", bits[idx]);
}
printk(KERN_ERR "\n");
}
#endif /* LIBLCD_BOOTINFO_H */
......@@ -8,6 +8,8 @@
#ifndef LCD_DOMAINS_CONSOLE_H
#define LCD_DOMAINS_CONSOLE_H
#include <linux/kernel.h> /* for va_list */
/**
* lcd_printk -- Print a message to the host kernel log
* @fmt: format string
......@@ -18,7 +20,13 @@
* Most of the standard format escapes are supported, but
* not the more fancy ones.
*/
void lcd_printk(char *fmt, ...);
void lcd_printk(const char *fmt, ...);
/**
* _lcd_printk -- Allow explicit pass of varargs pointer
* @fmt: the format string
* @args: the va_list varargs obtained via e.g. va_start
*/
void _lcd_printk(const char *fmt, va_list args);
/**
* Some helpful macros for printing file and line numbers.
......
......@@ -182,6 +182,18 @@ lcd_to_boot_cptr_cache(struct lcd_create_ctx *ctx)
{
return &ctx->lcd_boot_info->cptr_cache;
}
/**
* lcd_dump_virt_addr_space -- Print the virtual addr space in @ctx
*
* This is for debugging the virtual address space set up. Invoking this
* function will dump the virtual page tables set up for the LCD (the data
* in @ctx->gv_page_tables). This does not do page walks via %cr3. In the
* future, this function could be implemented differently for isolated
* and non-isolated code. Non-isolated code could use the EPTs to resolve
* guest physical to host physical, and do a full %cr3 based traversal (this
* isn't possible for isolated code since it can't access EPTs).
*/
void lcd_dump_virt_addr_space(struct lcd_create_ctx *ctx);
/**
* lcd_destroy_create_ctx -- Tear down lcd_create_ctx returned from
* lcd_create_module_lcd
......
......@@ -7,15 +7,22 @@
#include <linux/printk.h>
#include <liblcd/liblcd.h>
void lcd_printk(char *fmt, ...)
void _lcd_printk(const char *fmt, va_list args)
{
printk(KERN_ERR "message from klcd %p: ", current->lcd);
vprintk(fmt, args);
printk("\n"); /* flush */
}
void lcd_printk(const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
vprintk(fmt, args);
_lcd_printk(fmt, args);
va_end(args);
printk("\n"); /* flush */
}
/* EXPORTS -------------------------------------------------- */
EXPORT_SYMBOL(lcd_printk);
EXPORT_SYMBOL(_lcd_printk);
......@@ -208,7 +208,7 @@ int lcd_load_module(char *mdir, char *mname,
*m_init_link_addr = __gva((unsigned long)m->module_init);
*m_core_link_addr = __gva((unsigned long)m->module_core);
LCD_MSG("Loaded %s.ko: ", mname);
LIBLCD_MSG("Loaded %s.ko: ", mname);
printk(" init addr 0x%p init size 0x%x\n",
m->module_init, m->init_size);
printk(" core addr 0x%p core size 0x%x\n",
......
Subproject commit 54c7670a8c686e1af35bce031aa466b39f37a643
Subproject commit dccb7e435ffdf19355d019482a84fdae5d4b7b56
......@@ -385,7 +385,7 @@ static int alloc_metadata_page_blocks(struct lcd_page_allocator *pa,
/*
* Allocate the big chunks first
*/
while (metadata_sz > (1UL << (pa->max_order + PAGE_SIZE))) {
while (metadata_sz > (1UL << (pa->max_order + PAGE_SHIFT))) {
/*
* Allocate 2^max_order bytes
*/
......@@ -412,7 +412,7 @@ static int alloc_metadata_page_blocks(struct lcd_page_allocator *pa,
/*
* Shift to next 2^max_order chunk
*/
metadata_sz -= (1UL << (pa->max_order + PAGE_SIZE));
metadata_sz -= (1UL << (pa->max_order + PAGE_SHIFT));
}
/*
* Allocate the remainder, rounded up to the closest power of 2
......@@ -594,7 +594,7 @@ static unsigned long calc_metadata_size(unsigned int nr_pages_order,
*
* 1 - metadata to fit in memory area if we are embedding it
*/
if (embed_metadata && rslt > (1UL << (nr_pages_order + PAGE_SIZE))) {
if (embed_metadata && rslt > (1UL << (nr_pages_order + PAGE_SHIFT))) {
LIBLCD_ERR("trying to embed metadata, but it won't fit in the memory area; either increase the memory area size, or adjust other params so there is less metadata");
return -EINVAL;
}
......
......@@ -13,17 +13,14 @@
#include <lcd_config/post_hook.h>
void lcd_printk(char *fmt, ...)
void _lcd_printk(const char *fmt, va_list args)
{
va_list args;
char buf[512]; /* this is probably a bit big ... */
char *p;
unsigned char buf[512]; /* this is probably a bit big ... */
unsigned char *p;
/*
* Convert fmt string to chars
*/
va_start(args, fmt);
vsnprintf(buf, 512, fmt, args);
va_end(args);
/*
* Write char by char
*/
......@@ -34,3 +31,14 @@ void lcd_printk(char *fmt, ...)
*/
lcd_syscall_putchar(0);
}
void lcd_printk(const char *fmt, ...)
{
va_list args;
/*
* Convert fmt string to chars
*/
va_start(args, fmt);
_lcd_printk(fmt, args);
va_end(args);
}
......@@ -15,6 +15,8 @@
#include <lcd_config/post_hook.h>
static int thc_initialized;
int lcd_enter(void)
{
int ret;
......@@ -25,8 +27,7 @@ int lcd_enter(void)
* on failure (and everything will get torn down and freed
* then).
*
* Create our call endpoint (for call/reply interactions)
*/
* Create our call endpoint (for call/reply interactions) */
ret = _lcd_create_sync_endpoint(LCD_CPTR_CALL_ENDPOINT);
if (ret) {
LIBLCD_ERR("creating call endpoint");
......@@ -73,6 +74,8 @@ int lcd_enter(void)
* Set up async runtime
*/
thc_init();
thc_initialized = 1;
LIBLCD_MSG("async runtime initialized");
lcd_printk("===============");
lcd_printk(" LCD BOOTED ");
......@@ -94,7 +97,8 @@ void __noreturn lcd_exit(int retval)
* For now, just tear down async so we can make sure
* it all worked.
*/
thc_done();
if (thc_initialized)
thc_done();
LIBLCD_MSG("exiting");
......
......@@ -104,3 +104,14 @@ void mutex_unlock(struct mutex *lock)
/* SCHEDULING ------------------------------------------------------------ */
int _cond_resched(void) { return 0; } /* Never signal reschedule */
/* PRINTK -------------------------------------------------- */
int printk(const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
_lcd_printk(fmt, args);
va_end(args);
return 0;
}
......@@ -173,6 +173,11 @@ static int handle_syscall_pages_alloc(struct lcd *lcd)
* Get slot where to store alloc'd pages, flags,
* and order
*/
LCD_ERR("syscall args: %lx, %lx, %lx",
lcd_arch_get_syscall_arg0(lcd->lcd_arch),
lcd_arch_get_syscall_arg1(lcd->lcd_arch),
lcd_arch_get_syscall_arg2(lcd->lcd_arch));
slot = __cptr(lcd_arch_get_syscall_arg0(lcd->lcd_arch));
flags = (unsigned int)lcd_arch_get_syscall_arg1(lcd->lcd_arch);
order = (unsigned int)lcd_arch_get_syscall_arg2(lcd->lcd_arch);
......
#! /bin/bash -e
make libcap.microkernel
make microkernel
make libcap.liblcd
make liblcd
make test_mods
make libcap.microkernel $@
make microkernel $@
make libcap.liblcd $@
make liblcd $@
make test_mods $@
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