Module Name:    src
Committed By:   martin
Date:           Thu Feb 27 18:23:10 UTC 2020

Modified Files:
        src/sys/arch/powerpc/ibm4xx [netbsd-9]: pmap.c

Log Message:
Pull up following revision(s) (requested by rin in ticket #731):

        sys/arch/powerpc/ibm4xx/pmap.c: revision 1.80
        sys/arch/powerpc/ibm4xx/pmap.c: revision 1.77
        sys/arch/powerpc/ibm4xx/pmap.c: revision 1.78
        sys/arch/powerpc/ibm4xx/pmap.c: revision 1.79

Fix NULL dereference; "pap" argument of pmap_extract(9) can be NULL.

 -

Fix off-by-one error for ctx (ASID).

 -

Note that NUM_CTX = 256 = 0 stands for disabling protection by ASID.
Clear ti_ctx when flushing a TLB entry for clarity.

 -

In ppc4xx_tlb_find_victim(), mark kernel stack page TLBF_REF instead of
TLBF_USED. This should be originally intended behavior of this code
segment, because
- TLBF_USED is already checked just before, so marking this page
  TLBF_USED is no-op.
- TLBF_REF flag exempts that page from being flushed from TLB in next
  scan, when kernel stack may be still there with high probability.


To generate a diff of this commit:
cvs rdiff -u -r1.76 -r1.76.20.1 src/sys/arch/powerpc/ibm4xx/pmap.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/powerpc/ibm4xx/pmap.c
diff -u src/sys/arch/powerpc/ibm4xx/pmap.c:1.76 src/sys/arch/powerpc/ibm4xx/pmap.c:1.76.20.1
--- src/sys/arch/powerpc/ibm4xx/pmap.c:1.76	Sat Dec 24 19:02:16 2016
+++ src/sys/arch/powerpc/ibm4xx/pmap.c	Thu Feb 27 18:23:10 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.76 2016/12/24 19:02:16 cherry Exp $	*/
+/*	$NetBSD: pmap.c,v 1.76.20.1 2020/02/27 18:23:10 martin Exp $	*/
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.76 2016/12/24 19:02:16 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.76.20.1 2020/02/27 18:23:10 martin Exp $");
 
 #include <sys/param.h>
 #include <sys/cpu.h>
@@ -1021,7 +1021,7 @@ pmap_extract(struct pmap *pm, vaddr_t va
 	int s;
 
 	s = splvm();
-	if (pm->pm_ptbl[seg] && (pa = pm->pm_ptbl[seg][ptn])) {
+	if (pm->pm_ptbl[seg] && (pa = pm->pm_ptbl[seg][ptn]) && pap) {
 		*pap = TTE_PA(pa) | (va & PGOFSET);
 	}
 	splx(s);
@@ -1276,7 +1276,7 @@ ppc4xx_tlb_find_victim(void)
 			    (tlb_info[tlbnext].ti_ctx == KERNEL_PID) &&
 			     (flags & TLBF_USED)) {
 				/* Kernel stack page */
-				flags |= TLBF_USED;
+				flags |= TLBF_REF;
 				tlb_info[tlbnext].ti_flags = flags;
 			} else {
 				/* Found it! */
@@ -1535,6 +1535,7 @@ ctx_flush(int cnum)
 #endif
 			/* Invalidate particular TLB entry regardless of locked status */
 			__asm volatile("tlbwe %0,%1,0" : :"r"(0),"r"(i));
+			tlb_info[i].ti_ctx = 0;
 			tlb_info[i].ti_flags = 0;
 		}
 	}
@@ -1563,7 +1564,7 @@ ctx_alloc(struct pmap *pm)
 	/* Find a likely context. */
 	cnum = next;
 	do {
-		if ((++cnum) > NUMCTX)
+		if ((++cnum) >= NUMCTX)
 			cnum = MINCTX;
 	} while (ctxbusy[cnum] != NULL && cnum != next);
 
@@ -1573,7 +1574,7 @@ oops:
 		cnum = MINCTX; /* Never steal ctx 0 or 1 */
 	if (ctx_flush(cnum)) {
 		/* oops -- something's wired. */
-		if ((++cnum) > NUMCTX)
+		if ((++cnum) >= NUMCTX)
 			cnum = MINCTX;
 		goto oops;
 	}

Reply via email to