Merge memory paper code into memory system branch
authorSimon Gerber <simon.gerber@inf.ethz.ch>
Mon, 22 Oct 2018 20:51:06 +0000 (22:51 +0200)
committerSimon Gerber <simon.gerber@inf.ethz.ch>
Mon, 22 Oct 2018 20:51:06 +0000 (22:51 +0200)
Signed-off-by: Simon Gerber <simon.gerber@inf.ethz.ch>

23 files changed:
1  2 
capabilities/caps.hl
errors/errno.fugu
hake/RuleDefs.hs
if/Hakefile
include/barrelfish_kpi/capabilities.h
kernel/arch/x86_64/irq.c
kernel/arch/x86_64/page_mappings_arch.c
kernel/arch/x86_64/syscall.c
kernel/arch/x86_64/vmx_vmkit.c
kernel/cap_delete.c
kernel/capabilities.c
kernel/include/capabilities.h
kernel/include/target/x86_64/paging_kernel_target.h
lib/barrelfish/Hakefile
lib/barrelfish/arch/x86/pmap.c
lib/barrelfish/arch/x86_32/pmap.c
lib/barrelfish/arch/x86_64/pmap.c
lib/barrelfish/debug.c
lib/barrelfish/ram_alloc.c
lib/barrelfish/sys_debug.c
lib/posixcompat/Hakefile
lib/posixcompat/sbrk.c
platforms/Hakefile

Simple merge
Simple merge
Simple merge
diff --cc if/Hakefile
Simple merge
@@@ -369,7 -408,7 +408,8 @@@ enum vnode_cmd 
      VNodeCmd_Map,
      VNodeCmd_Unmap,
      VNodeCmd_Identify,   ///< Return the physical address of the VNode
 +    VNodeCmd_ModifyFlags,
