[PATCH 2/4] bsd-user: Deal with mmap where start > reserved_va

Bingwu Zhang posted 4 patches 2 days, 16 hours ago
Maintainers: Warner Losh <imp@bsdimp.com>, Kyle Evans <kevans@freebsd.org>, Laurent Vivier <laurent@vivier.eu>, Pierrick Bouvier <pierrick.bouvier@linaro.org>, "Alex Bennée" <alex.bennee@linaro.org>
[PATCH 2/4] bsd-user: Deal with mmap where start > reserved_va
Posted by Bingwu Zhang 2 days, 16 hours ago
From: Bingwu Zhang <xtex@astrafall.org>

Fixes: f12294b5bd21 ("bsd-user: Use page_find_range_empty for mmap_find_vma_reserved")
Signed-off-by: Bingwu Zhang <xtex@astrafall.org>
---
 bsd-user/mmap.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c
index 24ba1728eb55..fe77eceb4856 100644
--- a/bsd-user/mmap.c
+++ b/bsd-user/mmap.c
@@ -258,12 +258,14 @@ abi_ulong mmap_next_start = TASK_UNMAPPED_BASE;
 static abi_ulong mmap_find_vma_reserved(abi_ulong start, abi_ulong size,
                                         abi_ulong alignment)
 {
-    abi_ulong ret;
+    abi_ulong ret = -1;
 
-    ret = page_find_range_empty(start, reserved_va, size, alignment);
+    if (start <= reserved_va) {
+        ret = page_find_range_empty(start, reserved_va, size, alignment);
+    }
     if (ret == -1 && start > TARGET_PAGE_SIZE) {
         /* Restart at the beginning of the address space. */
-        ret = page_find_range_empty(TARGET_PAGE_SIZE, start - 1,
+        ret = page_find_range_empty(TARGET_PAGE_SIZE, MIN(start - 1, reserved_va),
                                     size, alignment);
     }
 

-- 
2.52.0
Re: [PATCH 2/4] bsd-user: Deal with mmap where start > reserved_va
Posted by Warner Losh 2 days, 8 hours ago
On Fri, Feb 27, 2026 at 9:47 AM Bingwu Zhang <xtex@envs.net> wrote:

> From: Bingwu Zhang <xtex@astrafall.org>
>
> Fixes: f12294b5bd21 ("bsd-user: Use page_find_range_empty for
> mmap_find_vma_reserved")
> Signed-off-by: Bingwu Zhang <xtex@astrafall.org>
> ---
>  bsd-user/mmap.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
>

Reviewed-by: Warner Losh <imp@bsdimp.com>

Have you run FreeBSD binaries with this?

Warner


> diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c
> index 24ba1728eb55..fe77eceb4856 100644
> --- a/bsd-user/mmap.c
> +++ b/bsd-user/mmap.c
> @@ -258,12 +258,14 @@ abi_ulong mmap_next_start = TASK_UNMAPPED_BASE;
>  static abi_ulong mmap_find_vma_reserved(abi_ulong start, abi_ulong size,
>                                          abi_ulong alignment)
>  {
> -    abi_ulong ret;
> +    abi_ulong ret = -1;
>
> -    ret = page_find_range_empty(start, reserved_va, size, alignment);
> +    if (start <= reserved_va) {
> +        ret = page_find_range_empty(start, reserved_va, size, alignment);
> +    }
>      if (ret == -1 && start > TARGET_PAGE_SIZE) {
>          /* Restart at the beginning of the address space. */
> -        ret = page_find_range_empty(TARGET_PAGE_SIZE, start - 1,
> +        ret = page_find_range_empty(TARGET_PAGE_SIZE, MIN(start - 1,
> reserved_va),
>                                      size, alignment);
>      }
>
>
> --
> 2.52.0
>
>
Re: [PATCH 2/4] bsd-user: Deal with mmap where start > reserved_va
Posted by Bingwu Zhang 2 days, 8 hours ago
On Saturday, February 28, 2026 7:49:39 AM China Standard Time Warner Losh 
wrote:
> Reviewed-by: Warner Losh <imp@bsdimp.com>

Thank you!

> Have you run FreeBSD binaries with this?

No I didn't. I only ran {i386,riscv32,mips}-linux-user, failed to compile 
tests/tcg/multiarch/test-mmap.c for i386 freebsd, compiler saying mremap is 
undeclared.

-- 
xtex (Bingwu Zhang) @ Sat, 28 Feb 2026 00:41:49 +0000
Re: [PATCH 2/4] bsd-user: Deal with mmap where start > reserved_va
Posted by Warner Losh 2 days, 7 hours ago
On Fri, Feb 27, 2026, 5:46 PM Bingwu Zhang <xtex@envs.net> wrote:

> On Saturday, February 28, 2026 7:49:39 AM China Standard Time Warner Losh
> wrote:
> > Reviewed-by: Warner Losh <imp@bsdimp.com>
>
> Thank you!
>
> > Have you run FreeBSD binaries with this?
>
> No I didn't. I only ran {i386,riscv32,mips}-linux-user, failed to compile
> tests/tcg/multiarch/test-mmap.c for i386 freebsd, compiler saying mremap
> is
> undeclared.
>

Ok. I'm planning on sending my pull request later tonight. You'll likely
need to rebase around that when it lands....  If linux works, you've not
broken bsd-user

Warner

-- 
> xtex (Bingwu Zhang) @ Sat, 28 Feb 2026 00:41:49 +0000
>
>
>
>