Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/xen Add PVH support for backend drivers grant opera...



details:   https://anonhg.NetBSD.org/src/rev/9c94db20e4ba
branches:  trunk
changeset: 369796:9c94db20e4ba
user:      bouyer <bouyer%NetBSD.org@localhost>
date:      Thu Sep 01 12:29:00 2022 +0000

description:
Add PVH support for backend drivers grant operation.
Now a domU in a PVH dom0 boots multiuser.

diffstat:

 sys/arch/xen/x86/xen_shm_machdep.c   |  56 +++++++++++++++++++++-
 sys/arch/xen/xen/pciback.c           |  35 +++++++++++++-
 sys/arch/xen/xen/xbdback_xenbus.c    |  64 +++++++++++++++++++++----
 sys/arch/xen/xen/xennetback_xenbus.c |  88 ++++++++++++++++++++++++++++++-----
 4 files changed, 211 insertions(+), 32 deletions(-)

diffs (truncated from 611 to 300 lines):

diff -r dcac1fc25152 -r 9c94db20e4ba sys/arch/xen/x86/xen_shm_machdep.c
--- a/sys/arch/xen/x86/xen_shm_machdep.c        Thu Sep 01 12:26:00 2022 +0000
+++ b/sys/arch/xen/x86/xen_shm_machdep.c        Thu Sep 01 12:29:00 2022 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: xen_shm_machdep.c,v 1.17 2021/02/21 20:11:59 jdolecek Exp $      */
+/*      $NetBSD: xen_shm_machdep.c,v 1.18 2022/09/01 12:29:00 bouyer Exp $      */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -25,7 +25,9 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xen_shm_machdep.c,v 1.17 2021/02/21 20:11:59 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_shm_machdep.c,v 1.18 2022/09/01 12:29:00 bouyer Exp $");
+
+#include "opt_xen.h"
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -39,6 +41,7 @@
 #include <xen/hypervisor.h>
 #include <xen/xen.h>
 #include <xen/evtchn.h>
+#include <xen/xenmem.h>
 #include <xen/xen_shm.h>
 
 /*
@@ -58,15 +61,28 @@
 {
        gnttab_map_grant_ref_t op[XENSHM_MAX_PAGES_PER_REQUEST];
        int ret, i;
+#ifndef XENPV
+       paddr_t base_paddr;
+#endif
+       
 
 #ifdef DIAGNOSTIC
        if (nentries > XENSHM_MAX_PAGES_PER_REQUEST) {
                panic("xen_shm_map: %d entries", nentries);
        }
 #endif
+#ifndef XENPV
+       base_paddr = xenmem_alloc_pa(nentries * PAGE_SIZE, PAGE_SIZE, false);
+       if (base_paddr == 0)
+               return ENOMEM;
+#endif
 
        for (i = 0; i < nentries; i++) {
+#ifndef XENPV
+               op[i].host_addr = base_paddr + i * PAGE_SIZE;
+#else
                op[i].host_addr = va + i * PAGE_SIZE;
+#endif
                op[i].dom = domid;
                op[i].ref = grefp[i];
                op[i].flags = GNTMAP_host_map |
@@ -79,7 +95,8 @@
                printf("%s: HYPERVISOR_grant_table_op failed %d\n", __func__,
                    ret);
 #endif
-               return EINVAL;
+               ret = EINVAL;
+               goto err1;
        }
 
        /*
@@ -116,7 +133,12 @@
                 */
                for (i = uncnt = 0; i < nentries; i++) {
                        if (op[i].status == 0) {
+#ifndef XENPV
+                               unop[uncnt].host_addr =
+                                   base_paddr + i * PAGE_SIZE;
+#else
                                unop[uncnt].host_addr = va + i * PAGE_SIZE;
+#endif
                                unop[uncnt].dev_bus_addr = 0;
                                unop[uncnt].handle = handlep[i];
                                uncnt++;
@@ -134,10 +156,23 @@
                printf("%s: HYPERVISOR_grant_table_op bad entry\n",
                    __func__);
 #endif
-               return EINVAL;
+               ret =  EINVAL;
+               goto err1;
        }
+#ifndef XENPV
+       for (i = 0; i < nentries; i++) {
+               pmap_kenter_pa(va + i * PAGE_SIZE,
+                   base_paddr + i * PAGE_SIZE,
+                   VM_PROT_READ | VM_PROT_WRITE, 0);
+       }
+#endif
 
        return 0;
+err1:
+#ifndef XENPV
+       xenmem_free_pa(base_paddr, nentries * PAGE_SIZE);
+#endif
+       return ret;
 }
 
 void
