No more intel/minix segments.

This commit removes all traces of Minix segments (the text/data/stack
memory map abstraction in the kernel) and significance of Intel segments
(hardware segments like CS, DS that add offsets to all addressing before
page table translation). This ultimately simplifies the memory layout
and addressing and makes the same layout possible on non-Intel
architectures.

There are only two types of addresses in the world now: virtual
and physical; even the kernel and processes have the same virtual
address space. Kernel and user processes can be distinguished at a
glance as processes won't use 0xF0000000 and above.

No static pre-allocated memory sizes exist any more.

Changes to booting:
        . The pre_init.c leaves the kernel and modules exactly as
          they were left by the bootloader in physical memory
        . The kernel starts running using physical addressing,
          loaded at a fixed location given in its linker script by the
          bootloader.  All code and data in this phase are linked to
          this fixed low location.
        . It makes a bootstrap pagetable to map itself to a
          fixed high location (also in linker script) and jumps to
          the high address. All code and data then use this high addressing.
        . All code/data symbols linked at the low addresses is prefixed by
          an objcopy step with __k_unpaged_*, so that that code cannot
          reference highly-linked symbols (which aren't valid yet) or vice
          versa (symbols that aren't valid any more).
        . The two addressing modes are separated in the linker script by
          collecting the unpaged_*.o objects and linking them with low
          addresses, and linking the rest high. Some objects are linked
          twice, once low and once high.
        . The bootstrap phase passes a lot of information (e.g. free memory
          list, physical location of the modules, etc.) using the kinfo
          struct.
        . After this bootstrap the low-linked part is freed.
        . The kernel maps in VM into the bootstrap page table so that VM can
          begin executing. Its first job is to make page tables for all other
          boot processes. So VM runs before RS, and RS gets a fully dynamic,
          VM-managed address space. VM gets its privilege info from RS as usual
          but that happens after RS starts running.
        . Both the kernel loading VM and VM organizing boot processes happen
	  using the libexec logic. This removes the last reason for VM to
	  still know much about exec() and vm/exec.c is gone.

Further Implementation:
        . All segments are based at 0 and have a 4 GB limit.
        . The kernel is mapped in at the top of the virtual address
          space so as not to constrain the user processes.
        . Processes do not use segments from the LDT at all; there are
          no segments in the LDT any more, so no LLDT is needed.
        . The Minix segments T/D/S are gone and so none of the
          user-space or in-kernel copy functions use them. The copy
          functions use a process endpoint of NONE to realize it's
          a physical address, virtual otherwise.
        . The umap call only makes sense to translate a virtual address
          to a physical address now.
        . Segments-related calls like newmap and alloc_segments are gone.
        . All segments-related translation in VM is gone (vir2map etc).
        . Initialization in VM is simpler as no moving around is necessary.
        . VM and all other boot processes can be linked wherever they wish
          and will be mapped in at the right location by the kernel and VM
          respectively.

Other changes:
        . The multiboot code is less special: it does not use mb_print
          for its diagnostics any more but uses printf() as normal, saving
          the output into the diagnostics buffer, only printing to the
          screen using the direct print functions if a panic() occurs.
        . The multiboot code uses the flexible 'free memory map list'
          style to receive the list of free memory if available.
        . The kernel determines the memory layout of the processes to
          a degree: it tells VM where the kernel starts and ends and
          where the kernel wants the top of the process to be. VM then
          uses this entire range, i.e. the stack is right at the top,
          and mmap()ped bits of memory are placed below that downwards,
          and the break grows upwards.

Other Consequences:
        . Every process gets its own page table as address spaces
          can't be separated any more by segments.
        . As all segments are 0-based, there is no distinction between
          virtual and linear addresses, nor between userspace and
          kernel addresses.
        . Less work is done when context switching, leading to a net
          performance increase. (8% faster on my machine for 'make servers'.)
	. The layout and configuration of the GDT makes sysenter and syscall
	  possible.
This commit is contained in:
Ben Gras
2012-05-07 16:03:35 +02:00
parent cfe1ed4df4
commit 50e2064049
139 changed files with 2468 additions and 4380 deletions

View File

@@ -5,7 +5,6 @@
SRCS+= \
do_fork.c \
do_exec.c \
do_newmap.c \
do_clear.c \
do_exit.c \
do_trace.c \

View File

@@ -35,10 +35,6 @@ int do_abort(struct proc * caller, message * m_ptr)
return p;
}
paramsbuffer[len] = '\0';
/* Parameters seem ok, copy them and prepare shutting down. */
if((p = arch_set_params(paramsbuffer, len+1)) != OK)
return p;
}
/* Now prepare to shutdown MINIX. */

