All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v2] linux-user: fix mmap_find_vma_reserved()
@ 2018-07-11 16:40 Laurent Vivier
  2018-07-11 18:27 ` Laurent Vivier
  2018-07-11 20:41 ` Richard Henderson
  0 siblings, 2 replies; 4+ messages in thread
From: Laurent Vivier @ 2018-07-11 16:40 UTC (permalink / raw)
  To: qemu-devel; +Cc: Riku Voipio, Richard Henderson, Laurent Vivier

The value given by mmap_find_vma_reserved() is used with mmap(),
so it is needed to be aligned with the host page size.

Since commit 18e80c55bb, reserved_va is only aligned to TARGET_PAGE_SIZE,
and it works well if this size is greater or equal to the host page size.

But ppc64 hosts have 64kB page size and when we start a 4kiB page size
guest (like i386), it fails when it tries to mmap the stack:

    mmap stack: Invalid argument

Fixes: 18e80c55bb (linux-user: Tidy and enforce reserved_va initialization)
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---

Notes:
    v2:
      fix typo s/has/as/

 linux-user/main.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/linux-user/main.c b/linux-user/main.c
index 52b5a618fe..15299e9dd7 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -689,6 +689,11 @@ int main(int argc, char **argv, char **envp)
     target_environ = envlist_to_environ(envlist, NULL);
     envlist_free(envlist);
 
+    /* reserved_va must be aligned with the host page size
+     * as it is used with mmap()
+     */
+    reserved_va &= qemu_host_page_mask;
+
     /*
      * Now that page sizes are configured in tcg_exec_init() we can do
      * proper page alignment for guest_base.
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH v2] linux-user: fix mmap_find_vma_reserved()
  2018-07-11 16:40 [Qemu-devel] [PATCH v2] linux-user: fix mmap_find_vma_reserved() Laurent Vivier
@ 2018-07-11 18:27 ` Laurent Vivier
  2018-07-11 20:44   ` Richard Henderson
  2018-07-11 20:41 ` Richard Henderson
  1 sibling, 1 reply; 4+ messages in thread
From: Laurent Vivier @ 2018-07-11 18:27 UTC (permalink / raw)
  To: qemu-devel, Richard Henderson; +Cc: Riku Voipio

Le 11/07/2018 à 18:40, Laurent Vivier a écrit :
> The value given by mmap_find_vma_reserved() is used with mmap(),
> so it is needed to be aligned with the host page size.
> 
> Since commit 18e80c55bb, reserved_va is only aligned to TARGET_PAGE_SIZE,
> and it works well if this size is greater or equal to the host page size.
> 
> But ppc64 hosts have 64kB page size and when we start a 4kiB page size
> guest (like i386), it fails when it tries to mmap the stack:
> 
>     mmap stack: Invalid argument
> 
> Fixes: 18e80c55bb (linux-user: Tidy and enforce reserved_va initialization)
> Signed-off-by: Laurent Vivier <laurent@vivier.eu>

Richard,

I think this fix could be merged into your "linux-user: Fix shmat
emulation by honoring host SHMLBA" patch, by adding something like this
instead:

--- a/linux-user/mmap.c
+++ b/linux-user/mmap.c
@@ -262,6 +262,8 @@ abi_ulong mmap_find_vma(abi_ulong start, abi_ulong
size, abi_ulong align)
     abi_ulong addr;
     int wrapped, repeat;

+    align = MAX(align, qemu_host_page_size);
+
     /* If 'start' == 0, then a default start address is used. */
     if (start == 0) {
         start = mmap_next_start;

Thanks,
Laurent

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH v2] linux-user: fix mmap_find_vma_reserved()
  2018-07-11 16:40 [Qemu-devel] [PATCH v2] linux-user: fix mmap_find_vma_reserved() Laurent Vivier
  2018-07-11 18:27 ` Laurent Vivier
@ 2018-07-11 20:41 ` Richard Henderson
  1 sibling, 0 replies; 4+ messages in thread
From: Richard Henderson @ 2018-07-11 20:41 UTC (permalink / raw)
  To: Laurent Vivier, qemu-devel; +Cc: Riku Voipio

On 07/11/2018 09:40 AM, Laurent Vivier wrote:
> The value given by mmap_find_vma_reserved() is used with mmap(),
> so it is needed to be aligned with the host page size.
> 
> Since commit 18e80c55bb, reserved_va is only aligned to TARGET_PAGE_SIZE,
> and it works well if this size is greater or equal to the host page size.
> 
> But ppc64 hosts have 64kB page size and when we start a 4kiB page size
> guest (like i386), it fails when it tries to mmap the stack:
> 
>     mmap stack: Invalid argument
> 
> Fixes: 18e80c55bb (linux-user: Tidy and enforce reserved_va initialization)
> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
> ---
> 
> Notes:
>     v2:
>       fix typo s/has/as/
> 
>  linux-user/main.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/linux-user/main.c b/linux-user/main.c
> index 52b5a618fe..15299e9dd7 100644
> --- a/linux-user/main.c
> +++ b/linux-user/main.c
> @@ -689,6 +689,11 @@ int main(int argc, char **argv, char **envp)
>      target_environ = envlist_to_environ(envlist, NULL);
>      envlist_free(envlist);
>  
> +    /* reserved_va must be aligned with the host page size
> +     * as it is used with mmap()
> +     */
> +    reserved_va &= qemu_host_page_mask;
> +

So... this silently overrides the command-line argument.  The current code is
only a problem because we assign the default to a global variable, which must
be a compile-time constant.

I wonder if it's worth add an error message in handle_arg_reserved_va, and
moving the default initialization logic from the global variable to here, as

    if (HOST_LONG_BITS == 64 &&
        TARGET_VIRT_ADDR_SPACE_BITS <= 32 &&
        reserved_va == 0) {
        reserved_va = MAX_RESERVED_VA & qemu_host_page_mask;
    }

merging your comment with the moved comment from the global variable init.


r~

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH v2] linux-user: fix mmap_find_vma_reserved()
  2018-07-11 18:27 ` Laurent Vivier
@ 2018-07-11 20:44   ` Richard Henderson
  0 siblings, 0 replies; 4+ messages in thread
From: Richard Henderson @ 2018-07-11 20:44 UTC (permalink / raw)
  To: Laurent Vivier, qemu-devel; +Cc: Riku Voipio

On 07/11/2018 01:27 PM, Laurent Vivier wrote:
> Richard,
> 
> I think this fix could be merged into your "linux-user: Fix shmat
> emulation by honoring host SHMLBA" patch, by adding something like this
> instead:

Well, not "instead", but "in addition".

Nothing works right when the guest adjustment itself is unaligned, as is the
case with reserved_va as you noted, and with (non-reserved) guest_base as I
noted in that patch.

For v2, I'll split the guest_base fix out to a separate patch.


r~

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-07-11 20:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-11 16:40 [Qemu-devel] [PATCH v2] linux-user: fix mmap_find_vma_reserved() Laurent Vivier
2018-07-11 18:27 ` Laurent Vivier
2018-07-11 20:44   ` Richard Henderson
2018-07-11 20:41 ` Richard Henderson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.