summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Belopuhov <mikeb@cvs.openbsd.org>2016-01-05 18:04:00 +0000
committerMike Belopuhov <mikeb@cvs.openbsd.org>2016-01-05 18:04:00 +0000
commit8ca854b3f1b618b79d60dbc969f2e0b08ce791a4 (patch)
tree7ff0c75c3c454969b2667000940fff6906b56d31
parent0d3162974abb0e74e67609f092a395a4b5049d40 (diff)
Move over to the v1 of Grant Table entries
In spite of comments in the Xen source code encouraging use of v2 entries in the new code, there's no benefit for us to do so at the moment. While v1 entries support only full page mappings, they're half the size of their newer counterparts, increasing the number of available grant table references from 8000 to 16000 within the same allotment of grant table frames (up to 32).
-rw-r--r--sys/dev/pv/xen.c30
-rw-r--r--sys/dev/pv/xenreg.h33
2 files changed, 18 insertions, 45 deletions
diff --git a/sys/dev/pv/xen.c b/sys/dev/pv/xen.c
index 047c74c384a..ede837b4064 100644
--- a/sys/dev/pv/xen.c
+++ b/sys/dev/pv/xen.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: xen.c,v 1.22 2016/01/05 13:47:28 mikeb Exp $ */
+/* $OpenBSD: xen.c,v 1.23 2016/01/05 18:03:59 mikeb Exp $ */
/*
* Copyright (c) 2015 Mike Belopuhov
@@ -790,11 +790,11 @@ xen_init_grant_tables(struct xen_softc *sc)
return (-1);
}
- gsv.version = 2;
+ gsv.version = 1;
ggv.dom = DOMID_SELF;
if (xen_hypercall(sc, XC_GNTTAB, 3, GNTTABOP_set_version, &gsv, 1) ||
xen_hypercall(sc, XC_GNTTAB, 3, GNTTABOP_get_version, &ggv, 1) ||
- ggv.version != 2) {
+ ggv.version != 1) {
printf("%s: failed to set grant tables API version\n",
sc->sc_dev.dv_xname);
return (-1);
@@ -882,12 +882,12 @@ xen_grant_table_alloc(struct xen_softc *sc, grant_ref_t *ref)
i = 0;
if (ge->ge_reserved && i < ge->ge_reserved)
continue;
- if (ge->ge_table[i].hdr.flags != GTF_invalid &&
- ge->ge_table[i].full_page.frame != 0)
+ if (ge->ge_table[i].flags != GTF_invalid &&
+ ge->ge_table[i].frame != 0)
continue;
*ref = ge->ge_start + i;
/* XXX Mark as taken */
- ge->ge_table[i].full_page.frame = 0xffffffff;
+ ge->ge_table[i].frame = 0xffffffff;
if ((ge->ge_next = i + 1) == GNTTAB_NEPG)
ge->ge_next = ge->ge_reserved + 1;
ge->ge_free--;
@@ -911,11 +911,11 @@ xen_grant_table_free(struct xen_softc *sc, grant_ref_t ref)
continue;
ref -= ge->ge_start;
mtx_enter(&ge->ge_mtx);
- if (ge->ge_table[ref].hdr.flags != GTF_invalid) {
+ if (ge->ge_table[ref].flags != GTF_invalid) {
mtx_leave(&ge->ge_mtx);
return;
}
- ge->ge_table[ref].full_page.frame = 0;
+ ge->ge_table[ref].frame = 0;
ge->ge_next = ref;
ge->ge_free++;
mtx_leave(&ge->ge_mtx);
@@ -933,11 +933,10 @@ xen_grant_table_enter(struct xen_softc *sc, grant_ref_t ref, paddr_t pa,
continue;
ref -= ge->ge_start;
mtx_enter(&ge->ge_mtx);
- ge->ge_table[ref].full_page.frame = atop(pa);
- ge->ge_table[ref].full_page.hdr.domid = 0;
+ ge->ge_table[ref].frame = atop(pa);
+ ge->ge_table[ref].domid = 0;
membar_producer();
- ge->ge_table[ref].full_page.hdr.flags =
- GTF_permit_access | flags;
+ ge->ge_table[ref].flags = GTF_permit_access | flags;
mtx_leave(&ge->ge_mtx);
return (0);
}
@@ -957,12 +956,11 @@ xen_grant_table_remove(struct xen_softc *sc, grant_ref_t ref)
mtx_enter(&ge->ge_mtx);
/* Invalidate the grant reference */
- ptr = (uint32_t *)&ge->ge_table[ref].hdr;
- flags = (ge->ge_table[ref].hdr.flags &
- ~(GTF_reading | GTF_writing));
+ ptr = (uint32_t *)&ge->ge_table[ref];
+ flags = (ge->ge_table[ref].flags & ~(GTF_reading | GTF_writing));
while (atomic_cas_uint(ptr, flags, 0) != flags)
CPU_BUSY_CYCLE();
- ge->ge_table[ref].full_page.frame = 0xffffffff;
+ ge->ge_table[ref].frame = 0xffffffff;
mtx_leave(&ge->ge_mtx);
break;
}
diff --git a/sys/dev/pv/xenreg.h b/sys/dev/pv/xenreg.h
index 5bdbbd709dd..edcaf9c20b7 100644
--- a/sys/dev/pv/xenreg.h
+++ b/sys/dev/pv/xenreg.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: xenreg.h,v 1.6 2015/12/22 22:16:53 mikeb Exp $ */
+/* $OpenBSD: xenreg.h,v 1.7 2016/01/05 18:03:59 mikeb Exp $ */
/*
* Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -615,9 +615,6 @@ typedef uint32_t grant_ref_t;
* GTF_reading: Grant entry is currently mapped for reading by @domid. [XEN]
* GTF_writing: Grant entry is currently mapped for writing by @domid. [XEN]
* GTF_PAT, GTF_PWT, GTF_PCD: (x86) cache attribute flags for the grant [GST]
- * GTF_sub_page: Grant access to only a subrange of the page. @domid
- * will only be allowed to copy from the grant, and not
- * map it. [GST]
*/
#define GTF_readonly (1<<2)
#define GTF_reading (1<<3)
@@ -625,39 +622,17 @@ typedef uint32_t grant_ref_t;
#define GTF_PWT (1<<5)
#define GTF_PCD (1<<6)
#define GTF_PAT (1<<7)
-#define GTF_sub_page (1<<8)
-struct grant_entry_header {
+typedef struct grant_entry {
uint16_t flags;
domid_t domid;
-};
-
-typedef union grant_entry {
- struct grant_entry_header hdr;
-
- /*
- * This member is used for V1-style full page grants, where either:
- *
- * -- hdr.type is GTF_accept_transfer, or
- * -- hdr.type is GTF_permit_access and GTF_sub_page is not set.
- *
- * In that case, the frame field has the same semantics as the
- * field of the same name in the V1 entry structure.
- */
- struct {
- struct grant_entry_header hdr;
- uint32_t pad0;
- uint64_t frame;
- } full_page;
-
- uint32_t __spacer[4]; /* Pad to a power of two */
-} grant_entry_t;
+ uint32_t frame;
+} __packed grant_entry_t;
/* Number of grant table entries per memory page */
#define GNTTAB_NEPG (PAGE_SIZE / sizeof(grant_entry_t))
#define GNTTABOP_query_size 6
-#define GNTTABOP_unmap_and_replace 7
#define GNTTABOP_set_version 8
#define GNTTABOP_get_version 10