Source-Changes-HG archive

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

[src/trunk]: src/sys/arch Work in progress on dom0 PVH support. kernel boots ...



details:   https://anonhg.NetBSD.org/src/rev/41bab2b02881
branches:  trunk
changeset: 946535:41bab2b02881
user:      bouyer <bouyer%NetBSD.org@localhost>
date:      Mon Nov 30 17:06:02 2020 +0000

description:
Work in progress on dom0 PVH support. kernel boots and xl info works,
but we can't start a domU yet.

diffstat:

 sys/arch/x86/x86/pmap.c       |   9 +++++++--
 sys/arch/xen/xen/hypervisor.c |  11 +++++++----
 sys/arch/xen/xen/privcmd.c    |  23 ++++++++++++++++++-----
 sys/arch/xen/xen/xenevt.c     |  15 +++++++++++++--
 4 files changed, 45 insertions(+), 13 deletions(-)

diffs (212 lines):

diff -r e68f02aef88c -r 41bab2b02881 sys/arch/x86/x86/pmap.c
--- a/sys/arch/x86/x86/pmap.c   Mon Nov 30 17:05:02 2020 +0000
+++ b/sys/arch/x86/x86/pmap.c   Mon Nov 30 17:06:02 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pmap.c,v 1.407 2020/09/06 02:18:53 riastradh Exp $     */
+/*     $NetBSD: pmap.c,v 1.408 2020/11/30 17:06:02 bouyer Exp $        */
 
 /*
  * Copyright (c) 2008, 2010, 2016, 2017, 2019, 2020 The NetBSD Foundation, Inc.
@@ -130,7 +130,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.407 2020/09/06 02:18:53 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.408 2020/11/30 17:06:02 bouyer Exp $");
 
 #include "opt_user_ldt.h"
 #include "opt_lockdebug.h"
@@ -175,6 +175,7 @@
 #ifdef XEN
 #include <xen/include/public/xen.h>
 #include <xen/hypervisor.h>
+#include <xen/xenpmap.h>
 #endif
 
 /*
@@ -5233,7 +5234,9 @@
        idx = (va - pgnt->pd_gnt_sva) / PAGE_SIZE;
        op = &pgnt->pd_gnt_ops[idx];
 
+#ifdef XENPV /* XXX */
        op->host_addr = xpmap_ptetomach(ptep);
+#endif
        op->dev_bus_addr = 0;
        op->status = GNTST_general_error;
        ret = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, op, 1);
@@ -5354,7 +5357,9 @@
                        KASSERT(pmap_valid_entry(ptes[pl1_i(va)]));
                        unmap_op.handle = op->handle;
                        unmap_op.dev_bus_addr = 0;
+#ifdef XENPV /* XXX */
                        unmap_op.host_addr = xpmap_ptetomach(&ptes[pl1_i(va)]);
