Commit 9829af71 authored by Charlie Jacobsen's avatar Charlie Jacobsen Committed by Vikram Narayanan

liblcd-v2: Low-level mmap done. Tweaked low-level mmap interface.

Easier to have caller pass memory object order and gpa base for
_lcd_mmap and _lcd_munmap, since in liblcd we can look those
things up easily.
parent 89df5958
......@@ -79,6 +79,7 @@ int _lcd_vmalloc(unsigned int order, cptr_t *slot_out);
/**
* _lcd_mmap -- Low-level memory mapping, calls into microkernel
* @mo: cptr to memory object capability (e.g., pages)
* @order: the memory object is 2^order pages in size
* @base: starting guest physical address where memory should be mapped
*
* Purpose: Maps the memory referred to by the @mo cptr_t in the caller's
......@@ -89,6 +90,10 @@ int _lcd_vmalloc(unsigned int order, cptr_t *slot_out);
* lcd_map_phys) is necessary before you try to do address -> cptr
* translation via lcd_phys_to_cptr (even for non-isolated code).
*
* Note: for isolated code, the microkernel ignores the @order argument.
* It is still needed though for isolated liblcd so that it knows how
* big the memory object is (it can't "ask" the microkernel).
*
* Non-isolated code notes
* -----------------------
*
......@@ -118,7 +123,7 @@ int _lcd_vmalloc(unsigned int order, cptr_t *slot_out);
* Furthermore, @base has an existing mapping, or the @mo won't
* fit, the microkernel will reject the mapping.
*/
int _lcd_mmap(cptr_t mo, gpa_t base);
int _lcd_mmap(cptr_t mo, unsigned int order, gpa_t base);
/**
* _lcd_munmap -- Low-level unmapping, calls into microkernel
......
......@@ -327,15 +327,15 @@ fail1:
return ret;
}
int _lcd_mmap(cptr_t mo_cptr, gpa_t base)
int _lcd_mmap(cptr_t mo_cptr, unsigned int order, gpa_t base)
{
gpa_t unused;
/*
* We cheat and use lcd_map_phys since all it does is add
* the memory object to the physical address space resource
* tree. For non-isolated, @order is ignored.
* tree.
*/
return lcd_map_phys(mo_cptr, 0, &unused);
return lcd_map_phys(mo_cptr, order, &unused);
}
static void do_phys_unmap(struct lcd *lcd, struct lcd_memory_object *mo,
......@@ -353,12 +353,14 @@ static void do_phys_unmap(struct lcd *lcd, struct lcd_memory_object *mo,
cap_cnode_metadata(mo_cnode));
}
void _lcd_munmap(cptr_t mo_cptr)
void _lcd_munmap(cptr_t mo_cptr, gpa_t base)
{
struct lcd_memory_object *mo;
struct cnode *cnode;
int ret;
/*
* Ignore base
*
* Get and lock the memory object
*/
ret = __lcd_get_memory_object(current->lcd, mo_cptr, &cnode, &mo);
......@@ -422,7 +424,8 @@ struct page *lcd_alloc_pages_exact_node(int nid, unsigned int flags,
return p;
fail3:
_lcd_munmap(slot);
/* gpa is ignored for non-isolated */
_lcd_munmap(slot, __gpa(0));
fail2:
lcd_cap_delete(slot); /* frees pages, etc. */
fail1:
......@@ -469,7 +472,8 @@ struct page *lcd_alloc_pages(unsigned int flags, unsigned int order)
return p;
fail3:
_lcd_munmap(slot);
/* gpa is ignored for non-isolated */
_lcd_munmap(slot, __gpa(0));
fail2:
lcd_cap_delete(slot); /* frees pages, etc. */
fail1:
......@@ -501,8 +505,10 @@ void lcd_free_pages(struct page *base, unsigned int order)
LIBLCD_ERR("warning: order doesn't match actual order");
/*
* Remove pages from resource tree ("unmap")
*
* gpa is ignored for non-isolated
*/
_lcd_munmap(page_cptr);
_lcd_munmap(page_cptr, __gpa(0));
/*
* Free pages
*/
......@@ -556,7 +562,8 @@ void* lcd_vmalloc(unsigned long sz)
return vptr;
fail3:
_lcd_munmap(slot);
/* gpa is ignored for non-isolated */
_lcd_munmap(slot, __gpa(0));
fail2:
lcd_cap_delete(slot); /* frees vmalloc mem, etc. */
fail1:
......@@ -579,8 +586,10 @@ void lcd_vfree(void *vptr)
}
/*
* Remove vmalloc mem from resource tree ("unmap")
*
* gpa is ignored for non-isolated
*/
_lcd_munmap(vmalloc_mem_cptr);
_lcd_munmap(vmalloc_mem_cptr, __gpa(0));
/*
* Free vmalloc mem
*/
......@@ -708,8 +717,10 @@ void lcd_unmap_phys(gpa_t base, unsigned int order)
}
/*
* Remove from resource tree
*
* gpa is ignored for non-isolated
*/
_lcd_munmap(mo_cptr);
_lcd_munmap(mo_cptr, __gpa(0));
}
void lcd_unmap_virt(gva_t base, unsigned int order)
......@@ -730,8 +741,10 @@ void lcd_unmap_virt(gva_t base, unsigned int order)
}
/*
* Remove memory object from resource tree
*
* gpa is ignored for non-isolated
*/
_lcd_munmap(mo_cptr);
_lcd_munmap(mo_cptr, __gpa(0));
}
/* VOLUNTEER HELPERS -------------------------------------------------- */
......
......@@ -108,14 +108,56 @@ fail1:
return ret;
}
int _lcd_mmap(cptr_t mo, gpa_t base)
int _lcd_mmap(cptr_t mo, unsigned int order, gpa_t base)
{
return lcd_syscall_mmap(mo, base);
int ret;
/*
* Do low level syscall to map memory object
*/
ret = lcd_syscall_mmap(mo, base);
if (ret) {
LIBLCD_ERR("low level mmap failed");
goto fail1;
}
/*
* Insert into resource tree (unlike kliblcd, all of our
* memory objects are always contiguous in guest physical)
*/
ret = __liblcd_mem_itree_insert(base, (1UL << (PAGE_SHIFT + order)),
mo);
if (ret) {
LIBLCD_ERR("error inserting into mem itree");
goto fail2;
}
return 0;
fail2:
lcd_syscall_munmap(mo);
fail1:
return ret;
}
void _lcd_munmap(cptr_t mo)
void _lcd_munmap(cptr_t mo, gpa_t base)
{
return lcd_syscall_munmap(mo);
int ret;
struct lcd_resource_node *n;
/*
* Look up resource node for memory object in itree
*/
ret = lcd_phys_to_resource_node(base, &n);
if (ret) {
LIBLCD_ERR("couldn't find memory object in tree");
return;
}
/*
* Remove from tree
*/
__liblcd_mem_itree_delete(n);
/*
* Unmap memory object
*/
lcd_syscall_munmap(mo);
}
/* PAGE ALLOCATOR -------------------------------------------------- */
......
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