[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 41/47] accel/tcg: Add mips support to alloc_code_gen_buffer_splitw
From: |
Richard Henderson |
Subject: |
[PULL 41/47] accel/tcg: Add mips support to alloc_code_gen_buffer_splitwx_memfd |
Date: |
Thu, 7 Jan 2021 10:14:42 -1000 |
Re-use the 256MiB region handling from alloc_code_gen_buffer_anon,
and replace that with the shared file mapping.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
accel/tcg/translate-all.c | 46 ++++++++++++++++++++++++++++++++-------
1 file changed, 38 insertions(+), 8 deletions(-)
diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c
index c37718db4d..02e1b05c42 100644
--- a/accel/tcg/translate-all.c
+++ b/accel/tcg/translate-all.c
@@ -1137,24 +1137,40 @@ static bool alloc_code_gen_buffer_anon(size_t size, int
prot,
static bool alloc_code_gen_buffer_splitwx_memfd(size_t size, Error **errp)
{
- void *buf_rw, *buf_rx;
+ void *buf_rw = NULL, *buf_rx = MAP_FAILED;
int fd = -1;
+#ifdef __mips__
+ /* Find space for the RX mapping, vs the 256MiB regions. */
+ if (!alloc_code_gen_buffer_anon(size, PROT_NONE,
+ MAP_PRIVATE | MAP_ANONYMOUS |
+ MAP_NORESERVE, errp)) {
+ return false;
+ }
+ /* The size of the mapping may have been adjusted. */
+ size = tcg_ctx->code_gen_buffer_size;
+ buf_rx = tcg_ctx->code_gen_buffer;
+#endif
+
buf_rw = qemu_memfd_alloc("tcg-jit", size, 0, &fd, errp);
if (buf_rw == NULL) {
- return false;
+ goto fail;
}
+#ifdef __mips__
+ void *tmp = mmap(buf_rx, size, PROT_READ | PROT_EXEC,
+ MAP_SHARED | MAP_FIXED, fd, 0);
+ if (tmp != buf_rx) {
+ goto fail_rx;
+ }
+#else
buf_rx = mmap(NULL, size, PROT_READ | PROT_EXEC, MAP_SHARED, fd, 0);
if (buf_rx == MAP_FAILED) {
- error_setg_errno(errp, errno,
- "failed to map shared memory for execute");
- munmap(buf_rw, size);
- close(fd);
- return false;
+ goto fail_rx;
}
- close(fd);
+#endif
+ close(fd);
tcg_ctx->code_gen_buffer = buf_rw;
tcg_ctx->code_gen_buffer_size = size;
tcg_splitwx_diff = buf_rx - buf_rw;
@@ -1163,6 +1179,20 @@ static bool alloc_code_gen_buffer_splitwx_memfd(size_t
size, Error **errp)
qemu_madvise(buf_rw, size, QEMU_MADV_HUGEPAGE);
qemu_madvise(buf_rx, size, QEMU_MADV_HUGEPAGE);
return true;
+
+ fail_rx:
+ error_setg_errno(errp, errno, "failed to map shared memory for execute");
+ fail:
+ if (buf_rx != MAP_FAILED) {
+ munmap(buf_rx, size);
+ }
+ if (buf_rw) {
+ munmap(buf_rw, size);
+ }
+ if (fd >= 0) {
+ close(fd);
+ }
+ return false;
}
#endif /* CONFIG_POSIX */
--
2.25.1
- [PULL 29/47] tcg/tci: Push const down through bytecode reading, (continued)
- [PULL 29/47] tcg/tci: Push const down through bytecode reading, Richard Henderson, 2021/01/07
- [PULL 32/47] tcg/ppc: Use tcg_out_mem_long to reset TCG_REG_TB, Richard Henderson, 2021/01/07
- [PULL 36/47] tcg/s390: Use tcg_tbrel_diff, Richard Henderson, 2021/01/07
- [PULL 20/47] tcg: Use Error with alloc_code_gen_buffer, Richard Henderson, 2021/01/07
- [PULL 33/47] tcg/ppc: Support split-wx code generation, Richard Henderson, 2021/01/07
- [PULL 37/47] tcg/s390: Support split-wx code generation, Richard Henderson, 2021/01/07
- [PULL 38/47] tcg/riscv: Fix branch range checks, Richard Henderson, 2021/01/07
- [PULL 34/47] tcg/sparc: Use tcg_tbrel_diff, Richard Henderson, 2021/01/07
- [PULL 45/47] tcg: Remove TCG_TARGET_SUPPORT_MIRROR, Richard Henderson, 2021/01/07
- [PULL 26/47] tcg/aarch64: Use B not BL for tcg_out_goto_long, Richard Henderson, 2021/01/07
- [PULL 41/47] accel/tcg: Add mips support to alloc_code_gen_buffer_splitwx_memfd,
Richard Henderson <=
- [PULL 30/47] tcg: Introduce tcg_tbrel_diff, Richard Henderson, 2021/01/07
- [PULL 28/47] disas: Push const down through host disassembly, Richard Henderson, 2021/01/07
- [PULL 31/47] tcg/ppc: Use tcg_tbrel_diff, Richard Henderson, 2021/01/07
- [PULL 35/47] tcg/sparc: Support split-wx code generation, Richard Henderson, 2021/01/07
- [PULL 42/47] tcg/mips: Do not assert on relocation overflow, Richard Henderson, 2021/01/07
- [PULL 39/47] tcg/riscv: Remove branch-over-branch fallback, Richard Henderson, 2021/01/07
- [PULL 40/47] tcg/riscv: Support split-wx code generation, Richard Henderson, 2021/01/07
- [PULL 47/47] tcg: Constify TCGLabelQemuLdst.raddr, Richard Henderson, 2021/01/07
- [PULL 44/47] tcg/arm: Support split-wx code generation, Richard Henderson, 2021/01/07
- [PULL 43/47] tcg/mips: Support split-wx code generation, Richard Henderson, 2021/01/07