unicorn/qemu
Sergey Fedorov ba9a237586
tcg: Rework tb_invalidated_flag
'tb_invalidated_flag' was meant to catch two events:
* some TB has been invalidated by tb_phys_invalidate();
* the whole translation buffer has been flushed by tb_flush().

Then it was checked:
* in cpu_exec() to ensure that the last executed TB can be safely
linked to directly call the next one;
* in cpu_exec_nocache() to decide if the original TB should be provided
for further possible invalidation along with the temporarily
generated TB.

It is always safe to patch an invalidated TB since it is not going to be
used anyway. It is also safe to call tb_phys_invalidate() for an already
invalidated TB. Thus, setting this flag in tb_phys_invalidate() is
simply unnecessary. Moreover, it can prevent from pretty proper linking
of TBs, if any arbitrary TB has been invalidated. So just don't touch it
in tb_phys_invalidate().

If this flag is only used to catch whether tb_flush() has been called
then rename it to 'tb_flushed'. Declare it as 'bool' and stick to using
only 'true' and 'false' to set its value. Also, instead of setting it in
tb_gen_code(), just after tb_flush() has been called, do it right inside
of tb_flush().

In cpu_exec(), this flag is used to track if tb_flush() has been called
and have made 'next_tb' (a reference to the last executed TB) invalid
for linking it to directly call the next TB. tb_flush() can be called
during the CPU execution loop from tb_gen_code(), during TB execution or
by another thread while 'tb_lock' is released. Catch for translation
buffer flush reliably by resetting this flag once before first TB lookup
and each time we find it set before trying to add a direct jump. Don't
touch in in tb_find_physical().

Each vCPU has its own execution loop in multithreaded mode and thus
should have its own copy of the flag to be able to reset it with its own
'next_tb' and don't affect any other vCPU execution thread. So make this
flag per-vCPU and move it to CPUState.

In cpu_exec_nocache(), we only need to check if tb_flush() has been
called from tb_gen_code() called by cpu_exec_nocache() itself. To do
this reliably, preserve the old value of the flag, reset it before
calling tb_gen_code(), check afterwards, and combine the saved value
back to the flag.

This patch is based on the patch "tcg: move tb_invalidated_flag to
CPUState" from Paolo Bonzini <pbonzini@redhat.com>.

Backports commit 6f789be56d3f38e9214dafcfab3bf9be7191f370 from qemu
2018-02-23 23:34:51 -05:00
..
crypto
default-configs
docs
fpu fpu: silence warnings 2018-02-22 09:52:28 -05:00
hw util: move declarations out of qemu-common.h 2018-02-22 09:25:48 -05:00
include tcg: Rework tb_invalidated_flag 2018-02-23 23:34:51 -05:00
qapi qapi: Change visit_type_FOO() to no longer return partial objects 2018-02-23 19:53:17 -05:00
qobject util: move declarations out of qemu-common.h 2018-02-22 09:25:48 -05:00
qom qapi: Use strict QMP input visitor in more places 2018-02-23 15:11:35 -05:00
scripts qapi: Change visit_type_FOO() to no longer return partial objects 2018-02-23 19:53:17 -05:00
target-arm tcg: Allow goto_tb to any target PC in user mode 2018-02-23 23:12:14 -05:00
target-i386 tcg: Allow goto_tb to any target PC in user mode 2018-02-23 23:12:14 -05:00
target-m68k tcg: Allow goto_tb to any target PC in user mode 2018-02-23 23:12:14 -05:00
target-mips tcg: Allow goto_tb to any target PC in user mode 2018-02-23 23:12:14 -05:00
target-sparc tcg: Allow goto_tb to any target PC in user mode 2018-02-23 23:12:14 -05:00
tcg tcg: Clean up from 'next_tb' 2018-02-23 23:29:04 -05:00
util util: align memory allocations to 2M on AArch64 2018-02-23 13:56:59 -05:00
aarch64.h cputlb: move CPU_LOOP() for tlb_reset() to exec.c 2018-02-23 10:46:31 -05:00
aarch64eb.h cputlb: move CPU_LOOP() for tlb_reset() to exec.c 2018-02-23 10:46:31 -05:00
accel.c
arm.h cputlb: move CPU_LOOP() for tlb_reset() to exec.c 2018-02-23 10:46:31 -05:00
armeb.h cputlb: move CPU_LOOP() for tlb_reset() to exec.c 2018-02-23 10:46:31 -05:00
CODING_STYLE
configure config.status: Pass extra parameters 2018-02-22 10:12:54 -05:00
COPYING
COPYING.LIB
cpu-exec-common.c
cpu-exec.c tcg: Rework tb_invalidated_flag 2018-02-23 23:34:51 -05:00
cpus.c
cputlb.c cputlb: move CPU_LOOP() for tlb_reset() to exec.c 2018-02-23 10:46:31 -05:00
exec.c include/exec: Move cputlb exec.c defs out 2018-02-23 10:52:25 -05:00
gen_all_header.sh
glib_compat.c glib_compat: backport hashtable iterator interfaces 2018-02-21 13:18:44 -05:00
HACKING
header_gen.py cputlb: move CPU_LOOP() for tlb_reset() to exec.c 2018-02-23 10:46:31 -05:00
ioport.c
LICENSE
m68k.h cputlb: move CPU_LOOP() for tlb_reset() to exec.c 2018-02-23 10:46:31 -05:00
Makefile
Makefile.objs
Makefile.target
memory_mapping.c include/qemu/osdep.h: Don't include qapi/error.h 2018-02-21 23:08:18 -05:00
memory.c include/qemu/osdep.h: Don't include qapi/error.h 2018-02-21 23:08:18 -05:00
mips64.h cputlb: move CPU_LOOP() for tlb_reset() to exec.c 2018-02-23 10:46:31 -05:00
mips64el.h cputlb: move CPU_LOOP() for tlb_reset() to exec.c 2018-02-23 10:46:31 -05:00
mips.h cputlb: move CPU_LOOP() for tlb_reset() to exec.c 2018-02-23 10:46:31 -05:00
mipsel.h cputlb: move CPU_LOOP() for tlb_reset() to exec.c 2018-02-23 10:46:31 -05:00
powerpc.h cputlb: move CPU_LOOP() for tlb_reset() to exec.c 2018-02-23 10:46:31 -05:00
qapi-schema.json
qemu-log.c log: move qemu_log_close/qemu_log_flush from header to log.c 2018-02-22 11:13:17 -05:00
qemu-timer.c
rules.mak
softmmu_template.h
sparc64.h cputlb: move CPU_LOOP() for tlb_reset() to exec.c 2018-02-23 10:46:31 -05:00
sparc.h cputlb: move CPU_LOOP() for tlb_reset() to exec.c 2018-02-23 10:46:31 -05:00
tcg-runtime.c
translate-all.c tcg: Rework tb_invalidated_flag 2018-02-23 23:34:51 -05:00
translate-all.h
translate-common.c
unicorn_common.h
VERSION
vl.c util: move declarations out of qemu-common.h 2018-02-22 09:25:48 -05:00
vl.h
x86_64.h cputlb: move CPU_LOOP() for tlb_reset() to exec.c 2018-02-23 10:46:31 -05:00