mbox

[v2,0/9] nptl: pthread cancellation refactor

Message ID 20210527172823.3461314-1-adhemerval.zanella@linaro.org
Headers

Message

Adhemerval Zanella Netto May 27, 2021, 5:28 p.m. UTC
  Changes from v1 [1]:

  - Moved the __do_cancel call for the BZ #19511 fix to a place where
    the PD is held by the thread.
  - Fixed style issues.
  - Added the BZ#19366 fix.

--

This patchset refactor and simplifies the nptl cancellation code.  The
1st patch is a NFC change.

The 2nd patch fixes an memory leak issue when pthread_create fails to
setup either the scheduling or affinity parameter.  The asynchronous
cancellation is removed in favor of using a member to indicate the
setup has failed and letting the created thread to deallocate the
memory (similar on how detached threads do).

The 3rd patch moves the signal handler setup to pthread_cancel, now that
asynchronous cancellation is not used anymore on thread creation.

The 4th removes the CANCELING_BITMASK bit, since it is mainly used to
signal that a syscall that has returned should be cancelled (which is
a wrong assumption, since syscall with side-effects should *not* be
cancelled as per BZ#12683).

The 5th and 6th patches move both the cancel state and cancel type out
of 'cancelhandling' variable, since with CANCELING_BITMASK and
pthread_cancel change in previous patch they are not accessed in a
concurrent manner.

The 7th and 8th patchies consolidates the raise as
'pthread_kill(pthread_self())' and use pthread_kill() on
pthread_cancel().

Finally, the 9th fixes another cancellation synchronization issue
when async cancellation might early exit the process due wrong
__nptl_nthreads update.

[1] https://sourceware.org/pipermail/libc-alpha/2021-May/126852.html

Adhemerval Zanella (9):
  nptl: Remove exit-thread.h
  nptl: Deallocate the thread stack on setup failure (BZ #19511)
  nptl: Install cancellation handler on pthread_cancel
  nptl: Remove CANCELING_BITMASK
  nptl: Move cancel state out of cancelhandling
  nptl: Move cancel type out of cancelhandling
  nptl: Implement raise in terms of pthread_kill
  nptl: Use pthread_kill on pthread_cancel
  nptl: Avoid async cancellation to wrongly update __nptl_nthreads (BZ
    #19366)

 csu/libc-start.c                      |   1 -
 include/pthread.h                     |   5 +
 manual/pattern.texi                   |   1 -
 manual/process.texi                   |   3 +-
 nptl/Versions                         |   3 +-
 nptl/allocatestack.c                  |   3 +
 nptl/cancellation.c                   |  62 +++--------
 nptl/cleanup_defer.c                  |  46 +-------
 nptl/descr.h                          |  32 ++----
 nptl/libc-cleanup.c                   |  46 +-------
 nptl/pthreadP.h                       |  24 +----
 nptl/pthread_cancel.c                 | 145 ++++++++------------------
 nptl/pthread_create.c                 | 102 +++++++-----------
 nptl/pthread_join_common.c            |   7 +-
 nptl/pthread_kill.c                   |  52 ++++++---
 nptl/pthread_self.c                   |   4 +-
 nptl/pthread_setcancelstate.c         |  36 +------
 nptl/pthread_setcanceltype.c          |  41 +-------
 nptl/pthread_testcancel.c             |  11 +-
 sysdeps/generic/exit-thread.h         |  28 -----
 sysdeps/htl/pthreadP.h                |   2 -
 sysdeps/nptl/dl-tls_init_tp.c         |   3 +
 sysdeps/nptl/libc_start_call_main.h   |   5 +-
 sysdeps/posix/raise.c                 |  11 +-
 sysdeps/unix/sysv/linux/exit-thread.h |  37 -------
 sysdeps/unix/sysv/linux/raise.c       |  52 ---------
 26 files changed, 211 insertions(+), 551 deletions(-)
 delete mode 100644 sysdeps/generic/exit-thread.h
 delete mode 100644 sysdeps/unix/sysv/linux/exit-thread.h
 delete mode 100644 sysdeps/unix/sysv/linux/raise.c