From patchwork Sun Mar 4 01:45:34 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 144476 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 0CFFBB6F9D for ; Sun, 4 Mar 2012 12:45:50 +1100 (EST) Received: from localhost ([::1]:52001 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S40WB-0000Oa-E7 for incoming@patchwork.ozlabs.org; Sat, 03 Mar 2012 20:45:47 -0500 Received: from eggs.gnu.org ([208.118.235.92]:52475) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S40W3-0000Nv-8n for qemu-devel@nongnu.org; Sat, 03 Mar 2012 20:45:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S40W1-0003jY-3I for qemu-devel@nongnu.org; Sat, 03 Mar 2012 20:45:38 -0500 Received: from cantor2.suse.de ([195.135.220.15]:34810 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S40W0-0003jT-Pc for qemu-devel@nongnu.org; Sat, 03 Mar 2012 20:45:37 -0500 Received: from relay2.suse.de (unknown [195.135.220.254]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx2.suse.de (Postfix) with ESMTP id 35A048C061; Sun, 4 Mar 2012 02:45:35 +0100 (CET) From: Alexander Graf To: qemu-devel qemu-devel Date: Sun, 4 Mar 2012 02:45:34 +0100 Message-Id: <1330825534-5562-1-git-send-email-agraf@suse.de> X-Mailer: git-send-email 1.7.3.4 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6 X-Received-From: 195.135.220.15 Cc: "Bernhard M. Wiedemann" , Riku Voipio , Paul Brook , Peter Maydell Subject: [Qemu-devel] [PATCH] linux-user: resolve reserved_va vma downwards X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org After consulting with Paul Brook, we concluded that it's best to search the VMA space downwards, so that we don't even get the chance to conflict with the brk range. This patch resolves a bunch of allocation conflicts when using -R. Signed-off-by: Alexander Graf --- This replaces the other patches I sent out earlier today. --- linux-user/main.c | 1 + linux-user/mmap.c | 35 ++++++++++++++++++++++++----------- linux-user/qemu.h | 1 + 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/linux-user/main.c b/linux-user/main.c index 6a5dfde..d61d731 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -3437,6 +3437,7 @@ int main(int argc, char **argv, char **envp) guest_base = HOST_PAGE_ALIGN((unsigned long)p); } qemu_log("Reserved 0x%lx bytes of guest address space\n", reserved_va); + mmap_next_start = reserved_va; } if (reserved_va || have_guest_base) { diff --git a/linux-user/mmap.c b/linux-user/mmap.c index e4db455..2620f88 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -212,7 +212,7 @@ static int mmap_frag(abi_ulong real_start, #else # define TASK_UNMAPPED_BASE 0x18000000 #endif -static abi_ulong mmap_next_start = TASK_UNMAPPED_BASE; +abi_ulong mmap_next_start = TASK_UNMAPPED_BASE; unsigned long last_brk; @@ -222,7 +222,7 @@ unsigned long last_brk; static abi_ulong mmap_find_vma_reserved(abi_ulong start, abi_ulong size) { abi_ulong addr; - abi_ulong last_addr; + abi_ulong end_addr; int prot; int looped = 0; @@ -230,25 +230,38 @@ static abi_ulong mmap_find_vma_reserved(abi_ulong start, abi_ulong size) return (abi_ulong)-1; } - last_addr = start; - for (addr = start; last_addr + size != addr; addr += qemu_host_page_size) { - if (last_addr + size >= RESERVED_VA - || (abi_ulong)(last_addr + size) < last_addr) { + size = HOST_PAGE_ALIGN(size); + end_addr = start + size; + if (end_addr > RESERVED_VA) { + end_addr = RESERVED_VA; + } + addr = end_addr - qemu_host_page_size; + + while (1) { + if (addr > end_addr) { if (looped) { return (abi_ulong)-1; } - last_addr = qemu_host_page_size; - addr = 0; + end_addr = RESERVED_VA; + addr = end_addr - qemu_host_page_size; looped = 1; continue; } prot = page_get_flags(addr); if (prot) { - last_addr = addr + qemu_host_page_size; + end_addr = addr; + } + if (addr + size == end_addr) { + break; } + addr -= qemu_host_page_size; + } + + if (start == mmap_next_start) { + mmap_next_start = addr; } - mmap_next_start = addr; - return last_addr; + + return addr; } #endif diff --git a/linux-user/qemu.h b/linux-user/qemu.h index aa06acf..5dc0720 100644 --- a/linux-user/qemu.h +++ b/linux-user/qemu.h @@ -254,6 +254,7 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, abi_ulong new_addr); int target_msync(abi_ulong start, abi_ulong len, int flags); extern unsigned long last_brk; +extern abi_ulong mmap_next_start; void mmap_lock(void); void mmap_unlock(void); abi_ulong mmap_find_vma(abi_ulong, abi_ulong);