Fixes alignment of xsave area in kernel_fpstate_t. The kernel requires it to be 64-byte aligned. Currently, we aligned the fpstate object itself, instead of the xsave area in it.
Without this, rt_sigreturn and sigreturn crash on x86 32-bit affecting all signal tests. With this fix, many signal tests work again, including linux.signalxxxx, linux.sigplainxxxx, linux.sigcontext, linux.signal_race. linux.alarm, linux.bad-signal-stack, linux.sigsuspend, linux.signest and a few others on Ubuntu 20.04.
Some others (linux.syscall_pwait, client.signal) now show a timeout, and client.events an assert failure. Those fixes will come later.
Issue: #5079, #4953 (closed)
Activity
requested review from @derekbruening
With the other fixes in place and this one, I see the following remaining failures in the CI run at e502a609.
2021-09-17T02:56:49.4933893Z ====> FAILURE in debug-internal-32 <==== 2021-09-17T02:56:49.4935042Z debug-internal-32: 337 tests passed, **** 14 tests failed, of which 4 were flaky, but ignoring 1 for i#2941: **** 2021-09-17T02:56:49.4936096Z (ignore: i#2941) code_api|linux.thread-reset 2021-09-17T02:56:49.4936726Z code_api|linux.syscall_pwait 2021-09-17T02:56:49.4937456Z code_api|linux.clone-reset 2021-09-17T02:56:49.4938025Z code_api|client.events 2021-09-17T02:56:49.4938574Z code_api|client.events_cpp 2021-09-17T02:56:49.4939321Z code_api|linux.persist-use_FLAKY 2021-09-17T02:56:49.4940089Z code_api|client.pcache-use 2021-09-17T02:56:49.4941550Z code_api|client.signal 2021-09-17T02:56:49.4942492Z code_api|tool.drcpusim.cpuid-Klamath 2021-09-17T02:56:49.4943536Z code_api|tool.drcpusim.cpuid-Deschutes 2021-09-17T02:56:49.4944347Z code_api|tool.histogram.offline 2021-09-17T02:56:49.4945006Z code_api|api.detach_spawn_stress_FLAKY 2021-09-17T02:56:49.4945630Z code_api|api.static_maps_mixup_novars_FLAKY 2021-09-17T02:56:49.4946258Z code_api|api.static_sideline_FLAKY 2021-09-17T02:56:49.4947203Z release-external-32: build successful; no tests for this build
3178 3178 memcpy(&f_new->sc, get_sigcontext_from_rt_frame(f_old), sizeof(sigcontext_t)); 3179 3179 if (sc_old->fpstate != NULL) { 3180 3180 /* up to caller to include enough space for fpstate at end */ 3181 uint offset_fpstate_xsave = offsetof(kernel_fpstate_t, _fxsr_env); 3182 /* i#5079: The kernel requires the xsave area to be 64-byte aligned, which 3183 * starts at _fxsr_env in kernel_fpstate_t. Please add a comment to _fxsr_env in sigcontext.h. I see from the comments there that we added the prior fields to the struct ourselves (the kernel treated those separately), which makes it seem a little better here: it's only DR who has this strange internal field alignment. Please add to those prepended-field comments too that adding them forces us to align the combined struct for an internal field here.
I added the comment in the definition of
_kernel_fpstate_t
.Note that the kernel also has the same prepended fields in
_fpstate_32
: https://elixir.bootlin.com/linux/v5.10.40/source/arch/x86/include/uapi/asm/sigcontext.h#L121, though it has a separate struct for those fields in addition (fregs_state). It also manually computes the_fxsr_env
address (https://elixir.bootlin.com/linux/v5.10.40/source/arch/x86/kernel/fpu/signal.c#L487) which lies inside_fpstate_32
, for the later alignment check (https://elixir.bootlin.com/linux/v5.10.40/source/arch/x86/kernel/fpu/signal.c#L335).