[PATCH v3 20/33] linux-user: Do early mmap placement only for reserved_va

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 20/33] linux-user: Do early mmap placement only for reserved_va
Posted by Richard Henderson 10 months, 4 weeks ago
For reserved_va, place all non-fixed maps then proceed
as for MAP_FIXED.

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

diff --git a/linux-user/mmap.c b/linux-user/mmap.c
index cc983bedbd..42eb3eb2b4 100644
--- a/linux-user/mmap.c
+++ b/linux-user/mmap.c
@@ -540,17 +540,19 @@ static abi_long target_mmap__locked(abi_ulong start, abi_ulong len,
     host_offset = offset & -host_page_size;
 
     /*
-     * If the user is asking for the kernel to find a location, do that
-     * before we truncate the length for mapping files below.
+     * For reserved_va, we are in full control of the allocation.
+     * Find a suitible hole and convert to MAP_FIXED.
      */
-    if (!(flags & (MAP_FIXED | MAP_FIXED_NOREPLACE))) {
+    if (reserved_va && !(flags & (MAP_FIXED | MAP_FIXED_NOREPLACE))) {
         host_len = len + offset - host_offset;
-        host_len = ROUND_UP(host_len, host_page_size);
-        start = mmap_find_vma(real_start, host_len, TARGET_PAGE_SIZE);
+        start = mmap_find_vma(real_start, host_len,
+                              MAX(host_page_size, TARGET_PAGE_SIZE));
         if (start == (abi_ulong)-1) {
             errno = ENOMEM;
             return -1;
         }
+        start += offset - host_offset;
+        flags |= MAP_FIXED;
     }
 
     /*
-- 
2.34.1
Re: [PATCH v3 20/33] linux-user: Do early mmap placement only for reserved_va
Posted by Ilya Leoshkevich 10 months ago
On Tue, Jan 02, 2024 at 12:57:55PM +1100, Richard Henderson wrote:
> For reserved_va, place all non-fixed maps then proceed
> as for MAP_FIXED.
> 
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  linux-user/mmap.c | 12 +++++++-----
>  1 file changed, 7 insertions(+), 5 deletions(-)
> 
> diff --git a/linux-user/mmap.c b/linux-user/mmap.c
> index cc983bedbd..42eb3eb2b4 100644
> --- a/linux-user/mmap.c
> +++ b/linux-user/mmap.c
> @@ -540,17 +540,19 @@ static abi_long target_mmap__locked(abi_ulong start, abi_ulong len,
>      host_offset = offset & -host_page_size;
>  
>      /*
> -     * If the user is asking for the kernel to find a location, do that
> -     * before we truncate the length for mapping files below.
> +     * For reserved_va, we are in full control of the allocation.
> +     * Find a suitible hole and convert to MAP_FIXED.

suitable?

[...]

Reviewed-by: Ilya Leoshkevich <iii@linux.ibm.com>
Re: [PATCH v3 20/33] linux-user: Do early mmap placement only for reserved_va
Posted by Pierrick Bouvier 10 months, 3 weeks ago
On 1/2/24 05:57, Richard Henderson wrote:
> For reserved_va, place all non-fixed maps then proceed
> as for MAP_FIXED.
> 
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>   linux-user/mmap.c | 12 +++++++-----
>   1 file changed, 7 insertions(+), 5 deletions(-)
> 
> diff --git a/linux-user/mmap.c b/linux-user/mmap.c
> index cc983bedbd..42eb3eb2b4 100644
> --- a/linux-user/mmap.c
> +++ b/linux-user/mmap.c
> @@ -540,17 +540,19 @@ static abi_long target_mmap__locked(abi_ulong start, abi_ulong len,
>       host_offset = offset & -host_page_size;
>   
>       /*
> -     * If the user is asking for the kernel to find a location, do that
> -     * before we truncate the length for mapping files below.
> +     * For reserved_va, we are in full control of the allocation.
> +     * Find a suitible hole and convert to MAP_FIXED.
>        */
> -    if (!(flags & (MAP_FIXED | MAP_FIXED_NOREPLACE))) {
> +    if (reserved_va && !(flags & (MAP_FIXED | MAP_FIXED_NOREPLACE))) {
>           host_len = len + offset - host_offset;
> -        host_len = ROUND_UP(host_len, host_page_size);
> -        start = mmap_find_vma(real_start, host_len, TARGET_PAGE_SIZE);
> +        start = mmap_find_vma(real_start, host_len,
> +                              MAX(host_page_size, TARGET_PAGE_SIZE));
>           if (start == (abi_ulong)-1) {
>               errno = ENOMEM;
>               return -1;
>           }
> +        start += offset - host_offset;
> +        flags |= MAP_FIXED;
>       }
>   
>       /*

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