* [PATCH 0/3] bsd-user: Baby Steps towards eliminating qemu_host_page_size, et al
@ 2024-06-07 4:25 Warner Losh
2024-06-07 4:25 ` [PATCH 1/3] linux-user: Adjust comment to reflect the code Warner Losh
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Warner Losh @ 2024-06-07 4:25 UTC (permalink / raw)
To: qemu-devel; +Cc: Kyle Evans, Laurent Vivier, Richard Henderson, Warner Losh
First baby-steps towards eliminating qemu_host_page_size: tackle the reserve_va
calculation (which is easier to copy from linux-user than to fix).
Warner Losh (3):
linux-user: Adjust comment to reflect the code.
bsd-user: port linux-user:ff8a8bbc2ad1 for variable page sizes
bsd-user: Catch up to run-time reserved_va math
bsd-user/main.c | 51 ++++++++++++++++++++++++++++++++++++-----------
linux-user/main.c | 8 ++++----
2 files changed, 43 insertions(+), 16 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/3] linux-user: Adjust comment to reflect the code.
2024-06-07 4:25 [PATCH 0/3] bsd-user: Baby Steps towards eliminating qemu_host_page_size, et al Warner Losh
@ 2024-06-07 4:25 ` Warner Losh
2024-06-07 4:25 ` [PATCH 2/3] bsd-user: port linux-user:ff8a8bbc2ad1 for variable page sizes Warner Losh
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Warner Losh @ 2024-06-07 4:25 UTC (permalink / raw)
To: qemu-devel; +Cc: Kyle Evans, Laurent Vivier, Richard Henderson, Warner Losh
If the user didn't specify a 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 <imp@bsdimp.com>
---
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) {
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/3] bsd-user: port linux-user:ff8a8bbc2ad1 for variable page sizes
2024-06-07 4:25 [PATCH 0/3] bsd-user: Baby Steps towards eliminating qemu_host_page_size, et al Warner Losh
2024-06-07 4:25 ` [PATCH 1/3] linux-user: Adjust comment to reflect the code Warner Losh
@ 2024-06-07 4:25 ` Warner Losh
2024-06-07 4:25 ` [PATCH 3/3] bsd-user: Catch up to run-time reserved_va math Warner Losh
2024-06-07 15:02 ` [PATCH 0/3] bsd-user: Baby Steps towards eliminating qemu_host_page_size, et al Richard Henderson
3 siblings, 0 replies; 5+ messages in thread
From: Warner Losh @ 2024-06-07 4:25 UTC (permalink / raw)
To: qemu-devel; +Cc: Kyle Evans, Laurent Vivier, Richard Henderson, Warner Losh
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 <imp@bsdimp.com>
---
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);
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 3/3] bsd-user: Catch up to run-time reserved_va math
2024-06-07 4:25 [PATCH 0/3] bsd-user: Baby Steps towards eliminating qemu_host_page_size, et al Warner Losh
2024-06-07 4:25 ` [PATCH 1/3] linux-user: Adjust comment to reflect the code Warner Losh
2024-06-07 4:25 ` [PATCH 2/3] bsd-user: port linux-user:ff8a8bbc2ad1 for variable page sizes Warner Losh
@ 2024-06-07 4:25 ` Warner Losh
2024-06-07 15:02 ` [PATCH 0/3] bsd-user: Baby Steps towards eliminating qemu_host_page_size, et al Richard Henderson
3 siblings, 0 replies; 5+ messages in thread
From: Warner Losh @ 2024-06-07 4:25 UTC (permalink / raw)
To: qemu-devel; +Cc: Kyle Evans, Laurent Vivier, Richard Henderson, Warner Losh
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 <imp@bsdimp.com>
---
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;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 0/3] bsd-user: Baby Steps towards eliminating qemu_host_page_size, et al
2024-06-07 4:25 [PATCH 0/3] bsd-user: Baby Steps towards eliminating qemu_host_page_size, et al Warner Losh
` (2 preceding siblings ...)
2024-06-07 4:25 ` [PATCH 3/3] bsd-user: Catch up to run-time reserved_va math Warner Losh
@ 2024-06-07 15:02 ` Richard Henderson
3 siblings, 0 replies; 5+ messages in thread
From: Richard Henderson @ 2024-06-07 15:02 UTC (permalink / raw)
To: Warner Losh, qemu-devel; +Cc: Kyle Evans, Laurent Vivier
On 6/6/24 21:25, Warner Losh wrote:
> Warner Losh (3):
> linux-user: Adjust comment to reflect the code.
> bsd-user: port linux-user:ff8a8bbc2ad1 for variable page sizes
> bsd-user: Catch up to run-time reserved_va math
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-06-07 23:44 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-07 4:25 [PATCH 0/3] bsd-user: Baby Steps towards eliminating qemu_host_page_size, et al Warner Losh
2024-06-07 4:25 ` [PATCH 1/3] linux-user: Adjust comment to reflect the code Warner Losh
2024-06-07 4:25 ` [PATCH 2/3] bsd-user: port linux-user:ff8a8bbc2ad1 for variable page sizes Warner Losh
2024-06-07 4:25 ` [PATCH 3/3] bsd-user: Catch up to run-time reserved_va math Warner Losh
2024-06-07 15:02 ` [PATCH 0/3] bsd-user: Baby Steps towards eliminating qemu_host_page_size, et al Richard Henderson
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).