View File

@@ -26,7 +26,6 @@ int do_copy(struct proc * caller, message * m_ptr)
struct vir_addr vir_addr[2]; /* virtual source and destination address */
phys_bytes bytes; /* number of bytes to copy */
int i;
endpoint_t pe;
#if 0
if (caller->p_endpoint != PM_PROC_NR && caller->p_endpoint != VFS_PROC_NR &&
@@ -47,11 +46,10 @@ int do_copy(struct proc * caller, message * m_ptr)
#endif
/* Dismember the command message. */
pe = vir_addr[_SRC_].proc_nr_e = m_ptr->CP_SRC_ENDPT;
vir_addr[_SRC_].segment = (pe == NONE ? PHYS_SEG : D);
vir_addr[_SRC_].proc_nr_e = m_ptr->CP_SRC_ENDPT;
vir_addr[_DST_].proc_nr_e = m_ptr->CP_DST_ENDPT;
vir_addr[_SRC_].offset = (vir_bytes) m_ptr->CP_SRC_ADDR;
pe = vir_addr[_DST_].proc_nr_e = m_ptr->CP_DST_ENDPT;
vir_addr[_DST_].segment = (pe == NONE ? PHYS_SEG : D);
vir_addr[_DST_].offset = (vir_bytes) m_ptr->CP_DST_ADDR;
bytes = (phys_bytes) m_ptr->CP_NR_BYTES;
@@ -63,10 +61,9 @@ int do_copy(struct proc * caller, message * m_ptr)
/* Check if process number was given implictly with SELF and is valid. */
if (vir_addr[i].proc_nr_e == SELF)
vir_addr[i].proc_nr_e = caller->p_endpoint;
if (vir_addr[i].segment != PHYS_SEG) {
if (vir_addr[i].proc_nr_e != NONE) {
if(! isokendpt(vir_addr[i].proc_nr_e, &p)) {
printf("do_copy: %d: seg 0x%x, %d not ok endpoint\n",
i, vir_addr[i].segment, vir_addr[i].proc_nr_e);
printf("do_copy: %d: %d not ok endpoint\n", i, vir_addr[i].proc_nr_e);
return(EINVAL);
}
}

View File

@@ -21,6 +21,7 @@ int do_exec(struct proc * caller, message * m_ptr)
/* Handle sys_exec(). A process has done a successful EXEC. Patch it up. */
register struct proc *rp;
int proc_nr;
char name[PROC_NAME_LEN];
if(!isokendpt(m_ptr->PR_ENDPT, &proc_nr))
return EINVAL;
@@ -33,11 +34,14 @@ int do_exec(struct proc * caller, message * m_ptr)
/* Save command name for debugging, ps(1) output, etc. */
if(data_copy(caller->p_endpoint, (vir_bytes) m_ptr->PR_NAME_PTR,
KERNEL, (vir_bytes) rp->p_name, (phys_bytes) P_NAME_LEN - 1) != OK)
strncpy(rp->p_name, "<unset>", P_NAME_LEN);
KERNEL, (vir_bytes) name,
(phys_bytes) sizeof(name) - 1) != OK)
strncpy(name, "<unset>", PROC_NAME_LEN);
/* Do architecture-specific exec() stuff. */
arch_pre_exec(rp, (u32_t) m_ptr->PR_IP_PTR, (u32_t) m_ptr->PR_STACK_PTR);
name[sizeof(name)-1] = '\0';
/* Set process state. */
arch_proc_init(rp, (u32_t) m_ptr->PR_IP_PTR, (u32_t) m_ptr->PR_STACK_PTR, name);
/* No reply to EXEC call */
RTS_UNSET(rp, RTS_RECEIVING);

