From nobody Wed Nov 5 00:16:10 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1531684696867638.071570470401; Sun, 15 Jul 2018 12:58:16 -0700 (PDT) Received: from localhost ([::1]:47363 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fen9h-0005ts-SF for importer@patchew.org; Sun, 15 Jul 2018 15:58:05 -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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 =20 -/* 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 i= t, - if directed by the command-line option, but not by default. */ -#if HOST_LONG_BITS =3D=3D 64 && TARGET_VIRT_ADDR_SPACE_BITS <=3D 32 -unsigned long reserved_va =3D MAX_RESERVED_VA; -#else unsigned long reserved_va; -#endif =20 static void usage(int exitcode); =20 @@ -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); =20 + /* Reserving *too* much vm space via mmap can run into problems + with rlimits, oom due to page table creation, etc. We will still t= ry it, + if directed by the command-line option, but not by default. */ + if (HOST_LONG_BITS =3D=3D 64 && + TARGET_VIRT_ADDR_SPACE_BITS <=3D 32 && + reserved_va =3D=3D 0) { + /* reserved_va must be aligned with the host page size + * as it is used with mmap() + */ + reserved_va =3D MAX_RESERVED_VA & qemu_host_page_mask; + } + cpu =3D cpu_create(cpu_type); env =3D cpu->env_ptr; cpu_reset(cpu); --=20 2.17.1