Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/usermode Fix /dev/kmem access and make vmstat(1) `w...



details:   https://anonhg.NetBSD.org/src/rev/97118a747d2b
branches:  trunk
changeset: 773598:97118a747d2b
user:      reinoud <reinoud%NetBSD.org@localhost>
date:      Wed Feb 08 17:55:21 2012 +0000

description:
Fix /dev/kmem access and make vmstat(1) `work'. Not sure all the results are
indeed valid or correct but at least it shows them without coredumping or
coredumping the kernel.

diffstat:

 sys/arch/usermode/include/cpu.h      |   6 +++---
 sys/arch/usermode/include/types.h    |   5 ++++-
 sys/arch/usermode/include/vmparam.h  |   3 ++-
 sys/arch/usermode/usermode/machdep.c |  29 ++++++++++++++++++++++++++---
 4 files changed, 35 insertions(+), 8 deletions(-)

diffs (114 lines):

diff -r 40c2b49716e5 -r 97118a747d2b sys/arch/usermode/include/cpu.h
--- a/sys/arch/usermode/include/cpu.h   Wed Feb 08 16:52:39 2012 +0000
+++ b/sys/arch/usermode/include/cpu.h   Wed Feb 08 17:55:21 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.h,v 1.9 2012/01/19 12:14:49 reinoud Exp $ */
+/* $NetBSD: cpu.h,v 1.10 2012/02/08 17:55:21 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -50,10 +50,10 @@
 
 
 struct cpu_info {
-       device_t        ci_dev;
+       struct cpu_data ci_data;                /* MI per-cpu data */
+       device_t        ci_dev;                 /* pointer to our device */
        struct cpu_info *ci_self;
        struct cpu_info *ci_next;
-       struct cpu_data ci_data;
        u_int           ci_cpuid;
        int             ci_want_resched;
        int             ci_idepth;
diff -r 40c2b49716e5 -r 97118a747d2b sys/arch/usermode/include/types.h
--- a/sys/arch/usermode/include/types.h Wed Feb 08 16:52:39 2012 +0000
+++ b/sys/arch/usermode/include/types.h Wed Feb 08 17:55:21 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: types.h,v 1.7 2012/01/08 18:06:00 jmcneill Exp $ */
+/* $NetBSD: types.h,v 1.8 2012/02/08 17:55:21 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -62,4 +62,7 @@
 #define __HAVE_OLD_DISKLABEL
 #endif
 
+#define __HAVE_CPU_DATA_FIRST
+#define __HAVE_MM_MD_KERNACC
+
 #endif /* !_ARCH_USERMODE_INCLUDE_TYPES_H */
diff -r 40c2b49716e5 -r 97118a747d2b sys/arch/usermode/include/vmparam.h
--- a/sys/arch/usermode/include/vmparam.h       Wed Feb 08 16:52:39 2012 +0000
+++ b/sys/arch/usermode/include/vmparam.h       Wed Feb 08 17:55:21 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: vmparam.h,v 1.15 2012/01/10 10:19:38 reinoud Exp $ */
+/* $NetBSD: vmparam.h,v 1.16 2012/02/08 17:55:21 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -36,6 +36,7 @@
 
 extern paddr_t kmem_k_start, kmem_k_end;
 extern paddr_t kmem_kvm_start, kmem_kvm_end;
+extern paddr_t kmem_kvm_cur_end;
 extern paddr_t kmem_user_start, kmem_user_end;
 
 #define VM_MIN_ADDRESS         kmem_user_start
diff -r 40c2b49716e5 -r 97118a747d2b sys/arch/usermode/usermode/machdep.c
--- a/sys/arch/usermode/usermode/machdep.c      Wed Feb 08 16:52:39 2012 +0000
+++ b/sys/arch/usermode/usermode/machdep.c      Wed Feb 08 17:55:21 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: machdep.c,v 1.52 2012/01/15 10:30:21 jmcneill Exp $ */
+/* $NetBSD: machdep.c,v 1.53 2012/02/08 17:55:21 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Reinoud Zandijk <reinoud%netbsd.org@localhost>
@@ -37,7 +37,7 @@
 #include "opt_memsize.h"
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.52 2012/01/15 10:30:21 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.53 2012/02/08 17:55:21 reinoud Exp $");
 
 #include <sys/types.h>
 #include <sys/systm.h>
@@ -55,6 +55,7 @@
 #include <uvm/uvm_page.h>
 
 #include <dev/mm.h>
+#include <machine/vmparam.h>
 #include <machine/machdep.h>
 #include <machine/thunk.h>
 
@@ -249,8 +250,30 @@
 }
 
 int
-mm_md_physacc(paddr_t pa, vm_prot_t prog)
+mm_md_physacc(paddr_t pa, vm_prot_t prot)
 {
+       // printf("%s: pa = %p, acc %d\n", __func__, (void *) pa, prot);
+       if (pa >= physmem * PAGE_SIZE)
+               return EFAULT;
        return 0;
 }
 
+
+int
+mm_md_kernacc(void *ptr, vm_prot_t prot, bool *handled)
+{
+       const vaddr_t va = (vaddr_t)ptr;
+       extern void *end;
+
+       // printf("%s: ptr %p, acc %d\n", __func__, ptr, prot);
+       if (va < kmem_kvm_start)
+               return EFAULT;
+       if ((va >= kmem_kvm_cur_end) && (va < kmem_k_start))
+               return EFAULT;
+       if (va > (vaddr_t) end)
+               return EFAULT;
+
+       *handled = true;
+       return 0;
+}
+



Home | Main Index | Thread Index | Old Index