Module Name:    src
Committed By:   simonb
Date:           Sun Jun 28 13:33:06 UTC 2020

Modified Files:
        src/sys/arch/mips/mips: mips_machdep.c

Log Message:
Fix mm_md_kernacc() for 64 bit kernels (including n32):
 - FAULT for any physical address less than start of cached XKPHY address.
 - Pass any remaining physical address less then end of RAM.
 - Pass any remaining physical address within the KEGS0 kernel address range.
Ignore all remaining addresses and fall back to uvm_kernacc() for checking
virtual address ranges.

Fixes pmap(1) (and probably other kmem grovellers).


To generate a diff of this commit:
cvs rdiff -u -r1.293 -r1.294 src/sys/arch/mips/mips/mips_machdep.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/mips/mips/mips_machdep.c
diff -u src/sys/arch/mips/mips/mips_machdep.c:1.293 src/sys/arch/mips/mips/mips_machdep.c:1.294
--- src/sys/arch/mips/mips/mips_machdep.c:1.293	Mon Jun 15 07:55:45 2020
+++ src/sys/arch/mips/mips/mips_machdep.c	Sun Jun 28 13:33:06 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: mips_machdep.c,v 1.293 2020/06/15 07:55:45 simonb Exp $	*/
+/*	$NetBSD: mips_machdep.c,v 1.294 2020/06/28 13:33:06 simonb Exp $	*/
 
 /*
  * Copyright 2002 Wasabi Systems, Inc.
@@ -111,7 +111,7 @@
  */
 
 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
-__KERNEL_RCSID(0, "$NetBSD: mips_machdep.c,v 1.293 2020/06/15 07:55:45 simonb Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mips_machdep.c,v 1.294 2020/06/28 13:33:06 simonb Exp $");
 
 #define __INTR_PRIVATE
 #include "opt_cputype.h"
@@ -2481,21 +2481,28 @@ mm_md_kernacc(void *ptr, vm_prot_t prot,
 	const vaddr_t v = (vaddr_t)ptr;
 
 #ifdef _LP64
-	if (v < MIPS_XKPHYS_START) {
+	extern char end[];
+
+	/* For any address < XKPHYS cached address 0, fault */
+	if (v < MIPS_PHYS_TO_XKPHYS_CACHED(0)) {
 		return EFAULT;
 	}
-	if (MIPS_XKPHYS_P(v) && v > MIPS_PHYS_TO_XKPHYS_CACHED(pmap_limits.avail_end +
+
+	/* If address < XKPHY(end of message buffer), good! */
+	if (v < MIPS_PHYS_TO_XKPHYS_CACHED(pmap_limits.avail_end +
 	    mips_round_page(MSGBUFSIZE))) {
-		return EFAULT;
-	}
-	if (MIPS_KSEG0_P(v) ||
-	    (MIPS_XKSEG_P(v) && v < MIPS_KSEG0_START)) {
+		/* XXX holes in RAM (eg, EdgeRouter 4) */
 		*handled = true;
 		return 0;
 	}
-	if (MIPS_KSEG1_P(v) || MIPS_KSEG2_P(v)) {
-		return EFAULT;
+
+	/* If address in KSEG0 and is before end of kernel, good! */
+	if (MIPS_KSEG0_P(v) && v < (vaddr_t)end) {
+		*handled = true;
+		return 0;
 	}
+
+	/* Otherwise, fall back to the uvm_kernacc() check. */
 #else
 	if (v < MIPS_KSEG0_START) {
 		return EFAULT;

Reply via email to