[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 35/41] accel/tcg: Add mips support to alloc_code_gen_buffer_sp
From: |
Richard Henderson |
Subject: |
[PATCH v3 35/41] accel/tcg: Add mips support to alloc_code_gen_buffer_splitwx_memfd |
Date: |
Thu, 5 Nov 2020 19:29:15 -0800 |
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 17df6c94fa..b49aaf1026 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
- [PATCH v3 17/41] tcg: Return the TB pointer from the rx region from exit_tb, (continued)
- [PATCH v3 17/41] tcg: Return the TB pointer from the rx region from exit_tb, Richard Henderson, 2020/11/05
- [PATCH v3 20/41] tcg/aarch64: Implement flush_idcache_range manually, Richard Henderson, 2020/11/05
- [PATCH v3 21/41] tcg/aarch64: Support split-wx code generation, Richard Henderson, 2020/11/05
- [PATCH v3 22/41] disas: Push const down through host disasassembly, Richard Henderson, 2020/11/05
- [PATCH v3 23/41] tcg/tci: Push const down through bytecode reading, Richard Henderson, 2020/11/05
- [PATCH v3 24/41] tcg: Introduce tcg_tbrel_diff, Richard Henderson, 2020/11/05
- [PATCH v3 25/41] tcg/ppc: Use tcg_tbrel_diff, Richard Henderson, 2020/11/05
- [PATCH v3 26/41] tcg/ppc: Use tcg_out_mem_long to reset TCG_REG_TB, Richard Henderson, 2020/11/05
- [PATCH v3 27/41] tcg/ppc: Support split-wx code generation, Richard Henderson, 2020/11/05
- [PATCH v3 29/41] tcg/sparc: Support split-wx code generation, Richard Henderson, 2020/11/05
- [PATCH v3 35/41] accel/tcg: Add mips support to alloc_code_gen_buffer_splitwx_memfd,
Richard Henderson <=
- [PATCH v3 32/41] tcg/riscv: Fix branch range checks, Richard Henderson, 2020/11/05
- [PATCH v3 31/41] tcg/s390: Support split-wx code generation, Richard Henderson, 2020/11/05
- [PATCH v3 36/41] tcg/mips: Do not assert on relocation overflow, Richard Henderson, 2020/11/05
- [PATCH v3 37/41] tcg/mips: Support split-wx code generation, Richard Henderson, 2020/11/05
- [PATCH v3 33/41] tcg/riscv: Remove branch-over-branch fallback, Richard Henderson, 2020/11/05
- [PATCH v3 28/41] tcg/sparc: Use tcg_tbrel_diff, Richard Henderson, 2020/11/05
- [PATCH v3 30/41] tcg/s390: Use tcg_tbrel_diff, Richard Henderson, 2020/11/05
- [PATCH v3 40/41] tcg: Constify tcg_code_gen_epilogue, Richard Henderson, 2020/11/05
- [PATCH v3 41/41] tcg: Constify TCGLabelQemuLdst.raddr, Richard Henderson, 2020/11/05
- [PATCH v3 34/41] tcg/riscv: Support split-wx code generation, Richard Henderson, 2020/11/05