qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Heiher <r@hev.cc>
To: qemu-devel@nongnu.org
Cc: aurelien@aurel32.net, yongbok.kim@imgtec.com, Heiher <wangr@lemote.com>
Subject: [Qemu-devel] [PATCH] linux-user: Fix do_store_exclusive for shared memory of interprocess.
Date: Sat, 15 Oct 2016 23:53:48 +0800	[thread overview]
Message-ID: <20161015155348.26834-1-r@hev.cc> (raw)

From: Heiher <wangr@lemote.com>

test case: http://pastebin.com/raw/x2GW4xNW

Signed-off-by: Heiher <wangr@lemote.com>
---
 linux-user/main.c | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/linux-user/main.c b/linux-user/main.c
index 0e31dad..81b0a49 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -2312,6 +2312,23 @@ static const uint8_t mips_syscall_args[] = {
 #  undef MIPS_SYS
 # endif /* O32 */
 
+#define cmpxchg_user(old, new, gaddr, target_type)			\
+({									\
+    abi_ulong __gaddr = (gaddr);					\
+    target_type *__hptr;						\
+    abi_long __ret = 0;							\
+    if ((__hptr = lock_user(VERIFY_WRITE, __gaddr, sizeof(target_type), 0))) { \
+        if ((old) != atomic_cmpxchg(__hptr, (old), (new)))		\
+            __ret = -TARGET_EAGAIN;					\
+        unlock_user(__hptr, __gaddr, sizeof(target_type));		\
+    } else								\
+        __ret = -TARGET_EFAULT;						\
+    __ret;								\
+})
+
+#define cmpxchg_user_u32(old, new, gaddr) cmpxchg_user((old), (new), (gaddr), uint32_t)
+#define cmpxchg_user_u64(old, new, gaddr) cmpxchg_user((old), (new), (gaddr), uint64_t)
+
 static int do_store_exclusive(CPUMIPSState *env)
 {
     target_ulong addr;
@@ -2342,12 +2359,15 @@ static int do_store_exclusive(CPUMIPSState *env)
                 env->active_tc.gpr[reg] = 0;
             } else {
                 if (d) {
-                    segv = put_user_u64(env->llnewval, addr);
+                    segv = cmpxchg_user_u64(env->llval, env->llnewval, addr);
                 } else {
-                    segv = put_user_u32(env->llnewval, addr);
+                    segv = cmpxchg_user_u32(env->llval, env->llnewval, addr);
                 }
                 if (!segv) {
                     env->active_tc.gpr[reg] = 1;
+                } else if (-TARGET_EAGAIN == segv) {
+                    segv = 0;
+                    env->active_tc.gpr[reg] = 0;
                 }
             }
         }
-- 
2.10.0

             reply	other threads:[~2016-10-15 15:54 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-15 15:53 Heiher [this message]
2016-10-15 16:04 ` [Qemu-devel] [PATCH] linux-user: Fix do_store_exclusive for shared memory of interprocess no-reply
2016-10-16 20:34 ` Emilio G. Cota
2016-10-18 17:55 ` Richard Henderson

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=20161015155348.26834-1-r@hev.cc \
    --to=r@hev.cc \
    --cc=aurelien@aurel32.net \
    --cc=qemu-devel@nongnu.org \
    --cc=wangr@lemote.com \
    --cc=yongbok.kim@imgtec.com \
    /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).