qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Sergey Fedorov <serge.fdrv@gmail.com>,
	Sergey Fedorov <sergey.fedorov@linaro.org>
Subject: [Qemu-devel] [PULL 06/58] tcg: Prepare safe access to tb_flushed out of tb_lock
Date: Tue, 13 Sep 2016 19:15:37 +0200	[thread overview]
Message-ID: <1473786989-54823-7-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1473786989-54823-1-git-send-email-pbonzini@redhat.com>

From: Sergey Fedorov <serge.fdrv@gmail.com>

Ensure atomicity and ordering of CPU's 'tb_flushed' access for future
translation block lookup out of 'tb_lock'.

This field can only be touched from another thread by tb_flush() in user
mode emulation. So the only access to be sequential atomic is:
 * a single write in tb_flush();
 * reads/writes out of 'tb_lock'.

In future, before enabling MTTCG in system mode, tb_flush() must be safe
and this field becomes unnecessary.

Signed-off-by: Sergey Fedorov <serge.fdrv@gmail.com>
Signed-off-by: Sergey Fedorov <sergey.fedorov@linaro.org>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Message-Id: <20160715175852.30749-5-sergey.fedorov@linaro.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 cpu-exec.c      | 16 +++++++---------
 translate-all.c |  4 ++--
 2 files changed, 9 insertions(+), 11 deletions(-)

diff --git a/cpu-exec.c b/cpu-exec.c
index 32b58ed..877ff8e 100644
--- a/cpu-exec.c
+++ b/cpu-exec.c
@@ -338,13 +338,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
@@ -356,7 +349,12 @@ static inline TranslationBlock *tb_find_fast(CPUState *cpu,
 #endif
     /* See if we can patch the calling TB. */
     if (last_tb && !qemu_loglevel_mask(CPU_LOG_TB_NOCHAIN)) {
-        tb_add_jump(last_tb, tb_exit, tb);
+        /* Check if translation buffer has been flushed */
+        if (cpu->tb_flushed) {
+            cpu->tb_flushed = false;
+        } else {
+            tb_add_jump(last_tb, tb_exit, tb);
+        }
     }
     tb_unlock();
     return tb;
@@ -617,7 +615,7 @@ int cpu_exec(CPUState *cpu)
                 break;
             }
 
-            cpu->tb_flushed = false; /* reset before first TB lookup */
+            atomic_mb_set(&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/translate-all.c b/translate-all.c
index 77ae59d..e753a50 100644
--- a/translate-all.c
+++ b/translate-all.c
@@ -848,7 +848,6 @@ void tb_flush(CPUState *cpu)
         > tcg_ctx.code_gen_buffer_size) {
         cpu_abort(cpu, "Internal error: code buffer overflow\n");
     }
-    tcg_ctx.tb_ctx.nb_tbs = 0;
 
     CPU_FOREACH(cpu) {
         int i;
@@ -856,9 +855,10 @@ void tb_flush(CPUState *cpu)
         for (i = 0; i < TB_JMP_CACHE_SIZE; ++i) {
             atomic_set(&cpu->tb_jmp_cache[i], NULL);
         }
-        cpu->tb_flushed = true;
+        atomic_mb_set(&cpu->tb_flushed, true);
     }
 
+    tcg_ctx.tb_ctx.nb_tbs = 0;
     qht_reset_size(&tcg_ctx.tb_ctx.htable, CODE_GEN_HTABLE_SIZE);
     page_flush_tb();
 
-- 
1.8.3.1

  parent reply	other threads:[~2016-09-13 17:17 UTC|newest]

