ref: 1a782fda3e0fcc3205dc4b2a9b6ef3a75f68efb7
parent: 78d2a52577c39f5f580b925931aa1ffbdc3d16be
author: cinap_lenrek <[email protected]>
date: Wed Nov 16 20:28:11 EST 2016
pc64: check if vmap() range fits in VMAPLEN window, remove unneeded vmapsync(), rename fault386() to faultamd64()
--- a/sys/src/9/pc64/fns.h
+++ b/sys/src/9/pc64/fns.h
@@ -180,7 +180,6 @@
void upareserve(uintptr, int);
void vectortable(void);
void* vmap(uintptr, int);
-int vmapsync(uintptr);
void vunmap(void*, int);
void wbinvd(void);
int wrmsr(int, vlong);
--- a/sys/src/9/pc64/mmu.c
+++ b/sys/src/9/pc64/mmu.c
@@ -506,6 +506,9 @@
/*
* Add a device mapping to the vmap range.
+ * note that the VMAP and KZERO PDPs are shared
+ * between processors (see mpstartap) so no
+ * synchronization is being done.
*/
void*
vmap(uintptr pa, int size)
@@ -513,6 +516,8 @@
uintptr va;
int o;
+ if(pa+size > VMAPSIZE)
+ return 0;
va = pa+VMAP;
/*
* might be asking for less than a page.
@@ -529,31 +534,4 @@
vunmap(void *v, int)
{
paddr(v); /* will panic on error */
-}
-
-/*
- * vmapsync() is currently unused as the VMAP and KZERO PDPs
- * are shared between processors. (see mpstartap)
- */
-int
-vmapsync(uintptr va)
-{
- uintptr *pte1, *pte2;
- int level;
-
- if(va < VMAP || m->machno == 0)
- return 0;
-
- for(level=0; level<2; level++){
- pte1 = mmuwalk(MACHP(0)->pml4, va, level, 0);
- if(pte1 && *pte1 & PTEVALID){
- pte2 = mmuwalk(m->pml4, va, level, 1);
- if(pte2 == 0)
- break;
- if(pte1 != pte2)
- *pte2 = *pte1;
- return 1;
- }
- }
- return 0;
}
--- a/sys/src/9/pc64/trap.c
+++ b/sys/src/9/pc64/trap.c
@@ -14,7 +14,7 @@
void noted(Ureg*, ulong);
static void debugbpt(Ureg*, void*);
-static void fault386(Ureg*, void*);
+static void faultamd64(Ureg*, void*);
static void doublefault(Ureg*, void*);
static void unexpected(Ureg*, void*);
static void _dumpstack(Ureg*);
@@ -225,7 +225,7 @@
* Syscall() is called directly without going through trap().
*/
trapenable(VectorBPT, debugbpt, 0, "debugpt");
- trapenable(VectorPF, fault386, 0, "fault386");
+ trapenable(VectorPF, faultamd64, 0, "faultamd64");
trapenable(Vector2F, doublefault, 0, "doublefault");
trapenable(Vector15, unexpected, 0, "unexpected");
nmienable();
@@ -315,9 +315,9 @@
Mach *mach;
if(!trapinited){
- /* fault386 can give a better error message */
+ /* faultamd64 can give a better error message */
if(ureg->type == VectorPF)
- fault386(ureg, nil);
+ faultamd64(ureg, nil);
panic("trap %llud: not ready", ureg->type);
}
@@ -614,7 +614,7 @@
extern void checkpages(void);
static void
-fault386(Ureg* ureg, void*)
+faultamd64(Ureg* ureg, void*)
{
uintptr addr;
int read, user, n, insyscall;
@@ -624,8 +624,6 @@
read = !(ureg->error & 2);
user = userureg(ureg);
if(!user){
- if(vmapsync(addr))
- return;
if(addr >= USTKTOP)
panic("kernel fault: bad address pc=%#p addr=%#p", ureg->pc, addr);
if(up == nil)