Skip to contentSkip to conversation

Xen-side netchannel2 patches, take two

PATCH In review [email protected] 6 participants 16 messages Oct 6, 2009 – Oct 8, 2009 Xen hypervisor interface

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Xen-side netchannel2 patches, take two

This patch series includes all of the Xen and tools bits of netchannel2. It's essentially similar to the one I posted on Sunday, except:

-- I've dropped the unmodified drivers support. It'd probably be
fairly straightforward to re-introduce it, but it's not clear that anyone's actually using unmodified drivers any more (they don't even build against a 2.6.27 kernel, for instance).

-- I've switched to using uint64_t for page numbers in the public
structures, because uint32_t is no longer enough now that Xen supports sparse physical memory.

-- The gnttab_get_status_frames structure now uses a
GUEST_HANDLE(uint64_t) for the pointer to the status frames array, rather than a straight uint64_t.

The problems which these changes fix were all pointed out by Jan Beulich (thanks!).

Most of these patches are unchanged since last time, but I'm reposting all of them just to keep everything together. The only one with substantial changes is number 5:

changeset:   20275:842baf721920
tag:         introduce-grant_entry_v2
user:        Steven Smith <[email protected]>
date:        Mon Sep 22 12:23:28 2008 +0100
files:       tools/libxc/xc_linux.c tools/libxc/xc_offline_page.c tools/libxc/xenctrl.h xen/arch/x86/hvm/hvm.c xen/arch/x86/mm.c xen/common/compat/grant_table.c xen/common/grant_table.c xen/include/Makefile xen/include/asm-x86/grant_table.h xen/include/public/grant_table.h xen/include/public/memory.h xen/include/public/xen.h xen/include/xen/grant_table.h xen/include/xlat.lst

description:
Introduce a grant_entry_v2 structure.

There are also minor changes to the next two patches, mostly just compensating for renamed fields in structures.

I've also fixed up the Linux patch queues to match the new interface, but won't be posting the new queues, because they're rather large and have no substantial changes from last time. Instead, I've pushed the changed queues to the git repos:

git://xenbits.xensource.com/people/ssmith/nc2-2.6.27.git branch pq_for_merge (for the XCI 2.6.27 tree)

git://xenbits.xensource.com/people/ssmith/netchannel2-pvops.git branch nc2/fixed_v2_grant_table_interface (for the upstream git tree)

If people would prefer I repost the whole series then I can do that as well.

I think this should cover all of the review comments; please shout at me if I've missed anything.

Steven.

#1 lore raw

PATCH 1/1 Simplify include/xen/grant_table.h a bit:

# HG changeset patch
# User Steven Smith <[email protected]> # Date 1222082607 -3600
# Node ID 5f2f5565914573282437bb31f790ffac1169755c # Parent 6f63970032a3fe5fda585beba929d2d7a5e14861 Simplify include/xen/grant_table.h a bit:

-- INITIAL_GRANT_ENTRIES is never used, so can be removed. -- Simplify num_act_frames_from_sha_frames a little.

xen/include/xen/grant_table.h +7 -14
diff -r 6f63970032a3 -r 5f2f55659145 xen/include/xen/grant_table.h
@@ -52,10 +52,6 @@
 #define GNTPIN_devr_shift    (24)
 #define GNTPIN_devr_inc      (1 << GNTPIN_devr_shift)
 #define GNTPIN_devr_mask     (0xFFU << GNTPIN_devr_shift)
-
-/* Initial size of a grant table. */
-#define INITIAL_NR_GRANT_ENTRIES ((INITIAL_NR_GRANT_FRAMES << PAGE_SHIFT) / \
-                                     sizeof(grant_entry_t))
 
 #ifndef DEFAULT_MAX_NR_GRANT_FRAMES /* to allow arch to override */
 /* Default maximum size of a grant table. [POLICY] */
@@ -128,16 +124,13 @@
 num_act_frames_from_sha_frames(const unsigned int num)
 {
     /* How many frames are needed for the active grant table,
-     * given the size of the shared grant table?
-     *
-     * act_per_page = PAGE_SIZE / sizeof(active_grant_entry_t);
-     * sha_per_page = PAGE_SIZE / sizeof(grant_entry_t);
-     * num_sha_entries = num * sha_per_page;
-     * num_act_frames = (num_sha_entries + (act_per_page-1)) / act_per_page;
-     */
-    return ((num * (PAGE_SIZE / sizeof(grant_entry_t))) +
-            ((PAGE_SIZE / sizeof(struct active_grant_entry))-1))
-           / (PAGE_SIZE / sizeof(struct active_grant_entry));
+     * given the size of the shared grant table? */
+    unsigned act_per_page = PAGE_SIZE / sizeof(struct active_grant_entry);
+    unsigned sha_per_page = PAGE_SIZE / sizeof(grant_entry_t);
+    unsigned num_sha_entries = num * sha_per_page;
+    unsigned num_act_frames =
+        (num_sha_entries + (act_per_page-1)) / act_per_page;
+    return num_act_frames;
 }
 
 static inline unsigned int

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#2 lore raw

PATCH 1/1 Slightly more accurate dependency tracking for the .c and .h files in

In reply to [email protected]

# HG changeset patch
# User Steven Smith <[email protected]>
# Date 1222082607 -3600
# Node ID c630fa8e84bdb0e1a79f7ccc42733ef5ea247cd2
# Parent 5f2f5565914573282437bb31f790ffac1169755c Slightly more accurate dependency tracking for the .c and .h files in include/compat. They should depend on the scripts which generate them, as well as the inputs to those scripts.

xen/include/Makefile +2 -2
diff -r 5f2f55659145 -r c630fa8e84bd xen/include/Makefile
@@ -44,7 +44,7 @@
 .PHONY: all
 all: $(headers-y)
 
-compat/%.h: compat/%.i Makefile
+compat/%.h: compat/%.i Makefile $(BASEDIR)/tools/compat-build-header.py
 	set -e; id=_$$(echo $@ | tr '[:lower:]-/.' '[:upper:]___'); \
 	echo "#ifndef $$id" >[email protected]; \
 	echo "#define $$id" >>[email protected]; \
@@ -60,7 +60,7 @@
 compat/%.i: compat/%.c Makefile
 	$(CPP) $(filter-out -M% .%.d,$(CFLAGS)) $(cppflags-y) -o $@ $<
 
-compat/%.c: public/%.h xlat.lst Makefile
+compat/%.c: public/%.h xlat.lst Makefile $(BASEDIR)/tools/compat-build-source.py
 	mkdir -p $(@D)
 	grep -v 'DEFINE_XEN_GUEST_HANDLE(long)' $< | \
 	$(PYTHON) $(BASEDIR)/tools/compat-build-source.py >[email protected]

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#3 lore raw

PATCH 1/1 Optimize memcpy for x86 arch. If source buffers does not start at a 64

In reply to [email protected]

# HG changeset patch
# User [email protected]
# Date 1221082224 25200
# Node ID 999da363259a122e0c15bf28a0885ec40751e906
# Parent c630fa8e84bdb0e1a79f7ccc42733ef5ea247cd2
Optimize memcpy for x86 arch. If source buffers does not start at a 64 bit boundary, copy a few bytes at the beginnig up to next 64-bit boundary and then does an aligned copy for the remaining data. This can reduce the copy cost by up to 50%.

xen/include/asm-x86/string.h +17 -1
diff -r c630fa8e84bd -r 999da363259a xen/include/asm-x86/string.h
@@ -96,13 +96,29 @@
 }
 
 #define __HAVE_ARCH_MEMCPY
+/* align source to a 64-bit boundary */
+static always_inline
+void *__var_memcpy(void *t, const void *f, size_t n)
+{
+    int off = (unsigned long)f & 0x7;
+    /* just do alignment if needed and if size is worth */
+    if ( (n > 32) && off ) {
+        size_t n1 = 8 - off;
+        __variable_memcpy(t, f, n1);
+        __variable_memcpy(t + n1, f + n1, n - n1);
+        return t;
+    } else {
+            return (__variable_memcpy(t, f, n));
+    }
+}
+
 #define memcpy(t,f,n) (__memcpy((t),(f),(n)))
 static always_inline
 void *__memcpy(void *t, const void *f, size_t n)
 {
     return (__builtin_constant_p(n) ?
             __constant_memcpy((t),(f),(n)) :
-            __variable_memcpy((t),(f),(n)));
+            __var_memcpy((t),(f),(n)));
 }
 
 /* Some version of gcc don't have this builtin. It's non-critical anyway. */

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#4 lore raw

PATCH 1/1 Rename the struct grant_entry to struct grant_entry_v1, so that it

In reply to [email protected]

# HG changeset patch
# User Steven Smith <[email protected]>
# Date 1222082608 -3600
# Node ID 1df819bcf08654a2f23e88ce22295caf7806d65c
# Parent 999da363259a122e0c15bf28a0885ec40751e906 Rename the struct grant_entry to struct grant_entry_v1, so that it isn't in the way when we introduce struct grant_entry_v2.

