Re: [PATCH 0/6] x86: 32-bit compatible C/R on x86_64

From: Dmitry Safonov
Date: Wed Jun 01 2016 - 09:16:44 EST

On 06/01/2016 04:11 PM, Dmitry Safonov wrote:
This patches set is an attempt to add checkpoint/restore
for 32-bit tasks in compatibility mode on x86_64 hosts.

Restore in CRIU starts from one root restoring process, which
reads info for all threads being restored from images files.
This information is used further to to find out which processes
share some resources. Later shared resources are restored only
by one process and all other inherit them.
After that it calls clone() and new threads restore their
properties in parallel. Those threads inherit all parent's
mappings and fetch properties from those mappings
(and do clone themself, if they have children/subthreads). [1]
Then starts restorer blob's play, it's PIE binary, which
unmaps all unneeded for restoring VMAs, maps new VMAs and
finalize restoring with sigreturn syscall. [2]

To restore of 32-bit task we need three things to do in running
x86_64 restorer blob:
a) set code selector to __USER32_CS (to run 32-bit code);
b) remap vdso blob from 64-bit to 32-bit
This is primary needed because restore may happen on a different
kernel, which has different vDSO image than we had on dump.
c) if 32-bit vDSO differ to dumped image, move it on free place
and add jump trampolines to that place.
d) switch TIF_IA32 flag, so kernel would know that it deals with
compatible 32-bit application.

From all this:
a) setting CS may be done from userspace, no patches needed;
b) patches 1-3 add ability to map different vDSO blobs on x86 kernel;
c) for remapping/moving 32-bit vDSO blob patches have been send earlier
and seems to be accepted [3]
d) and for swapping TIF_IA32 flag discussion with Andy ended in conclusion
that it's better to remove this flag completely.
Patches 4-6 deletes usage of TIF_IA32 from ptrace, signal and coredump
code. This is rework/resend of RFC [4]


Dmitry Safonov (6):
x86/vdso: unmap vdso blob on vvar mapping failure
x86/vdso: introduce do_map_vdso() and vdso_type enum
x86/arch_prctl/vdso: add ARCH_MAP_VDSO_*
x86/coredump: use core regs, rather that TIF_IA32 flag
x86/ptrace: down with test_thread_flag(TIF_IA32)
x86/signal: add SA_{X32,IA32}_ABI sa_flags

Oh, forgot to mention: this patches set is based on [3],
so kernel build bot may be not happy about applying them.
Anyway, I hope for the next revisions, the base-patches
will be applied to linux-next and build-bot will test them
just fine.

arch/x86/entry/vdso/vma.c | 72 +++++++++++++++++++++-----------------
arch/x86/ia32/ia32_signal.c | 2 +-
arch/x86/include/asm/compat.h | 8 ++---
arch/x86/include/asm/fpu/signal.h | 6 ++++
arch/x86/include/asm/vdso.h | 4 +++
arch/x86/include/uapi/asm/prctl.h | 6 ++++
arch/x86/include/uapi/asm/signal.h | 6 +++-
arch/x86/kernel/process_64.c | 10 ++++++
arch/x86/kernel/ptrace.c | 2 +-
arch/x86/kernel/signal.c | 19 +++++-----
arch/x86/kernel/signal_compat.c | 30 ++++++++++++++--
fs/binfmt_elf.c | 18 +++++-----
kernel/signal.c | 5 +++
13 files changed, 129 insertions(+), 59 deletions(-)

Dmitry Safonov