From: Laurent Vivier <laurent@vivier.eu>
To: qemu-devel@nongnu.org
Cc: Max Filippov <jcmvbkbc@gmail.com>,
Riku Voipio <riku.voipio@iki.fi>,
Richard Henderson <richard.henderson@linaro.org>,
Laurent Vivier <laurent@vivier.eu>,
Peter Maydell <peter.maydell@linaro.org>
Subject: [Qemu-devel] [PULL 06/15] linux-user: Pass CPUState to MAX_RESERVED_VA
Date: Tue, 10 Sep 2019 18:35:51 +0200 [thread overview]
Message-ID: <20190910163600.19971-7-laurent@vivier.eu> (raw)
In-Reply-To: <20190910163600.19971-1-laurent@vivier.eu>
From: Richard Henderson <richard.henderson@linaro.org>
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 <richard.henderson@linaro.org>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Message-Id: <20190822185929.16891-2-richard.henderson@linaro.org>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
linux-user/arm/target_cpu.h | 2 +-
linux-user/main.c | 43 +++++++++++++++++++++----------------
2 files changed, 26 insertions(+), 19 deletions(-)
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;
}
--
2.21.0
next prev parent reply other threads:[~2019-09-10 16:38 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-10 16:35 [Qemu-devel] [PULL 00/15] Linux user for 4.2 patches Laurent Vivier
2019-09-10 16:35 ` [Qemu-devel] [PULL 01/15] linux-user: remove useless variable Laurent Vivier
2019-09-10 16:35 ` [Qemu-devel] [PULL 02/15] linux-user: Add AT_HWCAP2 for aarch64-linux-user Laurent Vivier
2019-09-10 16:35 ` [Qemu-devel] [PULL 03/15] linux-user: erroneous fd_trans_unregister call Laurent Vivier
2019-09-10 16:35 ` [Qemu-devel] [PULL 04/15] linux-user: fail and report on bad dfilter specs Laurent Vivier
2019-09-10 16:35 ` [Qemu-devel] [PULL 05/15] linux-user: add memfd_create Laurent Vivier
2019-09-10 16:35 ` Laurent Vivier [this message]
2019-09-10 16:35 ` [Qemu-devel] [PULL 07/15] linux-user/arm: Adjust MAX_RESERVED_VA for M-profile Laurent Vivier
2019-09-10 16:35 ` [Qemu-devel] [PULL 08/15] linux-user: Support gdb 'qOffsets' query for ELF Laurent Vivier
2019-09-10 16:35 ` [Qemu-devel] [PULL 09/15] target/xtensa: linux-user: add call0 ABI support Laurent Vivier
2019-09-10 16:35 ` [Qemu-devel] [PULL 10/15] linux-user: drop redundant handling of environment variables Laurent Vivier
2019-09-10 16:35 ` [Qemu-devel] [PULL 11/15] linux-user: Add support for RNDRESEEDCRNG ioctl Laurent Vivier
2019-09-10 16:35 ` [Qemu-devel] [PULL 12/15] linux-user: Add support for FIOGETOWN and FIOSETOWN ioctls Laurent Vivier
2019-09-10 16:35 ` [Qemu-devel] [PULL 13/15] linux-user: Add support for FDFLUSH ioctl Laurent Vivier
2019-09-10 16:35 ` [Qemu-devel] [PULL 14/15] linux-user: Add support for FDMSGON and FDMSGOFF ioctls Laurent Vivier
2019-09-10 16:36 ` [Qemu-devel] [PULL 15/15] linux-user: Add support for FDRESET, FDRAWCMD, FDTWADDLE, and FDEJECT ioctls Laurent Vivier
2019-09-10 20:52 ` [Qemu-devel] [PULL 00/15] Linux user for 4.2 patches no-reply
2019-09-11 0:38 ` no-reply
2019-09-11 2:32 ` no-reply
2019-09-11 4:36 ` no-reply
2019-09-11 6:36 ` Laurent Vivier
2019-09-11 6:45 ` no-reply
2019-09-11 7:37 ` no-reply
2019-09-11 8:40 ` no-reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190910163600.19971-7-laurent@vivier.eu \
--to=laurent@vivier.eu \
--cc=jcmvbkbc@gmail.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=riku.voipio@iki.fi \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).