From patchwork Sat Jul 14 19:35:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 943990 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 41Sg0s3G50z9s1R for ; Sun, 15 Jul 2018 05:36:59 +1000 (AEST) Received: from localhost ([::1]:42523 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1feQLe-0004kq-FG for incoming@patchwork.ozlabs.org; Sat, 14 Jul 2018 15:36:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55528) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1feQLE-0004jn-LX for qemu-devel@nongnu.org; Sat, 14 Jul 2018 15:36:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1feQL9-0005tS-OK for qemu-devel@nongnu.org; Sat, 14 Jul 2018 15:36:28 -0400 Received: from mout.kundenserver.de ([212.227.17.24]:57785) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1feQL9-0005s7-Dz for qemu-devel@nongnu.org; Sat, 14 Jul 2018 15:36:23 -0400 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue105 [212.227.15.183]) with ESMTPSA (Nemesis) id 0MA6Lx-1flLHb3jdR-00BHvS; Sat, 14 Jul 2018 21:36:07 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Sat, 14 Jul 2018 21:35:53 +0200 Message-Id: <20180714193553.30846-1-laurent@vivier.eu> X-Mailer: git-send-email 2.17.1 X-Provags-ID: V03:K1:oNpsoOjYyBytufh0vk0ZyE/nAlLYkI39F1zwSGy8V0y7NMdWody 971phYwh9oMdAizvRjnQCtZbk6paP1p2D83n2cmfsXhu8FT7QpiyVcGS6LXsR1mDtTdoy6k /4E+TxNZfxH/AxmsM3lCWNo1ApWtTRrbfWEmkO8NyF6IcO2SBVjCDZpITr57XbW7o+fmwVs 07bOvXbJvYlkaq6V4OK/A== X-UI-Out-Filterresults: notjunk:1; V01:K0:hMPtDTO2Kgw=:k6IHGmvFAl5/G4sxXPU/Ue tB89uUiDNc3Odxstth15sVF3i7l5vS7p0YxUCuF5QQ+ugMexCT40XMCd/yPJucVLr/LA0bywR X+LJJ/OqqUfoKHrGA15O7T+dS8jAdGbpXYjvqA7qNh3PNEvbiI6fWx1n4H07D3rmCOce9GqnC 1ulnjwxpN+7G9aQBR8A0guYgDqaDPnhQVF+uXmbLqYqC8HlxNbEYLDE8PihPezbD8fJSQTFPR LW7eq2Ln4YXXy66Tjm8iRCpbVfuFKv5kOUIYO0g1yJIjMB2/LTMuRyjgD+PxCHevdA+fCmxPC qrUCDWhjrqO2esHRQ3wmjQ75Pc9mfVyyTby0Ki3gv2q3kx6HZCWYhv7RA2/FzWHStRmJFVs4v o+E8Mbw6/HYg8Hc8yRpGa+xlmMtFgiuqz4mz4EjOpe0gMN3i5hkec6hXKvfxf4mKu3UzDEGjE RliqFuedyr7maavOkYpT6y8yDNk1aZ76FyBI+fZnftfmZ4QB9eUnvejnPWAKejZWL1De1iO6V BGRELlWvLXTWPpxNDHD8qu6vNViEy3MdJLKtBTzROYrbLrsZaLgnwY5Rt2LQOrg6Wz+x0t+7R kGkf1Aq+Ra6tdDqzal+i61W4s8ezhXqG/7kauKPgBDXa5v2k3gkqyMKq4q3yYlObXnmX+sDQC nAVDr3q6H1d1t+Xb3xxZpBczn8P3co0fNIn089igQKbfVdIH4iG8cm8Uv6DcHvU0iESI= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 212.227.17.24 Subject: [Qemu-devel] [PATCH v3] 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 , Richard Henderson , 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 --- Notes: v3: move initialization of reserved_va to main() v2: fix typo s/has/as/ 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);