All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] Query: Adding support for clone3()
@ 2020-02-28  8:14 Viresh Kumar
  2020-02-28  8:58 ` Cyril Hrubis
  0 siblings, 1 reply; 5+ messages in thread
From: Viresh Kumar @ 2020-02-28  8:14 UTC (permalink / raw)
  To: ltp

Hey guys,

I was looking to start implementation of clone3() syscall in LTP
and am a bit confused here and need your help in doing the same.

LTP abstracts the call to clone() syscall in lib/cloner.c and the current
prototype of it looks like this.

       int clone(int (*fn)(void *), void *stack, int flags, void *arg, ...
                 /* pid_t *parent_tid, void *tls, pid_t *child_tid */ );

One of the challenges with the implementation of clone3() is that
there is no glibc wrapper available. And in case of clone() glibc
wrapper isn't ordinary as it takes care of calling fn() and handling
few stack related things, apart from calling the real syscall.

I am confused now on how should I write support for clone3().

Any suggestions will be appreciated. Thanks.

--
viresh

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [LTP] Query: Adding support for clone3()
  2020-02-28  8:14 [LTP] Query: Adding support for clone3() Viresh Kumar
@ 2020-02-28  8:58 ` Cyril Hrubis
  2020-02-28 10:24   ` Viresh Kumar
  0 siblings, 1 reply; 5+ messages in thread
From: Cyril Hrubis @ 2020-02-28  8:58 UTC (permalink / raw)
  To: ltp

Hi!
> I was looking to start implementation of clone3() syscall in LTP
> and am a bit confused here and need your help in doing the same.
> 
> LTP abstracts the call to clone() syscall in lib/cloner.c and the current
> prototype of it looks like this.
> 
>        int clone(int (*fn)(void *), void *stack, int flags, void *arg, ...
>                  /* pid_t *parent_tid, void *tls, pid_t *child_tid */ );

This function is there mostly for implementation of container testscases
so that they does not need to deal with the clone() syscall complexity.

> One of the challenges with the implementation of clone3() is that
> there is no glibc wrapper available. And in case of clone() glibc
> wrapper isn't ordinary as it takes care of calling fn() and handling
> few stack related things, apart from calling the real syscall.
> 
> I am confused now on how should I write support for clone3().
> 
> Any suggestions will be appreciated. Thanks.

Let's just add the code into lapi/clone.h, would that work for you?

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [LTP] Query: Adding support for clone3()
  2020-02-28  8:58 ` Cyril Hrubis
@ 2020-02-28 10:24   ` Viresh Kumar
  2020-02-28 11:48     ` Cyril Hrubis
  0 siblings, 1 reply; 5+ messages in thread
From: Viresh Kumar @ 2020-02-28 10:24 UTC (permalink / raw)
  To: ltp

On 28-02-20, 09:58, Cyril Hrubis wrote:
> Hi!
> > I was looking to start implementation of clone3() syscall in LTP
> > and am a bit confused here and need your help in doing the same.
> > 
> > LTP abstracts the call to clone() syscall in lib/cloner.c and the current
> > prototype of it looks like this.
> > 
> >        int clone(int (*fn)(void *), void *stack, int flags, void *arg, ...
> >                  /* pid_t *parent_tid, void *tls, pid_t *child_tid */ );
> 
> This function is there mostly for implementation of container testscases
> so that they does not need to deal with the clone() syscall complexity.

Right.

> > One of the challenges with the implementation of clone3() is that
> > there is no glibc wrapper available. And in case of clone() glibc
> > wrapper isn't ordinary as it takes care of calling fn() and handling
> > few stack related things, apart from calling the real syscall.
> > 
> > I am confused now on how should I write support for clone3().
> > 
> > Any suggestions will be appreciated. Thanks.
> 
> Let's just add the code into lapi/clone.h, would that work for you?

Which code are you talking about ?

Here is some stuff about the glibc wrapper for clone() from an stackoverflow
page [1]:

