From patchwork Tue Jun 26 16:19:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 140027 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp5455682lji; Tue, 26 Jun 2018 09:32:47 -0700 (PDT) X-Google-Smtp-Source: AAOMgpftHnHm5RchO6EGJP/cyUlsxyaMhOfnN9BNphVFY5TmRZadlSF+QxjMMcUiqB3v8TJdbj8H X-Received: by 2002:ac8:509:: with SMTP id u9-v6mr2083975qtg.97.1530030767858; Tue, 26 Jun 2018 09:32:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530030767; cv=none; d=google.com; s=arc-20160816; b=Kyix95E+FAwbIjKpXOm4gbJC5SQQF/A528ystDSGJa/rSYmRKCW96m3M2GM1/YSUMa gKjxDnYjD36cl94bB9n7sOIV9Dh0azApk9w1Z/qHIFV6pXqo5kIY/zzlgRKY4awm7JuI X/rSrdECpKcTfrBOQ8X2qHg7W1BGtfXaf9rqM4a+ovPrIMUb3I3H/iV0+zXI+FqTULIN pg6Gk/9qP6V1plJe1GdmNa7hlEyKjYXW0xe5blIE6iE6iUdp6tXq7uZ+jjarGiJBMtRp rC/mUODUpGpQKZ7KexVRcnpB41QHD6bdbds6gHAkxWAvsWoyNUD/PARURGDyEawGBflu qIgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=pokBvmOFXHrOHjr/EsOMYde6oJaivnnQyUK2iRji43M=; b=DbY7vQMeUvuZtlOIvXR1D5iJxe2IN6XL3A//6RbjlI/B7V5YYNmzNo/ldecAjwl1MN LdokwLDf1RMRGM4QbEigXlpoB/ZZNENNsemOsTvLp8GCgw2ytNm+F3h0HaPS/yiUg6FV Hc08B+b9gRTiPMI3o7GxqY2HooTul063guX/0rc5u9DFArDqK2BoiAZzciBUS/IwEwhm GPZDIJflnN6WL6ZeBeBolfqQ04i2WxwqQc7NUenr//kLpCsMy15RrHDcf9WTbmN+1HK3 31MHizw/hKqrkelORsYtx7TwVM3l13PHw4HsLAX7pWyz28chUa8uzogRp/iFdMo/Bg5u mApQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Qwx2Q+rt; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id n44-v6si1585155qta.205.2018.06.26.09.32.47 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 26 Jun 2018 09:32:47 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Qwx2Q+rt; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:53831 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fXqtb-0003Hc-8M for patch@linaro.org; Tue, 26 Jun 2018 12:32:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42545) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fXqgs-0000zd-KY for qemu-devel@nongnu.org; Tue, 26 Jun 2018 12:19:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fXqgm-0005ud-Ks for qemu-devel@nongnu.org; Tue, 26 Jun 2018 12:19:38 -0400 Received: from mail-pl0-x244.google.com ([2607:f8b0:400e:c01::244]:46409) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fXqgm-0005uA-Ce for qemu-devel@nongnu.org; Tue, 26 Jun 2018 12:19:32 -0400 Received: by mail-pl0-x244.google.com with SMTP id 30-v6so8763634pld.13 for ; Tue, 26 Jun 2018 09:19:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=pokBvmOFXHrOHjr/EsOMYde6oJaivnnQyUK2iRji43M=; b=Qwx2Q+rtrhrIRaE5/CjUBttjHHDVRyG1AkgHRDr5O31cL8u0UebdaAGgPjsz+4uwR0 0sOVrsaSt3mRZn6r5yXjLkfc3AuMIJrFuOcX/lLP9bGCbRRrqNSMGfCgva06KUQCfr2k aG/EVYHgr0J0mD3/2ZvjVIoteDH2P+gXu/xJw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=pokBvmOFXHrOHjr/EsOMYde6oJaivnnQyUK2iRji43M=; b=HI86/q7XvRcRzD1UeEGnuaHQ86pZNwQlEKsK85txZj0HmBNJa3KRMIsuUKH1gb1vTX ZttYeD+GiIUOXWoGfLtEGg1SSl/KSs791wrj3YO356A89KkK8GAW/nuQ2Aed6+bI+6NH TkFKOl8UearGjP2na9mm5oNSzb5NNfrSPnNHvj6A1a7cRY1MGE+A2vuyPJh/dv48riqj zGsNu1FCBzOmmmYks6Gj4DidEtsgnMAeoXRcftxKWrKNyhM9SuPcDRPt4bE0W3B6IIPW EjmrpU6Flv+T2olm75/gJSp+CGbrv7/YDoucGeYLiaaMXhCAV0se0ZQUkocKvXCBwWKW kKBg== X-Gm-Message-State: APt69E0IPXdJS5Qnf2zCZqQXe5bCwLD/g0nsCq9o9TW3GF6g7VcZZ4WU /9nWrWIkpiiZ0MFEZFnbDLYpbh0dxTg= X-Received: by 2002:a17:902:48c8:: with SMTP id u8-v6mr2344763plh.152.1530029971118; Tue, 26 Jun 2018 09:19:31 -0700 (PDT) Received: from cloudburst.twiddle.net (97-126-112-211.tukw.qwest.net. [97.126.112.211]) by smtp.gmail.com with ESMTPSA id 67-v6sm5054306pfm.171.2018.06.26.09.19.29 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 26 Jun 2018 09:19:29 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 26 Jun 2018 09:19:13 -0700 Message-Id: <20180626161921.27941-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180626161921.27941-1-richard.henderson@linaro.org> References: <20180626161921.27941-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c01::244 Subject: [Qemu-devel] [PATCH 05/13] target/ppc: Remove POWERPC_EXCP_STCX X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-ppc@nongnu.org, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Always use the gen_conditional_store implementation that uses atomic_cmpxchg. Make sure and clear reserve_addr across most interrupts crossing the cpu_loop. Signed-off-by: Richard Henderson --- target/ppc/cpu.h | 5 -- linux-user/ppc/cpu_loop.c | 123 +++++++------------------------------- target/ppc/translate.c | 14 ----- 3 files changed, 23 insertions(+), 119 deletions(-) -- 2.17.1 diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h index 973cf44cda..4edcf62cf7 100644 --- a/target/ppc/cpu.h +++ b/target/ppc/cpu.h @@ -196,7 +196,6 @@ enum { /* QEMU exceptions: special cases we want to stop translation */ POWERPC_EXCP_SYNC = 0x202, /* context synchronizing instruction */ POWERPC_EXCP_SYSCALL_USER = 0x203, /* System call in user mode only */ - POWERPC_EXCP_STCX = 0x204 /* Conditional stores in user mode */ }; /* Exceptions error codes */ @@ -994,10 +993,6 @@ struct CPUPPCState { /* Reservation value */ target_ulong reserve_val; target_ulong reserve_val2; - /* Reservation store address */ - target_ulong reserve_ea; - /* Reserved store source register and size */ - target_ulong reserve_info; /* Those ones are used in supervisor mode only */ /* machine state register */ diff --git a/linux-user/ppc/cpu_loop.c b/linux-user/ppc/cpu_loop.c index 2fb516cb00..133a87f349 100644 --- a/linux-user/ppc/cpu_loop.c +++ b/linux-user/ppc/cpu_loop.c @@ -65,99 +65,23 @@ int ppc_dcr_write (ppc_dcr_t *dcr_env, int dcrn, uint32_t val) return -1; } -static int do_store_exclusive(CPUPPCState *env) -{ - target_ulong addr; - target_ulong page_addr; - target_ulong val, val2 __attribute__((unused)) = 0; - int flags; - int segv = 0; - - addr = env->reserve_ea; - page_addr = addr & TARGET_PAGE_MASK; - start_exclusive(); - mmap_lock(); - flags = page_get_flags(page_addr); - if ((flags & PAGE_READ) == 0) { - segv = 1; - } else { - int reg = env->reserve_info & 0x1f; - int size = env->reserve_info >> 5; - int stored = 0; - - if (addr == env->reserve_addr) { - switch (size) { - case 1: segv = get_user_u8(val, addr); break; - case 2: segv = get_user_u16(val, addr); break; - case 4: segv = get_user_u32(val, addr); break; -#if defined(TARGET_PPC64) - case 8: segv = get_user_u64(val, addr); break; - case 16: { - segv = get_user_u64(val, addr); - if (!segv) { - segv = get_user_u64(val2, addr + 8); - } - break; - } -#endif - default: abort(); - } - if (!segv && val == env->reserve_val) { - val = env->gpr[reg]; - switch (size) { - case 1: segv = put_user_u8(val, addr); break; - case 2: segv = put_user_u16(val, addr); break; - case 4: segv = put_user_u32(val, addr); break; -#if defined(TARGET_PPC64) - case 8: segv = put_user_u64(val, addr); break; - case 16: { - if (val2 == env->reserve_val2) { - if (msr_le) { - val2 = val; - val = env->gpr[reg+1]; - } else { - val2 = env->gpr[reg+1]; - } - segv = put_user_u64(val, addr); - if (!segv) { - segv = put_user_u64(val2, addr + 8); - } - } - break; - } -#endif - default: abort(); - } - if (!segv) { - stored = 1; - } - } - } - env->crf[0] = (stored << 1) | xer_so; - env->reserve_addr = (target_ulong)-1; - } - if (!segv) { - env->nip += 4; - } - mmap_unlock(); - end_exclusive(); - return segv; -} - void cpu_loop(CPUPPCState *env) { CPUState *cs = CPU(ppc_env_get_cpu(env)); target_siginfo_t info; - int trapnr; + int trapnr, sig; target_ulong ret; for(;;) { + bool arch_interrupt; + cpu_exec_start(cs); trapnr = cpu_exec(cs); cpu_exec_end(cs); process_queued_cpu_work(cs); - switch(trapnr) { + arch_interrupt = true; + switch (trapnr) { case POWERPC_EXCP_NONE: /* Just go on */ break; @@ -524,26 +448,15 @@ void cpu_loop(CPUPPCState *env) } env->gpr[3] = ret; break; - case POWERPC_EXCP_STCX: - if (do_store_exclusive(env)) { - info.si_signo = TARGET_SIGSEGV; - info.si_errno = 0; - info.si_code = TARGET_SEGV_MAPERR; - info._sifields._sigfault._addr = env->nip; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - } - break; case EXCP_DEBUG: - { - int sig; - - sig = gdb_handlesig(cs, TARGET_SIGTRAP); - if (sig) { - info.si_signo = sig; - info.si_errno = 0; - info.si_code = TARGET_TRAP_BRKPT; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - } + sig = gdb_handlesig(cs, TARGET_SIGTRAP); + if (sig) { + info.si_signo = sig; + info.si_errno = 0; + info.si_code = TARGET_TRAP_BRKPT; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + } else { + arch_interrupt = false; } break; case EXCP_INTERRUPT: @@ -551,12 +464,22 @@ void cpu_loop(CPUPPCState *env) break; case EXCP_ATOMIC: cpu_exec_step_atomic(cs); + arch_interrupt = false; break; default: cpu_abort(cs, "Unknown exception 0x%x. Aborting\n", trapnr); break; } process_pending_signals(env); + + /* Most of the traps imply a transition through kernel mode, + * which implies an REI instruction has been executed. Which + * means that RX and LOCK_ADDR should be cleared. But there + * are a few exceptions for traps internal to QEMU. + */ + if (arch_interrupt) { + env->reserve_addr = -1; + } } } diff --git a/target/ppc/translate.c b/target/ppc/translate.c index c7b9d226eb..03e8c5df03 100644 --- a/target/ppc/translate.c +++ b/target/ppc/translate.c @@ -3201,19 +3201,6 @@ ST_ATOMIC(stwat, DEF_MEMOP(MO_UL), i32, trunc_tl_i32) ST_ATOMIC(stdat, DEF_MEMOP(MO_Q), i64, mov_i64) #endif -#if defined(CONFIG_USER_ONLY) -static void gen_conditional_store(DisasContext *ctx, TCGv EA, - int reg, int memop) -{ - TCGv t0 = tcg_temp_new(); - - tcg_gen_st_tl(EA, cpu_env, offsetof(CPUPPCState, reserve_ea)); - tcg_gen_movi_tl(t0, (MEMOP_GET_SIZE(memop) << 5) | reg); - tcg_gen_st_tl(t0, cpu_env, offsetof(CPUPPCState, reserve_info)); - tcg_temp_free(t0); - gen_exception_err(ctx, POWERPC_EXCP_STCX, 0); -} -#else static void gen_conditional_store(DisasContext *ctx, TCGv EA, int reg, int memop) { @@ -3244,7 +3231,6 @@ static void gen_conditional_store(DisasContext *ctx, TCGv EA, gen_set_label(l2); tcg_gen_movi_tl(cpu_reserve, -1); } -#endif #define STCX(name, memop) \ static void gen_##name(DisasContext *ctx) \