Message ID | 20230707204054.8792-18-richard.henderson@linaro.org |
---|---|
State | Superseded |
Headers | show |
Series | linux-user: mmap range fixes | expand |
On Fri, Jul 7, 2023 at 2:41 PM Richard Henderson < richard.henderson@linaro.org> wrote: > Use the interval tree to find empty space, rather than > probing each page in turn. > > Cc: Warner Losh <imp@bsdimp.com> > Cc: Kyle Evans <kevans@freebsd.org> > Signed-off-by: Richard Henderson <richard.henderson@linaro.org> > Reviewed-bt: Warner Losh <imp@bsdimp.com> I tested the prior version (with a different, but equivalent change) and it seemed to work where things had been broken previously. Warner > --- > bsd-user/mmap.c | 48 +++++++----------------------------------------- > 1 file changed, 7 insertions(+), 41 deletions(-) > > diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c > index 07b5b8055e..aca8764356 100644 > --- a/bsd-user/mmap.c > +++ b/bsd-user/mmap.c > @@ -222,50 +222,16 @@ unsigned long last_brk; > static abi_ulong mmap_find_vma_reserved(abi_ulong start, abi_ulong size, > abi_ulong alignment) > { > - abi_ulong addr; > - abi_ulong end_addr; > - int prot; > - int looped = 0; > + abi_ulong ret; > > - if (size > reserved_va) { > - return (abi_ulong)-1; > + 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, > + size, alignment); > } > > - size = HOST_PAGE_ALIGN(size) + alignment; > - end_addr = start + size; > - if (end_addr > reserved_va) { > - end_addr = reserved_va + 1; > - } > - addr = end_addr - qemu_host_page_size; > - > - while (1) { > - if (addr > end_addr) { > - if (looped) { > - return (abi_ulong)-1; > - } > - end_addr = reserved_va + 1; > - addr = end_addr - qemu_host_page_size; > - looped = 1; > - continue; > - } > - prot = page_get_flags(addr); > - if (prot) { > - end_addr = addr; > - } > - if (end_addr - addr >= size) { > - break; > - } > - addr -= qemu_host_page_size; > - } > - > - if (start == mmap_next_start) { > - mmap_next_start = addr; > - } > - /* addr is sufficiently low to align it up */ > - if (alignment != 0) { > - addr = (addr + alignment) & ~(alignment - 1); > - } > - return addr; > + return ret; > } > > /* > -- > 2.34.1 > >
diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c index 07b5b8055e..aca8764356 100644 --- a/bsd-user/mmap.c +++ b/bsd-user/mmap.c @@ -222,50 +222,16 @@ unsigned long last_brk; static abi_ulong mmap_find_vma_reserved(abi_ulong start, abi_ulong size, abi_ulong alignment) { - abi_ulong addr; - abi_ulong end_addr; - int prot; - int looped = 0; + abi_ulong ret; - if (size > reserved_va) { - return (abi_ulong)-1; + 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, + size, alignment); } - size = HOST_PAGE_ALIGN(size) + alignment; - end_addr = start + size; - if (end_addr > reserved_va) { - end_addr = reserved_va + 1; - } - addr = end_addr - qemu_host_page_size; - - while (1) { - if (addr > end_addr) { - if (looped) { - return (abi_ulong)-1; - } - end_addr = reserved_va + 1; - addr = end_addr - qemu_host_page_size; - looped = 1; - continue; - } - prot = page_get_flags(addr); - if (prot) { - end_addr = addr; - } - if (end_addr - addr >= size) { - break; - } - addr -= qemu_host_page_size; - } - - if (start == mmap_next_start) { - mmap_next_start = addr; - } - /* addr is sufficiently low to align it up */ - if (alignment != 0) { - addr = (addr + alignment) & ~(alignment - 1); - } - return addr; + return ret; } /*
Use the interval tree to find empty space, rather than probing each page in turn. Cc: Warner Losh <imp@bsdimp.com> Cc: Kyle Evans <kevans@freebsd.org> Signed-off-by: Richard Henderson <richard.henderson@linaro.org> --- bsd-user/mmap.c | 48 +++++++----------------------------------------- 1 file changed, 7 insertions(+), 41 deletions(-)