diff mbox

[Xen-devel,v3,2/3] xen: introduce arch_grant_(un)map_page_identity

Message ID 1406208666-23547-2-git-send-email-stefano.stabellini@eu.citrix.com
State New
Headers show

Commit Message

Stefano Stabellini July 24, 2014, 1:31 p.m. UTC
Introduce two arch specific functions to create a new p2m mapping of
granted pages at pfn == mfn.
The x86 implementation just returns ENOSYS.

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>

---
Changes in v3:
- fix commit title;
- use p2m_iommu types;
- call arch_grant_(un)map_page_identity functions from
arm_smmu_(un)map_page.
---
 xen/arch/arm/p2m.c                 |   22 ++++++++++++++++++++++
 xen/drivers/passthrough/arm/smmu.c |   13 ++-----------
 xen/include/asm-arm/p2m.h          |    4 ++++
 xen/include/asm-x86/p2m.h          |   13 +++++++++++++
 4 files changed, 41 insertions(+), 11 deletions(-)

Comments

Julien Grall July 24, 2014, 1:44 p.m. UTC | #1
Hi Stefano,

On 07/24/2014 02:31 PM, Stefano Stabellini wrote:
> Introduce two arch specific functions to create a new p2m mapping of
> granted pages at pfn == mfn.
> The x86 implementation just returns ENOSYS.
> 
> 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>
> 
> ---
> Changes in v3:
> - fix commit title;
> - use p2m_iommu types;
> - call arch_grant_(un)map_page_identity functions from
> arm_smmu_(un)map_page.
> ---
>  xen/arch/arm/p2m.c                 |   22 ++++++++++++++++++++++
>  xen/drivers/passthrough/arm/smmu.c |   13 ++-----------
>  xen/include/asm-arm/p2m.h          |    4 ++++
>  xen/include/asm-x86/p2m.h          |   13 +++++++++++++
>  4 files changed, 41 insertions(+), 11 deletions(-)
> 
> diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c
> index 9960e17..6024b03 100644
> --- a/xen/arch/arm/p2m.c
> +++ b/xen/arch/arm/p2m.c
> @@ -555,6 +555,28 @@ 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;

NIT: I would add an ASSERT(!is_domain_direct_mapped(d)) for sanity check.

