* [Qemu-devel] [PATCH 0/2] linux-user/arm: Adjust MAX_RESERVED_VA for M-profile
@ 2019-08-22 18:59 Richard Henderson
2019-08-22 18:59 ` [Qemu-devel] [PATCH 1/2] linux-user: Pass CPUState to MAX_RESERVED_VA Richard Henderson
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Richard Henderson @ 2019-08-22 18:59 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell, laurent
This is inspired by the discussion in
https://bugs.launchpad.net/qemu/+bug/1840922
Previously I suggested a new CPUClass hook, but when I went
to implement that seemed like overkill.
r~
Richard Henderson (2):
linux-user: Pass CPUState to MAX_RESERVED_VA
linux-user/arm: Adjust MAX_RESERVED_VA for M-profile
linux-user/arm/target_cpu.h | 24 ++++++++++++++++++---
linux-user/main.c | 43 +++++++++++++++++++++----------------
2 files changed, 46 insertions(+), 21 deletions(-)
--
2.17.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Qemu-devel] [PATCH 1/2] linux-user: Pass CPUState to MAX_RESERVED_VA
2019-08-22 18:59 [Qemu-devel] [PATCH 0/2] linux-user/arm: Adjust MAX_RESERVED_VA for M-profile Richard Henderson
@ 2019-08-22 18:59 ` Richard Henderson
2019-08-22 18:59 ` [Qemu-devel] [PATCH 2/2] linux-user/arm: Adjust MAX_RESERVED_VA for M-profile Richard Henderson
2019-09-03 13:35 ` [Qemu-devel] [PATCH 0/2] " Peter Maydell
2 siblings, 0 replies; 5+ messages in thread
From: Richard Henderson @ 2019-08-22 18:59 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell, laurent
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>
---
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 8a3764919a..279ea532d5 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 47917bbb20..35da3bf14c 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -78,12 +78,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
@@ -357,8 +357,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);
}
@@ -607,6 +606,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);
@@ -672,24 +672,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.17.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [Qemu-devel] [PATCH 2/2] linux-user/arm: Adjust MAX_RESERVED_VA for M-profile
2019-08-22 18:59 [Qemu-devel] [PATCH 0/2] linux-user/arm: Adjust MAX_RESERVED_VA for M-profile Richard Henderson
2019-08-22 18:59 ` [Qemu-devel] [PATCH 1/2] linux-user: Pass CPUState to MAX_RESERVED_VA Richard Henderson
@ 2019-08-22 18:59 ` Richard Henderson
2019-09-03 13:35 ` [Qemu-devel] [PATCH 0/2] " Peter Maydell
2 siblings, 0 replies; 5+ messages in thread
From: Richard Henderson @ 2019-08-22 18:59 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell, laurent
Limit the virtual address space for M-profile cpus to 2GB,
so that we avoid all of the magic addresses in the top half
of the M-profile system map.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/arm/target_cpu.h | 24 +++++++++++++++++++++---
1 file changed, 21 insertions(+), 3 deletions(-)
diff --git a/linux-user/arm/target_cpu.h b/linux-user/arm/target_cpu.h
index 279ea532d5..3f79356a07 100644
--- a/linux-user/arm/target_cpu.h
+++ b/linux-user/arm/target_cpu.h
@@ -19,9 +19,27 @@
#ifndef ARM_TARGET_CPU_H
#define ARM_TARGET_CPU_H
-/* We need to be able to map the commpage.
- See validate_guest_space in linux-user/elfload.c. */
-#define MAX_RESERVED_VA(CPU) 0xffff0000ul
+static inline unsigned long arm_max_reserved_va(CPUState *cs)
+{
+ ARMCPU *cpu = ARM_CPU(cs);
+
+ if (arm_feature(&cpu->env, ARM_FEATURE_M)) {
+ /*
+ * There are magic return addresses above 0xfe000000,
+ * and in general a lot of M-profile system stuff in
+ * the high addresses. Restrict linux-user to the
+ * cached write-back RAM in the system map.
+ */
+ return 0x80000000ul;
+ } else {
+ /*
+ * We need to be able to map the commpage.
+ * See validate_guest_space in linux-user/elfload.c.
+ */
+ return 0xffff0000ul;
+ }
+}
+#define MAX_RESERVED_VA arm_max_reserved_va
static inline void cpu_clone_regs(CPUARMState *env, target_ulong newsp)
{
--
2.17.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH 0/2] linux-user/arm: Adjust MAX_RESERVED_VA for M-profile
2019-08-22 18:59 [Qemu-devel] [PATCH 0/2] linux-user/arm: Adjust MAX_RESERVED_VA for M-profile Richard Henderson
2019-08-22 18:59 ` [Qemu-devel] [PATCH 1/2] linux-user: Pass CPUState to MAX_RESERVED_VA Richard Henderson
2019-08-22 18:59 ` [Qemu-devel] [PATCH 2/2] linux-user/arm: Adjust MAX_RESERVED_VA for M-profile Richard Henderson
@ 2019-09-03 13:35 ` Peter Maydell
2019-09-10 8:19 ` Laurent Vivier
2 siblings, 1 reply; 5+ messages in thread
From: Peter Maydell @ 2019-09-03 13:35 UTC (permalink / raw)
To: Richard Henderson; +Cc: QEMU Developers, Laurent Vivier
On Thu, 22 Aug 2019 at 19:59, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> This is inspired by the discussion in
>
> https://bugs.launchpad.net/qemu/+bug/1840922
>
> Previously I suggested a new CPUClass hook, but when I went
> to implement that seemed like overkill.
>
>
> r~
>
>
> Richard Henderson (2):
> linux-user: Pass CPUState to MAX_RESERVED_VA
> linux-user/arm: Adjust MAX_RESERVED_VA for M-profile
>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
thanks
-- PMM
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH 0/2] linux-user/arm: Adjust MAX_RESERVED_VA for M-profile
2019-09-03 13:35 ` [Qemu-devel] [PATCH 0/2] " Peter Maydell
@ 2019-09-10 8:19 ` Laurent Vivier
0 siblings, 0 replies; 5+ messages in thread
From: Laurent Vivier @ 2019-09-10 8:19 UTC (permalink / raw)
To: Peter Maydell, Richard Henderson; +Cc: QEMU Developers
Le 03/09/2019 à 15:35, Peter Maydell a écrit :
> On Thu, 22 Aug 2019 at 19:59, Richard Henderson
> <richard.henderson@linaro.org> wrote:
>>
>> This is inspired by the discussion in
>>
>> https://bugs.launchpad.net/qemu/+bug/1840922
>>
>> Previously I suggested a new CPUClass hook, but when I went
>> to implement that seemed like overkill.
>>
>>
>> r~
>>
>>
>> Richard Henderson (2):
>> linux-user: Pass CPUState to MAX_RESERVED_VA
>> linux-user/arm: Adjust MAX_RESERVED_VA for M-profile
>>
>
> Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Both applied to my linux-user branch.
Thanks,
Laurent
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2019-09-10 8:21 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-22 18:59 [Qemu-devel] [PATCH 0/2] linux-user/arm: Adjust MAX_RESERVED_VA for M-profile Richard Henderson
2019-08-22 18:59 ` [Qemu-devel] [PATCH 1/2] linux-user: Pass CPUState to MAX_RESERVED_VA Richard Henderson
2019-08-22 18:59 ` [Qemu-devel] [PATCH 2/2] linux-user/arm: Adjust MAX_RESERVED_VA for M-profile Richard Henderson
2019-09-03 13:35 ` [Qemu-devel] [PATCH 0/2] " Peter Maydell
2019-09-10 8:19 ` Laurent Vivier
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).