+#endif
                        ret = HYPERVISOR_grant_table_op(
                            GNTTABOP_unmap_grant_ref, &unmap_op, 1);
                        if (ret) {
diff -r e68f02aef88c -r 41bab2b02881 sys/arch/xen/xen/hypervisor.c
--- a/sys/arch/xen/xen/hypervisor.c     Mon Nov 30 17:05:02 2020 +0000
+++ b/sys/arch/xen/xen/hypervisor.c     Mon Nov 30 17:06:02 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: hypervisor.c,v 1.89 2020/09/15 10:58:02 bouyer Exp $ */
+/* $NetBSD: hypervisor.c,v 1.90 2020/11/30 17:06:02 bouyer Exp $ */
 
 /*
  * Copyright (c) 2005 Manuel Bouyer.
@@ -53,7 +53,7 @@
 
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: hypervisor.c,v 1.89 2020/09/15 10:58:02 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hypervisor.c,v 1.90 2020/11/30 17:06:02 bouyer Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -682,7 +682,9 @@
                config_found_ia(self, "xendevbus", &hac.hac_xencons, hypervisor_print);
        }
 #endif
-#if defined(XENPV) && defined(DOM0OPS)
+
+#if defined(DOM0OPS)
+#if defined(XENPV)
 #if NPCI > 0
 #if NACPICA > 0
        if (acpi_present) {
@@ -743,11 +745,12 @@
        }
 #endif /* NISA */
 #endif /* NPCI */
+#endif /* XENPV */
 
        if (xendomain_is_privileged()) {
                xenprivcmd_init();
        }
-#endif /* XENPV && DOM0OPS */
+#endif /* DOM0OPS */
 
        hypervisor_machdep_attach();
 
diff -r e68f02aef88c -r 41bab2b02881 sys/arch/xen/xen/privcmd.c
--- a/sys/arch/xen/xen/privcmd.c        Mon Nov 30 17:05:02 2020 +0000
+++ b/sys/arch/xen/xen/privcmd.c        Mon Nov 30 17:06:02 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: privcmd.c,v 1.59 2020/05/26 10:37:25 bouyer Exp $ */
+/* $NetBSD: privcmd.c,v 1.60 2020/11/30 17:06:02 bouyer Exp $ */
 
 /*-
  * Copyright (c) 2004 Christian Limpach.
@@ -27,7 +27,7 @@
 
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: privcmd.c,v 1.59 2020/05/26 10:37:25 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: privcmd.c,v 1.60 2020/11/30 17:06:02 bouyer Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -47,6 +47,7 @@
 #include <xen/hypervisor.h>
 #include <xen/xen.h>
 #include <xen/xenio.h>
+#include <xen/xenpmap.h>
 #include <xen/granttables.h>
 
 #define        PRIVCMD_MODE    (S_IRUSR)
@@ -741,6 +742,10 @@
                        : "=a" (error) : "0" (ap->a_data) : "memory" );
 #endif /* __i386__ */
 #if defined(__x86_64__)
+#ifndef XENPV
+               /* hypervisor can't access user memory if SMAP is enabled */
+               smap_disable();
+#endif
                {
                long i1, i2, i3;
                __asm volatile (
@@ -758,6 +763,9 @@
                          "g" (hc->arg[4])
                        : "r8", "r10", "memory" );
                }
+#ifndef XENPV
+               smap_enable();
+#endif
 #endif /* __x86_64__ */
                if (ap->a_command == IOCTL_PRIVCMD_HYPERCALL) {
                        if (error >= 0) {
@@ -915,6 +923,12 @@
                        continue;
                switch(pobj->type) {
                case PTYPE_PRIVCMD:
+               {
+                       u_int pm_flags = PMAP_CANFAIL | ufi->entry->protection;
+#ifdef XENPV
+                       if (pobj->u.pc.no_translate)
+                               pm_flags |= PMAP_MD_XEN_NOTR;
+#endif
                        if (pobj->u.pc.maddr[maddr_i] == INVALID_PAGE) {
                                /* This has already been flagged as error. */
                                error = EFAULT;
@@ -922,9 +936,7 @@
                        }
                        error = pmap_enter_ma(ufi->orig_map->pmap, vaddr,
                            pobj->u.pc.maddr[maddr_i], 0,
-                           ufi->entry->protection,
-                           PMAP_CANFAIL | ufi->entry->protection |
-                           (pobj->u.pc.no_translate ? PMAP_MD_XEN_NOTR : 0),
+                           ufi->entry->protection, pm_flags,
                            pobj->u.pc.domid);
                        if (error == ENOMEM) {
                                goto out;
@@ -934,6 +946,7 @@
                                error = EFAULT;
                        }
                        break;
+               }
                case PTYPE_GNTDEV_REF:
                {
                        struct pmap *pmap = ufi->orig_map->pmap;
diff -r e68f02aef88c -r 41bab2b02881 sys/arch/xen/xen/xenevt.c
--- a/sys/arch/xen/xen/xenevt.c Mon Nov 30 17:05:02 2020 +0000
+++ b/sys/arch/xen/xen/xenevt.c Mon Nov 30 17:06:02 2020 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: xenevt.c,v 1.60 2020/05/07 19:52:50 bouyer Exp $      */
+/*      $NetBSD: xenevt.c,v 1.61 2020/11/30 17:06:02 bouyer Exp $      */
 
 /*
  * Copyright (c) 2005 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xenevt.c,v 1.60 2020/05/07 19:52:50 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xenevt.c,v 1.61 2020/11/30 17:06:02 bouyer Exp $");
 
 #include "opt_xen.h"
 #include <sys/param.h>
@@ -46,7 +46,11 @@
 #include <uvm/uvm_extern.h>
 
 #include <xen/hypervisor.h>
+#include <xen/evtchn.h>
+#include <xen/intr.h>
+#ifdef XENPV
 #include <xen/xenpmap.h>
+#endif
 #include <xen/xenio.h>
 #include <xen/xenio3.h>
 #include <xen/xen.h>
@@ -165,6 +169,13 @@
 {
        int level = IPL_HIGH;
 
+       if (!xendomain_is_privileged())
+               return;
+#ifndef XENPV
+       if (vm_guest != VM_GUEST_XENPVH)
+               return;
+#endif
+
        mutex_init(&devevent_lock, MUTEX_DEFAULT, IPL_HIGH);
        STAILQ_INIT(&devevent_pending);
 



Home | Main Index | Thread Index | Old Index