qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Laurent Vivier <laurent@vivier.eu>
To: qemu-devel@nongnu.org
Cc: "Alex Bennée" <alex.bennee@linaro.org>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	"Laurent Vivier" <laurent@vivier.eu>
Subject: [PULL 1/9] linux-user: Set CF_PARALLEL when mapping shared memory
Date: Mon, 21 Jun 2021 13:04:37 +0200	[thread overview]
Message-ID: <20210621110445.231771-2-laurent@vivier.eu> (raw)
In-Reply-To: <20210621110445.231771-1-laurent@vivier.eu>

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

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>
---
 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 7e3b2450368a..0e103859fed8 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 974dd46c9a17..54037db8d66d 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.31.1



  reply	other threads:[~2021-06-21 11:08 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-21 11:04 [PULL 0/9] Linux user for 6.1 patches Laurent Vivier
2021-06-21 11:04 ` Laurent Vivier [this message]
2021-06-21 11:04 ` [PULL 2/9] linux-user: Disable static assert involving __SIGRTMAX if it is missing Laurent Vivier
2021-06-21 11:04 ` [PULL 3/9] linux-user/trace-events: fix minor typo in format string Laurent Vivier
2021-06-21 11:04 ` [PULL 4/9] linux-user: Implement pivot_root Laurent Vivier
2021-06-21 11:04 ` [PULL 5/9] linux-user: Let sigaction query SIGKILL/SIGSTOP Laurent Vivier
2021-06-21 11:04 ` [PULL 6/9] tests/tcg/linux-test: Check that sigaction can " Laurent Vivier
2021-06-21 11:04 ` [PULL 7/9] linux-user: Check for ieee128 fpbits in PPC64 HWCAP2 feature list Laurent Vivier
2021-06-21 11:04 ` [PULL 8/9] linux-user: Fix incorrect use of feature-test-macros Laurent Vivier
2021-06-21 11:04 ` [PULL 9/9] linux-user: Use public sigev_notify_thread_id member if available Laurent Vivier
2021-06-22 17:13 ` [PULL 0/9] Linux user for 6.1 patches Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210621110445.231771-2-laurent@vivier.eu \
    --to=laurent@vivier.eu \
    --cc=alex.bennee@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).