[Xen-devel,12/24] xen/arm: Replace DIV_ROUND_UP(..., PAGE_SIZE) by PFN_UP(...)

Message ID 20170613161323.25196-13-julien.grall@arm.com
State New
Headers show
Series
  • xen/arm: Extend the usage of typesafe MFN
Related show

Commit Message

Julien Grall June 13, 2017, 4:13 p.m.
DIV_ROUND_UP(..., PAGE_SIZE) and PFN_UP(...) are equivalent.

Signed-off-by: Julien Grall <julien.grall@arm.com>
---
 xen/arch/arm/domain_build.c | 4 ++--
 xen/arch/arm/gic-v2.c       | 2 +-
 xen/arch/arm/gic-v3.c       | 8 ++++----
 xen/arch/arm/kernel.c       | 2 +-
 4 files changed, 8 insertions(+), 8 deletions(-)

Comments

Stefano Stabellini June 15, 2017, 10:47 p.m. | #1
On Tue, 13 Jun 2017, Julien Grall wrote:
> DIV_ROUND_UP(..., PAGE_SIZE) and PFN_UP(...) are equivalent.
> 
> Signed-off-by: Julien Grall <julien.grall@arm.com>

Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>


> ---
>  xen/arch/arm/domain_build.c | 4 ++--
>  xen/arch/arm/gic-v2.c       | 2 +-
>  xen/arch/arm/gic-v3.c       | 8 ++++----
>  xen/arch/arm/kernel.c       | 2 +-
>  4 files changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
> index a04c8862db..a3243bdb5d 100644
> --- a/xen/arch/arm/domain_build.c
> +++ b/xen/arch/arm/domain_build.c
> @@ -1008,7 +1008,7 @@ static int map_range_to_domain(const struct dt_device_node *dev,
>      {
>          res = map_regions_p2mt(d,
>                                 _gfn(paddr_to_pfn(addr)),
> -                               DIV_ROUND_UP(len, PAGE_SIZE),
> +                               PFN_UP(len),
>                                 _mfn(paddr_to_pfn(addr)),
>                                 mr_data->p2mt);
>  
> @@ -1545,7 +1545,7 @@ static void acpi_map_other_tables(struct domain *d)
>          size = acpi_gbl_root_table_list.tables[i].length;
>          res = map_regions_p2mt(d,
>                                 _gfn(paddr_to_pfn(addr)),
> -                               DIV_ROUND_UP(size, PAGE_SIZE),
> +                               PFN_UP(size),
>                                 _mfn(paddr_to_pfn(addr)),
>                                 p2m_mmio_direct_c);
>          if ( res )
> diff --git a/xen/arch/arm/gic-v2.c b/xen/arch/arm/gic-v2.c
> index f8124e5e54..0482b1fe32 100644
> --- a/xen/arch/arm/gic-v2.c
> +++ b/xen/arch/arm/gic-v2.c
> @@ -598,7 +598,7 @@ static int gicv2_map_hwdown_extra_mappings(struct domain *d)
>                 v2m_data->spi_start, v2m_data->nr_spis);
>  
>          ret = map_mmio_regions(d, _gfn(paddr_to_pfn(v2m_data->addr)),
> -                               DIV_ROUND_UP(v2m_data->size, PAGE_SIZE),
> +                               PFN_UP(v2m_data->size),
>                                 _mfn(paddr_to_pfn(v2m_data->addr)));
>          if ( ret )
>          {
> diff --git a/xen/arch/arm/gic-v3.c b/xen/arch/arm/gic-v3.c
> index a559e5e260..bb845e955d 100644
> --- a/xen/arch/arm/gic-v3.c
> +++ b/xen/arch/arm/gic-v3.c
> @@ -1283,7 +1283,7 @@ static int gicv3_iomem_deny_access(const struct domain *d)
>      unsigned long mfn, nr;
>  
>      mfn = dbase >> PAGE_SHIFT;
> -    nr = DIV_ROUND_UP(SZ_64K, PAGE_SIZE);
> +    nr = PFN_UP(SZ_64K);
>      rc = iomem_deny_access(d, mfn, mfn + nr);
>      if ( rc )
>          return rc;
> @@ -1291,7 +1291,7 @@ static int gicv3_iomem_deny_access(const struct domain *d)
>      for ( i = 0; i < gicv3.rdist_count; i++ )
>      {
>          mfn = gicv3.rdist_regions[i].base >> PAGE_SHIFT;
> -        nr = DIV_ROUND_UP(gicv3.rdist_regions[i].size, PAGE_SIZE);
> +        nr = PFN_UP(gicv3.rdist_regions[i].size);
>          rc = iomem_deny_access(d, mfn, mfn + nr);
>          if ( rc )
>              return rc;
> @@ -1300,7 +1300,7 @@ static int gicv3_iomem_deny_access(const struct domain *d)
>      if ( cbase != INVALID_PADDR )
>      {
>          mfn = cbase >> PAGE_SHIFT;
> -        nr = DIV_ROUND_UP(csize, PAGE_SIZE);
> +        nr = PFN_UP(csize);
>          rc = iomem_deny_access(d, mfn, mfn + nr);
>          if ( rc )
>              return rc;
> @@ -1309,7 +1309,7 @@ static int gicv3_iomem_deny_access(const struct domain *d)
>      if ( vbase != INVALID_PADDR )
>      {
>          mfn = vbase >> PAGE_SHIFT;
> -        nr = DIV_ROUND_UP(csize, PAGE_SIZE);
> +        nr = PFN_UP(csize);
>          return iomem_deny_access(d, mfn, mfn + nr);
>      }
>  
> diff --git a/xen/arch/arm/kernel.c b/xen/arch/arm/kernel.c
> index e2512c4612..0ed8b6005c 100644
> --- a/xen/arch/arm/kernel.c
> +++ b/xen/arch/arm/kernel.c
> @@ -312,7 +312,7 @@ static __init int kernel_decompress(struct bootmodule *mod)
>       * Need to free pages after output_size here because they won't be
>       * freed by discard_initial_modules
>       */
> -    i = DIV_ROUND_UP(output_size, PAGE_SIZE);
> +    i = PFN_UP(output_size);
>      for ( ; i < (1 << kernel_order_out); i++ )
>          free_domheap_page(pages + i);
>  
> -- 
> 2.11.0
>

Patch hide | download patch | download mbox

diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
index a04c8862db..a3243bdb5d 100644
--- a/xen/arch/arm/domain_build.c
+++ b/xen/arch/arm/domain_build.c
@@ -1008,7 +1008,7 @@  static int map_range_to_domain(const struct dt_device_node *dev,
     {
         res = map_regions_p2mt(d,
                                _gfn(paddr_to_pfn(addr)),
-                               DIV_ROUND_UP(len, PAGE_SIZE),
+                               PFN_UP(len),
                                _mfn(paddr_to_pfn(addr)),
                                mr_data->p2mt);
 
@@ -1545,7 +1545,7 @@  static void acpi_map_other_tables(struct domain *d)
         size = acpi_gbl_root_table_list.tables[i].length;
         res = map_regions_p2mt(d,
                                _gfn(paddr_to_pfn(addr)),
-                               DIV_ROUND_UP(size, PAGE_SIZE),
+                               PFN_UP(size),
                                _mfn(paddr_to_pfn(addr)),
                                p2m_mmio_direct_c);
         if ( res )
diff --git a/xen/arch/arm/gic-v2.c b/xen/arch/arm/gic-v2.c
index f8124e5e54..0482b1fe32 100644
--- a/xen/arch/arm/gic-v2.c
+++ b/xen/arch/arm/gic-v2.c
@@ -598,7 +598,7 @@  static int gicv2_map_hwdown_extra_mappings(struct domain *d)
                v2m_data->spi_start, v2m_data->nr_spis);
 
         ret = map_mmio_regions(d, _gfn(paddr_to_pfn(v2m_data->addr)),
-                               DIV_ROUND_UP(v2m_data->size, PAGE_SIZE),
+                               PFN_UP(v2m_data->size),
                                _mfn(paddr_to_pfn(v2m_data->addr)));
         if ( ret )
         {
diff --git a/xen/arch/arm/gic-v3.c b/xen/arch/arm/gic-v3.c
index a559e5e260..bb845e955d 100644
--- a/xen/arch/arm/gic-v3.c
+++ b/xen/arch/arm/gic-v3.c
@@ -1283,7 +1283,7 @@  static int gicv3_iomem_deny_access(const struct domain *d)
     unsigned long mfn, nr;
 
     mfn = dbase >> PAGE_SHIFT;
-    nr = DIV_ROUND_UP(SZ_64K, PAGE_SIZE);
+    nr = PFN_UP(SZ_64K);
     rc = iomem_deny_access(d, mfn, mfn + nr);
     if ( rc )
         return rc;
@@ -1291,7 +1291,7 @@  static int gicv3_iomem_deny_access(const struct domain *d)
     for ( i = 0; i < gicv3.rdist_count; i++ )
     {
         mfn = gicv3.rdist_regions[i].base >> PAGE_SHIFT;
-        nr = DIV_ROUND_UP(gicv3.rdist_regions[i].size, PAGE_SIZE);
+        nr = PFN_UP(gicv3.rdist_regions[i].size);
         rc = iomem_deny_access(d, mfn, mfn + nr);
         if ( rc )
             return rc;
@@ -1300,7 +1300,7 @@  static int gicv3_iomem_deny_access(const struct domain *d)
     if ( cbase != INVALID_PADDR )
     {
         mfn = cbase >> PAGE_SHIFT;
-        nr = DIV_ROUND_UP(csize, PAGE_SIZE);
+        nr = PFN_UP(csize);
         rc = iomem_deny_access(d, mfn, mfn + nr);
         if ( rc )
             return rc;
@@ -1309,7 +1309,7 @@  static int gicv3_iomem_deny_access(const struct domain *d)
     if ( vbase != INVALID_PADDR )
     {
         mfn = vbase >> PAGE_SHIFT;
-        nr = DIV_ROUND_UP(csize, PAGE_SIZE);
+        nr = PFN_UP(csize);
         return iomem_deny_access(d, mfn, mfn + nr);
     }
 
diff --git a/xen/arch/arm/kernel.c b/xen/arch/arm/kernel.c
index e2512c4612..0ed8b6005c 100644
--- a/xen/arch/arm/kernel.c
+++ b/xen/arch/arm/kernel.c
@@ -312,7 +312,7 @@  static __init int kernel_decompress(struct bootmodule *mod)
      * Need to free pages after output_size here because they won't be
      * freed by discard_initial_modules
      */
-    i = DIV_ROUND_UP(output_size, PAGE_SIZE);
+    i = PFN_UP(output_size);
     for ( ; i < (1 << kernel_order_out); i++ )
         free_domheap_page(pages + i);