+     VNodeCmd_CleanDirtyBits, ///< Cleans all dirty bit in the table
  };
  
  /**
Simple merge
@@@ -156,9 -212,14 +212,12 @@@ static errval_t x86_64_non_ptable(struc
      lpaddr_t src_lp     = gen_phys_to_local_phys(src_gp);
  
      // set metadata
 -    create_mapping_cap(mapping_cte, src,
 -                       dest_lp + slot * sizeof(union x86_64_ptable_entry),
 -                       offset,
 -                       pte_count);
 +    create_mapping_cap(mapping_cte, src, cte_for_cap(dest),
 +                       slot, pte_count);
  
+     // use standard paging structs even if we're mapping EPT entries
+     is_ept = false;
      cslot_t last_slot = slot + pte_count;
      for (; slot < last_slot; slot++, offset += page_size) {
          // Destination
@@@ -1207,9 -1235,9 +1247,10 @@@ static invocation_handler_t invocations
      },
      [ObjType_VNode_x86_64_ptable] = {
          [VNodeCmd_Identify] = handle_vnode_identify,
+         [VNodeCmd_CleanDirtyBits] = handle_clean_dirty_bits,
          [VNodeCmd_Map]   = handle_map,
          [VNodeCmd_Unmap] = handle_unmap,
 +        [VNodeCmd_ModifyFlags] = handle_vnode_modify_flags,
      },
      [ObjType_Frame_Mapping] = {
          [MappingCmd_Destroy] = handle_mapping_destroy,
Simple merge
Simple merge
@@@ -55,10 -55,9 +55,10 @@@ void caps_trace_ctrl(uint64_t types, ge
  
  struct capability monitor_ep;
  
- STATIC_ASSERT(50 == ObjType_Num, "Knowledge of all cap types");
+ STATIC_ASSERT(58 == ObjType_Num, "Knowledge of all cap types");
  int sprint_cap(char *buf, size_t len, struct capability *cap)
  {
 +    char *mappingtype;
      switch (cap->type) {
      case ObjType_PhysAddr:
          return snprintf(buf, len,
          return snprintf(buf, len, "x86_64 PML4 at 0x%" PRIxGENPADDR,
                          cap->u.vnode_x86_64_pml4.base);
  
+     case ObjType_VNode_x86_64_ept_ptable:
+         return snprintf(buf, len, "x86_64 EPT Page table at 0x%" PRIxGENPADDR,
+                         cap->u.vnode_x86_64_ept_ptable.base);
+     case ObjType_VNode_x86_64_ept_pdir:
+         return snprintf(buf, len, "x86_64 EPT Page directory at 0x%" PRIxGENPADDR,
+                         cap->u.vnode_x86_64_ept_pdir.base);
+     case ObjType_VNode_x86_64_ept_pdpt:
+         return snprintf(buf, len, "x86_64 EPT PDPT at 0x%" PRIxGENPADDR,
+                         cap->u.vnode_x86_64_ept_pdpt.base);
+     case ObjType_VNode_x86_64_ept_pml4:
+         return snprintf(buf, len, "x86_64 EPT PML4 at 0x%" PRIxGENPADDR,
+                         cap->u.vnode_x86_64_ept_pml4.base);
      case ObjType_Frame_Mapping:
 -        return snprintf(buf, len, "Frame Mapping (Frame cap @%p, "
 -                                  "pte @0x%"PRIxLVADDR", pte_count=%hu)",
 -                                  cap->u.frame_mapping.cap,
 -                                  cap->u.frame_mapping.pte,
 -                                  cap->u.frame_mapping.pte_count);
 -
 +        mappingtype = "Frame";
 +        goto ObjType_Mapping;
      case ObjType_DevFrame_Mapping:
 -        return snprintf(buf, len, "DevFrame Mapping (DevFrame cap @%p, "
 -                                  "pte @0x%"PRIxLVADDR", pte_count=%hu)",
 -                                  cap->u.devframe_mapping.cap,
 -                                  cap->u.devframe_mapping.pte,
 -                                  cap->u.devframe_mapping.pte_count);
 +        mappingtype = "DevFrame";
 +        goto ObjType_Mapping;
  
      case ObjType_VNode_x86_64_pml4_Mapping:
 -        return snprintf(buf, len, "x86_64 PML4 Mapping (x86_64 PML4 cap @%p, "
 -                                  "pte @0x%"PRIxLVADDR", pte_count=%hu)",
 -                                  cap->u.vnode_x86_64_pml4_mapping.cap,
 -                                  cap->u.vnode_x86_64_pml4_mapping.pte,
 -                                  cap->u.vnode_x86_64_pml4_mapping.pte_count);
 -
 +        mappingtype = "x86_64 PML4";
 +        goto ObjType_Mapping;
      case ObjType_VNode_x86_64_pdpt_Mapping:
 -        return snprintf(buf, len, "x86_64 PDPT Mapping (x86_64 PDPT cap @%p, "
 -                                  "pte @0x%"PRIxLVADDR", pte_count=%hu)",
 -                                  cap->u.vnode_x86_64_pdpt_mapping.cap,
 -                                  cap->u.vnode_x86_64_pdpt_mapping.pte,
 -                                  cap->u.vnode_x86_64_pdpt_mapping.pte_count);
 -
 +        mappingtype = "x86_64 PDPT";
 +        goto ObjType_Mapping;
      case ObjType_VNode_x86_64_pdir_Mapping:
 -        return snprintf(buf, len, "x86_64 PDIR Mapping (x86_64 PDIR cap @%p, "
 -                                  "pte @0x%"PRIxLVADDR", pte_count=%hu)",
 -                                  cap->u.vnode_x86_64_pdir_mapping.cap,
 -                                  cap->u.vnode_x86_64_pdir_mapping.pte,
 -                                  cap->u.vnode_x86_64_pdir_mapping.pte_count);
 -
 +        mappingtype = "x86_64 PDIR";
 +        goto ObjType_Mapping;
      case ObjType_VNode_x86_64_ptable_Mapping:
 -        return snprintf(buf, len, "x86_64 PTABLE Mapping (x86_64 PTABLE cap @%p, "
 -                                  "pte @0x%"PRIxLVADDR", pte_count=%hu)",
 -                                  cap->u.vnode_x86_64_ptable_mapping.cap,
 -                                  cap->u.vnode_x86_64_ptable_mapping.pte,
 -                                  cap->u.vnode_x86_64_ptable_mapping.pte_count);
 -
 -    case ObjType_VNode_x86_32_pdpt_Mapping:
 -        return snprintf(buf, len, "x86_32 PDPT Mapping (x86_32 PDPT cap @%p, "
 -                                  "pte @0x%"PRIxLVADDR", pte_count=%hu)",
 -                                  cap->u.vnode_x86_32_pdpt_mapping.cap,
 -                                  cap->u.vnode_x86_32_pdpt_mapping.pte,
 -                                  cap->u.vnode_x86_32_pdpt_mapping.pte_count);
 +        mappingtype = "x86_64 PTABLE";
 +        goto ObjType_Mapping;
  
+     case ObjType_VNode_x86_64_ept_pml4_Mapping:
 -        return snprintf(buf, len, "x86_64 EPT PML4 Mapping (x86_64 PML4 cap @%p, "
 -                                  "pte @0x%"PRIxLVADDR", pte_count=%hu)",
 -                                  cap->u.vnode_x86_64_ept_pml4_mapping.cap,
 -                                  cap->u.vnode_x86_64_ept_pml4_mapping.pte,
 -                                  cap->u.vnode_x86_64_ept_pml4_mapping.pte_count);
 -
++        mappingtype = "x86_64 EPT PML4";
++        goto ObjType_Mapping;
+     case ObjType_VNode_x86_64_ept_pdpt_Mapping:
 -        return snprintf(buf, len, "x86_64 EPT PDPT Mapping (x86_64 PDPT cap @%p, "
 -                                  "pte @0x%"PRIxLVADDR", pte_count=%hu)",
 -                                  cap->u.vnode_x86_64_ept_pdpt_mapping.cap,
 -                                  cap->u.vnode_x86_64_ept_pdpt_mapping.pte,
 -                                  cap->u.vnode_x86_64_ept_pdpt_mapping.pte_count);
 -
++        mappingtype = "x86_64 EPT PDPT";
++        goto ObjType_Mapping;
+     case ObjType_VNode_x86_64_ept_pdir_Mapping:
 -        return snprintf(buf, len, "x86_64 EPT PDIR Mapping (x86_64 PDIR cap @%p, "
 -                                  "pte @0x%"PRIxLVADDR", pte_count=%hu)",
 -                                  cap->u.vnode_x86_64_ept_pdir_mapping.cap,
 -                                  cap->u.vnode_x86_64_ept_pdir_mapping.pte,
 -                                  cap->u.vnode_x86_64_ept_pdir_mapping.pte_count);
 -
++        mappingtype = "x86_64 EPT PDIR";
++        goto ObjType_Mapping;
+     case ObjType_VNode_x86_64_ept_ptable_Mapping:
 -        return snprintf(buf, len, "x86_64 EPT PTABLE Mapping (x86_64 PTABLE cap @%p, "
 -                                  "pte @0x%"PRIxLVADDR", pte_count=%hu)",
 -                                  cap->u.vnode_x86_64_ept_ptable_mapping.cap,
 -                                  cap->u.vnode_x86_64_ept_ptable_mapping.pte,
 -                                  cap->u.vnode_x86_64_ept_ptable_mapping.pte_count);
++        mappingtype = "x86_64 EPT PTABLE";
++        goto ObjType_Mapping;
 +    case ObjType_VNode_x86_32_pdpt_Mapping:
 +        mappingtype = "x86_32 PDPT";
 +        goto ObjType_Mapping;
      case ObjType_VNode_x86_32_pdir_Mapping:
 -        return snprintf(buf, len, "x86_32 PDIR Mapping (x86_32 PDIR cap @%p, "
 -                                  "pte @0x%"PRIxLVADDR", pte_count=%hu)",
 -                                  cap->u.vnode_x86_32_pdir_mapping.cap,
 -                                  cap->u.vnode_x86_32_pdir_mapping.pte,
 -                                  cap->u.vnode_x86_32_pdir_mapping.pte_count);
 -
 +        mappingtype = "x86_32 PDIR";
 +        goto ObjType_Mapping;
      case ObjType_VNode_x86_32_ptable_Mapping:
 -        return snprintf(buf, len, "x86_32 PTABLE Mapping (x86_32 PTABLE cap @%p, "
 -                                  "pte @0x%"PRIxLVADDR", pte_count=%hu)",
 -                                  cap->u.vnode_x86_32_ptable_mapping.cap,
 -                                  cap->u.vnode_x86_32_ptable_mapping.pte,
 -                                  cap->u.vnode_x86_32_ptable_mapping.pte_count);
 +        mappingtype = "x86_32 PTABLE";
 +        goto ObjType_Mapping;
  
      case ObjType_VNode_ARM_l1_Mapping:
 -        return snprintf(buf, len, "ARM l1 Mapping (ARM l1 cap @%p, "
 -                                  "pte @0x%"PRIxLVADDR", pte_count=%hu)",
 -                                  cap->u.vnode_arm_l1_mapping.cap,
 -                                  cap->u.vnode_arm_l1_mapping.pte,
 -                                  cap->u.vnode_arm_l1_mapping.pte_count);
 -
 +        mappingtype = "ARM l1";
 +        goto ObjType_Mapping;
      case ObjType_VNode_ARM_l2_Mapping:
 -        return snprintf(buf, len, "ARM l2 Mapping (ARM l2 cap @%p, "
 -                                  "pte @0x%"PRIxLVADDR", pte_count=%hu)",
 -                                  cap->u.vnode_arm_l2_mapping.cap,
 -                                  cap->u.vnode_arm_l2_mapping.pte,
 -                                  cap->u.vnode_arm_l2_mapping.pte_count);
 +        mappingtype = "ARM l2";
 +        goto ObjType_Mapping;
  
      case ObjType_VNode_AARCH64_l0_Mapping:
 -        return snprintf(buf, len, "AARCH64 l0 Mapping (AARCH64 l0 cap @%p, "
 -                                  "pte @0x%"PRIxLVADDR", pte_count=%hu)",
 -                                  cap->u.vnode_aarch64_l0_mapping.cap,
 -                                  cap->u.vnode_aarch64_l0_mapping.pte,
 -                                  cap->u.vnode_aarch64_l0_mapping.pte_count);
 -
 +        mappingtype = "AARCH64 l0";
 +        goto ObjType_Mapping;
      case ObjType_VNode_AARCH64_l1_Mapping:
 -        return snprintf(buf, len, "AARCH64 l1 Mapping (AARCH64 l1 cap @%p, "
 -                                  "pte @0x%"PRIxLVADDR", pte_count=%hu)",
 -                                  cap->u.vnode_aarch64_l1_mapping.cap,
 -                                  cap->u.vnode_aarch64_l1_mapping.pte,
 -                                  cap->u.vnode_aarch64_l1_mapping.pte_count);
 -
 +        mappingtype = "AARCH64 l1";
 +        goto ObjType_Mapping;
      case ObjType_VNode_AARCH64_l2_Mapping:
 -        return snprintf(buf, len, "AARCH64 l2 Mapping (AARCH64 l2 cap @%p, "
 -                                  "pte @0x%"PRIxLVADDR", pte_count=%hu)",
 -                                  cap->u.vnode_aarch64_l2_mapping.cap,
 -                                  cap->u.vnode_aarch64_l2_mapping.pte,
 -                                  cap->u.vnode_aarch64_l2_mapping.pte_count);
 -
 +        mappingtype = "AARCH64 l2";
 +        goto ObjType_Mapping;
      case ObjType_VNode_AARCH64_l3_Mapping:
 -        return snprintf(buf, len, "AARCH64 l3 Mapping (AARCH64 l3 cap @%p, "
 -                                  "pte @0x%"PRIxLVADDR", pte_count=%hu)",
 -                                  cap->u.vnode_aarch64_l3_mapping.cap,
 -                                  cap->u.vnode_aarch64_l3_mapping.pte,
 -                                  cap->u.vnode_aarch64_l3_mapping.pte_count);
 +        mappingtype = "AARCH64 l3";
 +        goto ObjType_Mapping;
 +
 +ObjType_Mapping:
 +        return snprintf(buf, len, "%s Mapping (%s cap @%p, "
 +                                  "ptable cap @0x%p, entry=%hu, pte_count=%hu)",
 +                                  mappingtype, mappingtype,
 +                                  cap->u.frame_mapping.cap,
 +                                  cap->u.frame_mapping.ptable,
 +                                  cap->u.frame_mapping.entry,
 +                                  cap->u.frame_mapping.pte_count);
  
      case ObjType_IRQTable:
          return snprintf(buf, len, "IRQTable cap");
Simple merge
@@@ -53,39 -54,38 +54,38 @@@ i
        -- sources specific to the architecture family
        archfam_srcs "x86_32"  = [ "arch/x86_32/debug.c" ,
                                "arch/x86_32/dispatch.c" , "arch/x86_32/syscalls.c" ,
 -                              "arch/x86_32/sys_debug.c", "target/x86_32/pmap_target.c",
 -                              "target/x86/pmap_x86.c",
 +                              "arch/x86_32/sys_debug.c", "arch/x86_32/pmap.c",
 +                              "arch/x86/pmap.c",
                                "vspace/arch/x86_32/layout.c" , "vspace/memobj_pinned.c" ,
-                               "vspace/pinned.c", "vspace/memobj_anon.c",
+                               "vspace/pinned.c",
                                "arch/x86/perfmon.c", "arch/x86/tls.c",
                                "arch/x86/sys_debug.c"]
        archfam_srcs "x86_64"  = [ "arch/x86_64/debug.c", "arch/x86_64/dispatch.c" ,
                                   "arch/x86_64/syscalls.c", "arch/x86_64/sys_debug.c",
                                   "arch/x86_64/ldt.c",
 -                                 "target/x86_64/pmap_target.c", "target/x86/pmap_x86.c",
 +                                 "arch/x86_64/pmap.c", "arch/x86/pmap.c",
                                   "vspace/arch/x86_64/layout.c",
-                                  "vspace/memobj_pinned.c", "vspace/pinned.c", "vspace/memobj_anon.c",
+                                  "vspace/memobj_pinned.c", "vspace/pinned.c",
                                   "arch/x86/perfmon.c", "arch/x86/tls.c",
                                   "arch/x86/sys_debug.c"]
        archfam_srcs "k1om"   = [ "arch/x86_64/debug.c", "arch/x86_64/dispatch.c" ,
                                   "arch/x86_64/syscalls.c", "arch/x86_64/sys_debug.c",
                                   "arch/x86_64/ldt.c",
 -                                 "target/x86_64/pmap_target.c", "target/x86/pmap_x86.c",
 +                                 "arch/x86_64/pmap.c", "arch/x86/pmap.c",
                                   "vspace/arch/x86_64/layout.c",
-                                  "vspace/memobj_pinned.c", "vspace/pinned.c", "vspace/memobj_anon.c",
+                                  "vspace/memobj_pinned.c", "vspace/pinned.c",
                                   "arch/x86/perfmon.c", "arch/x86/tls.c",
                                   "arch/x86/sys_debug.c"]
        archfam_srcs "arm"     = [ "arch/arm/debug.c", "arch/arm/dispatch.c",
 -                                 "arch/arm/pmap_arch.c",
 +                                 "arch/arm/pmap.c",
                                   "arch/arm/syscalls.c", "vspace/memobj_pinned.c" ,
-                                  "vspace/pinned.c", "vspace/memobj_anon.c",
-                                  "vspace/arch/arm/layout.c",
+                                  "vspace/pinned.c", "vspace/arch/arm/layout.c",
                                   "arch/arm/sys_debug.c"]
        archfam_srcs "aarch64"   = [ "arch/aarch64/debug.c", "arch/aarch64/dispatch.c",
                                     "arch/aarch64/context.S",
 -                                   "arch/aarch64/pmap_arch.c", "arch/aarch64/sys_debug.c",
 +                                   "arch/aarch64/pmap.c", "arch/aarch64/sys_debug.c",
                                     "arch/aarch64/syscalls.c", "vspace/memobj_pinned.c" ,
-                                    "vspace/pinned.c", "vspace/memobj_anon.c",
+                                    "vspace/pinned.c",
                                     "vspace/arch/aarch64/layout.c" ]
  
        archfam_srcs _         = []
        -- sources specific to the architecture family
        archfam_srcs "x86_32"  = [ "arch/x86_32/debug.c" ,
                                "arch/x86_32/dispatch.c" , "arch/x86_32/syscalls.c" ,
 -                              "arch/x86_32/sys_debug.c", "target/x86_32/pmap_target.c",
 -                              "target/x86/pmap_x86.c",
 +                              "arch/x86_32/sys_debug.c", "arch/x86_32/pmap.c",
 +                              "arch/x86/pmap.c",
                                "vspace/arch/x86_32/layout.c" , "vspace/memobj_pinned.c" ,
-                               "vspace/pinned.c", "vspace/memobj_anon.c",
-                               "arch/x86/perfmon.c", "arch/x86/tls.c",
+                               "vspace/pinned.c", "arch/x86/perfmon.c", "arch/x86/tls.c",
                                "arch/x86/sys_debug.c"]
        archfam_srcs "x86_64"  = [ "arch/x86_64/debug.c", "arch/x86_64/dispatch.c" ,
                                   "arch/x86_64/syscalls.c", "arch/x86_64/sys_debug.c",
                                   "arch/x86_64/ldt.c",
 -                                 "target/x86_64/pmap_target.c", "target/x86/pmap_x86.c",
 +                                 "arch/x86_64/pmap.c", "arch/x86/pmap.c",
                                   "vspace/arch/x86_64/layout.c",
-                                  "vspace/memobj_pinned.c", "vspace/pinned.c", "vspace/memobj_anon.c",
+                                  "vspace/memobj_pinned.c", "vspace/pinned.c",
                                   "arch/x86/perfmon.c", "arch/x86/tls.c",
                                   "arch/x86/sys_debug.c"]
        archfam_srcs "arm"     = [ "arch/arm/debug.c", "arch/arm/dispatch.c",
 -                                 "arch/arm/pmap_arch.c",
 +                                 "arch/arm/pmap.c",
                                   "arch/arm/syscalls.c", "vspace/memobj_pinned.c" ,
-                                  "vspace/pinned.c", "vspace/memobj_anon.c",
-                                  "vspace/arch/arm/layout.c",
+                                  "vspace/pinned.c", "vspace/arch/arm/layout.c",
                                   "arch/arm/sys_debug.c"]
        archfam_srcs "aarch64"   = [ "arch/aarch64/debug.c", "arch/aarch64/dispatch.c",
 -                                   "arch/aarch64/pmap_arch.c", "arch/aarch64/sys_debug.c",
 +                                   "arch/aarch64/pmap.c", "arch/aarch64/sys_debug.c",
                                     "arch/aarch64/syscalls.c", "vspace/memobj_pinned.c" ,
-                                    "vspace/pinned.c", "vspace/memobj_anon.c",
-                                    "vspace/arch/aarch64/layout.c" ]
+                                    "vspace/pinned.c", "vspace/arch/aarch64/layout.c" ]
  
        archfam_srcs _         = []
  
  #include <trace/trace.h>
  #include <trace_definitions/trace_defs.h>
  
 +// this should work for x86_64 and x86_32.
 +bool has_vnode(struct vnode *root, uint32_t entry, size_t len,
 +               bool only_pages)
 +{
 +    assert(root != NULL);
 +    assert(root->is_vnode);
 +    struct vnode *n;
 +
 +    uint32_t end_entry = entry + len;
 +
 +    // region we check [entry .. end_entry)
 +
 +    for (n = root->u.vnode.children; n; n = n->next) {
 +        // n is page table, we need to check if it's anywhere inside the
 +        // region to check [entry .. end_entry)
 +        // this amounts to n->entry == entry for len = 1
 +        if (n->is_vnode && n->entry >= entry && n->entry < end_entry) {
 +            if (only_pages) {
 +                return has_vnode(n, 0, PTABLE_SIZE, true);
 +            }
 +#ifdef LIBBARRELFISH_DEBUG_PMAP
 +            debug_printf("1: found page table inside our region\n");
 +#endif
 +            return true;
 +        } else if (n->is_vnode) {
 +            // all other vnodes do not overlap with us, so go to next
 +            assert(n->entry < entry || n->entry >= end_entry);
 +            continue;
 +        }
 +        // this remains the same regardless of `only_pages`.
 +        // n is frame [n->entry .. end)
 +        // 3 cases:
 +        // 1) entry < n->entry && end_entry >= end --> n is a strict subset of
 +        // our region
 +        // 2) entry inside n (entry >= n->entry && entry < end)
 +        // 3) end_entry inside n (end_entry >= n->entry && end_entry < end)
 +        uint32_t end = n->entry + n->u.frame.pte_count;
 +        if (entry < n->entry && end_entry >= end) {
 +#ifdef LIBBARRELFISH_DEBUG_PMAP
 +            debug_printf("2: found a strict subset of our region: (%"
 +                    PRIu32"--%"PRIu32") < (%"PRIu32"--%"PRIu32")\n",
 +                    n->entry, end, entry, end_entry);
 +#endif
 +            return true;
 +        }
 +        if (entry >= n->entry && entry < end) {
 +#ifdef LIBBARRELFISH_DEBUG_PMAP
 +            debug_printf("3: found a region starting inside our region: (%"
 +                    PRIu32"--%"PRIu32") <> (%"PRIu32"--%"PRIu32")\n",
 +                    n->entry, end, entry, end_entry);
 +#endif
 +            return true;
 +        }
 +        if (end_entry > n->entry && end_entry < end) {
 +#ifdef LIBBARRELFISH_DEBUG_PMAP
 +            debug_printf("4: found a region ending inside our region: (%"
 +                    PRIu32"--%"PRIu32") <> (%"PRIu32"--%"PRIu32")\n",
 +                    n->entry, end, entry, end_entry);
 +#endif
 +            return true;
 +        }
 +    }
 +
 +    return false;
 +}
 +
+ #if defined(PMAP_LL)
  /**
   * \brief Starting at a given root, return the vnode with entry equal to #entry
   */
