From: Paolo Bonzini <pbonzini@redhat.com>
To: fred.konrad@greensocs.com, qemu-devel@nongnu.org, mttcg@greensocs.com
Cc: peter.maydell@linaro.org, mark.burton@greensocs.com, vilanova@ac.upc.edu
Subject: Re: [Qemu-devel] [RFC PATCH] target-arm: protect cpu_exclusive_*.
Date: Tue, 16 Dec 2014 10:31:01 +0100 [thread overview]
Message-ID: <548FFBD5.5080405@redhat.com> (raw)
In-Reply-To: <1418721234-9588-1-git-send-email-fred.konrad@greensocs.com>
On 16/12/2014 10:13, fred.konrad@greensocs.com wrote:
> From: KONRAD Frederic <fred.konrad@greensocs.com>
>
> This adds a lock to avoid multiple exclusive access at the same time in case of
> TCG multithread.
>
> Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
> ---
> target-arm/cpu.c | 15 +++++++++++++++
> target-arm/cpu.h | 3 +++
> target-arm/helper.h | 3 +++
> target-arm/op_helper.c | 10 ++++++++++
> target-arm/translate.c | 6 ++++++
> 5 files changed, 37 insertions(+)
>
> diff --git a/target-arm/cpu.c b/target-arm/cpu.c
> index 5ce7350..a55017d 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);
> @@ -365,6 +378,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();
> }
> }
> @@ -404,6 +418,7 @@ static void arm_cpu_finalizefn(Object *obj)
> {
> ARMCPU *cpu = ARM_CPU(obj);
> g_hash_table_destroy(cpu->cp_regs);
> + qemu_mutex_destroy(&cpu_exclusive_lock);
No need for this, and for -smp 2 it will cause the same lock to be
destroyed twice.
Paolo
> }
>
> static void arm_cpu_realizefn(DeviceState *dev, Error **errp)
> diff --git a/target-arm/cpu.h b/target-arm/cpu.h
> index 7f80090..f01c9ef 100644
> --- a/target-arm/cpu.h
> +++ b/target-arm/cpu.h
> @@ -1539,4 +1539,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 62012c3..916772f 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 af51568..4a82ad5 100644
> --- a/target-arm/translate.c
> +++ b/target-arm/translate.c
> @@ -7377,6 +7377,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();
> @@ -7392,11 +7393,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
> @@ -7427,6 +7431,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);
>
> @@ -7491,6 +7496,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
>
>
next prev parent reply other threads:[~2014-12-16 9:31 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-16 9:13 [Qemu-devel] [RFC PATCH] target-arm: protect cpu_exclusive_* fred.konrad
2014-12-16 9:31 ` Paolo Bonzini [this message]
2014-12-16 9:36 ` Frederic Konrad
2014-12-16 9:49 ` Paolo Bonzini
2014-12-16 9:54 ` Frederic Konrad
2014-12-16 16:37 ` Peter Maydell
2014-12-17 10:27 ` Frederic Konrad
2014-12-17 10:28 ` Alexander Graf
2014-12-17 10:31 ` Mark Burton
2014-12-17 10:45 ` Alexander Graf
2014-12-17 11:12 ` Mark Burton
2014-12-17 11:18 ` Alexander Graf
2014-12-17 11:25 ` Paolo Bonzini
2014-12-17 11:36 ` Peter Maydell
2014-12-17 16:17 ` Mark Burton
2014-12-17 16:27 ` Peter Maydell
2014-12-17 16:29 ` Mark Burton
2014-12-17 16:39 ` Peter Maydell
2014-12-17 16:51 ` Peter Maydell
2014-12-18 9:12 ` Mark Burton
2014-12-18 12:24 ` Alexander Graf
2014-12-18 12:35 ` Dr. David Alan Gilbert
2014-12-18 13:28 ` Paolo Bonzini
2014-12-18 13:56 ` Mark Burton
2014-12-18 14:20 ` Mark Burton
2014-12-18 14:44 ` Alexander Graf
2014-12-18 14:51 ` Mark Burton
2014-12-18 15:05 ` Alexander Graf
2014-12-18 15:09 ` Mark Burton
2014-12-18 16:55 ` Paolo Bonzini
2014-12-17 15:52 ` Mark Burton
2014-12-17 16:20 ` Dr. David Alan Gilbert
2014-12-17 11:19 ` Peter Maydell
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=548FFBD5.5080405@redhat.com \
--to=pbonzini@redhat.com \
--cc=fred.konrad@greensocs.com \
--cc=mark.burton@greensocs.com \
--cc=mttcg@greensocs.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=vilanova@ac.upc.edu \
/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).