From patchwork Fri May 21 13:28:17 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Edgar E. Iglesias" X-Patchwork-Id: 53155 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id A2E1EB7D29 for ; Fri, 21 May 2010 23:38:48 +1000 (EST) Received: from localhost ([127.0.0.1]:55328 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OFSR3-0000eh-GW for incoming@patchwork.ozlabs.org; Fri, 21 May 2010 09:38:45 -0400 Received: from [140.186.70.92] (port=51104 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OFSOa-0008OM-Ik for qemu-devel@nongnu.org; Fri, 21 May 2010 09:36:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OFSOU-0007Gh-V9 for qemu-devel@nongnu.org; Fri, 21 May 2010 09:36:12 -0400 Received: from miranda.se.axis.com ([193.13.178.8]:51367) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OFSOU-0007Fi-Ic for qemu-devel@nongnu.org; Fri, 21 May 2010 09:36:06 -0400 Received: from localhost (edgar.se.axis.com [10.93.151.1]) by miranda.se.axis.com (8.13.4/8.13.4/Debian-3sarge3) with ESMTP id o4LDa3w2014820 for ; Fri, 21 May 2010 15:36:03 +0200 Date: Fri, 21 May 2010 15:28:17 +0200 From: "Edgar E. Iglesias" To: qemu-devel@nongnu.org Message-ID: <20100521132817.GA8021@edde.se.axis.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) Subject: [Qemu-devel] linux-user mmap bug X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Hi I ran into an mmap problem linux-user emulating CRIS (32bit) on x86_64 hosts. Guest asks for a non fixed mmap, QEMU tries the mmap but the kernel returns a high 64bit address. QEMU notices that it wont fit in the guests 32bit ptr size and retries with a low address but doesn't set the MAP_FIXED flag. Was something like the following patch the intended behaviour or did I missunderstand something? (it fixes my problem at least...) Cheers commit 96fd8e3fdedb697ba249f32245751a28979c3fab Author: Edgar E. Iglesias Date: Fri May 21 15:22:11 2010 +0200 linux-user: Set MAP_FIXED for mmap address fixups. Signed-off-by: Edgar E. Iglesias diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 6a1d933..5308fe1 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -304,7 +304,11 @@ abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size) * - shmat() with SHM_REMAP flag */ ptr = mmap(g2h(addr), size, PROT_NONE, - MAP_ANONYMOUS|MAP_PRIVATE|MAP_NORESERVE, -1, 0); + /* When the kernel returns addresses that the guest + cannot use we might need to fallback to fixed + allocations. */ + (addr ? MAP_FIXED : 0) + | MAP_ANONYMOUS|MAP_PRIVATE|MAP_NORESERVE, -1, 0); /* ENOMEM, if host address space has no memory */ if (ptr == MAP_FAILED) {