xen: introduce arch_grant_(un)map_page_identity
authorStefano Stabellini <stefano.stabellini@eu.citrix.com>
Fri, 1 Aug 2014 14:45:24 +0000 (15:45 +0100)
committerIan Campbell <ian.campbell@citrix.com>
Tue, 9 Sep 2014 10:47:08 +0000 (11:47 +0100)
Introduce two arch specific functions to create a new p2m mapping of
granted pages at pfn == mfn.
We don't an x86 implementation as these functions should never be
compiled on x86 (they are called from an if (0) statement).

Base the implementation of arm_smmu_(un)map_page on
arch_grant_(un)map_page_identity.

Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Acked-by: Julien Grall <julien.grall@linaro.org>
Acked-by: Jan Beulich <jbeulich@suse.com>
xen/arch/arm/p2m.c
xen/drivers/passthrough/arm/smmu.c
xen/include/asm-arm/p2m.h
xen/include/asm-x86/p2m.h

index fc8c0ddf603718259c639eb0cfb2262d3630022f..a7dcdf5f4ce063759c70b087e3169a621a32a006 100644 (file)
@@ -927,6 +927,32 @@ void guest_physmap_remove_page(struct domain *d,
                       pfn_to_paddr(mfn), MATTR_MEM, p2m_invalid);
 }
 
+int arch_grant_map_page_identity(struct domain *d, unsigned long frame,
+                                 bool_t writeable)
+{
+    p2m_type_t t;
+
+    ASSERT(is_domain_direct_mapped(d));
+
+    /* This is not an IOMMU mapping but it is not a regular RAM p2m type
+     * either. We are using IOMMU p2m types here to prevent the pages
+     * from being used as grants. */
+    if ( writeable )
+        t = p2m_iommu_map_rw;
+    else
+        t = p2m_iommu_map_ro;
+
+    return guest_physmap_add_entry(d, frame, frame, 0, t);
+}
+
+int arch_grant_unmap_page_identity(struct domain *d, unsigned long frame)
+{
+    ASSERT(is_domain_direct_mapped(d));
+
+    guest_physmap_remove_page(d, frame, frame, 0);
+    return 0;
+}
+
 int p2m_alloc_table(struct domain *d)
 {
     struct p2m_domain *p2m = &d->arch.p2m;
index f4eb2a2d59f5eee3b5256d414752b73afbe56c69..fb0c6941a52bf1bfe649d033e502f0b90b3708e6 100644 (file)
@@ -1539,8 +1539,6 @@ static void arm_smmu_iommu_domain_teardown(struct domain *d)
 static int arm_smmu_map_page(struct domain *d, unsigned long gfn,
                              unsigned long mfn, unsigned int flags)
 {
-    p2m_type_t t;
-
     /* Grant mappings can be used for DMA requests. The dev_bus_addr returned by
      * the hypercall is the MFN (not the IPA). For device protected by
      * an IOMMU, Xen needs to add a 1:1 mapping in the domain p2m to
@@ -1555,12 +1553,7 @@ static int arm_smmu_map_page(struct domain *d, unsigned long gfn,
     if ( !(flags & (IOMMUF_readable | IOMMUF_writable)) )
         return -EINVAL;
 
-    t = (flags & IOMMUF_writable) ? p2m_iommu_map_rw : p2m_iommu_map_ro;
-
-    /* The function guest_physmap_add_entry replaces the current mapping
-     * if there is already one...
-     */
-    return guest_physmap_add_entry(d, gfn, mfn, 0, t);
+    return arch_grant_map_page_identity(d, mfn, flags & IOMMUF_writable);
 }
 
 static int arm_smmu_unmap_page(struct domain *d, unsigned long gfn)
@@ -1571,9 +1564,7 @@ static int arm_smmu_unmap_page(struct domain *d, unsigned long gfn)
     if ( !is_domain_direct_mapped(d) )
         return -EINVAL;
 
-    guest_physmap_remove_page(d, gfn, gfn, 0);
-
-    return 0;
+    return arch_grant_unmap_page_identity(d, gfn);
 }
 
 static const struct iommu_ops arm_smmu_iommu_ops = {
index 08ce07b679b19a151ae68a2c8c15f03bb731a6d4..97cbae4d364bebd34c25a61d0b38fb35261027f6 100644 (file)
@@ -194,6 +194,10 @@ static inline int get_page_and_type(struct page_info *page,
     return rc;
 }
 
+int arch_grant_map_page_identity(struct domain *d, unsigned long frame,
+                                 bool_t writeable);
+int arch_grant_unmap_page_identity(struct domain *d, unsigned long frame);
+
 #endif /* _XEN_P2M_H */
 
 /*
index 39f235db411c002e78db83a17a7b22b125f77bd9..bae669e37cc9a06d53d433e4229a008003db5c15 100644 (file)
@@ -719,6 +719,10 @@ static inline unsigned int p2m_get_iommu_flags(p2m_type_t p2mt)
     return flags;
 }
 
+extern int arch_grant_map_page_identity(struct domain *d, unsigned long frame,
+                                 bool_t writeable);
+extern int arch_grant_unmap_page_identity(struct domain *d, unsigned long frame);
+
 #endif /* _XEN_P2M_H */
 
 /*