Commit c94e9745 authored by Charles Jacobsen's avatar Charles Jacobsen Committed by Vikram Narayanan
Browse files

libcap-integration: Microkernel and kliblcd build bug fixes.

Microkernel and kliblcd compile. Some linker errors due to
missing resource tree and create objects. Going to refactor
build now, more code shuffling fun.
parent 0be0f634
......@@ -11,6 +11,6 @@ KBUILD_CFLAGS := $(KBUILD_CFLAGS) $(LCD_DOMAINS_CFLAGS)
# Dive into subdirs (note that kliblcd is built with microkernel)
obj-m += microkernel/
obj-m += tests/
obj-m += test-mods/
#obj-m += tests/
#obj-m += test-mods/
......@@ -3,6 +3,7 @@
# since we have a kbuild file)
#
export LCD_DOMAINS_SRC_DIR=$(PWD)
export LCD_DOMAINS_INCLUDE=$(PWD)/include
export LCD_DOMAINS_CFLAGS=-Werror \
-I$(LCD_DOMAINS_INCLUDE) \
......@@ -13,9 +14,11 @@ export LCD_DOMAINS_CFLAGS=-Werror \
# Don't print "Entering directory..." etc.
MAKEFLAGS += --no-print-directory
all: liblcd the_rest
#all: liblcd the_rest
all: the_rest
the_rest: liblcd libcap.microkernel
#the_rest: liblcd libcap.microkernel
the_rest: libcap.microkernel
$(MAKE) -C .. M=$(PWD) -j8
liblcd: libcap.lcd
......
......@@ -42,7 +42,7 @@ int lcd_resource_tree_search(struct lcd_resource_tree *t,
*/
struct interval_tree_node *match;
match = interval_tree_first(&t->root, addr, addr);
match = interval_tree_iter_first(&t->root, addr, addr);
if (match) {
n_out = container_of(match, struct lcd_resource_node,
it_node);
......
/*
* liblcd.h
*
* Includes all the liblcd stuff in one header.
*
* Copyright: University of Utah
*/
#ifndef LCD_DOMAIN_LIBLCD
#define LCD_DOMAIN_LIBLCD
#include <lcd-domains/liblcd/address_spaces.h>
#include <lcd-domains/liblcd/allocator.h>
#include <lcd-domains/liblcd/boot_info.h>
#include <lcd-domains/liblcd/cap.h>
#include <lcd-domains/liblcd/console.h>
#include <lcd-domains/liblcd/create.h>
#include <lcd-domains/liblcd/enter_exit.h>
#include <lcd-domains/liblcd/mem.h>
#include <lcd-domains/liblcd/module_load.h>
#include <lcd-domains/liblcd/resource_tree.h>
#include <lcd-domains/liblcd/sync_ipc.h>
#include <lcd-domains/liblcd/syscall.h>
#endif /* LCD_DOMAIN_LIBLCD */
......@@ -147,23 +147,26 @@
#define LCD_HEAP_SIZE (16UL << 20) /* ........................ 16 MBs */
#define LCD_IOREMAP_SIZE (16UL << 20) /* ..................... 16 MBs */
#if ((LCD_BOOTSTRAP_PAGES_SIZE >> PAGE_SHIFT) & \
((LCD_BOOTSTRAP_PAGES_SIZE >> PAGE_SHIFT) - 1))
#error "LCD Bootstrap pages must be a power-of-two number of pages."
#endif
#if sizeof(struct lcd_boot_info) > LCD_BOOTSTRAP_PAGES_SIZE
#error "struct lcd_boot_info won't fit in bootstrap pages. Add more pages."
#endif
#if (LCD_BOOTSTRAP_PAGE_TABLES_SIZE >> PAGE_SHIFT != 2)
#error "We need exactly two page tables for the gv address space."
#endif
#if ((LCD_STACK_SIZE >> PAGE_SHIFT) & \
((LCD_STACK_SIZE >> PAGE_SHIFT) - 1))
#error "Number of LCD stack pages needs to be a power-of-two multiple."
#endif
static inline void
__lcd_build_checks__(void)
{
/*
* This function is for build checks only. (We can't put
* build bug on's in the top level.)
*/
/* LCD Bootstrap pages must be a power-of-two number of pages */
BUILD_BUG_ON_NOT_POWER_OF_2(LCD_BOOTSTRAP_PAGES_SIZE >> PAGE_SHIFT);
/* lcd_boot_info won't fit in bootstrap pages. Add more pages. */
BUILD_BUG_ON(sizeof(struct lcd_boot_info) > LCD_BOOTSTRAP_PAGES_SIZE);
/* We need exactly two page tables for the gv address space. */
BUILD_BUG_ON(LCD_BOOTSTRAP_PAGE_TABLES_SIZE >> PAGE_SHIFT != 2);
/* Number of LCD stack pages needs to be a power-of-two multiple. */
BUILD_BUG_ON_NOT_POWER_OF_2(LCD_STACK_SIZE >> PAGE_SHIFT);
}
/* Orders (for convenience) */
......
......@@ -65,6 +65,7 @@ struct lcd_page_block {
*
* See lcd_page_allocator_create for more details.
*/
struct lcd_page_allocator;
struct lcd_page_allocator_cbs {
int (*alloc_map_metadata_memory_chunk)(
......
......@@ -172,7 +172,7 @@ int lcd_create_module_lcd(char *mdir, char *mname, cptr_t *lcd,
static inline struct lcd_boot_info *
lcd_to_boot_info(struct lcd_create_ctx *ctx)
{
return cxt->lcd_boot_info;
return ctx->lcd_boot_info;
}
/**
* lcd_to_boot_cptr_cache -- Extract new LCD's bootstrap cptr cache
......@@ -181,7 +181,7 @@ lcd_to_boot_info(struct lcd_create_ctx *ctx)
static inline struct cptr_cache *
lcd_to_boot_cptr_cache(struct lcd_create_ctx *ctx)
{
return cxt->lcd_boot_info->cptr_cache;
return &ctx->lcd_boot_info->cptr_cache;
}
/**
* lcd_destroy_create_ctx -- Tear down lcd_create_ctx returned from
......
......@@ -483,6 +483,20 @@ int lcd_phys_to_resource_node(gpa_t paddr, struct lcd_resource_node **n);
*/
int lcd_virt_to_cptr(gva_t vaddr, cptr_t *c_out, unsigned int *order_out);
/* RESOURCE TREES -------------------------------------------------- */
/**
* lcd_alloc_init_resource_tree -- Create an empty resource tree
* @t_out: out param, the new tree
*/
int lcd_alloc_init_resource_tree(struct lcd_resource_tree **t_out);
/**
* lcd_destroy_free_resource_tree -- Destroy tree
* @t: the tree to destroy
*/
void lcd_destroy_free_resource_tree(struct lcd_resource_tree *t);
/* MISCELLANEOUS -------------------------------------------------- */
/**
......
......@@ -11,9 +11,11 @@
*
* Copyright: University of Utah
*/
#ifndef LCD_DOMAINS_RESOURCE_TREE_H
#define LCD_DOMAINS_RESOURCE_TREE_H
#include <libcap.h>
#include <linux/rb_tree.h>
#include <linux/rbtree.h>
#include <linux/interval_tree.h>
/**
......@@ -164,3 +166,5 @@ lcd_resource_tree_next(struct lcd_resource_node *n);
*/
void lcd_resource_tree_remove(struct lcd_resource_tree *t,
struct lcd_resource_node *n);
#endif /* LCD_DOMAINS_RESOURCE_TREE_H */
......@@ -6,6 +6,7 @@
#include <libcap.h>
#include <lcd-domains/liblcd.h>
#include "../microkernel/internal.h"
void lcd_cap_delete(cptr_t slot)
{
......
......@@ -1050,7 +1050,7 @@ static int gv_map(cptr_t lcd, struct create_module_cxt *cxt,
* Note! Call lcd_mm_gva_init before mapping any gva's.
*/
#include <liblcd.h>
#include <libcap.h>
#include <lcd-domains/liblcd.h>
#include "../microkernel/internal.h"
......@@ -1106,7 +1106,7 @@ int lcd_create_klcd(cptr_t *klcd)
goto fail2;
}
*lcd = slot;
*klcd = slot;
return 0;
......@@ -1123,7 +1123,7 @@ int lcd_config_registers(cptr_t lcd, gva_t pc, gva_t sp, gpa_t gva_root,
}
int lcd_memory_grant_and_map(cptr_t lcd, cptr_t mo, cptr_t dest_slot,
gpa_t base);
gpa_t base)
{
return __lcd_memory_grant_and_map(current->lcd, lcd, mo,
dest_slot, base);
......
......@@ -39,13 +39,13 @@ int lcd_enter(void)
/*
* Set up our cptr cache
*/
ret = cap_cptr_cache_alloc(&cache);
ret = cptr_cache_alloc(&cache);
if (ret) {
LCD_ERR("cptr cache alloc");
goto fail2;
}
current->cptr_cache = cache;
ret = cap_cptr_cache_init(cache);
ret = cptr_cache_init(cache);
if (ret) {
LCD_ERR("cptr cache init");
goto fail3;
......@@ -119,8 +119,8 @@ static void do_destroy_lcd(struct lcd *lcd)
static void do_destroy_cptr_cache(struct cptr_cache *c)
{
cap_cptr_cache_destroy(c);
cap_cptr_cache_free(c);
cptr_cache_destroy(c);
cptr_cache_free(c);
}
void lcd_exit(int retval)
......
......@@ -4,6 +4,8 @@
* Copyright: University of Utah
*/
#include <linux/slab.h>
#include <linux/mm.h>
#include <libcap.h>
#include <lcd-domains/liblcd.h>
#include "../microkernel/internal.h"
......@@ -134,7 +136,7 @@ static int mo_insert_in_trees(struct task_struct *t,
case LCD_MICROKERNEL_TYPE_ID_VMALLOC_MEM:
case LCD_MICROKERNEL_TYPE_ID_VOLUNTEERED_VMALLOC_MEM:
return mo_insert_in_tree(
t->lcd_resource_trees[LCD_RESOURCE_TREE_VMALLOC_MEM_IDX],
t->lcd_resource_trees[LCD_RESOURCE_TREE_VMALLOC_IDX],
mo,
mo_cptr);
default:
......@@ -171,7 +173,7 @@ static int mo_in_trees(struct task_struct *t, struct lcd_memory_object *mo)
case LCD_MICROKERNEL_TYPE_ID_VMALLOC_MEM:
case LCD_MICROKERNEL_TYPE_ID_VOLUNTEERED_VMALLOC_MEM:
return mo_in_tree(
t->lcd_resource_trees[LCD_RESOURCE_TREE_VMALLOC_MEM_IDX],
t->lcd_resource_trees[LCD_RESOURCE_TREE_VMALLOC_IDX],
mo);
default:
LCD_ERR("unexpected memory object type %d",
......@@ -208,17 +210,17 @@ static void mo_remove_from_trees(struct task_struct *t,
switch (mo->sub_type) {
case LCD_MICROKERNEL_TYPE_ID_PAGE:
case LCD_MICROKERNEL_TYPE_ID_VOLUNTEERED_PAGE:
return mo_remove_from_tree(
mo_remove_from_tree(
t->lcd_resource_trees[LCD_RESOURCE_TREE_RAM_IDX],
mo);
case LCD_MICROKERNEL_TYPE_ID_VOLUNTEERED_DEV_MEM:
return mo_remove_from_tree(
mo_remove_from_tree(
t->lcd_resource_trees[LCD_RESOURCE_TREE_DEV_MEM_IDX],
mo);
case LCD_MICROKERNEL_TYPE_ID_VMALLOC_MEM:
case LCD_MICROKERNEL_TYPE_ID_VOLUNTEERED_VMALLOC_MEM:
return mo_remove_from_tree(
t->lcd_resource_trees[LCD_RESOURCE_TREE_VMALLOC_MEM_IDX],
mo_remove_from_tree(
t->lcd_resource_trees[LCD_RESOURCE_TREE_VMALLOC_IDX],
mo);
default:
LCD_ERR("unexpected memory object type %d",
......@@ -298,7 +300,6 @@ int _lcd_vmalloc(unsigned int order, cptr_t *slot_out)
struct lcd *lcd = current->lcd;
cptr_t slot;
int ret;
unsigned int order;
/*
* Allocate a slot in caller's cspace
*/
......@@ -327,8 +328,8 @@ fail1:
/* LOW-LEVEL MAP -------------------------------------------------- */
int __lcd_mmap(struct lcd *lcd, struct lcd_memory_object *mo,
cptr_t mo_cptr, gpa_t base)
static int __lcd_mmap(struct lcd *lcd, struct lcd_memory_object *mo,
struct cnode *cnode, cptr_t mo_cptr, gpa_t base)
{
int ret;
/*
......@@ -351,8 +352,8 @@ int __lcd_mmap(struct lcd *lcd, struct lcd_memory_object *mo,
* "Map" in physical address space (this is a no-op for
* non-isolated code right now)
*/
ret = __lcd_mem_object_map(lcd, mo, cap_cnode_metadata(cnode),
__gpa(0));
ret = __lcd_do_map_memory_object(lcd, mo, cap_cnode_metadata(cnode),
__gpa(0));
if (ret) {
LIBLCD_ERR("physical map failed");
goto fail3;
......@@ -367,7 +368,7 @@ fail1:
return ret;
}
int _lcd_mmap(cptr_t mo, gpa_t base)
int _lcd_mmap(cptr_t mo_cptr, gpa_t base)
{
struct lcd_memory_object *mo;
struct cnode *cnode;
......@@ -379,7 +380,7 @@ int _lcd_mmap(cptr_t mo, gpa_t base)
*
* Get and lock the memory object
*/
ret = __lcd_get_memory_object(current->lcd, mo, &cnode, &mo);
ret = __lcd_get_memory_object(current->lcd, mo_cptr, &cnode, &mo);
if (ret) {
LIBLCD_ERR("error looking up memory object");
goto fail1;
......@@ -387,7 +388,7 @@ int _lcd_mmap(cptr_t mo, gpa_t base)
/*
* Do the map
*/
ret = __lcd_mmap(lcd, mo, mo_cptr, base);
ret = __lcd_mmap(current->lcd, mo, cnode, mo_cptr, base);
if (ret) {
LIBLCD_ERR("error mapping mem object");
goto fail2;
......@@ -405,8 +406,8 @@ fail1:
return ret;
}
void __lcd_munmap(struct lcd *lcd, struct lcd_memory_object *mo,
struct cnode *mo_cnode)
static void __lcd_munmap(struct lcd *lcd, struct lcd_memory_object *mo,
struct cnode *mo_cnode)
{
/*
* Remove from resource trees
......@@ -416,8 +417,8 @@ void __lcd_munmap(struct lcd *lcd, struct lcd_memory_object *mo,
* "Unmap" from physical address space (this is a no-op for
* non-isolated code right now)
*/
__lcd_mem_object_unmap(current->lcd, mo,
cap_cnode_metadata(cnode));
__lcd_do_unmap_memory_object(current->lcd, mo,
cap_cnode_metadata(mo_cnode));
}
void _lcd_munmap(cptr_t mo_cptr)
......@@ -580,7 +581,6 @@ void* lcd_vmalloc(unsigned long sz)
{
struct lcd *lcd = current->lcd;
unsigned int order;
unsigned int log_sz;
int ret;
cptr_t slot;
struct lcd_memory_object *mo;
......@@ -635,7 +635,6 @@ void lcd_vfree(void *vptr)
{
cptr_t vmalloc_mem_cptr;
int ret;
gpa_t gpa;
unsigned int unused;
/*
* Resolve vptr to cptr
......@@ -662,6 +661,8 @@ int lcd_map_phys(cptr_t pages, unsigned int order, gpa_t *base_out)
{
int ret;
struct page *p;
struct cnode *cnode;
struct lcd_memory_object *mo;
/*
* Ignore order, etc., since non-isolated code already has
* access to all physical memory. (We could maybe check that
......@@ -670,7 +671,7 @@ int lcd_map_phys(cptr_t pages, unsigned int order, gpa_t *base_out)
* Look up memory object so we can get struct page pointer,
* and then translate to physical address
*/
ret = __lcd_get_memory_object(current->lcd, slot, &cnode, &mo);
ret = __lcd_get_memory_object(current->lcd, pages, &cnode, &mo);
if (ret) {
LIBLCD_ERR("internal error: mem lookup failed");
goto fail1;
......@@ -678,7 +679,7 @@ int lcd_map_phys(cptr_t pages, unsigned int order, gpa_t *base_out)
/*
* "Map" the pages (adds pages to proper resource tree)
*/
ret = __lcd_mmap(current->lcd, mo, cnode, __gpa(0));
ret = __lcd_mmap(current->lcd, mo, cnode, pages, __gpa(0));
if (ret) {
LIBLCD_ERR("error mapping pages in resource tree");
goto fail2;
......@@ -841,7 +842,8 @@ static int volunteer_mem_obj(struct task_struct *t,
LIBLCD_ERR("cptr alloc failed");
goto fail2;
}
ret = __lcd_insert_memory_object(t->lcd, base, order, sub_type, &mo);
ret = __lcd_insert_memory_object(t->lcd, slot, mem_obj,
order, sub_type, &mo);
if (ret) {
LIBLCD_ERR("error inserting new memory object");
goto fail3;
......@@ -855,7 +857,7 @@ static int volunteer_mem_obj(struct task_struct *t,
*slot_out = slot;
fail3:
lcd_free_cptr(slot);
lcd_cptr_free(slot);
fail2:
fail1:
return ret;
......@@ -878,8 +880,8 @@ int lcd_volunteer_pages(struct page *base, unsigned int order,
cptr_t *slot_out)
{
return volunteer_mem_obj(current, base,
page_pfn(base), order,
LCD_MICROKERNEL_TYPE_ID_PAGE,
page_to_pfn(base), order,
LCD_MICROKERNEL_TYPE_ID_VOLUNTEERED_PAGE,
slot_out);
}
......@@ -895,7 +897,7 @@ int lcd_volunteer_dev_mem(gpa_t base, unsigned int order,
{
return volunteer_mem_obj(current, (void *)gpa_val(base),
gpa_val(base), order,
LCD_MICROKERNEL_TYPE_ID_DEV_MEM,
LCD_MICROKERNEL_TYPE_ID_VOLUNTEERED_DEV_MEM,
slot_out);
}
......@@ -911,7 +913,7 @@ int lcd_volunteer_vmalloc_mem(gva_t base, unsigned int order,
{
return volunteer_mem_obj(current, (void *)gva_val(base),
gva_val(base), order,
LCD_MICROKERNEL_TYPE_ID_VMALLOC_MEM,
LCD_MICROKERNEL_TYPE_ID_VOLUNTEERED_VMALLOC_MEM,
slot_out);
}
......@@ -943,7 +945,7 @@ int lcd_phys_to_cptr(gpa_t paddr, cptr_t *c_out, unsigned int *order_out)
* Pull out memory object cptr and order
*/
*c_out = n->cptr;
*order_out = n->order;
*order_out = n->nr_pages_order;
return 0;
......@@ -955,6 +957,7 @@ int lcd_virt_to_cptr(gva_t vaddr, cptr_t *c_out, unsigned int *order_out)
{
gpa_t gpa;
struct lcd_resource_node *n;
int ret;
/*
* Look in vmalloc tree first
*/
......@@ -976,7 +979,7 @@ int lcd_virt_to_cptr(gva_t vaddr, cptr_t *c_out, unsigned int *order_out)
* Pull out memory object cptr and order
*/
*c_out = n->cptr;
*order_out = n->order;
*order_out = n->nr_pages_order;
return 0;
}
......
......@@ -7,6 +7,7 @@
*/
#include <lcd-domains/liblcd.h>
#include "../microkernel/internal.h"
#include "internal.h"
int lcd_create_module_klcd(char *mdir, char *mname, cptr_t *klcd_out)
......@@ -36,11 +37,11 @@ int lcd_create_module_klcd(char *mdir, char *mname, cptr_t *klcd_out)
* We pass null values for most arguments, as these aren't
* used for kLCDs.
*/
ret = lcd_config(klcd,
__gva(hva_val(va2hva(m->init))),
__gva(0),
__gpa(0),
__gpa(0));
ret = lcd_config_registers(klcd,
__gva(hva_val(va2hva(m->init))),
__gva(0),
__gpa(0),
__gpa(0));
if (ret) {
LCD_ERR("failed to config klcd");
goto fail3;
......
......@@ -6,7 +6,9 @@
* Copyright: University of Utah
*/
#include <linux/slab.h>
#include <lcd-domains/liblcd.h>
#include "../microkernel/internal.h"
/* HOST LOAD/UNLOAD -------------------------------------------------- */
......
......@@ -6,6 +6,7 @@
#include <libcap.h>
#include <lcd-domains/liblcd.h>
#include "../microkernel/internal.h"
struct lcd_utcb *lcd_get_utcb(void)
{
......@@ -62,6 +63,6 @@ int lcd_sync_call(cptr_t endpoint)
int lcd_sync_reply(void)
{
return __lcd_reply(current->lcd, endpoint);
return __lcd_reply(current->lcd);
}
......@@ -6,7 +6,15 @@
obj-m += lcd_domains.o
# Arch independent code
lcd_domains-y += main.o ipc.o cap_types.o
lcd_domains-y += \
cap_types.o \
console.o \
create.o \
ipc.o \
main.o \
mem.o \
mem_itree.o \
run.o
# Arch dependent code
lcd_domains-y += arch/$(ARCH)/main.o
......@@ -16,15 +24,18 @@ lcd_domains-y += arch/$(ARCH)/traps.o
lcd_domains-y += ../libcap.out.microkernel/lib/libcap.a
# add libcap headers to include path
ccflags-y += -I../libcap.out.microkernel/include
ccflags-y += -I$(LCD_DOMAINS_SRC_DIR)/libcap.out.microkernel/include
# kliblcd
lcd_domains-y += $(addprefix ../kliblcd/, init.o \
mem.o \
ipc.o \
enterexit.o \
create.o \
cap.o \
cptr_cache.o \
dstore.o \
create_klcd.o)
lcd_domains-y += $(addprefix ../kliblcd/, \
boot_info.o \
cap.o \
console.o \
create.o \
enter_exit.o \
mem.o \
module_create_klcd.o \
module_load.o \
sync_ipc.o \
)
......@@ -27,6 +27,8 @@
#include <linux/module.h>
#include <linux/kernel.h>
#include "../../internal.h"
/* VMX DATA STRUCTURES -------------------------------------------------- */
......
......@@ -6,6 +6,7 @@
#include <linux/gfp.h>
#include <linux/list.h>
#include <linux/bitops.h>
#include <linux/slab.h>
#include <libcap.h>
#include "internal.h"
......@@ -21,11 +22,15 @@ struct type_ops_id {
/* REVOCATION CALLBACKS ---------------------------------------- */
static void mem_object_revoke(struct cspace *cspace, struct cnode *cnode,
static int mem_object_revoke(struct cspace *cspace, struct cnode *cnode,
void *object)
{
struct lcd_mapping_metadata *m;
struct lcd_memory_object *mo = (struct lcd_memory_object *)object;
/*
* Extract metadata
*/
m = cap_cnode_metadata(cnode);
/*
* Unmap memory object
*/
......@@ -35,39 +40,41 @@ static void mem_object_revoke(struct cspace *cspace, struct cnode *cnode,
*/
if (m)
kfree(m);
return 0;
}
static void page_revoke(struct cspace *cspace, struct cnode *cnode,
static int page_revoke(struct cspace *cspace, struct cnode *cnode,
void *object)
{
mem_object_revoke(cspace, cnode, object);
return mem_object_revoke(cspace, cnode, object);
}
static void vmalloc_mem_revoke(struct cspace *cspace, struct cnode *cnode,
static int vmalloc_mem_revoke(struct cspace *cspace, struct cnode *cnode,
void *object)
{