From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42546) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YCAZg-0002Th-Mh for qemu-devel@nongnu.org; Fri, 16 Jan 2015 12:20:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YCAZY-0003kn-Sd for qemu-devel@nongnu.org; Fri, 16 Jan 2015 12:20:44 -0500 Received: from [2001:41d0:8:2b42::1] (port=56817 helo=greensocs.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YCAZY-0003h8-2b for qemu-devel@nongnu.org; Fri, 16 Jan 2015 12:20:36 -0500 From: fred.konrad@greensocs.com Date: Fri, 16 Jan 2015 18:19:48 +0100 Message-Id: <1421428797-23697-2-git-send-email-fred.konrad@greensocs.com> In-Reply-To: <1421428797-23697-1-git-send-email-fred.konrad@greensocs.com> References: <1421428797-23697-1-git-send-email-fred.konrad@greensocs.com> Subject: [Qemu-devel] [RFC 01/10] target-arm: protect cpu_exclusive_*. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, mttcg@listserver.greensocs.com Cc: peter.maydell@linaro.org, jan.kiszka@siemens.com, mark.burton@greensocs.com, agraf@suse.de, pbonzini@redhat.com, fred.konrad@greensocs.com From: KONRAD Frederic This adds a lock to avoid multiple exclusive access at the same time in case of TCG multithread. Signed-off-by: KONRAD Frederic V1 -> V2: Removed qemu_mutex_destroy(). --- target-arm/cpu.c | 14 ++++++++++++++ target-arm/cpu.h | 3 +++ target-arm/helper.h | 3 +++ target-arm/op_helper.c | 10 ++++++++++ target-arm/translate.c | 6 ++++++ 5 files changed, 36 insertions(+) diff --git a/target-arm/cpu.c b/target-arm/cpu.c index 285947f..75bdc5b 100644 --- a/target-arm/cpu.c +++ b/target-arm/cpu.c @@ -31,6 +31,19 @@ #include "sysemu/kvm.h" #include "kvm_arm.h" +/* Protect cpu_exclusive_* variable .*/ +QemuMutex cpu_exclusive_lock; + +inline void arm_exclusive_lock(void) +{ + qemu_mutex_lock(&cpu_exclusive_lock); +} + +inline void arm_exclusive_unlock(void) +{ + qemu_mutex_unlock(&cpu_exclusive_lock); +} + static void arm_cpu_set_pc(CPUState *cs, vaddr value) { ARMCPU *cpu = ARM_CPU(cs); @@ -374,6 +387,7 @@ static void arm_cpu_initfn(Object *obj) cpu->psci_version = 2; /* TCG implements PSCI 0.2 */ if (!inited) { inited = true; + qemu_mutex_init(&cpu_exclusive_lock); arm_translate_init(); } } diff --git a/target-arm/cpu.h b/target-arm/cpu.h index 7ba55f0..2101d85 100644 --- a/target-arm/cpu.h +++ b/target-arm/cpu.h @@ -1821,4 +1821,7 @@ enum { QEMU_PSCI_CONDUIT_HVC = 2, }; +void arm_exclusive_lock(void); +void arm_exclusive_unlock(void); + #endif diff --git a/target-arm/helper.h b/target-arm/helper.h index dec3728..ce07711 100644 --- a/target-arm/helper.h +++ b/target-arm/helper.h @@ -529,6 +529,9 @@ DEF_HELPER_2(dc_zva, void, env, i64) DEF_HELPER_FLAGS_2(neon_pmull_64_lo, TCG_CALL_NO_RWG_SE, i64, i64, i64) DEF_HELPER_FLAGS_2(neon_pmull_64_hi, TCG_CALL_NO_RWG_SE, i64, i64, i64) +DEF_HELPER_0(exclusive_lock, void) +DEF_HELPER_0(exclusive_unlock, void) + #ifdef TARGET_AARCH64 #include "helper-a64.h" #endif diff --git a/target-arm/op_helper.c b/target-arm/op_helper.c index 2bed914..d830fd8 100644 --- a/target-arm/op_helper.c +++ b/target-arm/op_helper.c @@ -33,6 +33,16 @@ static void raise_exception(CPUARMState *env, int tt) cpu_loop_exit(cs); } +void HELPER(exclusive_lock)(void) +{ + arm_exclusive_lock(); +} + +void HELPER(exclusive_unlock)(void) +{ + arm_exclusive_unlock(); +} + uint32_t HELPER(neon_tbl)(CPUARMState *env, uint32_t ireg, uint32_t def, uint32_t rn, uint32_t maxindex) { diff --git a/target-arm/translate.c b/target-arm/translate.c index bdfcdf1..513d151 100644 --- a/target-arm/translate.c +++ b/target-arm/translate.c @@ -7381,6 +7381,7 @@ static void gen_load_exclusive(DisasContext *s, int rt, int rt2, abort(); } + gen_helper_exclusive_lock(); if (size == 3) { TCGv_i32 tmp2 = tcg_temp_new_i32(); TCGv_i32 tmp3 = tcg_temp_new_i32(); @@ -7396,11 +7397,14 @@ static void gen_load_exclusive(DisasContext *s, int rt, int rt2, store_reg(s, rt, tmp); tcg_gen_extu_i32_i64(cpu_exclusive_addr, addr); + gen_helper_exclusive_unlock(); } static void gen_clrex(DisasContext *s) { + gen_helper_exclusive_lock(); tcg_gen_movi_i64(cpu_exclusive_addr, -1); + gen_helper_exclusive_unlock(); } #ifdef CONFIG_USER_ONLY @@ -7431,6 +7435,7 @@ static void gen_store_exclusive(DisasContext *s, int rd, int rt, int rt2, done_label = gen_new_label(); extaddr = tcg_temp_new_i64(); tcg_gen_extu_i32_i64(extaddr, addr); + gen_helper_exclusive_lock(); tcg_gen_brcond_i64(TCG_COND_NE, extaddr, cpu_exclusive_addr, fail_label); tcg_temp_free_i64(extaddr); @@ -7495,6 +7500,7 @@ static void gen_store_exclusive(DisasContext *s, int rd, int rt, int rt2, tcg_gen_movi_i32(cpu_R[rd], 1); gen_set_label(done_label); tcg_gen_movi_i64(cpu_exclusive_addr, -1); + gen_helper_exclusive_unlock(); } #endif -- 1.9.0