View File

@@ -26,13 +26,11 @@ int do_fork(struct proc * caller, message * m_ptr)
{
/* Handle sys_fork(). PR_ENDPT has forked. The child is PR_SLOT. */
#if (_MINIX_CHIP == _CHIP_INTEL)
reg_t old_ldt_sel;
char *old_fpu_save_area_p;
#endif
register struct proc *rpc; /* child process pointer */
struct proc *rpp; /* parent process pointer */
struct mem_map *map_ptr; /* virtual address of map inside caller (PM) */
int gen, r;
int gen;
int p_proc;
int namelen;
@@ -51,19 +49,15 @@ int do_fork(struct proc * caller, message * m_ptr)
return EINVAL;
}
map_ptr= (struct mem_map *) m_ptr->PR_MEM_PTR;
/* make sure that the FPU context is saved in parent before copy */
save_fpu(rpp);
/* Copy parent 'proc' struct to child. And reinitialize some fields. */
gen = _ENDPOINT_G(rpc->p_endpoint);
#if (_MINIX_CHIP == _CHIP_INTEL)
old_ldt_sel = rpc->p_seg.p_ldt_sel; /* backup local descriptors */
old_fpu_save_area_p = rpc->p_seg.fpu_state;
#endif
*rpc = *rpp; /* copy 'proc' struct */
#if (_MINIX_CHIP == _CHIP_INTEL)
rpc->p_seg.p_ldt_sel = old_ldt_sel; /* restore descriptors */
rpc->p_seg.fpu_state = old_fpu_save_area_p;
if(proc_used_fpu(rpp))
memcpy(rpc->p_seg.fpu_state, rpp->p_seg.fpu_state, FPU_XFP_SIZE);
@@ -111,9 +105,6 @@ int do_fork(struct proc * caller, message * m_ptr)
m_ptr->PR_ENDPT = rpc->p_endpoint;
m_ptr->PR_FORK_MSGADDR = (char *) rpp->p_delivermsg_vir;
/* Install new map */
r = newmap(caller, rpc, map_ptr);
/* Don't schedule process in VM mode until it has a new pagetable. */
if(m_ptr->PR_FORK_FLAGS & PFF_VMINHIBIT) {
RTS_SET(rpc, RTS_VMINHIBIT);
@@ -128,7 +119,7 @@ int do_fork(struct proc * caller, message * m_ptr)
rpc->p_seg.p_cr3 = 0;
rpc->p_seg.p_cr3_v = NULL;
return r;
return OK;
}
#endif /* USE_FORK */

View File

