Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch Extend the xpmap API, as described in [1]. This cha...
details: https://anonhg.NetBSD.org/src/rev/e7268bb388aa
branches: trunk
changeset: 779948:e7268bb388aa
user: jym <jym%NetBSD.org@localhost>
date: Sat Jun 30 22:50:36 2012 +0000
description:
Extend the xpmap API, as described in [1]. This change is mechanical and
avoids exposing the MD phys_to_machine/machine_to_phys tables directly.
Added:
- xpmap_ptom handles PFN (pseudo physical) to MFN (machine frame number)
translations, and is under control of the domain.
- xpmap_mtop is its counterpart (MFN to PFN), and is under control of
hypervisor.
xpmap_ptom_map() map a pseudo-phys address to a machine address
xpmap_ptom_unmap() unmap a pseudo-phys address (invalidation)
xpmap_ptom_isvalid() check for pseudo-phys address validity
The parameters are physical/machine addresses, like bus_dma/bus_space(9).
As x86 MFNs are tracked by u_long (Xen's choice) while machine addresses
can be 64 bits entities (PAE), use ptoa() to avoid truncation when bit
shifting by PAGE_SHIFT.
I kept the same namespace (xpmap_) to avoid code churn.
[1] http://mail-index.netbsd.org/port-xen/2009/05/09/msg004951.html
XXX will document ptoa/atop/trunc_page separately.
diffstat:
sys/arch/amd64/include/pmap.h | 3 ++-
sys/arch/xen/include/xenpmap.h | 28 +++++++++++++++++++++++-----
sys/arch/xen/x86/x86_xpmap.c | 6 +++---
sys/arch/xen/x86/xen_bus_dma.c | 13 ++++++-------
sys/arch/xen/xen/balloon.c | 16 +++++-----------
sys/arch/xen/xen/if_xennet_xenbus.c | 16 +++++++---------
sys/arch/xen/xen/xen_machdep.c | 11 +++++++----
sys/arch/xen/xen/xennetback_xenbus.c | 7 +++----
8 files changed, 56 insertions(+), 44 deletions(-)
diffs (truncated from 325 to 300 lines):
diff -r cdb0d30adf7e -r e7268bb388aa sys/arch/amd64/include/pmap.h
--- a/sys/arch/amd64/include/pmap.h Sat Jun 30 21:31:15 2012 +0000
+++ b/sys/arch/amd64/include/pmap.h Sat Jun 30 22:50:36 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.h,v 1.33 2012/06/11 15:18:26 chs Exp $ */
+/* $NetBSD: pmap.h,v 1.34 2012/06/30 22:50:36 jym Exp $ */
/*
* Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -258,6 +258,7 @@
{
return xpmap_mtop_masked(pte & PG_FRAME);
}
+
static __inline void
pmap_pte_set(pt_entry_t *pte, pt_entry_t npte)
{
diff -r cdb0d30adf7e -r e7268bb388aa sys/arch/xen/include/xenpmap.h
--- a/sys/arch/xen/include/xenpmap.h Sat Jun 30 21:31:15 2012 +0000
+++ b/sys/arch/xen/include/xenpmap.h Sat Jun 30 22:50:36 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: xenpmap.h,v 1.36 2012/06/27 00:37:09 jym Exp $ */
+/* $NetBSD: xenpmap.h,v 1.37 2012/06/30 22:50:36 jym Exp $ */
/*
*
@@ -76,9 +76,6 @@
extern unsigned long *xpmap_phys_to_machine_mapping;
-#define mfn_to_pfn(mfn) (machine_to_phys_mapping[(mfn)])
-#define pfn_to_mfn(pfn) (xpmap_phys_to_machine_mapping[(pfn)])
-
static __inline paddr_t
xpmap_mtop_masked(paddr_t mpa)
{
@@ -95,7 +92,8 @@
static __inline paddr_t
xpmap_ptom_masked(paddr_t ppa)
{
- return (((paddr_t)xpmap_phys_to_machine_mapping[(ppa) >> PAGE_SHIFT])
+ return (
+ (paddr_t)xpmap_phys_to_machine_mapping[ppa >> PAGE_SHIFT]
<< PAGE_SHIFT);
}
@@ -105,6 +103,26 @@
return (xpmap_ptom_masked(ppa) | (ppa & ~PG_FRAME));
}
+static __inline void
+xpmap_ptom_map(paddr_t ppa, paddr_t mpa)
+{
+ xpmap_phys_to_machine_mapping[ppa >> PAGE_SHIFT] = mpa >> PAGE_SHIFT;
+}
+
+static __inline void
+xpmap_ptom_unmap(paddr_t ppa)
+{
+ xpmap_phys_to_machine_mapping[ppa >> PAGE_SHIFT] = INVALID_P2M_ENTRY;
+}
+
+static __inline bool
+xpmap_ptom_isvalid(paddr_t ppa)
+{
+ return (
+ xpmap_phys_to_machine_mapping[ppa >> PAGE_SHIFT]
+ != INVALID_P2M_ENTRY);
+}
+
static inline void
MULTI_update_va_mapping(
multicall_entry_t *mcl, vaddr_t va,
diff -r cdb0d30adf7e -r e7268bb388aa sys/arch/xen/x86/x86_xpmap.c
--- a/sys/arch/xen/x86/x86_xpmap.c Sat Jun 30 21:31:15 2012 +0000
+++ b/sys/arch/xen/x86/x86_xpmap.c Sat Jun 30 22:50:36 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: x86_xpmap.c,v 1.45 2012/06/27 00:37:10 jym Exp $ */
+/* $NetBSD: x86_xpmap.c,v 1.46 2012/06/30 22:50:37 jym Exp $ */
/*
* Copyright (c) 2006 Mathieu Ropert <mro%adviseo.fr@localhost>
@@ -69,7 +69,7 @@
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.45 2012/06/27 00:37:10 jym Exp $");
+__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.46 2012/06/30 22:50:37 jym Exp $");
#include "opt_xen.h"
#include "opt_ddb.h"
@@ -1092,7 +1092,7 @@
xpq_flush_queue();
op.cmd = MMUEXT_NEW_USER_BASEPTR;
- op.arg1.mfn = pfn_to_mfn(page >> PAGE_SHIFT);
+ op.arg1.mfn = xpmap_ptom_masked(page) >> PAGE_SHIFT;
if (HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0)
panic("xen_set_user_pgd: failed to install new user page"
" directory %#" PRIxPADDR, page);
diff -r cdb0d30adf7e -r e7268bb388aa sys/arch/xen/x86/xen_bus_dma.c
--- a/sys/arch/xen/x86/xen_bus_dma.c Sat Jun 30 21:31:15 2012 +0000
+++ b/sys/arch/xen/x86/xen_bus_dma.c Sat Jun 30 22:50:36 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: xen_bus_dma.c,v 1.24 2012/06/27 00:37:10 jym Exp $ */
+/* $NetBSD: xen_bus_dma.c,v 1.25 2012/06/30 22:50:37 jym Exp $ */
/* NetBSD bus_dma.c,v 1.21 2005/04/16 07:53:35 yamt Exp */
/*-
@@ -32,7 +32,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xen_bus_dma.c,v 1.24 2012/06/27 00:37:10 jym Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_bus_dma.c,v 1.25 2012/06/30 22:50:37 jym Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -90,8 +90,7 @@
for (pg = mlistp->tqh_first; pg != NULL; pg = pg->pageq.queue.tqe_next) {
pa = VM_PAGE_TO_PHYS(pg);
mfn = xpmap_ptom(pa) >> PAGE_SHIFT;
- xpmap_phys_to_machine_mapping[
- pa >> PAGE_SHIFT] = INVALID_P2M_ENTRY;
+ xpmap_ptom_unmap(pa);
xenguest_handle(res.extent_start) = &mfn;
res.nr_extents = 1;
res.extent_order = 0;
@@ -104,7 +103,7 @@
"failed: err %d (pa %#" PRIxPADDR " mfn %#lx)\n",
error, pa, mfn);
#endif
- xpmap_phys_to_machine_mapping[pa >> PAGE_SHIFT] = mfn;
+ xpmap_ptom_map(pa, ptoa(mfn));
error = ENOMEM;
goto failed;
@@ -132,7 +131,7 @@
for (pg = mlistp->tqh_first, i = 0; pg != NULL; pg = pgnext, i++) {
pgnext = pg->pageq.queue.tqe_next;
pa = VM_PAGE_TO_PHYS(pg);
- xpmap_phys_to_machine_mapping[pa >> PAGE_SHIFT] = mfn+i;
+ xpmap_ptom_map(pa, ptoa(mfn+i));
xpq_queue_machphys_update(((paddr_t)(mfn+i)) << PAGE_SHIFT, pa);
/* while here, give extra pages back to UVM */
if (i >= npagesreq) {
@@ -176,7 +175,7 @@
break;
}
pa = VM_PAGE_TO_PHYS(pg);
- xpmap_phys_to_machine_mapping[pa >> PAGE_SHIFT] = mfn;
+ xpmap_ptom_map(pa, ptoa(mfn));
xpq_queue_machphys_update(((paddr_t)mfn) << PAGE_SHIFT, pa);
TAILQ_REMOVE(mlistp, pg, pageq.queue);
uvm_pagefree(pg);
diff -r cdb0d30adf7e -r e7268bb388aa sys/arch/xen/xen/balloon.c
--- a/sys/arch/xen/xen/balloon.c Sat Jun 30 21:31:15 2012 +0000
+++ b/sys/arch/xen/xen/balloon.c Sat Jun 30 22:50:36 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: balloon.c,v 1.14 2012/06/27 00:37:10 jym Exp $ */
+/* $NetBSD: balloon.c,v 1.15 2012/06/30 22:50:37 jym Exp $ */
/*-
* Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -71,7 +71,7 @@
#define BALLOONDEBUG 0
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: balloon.c,v 1.14 2012/06/27 00:37:10 jym Exp $");
+__KERNEL_RCSID(0, "$NetBSD: balloon.c,v 1.15 2012/06/30 22:50:37 jym Exp $");
#include <sys/inttypes.h>
#include <sys/device.h>
@@ -397,11 +397,8 @@
mfn_list[rpages] = xpmap_ptom(pa) >> PAGE_SHIFT;
s = splvm();
-
/* Invalidate pg */
- xpmap_phys_to_machine_mapping[
- pa >> PAGE_SHIFT] = INVALID_P2M_ENTRY;
-
+ xpmap_ptom_unmap(pa);
splx(s);
SLIST_INSERT_HEAD(&balloon_sc->balloon_page_entries,
@@ -516,11 +513,8 @@
s = splvm();
- xpmap_phys_to_machine_mapping[
- pa >> PAGE_SHIFT] = mfn_list[rpages];
-
- xpq_queue_machphys_update(
- ((paddr_t) (mfn_list[rpages])) << PAGE_SHIFT, pa);
+ xpmap_ptom_map(pa, ptoa(mfn_list[rpages]));
+ xpq_queue_machphys_update(ptoa(mfn_list[rpages]), pa);
splx(s);
diff -r cdb0d30adf7e -r e7268bb388aa sys/arch/xen/xen/if_xennet_xenbus.c
--- a/sys/arch/xen/xen/if_xennet_xenbus.c Sat Jun 30 21:31:15 2012 +0000
+++ b/sys/arch/xen/xen/if_xennet_xenbus.c Sat Jun 30 22:50:36 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_xennet_xenbus.c,v 1.60 2012/06/27 00:37:10 jym Exp $ */
+/* $NetBSD: if_xennet_xenbus.c,v 1.61 2012/06/30 22:50:37 jym Exp $ */
/*
* Copyright (c) 2006 Manuel Bouyer.
@@ -85,7 +85,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_xennet_xenbus.c,v 1.60 2012/06/27 00:37:10 jym Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_xennet_xenbus.c,v 1.61 2012/06/30 22:50:37 jym Exp $");
#include "opt_xen.h"
#include "opt_nfs_boot.h"
@@ -686,7 +686,6 @@
struct xennet_rxreq *req;
struct xen_memory_reservation reservation;
int s, otherend_id, notify;
- paddr_t pfn;
otherend_id = sc->sc_xbusd->xbusd_otherend_id;
@@ -731,9 +730,9 @@
* Remove this page from pseudo phys map before
* passing back to Xen.
*/
- pfn = req->rxreq_pa >> PAGE_SHIFT;
- xennet_pages[i] = xpmap_phys_to_machine_mapping[pfn];
- xpmap_phys_to_machine_mapping[pfn] = INVALID_P2M_ENTRY;
+ xennet_pages[i] =
+ xpmap_ptom(req->rxreq_pa) >> PAGE_SHIFT;
+ xpmap_ptom_unmap(req->rxreq_pa);
}
}
@@ -842,8 +841,7 @@
MULTI_update_va_mapping(&mcl[0], va,
(ma << PAGE_SHIFT) | PG_V | PG_KW,
UVMF_TLB_FLUSH|UVMF_ALL);
- xpmap_phys_to_machine_mapping[
- pa >> PAGE_SHIFT] = ma;
+ xpmap_ptom_map(pa, ptoa(ma));
mcl[1].op = __HYPERVISOR_mmu_update;
mcl[1].args[0] = (unsigned long)mmu;
mcl[1].args[1] = 1;
@@ -1039,7 +1037,7 @@
mmu[0].val = pa >> PAGE_SHIFT;
MULTI_update_va_mapping(&mcl[0], va,
(ma << PAGE_SHIFT) | PG_V | PG_KW, UVMF_TLB_FLUSH|UVMF_ALL);
- xpmap_phys_to_machine_mapping[pa >> PAGE_SHIFT] = ma;
+ xpmap_ptom_map(pa, ptoa(ma));
mcl[1].op = __HYPERVISOR_mmu_update;
mcl[1].args[0] = (unsigned long)mmu;
mcl[1].args[1] = 1;
diff -r cdb0d30adf7e -r e7268bb388aa sys/arch/xen/xen/xen_machdep.c
--- a/sys/arch/xen/xen/xen_machdep.c Sat Jun 30 21:31:15 2012 +0000
+++ b/sys/arch/xen/xen/xen_machdep.c Sat Jun 30 22:50:36 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: xen_machdep.c,v 1.10 2012/02/12 14:38:18 jym Exp $ */
+/* $NetBSD: xen_machdep.c,v 1.11 2012/06/30 22:50:37 jym Exp $ */
/*
* Copyright (c) 2006 Manuel Bouyer.
@@ -53,7 +53,7 @@
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xen_machdep.c,v 1.10 2012/02/12 14:38:18 jym Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_machdep.c,v 1.11 2012/06/30 22:50:37 jym Exp $");
#include "opt_xen.h"
@@ -283,6 +283,7 @@
static void
xen_prepare_suspend(void)
{
+
kpreempt_disable();
pmap_xen_suspend();
@@ -292,8 +293,10 @@
* save/restore code does not translate these MFNs to their
* associated PFNs, so we must do it
*/
- xen_start_info.store_mfn = mfn_to_pfn(xen_start_info.store_mfn);
- xen_start_info.console_mfn = mfn_to_pfn(xen_start_info.console_mfn);
+ xen_start_info.store_mfn =
+ atop(xpmap_mtop(ptoa(xen_start_info.store_mfn)));
+ xen_start_info.console_mfn =
+ atop(xpmap_mtop(ptoa(xen_start_info.console_mfn)));
DPRINTK(("suspending domain\n"));
aprint_verbose("suspending domain\n");
diff -r cdb0d30adf7e -r e7268bb388aa sys/arch/xen/xen/xennetback_xenbus.c
--- a/sys/arch/xen/xen/xennetback_xenbus.c Sat Jun 30 21:31:15 2012 +0000
+++ b/sys/arch/xen/xen/xennetback_xenbus.c Sat Jun 30 22:50:36 2012 +0000
Home |
Main Index |
Thread Index |
Old Index