diff options
author | cinap_lenrek <cinap_lenrek@felloff.net> | 2015-04-16 00:45:25 +0200 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@felloff.net> | 2015-04-16 00:45:25 +0200 |
commit | 46070c3122227f5fc04c9b7a29d0652600fa7074 (patch) | |
tree | 82d1d3e022e7fe96baa7834f8a7718c818f39353 /sys/src/9/port/fault.c | |
parent | 88d7d8428a6cb10b421d5ff900617dad3c290fd1 (diff) |
kernel: add segio() function for reading/writing segments
devproc's procctlmemio() did not handle physical segment
types correctly, as it assumed it can just kmap() the page
in question and write to it. physical segments however
need to be mapped uncached but kmap() will always map
cached as it assumes normal memory. on some machines with
aliasing memory with different cache attributes
leads to undefined behaviour!
we borrow the code from devsegment and provide a generic
segio() function to read and write user segments which
handles all the cases without using kmap by just spawning
a kproc that attaches the segment that needs to be read
from or written to. fault() will setup the right mmu
attributes for us. it will also properly flush pages for
segments that maintain instruction cache when written.
however, tlb's have to be flushed separately.
segio() is used for devsegment and devproc now, which
also allows for simplification of fixfault() as there is no
special error handling case anymore as fixfault() is now
called from faulting process *only*.
reads from /proc/$pid/mem can now span multiple pages.
Diffstat (limited to 'sys/src/9/port/fault.c')
-rw-r--r-- | sys/src/9/port/fault.c | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/sys/src/9/port/fault.c b/sys/src/9/port/fault.c index 966c2992d..123ae4e80 100644 --- a/sys/src/9/port/fault.c +++ b/sys/src/9/port/fault.c @@ -40,7 +40,7 @@ fault(uintptr addr, int read) return -1; } - if(fixfault(s, addr, read, 1) == 0) + if(fixfault(s, addr, read) == 0) break; splhi(); @@ -58,7 +58,7 @@ fault(uintptr addr, int read) } static void -faulterror(char *s, Chan *c, int isfatal) +faulterror(char *s, Chan *c) { char buf[ERRMAX]; @@ -67,15 +67,14 @@ faulterror(char *s, Chan *c, int isfatal) s = buf; } if(up->nerrlab) { - if(isfatal) - postnote(up, 1, s, NDebug); + postnote(up, 1, s, NDebug); error(s); } pexit(s, 1); } static void -pio(Segment *s, uintptr addr, uintptr soff, Page **p, int isfatal) +pio(Segment *s, uintptr addr, uintptr soff, Page **p) { Page *new; KMap *k; @@ -120,11 +119,11 @@ retry: k = kmap(new); kaddr = (char*)VA(k); while(waserror()) { - if(isfatal && strcmp(up->errstr, Eintr) == 0) + if(strcmp(up->errstr, Eintr) == 0) continue; kunmap(k); putpage(new); - faulterror(Eioload, c, isfatal); + faulterror(Eioload, c); } n = devtab[c->type]->read(c, kaddr, ask, daddr); if(n != ask) @@ -194,7 +193,7 @@ void (*checkaddr)(uintptr, Segment *, Page *); uintptr addr2check; int -fixfault(Segment *s, uintptr addr, int read, int doputmmu) +fixfault(Segment *s, uintptr addr, int read) { int type; Pte **pte, *etp; @@ -222,7 +221,7 @@ fixfault(Segment *s, uintptr addr, int read, int doputmmu) case SG_TEXT: /* Demand load */ if(pagedout(*pg)) - pio(s, addr, soff, pg, doputmmu); + pio(s, addr, soff, pg); mmuphys = PPN((*pg)->pa) | PTERONLY|PTEVALID; (*pg)->modref = PG_REF; @@ -242,7 +241,7 @@ fixfault(Segment *s, uintptr addr, int read, int doputmmu) case SG_DATA: common: /* Demand load/pagein/copy on write */ if(pagedout(*pg)) - pio(s, addr, soff, pg, doputmmu); + pio(s, addr, soff, pg); /* * It's only possible to copy on write if @@ -288,8 +287,7 @@ fixfault(Segment *s, uintptr addr, int read, int doputmmu) } qunlock(s); - if(doputmmu) - putmmu(addr, mmuphys, *pg); + putmmu(addr, mmuphys, *pg); return 0; } |