Module Name: src Committed By: bouyer Date: Mon Nov 30 17:06:02 UTC 2020
Modified Files: src/sys/arch/x86/x86: pmap.c src/sys/arch/xen/xen: hypervisor.c privcmd.c xenevt.c Log Message: Work in progress on dom0 PVH support. kernel boots and xl info works, but we can't start a domU yet. To generate a diff of this commit: cvs rdiff -u -r1.407 -r1.408 src/sys/arch/x86/x86/pmap.c cvs rdiff -u -r1.89 -r1.90 src/sys/arch/xen/xen/hypervisor.c cvs rdiff -u -r1.59 -r1.60 src/sys/arch/xen/xen/privcmd.c cvs rdiff -u -r1.60 -r1.61 src/sys/arch/xen/xen/xenevt.c 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/x86/x86/pmap.c diff -u src/sys/arch/x86/x86/pmap.c:1.407 src/sys/arch/x86/x86/pmap.c:1.408 --- src/sys/arch/x86/x86/pmap.c:1.407 Sun Sep 6 02:18:53 2020 +++ src/sys/arch/x86/x86/pmap.c Mon Nov 30 17:06:02 2020 @@ -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 @@ __KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.4 #ifdef XEN #include <xen/include/public/xen.h> #include <xen/hypervisor.h> +#include <xen/xenpmap.h> #endif /* @@ -5233,7 +5234,9 @@ pmap_enter_gnt(struct pmap *pmap, vaddr_ 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 @@ pmap_remove_gnt(struct pmap *pmap, vaddr 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) { Index: src/sys/arch/xen/xen/hypervisor.c diff -u src/sys/arch/xen/xen/hypervisor.c:1.89 src/sys/arch/xen/xen/hypervisor.c:1.90 --- src/sys/arch/xen/xen/hypervisor.c:1.89 Tue Sep 15 10:58:02 2020 +++ src/sys/arch/xen/xen/hypervisor.c Mon Nov 30 17:06:02 2020 @@ -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 @@ hypervisor_attach(device_t parent, devic 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 @@ hypervisor_attach(device_t parent, devic } #endif /* NISA */ #endif /* NPCI */ +#endif /* XENPV */ if (xendomain_is_privileged()) { xenprivcmd_init(); } -#endif /* XENPV && DOM0OPS */ +#endif /* DOM0OPS */ hypervisor_machdep_attach(); Index: src/sys/arch/xen/xen/privcmd.c diff -u src/sys/arch/xen/xen/privcmd.c:1.59 src/sys/arch/xen/xen/privcmd.c:1.60 --- src/sys/arch/xen/xen/privcmd.c:1.59 Tue May 26 10:37:25 2020 +++ src/sys/arch/xen/xen/privcmd.c Mon Nov 30 17:06:02 2020 @@ -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 @@ __KERNEL_RCSID(0, "$NetBSD: privcmd.c,v #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 @@ privcmd_ioctl(void *v) : "=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 @@ privcmd_ioctl(void *v) "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 @@ privpgop_fault(struct uvm_faultinfo *ufi 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 @@ privpgop_fault(struct uvm_faultinfo *ufi } 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 @@ privpgop_fault(struct uvm_faultinfo *ufi error = EFAULT; } break; + } case PTYPE_GNTDEV_REF: { struct pmap *pmap = ufi->orig_map->pmap; Index: src/sys/arch/xen/xen/xenevt.c diff -u src/sys/arch/xen/xen/xenevt.c:1.60 src/sys/arch/xen/xen/xenevt.c:1.61 --- src/sys/arch/xen/xen/xenevt.c:1.60 Thu May 7 19:52:50 2020 +++ src/sys/arch/xen/xen/xenevt.c Mon Nov 30 17:06:02 2020 @@ -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 @@ __KERNEL_RCSID(0, "$NetBSD: xenevt.c,v 1 #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 @@ xenevtattach(int n) { 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);