@@@ -391,13 -489,24 +555,27 @@@ static errval_t deserialise_tree(struc
          n->u.vnode.cap.cnode     = cnode_page;
          n->u.vnode.cap.slot      = (*in)->slot;
          n->u.vnode.invokable     = n->u.vnode.cap;
-         n->u.vnode.children      = NULL;
-         n->next                  = parent->u.vnode.children;
-         parent->u.vnode.children = n;
+ #if defined(PMAP_LL)
+          n->u.vnode.children  = NULL;
+         // insert in linked list
+          n->next      = parent->u.vnode.children;
+          parent->u.vnode.children = n;
+ #elif defined(PMAP_ARRAY)
+         memset(n->u.vnode.children, 0, sizeof(struct vode *)*PTABLE_SIZE);
+         // insert in array
+         parent->u.vnode.children[n->entry] = n;
+ #else
+ #error Invalid pmap datastructure
+ #endif
+         n->u.vnode.base = (*in)->base;
+         n->type = (*in)->type;
+         // Count cnode_page slots that are in use
+         pmapx->used_cap_slots ++;
  
 +        // Count cnode_page slots that are in use
 +        pmapx->used_cap_slots ++;
 +
          (*in)++;
          (*inlen)--;
  
Simple merge
Simple merge
@@@ -132,10 -132,9 +132,10 @@@ void debug_printf(const char *fmt, ...
  /**
   * \brief Function to do the actual printing based on the type of capability
   */
- STATIC_ASSERT(50 == ObjType_Num, "Knowledge of all cap types");
+ STATIC_ASSERT(58 == ObjType_Num, "Knowledge of all cap types");
  int debug_print_cap(char *buf, size_t len, struct capability *cap)
  {
 +    char *mappingtype;
      switch (cap->type) {
      case ObjType_PhysAddr:
          return snprintf(buf, len,
          return snprintf(buf, len, "x86_64 PML4 at 0x%" PRIxGENPADDR,
                          cap->u.vnode_x86_64_pml4.base);
  
+     case ObjType_VNode_x86_64_ept_ptable:
+         return snprintf(buf, len, "x86_64 EPT Page table at 0x%" PRIxGENPADDR,
+                         cap->u.vnode_x86_64_ept_ptable.base);
+     case ObjType_VNode_x86_64_ept_pdir:
+         return snprintf(buf, len, "x86_64 EPT Page directory at 0x%" PRIxGENPADDR,
+                         cap->u.vnode_x86_64_ept_pdir.base);
+     case ObjType_VNode_x86_64_ept_pdpt:
+         return snprintf(buf, len, "x86_64 EPT PDPT at 0x%" PRIxGENPADDR,
+                         cap->u.vnode_x86_64_ept_pdpt.base);
+     case ObjType_VNode_x86_64_ept_pml4:
+         return snprintf(buf, len, "x86_64 EPT PML4 at 0x%" PRIxGENPADDR,
+                         cap->u.vnode_x86_64_ept_pml4.base);
      case ObjType_Frame_Mapping:
 -        return snprintf(buf, len, "Frame Mapping (Frame cap @%p, "
 -                                  "pte @0x%"PRIxLVADDR", pte_count=%hu)",
 -                                  cap->u.frame_mapping.cap,
 -                                  cap->u.frame_mapping.pte,
 -                                  cap->u.frame_mapping.pte_count);
 -
 +        mappingtype = "Frame";
 +        goto ObjType_Mapping;
      case ObjType_DevFrame_Mapping:
 -        return snprintf(buf, len, "DevFrame Mapping (DevFrame cap @%p, "
 -                                  "pte @0x%"PRIxLVADDR", pte_count=%hu)",
 -                                  cap->u.devframe_mapping.cap,
 -                                  cap->u.devframe_mapping.pte,
 -                                  cap->u.devframe_mapping.pte_count);
 +        mappingtype = "DevFrame";
 +        goto ObjType_Mapping;
  
      case ObjType_VNode_x86_64_pml4_Mapping:
 -        return snprintf(buf, len, "x86_64 PML4 Mapping (x86_64 PML4 cap @%p, "
 -                                  "pte @0x%"PRIxLVADDR", pte_count=%hu)",
 -                                  cap->u.vnode_x86_64_pml4_mapping.cap,
 -                                  cap->u.vnode_x86_64_pml4_mapping.pte,
 -                                  cap->u.vnode_x86_64_pml4_mapping.pte_count);
 -
 +        mappingtype = "x86_64 PML4";
 +        goto ObjType_Mapping;
      case ObjType_VNode_x86_64_pdpt_Mapping:
 -        return snprintf(buf, len, "x86_64 PDPT Mapping (x86_64 PDPT cap @%p, "
 -                                  "pte @0x%"PRIxLVADDR", pte_count=%hu)",
 -                                  cap->u.vnode_x86_64_pdpt_mapping.cap,
 -                                  cap->u.vnode_x86_64_pdpt_mapping.pte,
 -                                  cap->u.vnode_x86_64_pdpt_mapping.pte_count);
 -
 +        mappingtype = "x86_64 PDPT";
 +        goto ObjType_Mapping;
      case ObjType_VNode_x86_64_pdir_Mapping:
 -        return snprintf(buf, len, "x86_64 PDIR Mapping (x86_64 PDIR cap @%p, "
 -                                  "pte @0x%"PRIxLVADDR", pte_count=%hu)",
 -                                  cap->u.vnode_x86_64_pdir_mapping.cap,
 -                                  cap->u.vnode_x86_64_pdir_mapping.pte,
 -                                  cap->u.vnode_x86_64_pdir_mapping.pte_count);
 -
 +        mappingtype = "x86_64 PDIR";
 +        goto ObjType_Mapping;
      case ObjType_VNode_x86_64_ptable_Mapping:
 -        return snprintf(buf, len, "x86_64 PTABLE Mapping (x86_64 PTABLE cap @%p, "
 -                                  "pte @0x%"PRIxLVADDR", pte_count=%hu)",
 -                                  cap->u.vnode_x86_64_ptable_mapping.cap,
 -                                  cap->u.vnode_x86_64_ptable_mapping.pte,
 -                                  cap->u.vnode_x86_64_ptable_mapping.pte_count);
 +        mappingtype = "x86_64 PTABLE";
 +        goto ObjType_Mapping;
  
+     case ObjType_VNode_x86_64_ept_pml4_Mapping:
+         return snprintf(buf, len, "x86_64 EPT PML4 Mapping (x86_64 PML4 cap @%p, "
+                                   "pte @0x%"PRIxLVADDR", pte_count=%hu)",
+                                   cap->u.vnode_x86_64_ept_pml4_mapping.cap,
+                                   cap->u.vnode_x86_64_ept_pml4_mapping.pte,
+                                   cap->u.vnode_x86_64_ept_pml4_mapping.pte_count);
+     case ObjType_VNode_x86_64_ept_pdpt_Mapping:
+         return snprintf(buf, len, "x86_64 EPT PDPT Mapping (x86_64 PDPT cap @%p, "
+                                   "pte @0x%"PRIxLVADDR", pte_count=%hu)",
+                                   cap->u.vnode_x86_64_ept_pdpt_mapping.cap,
+                                   cap->u.vnode_x86_64_ept_pdpt_mapping.pte,
+                                   cap->u.vnode_x86_64_ept_pdpt_mapping.pte_count);
+     case ObjType_VNode_x86_64_ept_pdir_Mapping:
+         return snprintf(buf, len, "x86_64 EPT PDIR Mapping (x86_64 PDIR cap @%p, "
+                                   "pte @0x%"PRIxLVADDR", pte_count=%hu)",
+                                   cap->u.vnode_x86_64_ept_pdir_mapping.cap,
+                                   cap->u.vnode_x86_64_ept_pdir_mapping.pte,
+                                   cap->u.vnode_x86_64_ept_pdir_mapping.pte_count);
+     case ObjType_VNode_x86_64_ept_ptable_Mapping:
+         return snprintf(buf, len, "x86_64 EPT PTABLE Mapping (x86_64 PTABLE cap @%p, "
+                                   "pte @0x%"PRIxLVADDR", pte_count=%hu)",
+                                   cap->u.vnode_x86_64_ept_ptable_mapping.cap,
+                                   cap->u.vnode_x86_64_ept_ptable_mapping.pte,
+                                   cap->u.vnode_x86_64_ept_ptable_mapping.pte_count);
      case ObjType_VNode_x86_32_pdpt_Mapping:
 -        return snprintf(buf, len, "x86_32 PDPT Mapping (x86_32 PDPT cap @%p, "
 -                                  "pte @0x%"PRIxLVADDR", pte_count=%hu)",
 -                                  cap->u.vnode_x86_32_pdpt_mapping.cap,
 -                                  cap->u.vnode_x86_32_pdpt_mapping.pte,
 -                                  cap->u.vnode_x86_32_pdpt_mapping.pte_count);
 -
 +        mappingtype = "x86_32 PDPT";
 +        goto ObjType_Mapping;
      case ObjType_VNode_x86_32_pdir_Mapping:
 -        return snprintf(buf, len, "x86_32 PDIR Mapping (x86_32 PDIR cap @%p, "
 -                                  "pte @0x%"PRIxLVADDR", pte_count=%hu)",
 -                                  cap->u.vnode_x86_32_pdir_mapping.cap,
 -                                  cap->u.vnode_x86_32_pdir_mapping.pte,
 -                                  cap->u.vnode_x86_32_pdir_mapping.pte_count);
 -
 +        mappingtype = "x86_32 PDIR";
 +        goto ObjType_Mapping;
      case ObjType_VNode_x86_32_ptable_Mapping:
 -        return snprintf(buf, len, "x86_32 PTABLE Mapping (x86_32 PTABLE cap @%p, "
 -                                  "pte @0x%"PRIxLVADDR", pte_count=%hu)",
 -                                  cap->u.vnode_x86_32_ptable_mapping.cap,
 -                                  cap->u.vnode_x86_32_ptable_mapping.pte,
 -                                  cap->u.vnode_x86_32_ptable_mapping.pte_count);
 +        mappingtype = "x86_32 PTABLE";
 +        goto ObjType_Mapping;
  
      case ObjType_VNode_ARM_l1_Mapping:
 -        return snprintf(buf, len, "ARM l1 Mapping (ARM l1 cap @%p, "
 -                                  "pte @0x%"PRIxLVADDR", pte_count=%hu)",
 -                                  cap->u.vnode_arm_l1_mapping.cap,
 -                                  cap->u.vnode_arm_l1_mapping.pte,
 -                                  cap->u.vnode_arm_l1_mapping.pte_count);
 -
 +        mappingtype = "ARM l1";
 +        goto ObjType_Mapping;
      case ObjType_VNode_ARM_l2_Mapping:
 -        return snprintf(buf, len, "ARM l2 Mapping (ARM l2 cap @%p, "
 -                                  "pte @0x%"PRIxLVADDR", pte_count=%hu)",
 -                                  cap->u.vnode_arm_l2_mapping.cap,
 -                                  cap->u.vnode_arm_l2_mapping.pte,
 -                                  cap->u.vnode_arm_l2_mapping.pte_count);
 +        mappingtype = "ARM l2";
 +        goto ObjType_Mapping;
  
      case ObjType_VNode_AARCH64_l0_Mapping:
 -        return snprintf(buf, len, "AARCH64 l0 Mapping (AARCH64 l0 cap @0x%p, "
 -                                  "pte @0x%"PRIxLVADDR", pte_count=%hu)",
 -                                  cap->u.vnode_aarch64_l0_mapping.cap,
 -                                  cap->u.vnode_aarch64_l0_mapping.pte,
 -                                  cap->u.vnode_aarch64_l0_mapping.pte_count);
 -
 +        mappingtype = "AARCH64 l0";
 +        goto ObjType_Mapping;
      case ObjType_VNode_AARCH64_l1_Mapping:
 -        return snprintf(buf, len, "AARCH64 l1 Mapping (AARCH64 l1 cap @%p, "
 -                                  "pte @0x%"PRIxLVADDR", pte_count=%hu)",
 -                                  cap->u.vnode_aarch64_l1_mapping.cap,
 -                                  cap->u.vnode_aarch64_l1_mapping.pte,
 -                                  cap->u.vnode_aarch64_l1_mapping.pte_count);
 -
 +        mappingtype = "AARCH64 l1";
 +        goto ObjType_Mapping;
      case ObjType_VNode_AARCH64_l2_Mapping:
 -        return snprintf(buf, len, "AARCH64 l2 Mapping (AARCH64 l2 cap @%p, "
 -                                  "pte @0x%"PRIxLVADDR", pte_count=%hu)",
 -                                  cap->u.vnode_aarch64_l2_mapping.cap,
 -                                  cap->u.vnode_aarch64_l2_mapping.pte,
 -                                  cap->u.vnode_aarch64_l2_mapping.pte_count);
 -
 +        mappingtype = "AARCH64 l2";
 +        goto ObjType_Mapping;
      case ObjType_VNode_AARCH64_l3_Mapping:
 -        return snprintf(buf, len, "AARCH64 l3 Mapping (AARCH64 l3 cap @%p, "
 -                                  "pte @0x%"PRIxLVADDR", pte_count=%hu)",
 -                                  cap->u.vnode_aarch64_l3_mapping.cap,
 -                                  cap->u.vnode_aarch64_l3_mapping.pte,
 -                                  cap->u.vnode_aarch64_l3_mapping.pte_count);
 +        mappingtype = "AARCH64 l3";
 +        goto ObjType_Mapping;
  
 +ObjType_Mapping:
 +        return snprintf(buf, len, "%s Mapping (%s cap @%p, "
 +                                  "ptable cap @0x%p, entry=%hu, pte_count=%hu)",
 +                                  mappingtype, mappingtype,
 +                                  cap->u.frame_mapping.cap,
 +                                  cap->u.frame_mapping.ptable,
 +                                  cap->u.frame_mapping.entry,
 +                                  cap->u.frame_mapping.pte_count);
  
      case ObjType_IRQTable:
          return snprintf(buf, len, "IRQTable cap");
@@@ -96,14 -123,19 +123,24 @@@ errval_t ram_alloc_fixed(struct capref 
  
      if (size_bits == BASE_PAGE_BITS) {
          // XXX: Return error if check to see if out of slots
 -        assert(state->base_capnum < OBJSPERPAGE_CTE);
 +        if (state->base_capnum >= L2_CNODE_SLOTS) {
 +            debug_printf("%s: state->base_capnum = %d\n", __FUNCTION__,
 +                    state->base_capnum);
 +            return LIB_ERR_RAM_ALLOC_FIXED_EXHAUSTED;
 +        }
 +        assert(state->base_capnum < L2_CNODE_SLOTS);
          ret->cnode = cnode_base;
          ret->slot  = state->base_capnum++;
+ #ifdef ARRAKIS
+         struct frame_identity fi;
+         errval_t err2 = invoke_frame_identify(*ret, &fi);
+         if (err_is_fail(err2)){
+             DEBUG_ERR(err2, "frame_identify in ram_alloc");
+         }
+         assert(err_is_ok(err2));
+         debug_printf("[ARRADOMAIN] ram_alloc_fixed: allocated %zu bytes at 0x%zx\n",
+                 fi.bytes, fi.base);
+ #endif
          return SYS_ERR_OK;
      } else {
          return LIB_ERR_RAM_ALLOC_WRONG_SIZE;
Simple merge
Simple merge
@@@ -9,48 -9,67 +9,90 @@@
  
  #include <unistd.h>
  #include <barrelfish/barrelfish.h>
 -#include <posixcompat.h>
 +#include <barrelfish/cpu_arch.h>
++#include <posixcompat.h> // for sbrk_get_*() declarations
++
++// Uncomment this if you want to measure sbrk() collective runtime
++// TODO: make this a Config.hs flag maybe? -SG, 2018-10-18.
++// #define SBRK_COLLECT_STATS
  
  #if __SIZEOF_POINTER__ == 8
 -//need lot of memory...
 -#define SBRK_REGION_BYTES (1024*1024*200000ULL)
 -#else // still huge, but slightly more achievable in a 32-bit address space!
 -#define SBRK_REGION_BYTES (256 * 1024 * 1024)
 +#ifdef __x86_64__
 +// Large memory area + large pages on x86_64
- #define SBRK_REGION_BYTES (8UL * 512UL * LARGE_PAGE_SIZE)
++#define SBRK_REGION_BYTES (128UL * HUGE_PAGE_SIZE) // 64GB
 +#define SBRK_FLAGS (VREGION_FLAGS_READ_WRITE | VREGION_FLAGS_LARGE)
 +#define SBRK_MIN_MAPPING (16 * LARGE_PAGE_SIZE)
 +#define SBRK_REGION_ALIGNMENT LARGE_PAGE_SIZE
- #else 
++#else
 +// Large memory area + normal pages
- #define SBRK_REGION_BYTES (8UL * 512UL * LARGE_PAGE_SIZE)
++#define SBRK_REGION_BYTES (8UL * 512UL * LARGE_PAGE_SIZE) // 8GB
 +#define SBRK_FLAGS (VREGION_FLAGS_READ_WRITE)
 +#define SBRK_MIN_MAPPING (16 * LARGE_PAGE_SIZE)
 +#define SBRK_REGION_ALIGNMENT BASE_PAGE_SIZE
 +#endif
 +#else
 +// still huge, but slightly more achievable in a 32-bit address space!
- #define SBRK_REGION_BYTES (64 * 1024 * BASE_PAGE_SIZE)
++#define SBRK_REGION_BYTES (64 * 1024 * BASE_PAGE_SIZE) // 256MB
 +#define SBRK_FLAGS (VREGION_FLAGS_READ_WRITE)
 +#define SBRK_MIN_MAPPING (2 * BASE_PAGE_SIZE)
 +#define SBRK_REGION_ALIGNMENT BASE_PAGE_SIZE
  #endif
  
 +
+ static void *base = NULL;
+ static size_t offset = 0; ///< How much is currently used
+ static size_t goffset = 0; ///< Maximum ever allocated
+ static struct memobj_append memobj_;
+ static struct memobj *memobj = NULL;
+ static struct vregion vregion_;
+ static struct vregion *vregion = NULL;
+ struct memobj_anon* sbrk_get_memobj(void)
+ {
+     assert(memobj != NULL);
+     return (struct memobj_anon*) memobj;
+ }
+ struct vregion* sbrk_get_vregion(void)
+ {
+     assert(vregion != NULL);
+     return vregion;
+ }
 -void* sbrk_get_base(void) 
++void* sbrk_get_base(void)
+ {
+     assert(base != NULL);
+     return base;
+ }
+ size_t sbrk_get_offset(void)
+ {
+     assert(offset != 0);
+     return offset;
+ }
++#ifdef SBRK_COLLECT_STATS
+ uint64_t sbrk_times = 0;
+ static inline unsigned long bf_ticks(void)
+ {
+    unsigned int a, d;
+    __asm__ volatile("rdtsc" : "=a" (a), "=d" (d));
+    return ((unsigned long) a) | (((unsigned long) d) << 32);
+ }
++#endif
  void *sbrk(intptr_t increment)
  {
+     uint64_t start = bf_ticks();
      errval_t err;
      size_t orig_offset;
  
-     static void *base;
-     static size_t offset = 0;
-     static size_t goffset = 0;
-     static struct memobj_anon memobj_;
-     static struct memobj *memobj = NULL;
-     static struct vregion vregion_;
-     static struct vregion *vregion = NULL;
      if (!memobj) { // Initialize
 -        err = vspace_map_append_nomalloc(&base, &memobj_, &vregion_,
 -                                         SBRK_REGION_BYTES, NULL,
 -                                         VREGION_FLAGS_READ_WRITE, 0);
 +        err = vspace_map_anon_nomalloc(&base, &memobj_, &vregion_,
 +                                       SBRK_REGION_BYTES, NULL,
 +                                       SBRK_FLAGS, SBRK_REGION_ALIGNMENT);
          if (err_is_fail(err)) {
              DEBUG_ERR(err, "vspace_map_anon_nomalloc failed");
              return (void *)-1;
          return (void *)-1;
      }
  
 +    goffset += inc_bytes;
 +
 +    orig_offset = offset;
 +    offset += increment;
++#ifdef SBRK_COLLECT_TIMES
+     uint64_t end = bf_ticks();
+     sbrk_times += end - start;
++#endif
  
      void *ret = base + orig_offset;
      return ret;
Simple merge