[PATCH 0/2] x86: add arch_prctl to switch between native/compat modes

From: Dmitry Safonov
Date: Wed Apr 06 2016 - 12:45:14 EST


With those patches it becomes possible to tell the kernel in which mode
current task is.
I need it for compatibility process C/R:
restorer is native x86_64 process, that maps vmas, restore task parameters,
does clone to add threads and so on. To restore 32-bit application, that
runs on x86_64 (in compatibility mode), I need to set proper CS selector
for USER32_CS and tell the kernel, that the process is now in compat mode.
Switching selector isn't a hard task (and it's done in other selftests
with long jump/lret).
This patch makes possible to tell Linux kernel in which mode you are.

I also did vdso/vvar blob remapping on compat <-> native switch.
This part isn't really needed by CRIU, as on restore stage we already
have dumped vdso/vvar vma images.
So, this part is for other processes that may need to switch their mode.
(I will drop this part if no one else needs this possibility).

I add a selftest and I did CRIU branch that uses this to C/R 32-bit processes:
https://github.com/0x7f454c46/criu/tree/compat-2
There are dozens of patches there and I will prepare them for CRIU master
branch after mainstreaming this switching patch.

Dmitry Safonov (2):
x86/arch_prctl: add ARCH_SET_{COMPAT,NATIVE} to change compatible mode
x86/tools/testing: add test for ARCH_SET_COMPAT

arch/x86/entry/vdso/vma.c | 76 ++++--
arch/x86/include/asm/vdso.h | 5 +
arch/x86/include/uapi/asm/prctl.h | 6 +
arch/x86/kernel/process_64.c | 87 ++++++
tools/testing/selftests/x86/Makefile | 1 +
.../testing/selftests/x86/arch_prctl_set_compat.c | 295 +++++++++++++++++++++
6 files changed, 453 insertions(+), 17 deletions(-)
create mode 100644 tools/testing/selftests/x86/arch_prctl_set_compat.c

--
2.7.4