All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] linux-user: Set CF_PARALLEL when mapping shared memory
@ 2021-06-12  6:08 Richard Henderson
  2021-06-12 10:29 ` Laurent Vivier
  2021-06-14 12:06 ` Alex Bennée
  0 siblings, 2 replies; 3+ messages in thread
From: Richard Henderson @ 2021-06-12  6:08 UTC (permalink / raw)
  To: qemu-devel; +Cc: laurent

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>
---
 linux-user/mmap.c    | 14 ++++++++++++++
 linux-user/syscall.c | 12 ++++++++++++
 2 files changed, 26 insertions(+)

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;
 
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 974dd46c9a..54037db8d6 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -4603,6 +4603,7 @@ static inline abi_ulong target_shmlba(CPUArchState *cpu_env)
 static inline abi_ulong do_shmat(CPUArchState *cpu_env,
                                  int shmid, abi_ulong shmaddr, int shmflg)
 {
+    CPUState *cpu = env_cpu(cpu_env);
     abi_long raddr;
     void *host_raddr;
     struct shmid_ds shm_info;
@@ -4633,6 +4634,17 @@ static inline abi_ulong do_shmat(CPUArchState *cpu_env,
 
     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)
         host_raddr = shmat(shmid, (void *)g2h_untagged(shmaddr), shmflg);
     else {
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] linux-user: Set CF_PARALLEL when mapping shared memory
  2021-06-12  6:08 [PATCH] linux-user: Set CF_PARALLEL when mapping shared memory Richard Henderson
@ 2021-06-12 10:29 ` Laurent Vivier
  2021-06-14 12:06 ` Alex Bennée
  1 sibling, 0 replies; 3+ messages in thread
From: Laurent Vivier @ 2021-06-12 10:29 UTC (permalink / raw)
  To: Richard Henderson, qemu-devel

Le 12/06/2021 à 08:08, Richard Henderson a écrit :
> 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>
> ---
>  linux-user/mmap.c    | 14 ++++++++++++++
>  linux-user/syscall.c | 12 ++++++++++++
>  2 files changed, 26 insertions(+)
> 
> 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;
>  
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index 974dd46c9a..54037db8d6 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -4603,6 +4603,7 @@ static inline abi_ulong target_shmlba(CPUArchState *cpu_env)
>  static inline abi_ulong do_shmat(CPUArchState *cpu_env,
>                                   int shmid, abi_ulong shmaddr, int shmflg)
>  {
> +    CPUState *cpu = env_cpu(cpu_env);
>      abi_long raddr;
>      void *host_raddr;
>      struct shmid_ds shm_info;
> @@ -4633,6 +4634,17 @@ static inline abi_ulong do_shmat(CPUArchState *cpu_env,
>  
>      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)
>          host_raddr = shmat(shmid, (void *)g2h_untagged(shmaddr), shmflg);
>      else {
> 

Applied to my linux-user-for-6.1 branch.

Thanks,
Laurent



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] linux-user: Set CF_PARALLEL when mapping shared memory
  2021-06-12  6:08 [PATCH] linux-user: Set CF_PARALLEL when mapping shared memory Richard Henderson
  2021-06-12 10:29 ` Laurent Vivier
@ 2021-06-14 12:06 ` Alex Bennée
  1 sibling, 0 replies; 3+ messages in thread
From: Alex Bennée @ 2021-06-14 12:06 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel, laurent

Richard Henderson <richard.henderson@linaro.org> writes:

> 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>

-- 
Alex Bennée


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-06-14 12:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-12  6:08 [PATCH] linux-user: Set CF_PARALLEL when mapping shared memory Richard Henderson
2021-06-12 10:29 ` Laurent Vivier
2021-06-14 12:06 ` Alex Bennée

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.