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
This commit is contained in:
jdolecek 2018-05-19 15:03:26 +00:00
parent ce735ef0b5
commit 62a2bd8b5b
4 changed files with 76 additions and 5 deletions

View File

@ -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>

View File

@ -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)
/*

View File

@ -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_page *);
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
*/

View File

@ -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, vaddr_t *, vaddr_t *);
#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 */