unicorn/qemu
Samuel Damashek 670d81367b
cputlb: Fix for self-modifying writes across page boundaries
As it currently stands, QEMU does not properly handle self-modifying code
when the write is unaligned and crosses a page boundary. The procedure
for handling a write to the current translation block is to write-protect
the current translation block, catch the write, split up the translation
block into the current instruction (which remains write-protected so that
the current instruction is not modified) and the remaining instructions
in the translation block, and then restore the CPU state to before the
write occurred so the write will be retried and successfully executed.
However, since unaligned writes across pages are split into one-byte
writes for simplicity, writes to the second page (which is not the
current TB) may succeed before a write to the current TB is attempted,
and since these writes are not invalidated before resuming state after
splitting the TB, these writes will be performed a second time, thus
corrupting the second page. Credit goes to Patrick Hulin for
discovering this.

In recent 64-bit versions of Windows running in emulated mode, this
results in either being very unstable (a BSOD after a couple minutes of
uptime), or being entirely unable to boot. Windows performs one or more
8-byte unaligned self-modifying writes (xors) which intersect the end
of the current TB and the beginning of the next TB, which runs into the
aforementioned issue. This commit fixes that issue by making the
unaligned write loop perform the writes in forwards order, instead of
reverse order. This way, QEMU immediately tries to write to the current
TB, and splits the TB before any write to the second page is executed.
The write then proceeds as intended. With this patch applied, I am able
to boot and use Windows 7 64-bit and Windows 10 64-bit in QEMU without
KVM.

Per Richard Henderson's input, this patch also ensures the second page
is in the TLB before executing the write loop, to ensure the second
page is mapped.

The original discussion of the issue is located at
http://lists.nongnu.org/archive/html/qemu-devel/2014-08/msg02161.html.

Backports commit 81daabaf7a572f138a8b88ba6eea556bdb0cce46 from qemu
2018-02-25 03:12:11 -05:00
..
crypto
default-configs
docs
fpu softfloat: Handle snan_bit_is_one == 0 in MIPS pickNaNMulAdd() 2018-02-24 20:40:11 -05:00
hw qemu-common: push cpu.h inclusion out of qemu-common.h 2018-02-24 01:50:56 -05:00
include tcg: Improve the alignment check infrastructure 2018-02-25 02:23:28 -05:00
qapi qapi: Add new clone visitor 2018-02-25 01:34:12 -05:00
qobject util: move declarations out of qemu-common.h 2018-02-22 09:25:48 -05:00
qom qapi: Add new visit_complete() function 2018-02-25 01:20:03 -05:00
scripts qapi: Add new visit_complete() function 2018-02-25 01:20:03 -05:00
target-arm softfloat: Implement run-time-configurable meaning of signaling NaN bit 2018-02-24 20:27:12 -05:00
target-i386 target-i386: Publish advised value of MSR_IA32_FEATURE_CONTROL via fw_cfg 2018-02-25 02:49:42 -05:00
target-m68k softfloat: Implement run-time-configurable meaning of signaling NaN bit 2018-02-24 20:27:12 -05:00
target-mips target-mips: Add FCR31's FS bit definition 2018-02-24 21:32:10 -05:00
target-sparc target-sparc: Use sparc_cpu_parse_features() directly 2018-02-25 02:27:23 -05:00
tcg tcg: Improve the alignment check infrastructure 2018-02-25 02:23:28 -05:00
util range: Replace internal representation of Range 2018-02-25 00:44:36 -05:00
aarch64.h memory: Provide memory_region_init_rom() 2018-02-25 00:28:17 -05:00
aarch64eb.h memory: Provide memory_region_init_rom() 2018-02-25 00:28:17 -05:00
accel.c accel: make configure_accelerator return void 2018-02-24 00:31:28 -05:00
arm.h memory: Provide memory_region_init_rom() 2018-02-25 00:28:17 -05:00
armeb.h memory: Provide memory_region_init_rom() 2018-02-25 00:28:17 -05:00
CODING_STYLE
configure configure: Enable -Werror for MinGW builds, too 2018-02-24 18:56:05 -05:00
COPYING
COPYING.LIB
cpu-exec-common.c cpu-exec: Rename cpu_resume_from_signal() to cpu_loop_exit_noexc() 2018-02-24 17:25:28 -05:00
cpu-exec.c tb hash: hash phys_pc, pc, and flags with xxhash 2018-02-24 18:00:14 -05:00
cpus.c cpu: move exec-all.h inclusion out of cpu.h 2018-02-24 02:39:08 -05:00
cputlb.c cputlb: Add address parameter to VICTIM_TLB_HIT 2018-02-25 03:03:36 -05:00
exec.c exec: hide mr->ram_addr from qemu_get_ram_ptr users 2018-02-24 16:17:49 -05:00
gen_all_header.sh
glib_compat.c qapi: Fix memleak in string visitors on int lists 2018-02-25 00:20:34 -05:00
HACKING
header_gen.py memory: Provide memory_region_init_rom() 2018-02-25 00:28:17 -05:00
ioport.c hw: remove pio_addr_t 2018-02-24 02:43:16 -05:00
LICENSE
m68k.h memory: Provide memory_region_init_rom() 2018-02-25 00:28:17 -05:00
Makefile Makefile: Add a FORCE target 2018-02-24 17:03:51 -05:00
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 memory: Provide memory_region_init_rom() 2018-02-25 00:28:17 -05:00
mips64.h memory: Provide memory_region_init_rom() 2018-02-25 00:28:17 -05:00
mips64el.h memory: Provide memory_region_init_rom() 2018-02-25 00:28:17 -05:00
mips.h memory: Provide memory_region_init_rom() 2018-02-25 00:28:17 -05:00
mipsel.h memory: Provide memory_region_init_rom() 2018-02-25 00:28:17 -05:00
powerpc.h memory: Provide memory_region_init_rom() 2018-02-25 00:28:17 -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 Makefile: add dependency on scripts/create_config 2018-02-24 17:05:03 -05:00
softmmu_template.h cputlb: Fix for self-modifying writes across page boundaries 2018-02-25 03:12:11 -05:00
sparc64.h memory: Provide memory_region_init_rom() 2018-02-25 00:28:17 -05:00
sparc.h memory: Provide memory_region_init_rom() 2018-02-25 00:28:17 -05:00
tcg-runtime.c
translate-all.c exec: [tcg] Track which vCPU is performing translation and execution 2018-02-24 19:21:39 -05:00
translate-all.h user-exec: Push resume-from-signal code out to handle_cpu_signal() 2018-02-24 17:21:06 -05:00
translate-common.c
unicorn_common.h
VERSION
vl.c hw: explicitly include qemu/log.h 2018-02-24 02:00:45 -05:00
vl.h
x86_64.h memory: Provide memory_region_init_rom() 2018-02-25 00:28:17 -05:00