Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch/xen/xen in backend drivers, use xen_shm_(un)map for...
details: https://anonhg.NetBSD.org/src/rev/af403b6a4834
branches: trunk
changeset: 369801:af403b6a4834
user: bouyer <bouyer%NetBSD.org@localhost>
date: Thu Sep 01 15:33:23 2022 +0000
description:
in backend drivers, use xen_shm_(un)map for the rings instead of inline,
mostly duplicate code.
diffstat:
sys/arch/xen/xen/pciback.c | 70 +++-------------
sys/arch/xen/xen/xbdback_xenbus.c | 86 +++-----------------
sys/arch/xen/xen/xennetback_xenbus.c | 142 ++++------------------------------
3 files changed, 46 insertions(+), 252 deletions(-)
diffs (truncated from 520 to 300 lines):
diff -r 93de392eac2a -r af403b6a4834 sys/arch/xen/xen/pciback.c
--- a/sys/arch/xen/xen/pciback.c Thu Sep 01 15:32:16 2022 +0000
+++ b/sys/arch/xen/xen/pciback.c Thu Sep 01 15:33:23 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pciback.c,v 1.22 2022/09/01 12:29:00 bouyer Exp $ */
+/* $NetBSD: pciback.c,v 1.23 2022/09/01 15:33:23 bouyer Exp $ */
/*
* Copyright (c) 2009 Manuel Bouyer.
@@ -26,10 +26,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pciback.c,v 1.22 2022/09/01 12:29:00 bouyer Exp $");
-
-#include "opt_xen.h"
-
+__KERNEL_RCSID(0, "$NetBSD: pciback.c,v 1.23 2022/09/01 15:33:23 bouyer Exp $");
#include <sys/types.h>
#include <sys/param.h>
@@ -48,7 +45,7 @@
#include <xen/hypervisor.h>
#include <xen/evtchn.h>
#include <xen/granttables.h>
-#include <xen/xenmem.h>
+#include <xen/xen_shm.h>
#include <xen/include/public/io/pciif.h>
#include <xen/xenbus.h>
@@ -189,7 +186,6 @@
/* 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 */
@@ -521,8 +517,6 @@
{
struct pb_xenbus_instance *pbxi = arg;
struct pciback_pci_dev *pbd;
- struct gnttab_unmap_grant_ref op;
- int err;
hypervisor_mask_event(pbxi->pbx_evtchn);
xen_intr_disestablish(pbxi->pbx_ih);
@@ -533,30 +527,14 @@
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,
- &op, 1);
- if (err)
- aprint_error("pciback: unmap_grant_ref failed: %d\n",
- err);
+ xen_shm_unmap((vaddr_t)pbxi->pbx_sh_info, 1,
+ &pbxi->pbx_shinfo_handle);
+ uvm_km_free(kernel_map, (vaddr_t)pbxi->pbx_sh_info,
+ PAGE_SIZE, UVM_KMF_VAONLY);
}
-#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;
}
- uvm_km_free(kernel_map, (vaddr_t)pbxi->pbx_sh_info,
- PAGE_SIZE, UVM_KMF_VAONLY);
kmem_free(pbxi, sizeof(*pbxi));
return 0;
}
@@ -567,9 +545,9 @@
struct pb_xenbus_instance *pbxi = arg;
struct xenbus_device *xbusd = pbxi->pbx_xbusd;
int err;
- struct gnttab_map_grant_ref op;
evtchn_op_t evop;
u_long shared_ref;
+ grant_ref_t gshared_ref;
u_long revtchn;
/* do it only once */
@@ -606,30 +584,13 @@
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);
+ gshared_ref = shared_ref;
+ if (xen_shm_map(1, pbxi->pbx_domid, &gshared_ref,
+ (vaddr_t)pbxi->pbx_sh_info,
+ &pbxi->pbx_shinfo_handle, 0) != 0) {
+ aprint_error("pciback: can't map shared grant ref\n");
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;
- err = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1);
- if (err || op.status) {
- aprint_error("pciback: can't map shared grant ref: "
- "%d/%d\n", err, op.status);
- goto err1;
- }
- pbxi->pbx_shinfo_handle = op.handle;
evop.cmd = EVTCHNOP_bind_interdomain;
evop.u.bind_interdomain.remote_dom = pbxi->pbx_domid;
@@ -666,11 +627,8 @@
}
return;
err1:
-#ifndef XENPV
- pmap_kremove((vaddr_t)pbxi->pbx_sh_info, PAGE_SIZE);
- xenmem_free_pa(pbxi->pbx_sh_info_pa, PAGE_SIZE);
+ xen_shm_unmap((vaddr_t)pbxi->pbx_sh_info, 1, &pbxi->pbx_shinfo_handle);
err2:
-#endif
uvm_km_free(kernel_map, (vaddr_t)pbxi->pbx_sh_info,
PAGE_SIZE, UVM_KMF_VAONLY);
}
diff -r 93de392eac2a -r af403b6a4834 sys/arch/xen/xen/xbdback_xenbus.c
--- a/sys/arch/xen/xen/xbdback_xenbus.c Thu Sep 01 15:32:16 2022 +0000
+++ b/sys/arch/xen/xen/xbdback_xenbus.c Thu Sep 01 15:33:23 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: xbdback_xenbus.c,v 1.100 2022/09/01 12:29:00 bouyer Exp $ */
+/* $NetBSD: xbdback_xenbus.c,v 1.101 2022/09/01 15:33:23 bouyer Exp $ */
/*
* Copyright (c) 2006 Manuel Bouyer.
@@ -26,9 +26,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.100 2022/09/01 12:29:00 bouyer Exp $");
-
-#include "opt_xen.h"
+__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.101 2022/09/01 15:33:23 bouyer Exp $");
#include <sys/buf.h>
#include <sys/condvar.h>
@@ -51,7 +49,6 @@
#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>
@@ -211,7 +208,6 @@
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;
/*
@@ -426,9 +422,6 @@
xbdback_xenbus_destroy(void *arg)
{
struct xbdback_instance *xbdi = arg;
- struct xenbus_device *xbusd = xbdi->xbdi_xbusd;
- struct gnttab_unmap_grant_ref ungrop;
- int err;
XENPRINTF(("xbdback_xenbus_destroy state %d\n", xbdi->xbdi_status));
@@ -438,27 +431,8 @@
if (xbdi->xbdi_watch.node)
xenbus_unwatch_path(&xbdi->xbdi_watch);
/* unmap ring */
-#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,
- &ungrop, 1);
- 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
+ if (xbdi->xbdi_ring_handle) {
+ xen_shm_unmap(xbdi->xbdi_ring_va, 1, &xbdi->xbdi_ring_handle);
}
if (xbdi->xbdi_ring_va != 0) {
@@ -503,9 +477,8 @@
xbdback_connect(struct xbdback_instance *xbdi)
{
int err;
- struct gnttab_map_grant_ref grop;
- struct gnttab_unmap_grant_ref ungrop;
evtchn_op_t evop;
+ grant_ref_t gring_ref;
u_long ring_ref, revtchn;
char xsproto[32];
const char *proto;
@@ -562,33 +535,17 @@
return -1;
}
XENPRINTF(("xbdback %s: connect va 0x%" PRIxVADDR "\n", xbusd->xbusd_path, xbdi->xbdi_ring_va));
-#ifndef XENPV
- xbdi->xbdi_ring_pa = xenmem_alloc_pa(PAGE_SIZE, PAGE_SIZE, false);
- if (xbdi->xbdi_ring_pa == 0) {
- xenbus_dev_fatal(xbusd, ENOMEM,
- "can't get PA for ring", xbusd->xbusd_otherend);
- goto err;
- }
- pmap_kenter_pa(xbdi->xbdi_ring_va, xbdi->xbdi_ring_pa,
- VM_PROT_READ | VM_PROT_WRITE, 0);
- grop.host_addr = xbdi->xbdi_ring_pa;
-#else
- grop.host_addr = xbdi->xbdi_ring_va;
-#endif
- grop.flags = GNTMAP_host_map;
- grop.ref = ring_ref;
- grop.dom = xbdi->xbdi_domid;
- err = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref,
- &grop, 1);
- if (err || grop.status) {
- aprint_error("xbdback %s: can't map grant ref: %d/%d\n",
- xbusd->xbusd_path, err, grop.status);
+
+ gring_ref = ring_ref;
+ if (xen_shm_map(1, xbdi->xbdi_domid, &gring_ref, xbdi->xbdi_ring_va,
+ &xbdi->xbdi_ring_handle, 0) != 0) {
+ aprint_error("xbdback %s: can't map grant ref\n",
+ xbusd->xbusd_path);
xenbus_dev_fatal(xbusd, EINVAL,
"can't map ring", xbusd->xbusd_otherend);
goto err1;
}
- xbdi->xbdi_ring_handle = grop.handle;
- XENPRINTF(("xbdback %s: connect grhandle %d\n", xbusd->xbusd_path, grop.handle));
+ XENPRINTF(("xbdback %s: connect grhandle %d\n", xbusd->xbusd_path, xbdi->xbdi_ring_handle));
switch(xbdi->xbdi_proto) {
case XBDIP_NATIVE:
@@ -645,25 +602,8 @@
err2:
/* unmap ring */
-#ifndef XENPV
- ungrop.host_addr = xbdi->xbdi_ring_pa;
-#else
- ungrop.host_addr = xbdi->xbdi_ring_va;
-#endif
- ungrop.handle = xbdi->xbdi_ring_handle;
- ungrop.dev_bus_addr = 0;
- err = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref,
- &ungrop, 1);
- if (err)
- aprint_error("xbdback %s: unmap_grant_ref failed: %d\n",
- xbusd->xbusd_path, err);
-
+ xen_shm_unmap(xbdi->xbdi_ring_va, 1, &xbdi->xbdi_ring_handle);
err1:
-#ifndef XENPV
- pmap_kremove(xbdi->xbdi_ring_va, PAGE_SIZE);
- xenmem_free_pa(xbdi->xbdi_ring_pa, PAGE_SIZE);
-err:
-#endif
/* free ring VA space */
uvm_km_free(kernel_map, xbdi->xbdi_ring_va, PAGE_SIZE, UVM_KMF_VAONLY);
return -1;
diff -r 93de392eac2a -r af403b6a4834 sys/arch/xen/xen/xennetback_xenbus.c
--- a/sys/arch/xen/xen/xennetback_xenbus.c Thu Sep 01 15:32:16 2022 +0000
+++ b/sys/arch/xen/xen/xennetback_xenbus.c Thu Sep 01 15:33:23 2022 +0000
Home |
Main Index |
Thread Index |
Old Index