@@ -145,6 +180,11 @@
 {
        gnttab_unmap_grant_ref_t op[XENSHM_MAX_PAGES_PER_REQUEST];
        int ret, i;
+#ifndef XENPV
+       paddr_t base_paddr;
+       if (pmap_extract(pmap_kernel(), va, &base_paddr) != true)
+               panic("xen_shm_unmap: unmapped va");
+#endif
 
 #ifdef DIAGNOSTIC
        if (nentries > XENSHM_MAX_PAGES_PER_REQUEST) {
@@ -153,7 +193,12 @@
 #endif
 
        for (i = 0; i < nentries; i++) {
+#ifndef XENPV
+               pmap_kremove(va + i * PAGE_SIZE, PAGE_SIZE);
+               op[i].host_addr = base_paddr + i * PAGE_SIZE;
+#else
                op[i].host_addr = va + i * PAGE_SIZE;
+#endif
                op[i].dev_bus_addr = 0;
                op[i].handle = handlep[i];
        }
@@ -163,4 +208,7 @@
        if (__predict_false(ret)) {
                panic("xen_shm_unmap: unmap failed");
        }
+#ifndef XENPV
+       xenmem_free_pa(base_paddr, PAGE_SIZE * nentries);
+#endif
 }
diff -r dcac1fc25152 -r 9c94db20e4ba sys/arch/xen/xen/pciback.c
--- a/sys/arch/xen/xen/pciback.c        Thu Sep 01 12:26:00 2022 +0000
+++ b/sys/arch/xen/xen/pciback.c        Thu Sep 01 12:29:00 2022 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: pciback.c,v 1.21 2020/04/07 11:47:06 jdolecek Exp $      */
+/*      $NetBSD: pciback.c,v 1.22 2022/09/01 12:29:00 bouyer Exp $      */
 
 /*
  * Copyright (c) 2009 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pciback.c,v 1.21 2020/04/07 11:47:06 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pciback.c,v 1.22 2022/09/01 12:29:00 bouyer Exp $");
 
 #include "opt_xen.h"
 
@@ -48,6 +48,7 @@
 #include <xen/hypervisor.h>
 #include <xen/evtchn.h>
 #include <xen/granttables.h>
+#include <xen/xenmem.h>
 #include <xen/include/public/io/pciif.h>
 #include <xen/xenbus.h>
 
@@ -188,6 +189,7 @@
        /* communication with the domU */
         unsigned int pbx_evtchn; /* our even channel */
        struct intrhand *pbx_ih;
+        paddr_t *pbx_sh_info_pa;
         struct xen_pci_sharedinfo *pbx_sh_info;
         struct xen_pci_op op;
         grant_handle_t pbx_shinfo_handle; /* to unmap shared page */
@@ -529,8 +531,13 @@
            pbxi, pb_xenbus_instance, pbx_next);
        mutex_exit(&pb_xenbus_lock);
 
+
        if (pbxi->pbx_sh_info) {
+#ifndef XENPV
+               op.host_addr = pbxi->pbx_sh_info_pa;
+#else
                op.host_addr = (vaddr_t)pbxi->pbx_sh_info;
+#endif
                op.handle = pbxi->pbx_shinfo_handle;
                op.dev_bus_addr = 0;
                err = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref,
@@ -539,6 +546,12 @@
                        aprint_error("pciback: unmap_grant_ref failed: %d\n",
                            err);
        }
+#ifndef XENPV
+       if (pbxi->pbx_sh_info_pa) {
+               pmap_kremove((vaddr_t)pbxi->pbx_sh_info, PAGE_SIZE);
+               xenmem_free_pa(pbxi->pbx_sh_info_pa, PAGE_SIZE);
+       }
+#endif
        SLIST_FOREACH(pbd, &pbxi->pbx_pb_pci_dev, pb_guest_next) {
                pbd->pbx_instance = NULL;
        }
@@ -593,7 +606,20 @@
                            xbusd->xbusd_otherend);
                        break;
                }