> +
> +    /* 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)
> +{

Same here.

> +    guest_physmap_remove_page(d, frame, frame, 0);
> +    return 0;
> +}
> +

In any case:

Acked-by: Julien Grall <julien.grall@linaro.org>

Regards,
Stefano Stabellini July 24, 2014, 4:57 p.m. UTC | #2
On Thu, 24 Jul 2014, Julien Grall wrote:
> Hi Stefano,
> 
> On 07/24/2014 02:31 PM, Stefano Stabellini wrote:
> > Introduce two arch specific functions to create a new p2m mapping of
> > granted pages at pfn == mfn.
> > The x86 implementation just returns ENOSYS.
> > 
> > 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>
> > 
> > ---
> > Changes in v3:
> > - fix commit title;
> > - use p2m_iommu types;
> > - call arch_grant_(un)map_page_identity functions from
> > arm_smmu_(un)map_page.
> > ---
> >  xen/arch/arm/p2m.c                 |   22 ++++++++++++++++++++++
> >  xen/drivers/passthrough/arm/smmu.c |   13 ++-----------
> >  xen/include/asm-arm/p2m.h          |    4 ++++
> >  xen/include/asm-x86/p2m.h          |   13 +++++++++++++
> >  4 files changed, 41 insertions(+), 11 deletions(-)
> > 
> > diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c
> > index 9960e17..6024b03 100644
> > --- a/xen/arch/arm/p2m.c
> > +++ b/xen/arch/arm/p2m.c
> > @@ -555,6 +555,28 @@ 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;
> 
> NIT: I would add an ASSERT(!is_domain_direct_mapped(d)) for sanity check.
>

you mean 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)
> > +{
> 
> Same here.
> 
> > +    guest_physmap_remove_page(d, frame, frame, 0);
> > +    return 0;
> > +}
> > +
> 
> In any case:
> 
> Acked-by: Julien Grall <julien.grall@linaro.org>

thanks
Julien Grall July 24, 2014, 4:59 p.m. UTC | #3
On 07/24/2014 05:57 PM, Stefano Stabellini wrote:
> On Thu, 24 Jul 2014, Julien Grall wrote:
>> Hi Stefano,
>>
>> On 07/24/2014 02:31 PM, Stefano Stabellini wrote:
>>> Introduce two arch specific functions to create a new p2m mapping of
>>> granted pages at pfn == mfn.
>>> The x86 implementation just returns ENOSYS.
>>>
>>> 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>
>>>
>>> ---
>>> Changes in v3:
>>> - fix commit title;
>>> - use p2m_iommu types;
>>> - call arch_grant_(un)map_page_identity functions from
>>> arm_smmu_(un)map_page.
>>> ---
>>>  xen/arch/arm/p2m.c                 |   22 ++++++++++++++++++++++
>>>  xen/drivers/passthrough/arm/smmu.c |   13 ++-----------
>>>  xen/include/asm-arm/p2m.h          |    4 ++++
>>>  xen/include/asm-x86/p2m.h          |   13 +++++++++++++
>>>  4 files changed, 41 insertions(+), 11 deletions(-)
>>>
>>> diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c
>>> index 9960e17..6024b03 100644
>>> --- a/xen/arch/arm/p2m.c
>>> +++ b/xen/arch/arm/p2m.c
>>> @@ -555,6 +555,28 @@ 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;
>>
>> NIT: I would add an ASSERT(!is_domain_direct_mapped(d)) for sanity check.
>>
> 
> you mean ASSERT(is_domain_direct_mapped(d))

Yes. Sorry.

>>> +
>>> +    /* 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)
>>> +{
>>
>> Same here.
>>
>>> +    guest_physmap_remove_page(d, frame, frame, 0);
>>> +    return 0;
>>> +}
>>> +
>>
>> In any case:
>>
>> Acked-by: Julien Grall <julien.grall@linaro.org>
> 
> thanks
>
diff mbox

Patch

diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c
index 9960e17..6024b03 100644
--- a/xen/arch/arm/p2m.c
+++ b/xen/arch/arm/p2m.c
@@ -555,6 +555,28 @@  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;
+
+    /* 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)
+{
+    guest_physmap_remove_page(d, frame, frame, 0);
+    return 0;
+}
+
 int p2m_alloc_table(struct domain *d)
 {
     struct p2m_domain *p2m = &d->arch.p2m;
diff --git a/xen/drivers/passthrough/arm/smmu.c b/xen/drivers/passthrough/arm/smmu.c
index f4eb2a2..fb0c694 100644
--- a/xen/drivers/passthrough/arm/smmu.c
+++ b/xen/drivers/passthrough/arm/smmu.c
@@ -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 = {
diff --git a/xen/include/asm-arm/p2m.h b/xen/include/asm-arm/p2m.h
index 911d32d..b682f51 100644
--- a/xen/include/asm-arm/p2m.h
+++ b/xen/include/asm-arm/p2m.h
@@ -181,6 +181,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 */
 
 /*
diff --git a/xen/include/asm-x86/p2m.h b/xen/include/asm-x86/p2m.h
index 0ddbadb..faead11 100644
--- a/xen/include/asm-x86/p2m.h
+++ b/xen/include/asm-x86/p2m.h
@@ -717,6 +717,19 @@  static inline unsigned int p2m_get_iommu_flags(p2m_type_t p2mt)
 
     return flags;
 }
+ 
+static inline int arch_grant_map_page_identity(struct domain *d,
+                                               unsigned long frame,
+                                               bool_t writeable)
+{
+    return -ENOSYS;
+}
+
+static inline int arch_grant_unmap_page_identity(struct domain *d,
+                                                 unsigned long frame)
+{
+    return -ENOSYS;
+}
 
 #endif /* _XEN_P2M_H */