Source-Changes-HG archive

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

[src/trunk]: src/sys add experimental new function uvm_direct_pr...



details:   https://anonhg.NetBSD.org/src/rev/6f5e4dcfe2b8
branches:  trunk
changeset: 319169:6f5e4dcfe2b8
user:      jdolecek <jdolecek%NetBSD.org@localhost>
date:      Sat May 19 15:03:26 2018 +0000

description:
add experimental new function uvm_direct_process(), to allow of read/writes
of contents of uvm pages without mapping them into kernel, using
direct map or moral equivalent; pmaps supporting the interface need
to provide pmap_direct_process() and define PMAP_DIRECT

implement the new interface for amd64; I hear alpha and mips might be relatively
easy to add too, but I lack the knowledge

part of resolution for PR kern/53124

diffstat:

 sys/arch/amd64/include/pmap.h |  16 +++++++++++++-
 sys/uvm/uvm_page.c            |  49 +++++++++++++++++++++++++++++++++++++++++-
 sys/uvm/uvm_page.h            |   7 +++++-
 sys/uvm/uvm_pmap.h            |   9 +++++++-
 4 files changed, 76 insertions(+), 5 deletions(-)

diffs (144 lines):

diff -r 8789b0d9bfde -r 6f5e4dcfe2b8 sys/arch/amd64/include/pmap.h
--- a/sys/arch/amd64/include/pmap.h     Sat May 19 14:15:39 2018 +0000
+++ b/sys/arch/amd64/include/pmap.h     Sat May 19 15:03:26 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pmap.h,v 1.45 2018/02/22 13:27:18 maxv Exp $   */
+/*     $NetBSD: pmap.h,v 1.46 2018/05/19 15:03:26 jdolecek Exp $       */
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -318,6 +318,20 @@
 }
 #endif
 
+#ifdef __HAVE_DIRECT_MAP
+#define PMAP_DIRECT
+
+static __inline int
+pmap_direct_process(paddr_t pa, voff_t pgoff, size_t len,
+    int (*process)(void *, size_t, void *), void *arg)
+{
+       vaddr_t va = PMAP_DIRECT_MAP(pa);
+
+       return process((void *)(va + pgoff), len, arg);
+}
+
+#endif /* __HAVE_DIRECT_MAP */
+
 void pmap_changeprot_local(vaddr_t, vm_prot_t);
 
 #include <x86/pmap_pv.h>
diff -r 8789b0d9bfde -r 6f5e4dcfe2b8 sys/uvm/uvm_page.c
--- a/sys/uvm/uvm_page.c        Sat May 19 14:15:39 2018 +0000
+++ b/sys/uvm/uvm_page.c        Sat May 19 15:03:26 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uvm_page.c,v 1.197 2018/05/19 11:02:33 jdolecek Exp $  */
+/*     $NetBSD: uvm_page.c,v 1.198 2018/05/19 15:03:26 jdolecek Exp $  */
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -66,7 +66,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uvm_page.c,v 1.197 2018/05/19 11:02:33 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_page.c,v 1.198 2018/05/19 15:03:26 jdolecek Exp $");
 
 #include "opt_ddb.h"
 #include "opt_uvm.h"
@@ -1758,6 +1758,51 @@
        return true;
 }
 
+#ifdef PMAP_DIRECT
+/*
+ * Call pmap to translate physical address into a virtual and to run a callback
+ * for it. Used to avoid actually mapping the pages, pmap most likely uses direct map
+ * or equivalent.
+ */
+int
+uvm_direct_process(struct vm_page **pgs, u_int npages, voff_t off, vsize_t len,
+            int (*process)(void *, size_t, void *), void *arg)
+{
+       int error = 0;
+       paddr_t pa;
+       size_t todo;
+       voff_t pgoff = (off & PAGE_MASK);
+       struct vm_page *pg;
+
+       KASSERT(npages > 0 && len > 0);
+
+       for (int i = 0; i < npages; i++) {
+               pg = pgs[i];
+
+               KASSERT(len > 0);
+
+               /*
+                * Caller is responsible for ensuring all the pages are
+                * available.
+                */
+               KASSERT(pg != NULL && pg != PGO_DONTCARE);
+
+               pa = VM_PAGE_TO_PHYS(pg);
+               todo = MIN(len, PAGE_SIZE - pgoff);
+
+               error = pmap_direct_process(pa, pgoff, todo, process, arg);
+               if (error)
+                       break;
+
+               pgoff = 0;
+               len -= todo;
+       }
+
+       KASSERTMSG(error != 0 || len == 0, "len %lu != 0 for non-error", len);
+       return error;
+}
+#endif /* PMAP_DIRECT */
+
 #if defined(DDB) || defined(DEBUGPRINT)
 
 /*
diff -r 8789b0d9bfde -r 6f5e4dcfe2b8 sys/uvm/uvm_page.h
--- a/sys/uvm/uvm_page.h        Sat May 19 14:15:39 2018 +0000
+++ b/sys/uvm/uvm_page.h        Sat May 19 15:03:26 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uvm_page.h,v 1.82 2017/11/14 06:43:23 mrg Exp $        */
+/*     $NetBSD: uvm_page.h,v 1.83 2018/05/19 15:03:26 jdolecek Exp $   */
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -336,6 +336,11 @@
 struct vm_page *uvm_phys_to_vm_page(paddr_t);
 paddr_t uvm_vm_page_to_phys(const struct vm_page *);
 
+#if defined(PMAP_DIRECT)
+int uvm_direct_process(struct vm_page **, u_int, voff_t, vsize_t,
+           int (*)(void *, size_t, void *), void *);
+#endif
+
 /*
  * macros
  */
diff -r 8789b0d9bfde -r 6f5e4dcfe2b8 sys/uvm/uvm_pmap.h
--- a/sys/uvm/uvm_pmap.h        Sat May 19 14:15:39 2018 +0000
+++ b/sys/uvm/uvm_pmap.h        Sat May 19 15:03:26 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uvm_pmap.h,v 1.38 2013/02/02 14:06:58 matt Exp $       */
+/*     $NetBSD: uvm_pmap.h,v 1.39 2018/05/19 15:03:26 jdolecek Exp $   */
 
 /*
  * Copyright (c) 1991, 1993
@@ -212,6 +212,13 @@
 #if defined(PMAP_FORK)
 void           pmap_fork(pmap_t, pmap_t);
 #endif
+
+#if defined(PMAP_DIRECT)
+int            pmap_direct_process(paddr_t, voff_t, size_t,
+                   int (*)(void *, size_t, void *),
+                   void *);
+#endif
+
 #endif /* kernel*/
 #endif  /* PMAP_EXCLUDE_DECLS */
 



Home | Main Index | Thread Index | Old Index