Commit 574d0a19c6 for qemu.org

commit 574d0a19c64c85a38a8ba08a8f6298a3813b44e8
Author: Warner Losh <imp@bsdimp.com>
Date:   Sun May 24 10:19:29 2026 -0600

    bsd-user: Flag shared memory as needing atomics

    Catch up with linux-user 228168cbb7c:
        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.

    as well as subsequent tweaks and adjustmentst for bsd-user's code
    structure (we don't have one exit path linux-user does and could frankly
    stand to resturcture a bit to match the evolved code in linux-user). On
    non-private mmap(2) sharing and all successful shmat(2) calls we tell
    tcg that we're in a parallel context, which changes how it does atomics.

    Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
    Signed-off-by: Warner Losh <imp@bsdimp.com>

diff --git a/bsd-user/bsd-mem.h b/bsd-user/bsd-mem.h
index 3086143d40..65270e2cdf 100644
--- a/bsd-user/bsd-mem.h
+++ b/bsd-user/bsd-mem.h
@@ -389,6 +389,14 @@ static inline abi_long do_bsd_shmat(int shmid, abi_ulong shmaddr, int shmflg)
         }
     }

+    /*
+     * 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.
+     */
+    begin_parallel_context(thread_cpu);
+
     return raddr;
 }

diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c
index fe77eceb48..548b4824df 100644
--- a/bsd-user/mmap.c
+++ b/bsd-user/mmap.c
@@ -662,6 +662,15 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
     printf("\n");
 #endif
     mmap_unlock();
+    /*
+     * 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_TYPE) != MAP_PRIVATE) {
+        begin_parallel_context(thread_cpu);
+    }
     return start;
 fail:
     mmap_unlock();