tools/libxc/xc_linux.c +3 -3
diff -r 999da363259a -r 1df819bcf086 tools/libxc/xc_linux.c
@@ -558,14 +558,14 @@
     return ret;
 }
 
-struct grant_entry *xc_gnttab_map_table(int xc_handle, int domid, int *gnt_num)
+struct grant_entry_v1 *xc_gnttab_map_table(int xc_handle, int domid, int *gnt_num)
 {
     int rc, i;
     struct gnttab_query_size query;
     struct gnttab_setup_table setup;
     unsigned long *frame_list = NULL;
     xen_pfn_t *pfn_list = NULL;
-    struct grant_entry *gnt = NULL;
+    struct grant_entry_v1 *gnt = NULL;
 
     if (!gnt_num)
         return NULL;
@@ -581,7 +581,7 @@
     }
 
     *gnt_num = query.nr_frames *
-            (PAGE_SIZE / sizeof(struct grant_entry) );
+            (PAGE_SIZE / sizeof(struct grant_entry_v1) );
 
     frame_list = malloc(query.nr_frames * sizeof(unsigned long));
     if (!frame_list || lock_pages(frame_list, query.nr_frames *
tools/libxc/xc_offline_page.c +3 -3
diff -r 999da363259a -r 1df819bcf086 tools/libxc/xc_offline_page.c
@@ -133,7 +133,7 @@
   * There should no update to the grant when domain paused
   */
 static int xc_is_page_granted(int xc_handle, xen_pfn_t gpfn,
-                              struct grant_entry *gnttab, int gnt_num)
+                              struct grant_entry_v1 *gnttab, int gnt_num)
 {
     int i = 0;
 
@@ -549,7 +549,7 @@
     struct domain_mem_info minfo;
     struct xc_mmu *mmu = NULL;
     struct pte_backup old_ptes = {NULL, 0, 0};
-    struct grant_entry *gnttab = NULL;
+    struct grant_entry_v1 *gnttab = NULL;
     struct mmuext_op mops;
     int gnt_num, unpined = 0;
     void *old_p, *backup = NULL;
@@ -756,7 +756,7 @@
         free(backup);
 
     if (gnttab)
-        munmap(gnttab, gnt_num / (PAGE_SIZE/sizeof(struct grant_entry)));
+        munmap(gnttab, gnt_num / (PAGE_SIZE/sizeof(struct grant_entry_v1)));
 
     close_mem_info(xc_handle, &minfo);
 
tools/libxc/xenctrl.h +1 -1
diff -r 999da363259a -r 1df819bcf086 tools/libxc/xenctrl.h
@@ -943,7 +943,7 @@
 int xc_gnttab_op(int xc_handle, int cmd,
                  void * op, int op_size, int count);
 
-struct grant_entry *xc_gnttab_map_table(int xc_handle, int domid, int *gnt_num);
+struct grant_entry_v1 *xc_gnttab_map_table(int xc_handle, int domid, int *gnt_num);
 
 int xc_physdev_map_pirq(int xc_handle,
                         int domid,
xen/common/compat/grant_table.c +3 -3
diff -r 999da363259a -r 1df819bcf086 xen/common/compat/grant_table.c
@@ -5,9 +5,9 @@
 
 #include <compat/grant_table.h>
 
-#define xen_grant_entry grant_entry
-CHECK_grant_entry;
-#undef xen_grant_entry
+#define xen_grant_entry_v1 grant_entry_v1
+CHECK_grant_entry_v1;
+#undef xen_grant_entry_v1
 
 #define xen_gnttab_map_grant_ref gnttab_map_grant_ref
 CHECK_gnttab_map_grant_ref;
xen/common/grant_table.c +12 -12
diff -r 999da363259a -r 1df819bcf086 xen/common/grant_table.c
@@ -105,7 +105,7 @@
 }
 
 
-#define SHGNT_PER_PAGE (PAGE_SIZE / sizeof(grant_entry_t))
+#define SHGNT_PER_PAGE (PAGE_SIZE / sizeof(grant_entry_v1_t))
 #define shared_entry(t, e) \
     ((t)->shared[(e)/SHGNT_PER_PAGE][(e)%SHGNT_PER_PAGE])
 #define ACGNT_PER_PAGE (PAGE_SIZE / sizeof(struct active_grant_entry))
@@ -205,7 +205,7 @@
     unsigned int   cache_flags;
     struct active_grant_entry *act;
     struct grant_mapping *mt;
-    grant_entry_t *sha;
+    grant_entry_v1_t *sha;
     union grant_combo scombo, prev_scombo, new_scombo;
 
     /*
@@ -508,7 +508,7 @@
     domid_t          dom;
     struct domain   *ld, *rd;
     struct active_grant_entry *act;
-    grant_entry_t   *sha;
+    grant_entry_v1_t *sha;
     s16              rc = 0;
     u32              old_pin;
 
@@ -622,7 +622,7 @@
 {
     struct domain   *ld, *rd;
     struct active_grant_entry *act;
-    grant_entry_t   *sha;
+    grant_entry_v1_t *sha;
     struct page_info *pg;
 
     rd = op->rd;
@@ -1046,7 +1046,7 @@
     struct domain *rd, struct domain *ld, grant_ref_t ref)
 {
     struct grant_table *rgt;
-    struct grant_entry *sha;
+    struct grant_entry_v1 *sha;
     union grant_combo   scombo, prev_scombo, new_scombo;
     int                 retries = 0;
 
@@ -1115,7 +1115,7 @@
     struct domain *e;
     struct page_info *page;
     int i;
-    grant_entry_t *sha;
+    grant_entry_v1_t *sha;
     struct gnttab_transfer gop;
     unsigned long mfn;
     unsigned int max_bitsize;
@@ -1278,7 +1278,7 @@
 __release_grant_for_copy(
     struct domain *rd, unsigned long gref, int readonly)
 {
-    grant_entry_t *sha;
+    grant_entry_v1_t *sha;
     struct active_grant_entry *act;
     unsigned long r_frame;
 
@@ -1316,7 +1316,7 @@
     struct domain *rd, unsigned long gref, int readonly,
     unsigned long *frame)
 {
-    grant_entry_t *sha;
+    grant_entry_v1_t *sha;
     struct active_grant_entry *act;
     s16 rc = GNTST_okay;
     int retries = 0;
@@ -1654,7 +1654,7 @@
 
 static unsigned int max_nr_active_grant_frames(void)
 {
-    return (((max_nr_grant_frames * (PAGE_SIZE / sizeof(grant_entry_t))) + 
+    return (((max_nr_grant_frames * (PAGE_SIZE / sizeof(grant_entry_v1_t))) + 
                     ((PAGE_SIZE / sizeof(struct active_grant_entry))-1)) 
                    / (PAGE_SIZE / sizeof(struct active_grant_entry)));
 }
@@ -1667,7 +1667,7 @@
     int                 i;
 
     /* If this sizeof assertion fails, fix the function: shared_index */
-    ASSERT(sizeof(grant_entry_t) == 8);
+    ASSERT(sizeof(grant_entry_v1_t) == 8);
 
     if ( (t = xmalloc(struct grant_table)) == NULL )
         goto no_mem_0;
@@ -1703,7 +1703,7 @@
         t->maptrack[0][i].ref = i+1;
 
     /* Shared grant table. */
-    if ( (t->shared = xmalloc_array(struct grant_entry *,
+    if ( (t->shared = xmalloc_array(struct grant_entry_v1 *,
                                     max_nr_grant_frames)) == NULL )
         goto no_mem_3;
     memset(t->shared, 0, max_nr_grant_frames * sizeof(t->shared[0]));
@@ -1749,7 +1749,7 @@
     grant_handle_t        handle;
     struct domain        *rd;
     struct active_grant_entry *act;
-    struct grant_entry   *sha;
+    struct grant_entry_v1*sha;
     struct page_info     *pg;
 
     BUG_ON(!d->is_dying);
xen/include/public/grant_table.h +6 -2
diff -r 999da363259a -r 1df819bcf086 xen/include/public/grant_table.h
@@ -90,7 +90,11 @@
  * [XEN]: This field is written by Xen and read by the sharing guest.
  * [GST]: This field is written by the guest and read by Xen.
  */
-struct grant_entry {
+#if __XEN_INTERFACE_VERSION__ < 0x0003020a
+#define grant_entry_v1 grant_entry
+#define grant_entry_v1_t grant_entry_t
+#endif
+struct grant_entry_v1 {
     /* GTF_xxx: various type and flag information.  [XEN,GST] */
     uint16_t flags;
     /* The domain being granted foreign privileges. [GST] */
@@ -101,7 +105,7 @@
      */
     uint32_t frame;
 };
-typedef struct grant_entry grant_entry_t;
+typedef struct grant_entry_v1 grant_entry_v1_t;
 
 /*
  * Type of grant entry.
xen/include/public/xen-compat.h +1 -1
diff -r 999da363259a -r 1df819bcf086 xen/include/public/xen-compat.h
@@ -27,7 +27,7 @@
 #ifndef __XEN_PUBLIC_XEN_COMPAT_H__
 #define __XEN_PUBLIC_XEN_COMPAT_H__
 
-#define __XEN_LATEST_INTERFACE_VERSION__ 0x00030209
+#define __XEN_LATEST_INTERFACE_VERSION__ 0x0003020a
 
 #if defined(__XEN__) || defined(__XEN_TOOLS__)
 /* Xen is built with matching headers and implements the latest interface. */
xen/include/xen/grant_table.h +3 -3
diff -r 999da363259a -r 1df819bcf086 xen/include/xen/grant_table.h
@@ -80,7 +80,7 @@
     /* Table size. Number of frames shared with guest */
     unsigned int          nr_grant_frames;
     /* Shared grant table (see include/public/grant_table.h). */
-    struct grant_entry  **shared;
+    struct grant_entry_v1 **shared;
     /* Active grant table. */
     struct active_grant_entry **active;
     /* Mapping tracking table. */
@@ -117,7 +117,7 @@
 /* Number of grant table entries. Caller must hold d's grant table lock. */
 static inline unsigned int nr_grant_entries(struct grant_table *gt)
 {
-    return (nr_grant_frames(gt) << PAGE_SHIFT) / sizeof(grant_entry_t);
+    return (nr_grant_frames(gt) << PAGE_SHIFT) / sizeof(grant_entry_v1_t);
 }
 
 static inline unsigned int
@@ -126,7 +126,7 @@
     /* How many frames are needed for the active grant table,
      * given the size of the shared grant table? */
     unsigned act_per_page = PAGE_SIZE / sizeof(struct active_grant_entry);
-    unsigned sha_per_page = PAGE_SIZE / sizeof(grant_entry_t);
+    unsigned sha_per_page = PAGE_SIZE / sizeof(grant_entry_v1_t);
     unsigned num_sha_entries = num * sha_per_page;
     unsigned num_act_frames =
         (num_sha_entries + (act_per_page-1)) / act_per_page;
xen/include/xlat.lst +1 -1
diff -r 999da363259a -r 1df819bcf086 xen/include/xlat.lst
@@ -44,7 +44,7 @@
 !	gnttab_transfer			grant_table.h
 ?	gnttab_unmap_grant_ref		grant_table.h
 ?	gnttab_unmap_and_replace	grant_table.h
-?	grant_entry			grant_table.h
+?	grant_entry_v1			grant_table.h
 ?	kexec_exec			kexec.h
 !	kexec_image			kexec.h
 !	kexec_range			kexec.h

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#5 lore raw

PATCH 1/1 Introduce a grant_entry_v2 structure

In reply to [email protected]

# HG changeset patch
# User Steven Smith <[email protected]> # Date 1222082608 -3600
# Node ID 842baf721920b032f358ad326145817b42d053a1 # Parent 1df819bcf08654a2f23e88ce22295caf7806d65c Introduce a grant_entry_v2 structure.

tools/libxc/xc_linux.c +31 -1
diff -r 1df819bcf086 -r 842baf721920 tools/libxc/xc_linux.c
@@ -558,7 +558,21 @@
     return ret;
 }
 
-struct grant_entry_v1 *xc_gnttab_map_table(int xc_handle, int domid, int *gnt_num)
+int xc_gnttab_get_version(int xc_handle, int domid)
+{
+    struct gnttab_get_version query;
+    int rc;
+
+    query.dom = domid;
+    rc = xc_gnttab_op(xc_handle, GNTTABOP_get_version,
+                      &query, sizeof(query), 1);
+    if (rc < 0)
+        return rc;
+    else
+        return query.version;
+}
+
+static void *_gnttab_map_table(int xc_handle, int domid, int *gnt_num)
 {
     int rc, i;
     struct gnttab_query_size query;
@@ -638,6 +652,22 @@
     return gnt;
 }
 
+struct grant_entry_v1 *xc_gnttab_map_table_v1(int xc_handle, int domid,
+                                              int *gnt_num)
+{
+    if (xc_gnttab_get_version(xc_handle, domid) == 2)
+        return NULL;
+    return _gnttab_map_table(xc_handle, domid, gnt_num);
+}
+
+struct grant_entry_v2 *xc_gnttab_map_table_v2(int xc_handle, int domid,
+                                              int *gnt_num)
+{
+    if (xc_gnttab_get_version(xc_handle, domid) != 2)
+        return NULL;
+    return _gnttab_map_table(xc_handle, domid, gnt_num);
+}
+
 /*
  * Local variables:
  * mode: C
tools/libxc/xc_offline_page.c +35 -10

78 lines not on this page · raw message

tools/libxc/xenctrl.h +3 -1
diff -r 1df819bcf086 -r 842baf721920 tools/libxc/xenctrl.h
@@ -943,7 +943,9 @@
 int xc_gnttab_op(int xc_handle, int cmd,
                  void * op, int op_size, int count);
 
-struct grant_entry_v1 *xc_gnttab_map_table(int xc_handle, int domid, int *gnt_num);
+int xc_gnttab_get_version(int xc_handle, int domid);
+struct grant_entry_v1 *xc_gnttab_map_table_v1(int xc_handle, int domid, int *gnt_num);
+struct grant_entry_v2 *xc_gnttab_map_table_v2(int xc_handle, int domid, int *gnt_num);
 
 int xc_physdev_map_pirq(int xc_handle,
                         int domid,
xen/arch/x86/hvm/hvm.c +22 -9
diff -r 1df819bcf086 -r 842baf721920 xen/arch/x86/hvm/hvm.c
@@ -2084,12 +2084,26 @@
     return hvm_intblk_none;
 }
 
+static int grant_table_op_is_allowed(unsigned int cmd)
+{
+    switch (cmd) {
+    case GNTTABOP_query_size:
+    case GNTTABOP_setup_table:
+    case GNTTABOP_set_version:
+    case GNTTABOP_copy:
+    case GNTTABOP_map_grant_ref:
+    case GNTTABOP_unmap_grant_ref:
+        return 1;
+    default:
+        /* all other commands need auditing */
+        return 0;
+    }
+}
+
 static long hvm_grant_table_op(
     unsigned int cmd, XEN_GUEST_HANDLE(void) uop, unsigned int count)
 {
-    if ( (cmd != GNTTABOP_query_size) && (cmd != GNTTABOP_setup_table) &&
-         (cmd != GNTTABOP_map_grant_ref) && (cmd != GNTTABOP_unmap_grant_ref) &&
-         (cmd != GNTTABOP_copy))
+    if ( !grant_table_op_is_allowed(cmd) )
         return -ENOSYS; /* all other commands need auditing */
     return do_grant_table_op(cmd, uop, count);
 }
@@ -2141,13 +2155,12 @@
 
 #else /* defined(__x86_64__) */
 
-static long hvm_grant_table_op_compat32(
-    unsigned int cmd, XEN_GUEST_HANDLE(void) uop, unsigned int count)
+static long hvm_grant_table_op_compat32(unsigned int cmd,
+                                        XEN_GUEST_HANDLE(void) uop,
+                                        unsigned int count)
 {
-    if ( (cmd != GNTTABOP_query_size) && (cmd != GNTTABOP_setup_table) &&
-         (cmd != GNTTABOP_map_grant_ref) && (cmd != GNTTABOP_unmap_grant_ref) &&
-         (cmd != GNTTABOP_copy))
-        return -ENOSYS; /* all other commands need auditing */
+    if ( !grant_table_op_is_allowed(cmd) )
+        return -ENOSYS;
     return compat_grant_table_op(cmd, uop, count);
 }
 
xen/arch/x86/mm.c +19 -6
diff -r 1df819bcf086 -r 842baf721920 xen/arch/x86/mm.c
@@ -4000,12 +4000,25 @@
         case XENMAPSPACE_grant_table:
             spin_lock(&d->grant_table->lock);
 
-            if ( (xatp.idx >= nr_grant_frames(d->grant_table)) &&
-                 (xatp.idx < max_nr_grant_frames) )
-                gnttab_grow_table(d, xatp.idx + 1);
-
-            if ( xatp.idx < nr_grant_frames(d->grant_table) )
-                mfn = virt_to_mfn(d->grant_table->shared[xatp.idx]);
+            if ( d->grant_table->gt_version == 0 )
+                d->grant_table->gt_version = 1;
+
+            if ( d->grant_table->gt_version == 2 &&
+                 (xatp.idx & XENMAPIDX_grant_table_status) )
+            {
+                xatp.idx &= ~XENMAPIDX_grant_table_status;
+                if ( xatp.idx < nr_status_frames(d->grant_table) )
+                    mfn = virt_to_mfn(d->grant_table->status[xatp.idx]);
+            }
+            else
+            {
+                if ( (xatp.idx >= nr_grant_frames(d->grant_table)) &&
+                     (xatp.idx < max_nr_grant_frames) )
+                    gnttab_grow_table(d, xatp.idx + 1);
+
+                if ( xatp.idx < nr_grant_frames(d->grant_table) )
+                    mfn = virt_to_mfn(d->grant_table->shared_raw[xatp.idx]);
+            }
 
             spin_unlock(&d->grant_table->lock);
             break;
xen/common/compat/grant_table.c +81 -0

116 lines not on this page · raw message

xen/common/grant_table.c +565 -148

983 lines not on this page · raw message

xen/include/Makefile +1 -1
diff -r 1df819bcf086 -r 842baf721920 xen/include/Makefile
@@ -58,7 +58,7 @@
 	mv -f [email protected] $@
 
 compat/%.i: compat/%.c Makefile
-	$(CPP) $(filter-out -M% .%.d,$(CFLAGS)) $(cppflags-y) -o $@ $<
+	$(CPP) -include public/xen-compat.h $(filter-out -M% .%.d,$(CFLAGS)) $(cppflags-y) -o $@ $<
 
 compat/%.c: public/%.h xlat.lst Makefile $(BASEDIR)/tools/compat-build-source.py
 	mkdir -p $(@D)
xen/include/asm-x86/grant_table.h +17 -2
diff -r 1df819bcf086 -r 842baf721920 xen/include/asm-x86/grant_table.h
@@ -21,15 +21,30 @@
 #define gnttab_create_shared_page(d, t, i)                               \
     do {                                                                 \
         share_xen_page_with_guest(                                       \
-            virt_to_page((char *)(t)->shared[i]),                        \
+            virt_to_page((char *)(t)->shared_raw[i]),                    \
             (d), XENSHARE_writable);                                     \
     } while ( 0 )
 
+#define gnttab_create_status_page(d, t, i)                               \
+    do {                                                                 \
+        share_xen_page_with_guest(                                       \
+           virt_to_page((char *)(t)->status[i]),                         \
+            (d), XENSHARE_writable);                                     \
+    } while ( 0 )
+
+
 #define gnttab_shared_mfn(d, t, i)                      \
-    ((virt_to_maddr((t)->shared[i]) >> PAGE_SHIFT))
+    ((virt_to_maddr((t)->shared_raw[i]) >> PAGE_SHIFT))
 
 #define gnttab_shared_gmfn(d, t, i)                     \
     (mfn_to_gmfn(d, gnttab_shared_mfn(d, t, i)))
+
+
+#define gnttab_status_mfn(d, t, i)                      \
+    ((virt_to_maddr((t)->status[i]) >> PAGE_SHIFT))
+
+#define gnttab_status_gmfn(d, t, i)                     \
+    (mfn_to_gmfn(d, gnttab_status_mfn(d, t, i)))
 
 #define gnttab_mark_dirty(d, f) paging_mark_dirty((d), (f))
 
xen/include/public/grant_table.h +111 -0

129 lines not on this page · raw message

xen/include/public/memory.h +2 -0
diff -r 1df819bcf086 -r 842baf721920 xen/include/public/memory.h
@@ -211,6 +211,8 @@
 #define XENMAPSPACE_gmfn        2 /* GMFN */
     unsigned int space;
 
+#define XENMAPIDX_grant_table_status 0x80000000
+
     /* Index into source mapping space. */
     xen_ulong_t idx;
 
xen/include/public/xen.h +1 -0
diff -r 1df819bcf086 -r 842baf721920 xen/include/public/xen.h
@@ -47,6 +47,7 @@
 __DEFINE_XEN_GUEST_HANDLE(ulong, unsigned long);
 DEFINE_XEN_GUEST_HANDLE(void);
 
+DEFINE_XEN_GUEST_HANDLE(uint64_t);
 DEFINE_XEN_GUEST_HANDLE(xen_pfn_t);
 #endif
 
xen/include/xen/grant_table.h +24 -4
diff -r 1df819bcf086 -r 842baf721920 xen/include/xen/grant_table.h
@@ -80,7 +80,15 @@
     /* Table size. Number of frames shared with guest */
     unsigned int          nr_grant_frames;
     /* Shared grant table (see include/public/grant_table.h). */
-    struct grant_entry_v1 **shared;
+    union {
+        void **shared_raw;
+        struct grant_entry_v1 **shared_v1;
+        union grant_entry_v2 **shared_v2;
+    };
+    /* Number of grant status frames shared with guest (for version 2) */
+    unsigned int          nr_status_frames;
+    /* State grant table (see include/public/grant_table.h). */
+    grant_status_t       **status;
     /* Active grant table. */
     struct active_grant_entry **active;
     /* Mapping tracking table. */
@@ -89,6 +97,9 @@
     unsigned int          maptrack_limit;
     /* Lock protecting updates to active and shared grant tables. */
     spinlock_t            lock;
+    /* The defined versions are 1 and 2.  Set to 0 if we don't know
+       what version to use yet. */
+    unsigned              gt_version;
 };
 
 /* Create/destroy per-domain grant table context. */
@@ -114,10 +125,19 @@
     return gt->nr_grant_frames;
 }
 
-/* Number of grant table entries. Caller must hold d's grant table lock. */
-static inline unsigned int nr_grant_entries(struct grant_table *gt)
+/* Number of status grant table frames. Caller must hold d's gr. table lock.*/
+static inline unsigned int nr_status_frames(struct grant_table *gt)
 {
-    return (nr_grant_frames(gt) << PAGE_SHIFT) / sizeof(grant_entry_v1_t);
+    return gt->nr_status_frames;
+}
+
+#define GRANT_STATUS_PER_PAGE (PAGE_SIZE / sizeof(grant_status_t))
+#define GRANT_PER_PAGE (PAGE_SIZE / sizeof(grant_entry_v2_t))
+/* Number of grant table status entries. Caller must hold d's gr. table lock.*/
+static inline unsigned int grant_to_status_frames(int grant_frames)
+{
+    return (grant_frames * GRANT_PER_PAGE + GRANT_STATUS_PER_PAGE - 1) /
+        GRANT_STATUS_PER_PAGE;
 }
 
 static inline unsigned int
xen/include/xlat.lst +5 -0
diff -r 1df819bcf086 -r 842baf721920 xen/include/xlat.lst
@@ -44,7 +44,12 @@
 !	gnttab_transfer			grant_table.h
 ?	gnttab_unmap_grant_ref		grant_table.h
 ?	gnttab_unmap_and_replace	grant_table.h
+?	gnttab_set_version		grant_table.h
+?	gnttab_get_version		grant_table.h
+!	gnttab_get_status_frames	grant_table.h
 ?	grant_entry_v1			grant_table.h
+?       grant_entry_header              grant_table.h
+?	grant_entry_v2			grant_table.h
 ?	kexec_exec			kexec.h
 !	kexec_image			kexec.h
 !	kexec_range			kexec.h

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#6 lore raw

PATCH 1/1 Implement sub-page grant support

In reply to [email protected]

# HG changeset patch
# User Steven Smith <[email protected]> # Date 1222085347 -3600
# Node ID e9b623fd710f2130bcb925161abe26c6980b91c3 # Parent 842baf721920b032f358ad326145817b42d053a1 Implement sub-page grant support.

xen/common/grant_table.c +62 -10
diff -r 842baf721920 -r e9b623fd710f xen/common/grant_table.c
@@ -210,6 +210,7 @@
 
 static int _set_status_v1(domid_t  domid,
                           int readonly,
+                          int mapflag,
                           grant_entry_header_t *shah, 
                           struct active_grant_entry *act)
 {
@@ -226,6 +227,11 @@
      * so we allow a few retries before failing.
      */
     int retries = 0;
+
+    /* if this is a grant mapping operation we should ensure GTF_sub_page
+       is not set */
+    if (mapflag)
+        mask |= GTF_sub_page;
 
     scombo.word = *(u32 *)shah;
 
@@ -276,6 +282,7 @@
 
 static int _set_status_v2(domid_t  domid,
                           int readonly,
+                          int mapflag,
                           grant_entry_header_t *shah, 
                           struct active_grant_entry *act,
                           grant_status_t *status)
@@ -294,6 +301,11 @@
                   it back into two reads */
     flags = scombo.shorts.flags;
     id = scombo.shorts.domid;
+
+    /* if this is a grant mapping operation we should ensure GTF_sub_page
+       is not set */
+    if (mapflag)
+        mask |= GTF_sub_page;
 
     /* If not already pinned, check the grant domid and type. */
     if ( !act->pin &&
@@ -355,15 +367,16 @@
 static int _set_status(unsigned gt_version,
                        domid_t  domid,
                        int readonly,
+                       int mapflag,
                        grant_entry_header_t *shah,
                        struct active_grant_entry *act,
                        grant_status_t *status)
 {
 
     if (gt_version == 1)
-        return _set_status_v1(domid, readonly, shah, act);
+        return _set_status_v1(domid, readonly, mapflag, shah, act);
     else
-        return _set_status_v2(domid, readonly, shah, act, status);
+        return _set_status_v2(domid, readonly, mapflag, shah, act, status);
 }
 
 /*
@@ -460,10 +473,11 @@
     /* If already pinned, check the active domid and avoid refcnt overflow. */
     if ( act->pin &&
          ((act->domid != ld->domain_id) ||
-          (act->pin & 0x80808080U) != 0) )
+          (act->pin & 0x80808080U) != 0 ||
+          (act->is_sub_page)) )
         PIN_FAIL(unlock_out, GNTST_general_error,
-                 "Bad domain (%d != %d), or risk of counter overflow %08x\n",
-                 act->domid, ld->domain_id, act->pin);
+                 "Bad domain (%d != %d), or risk of counter overflow %08x, or subpage %d\n",
+                 act->domid, ld->domain_id, act->pin, act->is_sub_page);
 
     if ( !act->pin ||
          (!(op->flags & GNTMAP_readonly) &&
@@ -471,7 +485,7 @@
     {
         if ( (rc = _set_status(rd->grant_table->gt_version,
                                ld->domain_id, op->flags & GNTMAP_readonly,
-                               shah, act, status) ) != GNTST_okay )
+                               1, shah, act, status) ) != GNTST_okay )
              goto unlock_out;
 
         if ( !act->pin )
