Module Name:    src
Committed By:   jdolecek
Date:           Sat May 19 15:03:26 UTC 2018

Modified Files:
        src/sys/arch/amd64/include: pmap.h
        src/sys/uvm: uvm_page.c uvm_page.h uvm_pmap.h

Log Message:
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


To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.46 src/sys/arch/amd64/include/pmap.h
cvs rdiff -u -r1.197 -r1.198 src/sys/uvm/uvm_page.c
cvs rdiff -u -r1.82 -r1.83 src/sys/uvm/uvm_page.h
cvs rdiff -u -r1.38 -r1.39 src/sys/uvm/uvm_pmap.h

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/amd64/include/pmap.h
diff -u src/sys/arch/amd64/include/pmap.h:1.45 src/sys/arch/amd64/include/pmap.h:1.46
--- src/sys/arch/amd64/include/pmap.h:1.45	Thu Feb 22 13:27:18 2018
+++ src/sys/arch/amd64/include/pmap.h	Sat May 19 15:03:26 2018
@@ -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 @@ pmap_pte_flush(void)
 }
 #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>

Index: src/sys/uvm/uvm_page.c
diff -u src/sys/uvm/uvm_page.c:1.197 src/sys/uvm/uvm_page.c:1.198
--- src/sys/uvm/uvm_page.c:1.197	Sat May 19 11:02:33 2018
+++ src/sys/uvm/uvm_page.c	Sat May 19 15:03:26 2018
@@ -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 @@ uvm_page_locked_p(struct vm_page *pg)
 	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)
 
 /*

Index: src/sys/uvm/uvm_page.h
diff -u src/sys/uvm/uvm_page.h:1.82 src/sys/uvm/uvm_page.h:1.83
--- src/sys/uvm/uvm_page.h:1.82	Tue Nov 14 06:43:23 2017
+++ src/sys/uvm/uvm_page.h	Sat May 19 15:03:26 2018
@@ -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 @@ int uvm_page_lookup_freelist(struct vm_p
 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
  */

Index: src/sys/uvm/uvm_pmap.h
diff -u src/sys/uvm/uvm_pmap.h:1.38 src/sys/uvm/uvm_pmap.h:1.39
--- src/sys/uvm/uvm_pmap.h:1.38	Sat Feb  2 14:06:58 2013
+++ src/sys/uvm/uvm_pmap.h	Sat May 19 15:03:26 2018
@@ -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 @@ vaddr_t		pmap_steal_memory(vsize_t, vadd
 #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 */
 

Reply via email to