+#ifndef XENPV
+               pbxi->pbx_sh_info_pa =
+                   xenmem_alloc_pa(PAGE_SIZE, PAGE_SIZE, false);
+               if (pbxi->pbx_sh_info_pa == 0) {
+                       xenbus_dev_fatal(xbusd, ENOMEM,
+                           "can't get PA for ring", xbusd->xbusd_otherend);
+                       goto err2;
+               }
+               pmap_kenter_pa((vaddr_t)pbxi->pbx_sh_info, pbxi->pbx_sh_info_pa,
+                   VM_PROT_READ | VM_PROT_WRITE, 0);
+               op.host_addr = pbxi->pbx_sh_info_pa;
+#else
                op.host_addr = (vaddr_t)pbxi->pbx_sh_info;
+#endif
                op.flags = GNTMAP_host_map;
                op.ref = shared_ref;
                op.dom = pbxi->pbx_domid;
@@ -640,6 +666,11 @@
        }
        return;
 err1:
+#ifndef XENPV
+       pmap_kremove((vaddr_t)pbxi->pbx_sh_info, PAGE_SIZE);
+       xenmem_free_pa(pbxi->pbx_sh_info_pa, PAGE_SIZE);
+err2:
+#endif
        uvm_km_free(kernel_map, (vaddr_t)pbxi->pbx_sh_info,
            PAGE_SIZE, UVM_KMF_VAONLY);
 }
diff -r dcac1fc25152 -r 9c94db20e4ba sys/arch/xen/xen/xbdback_xenbus.c
--- a/sys/arch/xen/xen/xbdback_xenbus.c Thu Sep 01 12:26:00 2022 +0000
+++ b/sys/arch/xen/xen/xbdback_xenbus.c Thu Sep 01 12:29:00 2022 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: xbdback_xenbus.c,v 1.99 2021/07/28 22:17:49 jdolecek Exp $      */
+/*      $NetBSD: xbdback_xenbus.c,v 1.100 2022/09/01 12:29:00 bouyer Exp $      */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,9 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.99 2021/07/28 22:17:49 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.100 2022/09/01 12:29:00 bouyer Exp $");
+
+#include "opt_xen.h"
 
 #include <sys/buf.h>
 #include <sys/condvar.h>
@@ -46,8 +48,10 @@
 #include <sys/types.h>
 #include <sys/vnode.h>
 
+#include <xen/intr.h>
 #include <xen/hypervisor.h>
 #include <xen/xen.h>
+#include <xen/xenmem.h>
 #include <xen/xen_shm.h>
 #include <xen/evtchn.h>
 #include <xen/xenbus.h>
@@ -207,6 +211,7 @@
        enum xbdi_proto xbdi_proto;
        grant_handle_t xbdi_ring_handle; /* to unmap the ring */
        vaddr_t xbdi_ring_va; /* to unmap the ring */
+       paddr_t xbdi_ring_pa; /* to unmap the ring */
        /* disconnection must be postponed until all I/O is done */
        int xbdi_refcnt;
        /* 
@@ -432,10 +437,18 @@
        /* unregister watch */
        if (xbdi->xbdi_watch.node)
                xenbus_unwatch_path(&xbdi->xbdi_watch);
-
        /* unmap ring */
-       if (xbdi->xbdi_ring_va != 0) {
-               ungrop.host_addr = xbdi->xbdi_ring_va;
+#ifndef XENPV
+       ungrop.host_addr = xbdi->xbdi_ring_pa;
+       if (xbdi->xbdi_ring_pa != 0) {
+               KASSERT(xbdi->xbdi_ring_va != 0);
+               pmap_kremove(xbdi->xbdi_ring_va, PAGE_SIZE);
+       }
+#else
+       ungrop.host_addr = xbdi->xbdi_ring_va;
+#endif
+       
+       if (ungrop.host_addr != 0) {
                ungrop.handle = xbdi->xbdi_ring_handle;
                ungrop.dev_bus_addr = 0;
                err = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref,
@@ -443,9 +456,16 @@
                if (err)
                    printf("xbdback %s: unmap_grant_ref failed: %d\n",
                        xbusd->xbusd_otherend, err);
+#ifndef XENPV
+               xenmem_free_pa(xbdi->xbdi_ring_pa, PAGE_SIZE);
+#endif



Home | Main Index | Thread Index | Old Index