From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36174) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bvRHl-0003lH-3S for qemu-devel@nongnu.org; Sat, 15 Oct 2016 11:54:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bvRHh-0007F0-Qn for qemu-devel@nongnu.org; Sat, 15 Oct 2016 11:54:09 -0400 Received: from mail-pf0-x241.google.com ([2607:f8b0:400e:c00::241]:33598) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1bvRHh-0007Dr-Iq for qemu-devel@nongnu.org; Sat, 15 Oct 2016 11:54:05 -0400 Received: by mail-pf0-x241.google.com with SMTP id i85so5999410pfa.0 for ; Sat, 15 Oct 2016 08:54:04 -0700 (PDT) From: Heiher Date: Sat, 15 Oct 2016 23:53:48 +0800 Message-Id: <20161015155348.26834-1-r@hev.cc> Subject: [Qemu-devel] [PATCH] linux-user: Fix do_store_exclusive for shared memory of interprocess. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: aurelien@aurel32.net, yongbok.kim@imgtec.com, Heiher From: Heiher test case: http://pastebin.com/raw/x2GW4xNW Signed-off-by: Heiher --- 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