VM: memtype fix

. make more explicit when the default or per-block
	  memtype should be used

Change-Id: I5523db14ac036ec774a54392fb67f9acb8725731
This commit is contained in:
Ben Gras 2013-03-20 19:09:01 +00:00
parent 41fc49ed0c
commit f150ea2a1b
5 changed files with 33 additions and 34 deletions

View File

@ -52,9 +52,9 @@ static int getsrc(struct vir_region *region,
{ {
int srcproc; int srcproc;
if(region->memtype != &mem_type_shared) { if(region->def_memtype != &mem_type_shared) {
printf("shared region hasn't shared type but %s.\n", printf("shared region hasn't shared type but %s.\n",
region->memtype->name); region->def_memtype->name);
return EINVAL; return EINVAL;
} }
@ -78,9 +78,9 @@ static int getsrc(struct vir_region *region,
return EINVAL; return EINVAL;
} }
if((*r)->memtype != &mem_type_anon) { if((*r)->def_memtype != &mem_type_anon) {
printf("source region hasn't anon type but %s.\n", printf("source region hasn't anon type but %s.\n",
(*r)->memtype->name); (*r)->def_memtype->name);
return EINVAL; return EINVAL;
} }
@ -162,7 +162,7 @@ void shared_setsource(struct vir_region *vr, endpoint_t ep,
int id = src_vr->id; int id = src_vr->id;
vir_bytes vaddr = src_vr->vaddr; vir_bytes vaddr = src_vr->vaddr;
assert(vr->memtype == &mem_type_shared); assert(vr->def_memtype == &mem_type_shared);
if(!ep || !vaddr || !id) { if(!ep || !vaddr || !id) {
printf("VM: shared_setsource: zero ep/vaddr/id - ignoring\n"); printf("VM: shared_setsource: zero ep/vaddr/id - ignoring\n");

View File

@ -65,7 +65,7 @@ USE(newphysr,
newphysr->ph = newpb; newphysr->ph = newpb;
newphysr->parent = parent; newphysr->parent = parent;
newphysr->next_ph_list = newpb->firstregion; newphysr->next_ph_list = newpb->firstregion;
newphysr->memtype = parent->memtype; newphysr->memtype = parent->def_memtype;
newpb->firstregion = newphysr;); newpb->firstregion = newphysr;);
newpb->refcount++; newpb->refcount++;
} }
@ -120,7 +120,7 @@ void pb_unreferenced(struct vir_region *region, struct phys_region *pr, int rm)
if(pb->refcount == 0) { if(pb->refcount == 0) {
assert(!pb->firstregion); assert(!pb->firstregion);
int r; int r;
if((r = region->memtype->ev_unreference(pr)) != OK) if((r = region->def_memtype->ev_unreference(pr)) != OK)
panic("unref failed, %d", r); panic("unref failed, %d", r);
SLABFREE(pb); SLABFREE(pb);

View File

@ -13,7 +13,8 @@ typedef struct phys_region {
int written; /* written to pagetable */ int written; /* written to pagetable */
#endif #endif
mem_type_t *memtype; /* what kind of memory is it? */
mem_type_t *memtype;
/* list of phys_regions that reference the same phys_block */ /* list of phys_regions that reference the same phys_block */
struct phys_region *next_ph_list; struct phys_region *next_ph_list;

View File

@ -44,9 +44,9 @@ void map_printregion(struct vir_region *vr)
{ {
int i; int i;
struct phys_region *ph; struct phys_region *ph;
printf("map_printmap: map_name: %s\n", vr->memtype->name); printf("map_printmap: map_name: %s\n", vr->def_memtype->name);
printf("\t%lx (len 0x%lx, %lukB), %p\n", printf("\t%lx (len 0x%lx, %lukB), %p\n",
vr->vaddr, vr->length, vr->length/1024, vr->memtype->name); vr->vaddr, vr->length, vr->length/1024, vr->def_memtype->name);
printf("\t\tphysblocks:\n"); printf("\t\tphysblocks:\n");
for(i = 0; i < vr->length/VM_PAGE_SIZE; i++) { for(i = 0; i < vr->length/VM_PAGE_SIZE; i++) {
if(!(ph=vr->physblocks[i])) continue; if(!(ph=vr->physblocks[i])) continue;
@ -122,8 +122,8 @@ static struct vir_region *getnextvr(struct vir_region *vr)
int pr_writable(struct vir_region *vr, struct phys_region *pr) int pr_writable(struct vir_region *vr, struct phys_region *pr)
{ {
assert(vr->memtype->writable); assert(vr->def_memtype->writable);
return ((vr->flags & VR_WRITABLE) && vr->memtype->writable(pr)); return ((vr->flags & VR_WRITABLE) && vr->def_memtype->writable(pr));
} }
#if SANITYCHECKS #if SANITYCHECKS
@ -434,7 +434,7 @@ USE(newregion,
newregion->vaddr = startv; newregion->vaddr = startv;
newregion->length = length; newregion->length = length;
newregion->flags = flags; newregion->flags = flags;
newregion->memtype = memtype; newregion->def_memtype = memtype;
newregion->remaps = 0; newregion->remaps = 0;
newregion->id = id++; newregion->id = id++;
newregion->lower = newregion->higher = NULL; newregion->lower = newregion->higher = NULL;
@ -482,8 +482,8 @@ mem_type_t *memtype;
} }
/* If a new event is specified, invoke it. */ /* If a new event is specified, invoke it. */
if(newregion->memtype->ev_new) { if(newregion->def_memtype->ev_new) {
if(newregion->memtype->ev_new(newregion) != OK) { if(newregion->def_memtype->ev_new(newregion) != OK) {
/* ev_new will have freed and removed the region */ /* ev_new will have freed and removed the region */
return NULL; return NULL;
} }
@ -576,8 +576,8 @@ int map_free(struct vir_region *region)
return r; return r;
} }
if(region->memtype->ev_delete) if(region->def_memtype->ev_delete)
region->memtype->ev_delete(region); region->def_memtype->ev_delete(region);
free(region->physblocks); free(region->physblocks);
region->physblocks = NULL; region->physblocks = NULL;
SLABFREE(region); SLABFREE(region);
@ -711,13 +711,13 @@ int write;
* writable, nothing to do. * writable, nothing to do.
*/ */
assert(region->memtype->writable); assert(region->def_memtype->writable);
if(!write || !region->memtype->writable(ph)) { if(!write || !region->def_memtype->writable(ph)) {
assert(region->memtype->ev_pagefault); assert(region->def_memtype->ev_pagefault);
assert(ph->ph); assert(ph->ph);
if((r = region->memtype->ev_pagefault(vmp, if((r = region->def_memtype->ev_pagefault(vmp,
region, ph, write)) == SUSPEND) { region, ph, write)) == SUSPEND) {
panic("map_pf: memtype->ev_pagefault returned SUSPEND\n"); panic("map_pf: memtype->ev_pagefault returned SUSPEND\n");
return SUSPEND; return SUSPEND;
@ -819,10 +819,10 @@ static struct vir_region *map_copy_region(struct vmproc *vmp, struct vir_region
#endif #endif
vir_bytes p; vir_bytes p;
if(!(newvr = region_new(vr->parent, vr->vaddr, vr->length, vr->flags, vr->memtype))) if(!(newvr = region_new(vr->parent, vr->vaddr, vr->length, vr->flags, vr->def_memtype)))
return NULL; return NULL;
if(vr->memtype->ev_copy && (r=vr->memtype->ev_copy(vr, newvr)) != OK) { if(vr->def_memtype->ev_copy && (r=vr->def_memtype->ev_copy(vr, newvr)) != OK) {
map_free(newvr); map_free(newvr);
printf("VM: memtype-specific copy failed (%d)\n", r); printf("VM: memtype-specific copy failed (%d)\n", r);
return NULL; return NULL;
@ -1033,12 +1033,12 @@ int map_region_extend_upto_v(struct vmproc *vmp, vir_bytes v)
return ENOMEM; return ENOMEM;
} }
if(!vr->memtype->ev_resize) { if(!vr->def_memtype->ev_resize) {
printf("VM: can't resize this type of memory\n"); printf("VM: can't resize this type of memory\n");
return ENOMEM; return ENOMEM;
} }
return vr->memtype->ev_resize(vmp, vr, offset - vr->vaddr); return vr->def_memtype->ev_resize(vmp, vr, offset - vr->vaddr);
} }
/*========================================================================* /*========================================================================*
@ -1129,11 +1129,11 @@ int map_get_phys(struct vmproc *vmp, vir_bytes addr, phys_bytes *r)
(vr->vaddr != addr)) (vr->vaddr != addr))
return EINVAL; return EINVAL;
if (!vr->memtype->regionid) if (!vr->def_memtype->regionid)
return EINVAL; return EINVAL;
if(r) if(r)
*r = vr->memtype->regionid(vr); *r = vr->def_memtype->regionid(vr);
return OK; return OK;
} }
@ -1146,11 +1146,11 @@ int map_get_ref(struct vmproc *vmp, vir_bytes addr, u8_t *cnt)
struct vir_region *vr; struct vir_region *vr;
if (!(vr = map_lookup(vmp, addr, NULL)) || if (!(vr = map_lookup(vmp, addr, NULL)) ||
(vr->vaddr != addr) || !vr->memtype->refcount) (vr->vaddr != addr) || !vr->def_memtype->refcount)
return EINVAL; return EINVAL;
if (cnt) if (cnt)
*cnt = vr->memtype->refcount(vr); *cnt = vr->def_memtype->refcount(vr);
return OK; return OK;
} }

View File

@ -25,13 +25,11 @@ struct phys_block {
u32_t seencount; u32_t seencount;
#endif #endif
phys_bytes phys; /* physical memory */ phys_bytes phys; /* physical memory */
u8_t refcount; /* Refcount of these pages */
/* what kind of memory is it? */
mem_type_t *memtype;
/* first in list of phys_regions that reference this block */ /* first in list of phys_regions that reference this block */
struct phys_region *firstregion; struct phys_region *firstregion;
u8_t refcount; /* Refcount of these pages */
u8_t flags;
}; };
typedef struct vir_region { typedef struct vir_region {
@ -40,7 +38,7 @@ typedef struct vir_region {
struct phys_region **physblocks; struct phys_region **physblocks;
u16_t flags; u16_t flags;
struct vmproc *parent; /* Process that owns this vir_region. */ struct vmproc *parent; /* Process that owns this vir_region. */
mem_type_t *memtype; /* Default instantiated memory type. */ mem_type_t *def_memtype; /* Default instantiated memory type. */
int remaps; int remaps;
u32_t id; /* unique id */ u32_t id; /* unique id */