clone(void (*fn)(void *), void *stack_pointer)
{
    push fn onto stack_pointer
    syscall_clone()
    if (child) {
        pop fn off of stack
        fn();
        exit();
    }
}

This takes care of calling fn() and doing some stack related stuff.
The kernel syscall doesn't expect the fn() argument but only the
userspace calls do. How should I handle the extra stuff that userspace
expects for a clone() call ?

-- 
viresh

[1] https://stackoverflow.com/questions/18904292/is-it-true-that-fork-calls-clone-internally

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [LTP] Query: Adding support for clone3()
  2020-02-28 10:24   ` Viresh Kumar
@ 2020-02-28 11:48     ` Cyril Hrubis
  2020-03-04  7:45       ` Viresh Kumar
  0 siblings, 1 reply; 5+ messages in thread
From: Cyril Hrubis @ 2020-02-28 11:48 UTC (permalink / raw)
  To: ltp

Hi!
> > > One of the challenges with the implementation of clone3() is that
> > > there is no glibc wrapper available. And in case of clone() glibc
> > > wrapper isn't ordinary as it takes care of calling fn() and handling
> > > few stack related things, apart from calling the real syscall.
> > > 
> > > I am confused now on how should I write support for clone3().
> > > 
> > > Any suggestions will be appreciated. Thanks.
> > 
> > Let's just add the code into lapi/clone.h, would that work for you?
> 
> Which code are you talking about ?
> 
> Here is some stuff about the glibc wrapper for clone() from an stackoverflow
> page [1]:
> 
> clone(void (*fn)(void *), void *stack_pointer)
> {
>     push fn onto stack_pointer
>     syscall_clone()
>     if (child) {
>         pop fn off of stack
>         fn();
>         exit();
>     }
> }
> 
> This takes care of calling fn() and doing some stack related stuff.
> The kernel syscall doesn't expect the fn() argument but only the
> userspace calls do. How should I handle the extra stuff that userspace
> expects for a clone() call ?

That depends I guess mostly on the clone() flags, right? Unless we pass
CLONE_VM the child lives in a separate copy of the memory space and we
do not have to do anything about the stack.

So for the most clone3() tests we can just need the struct clone_args
and the syscall number and we can treat it mostly like more complex
version of fork(), i.e. pass NULL and 0 for the stack and stack_size
parameters.

So I would start by adding the kernel version of the clone3() syscall,
the structure, and the V0 structure size into the lapi header and use
that for a basic testcases.

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [LTP] Query: Adding support for clone3()
  2020-02-28 11:48     ` Cyril Hrubis
@ 2020-03-04  7:45       ` Viresh Kumar
  0 siblings, 0 replies; 5+ messages in thread
From: Viresh Kumar @ 2020-03-04  7:45 UTC (permalink / raw)
  To: ltp

On 28-02-20, 12:48, Cyril Hrubis wrote:
> That depends I guess mostly on the clone() flags, right? Unless we pass
> CLONE_VM the child lives in a separate copy of the memory space and we
> do not have to do anything about the stack.
> 
> So for the most clone3() tests we can just need the struct clone_args
> and the syscall number and we can treat it mostly like more complex
> version of fork(), i.e. pass NULL and 0 for the stack and stack_size
> parameters.
> 
> So I would start by adding the kernel version of the clone3() syscall,
> the structure, and the V0 structure size into the lapi header and use
> that for a basic testcases.

Okay, so you are suggesting here to create a separate
testcases/kernel/syscalls/clone3 directory for the tests ? That makes
sense as a user may want to test both clone and clone3 on a platform
for a given kernel version.

-- 
viresh

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-03-04  7:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-28  8:14 [LTP] Query: Adding support for clone3() Viresh Kumar
2020-02-28  8:58 ` Cyril Hrubis
2020-02-28 10:24   ` Viresh Kumar
2020-02-28 11:48     ` Cyril Hrubis
2020-03-04  7:45       ` Viresh Kumar

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.