c/r: 32-bit support on x86-64
The first patch is a resend from friday, and should be applied to v19. The second patch I think should be applied to v19 as well, as it will prevent accidental attempts to restart a 64-bit image with a 32-bit restart, and vice versa.
The third patch I think does things which need to be done, but it doesn't yet get 32-bit restart on x86-64 fully working. In particular, I always get a segfault in VDSO in __kernel_vsyscall(). What is odd is that the registers seem right, the segfault is at the right address, and gdb shows that the right instructions are at the faulting address - so the reason for the segfault is still a complete mystery to me.
A message that is not in the archive (sent off-list or not yet received): 1264470494-14049-1-git-send-email-serue-r/[email protected]
PATCH 1/4 x86-32 and ia32 eclone, checkpoint, restart fixes
From: Serge E. Hallyn <serue-r/[email protected]>
Eclone on x86-32 should use esi for 4th arg (upids), not edi, which is 5th arg. This will require a corresponding fix to user-cr, but (a) it's correct and (b) it's required so that IA32_ARG_FIXUP can put upids in the right register for process_64.c:sys_eclone(). IA32_ARG_FIXUP will (of course) put edi into r8, the 5th arg.
Add the ptregs_syscall stubs for eclone, checkpoint, and restart for 32-bit api on x86-64.
With this patch (and proper user-cr), checkpoint and eclone work on x86-32, x86-64, and in 32-bit mode on x86-64. (restart has not yet been tested)
--- arch/x86/ia32/ia32entry.S | 11 +++++++++++ arch/x86/kernel/process_32.c | 2 +- 2 files changed, 12 insertions(+), 1 deletions(-)
arch/x86/ia32/ia32entry.S +11 -0
@@ -477,6 +477,14 @@ quiet_ni_syscall: PTREGSCALL stub32_clone, sys32_clone, %rdx PTREGSCALL stub32_vfork, sys_vfork, %rdi PTREGSCALL stub32_iopl, sys_iopl, %rsi + PTREGSCALL stub32_eclone, sys_eclone, %r8 +#ifdef CONFIG_CHECKPOINT + PTREGSCALL stub32_checkpoint, sys_checkpoint, %r8 + PTREGSCALL stub32_restart, sys_restart, %r8 +#else + PTREGSCALL stub32_checkpoint, sys_ni_syscall, %r8 + PTREGSCALL stub32_restart, sys_ni_syscall, %r8 +#endif ENTRY(ia32_ptregs_common) popq %r11
@@ -841,4 +849,7 @@ ia32_sys_call_table: .quad compat_sys_pwritev .quad compat_sys_rt_tgsigqueueinfo /* 335 */ .quad sys_perf_event_open + .quad stub32_eclone + .quad stub32_checkpoint + .quad stub32_restart ia32_syscall_end:
arch/x86/kernel/process_32.c +1 -1
@@ -455,7 +455,7 @@ int sys_eclone(struct pt_regs *regs) flags_low = regs->bx; uca = (struct clone_args __user *)regs->cx; args_size = regs->dx; - pids = (pid_t __user *)regs->di; + pids = (pid_t __user *)regs->si;return do_eclone_common (regs, flags_low, uca, args_size, pids); }
Signature · 1 line
1.6.0.6
PATCH 2/4 restart only same bit-ness
In reply to a message not in the archiveFrom: Serge E. Hallyn <serue-r/[email protected]>
I'm hoping to get restart of 32-bit tasks on x86-64 working for v19, but restart of 32-bit tasks using a 64-bit restart program I'm not going to even try right now. Rather than get a completely uncommented '-22' return value from restore_cpu() or do_munmap(), catch it early enough to give a meaningful error in the logfile.
--- arch/x86/kernel/checkpoint.c | 21 ++++++++++++++++----- 1 files changed, 16 insertions(+), 5 deletions(-)
arch/x86/kernel/checkpoint.c +16 -5
@@ -272,11 +272,22 @@ int restore_thread(struct ckpt_ctx *ctx)load_TLS (thread, cpu);put_cpu (); -#if defined(CONFIG_X86_64 ) && defined(CONFIG_COMPAT ) -if (h->thread_info_flags & _TIF_IA32) -set_thread_flag (TIF_IA32 ); -else -clear_thread_flag (TIF_IA32 ); +#if defined(CONFIG_X86_64 ) + { +int pre, post; +/* +* Eventually we'd like to support mixed-bit restart, but for +* now don't pretend to. +*/ + pre =test_thread_flag (TIF_IA32 ); + post = h->thread_info_flags & _TIF_IA32; +if ((pre && !post) || (post && !pre)) { + ret = -EINVAL ; +ckpt_err (ctx, ret,"%d-bit restarting %d-bit\n" , + pre ?32 :64 , post ?32 :64 ); + goto out; + } + }#endif /* TODO: restore TIF flags as necessary (e.g. TIF_NOTSC) */
Signature · 1 line
1.6.0.6
PATCH 3/4 x86_64: make some changes to fs/gs register handling
In reply to a message not in the archiveFrom: Serge E. Hallyn <serue-r/[email protected]>
1. always save/restore fs/gs
not just if CONFIG_COMPAT and the task is 64-bit. Pretty sure that block wasn't doing what it wanted to do anyway :)
2. use rdmsrl for fs/gs for self-checkpoint
<shrug> other code seems to do it. It doesn't seem to make a difference one way or the other.
3. null out fs/gs if index is set
like __switch_to() does
4. fs and gs are not encoded segments, so don't run them through check_segment().
--- arch/x86/kernel/checkpoint_64.c | 32 ++++++++++++++++---------------- 1 files changed, 16 insertions(+), 16 deletions(-)
arch/x86/kernel/checkpoint_64.c +16 -16
@@ -162,21 +162,26 @@ void save_cpu_regs(struct ckpt_hdr_cpu *h, struct task_struct *t)savesegment (es, _es);savesegment (fs, _fs);savesegment (gs, _gs); +rdmsrl (MSR_FS_BASE , h->fs); +rdmsrl (MSR_KERNEL_GS_BASE , h->gs); }else { _ds = t->thread.ds; _es = t->thread.es; _fs = t->thread.fsindex; _gs = t->thread.gsindex; + h->fs = t->thread.fs; + h->gs = t->thread.gs; } h->ds =encode_segment (_ds); h->es =encode_segment (_es); h->fsindex =encode_segment (_fs); h->gsindex =encode_segment (_gs); -if (!test_tsk_thread_flag (t,TIF_IA32 )) { - h->fs = t->thread.fs; - h->gs = t->thread.gs; - } +/* see comment in __switch_to() */ +if (_fs) + h->fs =0 ; +if (_gs) + h->gs =0 ;/* * for checkpoint in process context (from within a container),
@@ -203,12 +208,6 @@ int load_cpu_regs(struct ckpt_hdr_cpu *h, struct task_struct *t) !check_segment(h->fsindex) || !check_segment(h->gsindex))return -EINVAL ; -#ifdef CONFIG_COMPAT -if (test_tsk_thread_flag (t,TIF_IA32 ) && - (!check_segment (h->fs) || !check_segment (h->gs))) -return -EINVAL ; -#endif - regs->r15 = h->r15; regs->r14 = h->r14; regs->r13 = h->r13;
@@ -240,18 +239,19 @@ int load_cpu_regs(struct ckpt_hdr_cpu *h, struct task_struct *t) thread->fsindex =decode_segment (h->fsindex); thread->gsindex =decode_segment (h->gsindex); -#ifdef CONFIG_COMPAT -if (!test_tsk_thread_flag (t,TIF_IA32 )) { - thread->fs = h->fs; - thread->gs = h->gs; - } -#endif + thread->fs = h->fs; + thread->gs = h->gs;/* XXX - unsure is this really needed ... */ loadsegment (fs, thread->fsindex);if (thread->fs)wrmsrl (MSR_FS_BASE , thread->fs);load_gs_index (thread->gsindex); +/* +* when we switch to user-space, the MSR_KERNEL_GS_BASE +* will be moved back to MSR_GS_BASE. +* http://lists.openwall.net/linux-kernel/2008/11/18/340 +*/ if (thread->gs)wrmsrl (MSR_KERNEL_GS_BASE , thread->gs);
Signature · 1 line
1.6.0.6
Oren Laadan
AppliedApplied, thanks.
Quoted 15 lines · serue-r/[email protected] wrote:
The first patch is a resend from friday, and should be applied to v19. The second patch I think should be applied to v19 as well, as it will prevent accidental attempts to restart a 64-bit image with a 32-bit restart, and vice versa.
The third patch I think does things which need to be done, but it doesn't yet get 32-bit restart on x86-64 fully working. In particular, I always get a segfault in VDSO in
__kernel_vsyscall(). What is odd is that the registers seem right, the segfault is at the right address, and gdb shows that the right instructions are at the faulting address - so the reason for the segfault is still a complete mystery to me.