From patchwork Sun Jul 15 19:52:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 944089 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=vivier.eu Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41THQB33Dmz9rxs for ; Mon, 16 Jul 2018 05:57:38 +1000 (AEST) Received: from localhost ([::1]:47362 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fen9E-0005bR-44 for incoming@patchwork.ozlabs.org; Sun, 15 Jul 2018 15:57:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54025) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fen51-00036h-Q7 for qemu-devel@nongnu.org; Sun, 15 Jul 2018 15:53:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fen4x-000650-32 for qemu-devel@nongnu.org; Sun, 15 Jul 2018 15:53:15 -0400 Received: from mout.kundenserver.de ([217.72.192.74]:59213) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fen4w-00062n-O7 for qemu-devel@nongnu.org; Sun, 15 Jul 2018 15:53:10 -0400 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue104 [212.227.15.183]) with ESMTPSA (Nemesis) id 0M731J-1g1Ymf3JVV-00wmPE; Sun, 15 Jul 2018 21:53:01 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Sun, 15 Jul 2018 21:52:41 +0200 Message-Id: <20180715195242.6645-4-laurent@vivier.eu> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180715195242.6645-1-laurent@vivier.eu> References: <20180715195242.6645-1-laurent@vivier.eu> X-Provags-ID: V03:K1:OYiNsALAZo76ku2sF18Wp63CqbZgf16v9MY4H6fzlcxkjQ01rp+ 12v+CNPjfNJ0itXfW36uCeGVX6GltRppd2F+zcKrw4dlHdcNX4EjBgNEqLZ+dpk5FJglGa6 fc0HvzQjtXpZq3+Ib+S1ibx9q+usGFbx3whgPzBLcL4dkbrd8sv8Gj2o8Les4D92FB4oziw WtsXh/KV2IpdSRw7meb9w== X-UI-Out-Filterresults: notjunk:1; V01:K0:kz4Cb0ZAJPE=:IBPd7JNPVfmudnAWcYn1zT da5ORIUpjW2xKm7jngTntPP6JNQShvxh403hJOrlFJ7OUA3IaC4+iTX0psi7SrVpI7ntrjBAj dp57nXaNRsBMZhBfQyc/lYRG3BX2sr/o1uwYysr9Dy0uzvKngiUgfnjf9ltJLladNUQrqEZNm l2ovrZQ1TJjfy4WfbpgBl5X4l+FjyUIFaljT9g2kUoOFqcOUbtWKDVjFDeRhz+syVbZ0VG97G J4Kpke91evxNWqDeT0MYlIrjgUw5IgqbGvZeiSUMXbyasaw1MuK7YFHqfUTUSwKAo41BId+5i hc7uP8lM6spQxkehgmCuCx92U4gvsHQYBVX8YO9ALTgMkPjLvXq1ArVh/c7FBQ/OlfhnKQcrJ Far62+M0Sepun//2Dlc8aXwNTFET0RvE7opsRUmOvj2a4q6Oq/oXzuoMCR6uSLs8+GvXRl5n+ t0EwS8kxWZ/LgCkpufQE40m/6Uif/5hw4rKc7IYqDW2Mq40jgEodLRg7VZOxOigWXmOqqYFD0 IkXkxj2AItaiP3+fJK5HnVtYcJyijtZv2vjWEBYsNQ+ln1mNvL+U/YLHT9hV7KRyEXY1pXyDS DnOi/iZ2VxN/j0IXQ0Y9q6dj9ojQgh6dnz5LN7VM+igKqUZZXE/fTNSDLPkB96zVIucx70Nix 4HRD37ejyvVziBbf4GuWPPcSvdLu+6o5X9ZSQHS+0Cx5dMt+AiUOFAc0n3OvDDXdSxfM= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 217.72.192.74 Subject: [Qemu-devel] [PULL 3/4] linux-user: fix mmap_find_vma_reserved() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Riku Voipio , Laurent Vivier Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 Reviewed-by: Richard Henderson Message-Id: <20180714193553.30846-1-laurent@vivier.eu> --- linux-user/main.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/linux-user/main.c b/linux-user/main.c index 52b5a618fe..ea00dd9057 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -78,14 +78,7 @@ int have_guest_base; # endif #endif -/* That said, reserving *too* much vm space via mmap can run into problems - with rlimits, oom due to page table creation, etc. We will still try it, - if directed by the command-line option, but not by default. */ -#if HOST_LONG_BITS == 64 && TARGET_VIRT_ADDR_SPACE_BITS <= 32 -unsigned long reserved_va = MAX_RESERVED_VA; -#else unsigned long reserved_va; -#endif static void usage(int exitcode); @@ -672,6 +665,18 @@ int main(int argc, char **argv, char **envp) /* init tcg before creating CPUs and to get qemu_host_page_size */ tcg_exec_init(0); + /* Reserving *too* much vm space via mmap can run into problems + with rlimits, oom due to page table creation, etc. We will still try it, + if directed by the command-line option, but not by default. */ + if (HOST_LONG_BITS == 64 && + TARGET_VIRT_ADDR_SPACE_BITS <= 32 && + reserved_va == 0) { + /* reserved_va must be aligned with the host page size + * as it is used with mmap() + */ + reserved_va = MAX_RESERVED_VA & qemu_host_page_mask; + } + cpu = cpu_create(cpu_type); env = cpu->env_ptr; cpu_reset(cpu);