From patchwork Mon Dec 11 19:06:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 121437 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp3166975qgn; Mon, 11 Dec 2017 11:07:38 -0800 (PST) X-Google-Smtp-Source: ACJfBotg7fR8PzPI8Bwaxf3rXV/EFlyKz/ecTtm8SfO/IjbiqhBVyJTHR91TfHIwriCkQH8jGOzt X-Received: by 10.98.147.215 with SMTP id r84mr1297762pfk.17.1513019258587; Mon, 11 Dec 2017 11:07:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1513019258; cv=none; d=google.com; s=arc-20160816; b=G9d86lt50BoUt1TzqSefrK12H2xJRPGJgtaH/oWYsHRiBw1xOeH4+vmR241AbBIWFg kw0o2PhvPLnFYqiAGxjGtHmQPdvCc1x55yZmJQfEMr6Rcyk6anRRktLbvIe/oTBsxrYX QgdnNoIR5+f+cbL95S3S1k5FgW4O/xNHbAf9bu2llMhZCaf91RVQJWXNihqBOl/qeB7+ dvVxMO2ebRxF7WSPES3CfNzFRqMqY1Zifcwi43bb+Q/Zr836WXQLwbkWcH926TFADHYR EjX/hdPd0Jn55tZaX6KZ2PZjaSetv24Mu01+WF39DV/w0+pP2NfPvjlFmg8FmfOnO0Nj isxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:to:from:delivered-to:sender:list-help :list-post:list-archive:list-subscribe:list-unsubscribe:list-id :precedence:mailing-list:dkim-signature:domainkey-signature :arc-authentication-results; bh=Bv5W98xu37vT+MgdtUhHZn23Nos8x8+3AsGEAetFdTs=; b=eB2UqYPm2QPMp3YCVwVa8FTQLsrZ9ZSg4BB974/L2ThjM0tutAYQoE5cf+5yBGaUWn cAU+cJENs5OwC3lokWR+l3Dip7IxyUMCEFLCoWwl9UbBW/Z/CvZoYYW9CHSGykap0HWK dIKVEvLr0WV/m+ZDnNkNtxnlU8OUAoozwiQjG/PIbmNMs5OqdjFb2gNppp8zo5HW6oK7 z1cBnsCxznf8IHhtuM+n7SyfWSv969hS8r5MGfT+/iKkAURze/cPaFLTXeo0VvzU/Eel ONgFuBx9DebjN+5IiBUKU7YwJyr9zIjERtQWqbYS8Mb0zj8mAzJuUrNjojO8mSrexExn aHCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=h5Nvu0bt; spf=pass (google.com: domain of libc-alpha-return-88014-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-88014-patch=linaro.org@sourceware.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id f23si7056822pgv.509.2017.12.11.11.07.38 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 Dec 2017 11:07:38 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-88014-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=h5Nvu0bt; spf=pass (google.com: domain of libc-alpha-return-88014-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-88014-patch=linaro.org@sourceware.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id; q=dns; s= default; b=xnTGxYfaq51lxP8hoPBKfjObGYYOAJiiTwM4SSDKf4NVnRfhjztVH 5KwDSg2dAxROvmSR5c66yhyDJArO4O7tNJVIruVPJRJFg8Aon6VAl/b5g/uy/SmQ CCunuB3z7i7WmH/HOlY6B6gxzEf9kh160QRiLaAnPlGjvw1Z9w8bYI= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id; s=default; bh=7qlaktpdsx9M44JjvvTOoGHJp5o=; b=h5Nvu0bte2VWoQxDoHrbEb4Rbh9k xwi3wSvtNz0wCZhTgyy3xAMkVij4cKz81j89MkXro+MZJ3TP3EKP8KRfc65ubF1q Szisp+VlKa0o+hM+N5pO+dH9J+Fv15MNjtggrsokdd+BfMmQRzq9fdlSVc7KoJ8z 24CTnWvMmvNeXYc= Received: (qmail 40479 invoked by alias); 11 Dec 2017 19:07:16 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 40451 invoked by uid 89); 11 Dec 2017 19:07:14 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-12.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=accomplish, sk:sparcv9, hppa X-HELO: mail-qt0-f179.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=Bv5W98xu37vT+MgdtUhHZn23Nos8x8+3AsGEAetFdTs=; b=kzDwp8sqR0SKAlsuEEBl1BDb8XVextMUaQXENFYFwJUTUPj7VBNDy5M9DNTln38xTk 62BZcorkTA4LmNsNnOsLF27tDlnlKdbCGIxLCk351ZQcRztGYoBTDmgVRxJ6rnTw9LAF o0jVLpdQWm07R4fKdNcyxrvUOwlVxv66YnxLWUn4QMTnWgX3meNgcVzSrjt8js0owQXN nQvoBMxcyPX6b5yCZW1TzWda75EbIfJcyeCLOOIltKyBwJZfpl4sltRJ39qVZq/HyLQ6 0Gov5wH2MoqiMOodUikXkR8xibwtD4eNEDMjHR2a6piPU8WSrZA9XgtKvvCxWm+L4XwK np1g== X-Gm-Message-State: AKGB3mL5WT+GNGl/Ab12ZMbscf8+U2hHOUslzOBQ/4a+mvvneyipYiSb 5if2VgHp7mZp74rvovtswJZ3KwIL21g= X-Received: by 10.55.19.158 with SMTP id 30mr2051646qkt.0.1513019229999; Mon, 11 Dec 2017 11:07:09 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH 00/19] nptl: Fix Race conditions in pthread cancellation (BZ#12683) Date: Mon, 11 Dec 2017 17:06:44 -0200 Message-Id: <1513019223-7603-1-git-send-email-adhemerval.zanella@linaro.org> 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//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