Thread overview: 60+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-13 17:15 [Qemu-devel] [PULL 00/58] First round of misc patches for QEMU 2.8 Paolo Bonzini
2016-09-13 17:15 ` [Qemu-devel] [PULL 01/58] qtail: clean up direct access to tqe_prev field Paolo Bonzini
2016-09-13 17:15 ` [Qemu-devel] [PULL 02/58] util/qemu-sockets: revert Yoda Conditions to normal Paolo Bonzini
2016-09-13 17:15 ` [Qemu-devel] [PULL 03/58] util: fix some coding style issue Paolo Bonzini
2016-09-13 17:15 ` [Qemu-devel] [PULL 04/58] tcg: Pass last_tb by value to tb_find_fast() Paolo Bonzini
2016-09-13 17:15 ` [Qemu-devel] [PULL 05/58] tcg: Prepare safe tb_jmp_cache lookup out of tb_lock Paolo Bonzini
2016-09-13 17:15 ` Paolo Bonzini [this message]
2016-09-13 17:15 ` [Qemu-devel] [PULL 07/58] tcg: Prepare TB invalidation for lockless TB lookup Paolo Bonzini
2016-09-13 17:15 ` [Qemu-devel] [PULL 08/58] tcg: set up tb->page_addr before insertion Paolo Bonzini
2016-09-13 17:15 ` [Qemu-devel] [PULL 09/58] tcg: cpu-exec: remove tb_lock from the hot-path Paolo Bonzini
2016-09-13 17:15 ` [Qemu-devel] [PULL 10/58] tcg: Avoid bouncing tb_lock between tb_gen_code() and tb_add_jump() Paolo Bonzini
2016-09-13 17:15 ` [Qemu-devel] [PULL 11/58] tcg: Merge tb_find_slow() and tb_find_fast() Paolo Bonzini
2016-09-13 17:15 ` [Qemu-devel] [PULL 12/58] tcg: rename tb_find_physical() Paolo Bonzini
2016-09-13 17:15 ` [Qemu-devel] [PULL 13/58] rules.mak: Don't extract libs from .mo-libs in link command Paolo Bonzini
2016-09-13 17:15 ` [Qemu-devel] [PULL 14/58] timer: update comments Paolo Bonzini
2016-09-13 17:15 ` [Qemu-devel] [PULL 15/58] cpus: rename local variable to meaningful one Paolo Bonzini
2016-09-13 17:15 ` [Qemu-devel] [PULL 16/58] cpus: update comments Paolo Bonzini
2016-09-13 17:15 ` [Qemu-devel] [PULL 17/58] help: Update help to remove misleading display information Paolo Bonzini
2016-09-13 17:15 ` [Qemu-devel] [PULL 18/58] lsi: print register names in debug prints Paolo Bonzini
2016-09-13 17:15 ` [Qemu-devel] [PULL 19/58] lsi: do not exit QEMU if reading invalid register Paolo Bonzini
2016-09-13 17:15 ` [Qemu-devel] [PULL 20/58] lsi: implement I/O memory space for Memory Move instructions Paolo Bonzini
2016-09-13 17:15 ` [Qemu-devel] [PULL 21/58] lsi: never set DMA FIFO Empty (DFE) bit in DSTAT register Paolo Bonzini
2016-09-13 17:15 ` [Qemu-devel] [PULL 22/58] MAINTAINERS: add myself as stubs maintainers Paolo Bonzini
2016-09-13 17:15 ` [Qemu-devel] [PULL 23/58] scsi-disk: change disk serial length from 20 to 36 Paolo Bonzini
2016-09-13 17:15 ` [Qemu-devel] [PULL 24/58] vmw_pvscsi: check page count while initialising descriptor rings Paolo Bonzini
2016-09-13 17:15 ` [Qemu-devel] [PULL 25/58] scsi: mptconfig: fix an assert expression Paolo Bonzini
2016-09-13 17:15 ` [Qemu-devel] [PULL 26/58] scsi: mptconfig: fix misuse of MPTSAS_CONFIG_PACK Paolo Bonzini
2016-09-13 17:15 ` [Qemu-devel] [PULL 27/58] vmxcap: Show raw MSR value Paolo Bonzini
2016-09-13 17:15 ` [Qemu-devel] [PULL 28/58] vmxcap: Add TSC scaling bit Paolo Bonzini
2016-09-13 17:16 ` [Qemu-devel] [PULL 29/58] doc/rcu: fix typo Paolo Bonzini
2016-09-13 17:16 ` [Qemu-devel] [PULL 30/58] chardev: Add 'help' option to print all available chardev backend types Paolo Bonzini
2016-09-13 17:16 ` [Qemu-devel] [PULL 31/58] MAINTAINERS: Fix wildcard for scsi headers Paolo Bonzini
2016-09-13 17:16 ` [Qemu-devel] [PULL 32/58] MAINTAINERS: Add some header files to the PC chipset section Paolo Bonzini
2016-09-13 17:16 ` [Qemu-devel] [PULL 33/58] scsi: pvscsi: limit loop to fetch SG list Paolo Bonzini
2016-09-13 17:16 ` [Qemu-devel] [PULL 34/58] default-configs: remove CONFIG_PAM Paolo Bonzini
2016-09-13 17:16 ` [Qemu-devel] [PULL 35/58] default-configs: removed obsolete CONFIG_ISA_MMIO Paolo Bonzini
2016-09-13 17:16 ` [Qemu-devel] [PULL 36/58] default-configs: remove CONFIG_PIIX_PCI Paolo Bonzini
2016-09-13 17:16 ` [Qemu-devel] [PULL 37/58] ipmi: check return of qemu_chr_fe_write() for errors Paolo Bonzini
2016-09-13 17:16 ` [Qemu-devel] [PULL 38/58] sclpconsolelm: remove bogus check for -EAGAIN Paolo Bonzini
2016-09-13 17:16 ` [Qemu-devel] [PULL 39/58] hw: replace most use of qemu_chr_fe_write with qemu_chr_fe_write_all Paolo Bonzini
2016-09-13 17:16 ` [Qemu-devel] [PULL 40/58] char: convert qemu_chr_fe_write to qemu_chr_fe_write_all Paolo Bonzini
2016-09-13 17:16 ` [Qemu-devel] [PULL 41/58] Revert "megasas: remove useless check for cmd->frame" Paolo Bonzini
2016-09-13 17:16 ` [Qemu-devel] [PULL 42/58] i8257: Make device "i8257" unavailable with -device Paolo Bonzini
2016-09-13 17:16 ` [Qemu-devel] [PULL 43/58] kvm-all: drop kvm_setup_guest_memory Paolo Bonzini
2016-09-13 17:16 ` [Qemu-devel] [PULL 44/58] atomics: Remove redundant barrier()'s Paolo Bonzini
2016-09-13 17:16 ` [Qemu-devel] [PULL 45/58] atomics: Use __atomic_*_n() variant primitives Paolo Bonzini
2016-09-13 17:16 ` [Qemu-devel] [PULL 46/58] checkpatch: Fix whitespace checks for documentation code blocks Paolo Bonzini
2016-09-13 17:16 ` [Qemu-devel] [PULL 47/58] optionrom: do not rely on compiler's bswap optimization Paolo Bonzini
2016-09-13 17:16 ` [Qemu-devel] [PULL 49/58] ppc: do not redefine CPUPPCState Paolo Bonzini
2016-09-13 17:16 ` [Qemu-devel] [PULL 50/58] cutils: Move buffer_is_zero and subroutines to a new file Paolo Bonzini
2016-09-13 17:16 ` [Qemu-devel] [PULL 51/58] cutils: Remove SPLAT macro Paolo Bonzini
2016-09-13 17:16 ` [Qemu-devel] [PULL 52/58] cutils: Export only buffer_is_zero Paolo Bonzini
2016-09-13 17:16 ` [Qemu-devel] [PULL 53/58] cutils: Rearrange buffer_is_zero acceleration Paolo Bonzini
2016-09-13 17:16 ` [Qemu-devel] [PULL 54/58] cutils: Remove aarch64 buffer zero checking Paolo Bonzini
2016-09-13 17:16 ` [Qemu-devel] [PULL 55/58] cutils: Remove ppc " Paolo Bonzini
2016-09-13 17:16 ` [Qemu-devel] [PULL 56/58] cutils: Add test for buffer_is_zero Paolo Bonzini
2016-09-13 17:16 ` [Qemu-devel] [PULL 57/58] cutils: Add SSE4 version Paolo Bonzini
2016-09-13 17:16 ` [Qemu-devel] [PULL 58/58] cutils: Add generic prefetch Paolo Bonzini
2016-09-13 17:49 ` [Qemu-devel] [PULL 00/58] First round of misc patches for QEMU 2.8 Peter Maydell
2016-09-13 19:08   ` Paolo Bonzini

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=1473786989-54823-7-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=serge.fdrv@gmail.com \
    --cc=sergey.fedorov@linaro.org \
    /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).