xen: XENMEM_add_to_physmap_batch: Mark 'foreign_id' as reserved for dev_mmio
authorJulien Grall <julien.grall@arm.com>
Fri, 27 May 2016 16:06:20 +0000 (17:06 +0100)
committerStefano Stabellini <sstabellini@kernel.org>
Mon, 30 May 2016 12:02:43 +0000 (13:02 +0100)
The field 'foreign_id' is not used when the space is dev_mmio. As the
space is not yet part of the stable ABI, the field is marked as reserved
for future use.

The value should always be 0, other values will return -EOPNOTSUPP.

Signed-off-by: Julien Grall <julien.grall@arm.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
Acked-by: Jan Beulich <jbeulich@suse.com>
xen/arch/arm/mm.c
xen/arch/x86/mm.c
xen/common/compat/memory.c
xen/common/memory.c
xen/include/public/memory.h
xen/include/xen/mm.h

index b46e23ed8c8b3e08cea39ba17414c5cf0973b703..0aa8092babe94bc4534064ca10ea5512c2198575 100644 (file)
@@ -1047,7 +1047,7 @@ void share_xen_page_with_privileged_guests(
 int xenmem_add_to_physmap_one(
     struct domain *d,
     unsigned int space,
-    domid_t foreign_domid,
+    union xen_add_to_physmap_batch_extra extra,
     unsigned long idx,
     xen_pfn_t gpfn)
 {
@@ -1103,7 +1103,8 @@ int xenmem_add_to_physmap_one(
     {
         struct domain *od;
         p2m_type_t p2mt;
-        od = rcu_lock_domain_by_any_id(foreign_domid);
+
+        od = rcu_lock_domain_by_any_id(extra.foreign_domid);
         if ( od == NULL )
             return -ESRCH;
 
@@ -1143,6 +1144,10 @@ int xenmem_add_to_physmap_one(
         break;
     }
     case XENMAPSPACE_dev_mmio:
+        /* extra should be 0. Reserved for future use. */
+        if ( extra.res0 )
+            return -EOPNOTSUPP;
+
         rc = map_dev_mmio_region(d, gpfn, 1, idx);
         return rc;
 
index 03a4d5b97b46e504683d1bdd122474821f85661e..8d10a3ecb9695d0bc3d8168c5db06d9a37c14ead 100644 (file)
@@ -4769,7 +4769,7 @@ static int handle_iomem_range(unsigned long s, unsigned long e, void *p)
 int xenmem_add_to_physmap_one(
     struct domain *d,
     unsigned int space,
-    domid_t foreign_domid,
+    union xen_add_to_physmap_batch_extra extra,
     unsigned long idx,
     xen_pfn_t gpfn)
 {
@@ -4830,7 +4830,7 @@ int xenmem_add_to_physmap_one(
             break;
         }
         case XENMAPSPACE_gmfn_foreign:
-            return p2m_add_foreign(d, idx, gpfn, foreign_domid);
+            return p2m_add_foreign(d, idx, gpfn, extra.foreign_domid);
         default:
             break;
     }
index 19a914d4d706398fceabc7aa70a152184ea3bff6..20c7671ffe9e9a46935ee9251c8bb479e3e410c0 100644 (file)
@@ -253,6 +253,13 @@ int compat_memory_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) compat)
             unsigned int size = cmp.atpb.size;
             xen_ulong_t *idxs = (void *)(nat.atpb + 1);
             xen_pfn_t *gpfns = (void *)(idxs + limit);
+            /*
+             * The union will always be 16-bit width. So it is not
+             * necessary to have the exact field which correspond to the
+             * space.
+             */
+            enum XLAT_add_to_physmap_batch_u u =
+                XLAT_add_to_physmap_batch_u_res0;
 
             if ( copy_from_guest(&cmp.atpb, compat, 1) ||
                  !compat_handle_okay(cmp.atpb.idxs, size) ||
index 644f81a5a43c59aeaaeda551936d54627ae3ada7..ccc643664d11301b2f3458bcabbe980f46e302b9 100644 (file)
@@ -639,9 +639,15 @@ static int xenmem_add_to_physmap(struct domain *d,
 {
     unsigned int done = 0;
     long rc = 0;
+    union xen_add_to_physmap_batch_extra extra;
+
+    if ( xatp->space != XENMAPSPACE_gmfn_foreign )
+        extra.res0 = 0;
+    else
+        extra.foreign_domid = DOMID_INVALID;
 
     if ( xatp->space != XENMAPSPACE_gmfn_range )
-        return xenmem_add_to_physmap_one(d, xatp->space, DOMID_INVALID,
+        return xenmem_add_to_physmap_one(d, xatp->space, extra,
                                          xatp->idx, xatp->gpfn);
 
     if ( xatp->size < start )
@@ -658,7 +664,7 @@ static int xenmem_add_to_physmap(struct domain *d,
 
     while ( xatp->size > done )
     {
-        rc = xenmem_add_to_physmap_one(d, xatp->space, DOMID_INVALID,
+        rc = xenmem_add_to_physmap_one(d, xatp->space, extra,
                                        xatp->idx, xatp->gpfn);
         if ( rc < 0 )
             break;
@@ -719,7 +725,7 @@ static int xenmem_add_to_physmap_batch(struct domain *d,
         }
 
         rc = xenmem_add_to_physmap_one(d, xatpb->space,
-                                       xatpb->foreign_domid,
+                                       xatpb->u,
                                        idx, gpfn);
 
         if ( unlikely(__copy_to_guest_offset(xatpb->errs, 0, &rc, 1)) )
index fe52ee18e504a640a41247954e062fc301e623f9..5f7e0d2c5418e0810a01b105bf497be494d651fc 100644 (file)
@@ -259,7 +259,15 @@ struct xen_add_to_physmap_batch {
 
     /* Number of pages to go through */
     uint16_t size;
-    domid_t foreign_domid; /* IFF gmfn_foreign */
+
+#if __XEN_INTERFACE_VERSION__ < 0x00040700
+    domid_t foreign_domid; /* IFF gmfn_foreign. Should be 0 for other spaces. */
+#else
+    union xen_add_to_physmap_batch_extra {
+        domid_t foreign_domid; /* gmfn_foreign */
+        uint16_t res0;  /* All the other spaces. Should be 0 */
+    } u;
+#endif
 
     /* Indexes into space being mapped. */
     XEN_GUEST_HANDLE(xen_ulong_t) idxs;
index d4721fc610a9617e94dabcda08d3284848ad2dfd..3cf646ac6bc1eae8c16b810717c9e850690d37c7 100644 (file)
@@ -50,6 +50,7 @@
 #include <xen/list.h>
 #include <xen/spinlock.h>
 #include <xen/typesafe.h>
+#include <public/memory.h>
 
 TYPE_SAFE(unsigned long, mfn);
 #define PRI_mfn          "05lx"
@@ -505,7 +506,7 @@ void scrub_one_page(struct page_info *);
 #endif
 
 int xenmem_add_to_physmap_one(struct domain *d, unsigned int space,
-                              domid_t foreign_domid,
+                              union xen_add_to_physmap_batch_extra extra,
                               unsigned long idx, xen_pfn_t gpfn);
 
 /* Returns 1 on success, 0 on error, negative if the ring