From patchwork Sun Jun 9 16:55:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13691302 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2871AC27C53 for ; Sun, 9 Jun 2024 16:57:55 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sGLqP-0002uD-HE; Sun, 09 Jun 2024 12:56:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sGLqO-0002tr-93 for qemu-devel@nongnu.org; Sun, 09 Jun 2024 12:56:36 -0400 Received: from mail-il1-x136.google.com ([2607:f8b0:4864:20::136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sGLqM-0000vQ-1a for qemu-devel@nongnu.org; Sun, 09 Jun 2024 12:56:36 -0400 Received: by mail-il1-x136.google.com with SMTP id e9e14a558f8ab-3759a6423a6so3981145ab.1 for ; Sun, 09 Jun 2024 09:56:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1717952192; x=1718556992; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tZ41jQOZIrAJPpWZ/KQuq7bouGxwk1FqF78+aO7+wdo=; b=pzkAiMdd4uCmXs5Qkm/Gy0NwnwJRyuduEycE8Xa9nv/PM38SehdoUhAHT+W9Iw7KxI vsUHCglDAXi1clXOln47pNrkP1jyzd888KKDrJD2XZN0jqvc5rAbn9A9P94pkrnXLQ02 UnM7fiy2wGicOF693TaYANy7MH63ReC3T/laeSWwFOG8pm7FhpZ5BPY4zxgbYjJ3ka/f FKQyfmWDk13baSdIsR15C7wSfiEWmX6hzAy4QWnQkoQigMRKzP032otYVUWNjgY6Ccpj kPtbCXBmYfHSsZISSkwFQqsl257jukyuLgDHu+T1jzW2eOVptnFv4DLWAzHLt2/eo7PP IYcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717952192; x=1718556992; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tZ41jQOZIrAJPpWZ/KQuq7bouGxwk1FqF78+aO7+wdo=; b=LUN/CiA7Y29p/21HzLDfgvGyn0y0NnugSr584Kd/0E3KS+4l5rUrdCjB5qpvinjWvh VJWLQ0ojlO2dwcgP8d+fEfrX2QrdVvFuB9nwY1Y57UWoDHrpbk1XYu8DM57WWzgIWL0d d6a36BO1a+xsULWIe69TboeYtTFwLbZTTPX8oaThUlkTWNPdvwwDir3LnQVmjLzQfu0b vvw01v10dP9ADxMPCZ2xkb2Yv8deHPfkb7Xb0AdQ863FuVNfu02S8eEpbrBxmFbZhVJx HIiJk9xMIe8E9yBY2C7PkGpVx5JOv7l+EtRluI8UF9FUQc60kTH7FORhvqQwqrgDbCTy 5PgA== X-Gm-Message-State: AOJu0YyoK9uBVX0GAt6p+eRnxJ2WhNz5SDFlRAqRnKZ4emwUTUvJNOoj rYDaBh/jrcN0ZBXyvUXcYh2uOOsYloEkR1Audg4UnwpYffGFEtaqMaUzB1ijmodcdSfRvNE5agM RrX0= X-Google-Smtp-Source: AGHT+IG37uBZW3PpabHaHDmI97lPKkCBR4534TOf/myvIf6uFhBU8ABkn8Ik0H1p8zgZL+wkEZYWjA== X-Received: by 2002:a05:6e02:b27:b0:374:aa87:bcaa with SMTP id e9e14a558f8ab-37580314d52mr91161615ab.14.1717952191884; Sun, 09 Jun 2024 09:56:31 -0700 (PDT) Received: from dune.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id e9e14a558f8ab-374bc1c82d4sm18891715ab.80.2024.06.09.09.56.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jun 2024 09:56:31 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Richard Henderson , Laurent Vivier , Warner Losh , Kyle Evans Subject: [PULL 1/3] linux-user: Adjust comment to reflect the code. Date: Sun, 9 Jun 2024 10:55:55 -0600 Message-ID: <20240609165557.52555-2-imp@bsdimp.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240609165557.52555-1-imp@bsdimp.com> References: <20240609165557.52555-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::136; envelope-from=imp@bsdimp.com; helo=mail-il1-x136.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org If the user didn't specify reserved_va, there's an else for 64-bit host 32-bit (or fewer) target to reserve 32-bits of address space. Update the comments to reflect this, and rejustify comment to 80 columns. Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- linux-user/main.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/linux-user/main.c b/linux-user/main.c index 94e4c47f052..94c99a1366f 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -814,10 +814,10 @@ int main(int argc, char **argv, char **envp) thread_cpu = cpu; /* - * 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. + * 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. Unless we're running a + * target address space of 32 or fewer bits on a host with 64 bits. */ max_reserved_va = MAX_RESERVED_VA(cpu); if (reserved_va != 0) { From patchwork Sun Jun 9 16:55:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13691299 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 139CEC27C55 for ; Sun, 9 Jun 2024 16:57:38 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sGLqS-0002vO-1q; Sun, 09 Jun 2024 12:56:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sGLqP-0002uE-FE for qemu-devel@nongnu.org; Sun, 09 Jun 2024 12:56:37 -0400 Received: from mail-il1-x129.google.com ([2607:f8b0:4864:20::129]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sGLqN-0000vc-Gx for qemu-devel@nongnu.org; Sun, 09 Jun 2024 12:56:37 -0400 Received: by mail-il1-x129.google.com with SMTP id e9e14a558f8ab-3759a6423a6so3981235ab.1 for ; Sun, 09 Jun 2024 09:56:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1717952193; x=1718556993; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gJYt42UkCG9pSrAZeGw/ivMlzQ7uAl4WEIfygl4y5Jw=; b=YORn0eoSEAHkCcWGYmftiATcsVFnC3rp+ClZgaWaQSlZJyjWCCKFZAs/PeZVGCCIUD BC4gpQ39QtUq8jeJUBQc8Msj8HCWPjaZxYHl1SOc77HGAuq+RIsCyezZGJN02Klqix83 fj+oD0g9zEEO1/8WFuwKTUemnqu4g2nZqnvUUzC/QsysNayV5Dk1Co8nOzUag4kvEOHS DDHBI0f6Pzp5SzxJ7HvhKLv9vZw6fglXVq77qRVoIrMGi+wd6nW/dDmcA9U19uIVdH1t VWxgDsiact/yPiooVW13NFm4NwnaekOz/2WHHBQZYzFB6ORD0i+tPXBV7tiDnebRbQvq 0gbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717952193; x=1718556993; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gJYt42UkCG9pSrAZeGw/ivMlzQ7uAl4WEIfygl4y5Jw=; b=wlzUVW5ZGsQIxZ/y+CmaVFqr2otk46VlybuUzqpTprjWfXUsoatHX8rV5YmZFi7SLF DKw5De15Vg3UX5qXM9H8Q9P+KTJSEVcARCClWt4EMFPmVgH3kx7W6jE8TtA+9SmMClwZ br4cB03K/Fm37vr+uOq558ugmCkIU9ahMl0U8xuvCy5S2tT1VcgeYcOwbRdnjvz82Dnv ho3WFpfLVbC4oPwDJTW4oP9ujOmH65U20W4/7DczKzMTgG+j482vsrYpkLsgOW0xBlQR fRljm1TQxsFu4Huv8k79vIbvPYRJD+gz7ANvtt+aCHSnWljGBfeoYrbVnNZWuUAblhCt hLMw== X-Gm-Message-State: AOJu0Yyo3fFxJN/5c6FBjvq8x9ZULU+VQtDL1m98G5pFDnK2JBjRz9ti 3pki9MIu9fHpt6teqQo4ObcBK7igdtPCKq2B93C3LM8LT3LpJoakekxfZ812TyTW54aKPs1eB86 ePZc= X-Google-Smtp-Source: AGHT+IHzd6pRE7hCKK7taodEpWSfj9g3SjZTkyxC5kfe63RQMzPAof9+PoDAHRWKRhRQzaYOj06x5A== X-Received: by 2002:a05:6e02:b27:b0:374:aa87:bcaa with SMTP id e9e14a558f8ab-37580314d52mr91161805ab.14.1717952193058; Sun, 09 Jun 2024 09:56:33 -0700 (PDT) Received: from dune.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id e9e14a558f8ab-374bc1c82d4sm18891715ab.80.2024.06.09.09.56.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jun 2024 09:56:32 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Richard Henderson , Laurent Vivier , Warner Losh , Kyle Evans Subject: [PULL 2/3] bsd-user: port linux-user:ff8a8bbc2ad1 for variable page sizes Date: Sun, 9 Jun 2024 10:55:56 -0600 Message-ID: <20240609165557.52555-3-imp@bsdimp.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240609165557.52555-1-imp@bsdimp.com> References: <20240609165557.52555-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::129; envelope-from=imp@bsdimp.com; helo=mail-il1-x129.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Bring in Richard Henderson's ff8a8bbc2ad1 to finalize the page size to allow TARGET_PAGE_BITS_VARY. bsd-user's "blitz" fork has aarch64 support, which is now variable page size. Add support for it here, even though it's effectively a nop in upstream qemu. Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/main.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/bsd-user/main.c b/bsd-user/main.c index 29a629d8779..d685734d087 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -46,6 +46,7 @@ #include "crypto/init.h" #include "qemu/guest-random.h" #include "gdbstub/user.h" +#include "exec/page-vary.h" #include "host-os.h" #include "target_arch_cpu.h" @@ -291,6 +292,7 @@ int main(int argc, char **argv) char **target_environ, **wrk; envlist_t *envlist = NULL; char *argv0 = NULL; + int host_page_size; adjust_ssize(); @@ -476,6 +478,16 @@ int main(int argc, char **argv) opt_one_insn_per_tb, &error_abort); ac->init_machine(NULL); } + + /* + * Finalize page size before creating CPUs. + * This will do nothing if !TARGET_PAGE_BITS_VARY. + * The most efficient setting is to match the host. + */ + host_page_size = qemu_real_host_page_size(); + set_preferred_target_page_bits(ctz32(host_page_size)); + finalize_target_page_bits(); + cpu = cpu_create(cpu_type); env = cpu_env(cpu); cpu_reset(cpu); From patchwork Sun Jun 9 16:55:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13691301 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 654C0C27C65 for ; Sun, 9 Jun 2024 16:57:42 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sGLqT-0002vw-Im; Sun, 09 Jun 2024 12:56:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sGLqP-0002uP-N5 for qemu-devel@nongnu.org; Sun, 09 Jun 2024 12:56:37 -0400 Received: from mail-il1-x12f.google.com ([2607:f8b0:4864:20::12f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sGLqN-0000vg-Rb for qemu-devel@nongnu.org; Sun, 09 Jun 2024 12:56:37 -0400 Received: by mail-il1-x12f.google.com with SMTP id e9e14a558f8ab-3758fdbd2daso6928675ab.3 for ; Sun, 09 Jun 2024 09:56:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1717952194; x=1718556994; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=DEhu8GM1157Qc3Msyh5LPqHzer+V664PIF9A9S8sV0c=; b=sBLQ6/KdWVphCHCHUybiUBldhGzNYz9ikZ4OZYHpU0UvE4EL8onrEAZ//rj2PjSh/n k5OPZbiGhxqhe5GMSHsx4QckWtRp7LMQe3KGNbtL+mJF+NgrEHgwWQ8UAm3D0V75pNSl b+fym0Pi7nVV/Gp38lH3Jns2rGSr6mkN2bZpP7QOKN5tPRwSZyLjrV47fZ4bsvJJYHZB emx0uLvuCRn+V3E2zwpqlqFA7mSMzW8GJWdTVkLHbPyWZXkOk1thnwV0ifpDZiN8haQj K0H3br8Md4otE44f46ee6GbYIoD//TPnokHt832xTqQpL4sm5l3aqR5JGHCWoX0IjgKR uRMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717952194; x=1718556994; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DEhu8GM1157Qc3Msyh5LPqHzer+V664PIF9A9S8sV0c=; b=VnomH/11Bd5QNVPZmTy0uKT4hzIQb1siM0E7e7FPxkz3Qz7qsde6Kt3Un1i+uDbkjZ LJlCvnJ0C0oJBdN+ftbRIHpz7vsHQzMnq4LLKZHfWU+Jj3tihedTYudxhNhLLqG1lwon vxsVBDTzA8hf/jyfQz+ckvrMNBjQrS/lbE0INTg5NiNacIEXiuZL/a6/ihi9yzBfH76r TQKnX/CQ0oMe2me156UtRwtCKmCe+Fuutq+opMQTU8rCNDaSVuSMDBX9d7r5gZgD0iX9 iA1NNPIL3NC2zr6pIxjC7S4jogOdFv5ln3S/MdD+ZR5qeS7astG81mkjh28kF2xE2HYj cqlQ== X-Gm-Message-State: AOJu0Yxt7XBZFYy8jczzI33B/qJmbHseIeOjpFYty7ABLoZQM2Fq+DGB 0VmMz6h43QTxjIGwFzUdfDS+eT+wikmSg6ErCAO/AP5xPLaIDk2VLRtReJtVF+Ii9PrxMCV/9On 3oo0= X-Google-Smtp-Source: AGHT+IECiRnsti1SWZU3P63wwX1+HGDEo6b9gPoGrL2luIk/ntqm5uDwxjXbcpBpqQpsKr3Vm0IZng== X-Received: by 2002:a92:cd81:0:b0:374:aa60:a5c3 with SMTP id e9e14a558f8ab-375803bf248mr88838905ab.28.1717952194395; Sun, 09 Jun 2024 09:56:34 -0700 (PDT) Received: from dune.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id e9e14a558f8ab-374bc1c82d4sm18891715ab.80.2024.06.09.09.56.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jun 2024 09:56:33 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Richard Henderson , Laurent Vivier , Warner Losh , Kyle Evans Subject: [PULL 3/3] bsd-user: Catch up to run-time reserved_va math Date: Sun, 9 Jun 2024 10:55:57 -0600 Message-ID: <20240609165557.52555-4-imp@bsdimp.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240609165557.52555-1-imp@bsdimp.com> References: <20240609165557.52555-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::12f; envelope-from=imp@bsdimp.com; helo=mail-il1-x12f.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Catch up to linux-user's 8f67b9c694d0, 13c13397556a, 2f7828b57293, and 95059f9c313a by Richard Henderson which made reserved_va a run-time calculation, defaulting to nothing except in the case of 64-bit host 32-bit target. Also include the adjustment of the comment heading that work submitted in the same patch stream. Since this is a direct copy, squash it into one patch rather than follow the Linux evolution since breaking this down further at this point doesn't make sense for this "new code". Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/main.c | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/bsd-user/main.c b/bsd-user/main.c index d685734d087..dcad266c2c9 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -77,25 +77,16 @@ bool have_guest_base; # if HOST_LONG_BITS > TARGET_VIRT_ADDR_SPACE_BITS # if TARGET_VIRT_ADDR_SPACE_BITS == 32 && \ (TARGET_LONG_BITS == 32 || defined(TARGET_ABI32)) -# define MAX_RESERVED_VA 0xfffffffful +# define MAX_RESERVED_VA(CPU) 0xfffffffful # else -# define MAX_RESERVED_VA ((1ul << TARGET_VIRT_ADDR_SPACE_BITS) - 1) +# define MAX_RESERVED_VA(CPU) ((1ul << TARGET_VIRT_ADDR_SPACE_BITS) - 1) # endif # else -# define MAX_RESERVED_VA 0 +# define MAX_RESERVED_VA(CPU) 0 # 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 const char *interp_prefix = CONFIG_QEMU_INTERP_PREFIX; const char *qemu_uname_release; @@ -293,6 +284,7 @@ int main(int argc, char **argv) envlist_t *envlist = NULL; char *argv0 = NULL; int host_page_size; + unsigned long max_reserved_va; adjust_ssize(); @@ -493,6 +485,29 @@ int main(int argc, char **argv) cpu_reset(cpu); thread_cpu = cpu; + /* + * 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. Unless we're running a + * target address space of 32 or fewer bits on a host with 64 bits. + */ + max_reserved_va = MAX_RESERVED_VA(cpu); + if (reserved_va != 0) { + if ((reserved_va + 1) % host_page_size) { + char *s = size_to_str(host_page_size); + fprintf(stderr, "Reserved virtual address not aligned mod %s\n", s); + g_free(s); + exit(EXIT_FAILURE); + } + if (max_reserved_va && reserved_va > max_reserved_va) { + fprintf(stderr, "Reserved virtual address too big\n"); + exit(EXIT_FAILURE); + } + } else if (HOST_LONG_BITS == 64 && TARGET_VIRT_ADDR_SPACE_BITS <= 32) { + /* MAX_RESERVED_VA + 1 is a large power of 2, so is aligned. */ + reserved_va = max_reserved_va; + } + if (getenv("QEMU_STRACE")) { do_strace = 1; }