@@ -482,6 +496,9 @@
             else
                 act->gfn = sha2->full_page.frame;
             act->frame = gmfn_to_mfn(rd, act->gfn);
+            act->start = 0;
+            act->length = PAGE_SIZE;
+            act->is_sub_page = 0;
         }
     }
 
@@ -1554,7 +1571,7 @@
 static int
 __acquire_grant_for_copy(
     struct domain *rd, unsigned long gref, int readonly,
-    unsigned long *frame)
+    unsigned long *frame, unsigned *page_off, unsigned *length)
 {
     grant_entry_v1_t *sha1;
     grant_entry_v2_t *sha2;
@@ -1601,21 +1618,40 @@
     {
         if ( (rc = _set_status(rd->grant_table->gt_version,
                                current->domain->domain_id, 
-                               readonly, shah, act, status) ) != GNTST_okay )
+                               readonly, 0, shah, act, status) ) != GNTST_okay )
              goto unlock_out;
+
         if ( !act->pin )
         {
             act->domid = current->domain->domain_id;
+            act->is_sub_page = 0;
+            act->start = 0;
+            act->length = PAGE_SIZE;
+
             if ( sha1 )
+            {
                 act->gfn = sha1->frame;
+            }
+            else if ( shah->flags & GTF_sub_page )
+            {
+                act->start = sha2->sub_page.page_off;
+                act->length = sha2->sub_page.length;
+                act->is_sub_page = 1;
+                act->gfn = sha2->sub_page.frame;
+            }
             else
+            {
                 act->gfn = sha2->full_page.frame;
+            }
+
             act->frame = gmfn_to_mfn(rd, act->gfn);
         }
     }
 
     act->pin += readonly ? GNTPIN_hstr_inc : GNTPIN_hstw_inc;
 
