This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 0/8] nptl: Fix Race conditions in pthread cancellation (BZ#12683)


Hi all,

This is an update of my initial patch set to fix BZ#12683 [1] and the 
implementation details are summarized at [2].  Main differences from previous
version are:

 * Added fix support for aarch64 and arm.
 * Clean up patch requirements with already pushed modifications
   (SYSCALL_CANCEL refactor and inline syscalls for non-cancellable calls).

For x86_64 and i386 implementation my approach was to just remove the
pthread_cond_{timed}wait assembly implementation and use default C code, but
since Torvald Riegel new condvar implementation [3] also removed them this
patchset do not contain such removals.  Also, this fix is easy to adjust
to new futex API also proposed by Torvalds and I can adjust the patch when
the new API is pushed upstream.  The bulk of implementation just depend of a
cancellable futex call done by new mechanism which is orthogonal of the new
proposed futex API.

The patchset fixes the x86_64, i386, x32, powerpc32, powerpc64{le}, aarch64,
and ARM port. It will require some help for alpha, hppa, ia64, m68k, microblaze,
nios2, s390, sh, sparc, and tile. I will summarize in wiki page the steps
required to adjust the remaining architectures, but based on arm/aarch64 the
minimal adjustments required are:

1. Write a new syscall implementation at sysdeps/unix/sysv/linux/<arch>/syscall_cancel.S
   that basically do:

long int __syscall_cancel_arch (volatile unsigned int *cancelhandling,
  __syscall_arg_t nr, __syscall_arg_t arg1, __syscall_arg_t arg2, 
  __syscall_arg_t arg3, __syscall_arg_t arg4, __syscall_arg_t arg5,
  __syscall_arg_t arg6)
{
  if (*cancelhandling & CANCELED_BITMASK)
    __syscall_do_cancel()

  return INLINE_SYSCALL (nr, 6, arg1, arg2, arg3, arg4, arg5, arg6);
}

2. Adjust sysdeps/unix/sysv/linux/<arch>/sysdep-cancel.h to make cancellable
   syscalls to call __syscall_cancel instead of *_{enable,disable}_asynccancel.

3. Create a function to get current IP address based on ucontext_t:

static inline
long int __pthread_get_ip (const struct ucontext *uc)
{
  // TODO
}

4. Define both SYSCALL_CANCEL_ERROR(__val) and SYSCALL_CANCEL_ERRNO(__val)
   macros.

I hope to get some reviews and then work on remaining ports for new 2.23
release.

[1] https://sourceware.org/ml/libc-alpha/2014-09/msg00613.html
[2] https://sourceware.org/glibc/wiki/Release/2.21/bz12683
[3] https://sourceware.org/ml/libc-alpha/2015-05/msg00287.html

--

 ChangeLog                                          | 175 +++++++++++++++++++++
 io/creat.c                                         |   3 -
 io/ppoll.c                                         |   2 -
 misc/pselect.c                                     |   2 -
 nptl/Makefile                                      |   5 +-
 nptl/Versions                                      |   3 +
 nptl/cancellation.c                                |  99 ------------
 nptl/descr.h                                       |  15 +-
 nptl/libc-cancellation.c                           |  60 ++++++-
 nptl/lll_timedlock_wait.c                          |   2 +-
 nptl/lll_timedwait_tid.c                           |   3 +-
 nptl/nptl-init.c                                   |  65 ++++----
 nptl/pthreadP.h                                    |  70 +++------
 nptl/pthread_cancel.c                              |  73 +--------
 nptl/pthread_cond_timedwait.c                      |  31 ++--
 nptl/pthread_cond_wait.c                           |  20 +--
 nptl/pthread_create.c                              |   6 +-
 nptl/pthread_exit.c                                |   9 +-
 nptl/pthread_join.c                                |   9 +-
 nptl/pthread_timedjoin.c                           |   8 -
 nptl/sem_wait.c                                    |   8 +-
 nptl/sem_waitcommon.c                              |  20 ++-
 nptl/tst-cancel26.c                                |  98 ++++++++++++
 rt/Makefile                                        |   1 -
 sysdeps/generic/sysdep-cancel.h                    |   3 -
 sysdeps/i386/nptl/tls.h                            |  11 --
 sysdeps/nptl/Makefile                              |   3 +-
 sysdeps/nptl/aio_misc.h                            |  15 +-
 sysdeps/nptl/gai_misc.h                            |  15 +-
 sysdeps/nptl/librt-cancellation.c                  |  24 ---
 sysdeps/nptl/lowlevellock.h                        |   2 +-
 sysdeps/posix/open64.c                             |  12 +-
 sysdeps/posix/pause.c                              |   2 -
 sysdeps/posix/sigpause.c                           |  11 +-
 sysdeps/posix/sigwait.c                            |   9 +-
 sysdeps/posix/waitid.c                             |  11 +-
 sysdeps/unix/sysdep.h                              |  68 ++++++--
 sysdeps/unix/sysv/linux/aarch64/syscall_cancel.S   |  75 +++++++++
 sysdeps/unix/sysv/linux/aarch64/sysdep-cancel.h    |  95 +++++------
 sysdeps/unix/sysv/linux/aarch64/sysdep.h           |   8 +
 sysdeps/unix/sysv/linux/arm/syscall_cancel.S       |  69 ++++++++
 sysdeps/unix/sysv/linux/arm/sysdep-cancel.h        |  65 ++++----
 sysdeps/unix/sysv/linux/arm/sysdep.h               |   8 +
 sysdeps/unix/sysv/linux/clock_nanosleep.c          |  17 +-
 sysdeps/unix/sysv/linux/fcntl.c                    |  33 ++--
 sysdeps/unix/sysv/linux/generic/creat.c            |   3 -
 .../unix/sysv/linux/generic/wordsize-32/fcntl.c    |  30 ++--
 sysdeps/unix/sysv/linux/i386/Makefile              |   1 +
 sysdeps/unix/sysv/linux/i386/fcntl.c               |   4 +-
 sysdeps/unix/sysv/linux/i386/libc-cancellation.c   |  46 ++++++
 sysdeps/unix/sysv/linux/i386/lowlevellock.h        |   2 +-
 sysdeps/unix/sysv/linux/i386/syscall_cancel.S      | 105 +++++++++++++
 sysdeps/unix/sysv/linux/i386/sysdep-cancel.h       | 144 ++++++-----------
 sysdeps/unix/sysv/linux/i386/sysdep.h              |   8 +
 sysdeps/unix/sysv/linux/lowlevellock-futex.h       |  46 +++++-
 .../sysv/linux/powerpc/powerpc32/sysdep-cancel.h   | 131 +++++++--------
 sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep.h |   8 +
 sysdeps/unix/sysv/linux/powerpc/powerpc64/fcntl.c  |   4 +-
 .../sysv/linux/powerpc/powerpc64/sysdep-cancel.h   | 137 +++++-----------
 sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep.h |   9 ++
 sysdeps/unix/sysv/linux/powerpc/syscall_cancel.S   |  63 ++++++++
 sysdeps/unix/sysv/linux/powerpc/sysdep.c           |  11 ++
 sysdeps/unix/sysv/linux/pthread_kill.c             |   5 +-
 sysdeps/unix/sysv/linux/sigwait.c                  |  36 +----
 sysdeps/unix/sysv/linux/socketcall.h               |  37 ++++-
 sysdeps/unix/sysv/linux/x86_64/cancellation.S      | 117 --------------
 sysdeps/unix/sysv/linux/x86_64/libc-cancellation.S |  21 ---
 .../unix/sysv/linux/x86_64/librt-cancellation.S    |  21 ---
 sysdeps/unix/sysv/linux/x86_64/lowlevellock.h      |   8 +-
 sysdeps/unix/sysv/linux/x86_64/syscall_cancel.S    |  62 ++++++++
 sysdeps/unix/sysv/linux/x86_64/sysdep-cancel.h     |  73 ++++-----
 sysdeps/unix/sysv/linux/x86_64/sysdep.h            |   8 +
 sysdeps/unix/sysv/linux/x86_64/x32/sysdep.h        |  21 +++
 sysdeps/x86_64/nptl/tcb-offsets.sym                |   1 -
 sysdeps/x86_64/nptl/tls.h                          |  11 --
 75 files changed, 1421 insertions(+), 1095 deletions(-)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]