summary refs log tree commit diff stats
path: root/linux-user/mmap.c
diff options
context:
space:
mode:
authorRichard Henderson <richard.henderson@linaro.org>2021-06-11 23:08:28 -0700
committerLaurent Vivier <laurent@vivier.eu>2021-06-15 08:28:56 +0200
commit228168cbb7cc40bfb1621b0b6868c018b522276a (patch)
treeb82f0e2af4188a3b465311b34e5b50d5ed28986b /linux-user/mmap.c
parent1ea06abceec61b6f3ab33dadb0510b6e09fb61e2 (diff)
downloadfocaccia-qemu-228168cbb7cc40bfb1621b0b6868c018b522276a.tar.gz
focaccia-qemu-228168cbb7cc40bfb1621b0b6868c018b522276a.zip
linux-user: Set CF_PARALLEL when mapping shared memory
Signal the translator to use host atomic instructions for
guest operations, insofar as it is possible.  This is the
best we can do to allow the guest to interact atomically
with other processes.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/121
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Message-Id: <20210612060828.695332-1-richard.henderson@linaro.org>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
Diffstat (limited to 'linux-user/mmap.c')
-rw-r--r--linux-user/mmap.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/linux-user/mmap.c b/linux-user/mmap.c
index 7e3b245036..0e103859fe 100644
--- a/linux-user/mmap.c
+++ b/linux-user/mmap.c
@@ -451,6 +451,20 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot,
         goto fail;
     }
 
+    /*
+     * If we're mapping shared memory, ensure we generate code for parallel
+     * execution and flush old translations.  This will work up to the level
+     * supported by the host -- anything that requires EXCP_ATOMIC will not
+     * be atomic with respect to an external process.
+     */
+    if (flags & MAP_SHARED) {
+        CPUState *cpu = thread_cpu;
+        if (!(cpu->tcg_cflags & CF_PARALLEL)) {
+            cpu->tcg_cflags |= CF_PARALLEL;
+            tb_flush(cpu);
+        }
+    }
+
     real_start = start & qemu_host_page_mask;
     host_offset = offset & qemu_host_page_mask;