implement s390 eclone syscall
PATCH 1/1 implement s390 eclone syscall
From: Serge E. Hallyn <serue-r/[email protected]>
This patch implements the s390 hook for sys_eclone.
The user-space clone-with-pids glue for s390 (clone_s390x.c from the user-cr package) is now:
struct pid_set {
int num_pids;
pid_t *pids;
}; #define do_eclone(flags, pids, args, sz) \
( { \
register unsigned long int __r1 asm ("1") = (unsigned long int)(__NR_eclone); \
register unsigned long int __r2 asm ("2") = (unsigned long int)(flags); \
register unsigned long int __r3 asm ("3") = (unsigned long int)(args); \
register unsigned long int __r4 asm ("4") = (unsigned long int)(sz); \
register unsigned long int __r5 asm ("5") = (unsigned long int)(pids); \
register long int __result asm ("2"); \
__asm__ __volatile__( \
" svc 0\n" /* do __NR_eclone syscall */ \
" ltgr %%r2,%%r2\n" /* returned 0? */ \
" jnz 1f\n" /* if not goto label 1 */ \
" lg %%r3,0(%%r15)\n" /* get fnarg off stack into arg 1 */ \
" lg %%r2,8(%%r15)\n" /* get fn off stack int r3 basr*/ \
" lgr %%r1,%%r15\n" /* tmp store old stack pointer */ \
" aghi %%r15,-160\n" /* move the stack */ \
" stg %%r1,0(%%r15)\n" /* and save old stack pointer */ \
" basr %%r14,%%r3\n" /* call fn(arg) */ \
" svc 1\n" /* call exit */ \
" 1:\n" \
: "=d" (__result) \
: "d" (__r1), "0" (__r2), "d" (__r3), "d" (__r4), "d" (__r5) \
: "memory"); \
__result; \
} )
int clone_with_pids(int (*fn)(void *), void *child_stack, int flags,
struct pid_set *target_pids, void *arg)
{
struct clone_args clone_args, *ca = &clone_args;
u64 *s;
memset(ca, 0, sizeof(struct clone_args));
ca->nr_pids = target_pids->num_pids;
if (!child_stack) {
/* we could pass in null and then in eclone not
* call exit if child_stack was null, but we'll
* just malloc here */
int sz = 4*getpagesize();
child_stack = malloc(sz);
if (!child_stack)
return -ENOMEM;
child_stack += sz; /* we'll decrement before assigning */
}
ca->child_stack = (u64) child_stack;
s = (u64 *) ca->child_stack;
*--s = (u64) arg;
*--s = (u64) fn;
ca->child_stack -= 16;
return do_eclone(flags, target_pids->pids, ca,
sizeof(struct clone_args));
}Changelog:
Nov 12: switch to latest (Nov 12) eclone format Nov 10: use orig_gpr2, not gprs[2] for input arg 1
--- arch/s390/include/asm/unistd.h | 3 +- arch/s390/kernel/compat_linux.c | 47 ++++++++++++++++++++++++++++++++++++++ arch/s390/kernel/process.c | 48 +++++++++++++++++++++++++++++++++++++++ arch/s390/kernel/syscalls.S | 1 + 4 files changed, 98 insertions(+), 1 deletions(-)
arch/s390/include/asm/unistd.h +2 -1
@@ -269,7 +269,8 @@#define __NR_pwritev 329#define __NR_rt_tgsigqueueinfo 330#define __NR_perf_event_open 331 -#define NR_syscalls 332 +#define __NR_eclone 332 +#define NR_syscalls 333/* * There are some system calls that are not present on 64 bit, some
arch/s390/kernel/compat_linux.c +47 -0
53 lines not on this page · raw message
arch/s390/kernel/process.c +48 -0
54 lines not on this page · raw message
arch/s390/kernel/syscalls.S +1 -0
@@ -340,3 +340,4 @@ SYSCALL(sys_preadv,sys_preadv,compat_sys_preadv_wrapper) SYSCALL(sys_pwritev,sys_pwritev,compat_sys_pwritev_wrapper) SYSCALL(sys_rt_tgsigqueueinfo,sys_rt_tgsigqueueinfo,compat_sys_rt_tgsigqueueinfo_wrapper) /* 330 */ SYSCALL(sys_perf_event_open,sys_perf_event_open,sys_perf_event_open_wrapper) +SYSCALL(sys_eclone,sys_eclone,sys_eclone_wrapper)
Signature · 1 line
1.6.1
A message that is not in the archive (sent off-list or not yet received): 1258089886-10034-1-git-send-email-serue-r/[email protected]
PATCH 1/2 use v13 of eclone in clone_s390x.c
From: Serge E. Hallyn <serue-r/[email protected]>
--- clone_s390x.c | 100 ++++++++++++++++++++++++++++++++++++++------------------ 1 files changed, 68 insertions(+), 32 deletions(-)
clone_s390x.c +68 -32
@@ -13,17 +13,20 @@#define _GNU_SOURCE#include <unistd.h> +#include <string.h> +#include <malloc.h> #include <errno.h> #include <sys/types.h> #include <sys/syscall.h> #include <asm/unistd.h> +#define __NR_eclone 332/* -* libc doesn't support clone_with_pid() yet... +* libc doesn't support eclone() yet... * below is arch-dependent code to use the syscall */ #include <linux/checkpoint.h> -#if defined(__NR_clone_with_pids) +#if defined(__NR_eclone)/* this really belongs to some kernel header ! */ struct pid_set {
@@ -31,42 +34,75 @@ struct pid_set {pid_t *pids; }; -/* (see: http://lkml.indiana.edu/hypermail/linux/kernel/9604.3/0204.html) */ +typedef unsigned long long u64 ; +typedef unsigned int u32 ; +typedef int pid_t ; +struct clone_args { +u64 clone_flags_high; +u64 child_stack; +u64 child_stack_size; +u64 parent_tid_ptr; +u64 child_tid_ptr; -#define do_clone_with_pids (stack, flags, ptid, ctid, setp) ({ \ - register unsigned long int __r2 asm ("2") = (unsigned long int)(stack);\ - register unsigned long int __r3 asm ("3") = (unsigned long int)(flags);\ - register unsigned long int __r4 asm ("4") = (unsigned long int)(ptid); \ - register unsigned long int __r5 asm ("5") = (unsigned long int)(ctid); \ - register unsigned long int __r6 asm ("6") = (unsigned long int)(NULL); \ - register unsigned long int __r7 asm ("7") = (unsigned long int)(setp); \ - register unsigned long int __result asm ("2"); \ - __asm__ __volatile__( \ - " lghi %%r1,%7\n" \ - " svc 0\n" \ - : "=d" (__result) \ - : "0" (__r2), "d" (__r3), \ - "d" (__r4), "d" (__r5), "d" (__r6), "d" (__r7), \ - "i" (__NR_clone_with_pids) \ - : "1", "cc", "memory" \ - ); \ - __result; \ - }) +u32 nr_pids; + +u32 reserved0; +u64 reserved1; +}; + +#define do_eclone (flags, pids, args, sz) \ +( { \ + register unsigned long int __r1 asm ("1") = (unsigned long int)(__NR_eclone); \ + register unsigned long int __r2 asm ("2") = (unsigned long int)(flags); \ + register unsigned long int __r3 asm ("3") = (unsigned long int)(args); \ + register unsigned long int __r4 asm ("4") = (unsigned long int)(sz); \ + register unsigned long int __r5 asm ("5") = (unsigned long int)(pids); \ + register long int __result asm ("2"); \ + __asm__ __volatile__( \ + " svc 0\n"/* do __NR_eclone syscall */ \ + " ltgr %%r2,%%r2\n" /* returned 0? */ \ + " jnz 1f\n" /* if not goto label 1 */ \ + " lg %%r3,0(%%r15)\n" /* get fnarg off stack into arg 1 */ \ + " lg %%r2,8(%%r15)\n" /* get fn off stack int r3 basr*/ \ + " lgr %%r1,%%r15\n" /* tmp store old stack pointer */ \ + " aghi %%r15,-160\n" /* move the stack */ \ + " stg %%r1,0(%%r15)\n" /* and save old stack pointer */ \ + " basr %%r14,%%r3\n" /* call fn(arg) */ \ + " svc 1\n" /* call exit */ \ + " 1:\n" \ + : "=d" (__result) \ + : "d" (__r1), "0" (__r2), "d" (__r3), "d" (__r4), "d" (__r5) \ +: " memory"); \ +__result; \ +} ) + int clone_with_pids(int (*fn)(void *), void *child_stack, int flags, struct pid_set *target_pids, void *arg) { -long retval; - retval =do_clone_with_pids (child_stack, flags,NULL ,NULL , - target_pids); +struct clone_args clone_args, *ca = &clone_args; +u64 *s; + +memset (ca,0 ,sizeof (struct clone_args )); + ca->nr_pids = target_pids->num_pids; +if (!child_stack) { +/* we could pass in null and then in eclone not +* call exit if child_stack was null, but we'll +* just malloc here */ +int sz =4 *getpagesize (); + child_stack =malloc (sz); +if (!child_stack) +return -ENOMEM ; + child_stack += sz;/* we'll decrement before assigning */ + } + ca->child_stack = (u64 ) child_stack; + s = (u64 *) ca->child_stack; + *--s = (u64 ) arg; + *--s = (u64 ) fn; + ca->child_stack -=16 ; -if (retval <0 ) { - errno = -retval; -return -1 ; - }else if (retval ==0 ) { -return fn (arg); - }else -return retval; +return do_eclone (flags, target_pids->pids, ca, +sizeof (struct clone_args )); }#endif /* !defined(__NR_clone_with_pids) */
Signature · 1 line
1.6.1.1
PATCH 2/2 add nsexeccwp to test clone-with-pids
In reply to a message not in the archiveFrom: Serge E. Hallyn <serue-r/[email protected]>
One of the concerns with clone-with-pids is whether the stack handling is all correct and robust enough to withstand real usage. Little testcases playing with pid values are also necessary, but can't replace really using clone-with-pids to start a shell from which to keep working.
This patch tweaks the old ns_exec.c namespace manipulation program to add a -z option to specify a pid. So you can:
nsexeccwp -cmp /bin/bash # start a shell in a new pidns+mntns mount -t proc proc /proc # mount private /proc echo $$ 1 nsexeccwp -z /bin/bash # start a shell with pid 999 echo $$ 999
--- Makefile | 5 +- clone.h | 54 +++++++++ nsexeccwp.c | 352 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 410 insertions(+), 1 deletions(-) create mode 100644 clone.h create mode 100644 nsexeccwp.c
Makefile +4 -1
@@ -20,7 +20,7 @@ CFLAGS += -g $(WARNS) $(CKPT_INCLUDE) $(DEBUG) # install dir INSTALL_DIR = /bin -PROGS = checkpoint restart ckptinfo +PROGS = checkpoint restart ckptinfo nsexeccwp # other cleanup OTHER = ckptinfo_types.c
@@ -39,11 +39,14 @@ restart: CFLAGS += -D__REENTRANT -pthread ifneq ($(SUBARCH),) restart: clone_$(SUBARCH).o restart: CFLAGS += -DARCH_HAS_CLONE_WITH_PID +nsexeccwp: clone_$(SUBARCH).o +nsexeccwp: CFLAGS += -DARCH_HAS_CLONE_WITH_PID endif # on powerpc, need also assembly file ifeq ($(SUBARCH),ppc) restart: clone_$(SUBARCH)_.o +nsexeccwp: clone_$(SUBARCH)_.o endif # ckptinfo dependencies
clone.h new file +54 -0
54 lines not on this page · raw message
nsexeccwp.c new file +352 -0
352 lines not on this page · raw message
Signature · 1 line
1.6.1.1
A message that is not in the archive (sent off-list or not yet received): 1258089886-10034-3-git-send-email-serue-r/[email protected]
Re: [PATCH user-cr 2/2] add nsexeccwp to test clone-with-pids
Quoting serue-r/[email protected] (serue-r/[email protected]):
...
nsexeccwp.c line 317
Quoted 6 lines
nsexeccwp.c new file +6
-0+ pid =clone_with_pids (do_child, stack, flags, &pid_set, + (void *)argv); +if (pid ==-1 ) { +perror ("clone" ); +return -1 ; + }
Come on Serge, what crapppy code! The clone_with_pids() wrapper used in user-cr doesn't set errno, so this is messed up on failure. Shape up!
-serge
Re: [PATCH user-cr 2/2] add nsexeccwp to test clone-with-pids
In reply to a message not in the archiveQuoted 5 lines · On Thu, 2009-11-12 at 23:24 -0600, serue-r/[email protected]…
nsexeccwp.c new file +5
-0+if (use_clone) { +int stacksize =4 *getpagesize (); +void *stack =malloc (stacksize); + +if (!stack) {
nsexeccwp.c line 313
Quoted 10 lines
nsexeccwp.c new file +10
-0+perror ("malloc" ); +return -1 ; + } + +printf ("about to clone with %lx\n" , flags); +if (chosen_pid) +printf ("Will choose pid %d\n" , chosen_pid); + flags |=SIGCHLD ; + pid =clone_with_pids (do_child, stack, flags, &pid_set, + (void *)argv);
The stack argument should be adjusted with the usual stack += stacksize
- 1 or similar, right?
A message that is not in the archive (sent off-list or not yet received): 1258325156.4031.3.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/[email protected]
Re: [PATCH user-cr 2/2] add nsexeccwp to test clone-with-pids
Quoted 11 lines · Nathan Lynch
Quoted 10 lines · On Thu, 2009-11-12 at 23:24 -0600, serue-r/[email protected]…
nsexeccwp.c new file +10
-0+if (use_clone) { +int stacksize =4 *getpagesize (); +void *stack =malloc (stacksize); + +if (!stack) { +perror ("malloc" ); +return -1 ; + } + +printf ("about to clone with %lx\n" , flags);
Quoted 8 lines
nsexeccwp.c line 313
Quoted 5 lines
nsexeccwp.c new file +5
-0+if (chosen_pid) +printf ("Will choose pid %d\n" , chosen_pid); + flags |=SIGCHLD ; + pid =clone_with_pids (do_child, stack, flags, &pid_set, + (void *)argv);The stack argument should be adjusted with the usual stack += stacksize
- 1 or similar, right?
the clone_with_pids() helper in user-cr/clone_s390x.c (and IIRC the x86 one by Suka also) does this implicitly, by doing:
s = child_stack; *--s = arg; *--s = fn; child_stack -= 16
-serge
A message that is not in the archive (sent off-list or not yet received): 20091116111249.GA32340-r/[email protected]
Re: [PATCH user-cr 2/2] add nsexeccwp to test clone-with-pids
Quoted 21 lines · Serge E. Hallyn
Quoted 11 lines · Nathan Lynch
Quoted 10 lines · On Thu, 2009-11-12 at 23:24 -0600, serue-r/[email protected]…
(quoted diff) +10
-0+ if (use_clone) { + int stacksize = 4*getpagesize(); + void *stack = malloc(stacksize); + + if (!stack) { + perror("malloc"); + return -1; + } + + printf("about to clone with %lx\n", flags);Quoted 8 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+ if (chosen_pid) + printf("Will choose pid %d\n", chosen_pid); + flags |= SIGCHLD; + pid = clone_with_pids(do_child, stack, flags, &pid_set, + (void *)argv);The stack argument should be adjusted with the usual stack += stacksize
- 1 or similar, right?
Quoted 7 lines
the
clone_with_pids()helper inuser-cr/clone_s390x.c(and IIRC the x86 one by Suka also) does this implicitly, by doing:s = child_stack; *--s = arg; *--s = fn; child_stack -= 16
That's setting up arguments for the function to run in the child, and afaict that code assumes the value of child_stack is the _end_ of the stack region. The code I quoted above is passing the beginning of the region (the return value from malloc).
On powerpc the segfaults went away when I made the following change.
nsexeccwp.c +2 -2
@@ -309,8 +309,8 @@ int main(int argc, char *argv[])if (chosen_pid)printf ("Will choose pid %d\n" , chosen_pid); flags |=SIGCHLD ; - pid =clone_with_pids (do_child, stack, flags, &pid_set, - (void *)argv); + pid =clone_with_pids (do_child, stack + stacksize -1 , + flags, &pid_set, (void *)argv);
A message that is not in the archive (sent off-list or not yet received): 1258328984.4031.21.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/[email protected]
Re: [PATCH user-cr 2/2] add nsexeccwp to test clone-with-pids
Quoted 25 lines · Nathan Lynch
Quoted 24 lines · Serge E. Hallyn
Quoted 11 lines · Nathan Lynch
Quoted 10 lines · On Thu, 2009-11-12 at 23:24 -0600, serue-r/[email protected]…
(quoted diff) +10
-0+ if (use_clone) { + int stacksize = 4*getpagesize(); + void *stack = malloc(stacksize); + + if (!stack) { + perror("malloc"); + return -1; + } + + printf("about to clone with %lx\n", flags);Quoted 8 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+ if (chosen_pid) + printf("Will choose pid %d\n", chosen_pid); + flags |= SIGCHLD; + pid = clone_with_pids(do_child, stack, flags, &pid_set, + (void *)argv);The stack argument should be adjusted with the usual stack += stacksize
- 1 or similar, right?the
clone_with_pids()helper inuser-cr/clone_s390x.c(and IIRC the x86 one by Suka also) does this implicitly, by doing:
Quoted 8 lines
Quoted 4 lines
s = child_stack; *--s = arg; *--s = fn; child_stack -= 16That's setting up arguments for the function to run in the child, and afaict that code assumes the value of
child_stackis the _end_ of the stack region.
Yes.
Quoted 2 lines
The code I quoted above is passing the beginning of the region (the return value from malloc).
Holy cow, that was a snafu in my switching to sending (stack_base,stack_size) for the previous version, and then back again. It was meant to send stack_base+stack_size now.
I say 'holy cow' because it doesn't segfault on s390x. And it certainly should!
Quoted 7 lines
On powerpc the segfaults went away when I made the following change.
nsexeccwp.c +0
-0
nsexeccwp.c int main(int argc, char *argv[]) · line 313
Quoted 7 lines
nsexeccwp.c +2
-2@@ -309,8 +309,8 @@ int main(int argc, char *argv[])if (chosen_pid)printf ("Will choose pid %d\n" , chosen_pid); flags |=SIGCHLD ; - pid =clone_with_pids (do_child, stack, flags, &pid_set, - (void *)argv); + pid =clone_with_pids (do_child, stack + stacksize -1 , + flags, &pid_set, (void *)argv);
Yes I don't think the -1 should be needed, but certainly the +stacksize is.
thanks,
-serge
A message that is not in the archive (sent off-list or not yet received): 20091116182655.GA3777-r/[email protected]
Re: [PATCH user-cr 2/2] add nsexeccwp to test clone-with-pids
Quoted 35 lines · Serge E. Hallyn
Quoted 25 lines · Nathan Lynch
Quoted 24 lines · Serge E. Hallyn
Quoted 11 lines · Nathan Lynch
Quoted 10 lines · On Thu, 2009-11-12 at 23:24 -0600, serue-r/[email protected]…
(quoted diff) +10
-0+ if (use_clone) { + int stacksize = 4*getpagesize(); + void *stack = malloc(stacksize); + + if (!stack) { + perror("malloc"); + return -1; + } + + printf("about to clone with %lx\n", flags);Quoted 8 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+ if (chosen_pid) + printf("Will choose pid %d\n", chosen_pid); + flags |= SIGCHLD; + pid = clone_with_pids(do_child, stack, flags, &pid_set, + (void *)argv);The stack argument should be adjusted with the usual stack += stacksize
- 1 or similar, right?the
clone_with_pids()helper inuser-cr/clone_s390x.c(and IIRC the x86 one by Suka also) does this implicitly, by doing:Quoted 8 lines
Quoted 4 lines
s = child_stack; *--s = arg; *--s = fn; child_stack -= 16That's setting up arguments for the function to run in the child, and afaict that code assumes the value of
child_stackis the _end_ of the stack region.
Quoted 8 lines
Yes.
Quoted 2 lines
The code I quoted above is passing the beginning of the region (the return value from malloc).
Holy cow, that was a snafu in my switching to sending (stack_base,stack_size) for the previous version, and then back again. It was meant to send stack_base+stack_size now.
Okay, here's the violence I've committed against your code to get eclone working on powerpc (tested 32-bit userspace against 64-bit kernel).
./nsexeccwp -z 300 /bin/bash -c 'echo $$'
[debugging cruft elided]
300
This is meant not for inclusion but for discussion at this point. I made some changes that will certainly break the builds for other architectures.
Note that I have generic code initializing clone_args with the true stack base and size and passing that to the architecture code. The architecture code (e.g. clone_ppc.c) is responsible for calculating the stack pointer to pass to the kernel. The architecture code is also responsible for clearing clone_args.child_stack_size and updating clone_args.child_stack, adjusting for alignment and arguments if appropriate. In this way, we can accommodate ia64 and parisc and keep platform details in platform-specific code.
clone_ppc.c | 54 +++++++++++++++++++++++++++++++++++ clone_ppc_.S | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- eclone.h | 25 ++++++++++++++++ nsexeccwp.c | 42 ++++++++++++---------------- 4 files changed, 182 insertions(+), 27 deletions(-)
clone_ppc.c +54 -0
@@ -10,14 +10,25 @@#define _GNU_SOURCE +#include <stdint.h> +#include <stdio.h> +#include <string.h> #include <unistd.h> #include <errno.h> #include <sys/types.h> #include <sys/syscall.h> #include <asm/unistd.h> +#include "eclone.h" +struct target_pid_set ; +struct pid_set { +size_t nr_pids; +pid_t *pids; +}; + + extern int __clone_with_pids(int (*fn)(void *arg), void *child_stack , int flags,
@@ -56,3 +67,46 @@ int clone_with_pids(int (*fn)(void *), void *child_stack, int flags, }#endif + +extern int __eclone (int (*fn)(void *arg), +void *child_sp, +int flags, +void *fn_arg, +struct clone_args *args, +size_t args_size, +pid_t *pids); + +int eclone (int (*fn)(void *),void *fn_arg,int clone_flags_low, +struct clone_args *clone_args,pid_t *pids) +{ +struct clone_args my_args; +unsigned long child_sp; +int newpid; + +if (clone_args->child_stack) + child_sp = clone_args->child_stack + + clone_args->child_stack_size -1 ; +else + child_sp =0 ; + + my_args = *clone_args; + my_args.child_stack = child_sp; + my_args.child_stack_size =0 ; + +printf ("%s: child_sp = %p\n" , __func__, (void *)child_sp); + + newpid =__eclone (fn, + (void *)child_sp, + clone_flags_low, + fn_arg, + &my_args, +sizeof (my_args), + pids); + +if (newpid <0 ) { + errno = -newpid; + newpid =-1 ; + } + +return newpid; +}
clone_ppc_.S +85 -3
104 lines not on this page · raw message
eclone.h new file +25 -0
@@ -0,0 +1,25 @@ +#ifndef _ECLONE_H_ +#define _ECLONE_H_ + +#include <stdint.h> + +struct clone_args { +uint64_t clone_flags_high; +uint64_t child_stack; +uint64_t child_stack_size; +uint64_t parent_tid_ptr; +uint64_t child_tid_ptr; + +uint32_t nr_pids; + +uint32_t reserved0; +uint64_t reserved1; +}; + +/* arch-dependent code implements this interface */ +extern int eclone (int (*fn)(void *),void *fn_arg, +int clone_flags_low, +struct clone_args *clone_args, +pid_t *pids); + +#endif
nsexeccwp.c +18 -24
94 lines not on this page · raw message
A message that is not in the archive (sent off-list or not yet received): 1258413522.4031.1036.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/[email protected]
Re: [PATCH user-cr 2/2] add nsexeccwp to test clone-with-pids
Quoted 19 lines · Nathan Lynch
Okay, here's the violence I've committed against your code to get eclone working on powerpc (tested 32-bit userspace against 64-bit kernel).
./nsexeccwp -z 300
/bin/bash-c 'echo $$'
[debugging cruft elided]
300This is meant not for inclusion but for discussion at this point. I made some changes that will certainly break the builds for other architectures.
Note that I have generic code initializing
clone_argswith the true stack base and size and passing that to the architecture code. The architecture code (e.g.clone_ppc.c) is responsible for calculating the stack pointer to pass to the kernel. The architecture code is also responsible for clearing clone_args.child_stack_size and updating clone_args.child_stack, adjusting for alignment and arguments if appropriate. In this way, we can accommodate ia64 and parisc and keep platform details in platform-specific code.
...
Quoted 15 lines
clone_ppc.c +3
-0@@ -10,14 +10,25 @@#define _GNU_SOURCE +#include <stdint.h> +#include <stdio.h> +#include <string.h> #include <unistd.h> #include <errno.h> #include <sys/types.h> #include <sys/syscall.h>
clone_ppc.c line 29
Quoted 10 lines
clone_ppc.c +6
-0#include <asm/unistd.h> +#include "eclone.h" +struct target_pid_set ; +struct pid_set { +size_t nr_pids; +pid_t *pids; +};
You shouldn't need the pid_set any more right?
...
Quoted 10 lines
clone_ppc.c +5
-0@@ -305,12 +294,17 @@ int main(int argc, char *argv[])return -1 ; } +memset (&clone_args,0 ,sizeof (clone_args)); + clone_args.child_stack = (unsigned long )stack; + clone_args.child_stack_size = stacksize; + clone_args.nr_pids = nr_pids; +printf ("about to clone with %lx\n" , flags);
clone_ppc.c int main(int argc, char *argv[]) · line 310
Quoted 10 lines
clone_ppc.c +2
-2if (chosen_pid)printf ("Will choose pid %d\n" , chosen_pid); +printf ("argv = %p\n" , argv); flags |=SIGCHLD ; - pid =clone_with_pids (do_child, stack, flags, &pid_set, - (void *)argv); + pid =eclone (do_child, argv, flags, &clone_args, &chosen_pid);if (pid ==-1 ) {perror ("clone" );return -1 ;
Yup, of course I agree with switching to a clean eclone passing the clone_args and no struct pid_set, i was just trying to minimize (to 0 :) the changes required for now in restart.c.
If you don't mind sending the patch to update restart.c as well as this (minus some debugging) when you're ready, I'll port clone_s390x.c to your precise api.
thanks,
-serge
Re: [PATCH user-cr 2/2] add nsexeccwp to test clone-with-pids
In reply to a message not in the archiveSubject: [PATCH 1/1] nsexeccwp bugfixes
1. As Nathan pointed out, I was passing in stack bottom, not stack top. Our clone_with_pids() helper in user-cr/clone_${ARCH}.c just accepts stack top.
2. The clone_with_pids() helper returns -errno on error, it doesn't set errno. Hande that right.
--- nsexeccwp.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-)
nsexeccwp.c +3 -1
@@ -304,6 +304,7 @@ int main(int argc, char *argv[])perror ("malloc" );return -1 ; } + stack += stacksize -1 ;printf ("about to clone with %lx\n" , flags);if (chosen_pid)
@@ -311,7 +312,8 @@ int main(int argc, char *argv[]) flags |=SIGCHLD ; pid =clone_with_pids (do_child, stack, flags, &pid_set, (void *)argv); -if (pid ==-1 ) { +if (pid <0 ) { + errno = -pid;perror ("clone" );return -1 ; }
Signature · 1 line
1.6.1.1
Quoted 3 lines · On Thu, 2009-11-12 at 23:24 -0600, serue-r/[email protected]…
From: Serge E. Hallyn <serue-r/[email protected]>
This patch implements the s390 hook for
sys_eclone.
Here's powerpc (this is on top of serge's eclone-v13-s390x.2 branch).
From 9c7ee027d1519a68308b20f5216a49eb43656ff6 Mon Sep 17 00:00:00 2001
From: Nathan Lynch <[email protected]>
Date: Mon, 16 Nov 2009 16:37:29 -0600
Subject: [PATCH] implement eclone for powerpc
Wired up for both ppc32 and ppc64, but tested only with the latter.
--- arch/powerpc/include/asm/syscalls.h | 6 ++++ arch/powerpc/include/asm/systbl.h | 1 + arch/powerpc/include/asm/unistd.h | 3 +- arch/powerpc/kernel/entry_32.S | 8 +++++ arch/powerpc/kernel/entry_64.S | 5 +++ arch/powerpc/kernel/process.c | 56 +++++++++++++++++++++++++++++++++++ 6 files changed, 78 insertions(+), 1 deletions(-)
arch/powerpc/include/asm/syscalls.h +6 -0
@@ -24,6 +24,12 @@ asmlinkage int sys_execve(unsigned long a0, unsigned long a1, asmlinkage int sys_clone(unsigned long clone_flags, unsigned long usp,int __user *parent_tidp,void __user *child_threadptr,int __user *child_tidp,int p6,struct pt_regs *regs); +asmlinkage int sys_eclone(unsigned long flags_low, +struct clone_args __user *args, +size_t args_size, +pid_t __user *pids, +unsigned long p5,unsigned long p6, +struct pt_regs *regs); asmlinkage int sys_fork(unsigned long p1, unsigned long p2,unsigned long p3,unsigned long p4,unsigned long p5,unsigned long p6,struct pt_regs *regs);
arch/powerpc/include/asm/systbl.h +1 -0
@@ -326,3 +326,4 @@ SYSCALL_SPU(perf_event_open) COMPAT_SYS_SPU(preadv) COMPAT_SYS_SPU(pwritev) COMPAT_SYS(rt_tgsigqueueinfo) +PPC_SYS(eclone)
arch/powerpc/include/asm/unistd.h +2 -1
@@ -345,10 +345,11 @@#define __NR_preadv 320#define __NR_pwritev 321#define __NR_rt_tgsigqueueinfo 322 +#define __NR_eclone 323#ifdef __KERNEL__ -#define __NR_syscalls 323 +#define __NR_syscalls 324#define __NR__exit __NR_exit#define NR_syscalls __NR_syscalls
arch/powerpc/kernel/entry_32.S +8 -0
@@ -586,6 +586,14 @@ ppc_clone: stw r0,_TRAP(r1) /* register set saved */ b sys_clone + .globl ppc_eclone +ppc_eclone: + SAVE_NVGPRS(r1) + lwz r0,_TRAP(r1) + rlwinm r0,r0,0,0,30 /* clear LSB to indicate full */ + stw r0,_TRAP(r1) /* register set saved */ + b sys_eclone + .globl ppc_swapcontext ppc_swapcontext: SAVE_NVGPRS(r1)
arch/powerpc/kernel/entry_64.S +5 -0
@@ -344,6 +344,11 @@ _GLOBAL(ppc_clone) bl .sys_clone b syscall_exit +_GLOBAL(ppc_eclone) + bl .save_nvgprs + bl .sys_eclone + b syscall_exit + _GLOBAL(ppc32_swapcontext) bl .save_nvgprs bl .compat_sys_swapcontext
arch/powerpc/kernel/process.c +56 -0
62 lines not on this page · raw message
Signature · 1 line
1.6.0.6
A message that is not in the archive (sent off-list or not yet received): 1258414596.4031.1058.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/[email protected]
Serge E. Hallyn
AppliedQuoted 6 lines · Nathan Lynch
Quoted 3 lines · On Thu, 2009-11-12 at 23:24 -0600, serue-r/[email protected]…
From: Serge E. Hallyn <serue-r/[email protected]>
This patch implements the s390 hook for
sys_eclone.Here's powerpc (this is on top of serge's eclone-v13-s390x.2 branch).
Pushed to branch eclone-v13-s390x.ppc ofgit://git.kernel.org/pub/scm/linux/kernel/git/sergeh/linux-cr.git
thanks,
-serge
A message that is not in the archive (sent off-list or not yet received): 20091117040321.GA32461-r/[email protected]
PATCH 1/1 fix warnings in i386 sys_eclone
With your eclone-v13-s390x.ppc.2 branch I get:
arch/x86/kernel/process_32.c: In function ‘sys_eclone’:arch/x86/kernel/process_32.c:479: warning: cast to pointer from integer of different sizearch/x86/kernel/process_32.c:480: warning: cast to pointer from integer of different size
arch/x86/kernel/process_32.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
arch/x86/kernel/process_32.c +2 -2
@@ -476,8 +476,8 @@ int sys_eclone(struct pt_regs *regs)* flags = (kca.clone_flags_high << 32) | flags_low; */ flags = flags_low; - parent_tid_ptr = (int *)kca.parent_tid_ptr; - child_tid_ptr = (int *)kca.child_tid_ptr; + parent_tid_ptr = (int *)(unsigned long )kca.parent_tid_ptr; + child_tid_ptr = (int *)(unsigned long )kca.child_tid_ptr; stack_size = (unsigned long )kca.child_stack_size;if (stack_size)
_______________________________________________
Containers mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/containers