[PATCH v6 1/8] linux-user: Unset MAP_FIXED_NOREPLACE for host

Helge Deller posted 8 patches 2 years, 6 months ago
Maintainers: Richard Henderson <richard.henderson@linaro.org>, Paolo Bonzini <pbonzini@redhat.com>, Laurent Vivier <laurent@vivier.eu>
There is a newer version of this series
[PATCH v6 1/8] linux-user: Unset MAP_FIXED_NOREPLACE for host
Posted by Helge Deller 2 years, 6 months ago
From: Akihiko Odaki <akihiko.odaki@daynix.com>

Passing MAP_FIXED_NOREPLACE to host will fail if the virtual
address space is reserved with mmap. Replace it with MAP_FIXED.

Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
Reviewed-by: Helge Deller <deller@gmx.de>
Signed-off-by: Helge Deller <deller@gmx.de>
---
 linux-user/mmap.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/linux-user/mmap.c b/linux-user/mmap.c
index a5dfb56545..2f26cbaf5d 100644
--- a/linux-user/mmap.c
+++ b/linux-user/mmap.c
@@ -610,6 +610,8 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot,
             goto fail;
         }

+        flags = (flags & ~MAP_FIXED_NOREPLACE) | MAP_FIXED;
+
         /*
          * worst case: we cannot map the file because the offset is not
          * aligned, so we read it
--
2.41.0
Re: [PATCH v6 1/8] linux-user: Unset MAP_FIXED_NOREPLACE for host
Posted by Richard Henderson 2 years, 6 months ago
On 8/1/23 16:27, Helge Deller wrote:
> From: Akihiko Odaki <akihiko.odaki@daynix.com>
> 
> Passing MAP_FIXED_NOREPLACE to host will fail if the virtual
> address space is reserved with mmap. Replace it with MAP_FIXED.
> 
> Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
> Reviewed-by: Helge Deller <deller@gmx.de>
> Signed-off-by: Helge Deller <deller@gmx.de>
> ---
>   linux-user/mmap.c | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/linux-user/mmap.c b/linux-user/mmap.c
> index a5dfb56545..2f26cbaf5d 100644
> --- a/linux-user/mmap.c
> +++ b/linux-user/mmap.c
> @@ -610,6 +610,8 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot,
>               goto fail;
>           }
> 
> +        flags = (flags & ~MAP_FIXED_NOREPLACE) | MAP_FIXED;


Again, this must be restricted to reserved_va == 0 or 64-bit guests will fail.


r~

> +
>           /*
>            * worst case: we cannot map the file because the offset is not
>            * aligned, so we read it
> --
> 2.41.0
>