xemu/target/s390x/tcg
Ilya Leoshkevich 066b9de4b3 target/s390x: Fix MVC not always invalidating translation blocks
Node.js crashes in qemu-system-s390x with random SIGSEGVs / SIGILLs.

The v8 JIT used by Node.js can garbage collect and overwrite unused
code. Overwriting is performed by WritableJitAllocation::CopyCode(),
which ultimately calls memcpy(). For certain sizes, memcpy() uses the
MVC instruction.

QEMU implements MVC and other similar instructions using helpers. While
TCG store ops invalidate affected translation blocks automatically,
helpers must do this manually by calling probe_access_flags(). The MVC
helper does this using the access_prepare() -> access_prepare_nf() ->
s390_probe_access() -> probe_access_flags() call chain.

At the last step of this chain, the store size is replaced with 0. This
causes the probe_access_flags() -> notdirty_write() ->
tb_invalidate_phys_range_fast() chain to miss some translation blocks.

When this happens, QEMU executes a mix of old and new code. This
quickly leads to either a SIGSEGV or a SIGILL in case the old code
ends in the middle of a new instruction.

Fix by passing the true size.

Reported-by: Berthold Gunreben <azouhr@opensuse.org>
Cc: Sarah Kriesch <ada.lovelace@gmx.de>
Cc: qemu-stable@nongnu.org
Closes: https://bugzilla.opensuse.org/show_bug.cgi?id=1235709
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: David Hildenbrand <david@redhat.com>
Fixes: e2faabee78 ("accel/tcg: Forward probe size on to notdirty_write")
Message-ID: <20250128001338.11474-1-iii@linux.ibm.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
(cherry picked from commit e43ced8be18dda77c229ab09f85136a4d600d40d)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
2025-02-01 11:59:14 +03:00
..
cc_helper.c target/s390x/tcg: Fix and improve the SACF instruction 2022-12-03 22:04:40 +01:00
crypto_helper.c target/helpers: Remove unnecessary 'qemu/main-loop.h' header 2023-08-31 19:47:43 +02:00
excp_helper.c target/s390x: Do not use unwind for per_check_exception 2024-05-29 12:40:49 +02:00
fpu_helper.c target/s390x: Fix the floating-point multiply-and-add NaN rules 2024-11-18 10:54:42 +01:00
insn-data.h.inc target/s390x: Emulate CVB, CVBY and CVBG 2024-02-06 09:51:37 +01:00
insn-format.h.inc target/s390x: Rename insn-data/format.def -> insn-data/format.h.inc 2022-11-05 20:35:45 +01:00
int_helper.c target/s390x: Emulate CVB, CVBY and CVBG 2024-02-06 09:51:37 +01:00
mem_helper.c target/s390x: Fix MVC not always invalidating translation blocks 2025-02-01 11:59:14 +03:00
meson.build target/s390x: start moving TCG-only code to tcg/ 2021-07-07 14:01:56 +02:00
misc_helper.c target/s390x: Simplify per_ifetch, per_check_exception 2024-05-29 12:41:15 +02:00
s390-tod.h target/s390x: start moving TCG-only code to tcg/ 2021-07-07 14:01:56 +02:00
tcg_s390x.h compiler.h: replace QEMU_NORETURN with G_NORETURN 2022-04-21 17:03:51 +04:00
translate.c target/s390x: fix build warning (gcc-12 -fsanitize=thread) 2024-08-15 16:33:56 +02:00
translate_vx.c.inc tcg: Rename cpu_env to tcg_env 2023-10-03 08:01:02 -07:00
vec.h Replace config-time define HOST_WORDS_BIGENDIAN 2022-04-06 10:50:37 +02:00
vec_fpu_helper.c target/s390x: Fix the floating-point multiply-and-add NaN rules 2024-11-18 10:54:42 +01:00
vec_helper.c target/s390x: Fix VSTL with a large length 2023-08-23 12:06:44 +02:00
vec_int_helper.c target/s390x: Use clmul_64 2023-09-15 13:57:00 +00:00
vec_string_helper.c target/s390x: Fix the "ignored match" case in VSTRS 2023-08-23 12:06:52 +02:00