From patchwork Wed Sep 11 06:49:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 173587 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:ce:0:0:0:0 with SMTP id r14csp364053ilq; Wed, 11 Sep 2019 00:05:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqyftM0UkF+nC5Kb35z1bU2waf/Af4tZu7ScUTSG5LJJ5bebwzSNboI2gJ9amdBUoLWjmZBf X-Received: by 2002:a17:906:3644:: with SMTP id r4mr6400394ejb.92.1568185502148; Wed, 11 Sep 2019 00:05:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568185502; cv=none; d=google.com; s=arc-20160816; b=r2Z/ltlbRgJI1exfpekMNchLUW0AImqJHxfrm1r4OWxU7mvgYwEhBC0eqPEpnD/9/Z cUSOcDhorz76um5BdWYHDVLGqw5T1E1cLK5rsrQVTO98NICVRzW00C3f4z3h0hvFkZ/m NAriCOYXFawvIG05E/+U5vOAQ3O8fcka4MXWN9Ww4Kd2QjxVsdihbFgrMeFbyzuwjqjl n/G/O66SwlTZnXrzTY9V3Hm6Qa457wPoec/JvPij7ItHnxTkbRw0wuX6VvnjvVpwSG80 2UeipyvOkmIxXyyvn/KyVDW60uwuW6bo/8EzSeuuIhoM68qtovsKBSxYaUpn5zvsoJxR LC4g== 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=ZAFdBDSBne4Fz4B+JBmP5dO8NVmKd0htiPcxjZ4mH5npw3jVTt18eR+FRN1+3v8oPb WPvKXm7NJQ6QI8EAKPENAKc/ruQdctxd3BNXQHtNSp5bjJ5ui6Xw3Mud8Z8cDLdFxkLY XtL2CW27NfMo+U9CjzBkI8OD4jczzPi1wxEUVKdTRL2Bo2O3Cq0xlgYarGdVjRv1H2Su y8wXRqljYbzVK/5SsZ7POE1zCwVhwZPrhRrZWEBlMHOaU+MqWSq2VAMzXxGw83rAMrhx sToraRtuIZ+ge/wjIHk5nnL4B/rV8PKKD6i+JTK3CCOegwhzxl0FtXIf1j7wX2hbebeV 0sEw== 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 a8si3162772edn.332.2019.09.11.00.05.01 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 11 Sep 2019 00:05:02 -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]:47142 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7wgW-0003up-NX for patch@linaro.org; Wed, 11 Sep 2019 03:05:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40858) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7wRh-00064k-BS for qemu-devel@nongnu.org; Wed, 11 Sep 2019 02:49:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i7wRf-0004OM-V1 for qemu-devel@nongnu.org; Wed, 11 Sep 2019 02:49:41 -0400 Received: from mout.kundenserver.de ([212.227.126.187]:58283) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i7wRf-0004NS-LU for qemu-devel@nongnu.org; Wed, 11 Sep 2019 02:49:39 -0400 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue011 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MWRi7-1hbqgV2OPT-00XrjM; Wed, 11 Sep 2019 08:49:28 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Wed, 11 Sep 2019 08:49:11 +0200 Message-Id: <20190911064920.1718-7-laurent@vivier.eu> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190911064920.1718-1-laurent@vivier.eu> References: <20190911064920.1718-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:lfv5mfUSpaYqspHFKcdASL7d5yzUy8SzbylCwkjxEMMQX0pt1dN WQW6rI2nCkDkFAiWvSAPysNHfX2PU7Qe45U9dcp47ivUYgEMkwinEnwH99BvjT+2FN6x5kJ HaKMksge0wZnCFb+vZSykuR1OZY6z5CuLtFggw1Ke6bMb6qpOTIhyxz5W2PPC3yJIM708ma VYO0f0UNibC2KBd6NNcVA== X-UI-Out-Filterresults: notjunk:1; V03:K0:6e6TxgXutMw=:kbGnVGt81wm7jYxVXxAjbh 7zacYdDUQwMER/eSkAFZ7VNjWIMmi+wGzqcje5pVnhK2rj8gUuZbAhoPttcvXgkEOo+J8sJE1 WdgKjXPq1RKCbLiZVg96TuWPa7eMCOZvjwbuEmKEVF8e+OhgQrfkUbeCLr4G2qaYGRVCEqFel LEh2aNkZ29T5TZN7Hub7v9Fccc7ULVpsTQzJfQ+xyUf7qpQ2ZN7/VVeFbSZrLNt6mrbTP4JkC yoE6BIWIiiGhzV3cBEl0K220Pusr8G4t8YF7/KGrNA8vhwFRfp7YxrXB4yG6Y63yMZtdBmtoU 5wmLHH4z1cctgqc6Y5WzGQwFtuKksqXFQDMTap0vxjejt5jz1bpSpUQfBZqccx7sqRVAhT733 ti/jwr0kBlH8r+Dc6KmVBBHEXly5tnawsq1qCvDPDOsQjx3Mg0eJThzuqfcj5nzzW9dzJjo1X J3ATpSbz077Ar5Ei4O6uPp41DgCd0BLZHSEogvxlJGiVp7+cZu3z/j2hx25zbEOZnLxemXXFs RTVqXDXNmMy/KuJWXxpv7Amlru0+yw8iwLHNvjK2qf6GB3ywkVHs5uYFhzL4sPbEuBgz5WeW1 IyYFbxqoyEBor0G9ifZwrzpNqiyD2qvGFI+lVDXfXBk7o37d/rIm2deRMwWhCJLdCRffkSKwT lc3Ah5xDpopr2uurllzxPgEeyOznIEjuAAebtMg1SGTF8R4I/VcBnIZFVwQ8yLQvK5Ypz3j2l q4p/D2Uw2t4tfyCSc7ICKxdvE7Q9C6EuLPl6i+73HRLph6nnhZsFQp2sIL7HWYRNcRypNHVre i2VCQ2+JH7GTn4ec9/E6R9Bf1CUS9tghIMCopx3IF+Lrf8IxtE= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 212.227.126.187 Subject: [Qemu-devel] [PULL v2 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; }