qemu-e2k/linux-user/hexagon
Mukilan Thiyagarajan c979d901c8 linux-user/hexagon: fix signal context save & restore
This patch fixes the issue originally reported in
this thread:

https://lists.gnu.org/archive/html/qemu-devel/2021-11/msg01102.html

The root cause of the issue is a bug in the hexagon specific
logic for saving & restoring context during signal delivery.
The CPU state has two different representations for the
predicate registers. The current logic saves & restores only
the aliased HEX_REG_P3_O register, which is part of env->gpr[]
field in the CPU state, but not the individual byte-level
predicate registers (pO, p1, p2, p3) backed by env->pred[].

Since all predicated instructions refer only to the
indiviual registers, switching to and back from a signal handler
can clobber these registers if the signal handler writes to them
causing the normal application code to behave unpredictably when
context is restored.

In the reported issue with the 'signals' test, since the updated
hexagon toolchain had built musl with -O2, the functions called
from non_trivial_free were inlined. This meant that the code
emitted reused predicate P0 computed in the entry translation
block of the function non_trivial_free in one of the child TB
as part of an assertion. Since P0 is clobbered by the signal
handler in the signals test, the assertion in non_trivial_free
fails incorectly. Since musl for hexagon implements the 'abort'
function by deliberately writing to memory via null pointer,
this causes the test to fail with segmentation fault.

This patch modifies the signal context save & restore logic
to include the individual p0, p1, p2, p3 and excludes the
32b p3_0 register since its value is derived from the former
registers. It also adds a new test case that reliabily
reproduces the issue for all four predicate registers.

Buglink: https://github.com/quic/toolchain_for_hexagon/issues/6
Signed-off-by: Mukilan Thiyagarajan <quic_mthiyaga@quicinc.com>
Signed-off-by: Taylor Simpson <tsimpson@quicinc.com>
Reviewed-by: Taylor Simpson <tsimpson@quicinc.com>
Message-Id: <20221229092006.10709-2-quic_mthiyaga@quicinc.com>
2023-01-05 09:19:02 -08:00
..
cpu_loop.c Remove qemu-common.h include from most units 2022-04-06 14:31:55 +02:00
signal.c linux-user/hexagon: fix signal context save & restore 2023-01-05 09:19:02 -08:00
sockbits.h Hexagon (linux-user/hexagon) Linux user emulation 2021-02-18 07:48:22 -08:00
syscall_nr.h linux-user: update syscall_nr.h to Linux v5.13 2021-07-13 13:59:59 +02:00
target_cpu.h Hexagon (linux-user/hexagon) Linux user emulation 2021-02-18 07:48:22 -08:00
target_elf.h Hexagon (linux-user/hexagon) Linux user emulation 2021-02-18 07:48:22 -08:00
target_errno_defs.h linux-user: Extract target errno to 'target_errno_defs.h' 2021-07-12 21:53:35 +02:00
target_fcntl.h Hexagon (linux-user/hexagon) Linux user emulation 2021-02-18 07:48:22 -08:00
target_mman.h linux-user: Provide MADV_* definitions 2022-09-27 09:30:09 +02:00
target_prctl.h linux-user: Split out do_prctl and subroutines 2022-01-06 11:40:52 +01:00
target_resource.h linux-user: Move generic TARGET_RLIMIT* definitions to generic/target_resource.h 2022-02-01 08:01:38 +01:00
target_signal.h Clean up decorations and whitespace around header guards 2022-05-11 16:50:32 +02:00
target_structs.h linux-user: Move target_struct.h generic definitions to generic/ 2022-01-11 18:40:44 +01:00
target_syscall.h Hexagon (linux-user/hexagon) Linux user emulation 2021-02-18 07:48:22 -08:00
termbits.h Hexagon (linux-user/hexagon) Linux user emulation 2021-02-18 07:48:22 -08:00