shithub: riscv

Download patch

ref: dbfec06bf1f8de922ca3af09d14675ef44ada5d2
parent: 0099db7b5b87adb72f1dfa69f893c41ab1c26d6e
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sun May 10 12:54:42 EDT 2020

kernel: fix checkpages() and segflush() on SG_PHYSICAL type segments

do not touch s->map on SG_PHYSICAL type segments as they do
not have a pte map (s->mapsize == 0 && s->map == nil).

also remove the SG_PHYSICAL switch in freepte(), this is never
reached.

--- a/sys/src/9/port/fault.c
+++ b/sys/src/9/port/fault.c
@@ -438,14 +438,16 @@
 		if((s = *sp) == nil)
 			continue;
 		qlock(s);
-		for(addr=s->base; addr<s->top; addr+=BY2PG){
-			off = addr - s->base;
-			if((p = s->map[off/PTEMAPMEM]) == nil)
-				continue;
-			pg = p->pages[(off&(PTEMAPMEM-1))/BY2PG];
-			if(pagedout(pg))
-				continue;
-			checkmmu(addr, pg->pa);
+		if(s->mapsize > 0){
+			for(addr=s->base; addr<s->top; addr+=BY2PG){
+				off = addr - s->base;
+				if((p = s->map[off/PTEMAPMEM]) == nil)
+					continue;
+				pg = p->pages[(off&(PTEMAPMEM-1))/BY2PG];
+				if(pagedout(pg))
+					continue;
+				checkmmu(addr, pg->pa);
+			}
 		}
 		qunlock(s);
 	}
--- a/sys/src/9/port/page.c
+++ b/sys/src/9/port/page.c
@@ -377,21 +377,10 @@
 
 	pg = p->first;
 	pe = p->last;
-
-	switch(s->type&SG_TYPE) {
-	case SG_PHYSICAL:
-		while(pg <= pe){
-			if(*pg != nil && decref(*pg) == 0)
-				free(*pg);
-			pg++;
-		}
-		break;
-	default:
-		while(pg <= pe){
-			if(*pg != nil)
-				putpage(*pg);
-			pg++;
-		}
+	while(pg <= pe){
+		if(*pg != nil)
+			putpage(*pg);
+		pg++;
 	}
 	free(p);
 }
--- a/sys/src/9/port/segment.c
+++ b/sys/src/9/port/segment.c
@@ -64,8 +64,11 @@
 	s->sema.prev = &s->sema;
 	s->sema.next = &s->sema;
 
-	if((type & SG_TYPE) == SG_PHYSICAL)
+	if((type & SG_TYPE) == SG_PHYSICAL){
+		s->map = nil;
+		s->mapsize = 0;
 		return s;
+	}
 
 	mapsize = ROUND(size, PTEPERTAB)/PTEPERTAB;
 	if(mapsize > nelem(s->ssegmap)){
@@ -477,9 +480,6 @@
 	Page **pg, **pe;
 	ulong pages;
 
-	if((s->type&SG_TYPE) == SG_PHYSICAL)
-		return 0;
-
 	pages = 0;
 	emap = &s->map[s->mapsize];
 	for(pte = s->map; pte < emap; pte++){
@@ -706,26 +706,25 @@
 		s->flushme = 1;
 	more:
 		len = (s->top < to ? s->top : to) - from;
-		off = from-s->base;
-		pte = s->map[off/PTEMAPMEM];
-		off &= PTEMAPMEM-1;
-		if(off+len > PTEMAPMEM)
-			len = PTEMAPMEM-off;
-
-		if(pte != nil) {
-			pg = &pte->pages[off/BY2PG];
-			pe = pg + len/BY2PG;
-			while(pg < pe) {
-				if(!pagedout(*pg))
-					(*pg)->txtflush = ~0;
-				pg++;
+		if(s->mapsize > 0){
+			off = from-s->base;
+			pte = s->map[off/PTEMAPMEM];
+			off &= PTEMAPMEM-1;
+			if(off+len > PTEMAPMEM)
+				len = PTEMAPMEM-off;
+			if(pte != nil) {
+				pg = &pte->pages[off/BY2PG];
+				pe = pg + len/BY2PG;
+				while(pg < pe) {
+					if(!pagedout(*pg))
+						(*pg)->txtflush = ~0;
+					pg++;
+				}
 			}
 		}
-
 		from += len;
 		if(from < to && from < s->top)
 			goto more;
-
 		qunlock(s);
 	}
 }
--- a/sys/src/9/port/userinit.c
+++ b/sys/src/9/port/userinit.c
@@ -54,7 +54,7 @@
 	kunmap(k);
 	p->txtflush = ~0;
 	segpage(up->seg[TSEG], p);
-	up->seg[TSEG]->flushme++;
+	up->seg[TSEG]->flushme = 1;
 
 	/*
 	 * Become a user process.