Re: [PATCH] ia64: enable HAVE_COPY_THREAD_TLS, switch to kernel_clone_args

From: Christian Brauner
Date: Thu May 14 2020 - 06:37:18 EST


On Thu, May 14, 2020 at 12:33:00PM +0200, Christian Brauner wrote:
> On Thu, May 14, 2020 at 12:21:13PM +0200, John Paul Adrian Glaubitz wrote:
> > On 5/14/20 12:19 PM, Christian Brauner wrote:
> > > Scratch that. It's even worse. On ia64 it is _invalid_ to pass a NULL
> > > stack. That's at least what the glibc assembly assumes:
> > >
> > > cmp.eq p6,p0=0,in0
> > > cmp.eq p7,p0=0,in1
> > > mov r8=EINVAL
> > > mov out0=in3 /* Flags are first syscall argument. */
> > > mov out1=in1 /* Stack address. */
> > > (p6) br.cond.spnt.many __syscall_error /* no NULL function pointers */
> > > (p7) br.cond.spnt.many __syscall_error /* no NULL stack pointers */
> > > ;;
> > > mov out2=in2 /* Stack size. */
> > >
> > > so newer systemd just works by accident on ia64 if at all correctly
> > > afaict.
> >
> > Hmm, interesting. I really wasn't aware of that. Thanks for the heads-up.
> >
> > I'll ask Michael whether he can come up for a solution for that problem.
> >
> > Maybe that's also why systemd crashes.
>
> Do you have a very minimalistic ia64 userspace preferably without systemd where
> you could simply test. That should give us an idea whether things work:
>
> #define _GNU_SOURCE
> #include <sys/wait.h>
> #include <sys/utsname.h>
> #include <sched.h>
> #include <string.h>
> #include <stdio.h>
> #include <stdlib.h>
> #include <unistd.h>
> #include <sys/mman.h>
>
> #define STACK_SIZE (8 * 1024 * 1024) /* standard stack size for threads in glibc */
>
> int main(int argc, char *argv[])
> {
> char *stack;
> pid_t pid;
>
> stack = mmap(NULL, STACK_SIZE, PROT_READ | PROT_WRITE,
> MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK, -1, 0);
> if (stack == MAP_FAILED)
> exit(EXIT_FAILURE);
>
> /*
> * Note that legacy clone() has different argument ordering on
> * different architectures so this won't work everywhere.
> */
> pid = syscall(189 /* __NR_clone2 */, SIGCHLD, stack, STACK_SIZE, NULL, NULL);

Please note that even on ia64 the stack grows down but in contrast to
all other architectures ia64 expects the _lowest_ address to be given
and will add STACK_SIZE to stack itself in copy_thread{_tls}(). (This is
all fixed in clone3() where you're always expected to pass down the
lowest address and the kernel figures it out for you.)

So this is intentional.

Christian