From patchwork Tue Sep 10 16:35:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 173538 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:ce:0:0:0:0 with SMTP id r14csp6037497ilq; Tue, 10 Sep 2019 09:37:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqxTX2PElCz96PM6uFVYhiXM9iRY+mmrF3gIHfBte6iGtuEm76eqAVncsXSfDqilVG9njnXY X-Received: by 2002:a50:f41a:: with SMTP id r26mr9754519edm.300.1568133467997; Tue, 10 Sep 2019 09:37:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568133467; cv=none; d=google.com; s=arc-20160816; b=aBhIDuODRSpkj5rwKQ0anAK4RvwRGe+dF++c7DNU/ZgCtMk1HpNBu2ch2s78JY8Wqj ydK2uaG1ikVNiUHwgvQmZUcbnJUizzOQVjDPfb/7HN8EsWjrH4SAB8xBgmkU7Rf/3hzW DqE47BHyLKIigxAM67zzgegSRHBzZvLVo8lnmI1u7nAoJz237vzU1OgYC7exuLtEJFKi weYafeK8fsa9BrNO4dRB5jc2WDI0Z17kxN3ZMVJGE+Ebm17nThnyugBDO6ElXSFnO5vM v4X/W9+zffclbaZJ0x8AAOwVj1fA5VL1yBbk/eD7lTlbQUG5u4s0v7uYURVhrtR+2VDC xzTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from; bh=/Dqr83SHQ3z/XApHSO4Zg34LIjGtHnwefMj5rEzrPDs=; b=h4WSUD+FvHV6rMW1zVGJ7rG/UctlQuO6MLzhCnoYEjbZoJ6ZqH3aFdO3sd+OgPp72t OzGjHeZ6kgyUJHLcM0ePd7RYvhC+81ILJfGxaGABVmeAxjgH3ZnkTVFoV22yz1PXwbZ9 XA++z0WPchI0OuK/wOgVDNc8KTroyTLWcgJCmTA88mdZcuK8wCrYigOpSbsMICipoNP8 XC40LJzVS1AC9+qxzLIAJaVGcMiBZAx5JcDTpRRc5YsldXBQfaDCbeen4xsfSH2MjgV+ s6Yp+I2EN8PXc4BNN9ilJpEKH5dCKEWZgfgzIRj3eDkdrAKi9SK0M8NULR/7C3DIhdgI CEvg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id a36si7184821edf.123.2019.09.10.09.37.47 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 10 Sep 2019 09:37:47 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1]:42884 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7j9G-0004aM-5j for patch@linaro.org; Tue, 10 Sep 2019 12:37:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53073) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7j7p-0004Uf-Rn for qemu-devel@nongnu.org; Tue, 10 Sep 2019 12:36:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i7j7o-00020T-G4 for qemu-devel@nongnu.org; Tue, 10 Sep 2019 12:36:17 -0400 Received: from mout.kundenserver.de ([212.227.126.131]:59679) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i7j7o-0001zK-6b for qemu-devel@nongnu.org; Tue, 10 Sep 2019 12:36:16 -0400 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue010 [212.227.15.167]) with ESMTPSA (Nemesis) id 1M6lUk-1i3sIc16fW-008Mwl; Tue, 10 Sep 2019 18:36:12 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Tue, 10 Sep 2019 18:35:51 +0200 Message-Id: <20190910163600.19971-7-laurent@vivier.eu> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190910163600.19971-1-laurent@vivier.eu> References: <20190910163600.19971-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:ELE3NguVAMW9oC7+Roai81gb83Tae7RgDGcbFSQPSxhXLlnKWiF WJYSH1vNO7P7AD1L/ej5Jai0Znd3mJrGMUGHcRmI5EC+C6MnmFuf+I4u7Sa7iRkvu3Ql/vW ++AnuhJL9FCbNXpSg2SuxNTqmcVbirTbIGtdAd9493Q/mYTawHfBVxQK2pZhsefvaIPiTAP 9OtOnl6sEZNxnPPmXJ5Ug== X-UI-Out-Filterresults: notjunk:1; V03:K0:I2jXH4wke7Q=:D+Mo61yGKXvn+FjM5shYRv uYp3Z7bmk4LU0+Yc6qDieIL4yEcMFBDdknmnheWENIbsOc+UKHEneZitCTs9w7j14mnGL1ua2 hLIHnsbxdTMtBX8F/ssDbGll49i5jGVhYLmVtGtJqx/FiVdKwYsHsh4PzPT2edLx0LaXjTEFy o8ATeQQdMJRuzGpHrCDM5myCy6nuKkjIMWt9aOOKyWnBctExqGawWOajNSSvFr4IEn938r2gO PR1ghDv7idn0UBtKXggB/JZBkgIP+T9fWEl9UF95fqwbGLVkJ+pcbBCCv9VF3nA2UyppXYthJ 0TjQq4KKm+qt/lujMI25WbXUGPzs6cha39vVkMMFNi1AA1ROHOvg0TNYO5obPvjz9/X9Q/ojx Z+f2srms0TUBAlXcrQB0t8SRwb7hoXquxmlwgzkBYT0u9LE7oc+wMba58bDX+w90dVX672zER IWU+ma+cPAdUHzyy9BNINDd6E7Qvlr6ekGbCGbvwY+SBbv0+SI2W9SQL6mVNIyxdaSzdnTc32 Ytrg2JN+6jEg/Bi/pLgbEXiT6J01Ue1Z5LUFrZlDwdWnNUgsCa9qDzsN9nhHGH6GIhLdn//CO e/Xr5Gm5GDzgY31FI2YCLcTfMMB3Ut2uKHLx+W3uS0ZWKCM9BrRelDS4lgfFmhBP7cKvBs9NM Stuu2Sfts3LNH9PdRbkOhbvnsPvlogYzhUW/8P2LIP1RW4Ljn02ttYACGX6VmSTo5O2ZCJ5gE zp8bctkOJv6JQXna7zZEridIldTFZFQ7KP15KdAbP9p/NFqg0RW57xmIPdWjGhHn+ezo+BuU6 NpQqFaSNFSZnFN+QwU1VMrntCmMs6GKsTHRvkIml8/5rgopJaY= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 212.227.126.131 Subject: [Qemu-devel] [PULL 06/15] linux-user: Pass CPUState to MAX_RESERVED_VA X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Max Filippov , Riku Voipio , Richard Henderson , Laurent Vivier , Peter Maydell Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson Turn the scalar macro into a functional macro. Move the creation of the cpu up a bit within main() so that we can pass it to the invocation of MAX_RESERVED_VA. Delay the validation of the -R parameter until MAX_RESERVED_VA is computed. So far no changes to any of the MAX_RESERVED_VA macros to actually use the cpu in any way, but ARM will need it. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell Message-Id: <20190822185929.16891-2-richard.henderson@linaro.org> Signed-off-by: Laurent Vivier --- linux-user/arm/target_cpu.h | 2 +- linux-user/main.c | 43 +++++++++++++++++++++---------------- 2 files changed, 26 insertions(+), 19 deletions(-) -- 2.21.0 diff --git a/linux-user/arm/target_cpu.h b/linux-user/arm/target_cpu.h index 8a3764919ad9..279ea532d5b7 100644 --- a/linux-user/arm/target_cpu.h +++ b/linux-user/arm/target_cpu.h @@ -21,7 +21,7 @@ /* We need to be able to map the commpage. See validate_guest_space in linux-user/elfload.c. */ -#define MAX_RESERVED_VA 0xffff0000ul +#define MAX_RESERVED_VA(CPU) 0xffff0000ul static inline void cpu_clone_regs(CPUARMState *env, target_ulong newsp) { diff --git a/linux-user/main.c b/linux-user/main.c index c257b063dbc1..24cb24f0bf8f 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -77,12 +77,12 @@ int have_guest_base; (TARGET_LONG_BITS == 32 || defined(TARGET_ABI32)) /* There are a number of places where we assign reserved_va to a variable of type abi_ulong and expect it to fit. Avoid the last page. */ -# define MAX_RESERVED_VA (0xfffffffful & TARGET_PAGE_MASK) +# define MAX_RESERVED_VA(CPU) (0xfffffffful & TARGET_PAGE_MASK) # else -# define MAX_RESERVED_VA (1ul << TARGET_VIRT_ADDR_SPACE_BITS) +# define MAX_RESERVED_VA(CPU) (1ul << TARGET_VIRT_ADDR_SPACE_BITS) # endif # else -# define MAX_RESERVED_VA 0 +# define MAX_RESERVED_VA(CPU) 0 # endif #endif @@ -356,8 +356,7 @@ static void handle_arg_reserved_va(const char *arg) unsigned long unshifted = reserved_va; p++; reserved_va <<= shift; - if (reserved_va >> shift != unshifted - || (MAX_RESERVED_VA && reserved_va > MAX_RESERVED_VA)) { + if (reserved_va >> shift != unshifted) { fprintf(stderr, "Reserved virtual address too big\n"); exit(EXIT_FAILURE); } @@ -605,6 +604,7 @@ int main(int argc, char **argv, char **envp) int i; int ret; int execfd; + unsigned long max_reserved_va; error_init(argv[0]); module_call_init(MODULE_INIT_TRACE); @@ -670,24 +670,31 @@ 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); - 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. + */ + max_reserved_va = MAX_RESERVED_VA(cpu); + if (reserved_va != 0) { + 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) { + /* + * 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; + } + if (getenv("QEMU_STRACE")) { do_strace = 1; }