[PATCH v1 0/4] selftests/x86: Improve signal test code

From: Chang S. Bae
Date: Mon Apr 03 2023 - 00:55:43 EST


Hi all,

This is a cleanup series to consolidate a common signal setup code.
Right now quite a bit of duplicated code is there in an unorganized
way. Here is a rework of that signal-related code:

(1) Consolidate the signal handler helpers

They have been exactly copied everywhere. Place them in the shared
code. Then, remove those duplicates.

(2) Simplify altstack code

Most cases require just a usable alternate stack. So, there is a
chance to simplify them all. Abstract the entire setup code to one
setup call. Then, it can reduce the amount of code there.

For testing sigaltstack() specifically, another helper is provided
that excludes the syscall part.

The series also includes some preparatory changes for them:

* Along with the rework, some existing problem was uncovered. A couple
of tests look to free the altstack memory even before the signal
delivery. Adjust the memory cleanup to resolve this issue.

* Also resolve a define conflict separately before including the
refactored header.

Then, there is another selftest fix that I posted:
https://lore.kernel.org/lkml/20230330233520.21937-1-chang.seok.bae@xxxxxxxxx/
which has a conflict with this. As the fix should go first, this
cleanup series is based on it.

FWIW, at the moment, the new x86 selftest cases -- lam and
test_shadow_stack do not conflict with this.

Here is the repository where this series can be found:
git://github.com/intel/amx-linux.git selftest-signal

Thanks,
Chang

Chang S. Bae (4):
selftests/x86: Fix the altstack free
selftests/x86/mov_ss_trap: Include processor-flags.h
selftests/x86: Consolidate signal handler helpers
selftests/x86: Refactor altstack setup code

tools/testing/selftests/x86/Makefile | 16 ++-
tools/testing/selftests/x86/amx.c | 67 +++--------
.../selftests/x86/corrupt_xstate_header.c | 15 +--
tools/testing/selftests/x86/entry_from_vm86.c | 25 +---
tools/testing/selftests/x86/fsgsbase.c | 25 +---
tools/testing/selftests/x86/helpers.c | 110 ++++++++++++++++++
tools/testing/selftests/x86/helpers.h | 10 ++
tools/testing/selftests/x86/ioperm.c | 26 +----
tools/testing/selftests/x86/iopl.c | 26 +----
tools/testing/selftests/x86/ldt_gdt.c | 19 +--
tools/testing/selftests/x86/mov_ss_trap.c | 26 +----
tools/testing/selftests/x86/ptrace_syscall.c | 24 +---
tools/testing/selftests/x86/sigaltstack.c | 67 +++--------
tools/testing/selftests/x86/sigreturn.c | 35 +-----
.../selftests/x86/single_step_syscall.c | 36 +-----
.../testing/selftests/x86/syscall_arg_fault.c | 24 +---
tools/testing/selftests/x86/syscall_nt.c | 13 ---
tools/testing/selftests/x86/sysret_rip.c | 24 +---
tools/testing/selftests/x86/test_vsyscall.c | 13 ---
tools/testing/selftests/x86/unwind_vdso.c | 13 ---
20 files changed, 205 insertions(+), 409 deletions(-)
create mode 100644 tools/testing/selftests/x86/helpers.c

--
2.17.1