From patchwork Mon Feb 26 21:03:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 129713 Delivered-To: patch@linaro.org Received: by 10.80.172.228 with SMTP id x91csp4291588edc; Mon, 26 Feb 2018 13:06:02 -0800 (PST) X-Google-Smtp-Source: AG47ELvqbSj3lOBUM8R3eP/Ok57f9nX08Etn+1MTvfeW1NTRXL8+6PCtk6l8GaSnTmb7U457tMSB X-Received: by 2002:a17:902:4581:: with SMTP id n1-v6mr10168693pld.135.1519679162336; Mon, 26 Feb 2018 13:06:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519679162; cv=none; d=google.com; s=arc-20160816; b=VfSz40i0yITdzpVCQySbN2N7yfkQUMcJfdIK0X59db0PaTUiui+bcHzcRTBdcHn3V0 tFUcj0D7jrPC3wJNjResl25r82sOqHi7ecILsiAcupvJUUUAwKVVYAMEZTQ8AuVycRoE rndV/n6HYXbWaOUFiG4A5rN66UQOW5smF3Pa7MNAVojNUAMD3AxyBmJuMGc7gwSLAkP0 h6tN1BjhG4G4LFODUM0NPIAp07KTme+iVP5xKfLF5zVwaCWJKmWkU1FS4+2DTc4qZ+fB AI2OhyVd5dgaYEDLyIAFhcs03k9SCQDNT9cw/6Kmh3X6GvtskiCahmudfTLZj/FMFPpf pwfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to: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=ApupUdJe2TrABzclDCvN56i2vD5eamKA5f/yCq1t9uw=; b=RsqCCo8as8i+RV2JVC09I4Nt+6UvngiHz2nuoBUtGf3f8Nh1BkipC6+klsQPKsk8ix 1uUMkY0X3wcGCWtMcqe1xdEiRPSq1rBeu4xQDKJ5kjp88vQ/IeVqq7Oi8sZ6Yhjda9wU 1JlnHqMziDC6yJkbJRa3cpbkNqyXO3T8LtdTtlOwF3lMfZ9/lGuMCYr2B8tND4A2NLHV AaJ1jcT25xfAjhZWT1YdUFbtlZa8uuNSDy22UeUM0+6Z2TpMeCXVXJeYFgtKa3vzoyUO WyQmvyaOWHUdTrvUElX2PMJvJWchCXN/7K1+Klx6KGjMbN725sWLl2kOrCRlhQoHuKUK AJiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=Vc+hJMKg; spf=pass (google.com: domain of libc-alpha-return-90628-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-90628-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 r6si7298055pfl.304.2018.02.26.13.06.01 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Feb 2018 13:06:02 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-90628-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=Vc+hJMKg; spf=pass (google.com: domain of libc-alpha-return-90628-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-90628-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:in-reply-to :references; q=dns; s=default; b=VpLquGPUz8Abvd1MoQ69NjxumhftXRI Ktc7isnxYvoFj4A/ENpBDynYWQbSPtp9dvGBtEyA+Qam021aB4uWNMffrSbnKHJ4 N0qA3d8DUgojBmVapGDpyyRqQNB8iWNnVIpnsy7fwzWxMZWe9w1GK6vpcpxd2rg3 +ljPM1ygdCxc= 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:in-reply-to :references; s=default; bh=8KIppOTzTCWZ97F5krfWa0pjP3s=; b=Vc+hJ MKgxFF80L9G67RigNhfbFsHA9IWBeHevLB2CaSAjPzjtvISM6FsvhP5EEGcR+QN7 FtKgwPftWCBlueuGhUYgRq/Dr+3fBqajejky2LN5T9sih9y70k60nK5LQxJ2D7wj VJmlahIjWaUmkN5dJ6rAlnOWtdyHNbTXo6BrN4= Received: (qmail 76987 invoked by alias); 26 Feb 2018 21:04:08 -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 76497 invoked by uid 89); 26 Feb 2018 21:04:05 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=r48 X-HELO: mail-qt0-f196.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:in-reply-to :references; bh=ApupUdJe2TrABzclDCvN56i2vD5eamKA5f/yCq1t9uw=; b=UA7BxrXa7Hhy+PvBF8Ow2FaRQBfuSUIaZryJKfKDPOX5Ehcn56v9MbnANjPNtX8Q6e d9UYc/wlwZk4OOQ89NLi/j/hXzdU8vBQu9A9rniTzuQ6PjLtttHsyqsMD6bEKACccip5 dk+KHO+6POOlFP7V61a8IMVRh4v0h7Hp6BBmn7FFzyxmyjybXS6urU/B0+bil15iOoXm vTy2bMUCOs2UH1es+dHBkAODggzVIvsDL3eDwG0bSPizl0H0gjc0CJDz2vLEf8Iylekf HGj7yAURZ7r4Fgu4+R8kQlRrk1RUBbfCZLPFHVfhVK3KV47Ve4G4CGdljo1HDBHUpY2j 5bWw== X-Gm-Message-State: APf1xPCq98iHaSsy3rvffhqYDMmXyF6EEwaPHimtF4+G0KYSCBxADq2M 1iHQsWg6NyvOAMJJXHWEGWg8DUXFAWM= X-Received: by 10.200.68.15 with SMTP id j15mr18833186qtn.60.1519679040560; Mon, 26 Feb 2018 13:04:00 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH v2 11/21] nptl: ia64: Fix Race conditions in pthread cancellation (BZ#12683) Date: Mon, 26 Feb 2018 18:03:26 -0300 Message-Id: <1519679016-12241-12-git-send-email-adhemerval.zanella@linaro.org> In-Reply-To: <1519679016-12241-1-git-send-email-adhemerval.zanella@linaro.org> References: <1519679016-12241-1-git-send-email-adhemerval.zanella@linaro.org> This patch adds the s390 modifications required for the BZ#12683. It basically adds the required ucontext_get_pc function. a workaround for mismatched sigcontext::sa_flags defiition between kernel and GLIBC (tracked by BZ#21634), and an arch specific syscall_cancel implementation. IA64 requires an arch-specific syscall_cancel implemetantion because {INLINE,INTERNAL}_SYSCALL is implemented by branching to a gate DSO (similar to i386) which renders the pointer comparison in SIGCANCEL handler wrong. This incurs in performance penalty due the use of a break instruction insteaf of a eds one, however cancellable syscalls should potentially incur in syscalls blocking. Checked with a ia64-linux-gnu build with run-tests-built=no. [BZ #12683] * sysdeps/unix/sysv/linux/ia64/sigcontextinfo.h (ucontext_get_pc, ucontext_get_mask): New functions. * sysdeps/unix/sysv/linux/ia64/syscall_cancel.S: New file. --- ChangeLog | 5 ++ sysdeps/unix/sysv/linux/ia64/sigcontextinfo.h | 24 +++++++ sysdeps/unix/sysv/linux/ia64/syscall_cancel.S | 94 +++++++++++++++++++++++++++ 3 files changed, 123 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/ia64/syscall_cancel.S -- 2.7.4 diff --git a/sysdeps/unix/sysv/linux/ia64/sigcontextinfo.h b/sysdeps/unix/sysv/linux/ia64/sigcontextinfo.h index 214292d..24cfb51 100644 --- a/sysdeps/unix/sysv/linux/ia64/sigcontextinfo.h +++ b/sysdeps/unix/sysv/linux/ia64/sigcontextinfo.h @@ -15,6 +15,11 @@ License along with the GNU C Library; if not, see . */ +#ifndef _SIGCONTEXTINFO_H +#define _SIGCONTEXTINFO_H + +#include + #define SIGCONTEXT siginfo_t *_si, struct sigcontext * #define SIGCONTEXT_EXTRA_ARGS _si, #define GET_PC(ctx) ((ctx)->sc_ip) @@ -23,3 +28,22 @@ #define CALL_SIGHANDLER(handler, signo, ctx) \ (handler)((signo), SIGCONTEXT_EXTRA_ARGS (ctx)) + +/* Different that other architectures, ia64 pass a sigcontext_t struct + in third argument for sa_sigaction handler with SA_SIGINFO. */ +static inline uintptr_t +ucontext_get_pc (const struct sigcontext *sigctx) +{ + return sigctx->sc_ip; +} + +static inline sigset_t * +ucontext_get_mask (const struct sigcontext *sigctx) +{ + /* IA64 sigcontext::sa_mask is a sigset_t since Linux 2.6.12 (initial + git repository build). */ + return (sigset_t *) &sigctx->sc_mask; +} +#define UCONTEXT_SIGMASK(ctx) ucontext_get_mask (ctx) + +#endif /* _SIGCONTEXTINFO_H */ diff --git a/sysdeps/unix/sysv/linux/ia64/syscall_cancel.S b/sysdeps/unix/sysv/linux/ia64/syscall_cancel.S new file mode 100644 index 0000000..9c6c9d3 --- /dev/null +++ b/sysdeps/unix/sysv/linux/ia64/syscall_cancel.S @@ -0,0 +1,94 @@ +/* Cancellable syscall wrapper. Linux/IA64 version. + Copyright (C) 2017 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#undef ret + +/* long int __syscall_cancel_arch (int *cancelhandling, long int nr, + long int arg1, long int arg2, long int arg3, + long int arg4, long int arg5, long int arg6) +*/ + +ENTRY (__syscall_cancel_arch) + .prologue 14, 40 + .mmi + .save ar.pfs, r41 + alloc r41 = ar.pfs, 8, 4, 8, 0 + .vframe r42 + mov r42 = r12 + .save rp, r40 + mov r40 = b0 + .body + ;; + + .global __syscall_cancel_arch_start + .type __syscall_cancel_arch_start,@function +__syscall_cancel_arch_start: + + ;; + .mmi + nop 0 + ld4.acq r14 = [r32] + nop 0 + ;; + .mib + nop 0 + tbit.z p6, p7 = r14, 2 + .pred.safe_across_calls p1-p63 + (p7) br.call.dpnt.many b0 = __syscall_do_cancel# + .pred.safe_across_calls p1-p5,p16-p63 + ;; + .mmi + mov r15 = r33 + mov r49 = r39 + mov r48 = r38 + .mmi + mov r47 = r37 + mov r46 = r36 + mov r45 = r35 + ;; + .mmi + nop 0 + mov r44 = r34 + nop 0 + ;; + break 0x100000 + ;; + + .global __syscall_cancel_arch_end + .type __syscall_cancel_arch_end,@function +__syscall_cancel_arch_end: + + ;; + .mmi + cmp.ne p6, p7 = -1, r10 + nop 0 + mov ar.pfs = r41 + ;; + .mmi + nop 0 + (p7) sub r8 = r0, r8 + mov b0 = r40 + .mmb + nop 0 + .restore sp + mov r12 = r42 + br.ret.sptk.many b0 + +END (__syscall_cancel_arch) +libc_hidden_def (__syscall_cancel_arch)