[PATCH v3 10/33] linux-user: Remove HOST_PAGE_ALIGN from mmap.c

Richard Henderson posted 33 patches 10 months, 4 weeks ago
Maintainers: Richard Henderson <richard.henderson@linaro.org>, Paolo Bonzini <pbonzini@redhat.com>, Riku Voipio <riku.voipio@iki.fi>, Warner Losh <imp@bsdimp.com>, Kyle Evans <kevans@freebsd.org>, Stefan Berger <stefanb@linux.vnet.ibm.com>, Eduardo Habkost <eduardo@habkost.net>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Yanan Wang <wangyanan55@huawei.com>, Laurent Vivier <laurent@vivier.eu>, Peter Xu <peterx@redhat.com>, Fabiano Rosas <farosas@suse.de>, David Hildenbrand <david@redhat.com>, Peter Maydell <peter.maydell@linaro.org>, Nicholas Piggin <npiggin@gmail.com>, Daniel Henrique Barboza <danielhb413@gmail.com>, "Cédric Le Goater" <clg@kaod.org>, "Alex Bennée" <alex.bennee@linaro.org>, Yoshinori Sato <ysato@users.sourceforge.jp>
There is a newer version of this series
[PATCH v3 10/33] linux-user: Remove HOST_PAGE_ALIGN from mmap.c
Posted by Richard Henderson 10 months, 4 weeks ago
This removes a hidden use of qemu_host_page_size, using instead
the existing host_page_size local within each function.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/mmap.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/linux-user/mmap.c b/linux-user/mmap.c
index 53e5486cc8..d11f758d07 100644
--- a/linux-user/mmap.c
+++ b/linux-user/mmap.c
@@ -191,7 +191,7 @@ int target_mprotect(abi_ulong start, abi_ulong len, int target_prot)
 
     last = start + len - 1;
     host_start = start & -host_page_size;
-    host_last = HOST_PAGE_ALIGN(last) - 1;
+    host_last = ROUND_UP(last, host_page_size) - 1;
     nranges = 0;
 
     mmap_lock();
@@ -389,8 +389,7 @@ abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size, abi_ulong align)
         start &= -host_page_size;
     }
     start = ROUND_UP(start, align);
-
-    size = HOST_PAGE_ALIGN(size);
+    size = ROUND_UP(size, host_page_size);
 
     if (reserved_va) {
         return mmap_find_vma_reserved(start, size, align);
@@ -550,7 +549,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot,
      */
     if (!(flags & (MAP_FIXED | MAP_FIXED_NOREPLACE))) {
         host_len = len + offset - host_offset;
-        host_len = HOST_PAGE_ALIGN(host_len);
+        host_len = ROUND_UP(host_len, host_page_size);
         start = mmap_find_vma(real_start, host_len, TARGET_PAGE_SIZE);
         if (start == (abi_ulong)-1) {
             errno = ENOMEM;
@@ -595,7 +594,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot,
         void *p;
 
         host_len = len + offset - host_offset;
-        host_len = HOST_PAGE_ALIGN(host_len);
+        host_len = ROUND_UP(host_len, host_page_size);
         host_prot = target_to_host_prot(target_prot);
 
         /* Note: we prefer to control the mapping address. */
@@ -625,7 +624,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot,
             goto fail;
         }
         last = start + len - 1;
-        real_last = HOST_PAGE_ALIGN(last) - 1;
+        real_last = ROUND_UP(last, host_page_size) - 1;
 
         /*
          * Test if requested memory area fits target address space
@@ -794,7 +793,7 @@ static int mmap_reserve_or_unmap(abi_ulong start, abi_ulong len)
 
     last = start + len - 1;
     real_start = start & -host_page_size;
-    real_last = HOST_PAGE_ALIGN(last) - 1;
+    real_last = ROUND_UP(last, host_page_size) - 1;
 
     /*
      * If guest pages remain on the first or last host pages,
-- 
2.34.1
Re: [PATCH v3 10/33] linux-user: Remove HOST_PAGE_ALIGN from mmap.c
Posted by Ilya Leoshkevich 10 months ago
On Tue, Jan 02, 2024 at 12:57:45PM +1100, Richard Henderson wrote:
> This removes a hidden use of qemu_host_page_size, using instead
> the existing host_page_size local within each function.
> 
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  linux-user/mmap.c | 13 ++++++-------
>  1 file changed, 6 insertions(+), 7 deletions(-)

Reviewed-by: Ilya Leoshkevich <iii@linux.ibm.com>
Re: [PATCH v3 10/33] linux-user: Remove HOST_PAGE_ALIGN from mmap.c
Posted by Pierrick Bouvier 10 months, 3 weeks ago
On 1/2/24 05:57, Richard Henderson wrote:
> This removes a hidden use of qemu_host_page_size, using instead
> the existing host_page_size local within each function.
> 
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>   linux-user/mmap.c | 13 ++++++-------
>   1 file changed, 6 insertions(+), 7 deletions(-)
> 
> diff --git a/linux-user/mmap.c b/linux-user/mmap.c
> index 53e5486cc8..d11f758d07 100644
> --- a/linux-user/mmap.c
> +++ b/linux-user/mmap.c
> @@ -191,7 +191,7 @@ int target_mprotect(abi_ulong start, abi_ulong len, int target_prot)
>   
>       last = start + len - 1;
>       host_start = start & -host_page_size;
> -    host_last = HOST_PAGE_ALIGN(last) - 1;
> +    host_last = ROUND_UP(last, host_page_size) - 1;
>       nranges = 0;
>   
>       mmap_lock();
> @@ -389,8 +389,7 @@ abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size, abi_ulong align)
>           start &= -host_page_size;
>       }
>       start = ROUND_UP(start, align);
> -
> -    size = HOST_PAGE_ALIGN(size);
> +    size = ROUND_UP(size, host_page_size);
>   
>       if (reserved_va) {
>           return mmap_find_vma_reserved(start, size, align);
> @@ -550,7 +549,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot,
>        */
>       if (!(flags & (MAP_FIXED | MAP_FIXED_NOREPLACE))) {
>           host_len = len + offset - host_offset;
> -        host_len = HOST_PAGE_ALIGN(host_len);
> +        host_len = ROUND_UP(host_len, host_page_size);
>           start = mmap_find_vma(real_start, host_len, TARGET_PAGE_SIZE);
>           if (start == (abi_ulong)-1) {
>               errno = ENOMEM;
> @@ -595,7 +594,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot,
>           void *p;
>   
>           host_len = len + offset - host_offset;
> -        host_len = HOST_PAGE_ALIGN(host_len);
> +        host_len = ROUND_UP(host_len, host_page_size);
>           host_prot = target_to_host_prot(target_prot);
>   
>           /* Note: we prefer to control the mapping address. */
> @@ -625,7 +624,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot,
>               goto fail;
>           }
>           last = start + len - 1;
> -        real_last = HOST_PAGE_ALIGN(last) - 1;
> +        real_last = ROUND_UP(last, host_page_size) - 1;
>   
>           /*
>            * Test if requested memory area fits target address space
> @@ -794,7 +793,7 @@ static int mmap_reserve_or_unmap(abi_ulong start, abi_ulong len)
>   
>       last = start + len - 1;
>       real_start = start & -host_page_size;
> -    real_last = HOST_PAGE_ALIGN(last) - 1;
> +    real_last = ROUND_UP(last, host_page_size) - 1;
>   
>       /*
>        * If guest pages remain on the first or last host pages,

Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>