+    *page_off = act->start;
+    *length = act->length;
     *frame = act->frame;
 
  unlock_out:
@@ -1667,10 +1703,18 @@
 
     if ( src_is_gref )
     {
-        rc = __acquire_grant_for_copy(sd, op->source.u.ref, 1, &s_frame);
+        unsigned source_off, source_len;
+        rc = __acquire_grant_for_copy(sd, op->source.u.ref, 1, &s_frame,
+                                      &source_off, &source_len);
         if ( rc != GNTST_okay )
             goto error_out;
         have_s_grant = 1;
+        if ( op->source.offset < source_off ||
+             op->len > source_len )
+            PIN_FAIL(error_out, GNTST_general_error,
+                     "copy source out of bounds: %d < %d || %d > %d\n",
+                     op->source.offset, source_off,
+                     op->len, source_len);
     }
     else
     {
@@ -1690,10 +1734,18 @@
 
     if ( dest_is_gref )
     {
-        rc = __acquire_grant_for_copy(dd, op->dest.u.ref, 0, &d_frame);
+        unsigned dest_off, dest_len;
+        rc = __acquire_grant_for_copy(dd, op->dest.u.ref, 0, &d_frame,
+                                      &dest_off, &dest_len);
         if ( rc != GNTST_okay )
             goto error_out;
         have_d_grant = 1;
+        if ( op->dest.offset < dest_off ||
+             op->len > dest_len )
+            PIN_FAIL(error_out, GNTST_general_error,
+                     "copy dest out of bounds: %d < %d || %d > %d\n",
+                     op->dest.offset, dest_off,
+                     op->len, dest_len);
     }
     else
     {
xen/include/public/grant_table.h +17 -0
diff -r 842baf721920 -r e9b623fd710f xen/include/public/grant_table.h
@@ -130,6 +130,9 @@
  *  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       (2)
 #define GTF_readonly        (1U<<_GTF_readonly)
@@ -143,6 +146,8 @@
 #define GTF_PCD             (1U<<_GTF_PCD)
 #define _GTF_PAT            (7)
 #define GTF_PAT             (1U<<_GTF_PAT)
+#define _GTF_sub_page       (8)
+#define GTF_sub_page        (1U<<_GTF_sub_page)
 
 /*
  * Subflags for GTF_accept_transfer:
@@ -200,6 +205,18 @@
         uint32_t pad0;
         uint64_t frame;
     } full_page;
+
+    /*
+     * If the grant type is GTF_grant_access and GTF_sub_page is set,
+     * @domid is allowed to access bytes [@page_off,@page_off+@length)
+     * in frame @frame.
+     */
+    struct {
+        grant_entry_header_t hdr;
+        uint16_t page_off;
+        uint16_t length;
+        uint64_t frame;
+    } sub_page;
 
     uint32_t __spacer[4]; /* Pad to a power of two */
 };
xen/include/xen/grant_table.h +8 -3
diff -r 842baf721920 -r e9b623fd710f xen/include/xen/grant_table.h
@@ -30,10 +30,15 @@
 
 /* Active grant entry - used for shadowing GTF_permit_access grants. */
 struct active_grant_entry {
-    u32           pin;    /* Reference count information.  */
-    domid_t       domid;  /* Domain being granted access.  */
+    u32           pin;    /* Reference count information.             */
+    domid_t       domid;  /* Domain being granted access.             */
+    unsigned long frame;  /* Frame being granted.                     */
     unsigned long gfn;    /* Guest's idea of the frame being granted. */
-    unsigned long frame;  /* Frame being granted.          */
+    unsigned      is_sub_page:1; /* True if this is a sub-page grant. */
+    unsigned      start:15; /* For sub-page grants, the start offset
+                               in the page.                           */
+    unsigned      length:16; /* For sub-page grants, the length of the
+                                grant.                                */
 };
 
  /* Count of writable host-CPU mappings. */

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#7 lore raw

PATCH 1/1 Transitive grant support

In reply to [email protected]

# HG changeset patch
# User Steven Smith <[email protected]> # Date 1227887022 0
# Node ID dfa92594086745b0fac52f07c3727a1e9061eb6a # Parent e9b623fd710f2130bcb925161abe26c6980b91c3 Transitive grant support.

xen/common/grant_table.c +196 -38
diff -r e9b623fd710f -r dfa925940867 xen/common/grant_table.c
@@ -309,11 +309,12 @@
 
     /* If not already pinned, check the grant domid and type. */
     if ( !act->pin &&
-         (((flags & mask) != GTF_permit_access) ||
+         ( (((flags & mask) != GTF_permit_access) &&
+            ((flags & mask) != GTF_transitive)) ||
           (id != domid)) )
         PIN_FAIL(done, GNTST_general_error,
-                 "Bad flags (%x) or dom (%d). (expected dom %d)\n",
-                 flags, id, domid);
+                 "Bad flags (%x) or dom (%d). (expected dom %d, flags %x)\n",
+                 flags, id, domid, mask);
 
     if ( readonly )
     {
@@ -338,7 +339,8 @@
 
     if ( !act->pin )
     {
-        if ( ((flags & mask) != GTF_permit_access) ||
+        if ( (((flags & mask) != GTF_permit_access) &&
+              ((flags & mask) != GTF_transitive)) ||
              (id != domid) ||
              (!readonly && (flags & GTF_readonly)) )
         {
@@ -1533,6 +1535,14 @@
     struct active_grant_entry *act;
     unsigned long r_frame;
     uint16_t *status;
+    domid_t trans_domid;
+    grant_ref_t trans_gref;
+    int released_read;
+    int released_write;
+    struct domain *trans_dom;
+
+    released_read = 0;
+    released_write = 0;
 
     spin_lock(&rd->grant_table->lock);
 
@@ -1541,9 +1551,19 @@
     r_frame = act->frame;
 
     if (rd->grant_table->gt_version == 1)
+    {
         status = &sha->flags;
+        trans_domid = rd->domain_id;
+        /* Shut the compiler up.  This'll never be used, because
+           trans_domid == rd->domain_id, but gcc doesn't know that. */
+        trans_gref = 0x1234567;
+    }
     else
+    {
         status = &status_entry(rd->grant_table, gref);
+        trans_domid = act->trans_dom;
+        trans_gref = act->trans_gref;
+    }
 
     if ( readonly )
     {
@@ -1555,13 +1575,51 @@
 
         act->pin -= GNTPIN_hstw_inc;
         if ( !(act->pin & (GNTPIN_devw_mask|GNTPIN_hstw_mask)) )
+        {
+            released_write = 1;
             gnttab_clear_flag(_GTF_writing, status);
+        }
     }
 
     if ( !act->pin )
+    {
         gnttab_clear_flag(_GTF_reading, status);
+        released_read = 1;
+    }
 
     spin_unlock(&rd->grant_table->lock);
+
+    if ( trans_domid != rd->domain_id )
+    {
+        if ( released_write || released_read )
+        {
+            trans_dom = rcu_lock_domain_by_id(trans_domid);
+            if ( trans_dom != NULL )
+            {
+                /* Recursive calls, but they're tail calls, so it's
+                   okay. */
+                if ( released_write )
+                    __release_grant_for_copy(trans_dom, trans_gref, 0);
+                else if ( released_read )
+                    __release_grant_for_copy(trans_dom, trans_gref, 1);
+            }
+        }
+    }
+}
+
+/* The status for a grant indicates that we're taking more access than
+   the pin requires.  Fix up the status to match the pin.  Called
+   under the domain's grant table lock. */
+/* Only safe on transitive grants.  Even then, note that we don't
+   attempt to drop any pin on the referent grant. */
+static void __fixup_status_for_pin(struct active_grant_entry *act,
+                                   uint16_t *status)
+{
+    if ( !(act->pin & GNTPIN_hstw_mask) )
+        *status &= ~_GTF_writing;
+
+    if ( !(act->pin & GNTPIN_hstr_mask) )
+        *status &= ~_GTF_reading;
 }
 
 /* Grab a frame number from a grant entry and update the flags and pin
@@ -1570,15 +1628,27 @@
    actually valid. */
 static int
 __acquire_grant_for_copy(
-    struct domain *rd, unsigned long gref, int readonly,
-    unsigned long *frame, unsigned *page_off, unsigned *length)
+    struct domain *rd, unsigned long gref, struct domain *ld, int readonly,
+    unsigned long *frame, unsigned *page_off, unsigned *length,
+    unsigned allow_transitive, struct domain **owning_domain)
 {
     grant_entry_v1_t *sha1;
     grant_entry_v2_t *sha2;
     grant_entry_header_t *shah;
     struct active_grant_entry *act;
     grant_status_t *status;
+    uint32_t old_pin;
+    domid_t trans_domid;
+    grant_ref_t trans_gref;
+    struct domain *rrd;
+    unsigned long grant_frame;
+    unsigned trans_page_off;
+    unsigned trans_length;
+    int is_sub_page;
+    struct domain *ignore;
     s16 rc = GNTST_okay;
+
+    *owning_domain = NULL;
 
     spin_lock(&rd->grant_table->lock);
 
@@ -1607,45 +1677,127 @@
 
     /* If already pinned, check the active domid and avoid refcnt overflow. */
     if ( act->pin &&
-         ((act->domid != current->domain->domain_id) ||
+         ((act->domid != ld->domain_id) ||
           (act->pin & 0x80808080U) != 0) )
         PIN_FAIL(unlock_out, GNTST_general_error,
                  "Bad domain (%d != %d), or risk of counter overflow %08x\n",
-                 act->domid, current->domain->domain_id, act->pin);
+                 act->domid, ld->domain_id, act->pin);
 
+    old_pin = act->pin;
     if ( !act->pin ||
          (!readonly && !(act->pin & (GNTPIN_devw_mask|GNTPIN_hstw_mask))) )
     {
         if ( (rc = _set_status(rd->grant_table->gt_version,
-                               current->domain->domain_id, 
-                               readonly, 0, shah, act, status) ) != GNTST_okay )
+                               ld->domain_id,
+                               readonly, 0, shah, act,
+                               status) ) != GNTST_okay )
              goto unlock_out;
+
+        trans_domid = ld->domain_id;
+        trans_gref = 0;
+        if ( sha2 && (shah->flags & GTF_type_mask) == GTF_transitive )
+        {
+            if ( !allow_transitive )
+                PIN_FAIL(unlock_out, GNTST_general_error,
+                         "transitive grant when transitivity not allowed\n");
+
+            trans_domid = sha2->transitive.trans_domid;
+            trans_gref = sha2->transitive.gref;
+            barrier(); /* Stop the compiler from re-loading
+                          trans_domid from shared memory */
+            if ( trans_domid == rd->domain_id )
+                PIN_FAIL(unlock_out, GNTST_general_error,
+                         "transitive grants cannot be self-referential\n");
+
+            /* We allow the trans_domid == ld->domain_id case, which
+               corresponds to a grant being issued by one domain, sent
+               to another one, and then transitively granted back to
+               the original domain.  Allowing it is easy, and means
+               that you don't need to go out of your way to avoid it
+               in the guest. */
+
+            rrd = rcu_lock_domain_by_id(trans_domid);
+            if ( rrd == NULL )
+                PIN_FAIL(unlock_out, GNTST_general_error,
+                         "transitive grant referenced bad domain %d\n",
+                         trans_domid);
+            spin_unlock(&rd->grant_table->lock);
+
+            rc = __acquire_grant_for_copy(rrd, trans_gref, rd,
+                                          readonly, &grant_frame,
+                                          &trans_page_off, &trans_length,
+                                          0, &ignore);
+
+            spin_lock(&rd->grant_table->lock);
+            if ( rc != GNTST_okay ) {
+                __fixup_status_for_pin(act, status);
+                spin_unlock(&rd->grant_table->lock);
+                return rc;
+            }
+
+            /* We dropped the lock, so we have to check that nobody
+               else tried to pin (or, for that matter, unpin) the
+               reference in *this* domain.  If they did, just give up
+               and try again. */
+            if ( act->pin != old_pin )
+            {
+                __fixup_status_for_pin(act, status);
+                spin_unlock(&rd->grant_table->lock);
+                return __acquire_grant_for_copy(rd, gref, ld, readonly,
+                                                frame, page_off, length,
+                                                allow_transitive,
+                                                owning_domain);
+            }
+
+            /* The actual remote remote grant may or may not be a
+               sub-page, but we always treat it as one because that
+               blocks mappings of transitive grants. */
+            is_sub_page = 1;
+            *owning_domain = rrd;
+            act->gfn = INVALID_GFN;
+        }
+        else if ( sha1 )
+        {
+            act->gfn = sha1->frame;
+            grant_frame = gmfn_to_mfn(rd, act->gfn);
+            is_sub_page = 0;
+            trans_page_off = 0;
+            trans_length = PAGE_SIZE;
+            *owning_domain = rd;
+        }
+        else if ( !(sha2->hdr.flags & GTF_sub_page) )
+        {
+            act->gfn = sha2->full_page.frame;
+            grant_frame = gmfn_to_mfn(rd, act->gfn);
+            is_sub_page = 0;
+            trans_page_off = 0;
+            trans_length = PAGE_SIZE;
+            *owning_domain = rd;
+        }
+        else
+        {
+            act->gfn = sha2->sub_page.frame;
+            grant_frame = gmfn_to_mfn(rd, act->gfn);
+            is_sub_page = 1;
+            trans_page_off = sha2->sub_page.page_off;
+            trans_length = sha2->sub_page.length;
+            *owning_domain = rd;
+        }
 
         if ( !act->pin )
         {
-            act->domid = current->domain->domain_id;
-            act->is_sub_page = 0;
-            act->start = 0;
-            act->length = PAGE_SIZE;
-
-            if ( sha1 )
-            {
-                act->gfn = sha1->frame;
-            }
-            else if ( shah->flags & GTF_sub_page )
-            {
-                act->start = sha2->sub_page.page_off;
-                act->length = sha2->sub_page.length;
-                act->is_sub_page = 1;
-                act->gfn = sha2->sub_page.frame;
-            }
-            else
-            {
-                act->gfn = sha2->full_page.frame;
-            }
-
-            act->frame = gmfn_to_mfn(rd, act->gfn);
+            act->domid = ld->domain_id;
+            act->is_sub_page = is_sub_page;
+            act->start = trans_page_off;
+            act->length = trans_length;
+            act->trans_dom = trans_domid;
+            act->trans_gref = trans_gref;
+            act->frame = grant_frame;
         }
+    }
+    else
+    {
+        *owning_domain = rd;
     }
 
     act->pin += readonly ? GNTPIN_hstr_inc : GNTPIN_hstw_inc;
@@ -1664,6 +1816,7 @@
     struct gnttab_copy *op)
 {
     struct domain *sd = NULL, *dd = NULL;
+    struct domain *source_domain = NULL, *dest_domain = NULL;
     unsigned long s_frame, d_frame;
     char *sp, *dp;
     s16 rc = GNTST_okay;
@@ -1704,8 +1857,9 @@
     if ( src_is_gref )
     {
         unsigned source_off, source_len;
-        rc = __acquire_grant_for_copy(sd, op->source.u.ref, 1, &s_frame,
-                                      &source_off, &source_len);
+        rc = __acquire_grant_for_copy(sd, op->source.u.ref, current->domain, 1,
+                                      &s_frame, &source_off, &source_len, 1,
+                                      &source_domain);
         if ( rc != GNTST_okay )
             goto error_out;
         have_s_grant = 1;
@@ -1719,11 +1873,12 @@
     else
     {
         s_frame = gmfn_to_mfn(sd, op->source.u.gmfn);
+        source_domain = sd;
     }
     if ( unlikely(!mfn_valid(s_frame)) )
         PIN_FAIL(error_out, GNTST_general_error,
                  "source frame %lx invalid.\n", s_frame);
-    if ( !get_page(mfn_to_page(s_frame), sd) )
+    if ( !get_page(mfn_to_page(s_frame), source_domain) )
     {
         if ( !sd->is_dying )
             gdprintk(XENLOG_WARNING, "Could not get src frame %lx\n", s_frame);
@@ -1735,8 +1890,9 @@
     if ( dest_is_gref )
     {
         unsigned dest_off, dest_len;
-        rc = __acquire_grant_for_copy(dd, op->dest.u.ref, 0, &d_frame,
-                                      &dest_off, &dest_len);
+        rc = __acquire_grant_for_copy(dd, op->dest.u.ref, current->domain, 0,
+                                      &d_frame, &dest_off, &dest_len, 1,
+                                      &dest_domain);
         if ( rc != GNTST_okay )
             goto error_out;
         have_d_grant = 1;
@@ -1750,11 +1906,13 @@
     else
     {
         d_frame = gmfn_to_mfn(dd, op->dest.u.gmfn);
+        dest_domain = dd;
     }
     if ( unlikely(!mfn_valid(d_frame)) )
         PIN_FAIL(error_out, GNTST_general_error,
                  "destination frame %lx invalid.\n", d_frame);
-    if ( !get_page_and_type(mfn_to_page(d_frame), dd, PGT_writable_page) )
+    if ( !get_page_and_type(mfn_to_page(d_frame), dest_domain,
+                            PGT_writable_page) )
     {
         if ( !dd->is_dying )
             gdprintk(XENLOG_WARNING, "Could not get dst frame %lx\n", d_frame);
xen/include/public/grant_table.h +24 -5
diff -r e9b623fd710f -r dfa925940867 xen/include/public/grant_table.h
@@ -85,6 +85,11 @@
  */
 
 /*
+ * Reference to a grant entry in a specified domain's grant table.
+ */
+typedef uint32_t grant_ref_t;
+
+/*
  * A grant table comprises a packed array of grant entries in one or more
  * page frames shared between Xen and a guest.
  * [XEN]: This field is written by Xen and read by the sharing guest.
@@ -118,10 +123,13 @@
  *  GTF_permit_access: Allow @domid to map/access @frame.
  *  GTF_accept_transfer: Allow @domid to transfer ownership of one page frame
  *                       to this guest. Xen writes the page number to @frame.
+ *  GTF_transitive: Allow @domid to transitively access a subrange of
+ *                  @trans_grant in @trans_domid.  No mappings are allowed.
  */
 #define GTF_invalid         (0U<<0)
 #define GTF_permit_access   (1U<<0)
 #define GTF_accept_transfer (2U<<0)
+#define GTF_transitive      (3U<<0)
 #define GTF_type_mask       (3U<<0)
 
 /*
@@ -218,6 +226,22 @@
         uint64_t frame;
     } sub_page;
 
+    /*
+     * If the grant is GTF_transitive, @domid is allowed to use the
+     * grant @gref in domain @trans_domid, as if it was the local
+     * domain.  Obviously, the transitive access must be compatible
+     * with the original grant.
+     *
+     * The current version of Xen does not allow transitive grants
+     * to be mapped.
+     */
+    struct {
+        grant_entry_header_t hdr;
+        domid_t trans_domid;
+        uint16_t pad0;
+        grant_ref_t gref;
+    } transitive;
+
     uint32_t __spacer[4]; /* Pad to a power of two */
 };
 typedef union grant_entry_v2 grant_entry_v2_t;
@@ -229,11 +253,6 @@
 /***********************************
  * GRANT TABLE QUERIES AND USES
  */
-
-/*
- * Reference to a grant entry in a specified domain's grant table.
- */
-typedef uint32_t grant_ref_t;
 
 /*
  * Handle to track a mapping created via a grant reference.
xen/include/xen/grant_table.h +2 -0
diff -r e9b623fd710f -r dfa925940867 xen/include/xen/grant_table.h
@@ -32,6 +32,8 @@
 struct active_grant_entry {
     u32           pin;    /* Reference count information.             */
     domid_t       domid;  /* Domain being granted access.             */
+    domid_t       trans_dom;
+    uint32_t      trans_gref;
     unsigned long frame;  /* Frame being granted.                     */
     unsigned long gfn;    /* Guest's idea of the frame being granted. */
     unsigned      is_sub_page:1; /* True if this is a sub-page grant. */

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#8 lore raw

PATCH 1/1 Tools-side support for creating and destroying netchannel2 interfaces

In reply to [email protected]

# HG changeset patch
# User Steven Smith <[email protected]>
# Date 1222085454 -3600
# Node ID fe10d9d213ebdd43ef0c1d74689db8afec6c8494
# Parent dfa92594086745b0fac52f07c3727a1e9061eb6a Tools-side support for creating and destroying netchannel2 interfaces.

tools/hotplug/Linux/Makefile +1 -0
diff -r dfa925940867 -r fe10d9d213eb tools/hotplug/Linux/Makefile
@@ -11,6 +11,7 @@
 XEN_SCRIPTS = network-bridge vif-bridge
 XEN_SCRIPTS += network-route vif-route
 XEN_SCRIPTS += network-nat vif-nat
+XEN_SCRIPTS += vif2
 XEN_SCRIPTS += block
 XEN_SCRIPTS += block-enbd block-nbd
 XEN_SCRIPTS += blktap
tools/hotplug/Linux/vif2 new file +46 -0

46 lines not on this page · raw message

tools/hotplug/Linux/xen-backend.rules +3 -2
diff -r dfa925940867 -r fe10d9d213eb tools/hotplug/Linux/xen-backend.rules
@@ -1,8 +1,9 @@
 SUBSYSTEM=="xen-backend", KERNEL=="tap*", RUN+="/etc/xen/scripts/blktap $env{ACTION}"
 SUBSYSTEM=="xen-backend", KERNEL=="vbd*", RUN+="/etc/xen/scripts/block $env{ACTION}"
 SUBSYSTEM=="xen-backend", KERNEL=="vtpm*", RUN+="/etc/xen/scripts/vtpm $env{ACTION}"
-SUBSYSTEM=="xen-backend", KERNEL=="vif*", ACTION=="online", RUN+="$env{script} online"
-SUBSYSTEM=="xen-backend", KERNEL=="vif*", ACTION=="offline", RUN+="$env{script} offline"
+SUBSYSTEM=="xen-backend", KERNEL=="vif2-*", RUN+="/etc/xen/scripts/vif2 $env{ACTION}"
+SUBSYSTEM=="xen-backend", KERNEL=="vif-*", ACTION=="online", RUN+="$env{script} online"
+SUBSYSTEM=="xen-backend", KERNEL=="vif-*", ACTION=="offline", RUN+="$env{script} offline"
 SUBSYSTEM=="xen-backend", KERNEL=="vscsi*", RUN+="/etc/xen/scripts/vscsi $env{ACTION}"
 SUBSYSTEM=="xen-backend", ACTION=="remove", RUN+="/etc/xen/scripts/xen-hotplug-cleanup"
 KERNEL=="evtchn", NAME="xen/%k"
tools/python/xen/xend/XendDevices.py +2 -1
diff -r dfa925940867 -r fe10d9d213eb tools/python/xen/xend/XendDevices.py
@@ -19,7 +19,7 @@
 # A collection of DevControllers 
 #
 
-from xen.xend.server import blkif, netif, tpmif, pciif, iopif, irqif, vfbif, vscsiif
+from xen.xend.server import blkif, netif, tpmif, pciif, iopif, irqif, vfbif, vscsiif, netif2
 from xen.xend.server.BlktapController import BlktapController, Blktap2Controller
 from xen.xend.server.ConsoleController import ConsoleController
 
@@ -37,6 +37,7 @@
     controllers = {
         'vbd': blkif.BlkifController,
         'vif': netif.NetifController,
+        'vif2': netif2.NetifController2,
         'vtpm': tpmif.TPMifController,
         'pci': pciif.PciController,
         'ioports': iopif.IOPortsController,
tools/python/xen/xend/XendDomainInfo.py +1 -1
diff -r dfa925940867 -r fe10d9d213eb tools/python/xen/xend/XendDomainInfo.py
@@ -1222,7 +1222,7 @@
                         break
                 self._waitForDevice_destroy(deviceClass, devid, backend)
 
-        if rm_cfg:
+        if rm_cfg and deviceClass != "vif2":
             if deviceClass == 'vif':
                 if self.domid is not None:
                     mac = ''
tools/python/xen/xend/server/netif2.py new file +163 -0

163 lines not on this page · raw message

tools/python/xen/xm/create.py +20 -0
diff -r dfa925940867 -r fe10d9d213eb tools/python/xen/xm/create.py
@@ -393,6 +393,12 @@
           This option may be repeated to add more than one vif.
           Specifying vifs will increase the number of interfaces as needed.""")
 
+gopts.var('vif2', val="front_mac=MAC,back_mac=MAC,backend=DOM,pdev=PDEV,max_bypasses=N,bridge=BRIDGE,filter_mac=<0|1>,front_filter_mac=<0|1>",
+          fn=append_value, default=[],
+          use="""Add a netchannel2 network interface using given front
+          and backend MAC addresses.  Randomly generated
+          addresses will be used if either address is missing.""")
+
 gopts.var('vtpm', val="instance=INSTANCE,backend=DOM,type=TYPE",
           fn=append_value, default=[],
           use="""Add a TPM interface. On the backend side use the given
@@ -931,6 +937,8 @@
 
     vifs = vals.vif
     vifs_n = len(vifs)
+    vifs2 = vals.vif2
+    vifs2_n = len(vifs2)
 
     if hasattr(vals, 'nics'):
         if vals.nics > 0:
@@ -955,6 +963,18 @@
             config_vif.append([k, d[k]])
 
         map(f, d.keys())
+        config_devs.append(['device', config_vif])
+
+    for c in vifs2:
+        d = comma_sep_kv_to_dict(c)
+        config_vif = ['vif2']
+
+        for k in d.keys():
+            if k not in ['front_mac', 'back_mac', 'backend', 'trusted',
+                         'back_trusted', 'front_filter_mac', 'filter_mac',
+                         'bridge', 'pdev', 'max_bypasses' ]:
+                err('Invalid vif2 option: ' + k)
+            config_vif.append([k, d[k]])
         config_devs.append(['device', config_vif])
 
 
tools/python/xen/xm/main.py +44 -0

68 lines not on this page · raw message

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#9 lore raw
In reply to [email protected]
Quoted 8 lines · On Tue, Oct 06, 2009 at 04:35:42PM +0100, [email protected] wrote:

This patch series includes all of the Xen and tools bits of netchannel2. It's essentially similar to the one I posted on Sunday, except:

-- I've dropped the unmodified drivers support. It'd probably be
fairly straightforward to re-introduce it, but it's not clear that anyone's actually using unmodified drivers any more (they don't even build against a 2.6.27 kernel, for instance).

At least Redhat/Fedora guys have been thinking of shipping pv-on-hvm Xen drivers for Fedora 12 / RHEL6.. But I don't know what's the status of that.

There's also a note about it on Xen Wiki:
http://wiki.xensource.com/xenwiki/XenParavirtOps

"Work in progress: pv-on-hvm driver support "

dunno about the status of that either :)

-- Pasi

#10 lore raw
Quoted 5 lines · On Tue, Oct 06, 2009 at 04:35:42PM +0100, [email protected] wrote:
Quoted 4 lines

This patch series includes all of the Xen and tools bits of netchannel2. It's essentially similar to the one I posted on Sunday, except:

Quoted 8 lines
Quoted 4 lines

-- I've dropped the unmodified drivers support. It'd probably be
fairly straightforward to re-introduce it, but it's not clear that anyone's actually using unmodified drivers any more (they don't even build against a 2.6.27 kernel, for instance).

At least Redhat/Fedora guys have been thinking of shipping pv-on-hvm Xen drivers for Fedora 12 / RHEL6.. But I don't know what's the status of that.

Yes, this certainly isn't a feature we want to drop. In fact, it would be good to see the pv-on-hvm drivers modified to use some of the pvops functions where available.

Ian

Quoted 14 lines

There's also a note about it on Xen Wiki:
http://wiki.xensource.com/xenwiki/XenParavirtOps

"Work in progress: pv-on-hvm driver support "

dunno about the status of that either :)

-- Pasi

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#11 lore raw
Quoted 11 lines · Ian Pratt
Quoted 11 lines · On Tue, Oct 06, 2009 at 04:35:42PM +0100, [email protected] wrote:
Quoted 10 lines

This patch series includes all of the Xen and tools bits of netchannel2. It's essentially similar to the one I posted on Sunday, except:

-- I've dropped the unmodified drivers support. It'd probably be
fairly straightforward to re-introduce it, but it's not clear that anyone's actually using unmodified drivers any more (they don't even build against a 2.6.27 kernel, for instance).

Quoted 6 lines
Quoted 4 lines

At least Redhat/Fedora guys have been thinking of shipping pv-on-hvm Xen drivers for Fedora 12 / RHEL6.. But I don't know what's the status of that.

Yes, this certainly isn't a feature we want to drop. In fact, it would be good to see the pv-on-hvm drivers modified to use some of the pvops functions where available.

Don Dutile from RH is actively working on this.

J

#12 lore raw

PATCH 1/1 linux-2.6.18-xen.hg: re-syncronize ring.h

This should be applied against the linux repository.

Patch 20267:e9366bed077e modified the definition of sring in the xen repo's version of ring.h, but not the version in the linux kernel repo. That change broke pause/resume/shutdown messages from the blktap2 kernel module, which (for the time being) relies on pad[0] being at consistent location in the sring struct. This patch fixes this regression by resyncronizing the two the files.

Signed off by: Jake Wires <[email protected]>

--Dutch

include/xen/interface/io/ring.h +2 -1
diff -r 4ac3e1d6605c include/xen/interface/io/ring.h
@@ -97,7 +97,8 @@ struct __name##_sring {                 
 struct __name##_sring {                                                 \
     RING_IDX req_prod, req_event;                                       \
     RING_IDX rsp_prod, rsp_event;                                       \
-    uint8_t  pad[48];                                                   \
+    uint8_t  netfront_smartpoll_active;                                 \
+    uint8_t  pad[47];                                                   \
     union __name##_sring_entry ring[1]; /* variable-length */           \
 };                                                                      \
                                                                         \

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#13 lore raw
In reply to Ian Pratt
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines

This patch series includes all of the Xen and tools bits of netchannel2. It's essentially similar to the one I posted on Sunday, except:

-- I've dropped the unmodified drivers support. It'd probably be
fairly straightforward to re-introduce it, but it's not clear that anyone's actually using unmodified drivers any more (they don't even build against a 2.6.27 kernel, for instance).

Quoted 6 lines
Quoted 3 lines

At least Redhat/Fedora guys have been thinking of shipping pv-on-hvm Xen drivers for Fedora 12 / RHEL6.. But I don't know what's the status of that.

Yes, this certainly isn't a feature we want to drop. In fact, it would be good to see the pv-on-hvm drivers modified to use some of the pvops functions where available.

Okay. If this is something which we want to keep working in the future then it might be a good idea to sanify the build system a bit. The current approach is an unholy mixture of 2.6.18, the host kernel, and whatever kernel you're grabbing the actual drivers from, and is basically just asking for trouble.

Steven.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#14 lore raw
Quoted 12 lines · Steven Smith
Quoted 12 lines
Quoted 12 lines
Quoted 8 lines

This patch series includes all of the Xen and tools bits of netchannel2. It's essentially similar to the one I posted on Sunday, except:

-- I've dropped the unmodified drivers support. It'd probably be
fairly straightforward to re-introduce it, but it's not clear that anyone's actually using unmodified drivers any more (they don't even build against a 2.6.27 kernel, for instance).

At least Redhat/Fedora guys have been thinking of shipping pv-on-hvm Xen drivers for Fedora 12 / RHEL6.. But I don't know what's the status of that.

Quoted 9 lines
Quoted 3 lines

Yes, this certainly isn't a feature we want to drop. In fact, it would be good to see the pv-on-hvm drivers modified to use some of the pvops functions where available.

Okay. If this is something which we want to keep working in the future then it might be a good idea to sanify the build system a bit. The current approach is an unholy mixture of 2.6.18, the host kernel, and whatever kernel you're grabbing the actual drivers from, and is basically just asking for trouble.

Hmm.. Did Novell guys port/fix the unmodified drivers to SLES11 (2.6.27) ?

-- Pasi

#15 lore raw
Quoted 2 lines
Quoted 1 line
Quoted 1 line

Pasi Kärkkäinen<[email protected]> 08.10.09 10:07 >>>

Hmm.. Did Novell guys port/fix the unmodified drivers to SLES11 (2.6.27) ?

Yes. They're building for us without extra patches afaict (I think we do need some adjustment on even newer kernels, due to the movement of the arch include directories, but that should be an upstreamable patch - not sure why it didn't get submitted). Of course the whole thing gets more complicated if you want to also consider a pv-ops-Xen-enabled kernel config, but otoh I recall Jeremy stating now and then that he would be working on pv driver building on pure pv-ops kernel sources.

Jan