Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch/xen change interface for xen_shm_map() so that call...
details: https://anonhg.NetBSD.org/src/rev/3b38a68a3b88
branches: trunk
changeset: 971256:3b38a68a3b88
user: jdolecek <jdolecek%NetBSD.org@localhost>
date: Sun Apr 19 18:47:40 2020 +0000
description:
change interface for xen_shm_map() so that caller always supplies the VA,
it now fails only if the Xen hypercall fails, in which case the failure
is final
change xbdback to pre-allocate KVA on xbdback attach (and free on detach),
so it has always KVA to map the request pages
remove no longer needed KVA allocation failure handling
diffstat:
sys/arch/xen/include/xen_shm.h | 8 +-
sys/arch/xen/x86/xen_shm_machdep.c | 158 ++-----------------------------
sys/arch/xen/xen/hypervisor.c | 7 +-
sys/arch/xen/xen/xbdback_xenbus.c | 184 ++++++++++++------------------------
4 files changed, 79 insertions(+), 278 deletions(-)
diffs (truncated from 647 to 300 lines):
diff -r 6bc1e5fdb130 -r 3b38a68a3b88 sys/arch/xen/include/xen_shm.h
--- a/sys/arch/xen/include/xen_shm.h Sun Apr 19 18:07:00 2020 +0000
+++ b/sys/arch/xen/include/xen_shm.h Sun Apr 19 18:47:40 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: xen_shm.h,v 1.10 2019/01/08 19:59:24 jdolecek Exp $ */
+/* $NetBSD: xen_shm.h,v 1.11 2020/04/19 18:47:40 jdolecek Exp $ */
/*
* Copyright (c) 2005 Manuel Bouyer.
@@ -27,7 +27,7 @@
#include "opt_xen.h"
-#define XENSHM_MAX_PAGES_PER_REQUEST (MAXPHYS >> PAGE_SHIFT)
+#define XENSHM_MAX_PAGES_PER_REQUEST ((MAXPHYS + PAGE_SIZE) >> PAGE_SHIFT)
/*
* Helper routines for the backend drivers. This implement the necessary
@@ -35,10 +35,8 @@
* space, do I/O to it, and unmap it.
*/
-int xen_shm_map(int, int, grant_ref_t *, vaddr_t *, grant_handle_t *, int);
+int xen_shm_map(int, int, grant_ref_t *, vaddr_t, grant_handle_t *, int);
void xen_shm_unmap(vaddr_t, int, grant_handle_t *);
-int xen_shm_callback(int (*)(void *), void *);
/* flags for xen_shm_map() */
-#define XSHM_CALLBACK 0x01 /* called from a callback */
#define XSHM_RO 0x02 /* map the guest's memory read-only */
diff -r 6bc1e5fdb130 -r 3b38a68a3b88 sys/arch/xen/x86/xen_shm_machdep.c
--- a/sys/arch/xen/x86/xen_shm_machdep.c Sun Apr 19 18:07:00 2020 +0000
+++ b/sys/arch/xen/x86/xen_shm_machdep.c Sun Apr 19 18:47:40 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: xen_shm_machdep.c,v 1.14 2020/04/13 00:27:16 chs Exp $ */
+/* $NetBSD: xen_shm_machdep.c,v 1.15 2020/04/19 18:47:40 jdolecek Exp $ */
/*
* Copyright (c) 2006 Manuel Bouyer.
@@ -25,7 +25,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xen_shm_machdep.c,v 1.14 2020/04/13 00:27:16 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_shm_machdep.c,v 1.15 2020/04/19 18:47:40 jdolecek Exp $");
#include <sys/types.h>
#include <sys/param.h>
@@ -55,71 +55,12 @@
* available.
*/
-/* Grab enough VM space to map an entire vbd ring. */
-/* Xen3 linux guests seems to eat more pages, gives enough for 10 vbd rings */
-#define BLKIF_RING_SIZE __RING_SIZE((blkif_sring_t *)0, PAGE_SIZE)
-#define XENSHM_NPAGES (BLKIF_RING_SIZE * (BLKIF_MAX_SEGMENTS_PER_REQUEST + 1) * 10)
-
-/* vm space management */
-static vmem_t *xen_shm_arena __read_mostly;
-
-/* callbacks are registered in a FIFO list. */
-static SIMPLEQ_HEAD(xen_shm_callback_head, xen_shm_callback_entry)
- xen_shm_callbacks;
-
-struct xen_shm_callback_entry {
- SIMPLEQ_ENTRY(xen_shm_callback_entry) xshmc_entries;
- int (*xshmc_callback)(void *); /* our callback */
- void *xshmc_arg; /* cookie passed to the callback */
-};
-
-/* a pool of struct xen_shm_callback_entry */
-static struct pool xen_shm_callback_pool;
-
-#ifdef DEBUG
-/* for ratecheck(9) */
-static struct timeval xen_shm_errintvl = { 60, 0 }; /* a minute, each */
-#endif
-
-void
-xen_shm_init(void)
-{
- vaddr_t xen_shm_base_address;
- vaddr_t xen_shm_end_address;
- u_long xen_shm_base_address_pg;
- vsize_t xen_shm_size;
-
- SIMPLEQ_INIT(&xen_shm_callbacks);
- pool_init(&xen_shm_callback_pool, sizeof(struct xen_shm_callback_entry),
- 0, 0, 0, "xshmc", NULL, IPL_VM);
- /* ensure we'll always get items */
- pool_prime(&xen_shm_callback_pool, 1);
-
- xen_shm_size = (XENSHM_NPAGES * PAGE_SIZE);
-
- xen_shm_base_address = uvm_km_alloc(kernel_map, xen_shm_size, 0,
- UVM_KMF_VAONLY);
- xen_shm_end_address = xen_shm_base_address + xen_shm_size;
- xen_shm_base_address_pg = xen_shm_base_address >> PAGE_SHIFT;
- if (xen_shm_base_address == 0) {
- panic("xen_shm_init no VM space");
- }
- xen_shm_arena = vmem_create("xen_shm", xen_shm_base_address_pg,
- (xen_shm_end_address >> PAGE_SHIFT) - 1 - xen_shm_base_address_pg,
- 1, NULL, NULL, NULL, 1, VM_NOSLEEP, IPL_VM);
- if (xen_shm_arena == NULL) {
- panic("xen_shm_init no arena");
- }
-}
-
int
-xen_shm_map(int nentries, int domid, grant_ref_t *grefp, vaddr_t *vap,
+xen_shm_map(int nentries, int domid, grant_ref_t *grefp, vaddr_t va,
grant_handle_t *handlep, int flags)
{
gnttab_map_grant_ref_t op[XENSHM_MAX_PAGES_PER_REQUEST];
- vmem_addr_t new_va_pg;
- vaddr_t new_va;
- int ret, i, s;
+ int ret, i;
#ifdef DIAGNOSTIC
if (nentries > XENSHM_MAX_PAGES_PER_REQUEST) {
@@ -127,41 +68,8 @@
}
#endif
- /* XXXSMP */
- s = splvm(); /* splvm is the lowest level blocking disk and net IRQ */
-
- /*
- * If a driver is waiting for resources, don't try to allocate
- * yet. This is to avoid a flood of small requests stalling large
- * ones.
- */
- if (__predict_false(SIMPLEQ_FIRST(&xen_shm_callbacks) != NULL) &&
- (flags & XSHM_CALLBACK) == 0) {
- splx(s);
-#ifdef DEBUG
- static struct timeval lasttime;
- if (ratecheck(&lasttime, &xen_shm_errintvl))
- printf("xen_shm_map: ENOMEM1\n");
-#endif
- return ENOMEM;
- }
-
- /* Allocate the needed virtual space. */
- if (vmem_alloc(xen_shm_arena, nentries,
- VM_INSTANTFIT | VM_NOSLEEP, &new_va_pg) != 0) {
- splx(s);
-#ifdef DEBUG
- static struct timeval lasttime;
- if (ratecheck(&lasttime, &xen_shm_errintvl))
- printf("xen_shm_map: ENOMEM\n");
-#endif
- return ENOMEM;
- }
- splx(s);
-
- new_va = new_va_pg << PAGE_SHIFT;
for (i = 0; i < nentries; i++) {
- op[i].host_addr = new_va + i * PAGE_SIZE;
+ op[i].host_addr = va + i * PAGE_SIZE;
op[i].dom = domid;
op[i].ref = grefp[i];
op[i].flags = GNTMAP_host_map |
@@ -170,16 +78,19 @@
ret = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, op, nentries);
if (__predict_false(ret)) {
- panic("xen_shm_map: HYPERVISOR_grant_table_op failed");
+ printf("%s: HYPERVISOR_grant_table_op failed\n", __func__);
+ return EINVAL;
}
for (i = 0; i < nentries; i++) {
+#ifdef DIAGNOSTIC
if (__predict_false(op[i].status))
- return op[i].status;
+ panic("%s: op[%d] status %d", __func__, i,
+ op[i].status);
+#endif
handlep[i] = op[i].handle;
}
- *vap = new_va;
return 0;
}
@@ -187,8 +98,7 @@
xen_shm_unmap(vaddr_t va, int nentries, grant_handle_t *handlep)
{
gnttab_unmap_grant_ref_t op[XENSHM_MAX_PAGES_PER_REQUEST];
- struct xen_shm_callback_entry *xshmc;
- int ret, i, s;
+ int ret, i;
#ifdef DIAGNOSTIC
if (nentries > XENSHM_MAX_PAGES_PER_REQUEST) {
@@ -207,48 +117,4 @@
if (__predict_false(ret)) {
panic("xen_shm_unmap: unmap failed");
}
-
- va = va >> PAGE_SHIFT;
-
- /* XXXSMP */
- s = splvm(); /* splvm is the lowest level blocking disk and net IRQ */
-
- vmem_free(xen_shm_arena, va, nentries);
- while (__predict_false((xshmc = SIMPLEQ_FIRST(&xen_shm_callbacks))
- != NULL)) {
- SIMPLEQ_REMOVE_HEAD(&xen_shm_callbacks, xshmc_entries);
- splx(s);
- if (xshmc->xshmc_callback(xshmc->xshmc_arg) == 0) {
- /* callback succeeded */
- s = splvm(); /* XXXSMP */
- pool_put(&xen_shm_callback_pool, xshmc);
- } else {
- /* callback failed, probably out of resources */
- s = splvm(); /* XXXSMP */
- SIMPLEQ_INSERT_TAIL(&xen_shm_callbacks, xshmc,
- xshmc_entries);
- break;
- }
- }
-
- splx(s);
}
-
-int
-xen_shm_callback(int (*callback)(void *), void *arg)
-{
- struct xen_shm_callback_entry *xshmc;
- int s;
-
- s = splvm(); /* XXXSMP */
- xshmc = pool_get(&xen_shm_callback_pool, PR_NOWAIT);
- if (xshmc == NULL) {
- splx(s);
- return ENOMEM;
- }
- xshmc->xshmc_arg = arg;
- xshmc->xshmc_callback = callback;
- SIMPLEQ_INSERT_TAIL(&xen_shm_callbacks, xshmc, xshmc_entries);
- splx(s);
- return 0;
-}
diff -r 6bc1e5fdb130 -r 3b38a68a3b88 sys/arch/xen/xen/hypervisor.c
--- a/sys/arch/xen/xen/hypervisor.c Sun Apr 19 18:07:00 2020 +0000
+++ b/sys/arch/xen/xen/hypervisor.c Sun Apr 19 18:47:40 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: hypervisor.c,v 1.74 2020/04/10 14:54:33 jdolecek Exp $ */
+/* $NetBSD: hypervisor.c,v 1.75 2020/04/19 18:47:40 jdolecek Exp $ */
/*
* Copyright (c) 2005 Manuel Bouyer.
@@ -53,7 +53,7 @@
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: hypervisor.c,v 1.74 2020/04/10 14:54:33 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hypervisor.c,v 1.75 2020/04/19 18:47:40 jdolecek Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -415,7 +415,7 @@
bi.common.len = sizeof(struct btinfo_rootdevice);
/* From i386/multiboot.c */
- /* $NetBSD: hypervisor.c,v 1.74 2020/04/10 14:54:33 jdolecek Exp $ */
+ /* $NetBSD: hypervisor.c,v 1.75 2020/04/19 18:47:40 jdolecek Exp $ */
int i, len;
vaddr_t data;
extern struct bootinfo bootinfo;
@@ -620,7 +620,6 @@
if (xendomain_is_privileged()) {
xenprivcmd_init();
- xen_shm_init();
}
#endif /* DOM0OPS */
diff -r 6bc1e5fdb130 -r 3b38a68a3b88 sys/arch/xen/xen/xbdback_xenbus.c
--- a/sys/arch/xen/xen/xbdback_xenbus.c Sun Apr 19 18:07:00 2020 +0000
+++ b/sys/arch/xen/xen/xbdback_xenbus.c Sun Apr 19 18:47:40 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: xbdback_xenbus.c,v 1.78 2020/04/13 00:27:17 chs Exp $ */
+/* $NetBSD: xbdback_xenbus.c,v 1.79 2020/04/19 18:47:40 jdolecek Exp $ */
/*
* Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.78 2020/04/13 00:27:17 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.79 2020/04/19 18:47:40 jdolecek Exp $");
#include <sys/atomic.h>
#include <sys/buf.h>
Home |
Main Index |
Thread Index |
Old Index