From patchwork Thu May 26 16:35:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: alvise rigo X-Patchwork-Id: 9137259 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2FBF76075A for ; Thu, 26 May 2016 16:41:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 239A22807E for ; Thu, 26 May 2016 16:41:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 183C2282E2; Thu, 26 May 2016 16:41:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 887682807E for ; Thu, 26 May 2016 16:41:04 +0000 (UTC) Received: from localhost ([::1]:39505 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b5yLH-0002Ir-NV for patchwork-qemu-devel@patchwork.kernel.org; Thu, 26 May 2016 12:41:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58498) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b5yGe-0006SB-Qb for qemu-devel@nongnu.org; Thu, 26 May 2016 12:36:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b5yGZ-0003ij-59 for qemu-devel@nongnu.org; Thu, 26 May 2016 12:36:15 -0400 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]:36193) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b5yGY-0003ib-R1 for qemu-devel@nongnu.org; Thu, 26 May 2016 12:36:11 -0400 Received: by mail-wm0-x243.google.com with SMTP id q62so7025972wmg.3 for ; Thu, 26 May 2016 09:36:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtualopensystems-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=elDhec1U0u/oWgiMMgfedHUuuUnzxnetzj/iyJD+POU=; b=NsKyfUYwIJ74ONU4sj8BIZ5IdTi38JQmnIaKscNOeL2u3GVX9HPCLmwWIU7fCbX8p9 8SStD9Zyvm5Ej/ib1OMVB1eFIH9d+XaPhi1XLYYeGRQpTh9yAhcw6D2TvIKbxWKYQmn3 1AqqohM8UA+3eEGbn+Op8YVuXTFJISzBXaJjq9oHfoAGm4vtSGDHiBCTD3xyd8l1s9r3 Rcaate0Na3V/674dyxXMPgW0985aaO9gsYzrAoY9oRS9+zIcMri4Sbnx4FU+rhs+U3fB gKfiGYZOyN9T0mGuLyoIGaiZOyGJwXr4+5Z/jZwM7WHBH0B9K2/PXkK/+hqboBF8IZy0 PKRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=elDhec1U0u/oWgiMMgfedHUuuUnzxnetzj/iyJD+POU=; b=Zb3Jev48X/J6TWRZeGlzDqY9H2PC/KHZSqXczFq9x0KhOfCr8IFnBYkrMDBcyiED+r GvykVrjxQEEypnU1ojWtpwN2xObtEgoSczXHg9d7scjYkWGKhfseHzmyS3SFP3jiqFmc BgtiVg07w+/bO6GVo7Fcjwocc+gOhHwDgeUCskBRg7HUWtr06N8R2g0bKmnMZDIGOdI4 Y2Nt07xZ/oRwwJuSaftP+pG0GqWPCba6QObfQINPiTK5FFwq+lx5l3jAQXcT0gMhfD27 63wcBIO8ZjptwfBWNsX3DZ2EEKE+DLNvaVbzQTw8q+aThT1pL5vYnoUWH8VdY0b0CpNv 1RUQ== X-Gm-Message-State: ALyK8tJVL2EqDziH18AKqb6oD1TMwdanBmZldBOzfP+hM1A+aDUoCVFEXtSCi/itOU2sMA== X-Received: by 10.194.18.207 with SMTP id y15mr10512450wjd.155.1464280570098; Thu, 26 May 2016 09:36:10 -0700 (PDT) Received: from linarch.localdomain (LPuteaux-656-1-278-113.w80-15.abo.wanadoo.fr. [80.15.154.113]) by smtp.googlemail.com with ESMTPSA id lf9sm15133703wjc.44.2016.05.26.09.36.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 May 2016 09:36:08 -0700 (PDT) From: Alvise Rigo To: mttcg@listserver.greensocs.com, alex.bennee@linaro.org Date: Thu, 26 May 2016 18:35:41 +0200 Message-Id: <20160526163549.3276-3-a.rigo@virtualopensystems.com> X-Mailer: git-send-email 2.8.3 In-Reply-To: <20160526163549.3276-1-a.rigo@virtualopensystems.com> References: <20160526163549.3276-1-a.rigo@virtualopensystems.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::243 Subject: [Qemu-devel] [RFC 02/10] softmmu_llsc_template.h: Move to multi-threading 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: peter.maydell@linaro.org, rth@twiddle.net, claudio.fontana@huawei.com, qemu-devel@nongnu.org, Alvise Rigo , cota@braap.org, serge.fdrv@gmail.com, pbonzini@redhat.com, jani.kokkonen@huawei.com, tech@virtualopensystems.com, fred.konrad@greensocs.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Using tcg_exclusive_{lock,unlock}(), make the emulation of LoadLink/StoreConditional thread safe. During an LL access, this lock protects the load access itself, the update of the exclusive history and the update of the VCPU's protected range. In a SC access, the lock protects the store access itself, the possible reset of other VCPUs' protected range and the reset of the exclusive context of calling VCPU. The lock is also taken when a normal store happens to access an exclusive page to reset other VCPUs' protected range in case of collision. Moreover, adapt target-arm to also cope with the new multi-threaded execution. Signed-off-by: Alvise Rigo --- softmmu_llsc_template.h | 11 +++++++++-- softmmu_template.h | 6 ++++++ target-arm/op_helper.c | 6 ++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/softmmu_llsc_template.h b/softmmu_llsc_template.h index 2c4a494..d3810c0 100644 --- a/softmmu_llsc_template.h +++ b/softmmu_llsc_template.h @@ -62,11 +62,13 @@ WORD_TYPE helper_ldlink_name(CPUArchState *env, target_ulong addr, hwaddr hw_addr; unsigned mmu_idx = get_mmuidx(oi); + index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1); + + tcg_exclusive_lock(); + /* Use the proper load helper from cpu_ldst.h */ ret = helper_ld(env, addr, oi, retaddr); - index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1); - /* hw_addr = hwaddr of the page (i.e. section->mr->ram_addr + xlat) * plus the offset (i.e. addr & ~TARGET_PAGE_MASK) */ hw_addr = (env->iotlb[mmu_idx][index].addr & TARGET_PAGE_MASK) + addr; @@ -95,6 +97,8 @@ WORD_TYPE helper_ldlink_name(CPUArchState *env, target_ulong addr, cc->cpu_set_excl_protected_range(this_cpu, hw_addr, DATA_SIZE); + tcg_exclusive_unlock(); + /* From now on we are in LL/SC context */ this_cpu->ll_sc_context = true; @@ -114,6 +118,8 @@ WORD_TYPE helper_stcond_name(CPUArchState *env, target_ulong addr, * access as one made by the store conditional wrapper. If the store * conditional does not succeed, the value will be set to 0.*/ cpu->excl_succeeded = true; + + tcg_exclusive_lock(); helper_st(env, addr, val, oi, retaddr); if (cpu->excl_succeeded) { @@ -123,6 +129,7 @@ WORD_TYPE helper_stcond_name(CPUArchState *env, target_ulong addr, /* Unset LL/SC context */ cc->cpu_reset_excl_context(cpu); + tcg_exclusive_unlock(); return ret; } diff --git a/softmmu_template.h b/softmmu_template.h index 76fe37e..9363a7b 100644 --- a/softmmu_template.h +++ b/softmmu_template.h @@ -537,11 +537,16 @@ static inline void smmu_helper(do_excl_store)(CPUArchState *env, } } + /* Take the lock in case we are not coming from a SC */ + tcg_exclusive_lock(); + smmu_helper(do_ram_store)(env, little_endian, val, addr, oi, get_mmuidx(oi), index, retaddr); reset_other_cpus_colliding_ll_addr(hw_addr, DATA_SIZE); + tcg_exclusive_unlock(); + return; } @@ -572,6 +577,7 @@ void helper_le_st_name(CPUArchState *env, target_ulong addr, DATA_TYPE val, /* Handle an IO access or exclusive access. */ if (unlikely(tlb_addr & ~TARGET_PAGE_MASK)) { if (tlb_addr & TLB_EXCL) { + smmu_helper(do_excl_store)(env, true, val, addr, oi, index, retaddr); return; diff --git a/target-arm/op_helper.c b/target-arm/op_helper.c index e22afc5..19ea52d 100644 --- a/target-arm/op_helper.c +++ b/target-arm/op_helper.c @@ -35,7 +35,9 @@ static void raise_exception(CPUARMState *env, uint32_t excp, cs->exception_index = excp; env->exception.syndrome = syndrome; env->exception.target_el = target_el; + tcg_exclusive_lock(); cc->cpu_reset_excl_context(cs); + tcg_exclusive_unlock(); cpu_loop_exit(cs); } @@ -58,7 +60,9 @@ void HELPER(atomic_clear)(CPUARMState *env) CPUState *cs = ENV_GET_CPU(env); CPUClass *cc = CPU_GET_CLASS(cs); + tcg_exclusive_lock(); cc->cpu_reset_excl_context(cs); + tcg_exclusive_unlock(); } uint32_t HELPER(neon_tbl)(CPUARMState *env, uint32_t ireg, uint32_t def, @@ -874,7 +878,9 @@ void HELPER(exception_return)(CPUARMState *env) aarch64_save_sp(env, cur_el); + tcg_exclusive_lock(); cc->cpu_reset_excl_context(cs); + tcg_exclusive_unlock(); /* We must squash the PSTATE.SS bit to zero unless both of the * following hold: