diff mbox series

[v3,5/6] xen/arm: don't iomem_permit_access for reserved-memory regions

Message ID 20190621235608.2153-5-sstabellini@kernel.org (mailing list archive)
State Superseded
Headers show
Series [v3,1/6] xen/arm: extend device_tree_for_each_node | expand

Commit Message

Stefano Stabellini June 21, 2019, 11:56 p.m. UTC
Don't allow reserved-memory regions to be remapped into any guests,
until reserved-memory regions are properly supported in Xen. For now,
do not call iomem_permit_access for them.

Signed-off-by: Stefano Stabellini <stefanos@xilinx.com>
---
Changes in v4:
- new patch
---
 xen/arch/arm/domain_build.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

Comments

Oleksandr Tyshchenko July 9, 2019, 10:29 a.m. UTC | #1
On 22.06.19 02:56, Stefano Stabellini wrote:

Hi, Stefano

> Don't allow reserved-memory regions to be remapped into any guests,
> until reserved-memory regions are properly supported in Xen. For now,
> do not call iomem_permit_access for them.
>
> Signed-off-by: Stefano Stabellini <stefanos@xilinx.com>
> ---
> Changes in v4:
> - new patch
> ---
>   xen/arch/arm/domain_build.c | 23 +++++++++++++++--------
>   1 file changed, 15 insertions(+), 8 deletions(-)
>
> diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
> index d9836779d1..76dd4bf6f9 100644
> --- a/xen/arch/arm/domain_build.c
> +++ b/xen/arch/arm/domain_build.c
> @@ -1158,15 +1158,22 @@ static int __init map_range_to_domain(const struct dt_device_node *dev,
>       bool need_mapping = !dt_device_for_passthrough(dev);
>       int res;
>   
> -    res = iomem_permit_access(d, paddr_to_pfn(addr),
> -                              paddr_to_pfn(PAGE_ALIGN(addr + len - 1)));
> -    if ( res )
> +    /*
> +     * Don't give iomem permissions for reserved-memory ranges until
> +     * reserved-memory support is complete.
> +     */
> +    if ( strcmp(dt_node_name(dev), "reserved-memory") )

This filter doesn't catch child nodes if the "reserved-memory" node has 
ones.

Here is my "reserved-memory" node:

reserved-memory {
         #address-cells = <2>;
         #size-cells = <2>;
         ranges;

         /* device specific region for Lossy Decompression */
         lossy_decompress: linux,lossy_decompress@54000000 {
             no-map;
             reg = <0x00000000 0x54000000 0x0 0x03000000>;
         };

         /* For Audio DSP */
         adsp_reserved: linux,adsp@57000000 {
             compatible = "shared-dma-pool";
             reusable;
             reg = <0x00000000 0x57000000 0x0 0x01000000>;
         };

         /* global autoconfigured region for contiguous allocations */
         linux,cma@58000000 {
             compatible = "shared-dma-pool";
             reusable;
             reg = <0x00000000 0x58000000 0x0 0x18000000>;
             linux,cma-default;
         };

         /* device specific region for contiguous allocations */
         mmp_reserved: linux,multimedia@70000000 {
             compatible = "shared-dma-pool";
             reusable;
             reg = <0x00000000 0x70000000 0x0 0x10000000>;
         };
     };


So, the dt_node_name(dev) for child nodes are:

- linux,lossy_decompress
- linux,adsp
- linux,cma
- linux,multimedia


Probably, we should check whether the parent node is "reserved-memory" 
as well.
Julien Grall July 10, 2019, 4:48 p.m. UTC | #2
Hi Stefano,

On 6/22/19 12:56 AM, Stefano Stabellini wrote:
> Don't allow reserved-memory regions to be remapped into any guests,
> until reserved-memory regions are properly supported in Xen. For now,
> do not call iomem_permit_access for them.
> 
> Signed-off-by: Stefano Stabellini <stefanos@xilinx.com>
> ---
> Changes in v4:
> - new patch
> ---
>   xen/arch/arm/domain_build.c | 23 +++++++++++++++--------
>   1 file changed, 15 insertions(+), 8 deletions(-)
> 
> diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
> index d9836779d1..76dd4bf6f9 100644
> --- a/xen/arch/arm/domain_build.c
> +++ b/xen/arch/arm/domain_build.c
> @@ -1158,15 +1158,22 @@ static int __init map_range_to_domain(const struct dt_device_node *dev,
>       bool need_mapping = !dt_device_for_passthrough(dev);
>       int res;
>   
> -    res = iomem_permit_access(d, paddr_to_pfn(addr),
> -                              paddr_to_pfn(PAGE_ALIGN(addr + len - 1)));
> -    if ( res )
> +    /*
> +     * Don't give iomem permissions for reserved-memory ranges until
> +     * reserved-memory support is complete.
> +     */
> +    if ( strcmp(dt_node_name(dev), "reserved-memory") )

Aside Oleksandr's comment, you should technically use dt_node_cmp(...) 
for comparing node name.

>       {
> -        printk(XENLOG_ERR "Unable to permit to dom%d access to"
> -               " 0x%"PRIx64" - 0x%"PRIx64"\n",
> -               d->domain_id,
> -               addr & PAGE_MASK, PAGE_ALIGN(addr + len) - 1);
> -        return res;
> +        res = iomem_permit_access(d, paddr_to_pfn(addr),
> +                                  paddr_to_pfn(PAGE_ALIGN(addr + len - 1)));
> +        if ( res )
> +        {
> +            printk(XENLOG_ERR "Unable to permit to dom%d access to"
> +                   " 0x%"PRIx64" - 0x%"PRIx64"\n",
> +                   d->domain_id,
> +                   addr & PAGE_MASK, PAGE_ALIGN(addr + len) - 1);
> +            return res;
> +        }
>       }
>   
>       if ( need_mapping )
> 

Cheers,
Stefano Stabellini Aug. 6, 2019, 7:29 p.m. UTC | #3
On Tue, 9 Jul 2019, Oleksandr wrote:
> 
> On 22.06.19 02:56, Stefano Stabellini wrote:
> 
> Hi, Stefano
> 
> > Don't allow reserved-memory regions to be remapped into any guests,
> > until reserved-memory regions are properly supported in Xen. For now,
> > do not call iomem_permit_access for them.
> > 
> > Signed-off-by: Stefano Stabellini <stefanos@xilinx.com>
> > ---
> > Changes in v4:
> > - new patch
> > ---
> >   xen/arch/arm/domain_build.c | 23 +++++++++++++++--------
> >   1 file changed, 15 insertions(+), 8 deletions(-)
> > 
> > diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
> > index d9836779d1..76dd4bf6f9 100644
> > --- a/xen/arch/arm/domain_build.c
> > +++ b/xen/arch/arm/domain_build.c
> > @@ -1158,15 +1158,22 @@ static int __init map_range_to_domain(const struct
> > dt_device_node *dev,
> >       bool need_mapping = !dt_device_for_passthrough(dev);
> >       int res;
> >   -    res = iomem_permit_access(d, paddr_to_pfn(addr),
> > -                              paddr_to_pfn(PAGE_ALIGN(addr + len - 1)));
> > -    if ( res )
> > +    /*
> > +     * Don't give iomem permissions for reserved-memory ranges until
> > +     * reserved-memory support is complete.
> > +     */
> > +    if ( strcmp(dt_node_name(dev), "reserved-memory") )
> 
> This filter doesn't catch child nodes if the "reserved-memory" node has ones.
> 
> Here is my "reserved-memory" node:
> 
> reserved-memory {
>         #address-cells = <2>;
>         #size-cells = <2>;
>         ranges;
> 
>         /* device specific region for Lossy Decompression */
>         lossy_decompress: linux,lossy_decompress@54000000 {
>             no-map;
>             reg = <0x00000000 0x54000000 0x0 0x03000000>;
>         };
> 
>         /* For Audio DSP */
>         adsp_reserved: linux,adsp@57000000 {
>             compatible = "shared-dma-pool";
>             reusable;
>             reg = <0x00000000 0x57000000 0x0 0x01000000>;
>         };
> 
>         /* global autoconfigured region for contiguous allocations */
>         linux,cma@58000000 {
>             compatible = "shared-dma-pool";
>             reusable;
>             reg = <0x00000000 0x58000000 0x0 0x18000000>;
>             linux,cma-default;
>         };
> 
>         /* device specific region for contiguous allocations */
>         mmp_reserved: linux,multimedia@70000000 {
>             compatible = "shared-dma-pool";
>             reusable;
>             reg = <0x00000000 0x70000000 0x0 0x10000000>;
>         };
>     };
> 
> 
> So, the dt_node_name(dev) for child nodes are:
> 
> - linux,lossy_decompress
> - linux,adsp
> - linux,cma
> - linux,multimedia
> 
> 
> Probably, we should check whether the parent node is "reserved-memory" as
> well.

Yes, that is a mistake, thanks for spotting it. I should check the
parent node name instead.
diff mbox series

Patch

diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
index d9836779d1..76dd4bf6f9 100644
--- a/xen/arch/arm/domain_build.c
+++ b/xen/arch/arm/domain_build.c
@@ -1158,15 +1158,22 @@  static int __init map_range_to_domain(const struct dt_device_node *dev,
     bool need_mapping = !dt_device_for_passthrough(dev);
     int res;
 
-    res = iomem_permit_access(d, paddr_to_pfn(addr),
-                              paddr_to_pfn(PAGE_ALIGN(addr + len - 1)));
-    if ( res )
+    /*
+     * Don't give iomem permissions for reserved-memory ranges until
+     * reserved-memory support is complete.
+     */
+    if ( strcmp(dt_node_name(dev), "reserved-memory") )
     {
-        printk(XENLOG_ERR "Unable to permit to dom%d access to"
-               " 0x%"PRIx64" - 0x%"PRIx64"\n",
-               d->domain_id,
-               addr & PAGE_MASK, PAGE_ALIGN(addr + len) - 1);
-        return res;
+        res = iomem_permit_access(d, paddr_to_pfn(addr),
+                                  paddr_to_pfn(PAGE_ALIGN(addr + len - 1)));
+        if ( res )
+        {
+            printk(XENLOG_ERR "Unable to permit to dom%d access to"
+                   " 0x%"PRIx64" - 0x%"PRIx64"\n",
+                   d->domain_id,
+                   addr & PAGE_MASK, PAGE_ALIGN(addr + len) - 1);
+            return res;
+        }
     }
 
     if ( need_mapping )