@@ -133,8 +133,8 @@ int do_getinfo(struct proc * caller, message * m_ptr)
return OK;
}
case GET_MONPARAMS: {
src_vir = (vir_bytes) params_buffer;
length = sizeof(params_buffer);
src_vir = (vir_bytes) kinfo.param_buf;
length = sizeof(kinfo.param_buf);
break;
}
case GET_RANDOMNESS: {

View File

@@ -1,50 +0,0 @@
/* The kernel call implemented in this file:
* m_type: SYS_NEWMAP
*
* The parameters for this kernel call are:
* m1_i1: PR_ENDPT (install new map for this process)
* m1_p1: PR_MEM_PTR (pointer to the new memory map)
*/
#include "kernel/system.h"
#include <minix/endpoint.h>
#if USE_NEWMAP
/*===========================================================================*
* do_newmap *
*===========================================================================*/
int do_newmap(struct proc * caller, message * m_ptr)
{
/* Handle sys_newmap(). Fetch the memory map. */
struct proc *rp; /* process whose map is to be loaded */
struct mem_map *map_ptr; /* virtual address of map inside caller */
int proc_nr;
map_ptr = (struct mem_map *) m_ptr->PR_MEM_PTR;
if (! isokendpt(m_ptr->PR_ENDPT, &proc_nr)) return(EINVAL);
if (iskerneln(proc_nr)) return(EPERM);
rp = proc_addr(proc_nr);
return newmap(caller, rp, map_ptr);
}
/*===========================================================================*
* newmap *
*===========================================================================*/
int newmap(struct proc *caller, struct proc *rp, struct mem_map *map_ptr)
{
int r;
/* Fetch the memory map. */
if((r=data_copy(caller->p_endpoint, (vir_bytes) map_ptr,
KERNEL, (vir_bytes) rp->p_memmap, sizeof(rp->p_memmap))) != OK) {
printf("newmap: data_copy failed! (%d)\n", r);
return r;
}
alloc_segments(rp);
return(OK);
}
#endif /* USE_NEWMAP */

View File

@@ -13,6 +13,7 @@
* VSCP_VEC_SIZE number of significant elements in vector
*/
#include <assert.h>
#include <minix/type.h>
#include <minix/safecopies.h>
@@ -245,6 +246,11 @@ int access; /* CPF_READ for a copy from granter to grantee, CPF_WRITE
vir_bytes size;
#endif
if(granter == NONE || grantee == NONE) {
printf("safecopy: nonsense processes\n");
return EFAULT;
}
/* See if there is a reasonable grant table. */
if(!(granter_p = endpoint_lookup(granter))) return EINVAL;
if(!HASGRANTTABLE(granter_p)) {
@@ -277,8 +283,6 @@ int access; /* CPF_READ for a copy from granter to grantee, CPF_WRITE
granter = new_granter;
/* Now it's a regular copy. */
v_src.segment = D;
v_dst.segment = D;
v_src.proc_nr_e = *src;
v_dst.proc_nr_e = *dst;
@@ -373,8 +377,8 @@ int do_vsafecopy(struct proc * caller, message * m_ptr)
/* Set vector copy parameters. */
src.proc_nr_e = caller->p_endpoint;
assert(src.proc_nr_e != NONE);
src.offset = (vir_bytes) m_ptr->VSCP_VEC_ADDR;
src.segment = dst.segment = D;
dst.proc_nr_e = KERNEL;
dst.offset = (vir_bytes) vec;

View File

@@ -120,21 +120,12 @@ int map_invoke_vm(struct proc * caller,
size_t size, int flag)
{
struct proc *src, *dst;
phys_bytes lin_src, lin_dst;
src = endpoint_lookup(end_s);
dst = endpoint_lookup(end_d);
lin_src = umap_local(src, D, off_s, size);
lin_dst = umap_local(dst, D, off_d, size);
if(lin_src == 0 || lin_dst == 0) {
printf("map_invoke_vm: error in umap_local.\n");
return EINVAL;
}
/* Make sure the linear addresses are both page aligned. */
if(lin_src % CLICK_SIZE != 0
|| lin_dst % CLICK_SIZE != 0) {
if(off_s % CLICK_SIZE != 0 || off_d % CLICK_SIZE != 0) {
printf("map_invoke_vm: linear addresses not page aligned.\n");
return EINVAL;
}
@@ -149,9 +140,9 @@ int map_invoke_vm(struct proc * caller,
/* Map to the destination. */
caller->p_vmrequest.req_type = req_type;
caller->p_vmrequest.target = end_d; /* destination proc */
caller->p_vmrequest.params.map.vir_d = lin_dst; /* destination addr */
caller->p_vmrequest.params.map.vir_d = off_d; /* destination addr */
caller->p_vmrequest.params.map.ep_s = end_s; /* source process */
caller->p_vmrequest.params.map.vir_s = lin_src; /* source address */
caller->p_vmrequest.params.map.vir_s = off_s; /* source address */
caller->p_vmrequest.params.map.length = (vir_bytes) size;
caller->p_vmrequest.params.map.writeflag = flag;

View File

@@ -51,15 +51,13 @@ int do_trace(struct proc * caller, message * m_ptr)
unsigned char ub;
int i;
#define COPYTOPROC(seg, addr, myaddr, length) { \
#define COPYTOPROC(addr, myaddr, length) { \
struct vir_addr fromaddr, toaddr; \
int r; \
fromaddr.proc_nr_e = KERNEL; \
toaddr.proc_nr_e = tr_proc_nr_e; \
fromaddr.offset = (myaddr); \
toaddr.offset = (addr); \
fromaddr.segment = D; \
toaddr.segment = (seg); \
if((r=virtual_copy_vmcheck(caller, &fromaddr, \
&toaddr, length)) != OK) { \
printf("Can't copy in sys_trace: %d\n", r);\
@@ -67,15 +65,13 @@ int do_trace(struct proc * caller, message * m_ptr)
} \
}
#define COPYFROMPROC(seg, addr, myaddr, length) { \
#define COPYFROMPROC(addr, myaddr, length) { \
struct vir_addr fromaddr, toaddr; \
int r; \
fromaddr.proc_nr_e = tr_proc_nr_e; \
toaddr.proc_nr_e = KERNEL; \
fromaddr.offset = (addr); \
toaddr.offset = (myaddr); \
fromaddr.segment = (seg); \
toaddr.segment = D; \
if((r=virtual_copy_vmcheck(caller, &fromaddr, \
&toaddr, length)) != OK) { \
printf("Can't copy in sys_trace: %d\n", r);\
@@ -96,12 +92,12 @@ int do_trace(struct proc * caller, message * m_ptr)
return(OK);
case T_GETINS: /* return value from instruction space */
COPYFROMPROC(T, tr_addr, (vir_bytes) &tr_data, sizeof(long));
COPYFROMPROC(tr_addr, (vir_bytes) &tr_data, sizeof(long));
m_ptr->CTL_DATA = tr_data;
break;
case T_GETDATA: /* return value from data space */
COPYFROMPROC(D, tr_addr, (vir_bytes) &tr_data, sizeof(long));
COPYFROMPROC(tr_addr, (vir_bytes) &tr_data, sizeof(long));
m_ptr->CTL_DATA= tr_data;
break;
@@ -125,12 +121,12 @@ int do_trace(struct proc * caller, message * m_ptr)
break;
case T_SETINS: /* set value in instruction space */
COPYTOPROC(T, tr_addr, (vir_bytes) &tr_data, sizeof(long));
COPYTOPROC(tr_addr, (vir_bytes) &tr_data, sizeof(long));
m_ptr->CTL_DATA = 0;
break;
case T_SETDATA: /* set value in data space */
COPYTOPROC(D, tr_addr, (vir_bytes) &tr_data, sizeof(long));
COPYTOPROC(tr_addr, (vir_bytes) &tr_data, sizeof(long));
m_ptr->CTL_DATA = 0;
break;
@@ -184,13 +180,13 @@ int do_trace(struct proc * caller, message * m_ptr)
break;
case T_READB_INS: /* get value from instruction space */
COPYFROMPROC(T, tr_addr, (vir_bytes) &ub, 1);
COPYFROMPROC(tr_addr, (vir_bytes) &ub, 1);
m_ptr->CTL_DATA = ub;
break;
case T_WRITEB_INS: /* set value in instruction space */
ub = (unsigned char) (tr_data & 0xff);
COPYTOPROC(T, tr_addr, (vir_bytes) &ub, 1);
COPYTOPROC(tr_addr, (vir_bytes) &ub, 1);
m_ptr->CTL_DATA = 0;
break;

View File

@@ -33,7 +33,6 @@ int do_umap_remote(struct proc * caller, message * m_ptr)
int endpt = (int) m_ptr->CP_SRC_ENDPT;
endpoint_t grantee = (endpoint_t) m_ptr->CP_DST_ENDPT;
int proc_nr, proc_nr_grantee;
int naughty = 0;
phys_bytes phys_addr = 0, lin_addr = 0;
struct proc *targetpr;
@@ -57,11 +56,6 @@ int do_umap_remote(struct proc * caller, message * m_ptr)
/* See which mapping should be made. */
switch(seg_type) {
case LOCAL_SEG:
phys_addr = lin_addr = umap_local(targetpr, seg_index, offset, count);
if(!lin_addr) return EFAULT;
naughty = 1;
break;
case LOCAL_VM_SEG:
if(seg_index == MEM_GRANT) {
vir_bytes newoffset;
@@ -84,11 +78,11 @@ int do_umap_remote(struct proc * caller, message * m_ptr)
/* New lookup. */
offset = newoffset;
targetpr = proc_addr(new_proc_nr);
seg_index = D;
seg_index = VIR_ADDR;
}
if(seg_index == T || seg_index == D || seg_index == S) {
phys_addr = lin_addr = umap_local(targetpr, seg_index, offset, count);
if(seg_index == VIR_ADDR) {
phys_addr = lin_addr = offset;
} else {
printf("SYSTEM: bogus seg type 0x%lx\n", seg_index);
return EFAULT;
@@ -115,7 +109,7 @@ int do_umap_remote(struct proc * caller, message * m_ptr)
}
m_ptr->CP_DST_ADDR = phys_addr;
if(naughty || phys_addr == 0) {
if(phys_addr == 0) {
printf("kernel: umap 0x%x done by %d / %s, pc 0x%lx, 0x%lx -> 0x%lx\n",
seg_type, caller->p_endpoint, caller->p_name,
caller->p_reg.pc, offset, phys_addr);

View File

@@ -111,11 +111,6 @@ int do_update(struct proc * caller, message * m_ptr)
/* Swap global process slot addresses. */
swap_proc_slot_pointer(get_cpulocal_var_ptr(ptproc), src_rp, dst_rp);
/* Fix segments. */
alloc_segments(src_rp);
alloc_segments(dst_rp);
prot_init();
#if DEBUG
printf("do_update: updated %d (%s, %d, %d) into %d (%s, %d, %d)\n",
src_rp->p_endpoint, src_rp->p_name, src_rp->p_nr, priv(src_rp)->s_proc_nr,

View File

@@ -120,13 +120,6 @@ int do_vmctl(struct proc * caller, message * m_ptr)
RTS_UNSET(p, RTS_VMREQUEST);
return OK;
case VMCTL_ENABLE_PAGING:
if(vm_running)
panic("do_vmctl: paging already enabled");
if (arch_enable_paging(caller, m_ptr) != OK)
panic("do_vmctl: paging enabling failed");
return OK;
case VMCTL_KERN_PHYSMAP:
{
int i = m_ptr->SVMCTL_VALUE;
@@ -177,6 +170,10 @@ int do_vmctl(struct proc * caller, message * m_ptr)
bits_fill(p->p_stale_tlb, CONFIG_MAX_CPUS);
#endif
return OK;
case VMCTL_CLEARMAPCACHE:
/* VM says: forget about old mappings we have cached. */
mem_clear_mapcache();
return OK;
}
/* Try architecture-specific vmctls. */

View File

@@ -29,7 +29,7 @@ int do_vumap(struct proc *caller, message *m_ptr)
struct proc *procp;
struct vumap_vir vvec[MAPVEC_NR];
struct vumap_phys pvec[MAPVEC_NR];
vir_bytes vaddr, paddr, vir_addr, lin_addr;
vir_bytes vaddr, paddr, vir_addr;
phys_bytes phys_addr;
int i, r, proc_nr, vcount, pcount, pmax, access;
size_t size, chunk, offset;
@@ -89,13 +89,9 @@ int do_vumap(struct proc *caller, message *m_ptr)
okendpt(granter, &proc_nr);
procp = proc_addr(proc_nr);
lin_addr = umap_local(procp, D, vir_addr, size);
if (!lin_addr)
return EFAULT;
/* Each virtual range is made up of one or more physical ranges. */
while (size > 0 && pcount < pmax) {
chunk = vm_lookup_range(procp, lin_addr, &phys_addr, size);
chunk = vm_lookup_range(procp, vir_addr, &phys_addr, size);
if (!chunk) {
/* Try to get the memory allocated, unless the memory
@@ -107,14 +103,14 @@ int do_vumap(struct proc *caller, message *m_ptr)
/* This call may suspend the current call, or return an
* error for a previous invocation.
*/
return vm_check_range(caller, procp, lin_addr, size);
return vm_check_range(caller, procp, vir_addr, size);
}
pvec[pcount].vp_addr = phys_addr;
pvec[pcount].vp_size = chunk;
pcount++;
lin_addr += chunk;
vir_addr += chunk;
size -= chunk;
}