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>
This commit is contained in:
Richard Henderson 2021-06-11 23:08:28 -07:00 committed by Laurent Vivier
parent 1ea06abcee
commit 228168cbb7
2 changed files with 26 additions and 0 deletions

View File

@ -451,6 +451,20 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot,
goto fail; 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; real_start = start & qemu_host_page_mask;
host_offset = offset & qemu_host_page_mask; host_offset = offset & qemu_host_page_mask;

View File

@ -4603,6 +4603,7 @@ static inline abi_ulong target_shmlba(CPUArchState *cpu_env)
static inline abi_ulong do_shmat(CPUArchState *cpu_env, static inline abi_ulong do_shmat(CPUArchState *cpu_env,
int shmid, abi_ulong shmaddr, int shmflg) int shmid, abi_ulong shmaddr, int shmflg)
{ {
CPUState *cpu = env_cpu(cpu_env);
abi_long raddr; abi_long raddr;
void *host_raddr; void *host_raddr;
struct shmid_ds shm_info; struct shmid_ds shm_info;
@ -4633,6 +4634,17 @@ static inline abi_ulong do_shmat(CPUArchState *cpu_env,
mmap_lock(); mmap_lock();
/*
* We're mapping shared memory, so 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 (!(cpu->tcg_cflags & CF_PARALLEL)) {
cpu->tcg_cflags |= CF_PARALLEL;
tb_flush(cpu);
}
if (shmaddr) if (shmaddr)
host_raddr = shmat(shmid, (void *)g2h_untagged(shmaddr), shmflg); host_raddr = shmat(shmid, (void *)g2h_untagged(shmaddr), shmflg);
else { else {