vm: Separate mmap regions.

Add support for compact address layout.  This feature can be enabled
through the ac_layout=1 boot option.

Change-Id: Ie20b808fce32b5c54d0a7e7210e0084a540e9613
This commit is contained in:
Cristiano Giuffrida 2014-03-12 00:02:34 +01:00 committed by David van Moolenbroek
parent 48f446ecd5
commit 53398d733f
6 changed files with 53 additions and 12 deletions

View file

@ -275,12 +275,12 @@ void get_parameters(kinfo_t *cbi, char *bootargs)
mb_set_param(cbi->param_buf, BOARDVARNAME,(char *)get_board_name(machine.board_id) , cbi); mb_set_param(cbi->param_buf, BOARDVARNAME,(char *)get_board_name(machine.board_id) , cbi);
/* round user stack down to leave a gap to catch kernel /* move user stack/data down to leave a gap to catch kernel
* stack overflow; and to distinguish kernel and user addresses * stack overflow; and to distinguish kernel and user addresses
* at a glance (0xf.. vs 0xe..) * at a glance (0xf.. vs 0xe..)
*/ */
cbi->user_sp &= 0xF0000000; cbi->user_sp = USR_STACKTOP;
cbi->user_end = cbi->user_sp; cbi->user_end = USR_DATATOP;
/* kernel bytes without bootstrap code/data that is currently /* kernel bytes without bootstrap code/data that is currently
* still needed but will be freed after bootstrapping. * still needed but will be freed after bootstrapping.

View file

@ -157,12 +157,12 @@ void get_parameters(u32_t ebx, kinfo_t *cbi)
mb_set_param(cbi->param_buf, ARCHVARNAME, (char *)get_board_arch_name(BOARD_ID_INTEL), cbi); mb_set_param(cbi->param_buf, ARCHVARNAME, (char *)get_board_arch_name(BOARD_ID_INTEL), cbi);
mb_set_param(cbi->param_buf, BOARDVARNAME,(char *)get_board_name(BOARD_ID_INTEL) , cbi); mb_set_param(cbi->param_buf, BOARDVARNAME,(char *)get_board_name(BOARD_ID_INTEL) , cbi);
/* round user stack down to leave a gap to catch kernel /* move user stack/data down to leave a gap to catch kernel
* stack overflow; and to distinguish kernel and user addresses * stack overflow; and to distinguish kernel and user addresses
* at a glance (0xf.. vs 0xe..) * at a glance (0xf.. vs 0xe..)
*/ */
cbi->user_sp &= 0xF0000000; cbi->user_sp = USR_STACKTOP;
cbi->user_end = cbi->user_sp; cbi->user_end = USR_DATATOP;
/* kernel bytes without bootstrap code/data that is currently /* kernel bytes without bootstrap code/data that is currently
* still needed but will be freed after bootstrapping. * still needed but will be freed after bootstrapping.

View file

@ -30,4 +30,25 @@
/* for kputc() */ /* for kputc() */
#define END_OF_KMESS 0 #define END_OF_KMESS 0
/* User limits. */
#ifndef USR_DATATOP
#ifndef _MINIX_MAGIC
#define USR_DATATOP 0xF0000000
#else
#define USR_DATATOP 0xE0000000 /* TODO: is this necessary? */
#endif
#endif
#ifndef USR_STACKTOP
#define USR_STACKTOP USR_DATATOP
#endif
#ifndef USR_DATATOP_COMPACT
#define USR_DATATOP_COMPACT USR_DATATOP
#endif
#ifndef USR_STACKTOP_COMPACT
#define USR_STACKTOP_COMPACT 0x50000000
#endif
#endif /* CONST_H */ #endif /* CONST_H */

View file

@ -426,6 +426,13 @@ void cstart()
if(!value || system_hz < 2 || system_hz > 50000) /* sanity check */ if(!value || system_hz < 2 || system_hz > 50000) /* sanity check */
system_hz = DEFAULT_HZ; system_hz = DEFAULT_HZ;
/* Get memory parameters. */
value = env_get("ac_layout");
if(value && atoi(value)) {
kinfo.user_sp = (vir_bytes) USR_STACKTOP_COMPACT;
kinfo.user_end = (vir_bytes) USR_DATATOP_COMPACT;
}
DEBUGEXTRA(("cstart\n")); DEBUGEXTRA(("cstart\n"));
/* Record miscellaneous information for user-space servers. */ /* Record miscellaneous information for user-space servers. */

View file

@ -75,7 +75,7 @@ static struct vir_region *mmap_region(struct vmproc *vmp, vir_bytes addr,
if (!vr) { if (!vr) {
/* No address given or address already in use. */ /* No address given or address already in use. */
vr = map_page_region(vmp, VM_PAGE_SIZE, VM_DATATOP, len, vr = map_page_region(vmp, VM_MMAPBASE, VM_MMAPTOP, len,
vrflags, mfflags, mt); vrflags, mfflags, mt);
} }
@ -349,7 +349,7 @@ int do_map_phys(message *m)
if(len % VM_PAGE_SIZE) if(len % VM_PAGE_SIZE)
len += VM_PAGE_SIZE - (len % VM_PAGE_SIZE); len += VM_PAGE_SIZE - (len % VM_PAGE_SIZE);
if(!(vr = map_page_region(vmp, 0, VM_DATATOP, len, if(!(vr = map_page_region(vmp, VM_MMAPBASE, VM_MMAPTOP, len,
VR_DIRECT | VR_WRITABLE, 0, &mem_type_directphys))) { VR_DIRECT | VR_WRITABLE, 0, &mem_type_directphys))) {
return ENOMEM; return ENOMEM;
} }
@ -419,8 +419,8 @@ int do_remap(message *m)
vr = map_page_region(dvmp, da, 0, size, flags, 0, vr = map_page_region(dvmp, da, 0, size, flags, 0,
&mem_type_shared); &mem_type_shared);
else else
vr = map_page_region(dvmp, 0, VM_DATATOP, size, flags, 0, vr = map_page_region(dvmp, VM_MMAPBASE, VM_MMAPTOP, size,
&mem_type_shared); flags, 0, &mem_type_shared);
if(!vr) { if(!vr) {
printf("VM: re-map of shared area failed\n"); printf("VM: re-map of shared area failed\n");

View file

@ -63,7 +63,20 @@
/* And what is the highest addressable piece of memory? */ /* And what is the highest addressable piece of memory? */
#define VM_DATATOP kernel_boot_info.user_end #define VM_DATATOP kernel_boot_info.user_end
#define VM_STACKTOP kernel_boot_info.user_sp #define VM_STACKTOP kernel_boot_info.user_sp
/* Live update will work only with magic instrumentation. Live update requires
* strict separation of regions within the process to succeed. Therefore,
* apply this strict separation only if magic instrumentation is used.
* Otherwise, do not place such limitations on processes.
*/
#ifdef _MINIX_MAGIC
#define VM_MMAPTOP (VM_STACKTOP-DEFAULT_STACK_LIMIT)
#define VM_MMAPBASE (VM_MMAPTOP/2)
#else
#define VM_MMAPTOP VM_DATATOP
#define VM_MMAPBASE VM_PAGE_SIZE
#endif #endif
#endif