This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH 00/19] nptl: Fix Race conditions in pthread cancellation (BZ#12683)
- From: John Paul Adrian Glaubitz <glaubitz at physik dot fu-berlin dot de>
- To: Adhemerval Zanella <adhemerval dot zanella at linaro dot org>
- Cc: libc-alpha at sourceware dot org
- Date: Mon, 11 Dec 2017 20:18:29 +0100
- Subject: Re: [PATCH 00/19] nptl: Fix Race conditions in pthread cancellation (BZ#12683)
- Authentication-results: sourceware.org; auth=none
- References: <1513019223-7603-1-git-send-email-adhemerval.zanella@linaro.org>
Hi Adhemerval!
You should still have access to my SH porterbox and if you let me know what to test, I can also test on real m68k hardware.
Adrian
> On Dec 11, 2017, at 8:06 PM, Adhemerval Zanella <adhemerval.zanella@linaro.org> wrote:
>
> Another release, another submission for BZ#12683. This time I finished
> support for all support archictures and did some testing on more ports
> which resulted in a lot of small fixes.
>
> I have simplified a lot the work required to adjust a new port [1] on
> this new cancellable syscall mechanism. A default implementation
> at sysdeps/unix/sysv/linux/syscall_cancel.c is provided and used on
> architectures (x86_64 and aarch64 for instance). It should works
> as long the requires syscall markers (__syscall_cancel_arch_{start,end})
> as placed right before the cancellation flag test and after the
> syscall trap instruction respectively.
>
> However some architecture still requires an assembly crafted
> implementation (for instance if the syscall itself is done through a
> kernel gate as for i686 or ia64 or if it requires a special gate due
> ABI constraint like ARM). In such case the syscall wrapper
> should be place at sysdeps/unix/sysv/linux/<arch>/syscall_cancel.S
> with following semantic:
>
> ---
> 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()
>
> INTERNAL_SYSCALL_DECL (err);
> result = INTERNAL_SYSCALL_NCS (nr, err, 6, a1, a2, a3, a4, a5, a6);
> if (INTERNAL_SYSCALL_ERROR_P (result, err))
> return -INTERNAL_SYSCALL_ERRNO (result, err);
> return result;
> }
>
> * If the architectures requires a cancellation entrypoint for 7 argument
> syscalls (as for MIPSo32) it will need to define SYSCALL_CANCEL7_ARG7
> on sysdep.h.
> ---
>
> The another architecture specific code is to obtain both the program
> counter and process signal mask in the signal handler. To accomplish it
> each architecture implements a new function, ucontext_get_pc, on
> sigcontextinfo.h header as:
>
> ---
> static inline uintptr_t
> ucontext_get_pc (const void *cxt)
> {
> // TODO: return current program counter based on uc. Usually
> // the CTX points to a ucontext_t, however it is architecture
> // dependent (for instance sparc calls with sigcontext).
> }
>
> * If the signal frame signal mask is not directly accessible through the
> CTX pointer (either because the kernel invokes the handler with a different
> object than ucontext_t, as SPARC; or due type mismatch between kernel and
> glibc, as for IA64) the architecture might define UCONTEXT_SIGMASK to
> get the uc_mask pointer.
> ---
>
> I currently tested on x86_64-linux-gnu, x86_64-linux-gnu-x32, i686-linux-gnu,
> arm-linux-gnueabihf, aarch64-linux-gnu, sparcv9-linux-gnu, sparc64-linux-gnu,
> alpha-linux-gnu, and hppa-linux-gnu. I also did some simple tests on
> ia64-linux-gnu and mips{64}-linux-gnu (to check for the correctness in the
> syscall wrapper implementation). For the rest of support architectures
> I just did a cross build/check.
>
> [1] https://sourceware.org/glibc/wiki/PortStatus
>
> Adhemerval Zanella (19):
> nptl: Fix testcases for new pthread cancellation mechanism
> nptl: Fix Race conditions in pthread cancellation (BZ#12683)
> nptl: x86_64: Fix Race conditions in pthread cancellation (BZ#12683)
> nptl: x32: Fix Race conditions in pthread cancellation (BZ#12683)
> nptl: i386: Fix Race conditions in pthread cancellation (BZ#12683)
> nptl: powerpc: Fix Race conditions in pthread cancellation (BZ#12683)
> nptl: aarch64: Fix Race conditions in pthread cancellation (BZ#12683)
> nptl: arm: Fix Race conditions in pthread cancellation (BZ#12683)
> nptl: s390: Fix Race conditions in pthread cancellation (BZ#12683)
> nptl: ia64: Fix Race conditions in pthread cancellation (BZ#12683)
> nptl: alpha: Fix Race conditions in pthread cancellation (BZ#12683)
> nptl: m68k: Fix Race conditions in pthread cancellation (BZ#12683)
> nptl: microblaze: Fix Race conditions in pthread cancellation
> (BZ#12683)
> nptl: tile: Fix Race conditions in pthread cancellation (BZ#12683)
> nptl: sparc: Fix Race conditions in pthread cancellation (BZ#12683)
> nptl: nios2: Fix Race conditions in pthread cancellation (BZ#12683)
> nptl: sh: Fix Race conditions in pthread cancellation (BZ#12683)
> nptl: mips: Fix Race conditions in pthread cancellation (BZ#12683)
> nptl: hppa: Fix Race conditions in pthread cancellation (BZ#12683)
>
> ChangeLog | 199 +++++++++++++++++++++
> debug/tst-backtrace5.c | 26 +--
> include/libc-pointer-arith.h | 16 +-
> io/creat.c | 3 -
> io/ppoll.c | 2 -
> manual/llio.texi | 4 +-
> misc/pselect.c | 2 -
> nptl/Makefile | 25 +--
> nptl/Versions | 3 +
> nptl/cancellation.c | 101 -----------
> nptl/descr.h | 15 +-
> nptl/libc-cancellation.c | 48 ++++-
> nptl/lll_timedlock_wait.c | 2 +-
> nptl/lll_timedwait_tid.c | 3 +-
> nptl/nptl-init.c | 78 +++++---
> nptl/pthreadP.h | 74 +++-----
> nptl/pthread_cancel.c | 68 ++-----
> nptl/pthread_create.c | 7 +-
> nptl/pthread_exit.c | 9 +-
> nptl/pthread_join.c | 10 +-
> nptl/pthread_timedjoin.c | 9 +-
> nptl/sem_wait.c | 8 +-
> nptl/tst-cancel-wrappers.sh | 92 ----------
> nptl/tst-cancel2.c | 3 -
> nptl/tst-cancel28.c | 94 ++++++++++
> nptl/tst-cancel3.c | 3 -
> nptl/tst-cancel4.c | 8 +
> rt/Makefile | 1 -
> support/temp_file.c | 23 +++
> support/temp_file.h | 6 +
> sysdeps/generic/sigcontextinfo.h | 15 ++
> sysdeps/generic/sysdep-cancel.h | 3 -
> sysdeps/i386/nptl/tls.h | 11 --
> sysdeps/mips/nptl/tls.h | 2 +-
> sysdeps/nptl/Makefile | 3 +-
> sysdeps/nptl/aio_misc.h | 13 +-
> sysdeps/nptl/gai_misc.h | 13 +-
> sysdeps/nptl/lowlevellock.h | 5 +-
> sysdeps/posix/open64.c | 12 +-
> sysdeps/posix/pause.c | 2 -
> sysdeps/posix/sigpause.c | 3 -
> sysdeps/posix/sigwait.c | 9 +-
> sysdeps/posix/waitid.c | 11 +-
> sysdeps/sh/sysdep.h | 1 +
> sysdeps/sparc/sparc32/lowlevellock.c | 3 +-
> sysdeps/unix/sysdep.h | 118 ++++++++++--
> sysdeps/unix/sysv/linux/aarch64/sigcontextinfo.h | 11 ++
> sysdeps/unix/sysv/linux/alpha/sigcontextinfo.h | 13 ++
> sysdeps/unix/sysv/linux/arm/sigcontextinfo.h | 12 ++
> sysdeps/unix/sysv/linux/arm/syscall_cancel.S | 69 +++++++
> sysdeps/unix/sysv/linux/clock_nanosleep.c | 20 +--
> sysdeps/unix/sysv/linux/creat.c | 2 -
> sysdeps/unix/sysv/linux/creat64.c | 2 -
> sysdeps/unix/sysv/linux/futex-internal.h | 18 +-
> .../sysv/linux/hppa/sigcontextinfo.h} | 26 ++-
> sysdeps/unix/sysv/linux/hppa/syscall_cancel.S | 82 +++++++++
> sysdeps/unix/sysv/linux/i386/Makefile | 2 +-
> sysdeps/unix/sysv/linux/i386/lowlevellock.h | 2 +-
> sysdeps/unix/sysv/linux/i386/sigcontextinfo.h | 13 ++
> sysdeps/unix/sysv/linux/i386/syscall_cancel.S | 107 +++++++++++
> sysdeps/unix/sysv/linux/ia64/sigcontextinfo.h | 24 +++
> sysdeps/unix/sysv/linux/ia64/syscall_cancel.S | 94 ++++++++++
> sysdeps/unix/sysv/linux/lowlevellock-futex.h | 34 +++-
> sysdeps/unix/sysv/linux/m68k/sigcontextinfo.h | 13 ++
> .../unix/sysv/linux/microblaze/sigcontextinfo.h | 13 ++
> .../unix/sysv/linux/microblaze/syscall_cancel.S | 62 +++++++
> .../unix/sysv/linux/mips/mips32/syscall_cancel.S | 128 +++++++++++++
> sysdeps/unix/sysv/linux/mips/mips32/sysdep.h | 4 +
> sysdeps/unix/sysv/linux/mips/sigcontextinfo.h | 13 +-
> sysdeps/unix/sysv/linux/nios2/sigcontextinfo.h | 16 ++
> sysdeps/unix/sysv/linux/powerpc/sigcontextinfo.h | 16 ++
> sysdeps/unix/sysv/linux/powerpc/syscall.S | 14 ++
> sysdeps/unix/sysv/linux/powerpc/syscall_cancel.S | 64 +++++++
> sysdeps/unix/sysv/linux/pthread_kill.c | 5 +-
> sysdeps/unix/sysv/linux/s390/sigcontextinfo.h | 17 ++
> sysdeps/unix/sysv/linux/sh/sigcontextinfo.h | 11 ++
> sysdeps/unix/sysv/linux/sh/syscall_cancel.S | 125 +++++++++++++
> sysdeps/unix/sysv/linux/sigwait.c | 3 -
> sysdeps/unix/sysv/linux/sigwaitinfo.c | 3 -
> sysdeps/unix/sysv/linux/socketcall.h | 37 +++-
> sysdeps/unix/sysv/linux/sparc/lowlevellock.h | 2 +-
> .../unix/sysv/linux/sparc/sparc32/sigcontextinfo.h | 52 ++++++
> .../unix/sysv/linux/sparc/sparc32/syscall_cancel.S | 74 ++++++++
> .../libc-cancellation.S => sparc/sparc64/pause.c} | 14 +-
> .../unix/sysv/linux/sparc/sparc64/sigcontextinfo.h | 40 +++++
> .../unix/sysv/linux/sparc/sparc64/syscall_cancel.S | 74 ++++++++
> sysdeps/unix/sysv/linux/syscall_cancel.c | 63 +++++++
> sysdeps/unix/sysv/linux/sysdep.h | 17 ++
> sysdeps/unix/sysv/linux/tile/sigcontextinfo.h | 12 ++
> sysdeps/unix/sysv/linux/x86_64/cancellation.S | 115 ------------
> .../unix/sysv/linux/x86_64/librt-cancellation.S | 21 ---
> sysdeps/unix/sysv/linux/x86_64/lowlevellock.h | 8 +-
> sysdeps/unix/sysv/linux/x86_64/sigcontextinfo.h | 11 ++
> sysdeps/unix/sysv/linux/x86_64/x32/sysdep.h | 13 ++
> sysdeps/x86_64/nptl/tcb-offsets.sym | 1 -
> sysdeps/x86_64/nptl/tls.h | 11 --
> 96 files changed, 2052 insertions(+), 717 deletions(-)
> delete mode 100644 nptl/cancellation.c
> delete mode 100644 nptl/tst-cancel-wrappers.sh
> create mode 100644 nptl/tst-cancel28.c
> create mode 100644 sysdeps/unix/sysv/linux/arm/syscall_cancel.S
> rename sysdeps/{nptl/librt-cancellation.c => unix/sysv/linux/hppa/sigcontextinfo.h} (55%)
> create mode 100644 sysdeps/unix/sysv/linux/hppa/syscall_cancel.S
> create mode 100644 sysdeps/unix/sysv/linux/i386/syscall_cancel.S
> create mode 100644 sysdeps/unix/sysv/linux/ia64/syscall_cancel.S
> create mode 100644 sysdeps/unix/sysv/linux/microblaze/syscall_cancel.S
> create mode 100644 sysdeps/unix/sysv/linux/mips/mips32/syscall_cancel.S
> create mode 100644 sysdeps/unix/sysv/linux/powerpc/syscall_cancel.S
> create mode 100644 sysdeps/unix/sysv/linux/sh/syscall_cancel.S
> create mode 100644 sysdeps/unix/sysv/linux/sparc/sparc32/syscall_cancel.S
> rename sysdeps/unix/sysv/linux/{x86_64/libc-cancellation.S => sparc/sparc64/pause.c} (66%)
> create mode 100644 sysdeps/unix/sysv/linux/sparc/sparc64/syscall_cancel.S
> create mode 100644 sysdeps/unix/sysv/linux/syscall_cancel.c
> delete mode 100644 sysdeps/unix/sysv/linux/x86_64/cancellation.S
> delete mode 100644 sysdeps/unix/sysv/linux/x86_64/librt-cancellation.S
>
> --
> 2.7.4