From patchwork Wed Jul 13 21:00:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: sergey.fedorov@linaro.org X-Patchwork-Id: 9228495 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 CBFB060868 for ; Wed, 13 Jul 2016 21:17:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B785527FA4 for ; Wed, 13 Jul 2016 21:17:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ABEB728066; Wed, 13 Jul 2016 21:17:04 +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 0094F27FA4 for ; Wed, 13 Jul 2016 21:17:03 +0000 (UTC) Received: from localhost ([::1]:49996 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bNRWh-0002Ba-8N for patchwork-qemu-devel@patchwork.kernel.org; Wed, 13 Jul 2016 17:17:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58228) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bNRH0-0007Je-DX for qemu-devel@nongnu.org; Wed, 13 Jul 2016 17:00:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bNRGz-0001Ic-1t for qemu-devel@nongnu.org; Wed, 13 Jul 2016 17:00:50 -0400 Received: from mail-lf0-x235.google.com ([2a00:1450:4010:c07::235]:36432) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bNRGy-0001IW-MH for qemu-devel@nongnu.org; Wed, 13 Jul 2016 17:00:48 -0400 Received: by mail-lf0-x235.google.com with SMTP id q132so48177063lfe.3 for ; Wed, 13 Jul 2016 14:00:48 -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=OzrcP+sstpMBC2i3KSBl8lIYMMF6pqPMgSkRtaNQ9/M=; b=NyFOFgJhMMuXI1fg7NvErVaBCnZi+v/qUm0uw2rUmzilfWDQ8FLmZEdpLxKmd1npDu jXDWJclRrOWR6t9GQxmoyxjALuC9p+Zem3KwmGFQcCFiM91CMSz/MaPevktH+oWwu12L D/8+ShNN3J2i8mzJ+yRmTMBSbLMzcpJGdRlw0= 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=OzrcP+sstpMBC2i3KSBl8lIYMMF6pqPMgSkRtaNQ9/M=; b=DBCFODdA/6jW3DTsExGb+yYi+4ZcoWPZtdO9ujNXBPC6vqZEeugzD4sftr9vH2uU22 9BYZyYiHsKx217hHlMJyw22MNruYB2s28VE3NL38rG4OIRQ52al/dMUpEaqcjLSCrxxZ Gi9Mky4n+IQ2907Vkc4GI7M3o/anzzu55m5r4Wb6XxG5RauNDBTlJAtVCT0yivJ5ukox LugKNCRRJAd8qqkpTWIofNdOYu4z0ev1hq0GvsrWMAKVrvVD1BLDHqZA6J7EFrFXaMVa CoboPDIBoPWGAKdChXic3Bf4UGwcQENqPzqH+NiWvePpuc6acr+YoToW2Kx4M+EplCAm 5Y7g== X-Gm-Message-State: ALyK8tIqXKphe85eM6cu1ZdER/2e7ZhLseke2agKLrIC4rQEzH6S8i4Pubej6yfkKddEzsvc X-Received: by 10.25.219.130 with SMTP id t2mr5509587lfi.26.1468443647847; Wed, 13 Jul 2016 14:00:47 -0700 (PDT) Received: from sergey-laptop.Dlink (broadband-46-188-120-37.2com.net. [46.188.120.37]) by smtp.gmail.com with ESMTPSA id 16sm152403lja.31.2016.07.13.14.00.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 13 Jul 2016 14:00:46 -0700 (PDT) From: Sergey Fedorov To: qemu-devel@nongnu.org Date: Thu, 14 Jul 2016 00:00:22 +0300 Message-Id: <1468443622-17368-13-git-send-email-sergey.fedorov@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1468443622-17368-1-git-send-email-sergey.fedorov@linaro.org> References: <1468443622-17368-1-git-send-email-sergey.fedorov@linaro.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:4010:c07::235 Subject: [Qemu-devel] [PATCH v3 12/12] tcg: Make tb_flush() thread safe 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: MTTCG Devel , Peter Maydell , Sergey Fedorov , patches@linaro.org, Peter Crosthwaite , Alvise Rigo , "Emilio G. Cota" , Paolo Bonzini , serge.fdrv@gmail.com, Richard Henderson , =?UTF-8?Q?Alex_Benn=c3=a9e?= , =?UTF-8?B?S09OUkFEIEZyw6lkw6lyaWM=?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Sergey Fedorov Use async_safe_run_on_cpu() to make tb_flush() thread safe. Signed-off-by: Sergey Fedorov Signed-off-by: Sergey Fedorov --- Changes in v3: - 'tb_flushed' removed Changes in v2: - stale comment about unsafe tb_flush() removed --- cpu-exec.c | 14 +------------- include/qom/cpu.h | 2 -- translate-all.c | 14 ++++++++------ 3 files changed, 9 insertions(+), 21 deletions(-) diff --git a/cpu-exec.c b/cpu-exec.c index b840e1d2dd41..0b7614ffcc9b 100644 --- a/cpu-exec.c +++ b/cpu-exec.c @@ -203,20 +203,16 @@ static void cpu_exec_nocache(CPUState *cpu, int max_cycles, TranslationBlock *orig_tb, bool ignore_icount) { TranslationBlock *tb; - bool old_tb_flushed; /* Should never happen. We only end up here when an existing TB is too long. */ if (max_cycles > CF_COUNT_MASK) max_cycles = CF_COUNT_MASK; - old_tb_flushed = cpu->tb_flushed; - cpu->tb_flushed = false; tb = tb_gen_code(cpu, orig_tb->pc, orig_tb->cs_base, orig_tb->flags, max_cycles | CF_NOCACHE | (ignore_icount ? CF_IGNORE_ICOUNT : 0)); - tb->orig_tb = cpu->tb_flushed ? NULL : orig_tb; - cpu->tb_flushed |= old_tb_flushed; + tb->orig_tb = orig_tb; /* execute the generated code */ trace_exec_tb_nocache(tb, tb->pc); cpu_tb_exec(cpu, tb); @@ -338,13 +334,6 @@ static inline TranslationBlock *tb_find_fast(CPUState *cpu, tb->flags != flags)) { tb = tb_find_slow(cpu, pc, cs_base, flags); } - if (cpu->tb_flushed) { - /* Ensure that no TB jump will be modified as the - * translation buffer has been flushed. - */ - *last_tb = NULL; - cpu->tb_flushed = false; - } #ifndef CONFIG_USER_ONLY /* We don't take care of direct jumps when address mapping changes in * system emulation. So it's not safe to make a direct jump to a TB @@ -619,7 +608,6 @@ int cpu_exec(CPUState *cpu) } last_tb = NULL; /* forget the last executed TB after exception */ - cpu->tb_flushed = false; /* reset before first TB lookup */ for(;;) { cpu_handle_interrupt(cpu, &last_tb); tb = tb_find_fast(cpu, &last_tb, tb_exit); diff --git a/include/qom/cpu.h b/include/qom/cpu.h index ab67bf2ba19f..9af4420d2bb5 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -258,7 +258,6 @@ struct qemu_work_item { * @crash_occurred: Indicates the OS reported a crash (panic) for this CPU * @tcg_exit_req: Set to force TCG to stop executing linked TBs for this * CPU and return to its top level loop. - * @tb_flushed: Indicates the translation buffer has been flushed. * @singlestep_enabled: Flags for single-stepping. * @icount_extra: Instructions until next timer event. * @icount_decr: Number of cycles left, with interrupt flag in high bit. @@ -310,7 +309,6 @@ struct CPUState { bool unplug; bool crash_occurred; bool exit_request; - bool tb_flushed; uint32_t interrupt_request; int singlestep_enabled; int64_t icount_extra; diff --git a/translate-all.c b/translate-all.c index 0d47c1c0cf82..b04e9113c18c 100644 --- a/translate-all.c +++ b/translate-all.c @@ -831,8 +831,7 @@ static void page_flush_tb(void) } /* flush all the translation blocks */ -/* XXX: tb_flush is currently not thread safe */ -void tb_flush(CPUState *cpu) +static void do_tb_flush(CPUState *cpu, void *data) { #if defined(DEBUG_FLUSH) printf("qemu: flush code_size=%ld nb_tbs=%d avg_tb_size=%ld\n", @@ -849,7 +848,6 @@ void tb_flush(CPUState *cpu) CPU_FOREACH(cpu) { memset(cpu->tb_jmp_cache, 0, sizeof(cpu->tb_jmp_cache)); - cpu->tb_flushed = true; } qht_reset_size(&tcg_ctx.tb_ctx.htable, CODE_GEN_HTABLE_SIZE); @@ -861,6 +859,11 @@ void tb_flush(CPUState *cpu) tcg_ctx.tb_ctx.tb_flush_count++; } +void tb_flush(CPUState *cpu) +{ + async_safe_run_on_cpu(cpu, do_tb_flush, NULL); +} + #ifdef DEBUG_TB_CHECK static void @@ -1163,9 +1166,8 @@ TranslationBlock *tb_gen_code(CPUState *cpu, buffer_overflow: /* flush must be done */ tb_flush(cpu); - /* cannot fail at this point */ - tb = tb_alloc(pc); - assert(tb != NULL); + mmap_unlock(); + cpu_loop_exit(cpu); } gen_code_buf = tcg_ctx.code_gen_ptr;