From patchwork Mon Feb 26 21:03:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 129702 Delivered-To: patch@linaro.org Received: by 10.80.172.228 with SMTP id x91csp4289528edc; Mon, 26 Feb 2018 13:03:59 -0800 (PST) X-Google-Smtp-Source: AG47ELv9++xpZToOGFzzJuU0SgRm72NZLqh8Ze8UeVheBzrZJk00hTuCDMJg3qC9+8nC/7vUMX3W X-Received: by 2002:a17:902:4203:: with SMTP id g3-v6mr6368758pld.143.1519679039653; Mon, 26 Feb 2018 13:03:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519679039; cv=none; d=google.com; s=arc-20160816; b=zdwYv3iImMk+X7ZtiOLjtRYRmE0hEQpivLMXvrJv5FjBtq7exqNejF5RKytfneZlZC PWjuAjYQ9D1gjvp/WRAiKlSc6Y9ZdO85YjNIPft8TeOlEIY9rExw1Ojk81p90xonNaRC efb6tTalXrLzdrHMJ0z3+Pu7Tuy75lJYkCK3BXlOsZeYKIHLBqIkpqyQHtfVXhc6bquj bKcpfICvsQL/hWMAnY7OBcRbTdabtgoIuu9ZrmDJZKw4Th08qf+J9XzNXbOVuAUaVYBc GKEskfwG401Q+PYAH71Lh1Ypa5SG+rLlOSa8iWlSTGDfZ97IydqOfSJ5DvEt8yTaBANT 1cKQ== 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=7rJUZ/2PnzRy3pNlmT8RDxltSHh/W0KAjEtLfwj1ZOA=; b=Q4mMJYA3XtmuieD3IGj72z/PCHEfokeAr1lhlw4vLiTHUvmkl8nhCIXgyINiQgNhfy 2QfErDQ95U+hknnEfuOko3kHQEJJKc07b1dzwXD1St0akTBr+eKJA5xWWT3AWQJDJ4dj myqjHft6gAXYY12KsvVrrA4B9RoKxAGcLG4gg3qcx9zwodXOQutnERbFOESJvUSsWUpJ y+G5obM65OkPYNwIaeQP1a7xxzhn36ttEKtB8k9ltBXk/PQWALD47e/NOeDG1fTGEqem qGh3J7zDUD/IFfV8WzTW8ChMtYCsFfZhEcBSUGNkdtjdZqCX8LxPEfbXtMXoOSNcCH7/ jOjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=fyRK2H+t; spf=pass (google.com: domain of libc-alpha-return-90617-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-90617-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 p25si6021427pgn.151.2018.02.26.13.03.59 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Feb 2018 13:03:59 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-90617-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=fyRK2H+t; spf=pass (google.com: domain of libc-alpha-return-90617-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-90617-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=DyVSWB6lzs/j0r6pGHWGYIUfgFHSrsK qw8mdHj5URgLK+4vcX5VudGwaupebwRYtWP5ae8XkKspziMZ992LQVk72ab8IpJa O0pO0Y4e4xoV6VsOyLI5KtGmOiJ4IuedwTzpjKlFapFW58jlDCp98eXkql4/K3Cp N46cSDLdwS5E= 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=CtONDVwzbIr/Tn5CJTCBFJhgYJg=; b=fyRK2 H+tyVE/7k7APSv7wNCw07ZSFNycMPcLLdyZ0YwGfFZZcaHlfUI2Vklq3r+BO0flq k+LyCOYaC28EvtBHiN/oVmYghP9qGMwTGzudhKd47wx63x42BcHSijcSPTZgBCFE DZnhwvLBB3ikCQn1CAZqE1avFliswVsfYjA02I= Received: (qmail 73689 invoked by alias); 26 Feb 2018 21:03:48 -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 73127 invoked by uid 89); 26 Feb 2018 21:03:47 -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, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-qt0-f180.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=7rJUZ/2PnzRy3pNlmT8RDxltSHh/W0KAjEtLfwj1ZOA=; b=X5UIt/Q4oqBF2RMniJZbdUccfcP8et/DIZt6fDjYcd+X9LAE9/RIyD/B836LsqYHG1 N37iHQr/MlPh9NlUkE+IIzAhzS+CQdgqURweB9BzMvacqVL8Z2lhQrgiIx0rIuD4jvdT PykF9JgpnxIPki8oaUfPrjhqQBrI/N1rBkr4uxy3DUkzsgxbnEgGtdejda6L45z1HW8u IF1HjzL9rru9iqI16OaZ2u7Q0aPVXVlOBmhCaxLbHA9A2VOdapaxGFvmaUDnxdqWgQm1 vnYXGXaVrnYmP36HaBVn3MIA4G6CcEJ1V+ExCzWkCGVpLTBswYqXI5O2GEhK/XwNGrsh 51xg== X-Gm-Message-State: APf1xPCP2lviNrtXTtGIY/VgLe7cR7L6RLdwnHgYoWTqTrwnR/64FTl/ huummD7RFB0gUxVa/zA6qfKYkoVUQFc= X-Received: by 10.200.58.230 with SMTP id x93mr19951005qte.72.1519679024799; Mon, 26 Feb 2018 13:03:44 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH v2 01/21] powerpc: Create stackframe information on syscall Date: Mon, 26 Feb 2018 18:03:16 -0300 Message-Id: <1519679016-12241-2-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 a minimal stackframe creation on powerpc syscall implementation so backtrace works correctly on a signal handler. Checked on powerpc64le-linux-gnu. * sysdeps/unix/sysv/linux/powerpc/syscall.S (syscall): Create stack frame. --- ChangeLog | 3 +++ sysdeps/unix/sysv/linux/powerpc/syscall.S | 14 ++++++++++++++ 2 files changed, 17 insertions(+) -- 2.7.4 diff --git a/sysdeps/unix/sysv/linux/powerpc/syscall.S b/sysdeps/unix/sysv/linux/powerpc/syscall.S index 2da9172..fae0fe8 100644 --- a/sysdeps/unix/sysv/linux/powerpc/syscall.S +++ b/sysdeps/unix/sysv/linux/powerpc/syscall.S @@ -19,6 +19,14 @@ ENTRY (syscall) ABORT_TRANSACTION + /* Creates a minimum stack frame so backtrace works. */ +#ifdef __powerpc64__ + stdu r1, -FRAME_MIN_SIZE (r1) + cfi_adjust_cfa_offset (FRAME_MIN_SIZE) +#else + stwu r1,-16(1) + cfi_def_cfa_offset (16) +#endif mr r0,r3 mr r3,r4 mr r4,r5 @@ -26,6 +34,12 @@ ENTRY (syscall) mr r6,r7 mr r7,r8 mr r8,r9 +#ifdef __powerpc64__ + addi r1, r1, FRAME_MIN_SIZE +#else + addi r1,r1,16 +#endif + cfi_def_cfa_offset (0) sc PSEUDO_RET PSEUDO_END (syscall) From patchwork Mon Feb 26 21:03:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 129704 Delivered-To: patch@linaro.org Received: by 10.80.172.228 with SMTP id x91csp4289892edc; Mon, 26 Feb 2018 13:04:21 -0800 (PST) X-Google-Smtp-Source: AH8x226jj4R6g7VaoJ8o450dVRcCuXgk37zS/dn2PIfP7Y2vZe7Ne/EMXUgt9PidGJJ23hPc2vKQ X-Received: by 10.101.91.193 with SMTP id o1mr9689421pgr.315.1519679061318; Mon, 26 Feb 2018 13:04:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519679061; cv=none; d=google.com; s=arc-20160816; b=OVaqQ+me9bLgIA0KEZQ6qAxIqg3+iNU4I9OLAZoauoQNRhmn3ETuLfmzMDl9ALf+Tj mWjRny4lyy45MLNZBApd/AXdfyjyV2kAowjnEi7joNIX+hkl615qz/5QL/TVjFCbiDPA HK/IdU9X00RJmjj4vCB5LaGE8UB5cJzXlBISgM098jbvmgtKxuQZ9Qk76y7If7Mz2dKp oIxnJWeipKoB8Rdcsh3NUH/dGAJSisQ2/ybB0+uNsW0ea0g4YuAYZ7tyqqX0Su6AkeQU qVdfKwMdxxYYb0Ylmo/bQr2sb9E+pOT/fOCRI+znEa66WQ6VizMX//4riIdlOhdttG87 YGtQ== 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:cc: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=3l0zgsESuphvlMG4D9KuxssfKvSKNnyXxUa9aSL9zfg=; b=xWZvcHW9WFxI5Asgr1z3op2cNQCmgUfZ8dtzlv6gcPDFJf7SZAyusbF75uNQKgx53V Ej05JKusjpmfx5+fm/5Q3C7B5wEizQFxdra9suhFpnB/TJWLWHaPJ8Hxx7wfy2jKVPjy UdL0D1Ron7PRobcdp5CbPOD3gPxOEX7BLsm3t07VJSitoDXQxCgGvrkj4rAiqqM09krF E4xNx2/bWOkMlMEKG4gCyD+Hs5XS906OLAZB5md3rED2WQr7AqP0U1XqBMy7B/1LcGqP iOJ9YZTdo52GZQp3phE5tjWVoF7TfHP236egklVITZUHke8TvNLArQr436KCRuf/ka/W ekFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=uywM3OtU; spf=pass (google.com: domain of libc-alpha-return-90619-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-90619-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 m22si5969588pgv.643.2018.02.26.13.04.20 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Feb 2018 13:04:21 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-90619-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=uywM3OtU; spf=pass (google.com: domain of libc-alpha-return-90619-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-90619-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:cc:subject:date:message-id:in-reply-to :references; q=dns; s=default; b=qH3G2MQhSI6Wr+8E7IujKi4Wv4ZHl7r 7GRp7goWp77nkATp5rph3KGjITio8CzXLvRaZ0TOVB9DjjfNeweZl1WKZU8/fWo3 bgZ0UMCpLJOhhd69ClqvY6Ywh2URrIUpJe/RmsltDby6GXdrDTUmdl2rvN8hlNSX qg9piAZZJBuk= 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:cc:subject:date:message-id:in-reply-to :references; s=default; bh=Bvssc1gA//UB2OrBe+3dG+3obhU=; b=uywM3 OtUXlNc0vjoCtI6tGP4XnldbgPtrOhXNnbXcw87fjOCIK55KRrHmL27vqNPGDIvd faMcoJwT/mWifQ6IEI4aKEyLu4KGQS4dE+J8qsJM+xreTrTbnkB1frKlbLaQA+10 /2TJ6A4TzmpIbHZkPzWZf5XG2hVsuf9ROs2pjs= Received: (qmail 74563 invoked by alias); 26 Feb 2018 21:03:52 -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 74436 invoked by uid 89); 26 Feb 2018 21:03:51 -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= X-HELO: mail-qk0-f177.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:cc:subject:date:message-id:in-reply-to :references; bh=3l0zgsESuphvlMG4D9KuxssfKvSKNnyXxUa9aSL9zfg=; b=GJM56/lDL2y++tkuxEy9HQPCsSWokH8bVgPmdp9+ZLCasZOp3qKxlB+hjdkLdz241l zbKTvX0/7Z93TMm2KpixsDeW+YZomkBuzN11sEGza4bH7aHrM9XyRGhbLMsEes9yuQ8v j/bsJ6kPSixc6qha5vWyKRkooPZJ7elTFPVSBK/dn57jYO4saQw/hZLjxJ6xCwjd5VKN WEDtonMCfvqHaxe0YEPLY9J+GPspgzQSotOh6DPetSvwCUXGftlYPnyxNQxMhjbR9v4l wFquvHIIJpoRrlatyImwVXHRo1HDb3KDUCsuXe7sEPxI4VyNfDUKVSpWmZVBBA6wmF6D XF7Q== X-Gm-Message-State: APf1xPBFS0HOnQf7V6S37FX/0EDgo9te85wPOJQl6WrKAUqGaDz1dvLt jB5LHULSsAk9AUtfi0/cqJks0rT8BhY= X-Received: by 10.55.207.82 with SMTP id e79mr15191264qkj.219.1519679026433; Mon, 26 Feb 2018 13:03:46 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Adhemerval Zanella Subject: [PATCH v2 02/21] nptl: Fix testcases for new pthread cancellation mechanism Date: Mon, 26 Feb 2018 18:03:17 -0300 Message-Id: <1519679016-12241-3-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> From: Adhemerval Zanella With upcoming fix for BZ#12683, pthread cancellation does not act for: 1. If syscall is blocked but with some side effects already having taken place (e.g. a partial read or write). 2. After the syscall has returned. The main change is due the fact programs need to act in syscalls with side-effects (for instance, to avoid leak of allocated resources or handle partial read/write). This patch changes the NPTL testcase that assumes the old behavior and also remove the tst-cancel-wrappers.sh test (which checks for symbols that will not exist anymore). For tst-cancel{2,3} case it remove the pipe close because it might cause the write syscall to return with side effects if the close is executed before the pthread cancel. It also changes how to call the read syscall on tst-backtrace{5,6} to use syscall instead of read cancelable syscall to avoid need to handle the cancelable bridge function calls. It requires a change on powerpc syscall implementation to create a stackframe, since powerpc backtrace rely on such information. Checked on i686-linux-gnu, x86_64-linux-gnu, x86_64-linux-gnux32, aarch64-linux-gnu, arm-linux-gnueabihf, powerpc64le-linux-gnu, powerpc-linux-gnu, sparcv9-linux-gnu, and sparc64-linux-gnu. * debug/tst-backtrace5.c (handle_signal): Check for syscall instead of read. (fn): Issue the read syscall instead of call the cancellable syscall. * nptl/Makefile [$(run-built-tests) = yes] (tests-special): Remove tst-cancel-wrappers.sh. * nptl/tst-cancel-wrappers.sh: Remove file. * nptl/tst-cancel2.c (do_test): Do not close pipe. * nptl/tst-cancel3.c (do_test): Likewise. * nptl/tst-cancel4.c (tf_write): Handle cancelled syscall with side-effects. (tf_send): Likewise. * sysdeps/unix/sysv/linux/powerpc/syscall.S (syscall): Create stack frame. --- ChangeLog | 14 ++++++- debug/tst-backtrace5.c | 28 ++++++++------ nptl/Makefile | 17 +-------- nptl/tst-cancel-wrappers.sh | 92 --------------------------------------------- nptl/tst-cancel2.c | 3 -- nptl/tst-cancel3.c | 3 -- nptl/tst-cancel4.c | 8 ++++ 7 files changed, 39 insertions(+), 126 deletions(-) delete mode 100644 nptl/tst-cancel-wrappers.sh -- 2.7.4 diff --git a/debug/tst-backtrace5.c b/debug/tst-backtrace5.c index 0e6fb1a..a6d66c8 100644 --- a/debug/tst-backtrace5.c +++ b/debug/tst-backtrace5.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -33,7 +34,7 @@ #endif /* The backtrace should include at least handle_signal, a signal - trampoline, read, 3 * fn, and do_test. */ + trampoline, syscall, 3 * fn, and do_test. */ #define NUM_FUNCTIONS 7 void @@ -71,16 +72,18 @@ handle_signal (int signum) } /* Do not check name for signal trampoline. */ i = 2; - if (!match (symbols[i++], "read")) + + if (match (symbols[i], "__kernel_vsyscall")) + i++; + + /* We are using syscall(...) instead of read. */ + if (!match (symbols[i++], "syscall")) { - /* Perhaps symbols[2] is __kernel_vsyscall? */ - if (!match (symbols[i++], "read")) - { - FAIL (); - return; - } + FAIL (); + return; } - for (; i < n - 1; i++) + + for (; i < n - 2; i++) if (!match (symbols[i], "fn")) { FAIL (); @@ -123,8 +126,11 @@ fn (int c, int flags) _exit (0); } - /* In the parent. */ - read (pipefd[0], r, 1); + /* To avoid need to handle cancellation syscall backtrace (which call + the function using both the generic bridge (__syscall_cancel) and + the architecture defined one (__syscall_cancel_arch), issue the + syscall directly. */ + syscall (__NR_read, pipefd[0], r, 1); return 0; } diff --git a/nptl/Makefile b/nptl/Makefile index de37fb4..76ecf6c 100644 --- a/nptl/Makefile +++ b/nptl/Makefile @@ -452,8 +452,7 @@ tests-reverse += tst-cancel5 tst-cancel23 tst-vfork1x tst-vfork2x ifeq ($(run-built-tests),yes) tests-special += $(objpfx)tst-stack3-mem.out $(objpfx)tst-oddstacklimit.out ifeq ($(build-shared),yes) -tests-special += $(objpfx)tst-tls6.out $(objpfx)tst-cleanup0-cmp.out \ - $(objpfx)tst-cancel-wrappers.out +tests-special += $(objpfx)tst-tls6.out $(objpfx)tst-cleanup0-cmp.out endif endif @@ -682,7 +681,7 @@ $(objpfx)$(multidir)/crtn.o: $(objpfx)crtn.o $(objpfx)$(multidir)/ endif generated += libpthread_nonshared.a \ - multidir.mk tst-atfork2.mtrace tst-cancel-wrappers.out \ + multidir.mk tst-atfork2.mtrace \ tst-tls6.out generated += $(objpfx)tst-atfork2.mtrace \ @@ -694,18 +693,6 @@ LDFLAGS-pthread.so += -e __nptl_main $(objpfx)pt-interp.os: $(common-objpfx)runtime-linker.h endif -ifeq ($(run-built-tests),yes) -ifeq (yes,$(build-shared)) -$(objpfx)tst-cancel-wrappers.out: tst-cancel-wrappers.sh - $(SHELL) $< '$(NM)' \ - $(common-objpfx)libc_pic.a \ - $(common-objpfx)libc.a \ - $(objpfx)libpthread_pic.a \ - $(objpfx)libpthread.a > $@; \ - $(evaluate-test) -endif -endif - tst-exec4-ARGS = $(host-test-program-cmd) $(objpfx)tst-execstack: $(libdl) diff --git a/nptl/tst-cancel-wrappers.sh b/nptl/tst-cancel-wrappers.sh deleted file mode 100644 index 0c5b614..0000000 --- a/nptl/tst-cancel-wrappers.sh +++ /dev/null @@ -1,92 +0,0 @@ -#!/bin/sh -# Test whether all cancelable functions are cancelable. -# Copyright (C) 2002-2018 Free Software Foundation, Inc. -# This file is part of the GNU C Library. -# Contributed by Jakub Jelinek , 2002. - -# 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 -# . - -NM="$1"; shift -while [ $# -gt 0 ]; do - ( $NM -P $1; echo 'end[end]:' ) | gawk ' BEGIN { -C["accept"]=1 -C["close"]=1 -C["connect"]=1 -C["creat"]=1 -C["fcntl"]=1 -C["fdatasync"]=1 -C["fsync"]=1 -C["msgrcv"]=1 -C["msgsnd"]=1 -C["msync"]=1 -C["nanosleep"]=1 -C["open"]=1 -C["open64"]=1 -C["pause"]=1 -C["poll"]=1 -C["pread"]=1 -C["pread64"]=1 -C["pselect"]=1 -C["pwrite"]=1 -C["pwrite64"]=1 -C["read"]=1 -C["readv"]=1 -C["recv"]=1 -C["recvfrom"]=1 -C["recvmsg"]=1 -C["select"]=1 -C["send"]=1 -C["sendmsg"]=1 -C["sendto"]=1 -C["sigpause"]=1 -C["sigsuspend"]=1 -C["sigwait"]=1 -C["sigwaitinfo"]=1 -C["tcdrain"]=1 -C["wait"]=1 -C["waitid"]=1 -C["waitpid"]=1 -C["write"]=1 -C["writev"]=1 -C["__xpg_sigpause"]=1 -} -/:$/ { - if (seen) - { - if (!seen_enable || !seen_disable) - { - printf "in '$1'(%s) %s'\''s cancellation missing\n", object, seen - ret = 1 - } - } - seen="" - seen_enable="" - seen_disable="" - object=gensub(/^.*\[(.*)\]:$/, "\\1", 1, $0) - next -} -{ - if (C[$1] && $2 ~ /^[TW]$/) - seen=$1 - else if ($1 ~ /^([.]|)__(libc|pthread)_enable_asynccancel$/ && $2 == "U") - seen_enable=1 - else if ($1 ~ /^([.]|)__(libc|pthread)_disable_asynccancel$/ && $2 == "U") - seen_disable=1 -} -END { - exit ret -}' || exit - shift -done diff --git a/nptl/tst-cancel2.c b/nptl/tst-cancel2.c index e2926bd..45e9a61 100644 --- a/nptl/tst-cancel2.c +++ b/nptl/tst-cancel2.c @@ -73,9 +73,6 @@ do_test (void) return 1; } - /* This will cause the write in the child to return. */ - close (fd[0]); - if (pthread_join (th, &r) != 0) { puts ("join failed"); diff --git a/nptl/tst-cancel3.c b/nptl/tst-cancel3.c index a82c8f2..67f6543 100644 --- a/nptl/tst-cancel3.c +++ b/nptl/tst-cancel3.c @@ -75,9 +75,6 @@ do_test (void) return 1; } - /* This will cause the read in the child to return. */ - close (fd[0]); - if (pthread_join (th, &r) != 0) { puts ("join failed"); diff --git a/nptl/tst-cancel4.c b/nptl/tst-cancel4.c index 0532538..2614f9a 100644 --- a/nptl/tst-cancel4.c +++ b/nptl/tst-cancel4.c @@ -166,6 +166,10 @@ tf_write (void *arg) char buf[WRITE_BUFFER_SIZE]; memset (buf, '\0', sizeof (buf)); s = write (fd, buf, sizeof (buf)); + /* The write can return a value higher than 0 (meaning partial write) + due to the SIGCANCEL, but the thread may still be pending + cancellation. */ + pthread_testcancel (); pthread_cleanup_pop (0); @@ -743,6 +747,10 @@ tf_send (void *arg) char mem[WRITE_BUFFER_SIZE]; send (tempfd2, mem, arg == NULL ? sizeof (mem) : 1, 0); + /* Thez send can return a value higher than 0 (meaning partial send) + due to the SIGCANCEL, but the thread may still be pending + cancellation. */ + pthread_testcancel (); pthread_cleanup_pop (0); From patchwork Mon Feb 26 21:03:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 129711 Delivered-To: patch@linaro.org Received: by 10.80.172.228 with SMTP id x91csp4291145edc; Mon, 26 Feb 2018 13:05:37 -0800 (PST) X-Google-Smtp-Source: AH8x226js/OiGD1oiY/X2JgjXOCB78+DIfFNk707yDpfvlgF64VvsFcaPZ9Rq4euJcT+LvanqMvj X-Received: by 2002:a17:902:63:: with SMTP id 90-v6mr11687447pla.125.1519679137514; Mon, 26 Feb 2018 13:05:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519679137; cv=none; d=google.com; s=arc-20160816; b=uuOWu/5e4XQvFC4QDLwLslMoyR5ZKQp9R//J9uR3AHuAiPKYOLtIMu3RlriU6JfqMh atM6LdOd7pdPBkkiOmc/TM+TgjTQeB9bcVE1BFrP9U/MZcgaYArwgrAIlswcGiQ9nUSC nV24+fIG5Xnp2GvQ2X/Pe8QKTlEsbjt/I5tw6pQUpPjIzINuGonqi69L2owmdIy1qChu sjFXC5ESgoeyNvkn+ip1JNp30hl0NN8kwPvT10k+qjCJOVErIS/FKYYahzlc8daRsUwf M2MIE7Yg75OWY5eFvjZArXcOXzp6yLxz1j3ywq7zrU7tBKcMowneDXDRIBNjUo7g3jQT nP7w== 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=5tkReYNSc1T2QkSAeogg6dLsNiG9LlTZHRQN0q+x3Tg=; b=Bw94bk+rZBMWG3PSSLFzHkYh6RvcFKrOpr5a3DCe37JVJrB0B3KlPbIR7cAsxSG/p3 1fg3j3b16tvdVoXlAi3U7/szKKOVZoicHRwcHDVydKPqlxdMMB0l6oTbRcLp661FKinM 13fwV7Aapy8B41oC8V/5it0tfEn3oMwBzfOgkwKTgfKaKO5JkVIxGV5SYibxSOWwBpbX OwifTQU/s/16eTmUCIbokWHiqV3NEzo2sHgmcHqMLl1zcoQnyCTqD6lHu9O0HgrnAme6 Q3vuOgViHQAxnoIRWYQTHDCi6gvPkMt4gzW6CzCmgg3s8Qt7pAUe5OzC7HnlUn59jVQe 4Fiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=OQMPp5S2; spf=pass (google.com: domain of libc-alpha-return-90626-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-90626-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 e39-v6si7260457plg.364.2018.02.26.13.05.36 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Feb 2018 13:05:37 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-90626-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=OQMPp5S2; spf=pass (google.com: domain of libc-alpha-return-90626-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-90626-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=OXpFIFy7aNAybV7laT/Z14waDmGuFm4 /uEZ5vjEncWaD1KbBMVbr4Ufp9WX8D2zBNNXWp8yvS3EecLbjyPW9CUj0bIt1OUB vtQ1dIz5vbd5VdBiyNCztazSIG6MKlqFQAzrtAHMVaPxp3nsdYfLWgrgN+3Cs7Ia 1TwbPPzwLmd8= 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=9BsXeM7gPFikQSMStNVn/4JFNfQ=; b=OQMPp 5S24aOtlwdI2eJ1OvEV+5UHgWX/6F6dV7oOAc5591ZWW+MmdXwxddkKKFVJQptjH EdGG40nERO6IGiPqZMA35XqRArCnbwjRnBW89XR6lc0J2N0EX3gdWFz3T8dBLVMg ++ArTeP7RVbAEiQSAeOcQxn+Ark1QtW/cLRt8s= Received: (qmail 76335 invoked by alias); 26 Feb 2018 21:04:04 -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 76214 invoked by uid 89); 26 Feb 2018 21:04:03 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS, TIME_LIMIT_EXCEEDED, UNSUBSCRIBE_BODY autolearn=unavailable version=3.3.2 spammy=Obtain, leakage, Safety X-HELO: mail-qk0-f173.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=5tkReYNSc1T2QkSAeogg6dLsNiG9LlTZHRQN0q+x3Tg=; b=SZzgkYLe+MZefwd5jHs63YlKYKqIijZx+u1dbkCtu7DluW+yySvIqtjN46jLx+XHfa UnTXlORLRUjEEWZXGaM8D/IKwKMlzvehfpmd0Md/8BQkBCINcSOdwuQ1rqr0R4Nker3E cN9R+M3NtxJ+nDaqAQPl0gn/BfZ63fDSibDPv2BakDfp8TiePwL12Mxy06KbfyPceeRe sumwqOfjkRHlQz2Rf5T110E2d6GBkkgdFzwfPNwaaO21k0Q6ztfzXCrXIQ7+jv/DHmSx 5sPuxCbOX7rrgadwLx76a1zyRPZckUHFc+gF+q+guil95pPdOATCYBdKoLB2oo6QYaKs LxtA== X-Gm-Message-State: APf1xPD6ILEvPl9xl8qKKloEglLJRwcRKMGGGsc62nTfpyXs2c3h7wcL WJN3UuBQzgUpBNtwF7w40uyNqLbAq9E= X-Received: by 10.55.158.83 with SMTP id h80mr18162711qke.330.1519679028144; Mon, 26 Feb 2018 13:03:48 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH v2 03/21] nptl: Fix Race conditions in pthread cancellation (BZ#12683) Date: Mon, 26 Feb 2018 18:03:18 -0300 Message-Id: <1519679016-12241-4-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 patches fixes some race conditions in NPTL cancellation code by redefining how cancellable syscalls are defined and handled. Current approach is to enable asynchronous cancellation prior to making the syscall and restore the previous cancellation type once the syscall returns. As decribed in BZ#12683, this approach shows 2 important problems: 1. Cancellation can act after the syscall has returned from kernel, but before userspace saves the return value. It might result in a resource leak if the syscall allocated a resource or a side effect (partial read/write), and there is no way to program handle it with cancellation handlers. 2. If a signal is handled while the thread is blocked at a cancellable syscall, the entire signal handler runs with asynchronous cancellation enabled. This can lead to issues if the signal handler call functions which are async-signal-safe but not async-cancel-safe. For cancellation to work correctly, there are 5 points at which the cancellation signal could arrive: 1. Before the final "testcancel" and before the syscall is made. 2. Between the "testcancel" and the syscall. 3. While the syscall is blocked and no side effects have yet taken place. 4. While the syscall is blocked but with some side effects already having taken place (e.g. a partial read or write). 5. After the syscall has returned. And GLIBC wants to act on cancellation in cases 1, 2, and 3 but not in case 4 or 5. The proposed solution follows: * Handling case 1 is trivial: do a conditional branch based on whether the thread has received a cancellation request; * Case 2 can be caught by the signal handler determining that the saved program counter (from the ucontext_t) is in some address range beginning just before the "testcancel" and ending with the syscall instruction. * In this case, except for certain syscalls that ALWAYS fail with EINTR even for non-interrupting signals, the kernel will reset the program counter to point at the syscall instruction during signal handling, so that the syscall is restarted when the signal handler returns. So, from the signal handler's standpoint, this looks the same as case 2, and thus it's taken care of. * In this case, the kernel cannot restart the syscall; when it's interrupted by a signal, the kernel must cause the syscall to return with whatever partial result it obtained (e.g. partial read or write). * In this case, the saved program counter points just after the syscall instruction, so the signal handler won't act on cancellation. This one is equal to 4. since the program counter is past the syscall instruction already. Another case that needs handling is syscalls that fail with EINTR even when the signal handler is non-interrupting. In this case, the syscall wrapper code can just check the cancellation flag when the errno result is EINTR, and act on cancellation if it's set. The proposed GLIBC adjustments are: 1. Remove the enable_asynccancel/disable_asynccancel function usage in syscall definition and instead make them call a common symbol that will check if cancellation is enabled (__syscall_cancel at nptl/libc-cancellation.c), call the arch-specific cancellable entry-point (__syscall_cancel_arch) and cancel the thread when required. 2. Provide a arch-specific symbol that contains global markers. These markers will be used in SIGCANCEL handler to check if the interruption has been called in a valid syscall and if the syscalls has been completed or not. A default version is provided (sysdeps/unix/sysv/linux/syscall_cancel.c), however the markers may not be set on correct expected places depeding of how INTERNAL_SYSCALL_NCS is implemented by the underlying architecture. In this case arch-specific implementation should be provided. 3. Rewrite SIGCANCEL asynchronous handler to check for both cancelling type and if current IP from signal handler falls between the global markes and act accordingly (sigcancel_handler at nptl/nptl-init.c). 4. Adjust nptl/pthread_cancel.c to send an signal instead of acting directly. This avoid synchronization issues when updating the cancellation status and also focus the logic on signal handler and cancellation syscall code. 5. Adjust pthread code to replace CANCEL_ASYNC/CANCEL_RESET calls to appropriated cancelable futex syscalls. 6. Adjust libc code to replace LIBC_CANCEL_ASYNC/LIBC_CANCEL_RESET to appropriated cancelable syscalls. 7. Adjust 'lowlevellock-futex.h' arch-specific implementations to provide cancelable futex calls (used in libpthread code). This patch adds the proposed changes to NPTL. The code leaves all the ports broken without further patches in the list. [BZ #12683] * nptl/Makefile [routines]: Add syscall_cancel object. [libpthread-routines]: Remove cancellation object. (CFLAGS-cancellation.c): Remove rule. (CFLAGS-syscall_cancel.c): New rule. (tests): Add tst-cancel28. * nptl/Versions [GLIBC_PRIVATE] (libc): Add __syscall_cancel, __syscall_cancel_arch_start, and __syscall_cancel_arch_end. * nptl/cancellation.c: Remove file. * nptl/descr.h (CANCELING_BIT): Remove define. (CANCELING_BITMASK): Likewise. (CANCEL_RESTMASK): Adjust value with CANCELED_BIT remove. * nptl/libc-cancellation.c (__syscall_cancel): Add non-cancellable implementation for loader and cancellable one for libc. (__syscall_do_cancel): New function: cancel call for syscall wrappers. * nptl/lll_timedlock_wait.c (__lll_timedlock_wait): Use cancellable futex operation. (__lll_timedwait_tid): Likewise. * nptl/nptl-init.c (sigcancel_handler): Rewrite function to avoid race conditions. (__pthread_initialize_minimal_internal): Add SA_RESTART to SIGCANCEL handler. * nptl/pt-system.c [LIBC_CANCEL_HANDLED]: Remove definition. * io/creat.c (LIBC_CANCEL_HANDLED): Likewise. * io/ppoll.c [ppoll] (LIBC_CANCEL_HANDLED): Likewise. * misc/pselect [__pselect] (LIBC_CANCEL_HANDLED): Likewise. * sysdeps/posix/pause.c (LIBC_CANCEL_HANDLED): Likewise. * sysdeps/unix/sysv/linux/generic/creat.c (LIBC_CANCEL_HANDLED): Likewise. * nptl/pthreadP.h (__do_cancel): Rewrite to both disable asynchronous cancellation and setting the thread as cancelled. (CANCEL_ASYNC): Remove definition. (CANCEL_RESET): Likewise. (LIBC_CANCEL_ASYNC): Likewise. (LIBC_CANCEL_RESET): Likewise. (LIBC_CANCEL_HANDLED): Likewise. (__syscall_cancel_arch): Add prototype. (__pthread_enable_asynccancel): Remove prototype. (__pthread_disable_asynccancel): Likewise. (__libc_enable_asynccancel): Likewise. (__libc_disable_asynccancel): Likewise. (__librt_enable_asynccancel): Likewise. (__librt_disable_asynccancel): Likewise. (__syscall_cancel_arch): Add prototype. (__syscall_do_cancel): Likewise. * nptl/pthread_cancel.c (pthread_cancel): Rewrite to just set CANCELLED_BIT and call __pthread_kill. * nptl/pthread_create.c (start_thread): Likewise. * nptl/pthread_timedjoin.c (pthread_timedjoin_np): Likewise. * nptl/sem_timedwait.c (sem_timedwait): Likewise. * nptl/sem_wait.c (__new_sem_wait): Likewise. * nptl/sem_waitcommon.c (futex_abstimed_wait): Likewise. * sysdeps/nptl/aio_misc.h (AIO_MISC_WAIT): Likewise. * sysdeps/nptl/gai_misc.h (GAI_MISC_WAIT): Likewise. * sysdeps/posix/sigpause.c (do_sigpause): Likewise. * sysdeps/posix/sigwait.c (__sigwait): Likewise. * sysdeps/posix/waitid.c (__waitid): Likewise. * sysdeps/nptl/lowlevellock.h (lll_wait_tid): Likewise. * sysdeps/posix/open64.c (__libc_open64): Likewise. * sysdeps/unix/sysv/linux/sigwait.c (__sigwait): Likewise. * nptl/pthread_exit.c (pthread_exit): Rewrite to set EXITING_BIT before call __pthread_unwind. * nptl/pthread_join.c (pthread_join): Remove CANCEL_ASYNC/CANCEL_RESET usage. * rt/Makefile [CFLAGS-librt-cancellation.c]: Remove rule. * sysdeps/generic/sysdep-cancel.h (LIBC_CANCEL_ASYNC): Remove define. (LIBC_CANCEL_RESET): Likewise. (LIBC_CANCEL_HANDLED): Likewise. * sysdeps/unix/sysv/linux/clock_nanosleep.c (__clock_nanosleep): Likewise. * sysdeps/unix/sysv/linux/fcntl.c (__libc_fcntl): Likewise. * sysdeps/unix/sysv/linux/generic/wordsize-32/fcntl.c (__libc_fcntl): Likewise. * sysdeps/nptl/Makefile [$(subdir) = rt] (librt-sysdep_routines): Remove librt-cancellation object. [$(subdir) = rt] (librt-cancellation.c): Remove rule. * sysdeps/nptl/librt-cancellation.c: Remove file. * sysdeps/unix/sysv/linux/futex-internal.h (lll_futex_wait_cancel): Use lll_futex_timed_wait_cancel. (futex_reltimed_wait_cancelable): Likewise. (futex_abstimed_wait_cancelable)): Use lll_futex_timed_wait_bitset_cancel. * sysdeps/unix/sysv/linux/lowlevellock-futex.h (lll_futex_wait_cancel): New macro. (lll_futex_timed_wait_cancel): Likewise. (lll_futex_timed_wait_bitset_cancel): Likewise. * sysdeps/unix/sysdep.h (SYSCALL_CANCEL): New macro: cancelable syscall calls. (INTERNAL_SYSCALL_NCS_CALL): New macro. (__syscall_cancel): New prototype. * sysdeps/unix/sysv/linux/socketcall.h (SOCKETCALL): Use __SSC macros. (SOCKETCALL_CANCEL): Use SYSCALL_CANCEL macros. * sysdeps/generic/sysdep-cancel.h (LIBC_CANCEL_ASYNC): Remove define. (LIBC_CANCEL_RESET): Likewise. (LIBC_CANCEL_HANDLED): Likewise. * sysdeps/unix/sysv/linux/pthread_kill.c (__pthread_kill): Allow SIGCANCEL to be sent. * nptl/tst-cancel28.c: New file. * sysdeps/unix/sysv/linux/syscall_cancel.c: Likewise. * support/temp_file.c (create_temp_fifo): New function. * support/temp_file.h (create_temp_fifo): Likewise. --- ChangeLog | 85 ++++++++++++++++++++++ io/creat.c | 3 - io/ppoll.c | 2 - manual/llio.texi | 4 +- misc/pselect.c | 2 - nptl/Makefile | 8 +-- nptl/Versions | 3 + nptl/cancellation.c | 101 --------------------------- nptl/descr.h | 15 ++-- nptl/libc-cancellation.c | 47 ++++++++++++- nptl/lll_timedlock_wait.c | 2 +- nptl/lll_timedwait_tid.c | 3 +- nptl/nptl-init.c | 78 +++++++++++++-------- nptl/pthreadP.h | 73 +++++++------------ nptl/pthread_cancel.c | 68 ++++-------------- nptl/pthread_create.c | 7 +- nptl/pthread_exit.c | 9 ++- nptl/pthread_join_common.c | 7 +- nptl/sem_wait.c | 8 +-- nptl/tst-cancel28.c | 94 +++++++++++++++++++++++++ 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/nptl/Makefile | 3 +- sysdeps/nptl/aio_misc.h | 13 +--- sysdeps/nptl/gai_misc.h | 13 +--- sysdeps/nptl/librt-cancellation.c | 24 ------- 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/sparc/sparc32/lowlevellock.c | 3 +- sysdeps/unix/sysdep.h | 96 +++++++++++++++++++++---- 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 ++--- sysdeps/unix/sysv/linux/lowlevellock-futex.h | 34 ++++++++- sysdeps/unix/sysv/linux/pthread_kill.c | 5 +- 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/syscall_cancel.c | 62 ++++++++++++++++ sysdeps/unix/sysv/linux/sysdep.h | 17 +++++ 48 files changed, 639 insertions(+), 425 deletions(-) delete mode 100644 nptl/cancellation.c create mode 100644 nptl/tst-cancel28.c delete mode 100644 sysdeps/nptl/librt-cancellation.c create mode 100644 sysdeps/unix/sysv/linux/syscall_cancel.c -- 2.7.4 diff --git a/io/creat.c b/io/creat.c index 21ee56e..3d0afca 100644 --- a/io/creat.c +++ b/io/creat.c @@ -27,6 +27,3 @@ creat (const char *file, mode_t mode) { return __open (file, O_WRONLY|O_CREAT|O_TRUNC, mode); } - -/* __open handles cancellation. */ -LIBC_CANCEL_HANDLED (); diff --git a/io/ppoll.c b/io/ppoll.c index ec26b99..5ccfdb9 100644 --- a/io/ppoll.c +++ b/io/ppoll.c @@ -70,7 +70,5 @@ ppoll (struct pollfd *fds, nfds_t nfds, const struct timespec *timeout, } #ifndef ppoll -/* __poll handles cancellation. */ -LIBC_CANCEL_HANDLED (); libc_hidden_def (ppoll); #endif diff --git a/manual/llio.texi b/manual/llio.texi index b4fd5e1..573c34b 100644 --- a/manual/llio.texi +++ b/manual/llio.texi @@ -2531,13 +2531,13 @@ aiocb64}, since the LFS transparently replaces the old interface. @c sigemptyset ok @c sigaddset ok @c setjmp ok -@c CANCEL_ASYNC -> pthread_enable_asynccancel ok +@c __pthread_setcanceltype ok @c do_cancel ok @c pthread_unwind ok @c Unwind_ForcedUnwind or longjmp ok [@ascuheap @acsmem?] @c lll_lock @asulock @aculock @c lll_unlock @asulock @aculock -@c CANCEL_RESET -> pthread_disable_asynccancel ok +@c __pthread_setcanceltype ok @c lll_futex_wait ok @c ->start_routine ok ----- @c call_tls_dtors @asulock @ascuheap @aculock @acsmem diff --git a/misc/pselect.c b/misc/pselect.c index 2c29230..07d5ffc 100644 --- a/misc/pselect.c +++ b/misc/pselect.c @@ -73,6 +73,4 @@ __pselect (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, } #ifndef __pselect weak_alias (__pselect, pselect) -/* __select handles cancellation. */ -LIBC_CANCEL_HANDLED (); #endif diff --git a/nptl/Makefile b/nptl/Makefile index 76ecf6c..34a7a18 100644 --- a/nptl/Makefile +++ b/nptl/Makefile @@ -30,7 +30,7 @@ install-lib-ldscripts := libpthread.so routines = alloca_cutoff forward libc-lowlevellock libc-cancellation \ libc-cleanup libc_pthread_init libc_multiple_threads \ - register-atfork pthread_self + register-atfork pthread_self syscall_cancel shared-only-routines = forward # We need to provide certain routines for compatibility with existing @@ -117,7 +117,6 @@ libpthread-routines = nptl-init vars events version pt-interp \ cleanup cleanup_defer cleanup_compat \ cleanup_defer_compat unwind \ pt-longjmp pt-cleanup\ - cancellation \ lowlevellock \ lll_timedlock_wait lll_timedwait_tid \ pt-fork pt-vfork \ @@ -166,7 +165,6 @@ CFLAGS-pthread_setcanceltype.c += -fexceptions -fasynchronous-unwind-tables # These are internal functions which similar functionality as setcancelstate # and setcanceltype. -CFLAGS-cancellation.c += -fasynchronous-unwind-tables CFLAGS-libc-cancellation.c += -fasynchronous-unwind-tables # Calling pthread_exit() must cause the registered cancel handlers to @@ -225,6 +223,8 @@ CFLAGS-fsync.c += -fexceptions -fasynchronous-unwind-tables CFLAGS-pt-system.c += -fexceptions +CFLAGS-syscall_cancel.c = -fexceptions -fasynchronous-unwind-tables + LDLIBS-tst-once5 = -lstdc++ CFLAGS-tst-thread_local1.o = -std=gnu++11 LDLIBS-tst-thread_local1 = -lstdc++ @@ -277,7 +277,7 @@ tests = tst-attr1 tst-attr2 tst-attr3 tst-default-attr \ tst-cancel11 tst-cancel12 tst-cancel13 tst-cancel14 tst-cancel15 \ tst-cancel16 tst-cancel17 tst-cancel18 tst-cancel19 tst-cancel20 \ tst-cancel21 tst-cancel22 tst-cancel23 tst-cancel24 tst-cancel25 \ - tst-cancel26 tst-cancel27 \ + tst-cancel26 tst-cancel27 tst-cancel28 \ tst-cancel-self tst-cancel-self-cancelstate \ tst-cancel-self-canceltype tst-cancel-self-testcancel \ tst-cleanup0 tst-cleanup1 tst-cleanup2 tst-cleanup3 tst-cleanup4 \ diff --git a/nptl/Versions b/nptl/Versions index 0ae5def..734d47a 100644 --- a/nptl/Versions +++ b/nptl/Versions @@ -36,6 +36,9 @@ libc { __libc_pthread_init; __libc_current_sigrtmin_private; __libc_current_sigrtmax_private; __libc_allocate_rtsig_private; + __syscall_cancel; + __syscall_cancel_arch_start; + __syscall_cancel_arch_end; } } diff --git a/nptl/cancellation.c b/nptl/cancellation.c deleted file mode 100644 index 47a9b55..0000000 --- a/nptl/cancellation.c +++ /dev/null @@ -1,101 +0,0 @@ -/* Copyright (C) 2002-2018 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 2002. - - 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 -#include -#include "pthreadP.h" -#include - - -/* The next two functions are similar to pthread_setcanceltype() but - more specialized for the use in the cancelable functions like write(). - They do not need to check parameters etc. */ -int -attribute_hidden -__pthread_enable_asynccancel (void) -{ - struct pthread *self = THREAD_SELF; - int oldval = THREAD_GETMEM (self, cancelhandling); - - while (1) - { - int newval = oldval | CANCELTYPE_BITMASK; - - if (newval == oldval) - break; - - int curval = THREAD_ATOMIC_CMPXCHG_VAL (self, cancelhandling, newval, - oldval); - if (__glibc_likely (curval == oldval)) - { - if (CANCEL_ENABLED_AND_CANCELED_AND_ASYNCHRONOUS (newval)) - { - THREAD_SETMEM (self, result, PTHREAD_CANCELED); - __do_cancel (); - } - - break; - } - - /* Prepare the next round. */ - oldval = curval; - } - - return oldval; -} - - -void -attribute_hidden -__pthread_disable_asynccancel (int oldtype) -{ - /* If asynchronous cancellation was enabled before we do not have - anything to do. */ - if (oldtype & CANCELTYPE_BITMASK) - return; - - struct pthread *self = THREAD_SELF; - int newval; - - int oldval = THREAD_GETMEM (self, cancelhandling); - - while (1) - { - newval = oldval & ~CANCELTYPE_BITMASK; - - int curval = THREAD_ATOMIC_CMPXCHG_VAL (self, cancelhandling, newval, - oldval); - if (__glibc_likely (curval == oldval)) - break; - - /* Prepare the next round. */ - oldval = curval; - } - - /* We cannot return when we are being canceled. Upon return the - thread might be things which would have to be undone. The - following loop should loop until the cancellation signal is - delivered. */ - while (__builtin_expect ((newval & (CANCELING_BITMASK | CANCELED_BITMASK)) - == CANCELING_BITMASK, 0)) - { - futex_wait_simple ((unsigned int *) &self->cancelhandling, newval, - FUTEX_PRIVATE); - newval = THREAD_GETMEM (self, cancelhandling); - } -} diff --git a/nptl/descr.h b/nptl/descr.h index 64ba29e..4595165 100644 --- a/nptl/descr.h +++ b/nptl/descr.h @@ -278,23 +278,20 @@ struct pthread /* Bit set if asynchronous cancellation mode is selected. */ #define CANCELTYPE_BIT 1 #define CANCELTYPE_BITMASK (0x01 << CANCELTYPE_BIT) - /* Bit set if canceling has been initiated. */ -#define CANCELING_BIT 2 -#define CANCELING_BITMASK (0x01 << CANCELING_BIT) - /* Bit set if canceled. */ -#define CANCELED_BIT 3 + /* Bit set if threads is canceled. */ +#define CANCELED_BIT 2 #define CANCELED_BITMASK (0x01 << CANCELED_BIT) /* Bit set if thread is exiting. */ -#define EXITING_BIT 4 +#define EXITING_BIT 3 #define EXITING_BITMASK (0x01 << EXITING_BIT) /* Bit set if thread terminated and TCB is freed. */ -#define TERMINATED_BIT 5 +#define TERMINATED_BIT 4 #define TERMINATED_BITMASK (0x01 << TERMINATED_BIT) /* Bit set if thread is supposed to change XID. */ -#define SETXID_BIT 6 +#define SETXID_BIT 5 #define SETXID_BITMASK (0x01 << SETXID_BIT) /* Mask for the rest. Helps the compiler to optimize. */ -#define CANCEL_RESTMASK 0xffffff80 +#define CANCEL_RESTMASK 0xffffffc0 #define CANCEL_ENABLED_AND_CANCELED(value) \ (((value) & (CANCELSTATE_BITMASK | CANCELED_BITMASK | EXITING_BITMASK \ diff --git a/nptl/libc-cancellation.c b/nptl/libc-cancellation.c index aef5b5d..9b054aa 100644 --- a/nptl/libc-cancellation.c +++ b/nptl/libc-cancellation.c @@ -16,9 +16,50 @@ License along with the GNU C Library; if not, see . */ +#include +#include #include "pthreadP.h" +/* Cancellation function called by all cancellable syscalls. */ +long int +__syscall_cancel (__syscall_arg_t nr, __syscall_arg_t a1, + __syscall_arg_t a2, __syscall_arg_t a3, + __syscall_arg_t a4, __syscall_arg_t a5, + __syscall_arg_t a6) +{ + pthread_t self = (pthread_t) THREAD_SELF; + volatile struct pthread *pd = (volatile struct pthread *) self; + long int result; -#define __pthread_enable_asynccancel __libc_enable_asynccancel -#define __pthread_disable_asynccancel __libc_disable_asynccancel -#include + /* If cancellation is not enabled, call the syscall directly. */ + if (pd->cancelhandling & CANCELSTATE_BITMASK) + { + INTERNAL_SYSCALL_DECL (err); + result = INTERNAL_SYSCALL_NCS_CALL (nr, err, a1, a2, a3, a4, a5, a6); + if (INTERNAL_SYSCALL_ERROR_P (result, err)) + return -INTERNAL_SYSCALL_ERRNO (result, err); + return result; + } + + /* Call the arch-specific entry points that contains the globals markers + to be checked by SIGCANCEL handler. */ + result = __syscall_cancel_arch (&pd->cancelhandling, nr, a1, a2, a3, a4, a5, + a6); + + if ((result == -EINTR) + && (pd->cancelhandling & CANCELED_BITMASK) + && !(pd->cancelhandling & CANCELSTATE_BITMASK)) + __syscall_do_cancel (); + + return result; +} +libc_hidden_def (__syscall_cancel) + +/* Since __do_cancel is a always inline function, this creates a symbol the + arch-specific symbol can call to cancel the thread. */ +void +__cleanup_fct_attribute attribute_hidden __attribute ((noreturn)) +__syscall_do_cancel (void) +{ + __do_cancel (); +} diff --git a/nptl/lll_timedlock_wait.c b/nptl/lll_timedlock_wait.c index 91bf963..f1f2bed 100644 --- a/nptl/lll_timedlock_wait.c +++ b/nptl/lll_timedlock_wait.c @@ -52,7 +52,7 @@ __lll_timedlock_wait (int *futex, const struct timespec *abstime, int private) return ETIMEDOUT; /* If *futex == 2, wait until woken or timeout. */ - lll_futex_timed_wait (futex, 2, &rt, private); + lll_futex_timed_wait_cancel (futex, 2, &rt, private); } return 0; diff --git a/nptl/lll_timedwait_tid.c b/nptl/lll_timedwait_tid.c index c836a6f..e0b001c 100644 --- a/nptl/lll_timedwait_tid.c +++ b/nptl/lll_timedwait_tid.c @@ -62,7 +62,8 @@ __lll_timedwait_tid (int *tidp, const struct timespec *abstime) The kernel up to version 3.16.3 does not use the private futex operations for futex wake-up when the clone terminates. */ - if (lll_futex_timed_wait (tidp, tid, &rt, LLL_SHARED) == -ETIMEDOUT) + if (lll_futex_timed_wait_cancel (tidp, tid, &rt, LLL_SHARED) + == -ETIMEDOUT) return ETIMEDOUT; } diff --git a/nptl/nptl-init.c b/nptl/nptl-init.c index 5a4b524..5cf6de9 100644 --- a/nptl/nptl-init.c +++ b/nptl/nptl-init.c @@ -38,6 +38,7 @@ #include #include #include +#include #ifndef TLS_MULTIPLE_THREADS_IN_TCB /* Pointer to the corresponding variable in libc. */ @@ -175,49 +176,65 @@ __nptl_set_robust (struct pthread *self) #ifdef SIGCANCEL + +extern const char __syscall_cancel_arch_start[1]; +extern const char __syscall_cancel_arch_end[1]; + +/* Workaround for architectures which either does not define the mask + as a sigset (alpha) or does not call sa_sigaction with a ucontext_t + as third argument (sparc). */ +# ifndef UCONTEXT_SIGMASK +# define UCONTEXT_SIGMASK(cxt) \ + &(((ucontext_t*) (cxt))->uc_sigmask) +# endif + /* For asynchronous cancellation we use a signal. This is the handler. */ static void sigcancel_handler (int sig, siginfo_t *si, void *ctx) { + INTERNAL_SYSCALL_DECL (err); + pid_t pid = INTERNAL_SYSCALL_CALL (getpid, err); + /* Safety check. It would be possible to call this function for other signals and send a signal from another process. This is not correct and might even be a security problem. Try to catch as many incorrect invocations as possible. */ if (sig != SIGCANCEL - || si->si_pid != __getpid() + || si->si_pid != pid || si->si_code != SI_TKILL) return; struct pthread *self = THREAD_SELF; + volatile struct pthread *pd = (volatile struct pthread *) self; - int oldval = THREAD_GETMEM (self, cancelhandling); - while (1) + if (((pd->cancelhandling & (CANCELSTATE_BITMASK)) != 0) + || ((pd->cancelhandling & CANCELED_BITMASK) == 0)) + return; + + /* Add SIGCANCEL on ignored sigmask to avoid the handler to be called + again. */ + sigset_t *set = UCONTEXT_SIGMASK (ctx); + __sigaddset (set, SIGCANCEL); + + /* Check if asynchronous cancellation mode is set and if interrupted + instruction pointer falls within the cancellable syscall bridge. For + interruptable syscalls that might generate external side-effects (partial + reads or writes, for instance), the kernel will set the IP to after + '__syscall_cancel_arch_end', thus disabling the cancellation and allowing + the process to handle such conditions. */ + uintptr_t pc = ucontext_get_pc (ctx); + if (pd->cancelhandling & CANCELTYPE_BITMASK + || (pc >= (uintptr_t) __syscall_cancel_arch_start + && pc < (uintptr_t) __syscall_cancel_arch_end)) { - /* We are canceled now. When canceled by another thread this flag - is already set but if the signal is directly send (internally or - from another process) is has to be done here. */ - int newval = oldval | CANCELING_BITMASK | CANCELED_BITMASK; - - if (oldval == newval || (oldval & EXITING_BITMASK) != 0) - /* Already canceled or exiting. */ - break; - - int curval = THREAD_ATOMIC_CMPXCHG_VAL (self, cancelhandling, newval, - oldval); - if (curval == oldval) - { - /* Set the return value. */ - THREAD_SETMEM (self, result, PTHREAD_CANCELED); - - /* Make sure asynchronous cancellation is still enabled. */ - if ((newval & CANCELTYPE_BITMASK) != 0) - /* Run the registered destructors and terminate the thread. */ - __do_cancel (); - - break; - } - - oldval = curval; + THREAD_ATOMIC_BIT_SET (self, cancelhandling, EXITING_BIT); + THREAD_SETMEM (self, result, PTHREAD_CANCELED); + + INTERNAL_SYSCALL_CALL (rt_sigprocmask, err, SIG_SETMASK, set, NULL, + _NSIG / 8); + + __do_cancel (); + return; } } #endif @@ -372,7 +389,10 @@ __pthread_initialize_minimal_internal (void) cannot install the handler we do not abort. Maybe we should, but it is only asynchronous cancellation which is affected. */ sa.sa_sigaction = sigcancel_handler; - sa.sa_flags = SA_SIGINFO; + /* The signal handle should be non-interruptible to avoid the risk of + spurious EINTR caused by SIGCANCEL sent to process or if pthread_cancel + is called while cancellation is disabled in the target thread. */ + sa.sa_flags = SA_SIGINFO | SA_RESTART; (void) __libc_sigaction (SIGCANCEL, &sa, NULL); # endif diff --git a/nptl/pthreadP.h b/nptl/pthreadP.h index 075530c..bb7ff81 100644 --- a/nptl/pthreadP.h +++ b/nptl/pthreadP.h @@ -291,51 +291,37 @@ __do_cancel (void) { struct pthread *self = THREAD_SELF; - /* Make sure we get no more cancellations. */ - THREAD_ATOMIC_BIT_SET (self, cancelhandling, EXITING_BIT); + /* Make sure we get no more cancellations by clearing the cancel + state. */ + int oldval = THREAD_GETMEM (self, cancelhandling); + while (1) + { + int newval = (oldval | CANCELSTATE_BITMASK); + newval &= ~(CANCELTYPE_BITMASK); + if (oldval == newval) + break; + + int curval = THREAD_ATOMIC_CMPXCHG_VAL (self, cancelhandling, newval, + oldval); + if (__glibc_likely (curval == oldval)) + break; + oldval = curval; + } + + THREAD_SETMEM (self, result, PTHREAD_CANCELED); __pthread_unwind ((__pthread_unwind_buf_t *) THREAD_GETMEM (self, cleanup_jmp_buf)); } -/* Set cancellation mode to asynchronous. */ -#define CANCEL_ASYNC() \ - __pthread_enable_asynccancel () -/* Reset to previous cancellation mode. */ -#define CANCEL_RESET(oldtype) \ - __pthread_disable_asynccancel (oldtype) - -#if IS_IN (libc) -/* Same as CANCEL_ASYNC, but for use in libc.so. */ -# define LIBC_CANCEL_ASYNC() \ - __libc_enable_asynccancel () -/* Same as CANCEL_RESET, but for use in libc.so. */ -# define LIBC_CANCEL_RESET(oldtype) \ - __libc_disable_asynccancel (oldtype) -# define LIBC_CANCEL_HANDLED() \ - __asm (".globl " __SYMBOL_PREFIX "__libc_enable_asynccancel"); \ - __asm (".globl " __SYMBOL_PREFIX "__libc_disable_asynccancel") -#elif IS_IN (libpthread) -# define LIBC_CANCEL_ASYNC() CANCEL_ASYNC () -# define LIBC_CANCEL_RESET(val) CANCEL_RESET (val) -# define LIBC_CANCEL_HANDLED() \ - __asm (".globl " __SYMBOL_PREFIX "__pthread_enable_asynccancel"); \ - __asm (".globl " __SYMBOL_PREFIX "__pthread_disable_asynccancel") -#elif IS_IN (librt) -# define LIBC_CANCEL_ASYNC() \ - __librt_enable_asynccancel () -# define LIBC_CANCEL_RESET(val) \ - __librt_disable_asynccancel (val) -# define LIBC_CANCEL_HANDLED() \ - __asm (".globl " __SYMBOL_PREFIX "__librt_enable_asynccancel"); \ - __asm (".globl " __SYMBOL_PREFIX "__librt_disable_asynccancel") -#else -# define LIBC_CANCEL_ASYNC() 0 /* Just a dummy value. */ -# define LIBC_CANCEL_RESET(val) ((void)(val)) /* Nothing, but evaluate it. */ -# define LIBC_CANCEL_HANDLED() /* Nothing. */ -#endif +extern long int __syscall_cancel_arch (volatile int *, __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); +libc_hidden_proto (__syscall_cancel_arch); +extern void __syscall_do_cancel (void) + __cleanup_fct_attribute attribute_hidden __attribute ((__noreturn__)); /* Internal prototypes. */ @@ -503,8 +489,6 @@ extern int __pthread_kill (pthread_t threadid, int signo); extern void __pthread_exit (void *value) __attribute__ ((__noreturn__)); extern int __pthread_join (pthread_t threadid, void **thread_return); extern int __pthread_setcanceltype (int type, int *oldtype); -extern int __pthread_enable_asynccancel (void) attribute_hidden; -extern void __pthread_disable_asynccancel (int oldtype) attribute_hidden; extern void __pthread_testcancel (void); extern int __pthread_timedjoin_ex (pthread_t, void **, const struct timespec *, bool); @@ -543,15 +527,6 @@ extern int __pthread_cond_wait_2_0 (pthread_cond_2_0_t *cond, extern int __pthread_getaffinity_np (pthread_t th, size_t cpusetsize, cpu_set_t *cpuset); -/* The two functions are in libc.so and not exported. */ -extern int __libc_enable_asynccancel (void) attribute_hidden; -extern void __libc_disable_asynccancel (int oldtype) attribute_hidden; - - -/* The two functions are in librt.so and not exported. */ -extern int __librt_enable_asynccancel (void) attribute_hidden; -extern void __librt_disable_asynccancel (int oldtype) attribute_hidden; - #if IS_IN (libpthread) /* Special versions which use non-exported functions. */ extern void __pthread_cleanup_push (struct _pthread_cleanup_buffer *buffer, diff --git a/nptl/pthread_cancel.c b/nptl/pthread_cancel.c index 84c8c4e..20ff7e0 100644 --- a/nptl/pthread_cancel.c +++ b/nptl/pthread_cancel.c @@ -37,67 +37,23 @@ __pthread_cancel (pthread_t th) #ifdef SHARED pthread_cancel_init (); #endif - int result = 0; - int oldval; - int newval; - do - { - again: - oldval = pd->cancelhandling; - newval = oldval | CANCELING_BITMASK | CANCELED_BITMASK; - /* Avoid doing unnecessary work. The atomic operation can - potentially be expensive if the bug has to be locked and - remote cache lines have to be invalidated. */ - if (oldval == newval) - break; + THREAD_ATOMIC_BIT_SET (pd, cancelhandling, CANCELED_BIT); - /* If the cancellation is handled asynchronously just send a - signal. We avoid this if possible since it's more - expensive. */ - if (CANCEL_ENABLED_AND_CANCELED_AND_ASYNCHRONOUS (newval)) - { - /* Mark the cancellation as "in progress". */ - if (atomic_compare_and_exchange_bool_acq (&pd->cancelhandling, - oldval | CANCELING_BITMASK, - oldval)) - goto again; - -#ifdef SIGCANCEL - /* The cancellation handler will take care of marking the - thread as canceled. */ - pid_t pid = __getpid (); - - INTERNAL_SYSCALL_DECL (err); - int val = INTERNAL_SYSCALL_CALL (tgkill, err, pid, pd->tid, - SIGCANCEL); - if (INTERNAL_SYSCALL_ERROR_P (val, err)) - result = INTERNAL_SYSCALL_ERRNO (val, err); -#else - /* It should be impossible to get here at all, since - pthread_setcanceltype should never have allowed - PTHREAD_CANCEL_ASYNCHRONOUS to be set. */ - abort (); -#endif - - break; - } - - /* A single-threaded process should be able to kill itself, since - there is nothing in the POSIX specification that says that it - cannot. So we set multiple_threads to true so that cancellation - points get executed. */ - THREAD_SETMEM (THREAD_SELF, header.multiple_threads, 1); + /* A single-threaded process should be able to kill itself, since there is + nothing in the POSIX specification that says that it cannot. So we set + multiple_threads to true so that cancellation points get executed. */ + THREAD_SETMEM (THREAD_SELF, header.multiple_threads, 1); #ifndef TLS_MULTIPLE_THREADS_IN_TCB - __pthread_multiple_threads = *__libc_multiple_threads_ptr = 1; + __pthread_multiple_threads = *__libc_multiple_threads_ptr = 1; #endif - } - /* Mark the thread as canceled. This has to be done - atomically since other bits could be modified as well. */ - while (atomic_compare_and_exchange_bool_acq (&pd->cancelhandling, newval, - oldval)); - return result; + /* Avoid signaling when thread attempts cancel itself (pthread_kill + is expensive). */ + if (pd == THREAD_SELF && !(pd->cancelhandling & CANCELTYPE_BITMASK)) + return 0; + + return __pthread_kill (th, SIGCANCEL); } weak_alias (__pthread_cancel, pthread_cancel) diff --git a/nptl/pthread_create.c b/nptl/pthread_create.c index caaf07c..cf0dc37 100644 --- a/nptl/pthread_create.c +++ b/nptl/pthread_create.c @@ -412,7 +412,7 @@ START_THREAD_DEFN /* If the parent was running cancellation handlers while creating the thread the new thread inherited the signal mask. Reset the cancellation signal mask. */ - if (__glibc_unlikely (pd->parent_cancelhandling & CANCELING_BITMASK)) + if (__glibc_unlikely (pd->parent_cancelhandling & CANCELED_BITMASK)) { INTERNAL_SYSCALL_DECL (err); sigset_t mask; @@ -444,7 +444,8 @@ START_THREAD_DEFN have ownership (see CONCURRENCY NOTES above). */ if (__glibc_unlikely (pd->stopped_start)) { - int oldtype = CANCEL_ASYNC (); + int ct; + __pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, &ct); /* Get the lock the parent locked to force synchronization. */ lll_lock (pd->lock, LLL_PRIVATE); @@ -454,7 +455,7 @@ START_THREAD_DEFN /* And give it up right away. */ lll_unlock (pd->lock, LLL_PRIVATE); - CANCEL_RESET (oldtype); + __pthread_setcanceltype (ct, NULL); } LIBC_PROBE (pthread_start, 3, (pthread_t) pd, pd->start_routine, pd->arg); diff --git a/nptl/pthread_exit.c b/nptl/pthread_exit.c index c8383e4..b69dee3 100644 --- a/nptl/pthread_exit.c +++ b/nptl/pthread_exit.c @@ -23,9 +23,14 @@ void __pthread_exit (void *value) { - THREAD_SETMEM (THREAD_SELF, result, value); + struct pthread *self = THREAD_SELF; - __do_cancel (); + THREAD_SETMEM (self, result, value); + + THREAD_ATOMIC_BIT_SET (self, cancelhandling, EXITING_BIT); + + __pthread_unwind ((__pthread_unwind_buf_t *) + THREAD_GETMEM (self, cleanup_jmp_buf)); } weak_alias (__pthread_exit, pthread_exit) diff --git a/nptl/pthread_join_common.c b/nptl/pthread_join_common.c index 702fcd1..9b2adc6 100644 --- a/nptl/pthread_join_common.c +++ b/nptl/pthread_join_common.c @@ -54,7 +54,7 @@ __pthread_timedjoin_ex (pthread_t threadid, void **thread_return, if ((pd == self || (self->joinid == pd && (pd->cancelhandling - & (CANCELING_BITMASK | CANCELED_BITMASK | EXITING_BITMASK + & (CANCELED_BITMASK | EXITING_BITMASK | TERMINATED_BITMASK)) == 0)) && !CANCEL_ENABLED_AND_CANCELED (self->cancelhandling)) /* This is a deadlock situation. The threads are waiting for each @@ -81,14 +81,15 @@ __pthread_timedjoin_ex (pthread_t threadid, void **thread_return, un-wait-ed for again. */ pthread_cleanup_push (cleanup, &pd->joinid); - int oldtype = CANCEL_ASYNC (); + int ct; + __pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, &ct); if (abstime != NULL) result = lll_timedwait_tid (pd->tid, abstime); else lll_wait_tid (pd->tid); - CANCEL_RESET (oldtype); + __pthread_setcanceltype (ct, NULL); pthread_cleanup_pop (0); } diff --git a/nptl/sem_wait.c b/nptl/sem_wait.c index e7d9106..e057b05 100644 --- a/nptl/sem_wait.c +++ b/nptl/sem_wait.c @@ -56,14 +56,8 @@ __old_sem_wait (sem_t *sem) if (atomic_decrement_if_positive (futex) > 0) return 0; - /* Enable asynchronous cancellation. Required by the standard. */ - int oldtype = __pthread_enable_asynccancel (); - /* Always assume the semaphore is shared. */ - err = lll_futex_wait (futex, 0, LLL_SHARED); - - /* Disable asynchronous cancellation. */ - __pthread_disable_asynccancel (oldtype); + err = lll_futex_wait_cancel (futex, 0, LLL_SHARED); } while (err == 0 || err == -EWOULDBLOCK); diff --git a/nptl/tst-cancel28.c b/nptl/tst-cancel28.c new file mode 100644 index 0000000..185dedd --- /dev/null +++ b/nptl/tst-cancel28.c @@ -0,0 +1,94 @@ +/* Check side-effect act for cancellable syscalls (BZ #12683). + 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 + . */ + +/* This testcase checks if there is resource leakage if the syscall has + returned from kernelspace, but before userspace saves the return + value. The 'leaker' thread should be able to close the file descriptor + if the resource is already allocated, meaning that if the cancellation + signal arrives *after* the open syscal return from kernel, the + side-effect should be visible to application. */ + +#include +#include +#include +#include +#include + +#include +#include +#include + +static void * +writeopener (void *arg) +{ + int fd; + for (;;) + { + fd = open (arg, O_WRONLY); + close (fd); + } + return NULL; +} + +static void * +leaker (void *arg) +{ + int fd = open (arg, O_RDONLY); + pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, 0); + close (fd); + return NULL; +} + + +#define ITER_COUNT 1000 +#define MAX_FILENO 1024 + +static int +do_test (void) +{ + struct stat st; + int i; + + char *name = NULL; + support_create_temp_fifo ("tst-cancel28", &name); + + srand (1); + + xpthread_create (NULL, writeopener, name); + for (i = 0; i < ITER_COUNT; i++) + { + pthread_t td = xpthread_create (NULL, leaker, name); + struct timespec ts = + { .tv_nsec = rand () % 100000, .tv_sec = 0 }; + nanosleep (&ts, NULL); + /* Ignore pthread_cancel result because it might be the + case when pthread_cancel is called when thread is already + exited. */ + pthread_cancel (td); + xpthread_join (td); + } + + for (i = STDERR_FILENO+1; i < MAX_FILENO; i++) + if (fstat (i, &st) == 0) + FAIL_EXIT1 ("leaked fd %d", i); + + return 0; +} + +#define TIMEOUT 10 +#include diff --git a/rt/Makefile b/rt/Makefile index 6d6b896..9c32752 100644 --- a/rt/Makefile +++ b/rt/Makefile @@ -64,7 +64,6 @@ CFLAGS-aio_suspend.c += -fexceptions CFLAGS-mq_timedreceive.c += -fexceptions -fasynchronous-unwind-tables CFLAGS-mq_timedsend.c += -fexceptions -fasynchronous-unwind-tables CFLAGS-clock_nanosleep.c += -fexceptions -fasynchronous-unwind-tables -CFLAGS-librt-cancellation.c += -fasynchronous-unwind-tables LDFLAGS-rt.so = -Wl,--enable-new-dtags,-z,nodelete diff --git a/support/temp_file.c b/support/temp_file.c index 0bbc7f9..362ef17 100644 --- a/support/temp_file.c +++ b/support/temp_file.c @@ -86,6 +86,29 @@ create_temp_file (const char *base, char **filename) return fd; } +int +support_create_temp_fifo (const char *base, char **fifoname) +{ + char *fname = xasprintf ("%s/%sXXXXXX", test_dir, base); + mktemp (fname); + + int fd = mkfifo (fname, 0600); + if (fd == -1) + { + printf ("cannot open temporary fifo '%s': %m\n", fname); + free (fname); + return -1; + } + + add_temp_file (fname); + if (fifoname != NULL) + *fifoname = fname; + else + free (fname); + + return fd; +} + char * support_create_temp_directory (const char *base) { diff --git a/support/temp_file.h b/support/temp_file.h index c7795cc..081b241 100644 --- a/support/temp_file.h +++ b/support/temp_file.h @@ -32,6 +32,12 @@ void add_temp_file (const char *name); *FILENAME. */ int create_temp_file (const char *base, char **filename); +/* Create a temporary fifo. Return the opened file descriptor on + success, or -1 on failure. Write the file name to *FILENAME if + FILENAME is not NULL. In this case, the caller is expected to free + *FILENAME. */ +int support_create_temp_fifo (const char *name, char **fifoname); + /* Create a temporary directory and schedule it for deletion. BASE is used as a prefix for the unique directory name, which the function returns. The caller should free this string. */ diff --git a/sysdeps/generic/sigcontextinfo.h b/sysdeps/generic/sigcontextinfo.h index 078b034..60fdf0e 100644 --- a/sysdeps/generic/sigcontextinfo.h +++ b/sysdeps/generic/sigcontextinfo.h @@ -16,6 +16,11 @@ License along with the GNU C Library; if not, see . */ +#ifndef _SIGCONTEXTINFO_H +#define _SIGCONTEXTINFO_H + +#include + /* In general we cannot provide any information. */ #define SIGCONTEXT struct sigcontext * #define SIGCONTEXT_EXTRA_ARGS @@ -24,3 +29,13 @@ #define GET_STACK(ctx) ((void *) 0) #define CALL_SIGHANDLER(handler, signo, ctx) \ (handler)((signo), SIGCONTEXT_EXTRA_ARGS (ctx)) + +/* Obtain the Program Counter from third argument in signal handler set + with SA_SIGINFO. */ +static inline uintptr_t +ucontext_get_pc (void *ctx) +{ + return 0; +} + +#endif diff --git a/sysdeps/generic/sysdep-cancel.h b/sysdeps/generic/sysdep-cancel.h index ba6a1e0..5c84b44 100644 --- a/sysdeps/generic/sysdep-cancel.h +++ b/sysdeps/generic/sysdep-cancel.h @@ -3,6 +3,3 @@ /* No multi-thread handling enabled. */ #define SINGLE_THREAD_P (1) #define RTLD_SINGLE_THREAD_P (1) -#define LIBC_CANCEL_ASYNC() 0 /* Just a dummy value. */ -#define LIBC_CANCEL_RESET(val) ((void)(val)) /* Nothing, but evaluate it. */ -#define LIBC_CANCEL_HANDLED() /* Nothing. */ diff --git a/sysdeps/nptl/Makefile b/sysdeps/nptl/Makefile index 6b87b82..f537fc0 100644 --- a/sysdeps/nptl/Makefile +++ b/sysdeps/nptl/Makefile @@ -21,8 +21,7 @@ libpthread-sysdep_routines += errno-loc endif ifeq ($(subdir),rt) -librt-sysdep_routines += timer_routines librt-cancellation -CFLAGS-librt-cancellation.c += -fexceptions -fasynchronous-unwind-tables +librt-sysdep_routines += timer_routines tests += tst-mqueue8x CFLAGS-tst-mqueue8x.c += -fexceptions diff --git a/sysdeps/nptl/aio_misc.h b/sysdeps/nptl/aio_misc.h index 206d8e1..92c262d 100644 --- a/sysdeps/nptl/aio_misc.h +++ b/sysdeps/nptl/aio_misc.h @@ -34,22 +34,18 @@ #define AIO_MISC_WAIT(result, futex, timeout, cancel) \ do { \ - volatile unsigned int *futexaddr = &futex; \ + unsigned int *futexaddr = (unsigned int *)&futex; \ unsigned int oldval = futex; \ \ if (oldval != 0) \ { \ pthread_mutex_unlock (&__aio_requests_mutex); \ \ - int oldtype; \ - if (cancel) \ - oldtype = LIBC_CANCEL_ASYNC (); \ - \ int status; \ do \ { \ - status = futex_reltimed_wait ((unsigned int *) futexaddr, oldval, \ - timeout, FUTEX_PRIVATE); \ + status = futex_reltimed_wait_cancelable (futexaddr, oldval, \ + timeout, FUTEX_PRIVATE); \ if (status != EAGAIN) \ break; \ \ @@ -57,9 +53,6 @@ } \ while (oldval != 0); \ \ - if (cancel) \ - LIBC_CANCEL_RESET (oldtype); \ - \ if (status == EINTR) \ result = EINTR; \ else if (status == ETIMEDOUT) \ diff --git a/sysdeps/nptl/gai_misc.h b/sysdeps/nptl/gai_misc.h index 815e6c0..3dca11e 100644 --- a/sysdeps/nptl/gai_misc.h +++ b/sysdeps/nptl/gai_misc.h @@ -35,22 +35,18 @@ #define GAI_MISC_WAIT(result, futex, timeout, cancel) \ do { \ - volatile unsigned int *futexaddr = &futex; \ + unsigned int *futexaddr = (unsigned int *)&futex; \ unsigned int oldval = futex; \ \ if (oldval != 0) \ { \ pthread_mutex_unlock (&__gai_requests_mutex); \ \ - int oldtype; \ - if (cancel) \ - oldtype = LIBC_CANCEL_ASYNC (); \ - \ int status; \ do \ { \ - status = futex_reltimed_wait ((unsigned int *) futexaddr, oldval, \ - timeout, FUTEX_PRIVATE); \ + status = futex_reltimed_wait_cancelable (futexaddr, oldval, \ + timeout, FUTEX_PRIVATE); \ if (status != EAGAIN) \ break; \ \ @@ -58,9 +54,6 @@ } \ while (oldval != 0); \ \ - if (cancel) \ - LIBC_CANCEL_RESET (oldtype); \ - \ if (status == EINTR) \ result = EINTR; \ else if (status == ETIMEDOUT) \ diff --git a/sysdeps/nptl/librt-cancellation.c b/sysdeps/nptl/librt-cancellation.c deleted file mode 100644 index 39c5991..0000000 --- a/sysdeps/nptl/librt-cancellation.c +++ /dev/null @@ -1,24 +0,0 @@ -/* Copyright (C) 2002-2018 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 2002. - - 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 - - -#define __pthread_enable_asynccancel __librt_enable_asynccancel -#define __pthread_disable_asynccancel __librt_disable_asynccancel -#include diff --git a/sysdeps/nptl/lowlevellock.h b/sysdeps/nptl/lowlevellock.h index 8326e28..5af4a48 100644 --- a/sysdeps/nptl/lowlevellock.h +++ b/sysdeps/nptl/lowlevellock.h @@ -180,12 +180,13 @@ extern int __lll_timedlock_wait (int *futex, const struct timespec *, wake-up when the clone terminates. The memory location contains the thread ID while the clone is running and is reset to zero by the kernel afterwards. The kernel up to version 3.16.3 does not use the private futex - operations for futex wake-up when the clone terminates. */ + operations for futex wake-up when the clone terminates. + Both lll_wait_tid and lll_timewait_tid acts as cancellation points. */ #define lll_wait_tid(tid) \ do { \ __typeof (tid) __tid; \ while ((__tid = (tid)) != 0) \ - lll_futex_wait (&(tid), __tid, LLL_SHARED);\ + lll_futex_wait_cancel (&(tid), __tid, LLL_SHARED);\ } while (0) extern int __lll_timedwait_tid (int *, const struct timespec *) diff --git a/sysdeps/posix/open64.c b/sysdeps/posix/open64.c index c4209c8..e4ec5d1 100644 --- a/sysdeps/posix/open64.c +++ b/sysdeps/posix/open64.c @@ -34,16 +34,8 @@ __libc_open64 (const char *file, int oflag, ...) va_end (arg); } - if (SINGLE_THREAD_P) - return __libc_open (file, oflag | O_LARGEFILE, mode); - - int oldtype = LIBC_CANCEL_ASYNC (); - - int result = __libc_open (file, oflag | O_LARGEFILE, mode); - - LIBC_CANCEL_RESET (oldtype); - - return result; + /* __libc_open should be a cancellation point. */ + return __libc_open (file, oflag | O_LARGEFILE, mode); } weak_alias (__libc_open64, __open64) libc_hidden_weak (__open64) diff --git a/sysdeps/posix/pause.c b/sysdeps/posix/pause.c index 2b9eca2..879a8ab 100644 --- a/sysdeps/posix/pause.c +++ b/sysdeps/posix/pause.c @@ -38,5 +38,3 @@ __libc_pause (void) return __sigsuspend (&set); } weak_alias (__libc_pause, pause) - -LIBC_CANCEL_HANDLED (); /* sigsuspend handles our cancellation. */ diff --git a/sysdeps/posix/sigpause.c b/sysdeps/posix/sigpause.c index db9df8e..9a17d1b 100644 --- a/sysdeps/posix/sigpause.c +++ b/sysdeps/posix/sigpause.c @@ -70,6 +70,3 @@ __xpg_sigpause (int sig) return __sigpause (sig, 1); } strong_alias (__xpg_sigpause, __libc___xpg_sigpause) - -/* __sigsuspend handles cancellation. */ -LIBC_CANCEL_HANDLED (); diff --git a/sysdeps/posix/sigwait.c b/sysdeps/posix/sigwait.c index 4ff9d84..2387ecc 100644 --- a/sysdeps/posix/sigwait.c +++ b/sysdeps/posix/sigwait.c @@ -88,13 +88,8 @@ __sigwait (const sigset_t *set, int *sig) if (SINGLE_THREAD_P) return do_sigwait (set, sig); - int oldtype = LIBC_CANCEL_ASYNC (); - - int result = do_sigwait (set, sig); - - LIBC_CANCEL_RESET (oldtype); - - return result; + /* do_sigwait should be a cancellation point. */ + return do_sigwait (set, sig); } libc_hidden_def (__sigwait) weak_alias (__sigwait, sigwait) diff --git a/sysdeps/posix/waitid.c b/sysdeps/posix/waitid.c index 3207c74..7be34d2 100644 --- a/sysdeps/posix/waitid.c +++ b/sysdeps/posix/waitid.c @@ -151,16 +151,7 @@ OUR_WAITID (idtype_t idtype, id_t id, siginfo_t *infop, int options) int __waitid (idtype_t idtype, id_t id, siginfo_t *infop, int options) { - if (SINGLE_THREAD_P) - return do_waitid (idtype, id, infop, options); - - int oldtype = LIBC_CANCEL_ASYNC (); - - int result = do_waitid (idtype, id, infop, options); - - LIBC_CANCEL_RESET (oldtype); - - return result; + return do_waitid (idtype, id, infop, options); } weak_alias (__waitid, waitid) strong_alias (__waitid, __libc_waitid) diff --git a/sysdeps/sparc/sparc32/lowlevellock.c b/sysdeps/sparc/sparc32/lowlevellock.c index 8b18559..3b4cca6 100644 --- a/sysdeps/sparc/sparc32/lowlevellock.c +++ b/sysdeps/sparc/sparc32/lowlevellock.c @@ -122,7 +122,8 @@ __lll_timedwait_tid (int *tidp, const struct timespec *abstime) /* Wait until thread terminates. The kernel so far does not use the private futex operations for this. */ - if (lll_futex_timed_wait (tidp, tid, &rt, LLL_SHARED) == -ETIMEDOUT) + if (lll_futex_timed_wait_cancel (tidp, tid, &rt, LLL_SHARED) + == -ETIMEDOUT) return ETIMEDOUT; } diff --git a/sysdeps/unix/sysdep.h b/sysdeps/unix/sysdep.h index aac9303..cea81a5 100644 --- a/sysdeps/unix/sysdep.h +++ b/sysdeps/unix/sysdep.h @@ -24,6 +24,9 @@ #define SYSCALL__(name, args) PSEUDO (__##name, name, args) #define SYSCALL(name, args) PSEUDO (name, name, args) +#ifndef __ASSEMBLER__ +# include + #define __SYSCALL_CONCAT_X(a,b) a##b #define __SYSCALL_CONCAT(a,b) __SYSCALL_CONCAT_X (a, b) @@ -57,6 +60,29 @@ #define INTERNAL_SYSCALL_CALL(...) \ __INTERNAL_SYSCALL_DISP (__INTERNAL_SYSCALL, __VA_ARGS__) +#define __INTERNAL_SYSCALL_NCS0(name, err) \ + INTERNAL_SYSCALL_NCS (name, err, 0) +#define __INTERNAL_SYSCALL_NCS1(name, err, a1) \ + INTERNAL_SYSCALL_NCS (name, err, 1, a1) +#define __INTERNAL_SYSCALL_NCS2(name, err, a1, a2) \ + INTERNAL_SYSCALL_NCS (name, err, 2, a1, a2) +#define __INTERNAL_SYSCALL_NCS3(name, err, a1, a2, a3) \ + INTERNAL_SYSCALL_NCS (name, err, 3, a1, a2, a3) +#define __INTERNAL_SYSCALL_NCS4(name, err, a1, a2, a3, a4) \ + INTERNAL_SYSCALL_NCS (name, err, 4, a1, a2, a3, a4) +#define __INTERNAL_SYSCALL_NCS5(name, err, a1, a2, a3, a4, a5) \ + INTERNAL_SYSCALL_NCS (name, err, 5, a1, a2, a3, a4, a5) +#define __INTERNAL_SYSCALL_NCS6(name, err, a1, a2, a3, a4, a5, a6) \ + INTERNAL_SYSCALL_NCS (name, err, 6, a1, a2, a3, a4, a5, a6) +#define __INTERNAL_SYSCALL_NCS7(name, err, a1, a2, a3, a4, a5, a6, a7) \ + INTERNAL_SYSCALL_NCS (name, err, 7, a1, a2, a3, a4, a5, a6, a7) + +/* Issue a syscall defined by syscall number plus any other argument required. + It is similar to INTERNAL_SYSCALL_NCS macro, but without the need to pass + the expected argument number as third parameter. */ +#define INTERNAL_SYSCALL_NCS_CALL(...) \ + __INTERNAL_SYSCALL_DISP (__INTERNAL_SYSCALL_NCS, __VA_ARGS__) + #define __INLINE_SYSCALL0(name) \ INLINE_SYSCALL (name, 0) #define __INLINE_SYSCALL1(name, a1) \ @@ -88,19 +114,65 @@ #define INLINE_SYSCALL_CALL(...) \ __INLINE_SYSCALL_DISP (__INLINE_SYSCALL, __VA_ARGS__) -#define SYSCALL_CANCEL(...) \ - ({ \ - long int sc_ret; \ - if (SINGLE_THREAD_P) \ - sc_ret = INLINE_SYSCALL_CALL (__VA_ARGS__); \ - else \ - { \ - int sc_cancel_oldtype = LIBC_CANCEL_ASYNC (); \ - sc_ret = INLINE_SYSCALL_CALL (__VA_ARGS__); \ - LIBC_CANCEL_RESET (sc_cancel_oldtype); \ - } \ - sc_ret; \ + +/* Cancellation macros. */ +#ifndef __SSC +typedef long int __syscall_arg_t; +# define __SSC(__x) ((__syscall_arg_t) (__x)) +#endif + +long int __syscall_cancel (__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); +libc_hidden_proto (__syscall_cancel); + +#define __SYSCALL_CANCEL0(name) \ + (__syscall_cancel)(__NR_##name, 0, 0, 0, 0, 0, 0) +#define __SYSCALL_CANCEL1(name, a1) \ + (__syscall_cancel)(__NR_##name, __SSC(a1), 0, 0, 0, 0, 0) +#define __SYSCALL_CANCEL2(name, a1, a2) \ + (__syscall_cancel)(__NR_##name, __SSC(a1), __SSC(a2), 0, 0, 0, 0) +#define __SYSCALL_CANCEL3(name, a1, a2, a3) \ + (__syscall_cancel)(__NR_##name, __SSC(a1), __SSC(a2), __SSC(a3), 0, 0, 0) +#define __SYSCALL_CANCEL4(name, a1, a2, a3, a4) \ + (__syscall_cancel)(__NR_##name, __SSC(a1), __SSC(a2), __SSC(a3), \ + __SSC(a4), 0, 0) +#define __SYSCALL_CANCEL5(name, a1, a2, a3, a4, a5) \ + (__syscall_cancel)(__NR_##name, __SSC(a1), __SSC(a2), __SSC(a3), \ + __SSC(a4), __SSC(a5), 0) +#define __SYSCALL_CANCEL6(name, a1, a2, a3, a4, a5, a6) \ + (__syscall_cancel)(__NR_##name, __SSC(a1), __SSC(a2), __SSC(a3), \ + __SSC(a4), __SSC(a5), __SSC(a6)) + +#define __SYSCALL_CANCEL_NARGS_X(a,b,c,d,e,f,g,h,n,...) n +#define __SYSCALL_CANCEL_NARGS(...) \ + __SYSCALL_CANCEL_NARGS_X (__VA_ARGS__,7,6,5,4,3,2,1,0,) +#define __SYSCALL_CANCEL_CONCAT_X(a,b) a##b +#define __SYSCALL_CANCEL_CONCAT(a,b) __SYSCALL_CANCEL_CONCAT_X (a, b) +#define __SYSCALL_CANCEL_DISP(b,...) \ + __SYSCALL_CANCEL_CONCAT (b,__SYSCALL_CANCEL_NARGS(__VA_ARGS__))(__VA_ARGS__) + +#define __SYSCALL_CANCEL_CALL(...) \ + __SYSCALL_CANCEL_DISP (__SYSCALL_CANCEL, __VA_ARGS__) + +#define SYSCALL_CANCEL_NCS(name, nr, args...) \ + __SYSCALL_CANCEL_CALL (name, nr, args) + + +/* The loader does not need to handle thread cancellation, use direct + syscall instead. */ +#if IS_IN (rtld) +# define SYSCALL_CANCEL(...) INLINE_SYSCALL_CALL (__VA_ARGS__) +#else +# define SYSCALL_CANCEL(...) \ + ({ \ + long int sc_ret = __SYSCALL_CANCEL_CALL (__VA_ARGS__); \ + SYSCALL_CANCEL_RET ((sc_ret)); \ }) +#endif + +#endif /* __ASSEMBLER__ */ /* Machine-dependent sysdep.h files are expected to define the macro PSEUDO (function_name, syscall_name) to emit assembly code to define the diff --git a/sysdeps/unix/sysv/linux/clock_nanosleep.c b/sysdeps/unix/sysv/linux/clock_nanosleep.c index 93d5d6e..7f86c10 100644 --- a/sysdeps/unix/sysv/linux/clock_nanosleep.c +++ b/sysdeps/unix/sysv/linux/clock_nanosleep.c @@ -28,27 +28,13 @@ int __clock_nanosleep (clockid_t clock_id, int flags, const struct timespec *req, struct timespec *rem) { - INTERNAL_SYSCALL_DECL (err); - int r; - if (clock_id == CLOCK_THREAD_CPUTIME_ID) return EINVAL; if (clock_id == CLOCK_PROCESS_CPUTIME_ID) clock_id = MAKE_PROCESS_CPUCLOCK (0, CPUCLOCK_SCHED); - if (SINGLE_THREAD_P) - r = INTERNAL_SYSCALL (clock_nanosleep, err, 4, clock_id, flags, req, rem); - else - { - int oldstate = LIBC_CANCEL_ASYNC (); - - r = INTERNAL_SYSCALL (clock_nanosleep, err, 4, clock_id, flags, req, - rem); - - LIBC_CANCEL_RESET (oldstate); - } - - return (INTERNAL_SYSCALL_ERROR_P (r, err) - ? INTERNAL_SYSCALL_ERRNO (r, err) : 0); + /* If the call is interrupted by a signal handler or encounters an error, + it returns a positive value similar to errno. */ + return -SYSCALL_CANCEL_NCS (clock_nanosleep, clock_id, flags, req, rem); } weak_alias (__clock_nanosleep, clock_nanosleep) diff --git a/sysdeps/unix/sysv/linux/creat.c b/sysdeps/unix/sysv/linux/creat.c index c996cbd..089a869 100644 --- a/sysdeps/unix/sysv/linux/creat.c +++ b/sysdeps/unix/sysv/linux/creat.c @@ -35,6 +35,4 @@ __creat (const char *file, mode_t mode) } weak_alias (__creat, creat) -LIBC_CANCEL_HANDLED (); - #endif diff --git a/sysdeps/unix/sysv/linux/creat64.c b/sysdeps/unix/sysv/linux/creat64.c index d3ada38..c9eba2e 100644 --- a/sysdeps/unix/sysv/linux/creat64.c +++ b/sysdeps/unix/sysv/linux/creat64.c @@ -37,5 +37,3 @@ weak_alias (__creat64, creat64) strong_alias (__creat64, __creat) weak_alias (__creat64, creat) #endif - -LIBC_CANCEL_HANDLED (); diff --git a/sysdeps/unix/sysv/linux/futex-internal.h b/sysdeps/unix/sysv/linux/futex-internal.h index 96a07b0..9f25bfc 100644 --- a/sysdeps/unix/sysv/linux/futex-internal.h +++ b/sysdeps/unix/sysv/linux/futex-internal.h @@ -83,10 +83,7 @@ static __always_inline int futex_wait_cancelable (unsigned int *futex_word, unsigned int expected, int private) { - int oldtype; - oldtype = __pthread_enable_asynccancel (); - int err = lll_futex_timed_wait (futex_word, expected, NULL, private); - __pthread_disable_asynccancel (oldtype); + int err = lll_futex_timed_wait_cancel (futex_word, expected, NULL, private); switch (err) { case 0: @@ -137,10 +134,7 @@ futex_reltimed_wait_cancelable (unsigned int *futex_word, unsigned int expected, const struct timespec *reltime, int private) { - int oldtype; - oldtype = __pthread_enable_asynccancel (); - int err = lll_futex_timed_wait (futex_word, expected, reltime, private); - __pthread_disable_asynccancel (oldtype); + int err = lll_futex_timed_wait_cancel (futex_word, expected, reltime, private); switch (err) { case 0: @@ -200,11 +194,9 @@ futex_abstimed_wait_cancelable (unsigned int *futex_word, despite them being valid. */ if (__glibc_unlikely ((abstime != NULL) && (abstime->tv_sec < 0))) return ETIMEDOUT; - int oldtype; - oldtype = __pthread_enable_asynccancel (); - int err = lll_futex_timed_wait_bitset (futex_word, expected, abstime, - FUTEX_CLOCK_REALTIME, private); - __pthread_disable_asynccancel (oldtype); + int err = lll_futex_timed_wait_bitset_cancel (futex_word, expected, abstime, + FUTEX_CLOCK_REALTIME, + private); switch (err) { case 0: diff --git a/sysdeps/unix/sysv/linux/lowlevellock-futex.h b/sysdeps/unix/sysv/linux/lowlevellock-futex.h index 4eddadb..3a63ad5 100644 --- a/sysdeps/unix/sysv/linux/lowlevellock-futex.h +++ b/sysdeps/unix/sysv/linux/lowlevellock-futex.h @@ -89,6 +89,12 @@ ? -INTERNAL_SYSCALL_ERRNO (__ret, __err) : 0); \ }) +#define lll_futex_syscall_cp(...) \ + ({ \ + long int __ret = __SYSCALL_CANCEL_CALL (__VA_ARGS__); \ + __ret; \ + }) + #define lll_futex_wait(futexp, val, private) \ lll_futex_timed_wait (futexp, val, NULL, private) @@ -140,6 +146,32 @@ private), \ nr_wake, nr_move, mutex, val) -#endif /* !__ASSEMBLER__ */ +/* Cancellable futex macros. */ +#define lll_futex_wait_cancel(futexp, val, private) \ + lll_futex_timed_wait_cancel (futexp, val, NULL, private) + +#define lll_futex_timed_wait_cancel(futexp, val, timeout, private) \ + ({ \ + long int __ret; \ + int __op = FUTEX_WAIT; \ + __ret = lll_futex_syscall_cp (futex, futexp, \ + __lll_private_flag (__op, private), \ + val, timeout); \ + __ret; \ + }) + +#define lll_futex_timed_wait_bitset_cancel(futexp, val, timeout, \ + clockbit, private) \ + ({ \ + long int __ret; \ + int __op = FUTEX_WAIT_BITSET | clockbit; \ + __ret = lll_futex_syscall_cp (futex, futexp, \ + __lll_private_flag (__op, private), \ + val, timeout, 0, \ + FUTEX_BITSET_MATCH_ANY); \ + __ret; \ + }) + +# endif /* !__ASSEMBLER__ */ #endif /* lowlevellock-futex.h */ diff --git a/sysdeps/unix/sysv/linux/pthread_kill.c b/sysdeps/unix/sysv/linux/pthread_kill.c index 3a6171b..58980c3 100644 --- a/sysdeps/unix/sysv/linux/pthread_kill.c +++ b/sysdeps/unix/sysv/linux/pthread_kill.c @@ -42,9 +42,8 @@ __pthread_kill (pthread_t threadid, int signo) /* Not a valid thread handle. */ return ESRCH; - /* Disallow sending the signal we use for cancellation, timers, - for the setxid implementation. */ - if (signo == SIGCANCEL || signo == SIGTIMER || signo == SIGSETXID) + /* Disallow sending the signal we use for setxid implementation. */ + if (signo == SIGSETXID) return EINVAL; /* We have a special syscall to do the work. */ diff --git a/sysdeps/unix/sysv/linux/sigwait.c b/sysdeps/unix/sysv/linux/sigwait.c index 920c924..18ef2cf 100644 --- a/sysdeps/unix/sysv/linux/sigwait.c +++ b/sysdeps/unix/sysv/linux/sigwait.c @@ -37,6 +37,3 @@ __sigwait (const sigset_t *set, int *sig) libc_hidden_def (__sigwait) weak_alias (__sigwait, sigwait) strong_alias (__sigwait, __libc_sigwait) - -/* __sigtimedwait handles cancellation. */ -LIBC_CANCEL_HANDLED (); diff --git a/sysdeps/unix/sysv/linux/sigwaitinfo.c b/sysdeps/unix/sysv/linux/sigwaitinfo.c index 55003fc..71bdc94 100644 --- a/sysdeps/unix/sysv/linux/sigwaitinfo.c +++ b/sysdeps/unix/sysv/linux/sigwaitinfo.c @@ -28,6 +28,3 @@ __sigwaitinfo (const sigset_t *set, siginfo_t *info) libc_hidden_def (__sigwaitinfo) weak_alias (__sigwaitinfo, sigwaitinfo) strong_alias (__sigwaitinfo, __libc_sigwaitinfo) - -/* __sigtimedwait handles cancellation. */ -LIBC_CANCEL_HANDLED (); diff --git a/sysdeps/unix/sysv/linux/socketcall.h b/sysdeps/unix/sysv/linux/socketcall.h index bbae6f8..eda233d 100644 --- a/sysdeps/unix/sysv/linux/socketcall.h +++ b/sysdeps/unix/sysv/linux/socketcall.h @@ -87,16 +87,39 @@ }) -#if IS_IN (libc) -# define __pthread_enable_asynccancel __libc_enable_asynccancel -# define __pthread_disable_asynccancel __libc_disable_asynccancel -#endif +#define __SOCKETCALL_CANCEL1(__name, __a1) \ + SYSCALL_CANCEL_NCS (socketcall, __name, \ + ((long int [1]) { (long int) __a1 })) +#define __SOCKETCALL_CANCEL2(__name, __a1, __a2) \ + SYSCALL_CANCEL_NCS (socketcall, __name, \ + ((long int [2]) { (long int) __a1, (long int) __a2 })) +#define __SOCKETCALL_CANCEL3(__name, __a1, __a2, __a3) \ + SYSCALL_CANCEL_NCS (socketcall, __name, \ + ((long int [3]) { (long int) __a1, (long int) __a2, (long int) __a3 })) +#define __SOCKETCALL_CANCEL4(__name, __a1, __a2, __a3, __a4) \ + SYSCALL_CANCEL_NCS (socketcall, __name, \ + ((long int [4]) { (long int) __a1, (long int) __a2, (long int) __a3, \ + (long int) __a4 })) +#define __SOCKETCALL_CANCEL5(__name, __a1, __a2, __a3, __a4, __a5) \ + SYSCALL_CANCEL_NCS (socketcall, __name, \ + ((long int [5]) { (long int) __a1, (long int) __a2, (long int) __a3, \ + (long int) __a4, (long int) __a5 })) +#define __SOCKETCALL_CANCEL6(__name, __a1, __a2, __a3, __a4, __a5, __a6) \ + SYSCALL_CANCEL_NCS (socketcall, __name, \ + ((long int [6]) { (long int) __a1, (long int) __a2, (long int) __a3, \ + (long int) __a4, (long int) __a5, (long int) __a6 })) + +#define __SOCKETCALL_CANCEL(...) __SOCKETCALL_DISP (__SOCKETCALL_CANCEL,\ + __VA_ARGS__) #define SOCKETCALL_CANCEL(name, args...) \ ({ \ - int oldtype = LIBC_CANCEL_ASYNC (); \ - long int sc_ret = __SOCKETCALL (SOCKOP_##name, args); \ - LIBC_CANCEL_RESET (oldtype); \ + long int sc_ret = __SOCKETCALL_CANCEL (SOCKOP_##name, args); \ + if (sc_ret > -4096UL) \ + { \ + __set_errno (-sc_ret); \ + sc_ret = -1L; \ + } \ sc_ret; \ }) diff --git a/sysdeps/unix/sysv/linux/syscall_cancel.c b/sysdeps/unix/sysv/linux/syscall_cancel.c new file mode 100644 index 0000000..ac08bb7 --- /dev/null +++ b/sysdeps/unix/sysv/linux/syscall_cancel.c @@ -0,0 +1,62 @@ +/* Default cancellation syscall bridge. + 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 +#include + +#define ADD_LABEL(__label) \ + asm volatile ( \ + ".global " __label "\t\n" \ + ".type " __label ",\%function\t\n" \ + __label ":\n"); + +/* This is the generic version of the cancellable syscall code which + adds the label guards (__syscall_cancel_arch_{start,end}) used + on SIGCANCEL handler (sigcancel_handler at nptl-init.c) to check if + the cancelled syscall have side-effects that need to be signaled to + program. + + An important contrainst should be observed when using this generic + implementation: the __syscall_cancel_arch_end should point to the + immediate next instruction after the syscall one. This is because + kernel will signal interrupted syscall with side effects by setting + the signal frame Program Counter right after the syscall instruction. + + If the INTERNAL_SYSCALL_NCS macro use more instructions to get the + error condition from kernel (as for powerpc and sparc), uses an + out of the line helper (as for ARM thumb), or uses a kernel helper + gate (as for i686 or ia64) the architecture should either adjust the + macro or provide a custom __syscall_cancel_arch implementation. */ +long int +__syscall_cancel_arch (volatile int *ch, __syscall_arg_t nr, + __syscall_arg_t a1, __syscall_arg_t a2, + __syscall_arg_t a3, __syscall_arg_t a4, + __syscall_arg_t a5, __syscall_arg_t a6) +{ + ADD_LABEL ("__syscall_cancel_arch_start"); + if (__glibc_unlikely (*ch & CANCELED_BITMASK)) + __syscall_do_cancel(); + + INTERNAL_SYSCALL_DECL(err); + long int result = INTERNAL_SYSCALL_NCS (nr, err, 6, a1, a2, a3, a4, a5, a6); + ADD_LABEL ("__syscall_cancel_arch_end"); + if (INTERNAL_SYSCALL_ERROR_P (result, err)) + return -INTERNAL_SYSCALL_ERRNO (result, err); + return result; +} +libc_hidden_def (__syscall_cancel_arch) diff --git a/sysdeps/unix/sysv/linux/sysdep.h b/sysdeps/unix/sysv/linux/sysdep.h index 4fd0a9b..235399e 100644 --- a/sysdeps/unix/sysv/linux/sysdep.h +++ b/sysdeps/unix/sysv/linux/sysdep.h @@ -27,6 +27,23 @@ -1l; \ }) +/* Check error from cancellable syscall and set errno accordingly. + Linux uses a negative return value to indicate syscall errors + and since version 2.1 the return value of a system call might be + negative even if the call succeeded (e.g., the `lseek' system call + might return a large offset). + Current contract is kernel make sure the no syscall returns a value + in -1 .. -4095 as a valid result so we can savely test with -4095. */ +#define SYSCALL_CANCEL_RET(__ret) \ + ({ \ + if (__ret > -4096UL) \ + { \ + __set_errno (-__ret); \ + __ret = -1; \ + } \ + __ret; \ + }) + /* Provide a dummy argument that can be used to force register alignment for register pairs if required by the syscall ABI. */ #ifdef __ASSUME_ALIGNED_REGISTER_PAIRS From patchwork Mon Feb 26 21:03:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 129706 Delivered-To: patch@linaro.org Received: by 10.80.172.228 with SMTP id x91csp4290278edc; Mon, 26 Feb 2018 13:04:44 -0800 (PST) X-Google-Smtp-Source: AH8x225szdm4yXF8kUAql3HL9AwZIcothzDblllmmSl5eLi8pIFYXKcKrzJ61Fj8DjvoYLADdrLa X-Received: by 2002:a17:902:724a:: with SMTP id c10-v6mr11808138pll.98.1519679084158; Mon, 26 Feb 2018 13:04:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519679084; cv=none; d=google.com; s=arc-20160816; b=nIM8KQp60ANiy3t6+vFefiNxmkIK88OJ4jMRllyVDnN+5cdhLpOajGMxhNThc6mmoI V2IH1O0kczE60v3XZ6j4ELPae5hBJzLjWs6DTkInEVTogGm+Qg5MB6ZtQmv0CsWaEJLx PPS08nXd3koCBaGqjL39r3bA4gZA0G8jpwnd1QqSNAgXn0LDInDfX/GOcb1uyVtEZHnn 7PVQ6at5MITYy8zM3d0+J0OF6L9MVgx7PxdpOP+gIEXSnLt5olsIT5g+WA6inUpxIm3s 5Qa82LuGc1E68lWE+p4800LSEfEEJeCr8xTdYy6mU1PswngSsIsVHVagUCTzrPuILQFP ZH7g== 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=0OvUE6+pqjeOafyE/ME95EIdFmdPEo1SAGyN3s7voRA=; b=rxNVoWNtaPRqGOhsUYwSACEqzsDKGD7N3OqPkbC5iSRLkGLU6FOH0Ab6e/rLKr5+sf NbHHK7+AapUHALeMu6bI4UJG4sH3/0wC191fL31MCgqho5rc/JN562k+4mmyJwZKacYj P/KY8HSJF8x8LylJqkFBokKW/cCsEo56Ezpz3W4QEenHlm7jG+8FpGBU1w4O4Iswr2O2 8AxgeCE1v1qzQbjgpO42kXvaJEyBMfw6mamyq9moxYSoF8KB+kNAHIKs/D1JhUJ3m6xp J97mfuZH6NwXpgTB4Ag5BKAC6coOGZYDonSXCPdk7CnRYccGAkWDSy+jCpvjEgrg9+RA 8fKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=gCHgi0/w; spf=pass (google.com: domain of libc-alpha-return-90621-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-90621-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 s11si6001468pgp.162.2018.02.26.13.04.43 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Feb 2018 13:04:44 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-90621-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=gCHgi0/w; spf=pass (google.com: domain of libc-alpha-return-90621-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-90621-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=Sgwxe2cyZJ3xGHDm1NlTjCFo90oAGWr PUQS+l4jQgflQgwb2+Gocr+U+A+IRxLwcuR2ncyHpU7eyY/MY+UjJfiKgb3CcI3m sr2zklDPeoZe34318RIvoGcKstERnkcZ8h6aoXpEIgVlZknFwOJjJ6Om9zKNhaZc ov7L1VrZh2tY= 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=czAQe8icjjVu6ZnMr8Hyl2WHUxM=; b=gCHgi 0/wp0ofWTLlbP8upbsd4tzyfMANA2upeZXzj7P0fh+cHvVzkI2RrRghcpyA/VA6R jiA1xbJOcSs05Dv0zVpybF3bmIEyxTaGYbidafRhi8cjFxcouXGfsXJ7buciASWk yVm3kh2y827v0RpR48jTt4UZ0vCy2goaAJyHac= Received: (qmail 75113 invoked by alias); 26 Feb 2018 21:03:56 -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 74980 invoked by uid 89); 26 Feb 2018 21:03:55 -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=Hx-spam-relays-external:209.85.220.196, H*RU:209.85.220.196 X-HELO: mail-qk0-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=0OvUE6+pqjeOafyE/ME95EIdFmdPEo1SAGyN3s7voRA=; b=bVlIBYv1KSo3zFBXEmEjTFBysNvgP3RVlDnOHzdpWfvG/2SIM/qCZ30odib5IknjwD OgRr3VVj9mkoUqjXcwXKVt1DccvssjGjw2lDzBWOxGb+8iNIBYYG73lZSL9Or1o3W/7O 4ScV9RsqUnlb2P1CQJZ14HMeWe85Nh/Vf6tFdCfP3WeO7VDGm3tLJ8kz2QQVIOQ9sQ+8 ggy89CWWTEq0Q4D4fF1A7Pcadpg0Yv7ZZTDGv7OyfRMSJOaD8H/Aeasf3yOVF5jvl1+H NX/AosvtFSQ2Qr/2ptY3FBSJYtXNoI+m6g1CYgnsbJ8AxIQcmKUr6y15TlbHkMqC24W7 C8RA== X-Gm-Message-State: APf1xPC8oJDWI4DgCwgqaEOywJDUaUWn5GnebDaVU9DsEEIzcTbSvXMQ 6REbV4yKXFR6BLKdCNSaBbNboTiJf/I= X-Received: by 10.55.161.134 with SMTP id k128mr18222526qke.295.1519679029483; Mon, 26 Feb 2018 13:03:49 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH v2 04/21] nptl: x86_64: Fix Race conditions in pthread cancellation (BZ#12683) Date: Mon, 26 Feb 2018 18:03:19 -0300 Message-Id: <1519679016-12241-5-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 patches adds the x86_64 modification required for the BZ#12683. It basically provide the required ucontext_get_pc symbol and remove the arch-specific libc-cancellation implementations. It also remove bogus arch-specific THREAD_ATOMIC_BIT_SET where it always reference to current thread instead of the one referenced by input 'descr' argument. It works as long the input is the self thread pointer, however it creates wrong code is it used along with a description to a different one (as on nptl/pthread_cancel.c). The code generated create an additional load to reference to TLS segment, for instance the code: THREAD_ATOMIC_BIT_SET (THREAD_SELF, cancelhandling, CANCELED_BIT); Compiles to: lock;orl $4, %fs:776 Where with patch changes it now compiles to: mov %fs:16,%rax lock;orl $4, 776(%rax) If some usage indeed proves to be a hotspot we can add an extra macro with a more descriptive name (THREAD_ATOMIC_BIT_SET_SELF for instance) where x86_64 might optimize it. In fact all x86_64 THREAD_ATOMIC_* macros do not respect the input descr and possible will fail when used with a 'descr' difference than THREAD_SELF. Checked on x86_64-linux-gnu. [BZ #12683] * sysdeps/unix/sysv/linux/x86_64/cancellation.S: Remove file. * sysdeps/unix/sysv/linux/x86_64/libc-cancellation.S: Remove file. * sysdeps/unix/sysv/linux/x86_64/librt-cancellation.S: Remove file. * sysdeps/unix/sysv/linux/x86_64/lowlevellock.h (lll_wait_tid): Use cancellable futex wait call. * sysdeps/unix/sysv/linux/x86_64/sigcontextinfo.h (ucontext_get_pc): New function. * sysdeps/x86_64/nptl/tcb-offsets.sym (TCB_CANCELING_BITMASK): Remove. * sysdeps/x86_64/nptl/tls.h (THREAD_ATOMIC_CMPXCHG_VAL, THREAD_ATOMIC_BIT_SET): Remove macros. --- ChangeLog | 13 +++ sysdeps/unix/sysv/linux/x86_64/cancellation.S | 115 --------------------- 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/sigcontextinfo.h | 11 ++ sysdeps/x86_64/nptl/tcb-offsets.sym | 1 - sysdeps/x86_64/nptl/tls.h | 11 -- 8 files changed, 28 insertions(+), 173 deletions(-) delete mode 100644 sysdeps/unix/sysv/linux/x86_64/cancellation.S delete mode 100644 sysdeps/unix/sysv/linux/x86_64/libc-cancellation.S delete mode 100644 sysdeps/unix/sysv/linux/x86_64/librt-cancellation.S -- 2.7.4 diff --git a/sysdeps/unix/sysv/linux/x86_64/cancellation.S b/sysdeps/unix/sysv/linux/x86_64/cancellation.S deleted file mode 100644 index f3fb19d..0000000 --- a/sysdeps/unix/sysv/linux/x86_64/cancellation.S +++ /dev/null @@ -1,115 +0,0 @@ -/* Copyright (C) 2009-2018 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 2009. - - 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 -#include -#include -#include "lowlevellock.h" - -#define PTHREAD_UNWIND JUMPTARGET(__pthread_unwind) -#if IS_IN (libpthread) -# if defined SHARED && !defined NO_HIDDEN -# undef PTHREAD_UNWIND -# define PTHREAD_UNWIND __GI___pthread_unwind -# endif -#else -# ifndef SHARED - .weak __pthread_unwind -# endif -#endif - - -#ifdef __ASSUME_PRIVATE_FUTEX -# define LOAD_PRIVATE_FUTEX_WAIT(reg) \ - movl $(FUTEX_WAIT | FUTEX_PRIVATE_FLAG), reg -#else -# if FUTEX_WAIT == 0 -# define LOAD_PRIVATE_FUTEX_WAIT(reg) \ - movl %fs:PRIVATE_FUTEX, reg -# else -# define LOAD_PRIVATE_FUTEX_WAIT(reg) \ - movl %fs:PRIVATE_FUTEX, reg ; \ - orl $FUTEX_WAIT, reg -# endif -#endif - -/* It is crucial that the functions in this file don't modify registers - other than %rax and %r11. The syscall wrapper code depends on this - because it doesn't explicitly save the other registers which hold - relevant values. */ - .text - - .hidden __pthread_enable_asynccancel -ENTRY(__pthread_enable_asynccancel) - movl %fs:CANCELHANDLING, %eax -2: movl %eax, %r11d - orl $TCB_CANCELTYPE_BITMASK, %r11d - cmpl %eax, %r11d - je 1f - - lock - cmpxchgl %r11d, %fs:CANCELHANDLING - jnz 2b - - andl $(TCB_CANCELSTATE_BITMASK|TCB_CANCELTYPE_BITMASK|TCB_CANCELED_BITMASK|TCB_EXITING_BITMASK|TCB_CANCEL_RESTMASK|TCB_TERMINATED_BITMASK), %r11d - cmpl $(TCB_CANCELTYPE_BITMASK|TCB_CANCELED_BITMASK), %r11d - je 3f - -1: ret - -3: subq $8, %rsp - cfi_adjust_cfa_offset(8) - LP_OP(mov) $TCB_PTHREAD_CANCELED, %fs:RESULT - lock - orl $TCB_EXITING_BITMASK, %fs:CANCELHANDLING - mov %fs:CLEANUP_JMP_BUF, %RDI_LP - call PTHREAD_UNWIND - hlt -END(__pthread_enable_asynccancel) - - - .hidden __pthread_disable_asynccancel -ENTRY(__pthread_disable_asynccancel) - testl $TCB_CANCELTYPE_BITMASK, %edi - jnz 1f - - movl %fs:CANCELHANDLING, %eax -2: movl %eax, %r11d - andl $~TCB_CANCELTYPE_BITMASK, %r11d - lock - cmpxchgl %r11d, %fs:CANCELHANDLING - jnz 2b - - movl %r11d, %eax -3: andl $(TCB_CANCELING_BITMASK|TCB_CANCELED_BITMASK), %eax - cmpl $TCB_CANCELING_BITMASK, %eax - je 4f -1: ret - - /* Performance doesn't matter in this loop. We will - delay until the thread is canceled. And we will unlikely - enter the loop twice. */ -4: mov %fs:0, %RDI_LP - movl $__NR_futex, %eax - xorq %r10, %r10 - addq $CANCELHANDLING, %rdi - LOAD_PRIVATE_FUTEX_WAIT (%esi) - syscall - movl %fs:CANCELHANDLING, %eax - jmp 3b -END(__pthread_disable_asynccancel) diff --git a/sysdeps/unix/sysv/linux/x86_64/libc-cancellation.S b/sysdeps/unix/sysv/linux/x86_64/libc-cancellation.S deleted file mode 100644 index ed7af0d..0000000 --- a/sysdeps/unix/sysv/linux/x86_64/libc-cancellation.S +++ /dev/null @@ -1,21 +0,0 @@ -/* Copyright (C) 2009-2018 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 2009. - - 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 - . */ - -#define __pthread_enable_asynccancel __libc_enable_asynccancel -#define __pthread_disable_asynccancel __libc_disable_asynccancel -#include "cancellation.S" diff --git a/sysdeps/unix/sysv/linux/x86_64/librt-cancellation.S b/sysdeps/unix/sysv/linux/x86_64/librt-cancellation.S deleted file mode 100644 index d0f0ee4..0000000 --- a/sysdeps/unix/sysv/linux/x86_64/librt-cancellation.S +++ /dev/null @@ -1,21 +0,0 @@ -/* Copyright (C) 2009-2018 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 2009. - - 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 - . */ - -#define __pthread_enable_asynccancel __librt_enable_asynccancel -#define __pthread_disable_asynccancel __librt_disable_asynccancel -#include "cancellation.S" diff --git a/sysdeps/unix/sysv/linux/x86_64/lowlevellock.h b/sysdeps/unix/sysv/linux/x86_64/lowlevellock.h index eedb6fc..957d4c1 100644 --- a/sysdeps/unix/sysv/linux/x86_64/lowlevellock.h +++ b/sysdeps/unix/sysv/linux/x86_64/lowlevellock.h @@ -231,10 +231,10 @@ extern int __lll_timedlock_elision (int *futex, short *adapt_count, afterwards. The kernel up to version 3.16.3 does not use the private futex operations for futex wake-up when the clone terminates. */ #define lll_wait_tid(tid) \ - do { \ - __typeof (tid) __tid; \ - while ((__tid = (tid)) != 0) \ - lll_futex_wait (&(tid), __tid, LLL_SHARED);\ + do { \ + __typeof (tid) __tid; \ + while ((__tid = (tid)) != 0) \ + lll_futex_wait_cancel (&(tid), __tid, LLL_SHARED); \ } while (0) extern int __lll_timedwait_tid (int *, const struct timespec *) diff --git a/sysdeps/unix/sysv/linux/x86_64/sigcontextinfo.h b/sysdeps/unix/sysv/linux/x86_64/sigcontextinfo.h index 41ace60..3cc7336 100644 --- a/sysdeps/unix/sysv/linux/x86_64/sigcontextinfo.h +++ b/sysdeps/unix/sysv/linux/x86_64/sigcontextinfo.h @@ -15,6 +15,9 @@ License along with the GNU C Library; if not, see . */ +#ifndef _SIGCONTEXTINFO_H +#define _SIGCONTEXTINFO_H + #include #define SIGCONTEXT siginfo_t *_si, ucontext_t * @@ -28,3 +31,11 @@ #define CALL_SIGHANDLER(handler, signo, ctx) \ (handler)((signo), SIGCONTEXT_EXTRA_ARGS (ctx)) + +static inline +uintptr_t ucontext_get_pc (const ucontext_t *uc) +{ + return uc->uc_mcontext.gregs[REG_RIP]; +} + +#endif diff --git a/sysdeps/x86_64/nptl/tcb-offsets.sym b/sysdeps/x86_64/nptl/tcb-offsets.sym index 8a25c48..b225e5b 100644 --- a/sysdeps/x86_64/nptl/tcb-offsets.sym +++ b/sysdeps/x86_64/nptl/tcb-offsets.sym @@ -19,7 +19,6 @@ PRIVATE_FUTEX offsetof (tcbhead_t, private_futex) -- Not strictly offsets, but these values are also used in the TCB. TCB_CANCELSTATE_BITMASK CANCELSTATE_BITMASK TCB_CANCELTYPE_BITMASK CANCELTYPE_BITMASK -TCB_CANCELING_BITMASK CANCELING_BITMASK TCB_CANCELED_BITMASK CANCELED_BITMASK TCB_EXITING_BITMASK EXITING_BITMASK TCB_CANCEL_RESTMASK CANCEL_RESTMASK diff --git a/sysdeps/x86_64/nptl/tls.h b/sysdeps/x86_64/nptl/tls.h index bdd0237..ed0c65b 100644 --- a/sysdeps/x86_64/nptl/tls.h +++ b/sysdeps/x86_64/nptl/tls.h @@ -315,17 +315,6 @@ typedef struct abort (); }) -/* Atomic set bit. */ -# define THREAD_ATOMIC_BIT_SET(descr, member, bit) \ - (void) ({ if (sizeof ((descr)->member) == 4) \ - asm volatile (LOCK_PREFIX "orl %1, %%fs:%P0" \ - :: "i" (offsetof (struct pthread, member)), \ - "ir" (1 << (bit))); \ - else \ - /* Not necessary for other sizes in the moment. */ \ - abort (); }) - - /* Set the stack guard field in TCB head. */ # define THREAD_SET_STACK_GUARD(value) \ THREAD_SETMEM (THREAD_SELF, header.stack_guard, value) From patchwork Mon Feb 26 21:03:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 129705 Delivered-To: patch@linaro.org Received: by 10.80.172.228 with SMTP id x91csp4290078edc; Mon, 26 Feb 2018 13:04:33 -0800 (PST) X-Google-Smtp-Source: AH8x225mNs6gmyRFJJo5/PHKZs17W7H/LPkEiQXKNRLgb1CRq3IC9qDoVLLxDVtSSA/O4+tpSG1F X-Received: by 10.99.127.69 with SMTP id p5mr9396063pgn.346.1519679073108; Mon, 26 Feb 2018 13:04:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519679073; cv=none; d=google.com; s=arc-20160816; b=OxBC7DnYz4C/Opt9Iwb5OKuO+Sw4s1jZOk68pH/XqvnswJ2rTmEPAqlKdMXezi6zhx QvQAuikX6GKn5EhTZREOnNK61QuH0V+4a9sIZ4d+H3Ob3d68aSM5IqGcKKYOaSfvZ5jd pXxGi2JjuB4PzPoa3rGw0KCfGu2sBWMRENr8ob8sKt+ksHQvN7ZKAEu3/t6IPze7pROq npK0s6ubcxrHh1KUHdSGXPW98pboLf8YdDyJUrD7nzPbk2YY8OnPOfxTdp8+WPArGdyO 0EwDOj5xh3ePFlWbHV9pj57h4oR9IMLNhzUS1EpF30pOZsKNTnnfa3V4VUyDEeFtl9Ak WNgA== 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=p8suRjrFsnvbGHU+pIxX4d3nMdMgiYQq/qYtPg2hiUQ=; b=QB6vIeDKLlimAPPCEAEHwGF8JC1Ss142cBu8mHTNui6wKdN0XN37DOVFXXrOM6Qywy 1S6WxsvHgltM4fCw23l/muvGATIJOnTmJ2H7kshb6Jiimt5V6nxRGJI79fwNVhYDrLkY Dn4jRgu1b1lXe/75Wzk7RRfPWXofs69XYsZIF1XobzY/yA/RhI8jWh8o9dM9ywvE18Wn PKE7ROFvEuqMGemi7fE8w64RJh00XROBe+PLB9YQt+O86isRZi1BqA2Pb6Ak4JEYu8r/ C7ofCPD4Rwulzigu8eU3jp20Bhhahsr5qMvv1EOkJy9U1cVp/dW1EVYUv/Bcgif0AvKP 2YZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=HT4YoxtJ; spf=pass (google.com: domain of libc-alpha-return-90620-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-90620-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 l9si7289875pff.155.2018.02.26.13.04.32 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Feb 2018 13:04:33 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-90620-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=HT4YoxtJ; spf=pass (google.com: domain of libc-alpha-return-90620-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-90620-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=pdfToa18g3t3qnx96BfvHA4XHSqoOrK 2E0Cb/Qek00RN+SkUCJNVTj3BELWAA88Z8CHExSDmyO02E6XnwD0WeqcdrG0MMpF 8hHpjfP7m8sgs2O9vl/Reek6JCXrnlsVnwj+bNdUrfWqIsTl9s9+3PuWxM4k6Rfs Q0lpUKB36FIg= 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=yRvVSlCnSHEmuGWp6ykAQdOwQeA=; b=HT4Yo xtJlbiT9S5npcmRGv8wWzKfaKrPjry5J4nyvEK1VhQiJ1p+VEteWb/XHb7nm5t5b GVDKkFH1h3PY4BaQtkDiniibdiF3t300w/Mi38Jd6zhHFa7BO9Uh4zF24QrJYCeO Y7piJpUgH6VcUxPkKXHYHW1XJ2Dwnkcpt51o7k= Received: (qmail 75031 invoked by alias); 26 Feb 2018 21:03:55 -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 74908 invoked by uid 89); 26 Feb 2018 21:03:54 -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, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-qt0-f195.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=p8suRjrFsnvbGHU+pIxX4d3nMdMgiYQq/qYtPg2hiUQ=; b=cLlhqnxd2WwWPsXhBHo8Ts1voyotn0HGN6nlQ7MNKl+CvLKWne0oZ5EyW681YdzMN1 P2HRp4J+t+IMQiALLH7Lkhm8CrqDMB3Lpi6XpZrxbi8H0DFTvrLZnFn7D3LGvk+n6hSz 88RaGexNYChvrpapQ7EJdzAdn0j+FpdCzBPowWYG0xFPt0ldeDJYHG7Tzn1wOOaWR9NT vD7RhAQq7droM9DG7oK+WtSuU58kZPlchuuKfTr9V/JHLYKIjW+cV6MqVitj6P7ZOauF lc+tTu96/3Ucx1oC/S8fCaYT39PySd1IcmgfRmwDo90v05ziNo1InnWYZnb+n5Kgdw18 dJEA== X-Gm-Message-State: APf1xPCHNPcZ0o6TWOEVBuD4rE7wcW8+kNur/g6Mz98mxrUSRWzWTLa1 ShHeVjBb9v0qFb2nvtK4Mbp/hslwgY8= X-Received: by 10.200.24.196 with SMTP id o4mr19306746qtk.79.1519679030987; Mon, 26 Feb 2018 13:03:50 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH v2 05/21] nptl: x32: Fix Race conditions in pthread cancellation (BZ#12683) Date: Mon, 26 Feb 2018 18:03:20 -0300 Message-Id: <1519679016-12241-6-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 patches adds the x32 modification required for the BZ#12683. It basically adjust the syscall size used to pass the arguments to the syscall cancel wrappers by zero extending pointers type while preserting values for default types (such as off_t). Checked on x86_64-linux-gnu-x32. [BZ #12683] * sysdeps/unix/sysv/linux/x86_64/x32/sysdep.h (__syscall_arg_t): Define type for x32. (__SSC): Add platform specific macro. * include/libc-pointer-arith.h (__integer_if_pointer_type_sub, __integer_if_pointer_type, cast_to_integer): Parametrize integer type cast. (cast_to_uinteger): New macro. --- ChangeLog | 9 +++++++++ include/libc-pointer-arith.h | 16 +++++++++++----- sysdeps/unix/sysv/linux/x86_64/x32/sysdep.h | 13 +++++++++++++ 3 files changed, 33 insertions(+), 5 deletions(-) -- 2.7.4 diff --git a/include/libc-pointer-arith.h b/include/libc-pointer-arith.h index 1ee3362..65107cc 100644 --- a/include/libc-pointer-arith.h +++ b/include/libc-pointer-arith.h @@ -25,17 +25,23 @@ # define __pointer_type(type) (__builtin_classify_type ((type) 0) == 5) /* intptr_t if P is true, or T if P is false. */ -# define __integer_if_pointer_type_sub(T, P) \ +# define __integer_if_pointer_type_sub(T, P, INTTYPE) \ __typeof__ (*(0 ? (__typeof__ (0 ? (T *) 0 : (void *) (P))) 0 \ - : (__typeof__ (0 ? (intptr_t *) 0 : (void *) (!(P)))) 0)) + : (__typeof__ (0 ? (INTTYPE *) 0 : (void *) (!(P)))) 0)) /* intptr_t if EXPR has a pointer type, or the type of EXPR otherwise. */ -# define __integer_if_pointer_type(expr) \ +# define __integer_if_pointer_type(expr, inttype) \ __integer_if_pointer_type_sub(__typeof__ ((__typeof__ (expr)) 0), \ - __pointer_type (__typeof__ (expr))) + __pointer_type (__typeof__ (expr)), \ + inttype) /* Cast an integer or a pointer VAL to integer with proper type. */ -# define cast_to_integer(val) ((__integer_if_pointer_type (val)) (val)) +# define cast_to_integer(val) \ + ((__integer_if_pointer_type (val, intptr_t)) (val)) + +/* Cast an integer or a pointer VAL to unsigned integer with proper type. */ +# define cast_to_uinteger(val) \ + ((__integer_if_pointer_type (val, uintptr_t)) (val)) /* Align a value by rounding down to closest size. e.g. Using size of 4096, we get this behavior: diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/sysdep.h b/sysdeps/unix/sysv/linux/x86_64/x32/sysdep.h index 7f978c7..787e7f2 100644 --- a/sysdeps/unix/sysv/linux/x86_64/x32/sysdep.h +++ b/sysdeps/unix/sysv/linux/x86_64/x32/sysdep.h @@ -18,6 +18,19 @@ #ifndef _LINUX_X32_SYSDEP_H #define _LINUX_X32_SYSDEP_H 1 +#ifndef __ASSEMBLER__ +#include +#include + +typedef long long int __syscall_arg_t; + +/* Syscall arguments for x32 follows x86_64 size, however pointers are 32 + bits in size. The idea is to zero extend pointer types while cast to + signed 64 bit default arguments. */ +#define __SSC(__x) ((__syscall_arg_t) cast_to_uinteger (__x)) + +#endif + /* There is some commonality. */ #include #include From patchwork Mon Feb 26 21:03:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 129708 Delivered-To: patch@linaro.org Received: by 10.80.172.228 with SMTP id x91csp4290588edc; Mon, 26 Feb 2018 13:05:03 -0800 (PST) X-Google-Smtp-Source: AH8x227ZJRXRBYAQ+oksraB3hDqobv22HozqDcIOgl01Aporxn8+7/Ns0e9jeYy2WWB9ChTS9fCL X-Received: by 2002:a17:902:968e:: with SMTP id n14-v6mr12002256plp.21.1519679103473; Mon, 26 Feb 2018 13:05:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519679103; cv=none; d=google.com; s=arc-20160816; b=XgMjkIwnhKNd4bSjEbCQrLPFgKvAhOBcqbnU0fzzt9siTR57/OhTIqgCNdVc9qw0u6 29KxzDWKk2Ndc1R0rXKktkNhWIhnzMGQZEWLrQJQrveoMnkJ03xj6NKiegWYzq90+n6h RxymckEzVzFGzPuj50tp5/4htIJ6pu6UErddw7sRMRWtBD/KLB4xwYRkmGGUWg2YbpFS +n/Oiwuhgvuv4UG3LmWe0KC9RhXunCkIwhmSDv7g1GwrGgjLvNR0Ty02LDbMOmwC8fso JtIBqSZCKU8PSoxkq5nTIwSKIbC69TbynOzQG1hLJJuB0+xy1m8MIBozh7ehD9GjEQSW Qszg== 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=aXQVoRcRGXRM63V0IWe+RSmCm6b7Q6tYt2UgkQQodqI=; b=KVuiRFi+nFD7dRs9DoL/iSdPwHL9YORwC0JI7XWq+1YpSeWJr6Kzp5BPReTnmeS4e1 1wlGkXRiz6U2IZvT8e+ugvjWbn+s/pG+2GZvQMhubjL7hmwq4ZTWxlfftU8O4Q3wtJUD 8oJN89vDvbCGPD07UMQzg0hDWctw5tAKLzRss9DqldbU/0upM0EwdXtWn7Y7C/tQk+WQ b8dHfTQYUyXSxLSpKzaNan4t3NkZG55nT3FFvDQCcNDK34uTnU2leCZq1IAg7+De7ziX z5+DstcLo0e6Oj9+aSZwBzb9J3DnOgFXGgnEP44fW6xmYUR/of9Hk6jbMIjAXjsjgwEI i5Xw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=q9k6PXav; spf=pass (google.com: domain of libc-alpha-return-90623-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-90623-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 e3-v6si7337996plb.100.2018.02.26.13.05.03 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Feb 2018 13:05:03 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-90623-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=q9k6PXav; spf=pass (google.com: domain of libc-alpha-return-90623-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-90623-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=cm7RmyOAuIeyFfajmX0qToOeH0CoUqA 2gSjM7uw2Jeb/VQmWQvyJozqK33Rj5pBom6ExkMqfpINXXKK0I0v0dEeVPn/cmgE svBm5KbOaXYMooK4X0l4oUOCImmWsT7+iYc2veLHvx+QHkLjRjdmPGFPAB5/xeZy gJqhxAtYntu4= 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=oKZZZXsWDeN2k4ISsoesKq94kj0=; b=q9k6P Xav2HTiv6mVkaHzTqwl/tBvBcGsx6LD40NlZCIpQ1xblhsISPsAxWp3J4kpcDlDk 1XSI7C+6BOamTn86f9hUho97PpFQcniSba5XIyWpjz4mq1cNizGAjWH7f4SjooLG X26Gn7cfFt+d/8RXMJsgOJGJxIpr9ik2rUQcfE= Received: (qmail 75535 invoked by alias); 26 Feb 2018 21:03:58 -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 75412 invoked by uid 89); 26 Feb 2018 21:03:58 -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= 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=aXQVoRcRGXRM63V0IWe+RSmCm6b7Q6tYt2UgkQQodqI=; b=QRaQM4q29fqt7xlLz5tLfKuiTa5qpwSDjKTI8Lq9QQFZ06PtaCO+F5RgatqFjmmk67 DAUS14Zj9Cii+aep/cpyMuj56zpK1qCbTsRLEWnUKnn7W450LdTojobUlziukcew3Dxz D9xetDEX22DGujYLXtMrrhZ6uhUauXrtNyXgAiToJDnmonSfQH+VFLLnnQXuFkeZZXXL /9NF/Y2envn7gMxpHxWYq2RYW8kb5e/uHQ7f0c08g34wuiSlPNhGSA9Li8hO+yq6h4Vd InBqQktPg10wrwMyNLk+KCQNGWQeTLW5dzg8rxgpn1Oy58Ot4cn3RijxcNy8lISXkEqX rL0w== X-Gm-Message-State: APf1xPBeopwEMuVxilfTzboeTPVeUfxedDFVCbYxMCk04dbhaS2wAW9Z BOBy3fawdP6TKMmcnLsvL0dzkm4SOXY= X-Received: by 10.200.9.48 with SMTP id t45mr20324388qth.107.1519679032402; Mon, 26 Feb 2018 13:03:52 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH v2 06/21] nptl: i386: Fix Race conditions in pthread cancellation (BZ#12683) Date: Mon, 26 Feb 2018 18:03:21 -0300 Message-Id: <1519679016-12241-7-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 i386 modifications required for the BZ#12683. It basically provides the required ucontext_get_pc symbol, add the cancelable syscall wrapper and fix a thread atomic update macro. On i386 an arch-specific cancellation implementation is required because depending of the glibc configuration and underlying kernel the syscall may be done using a vDSO symbol (__kernel_vsyscall). By using the vDSO symbol the resulting PC value for an interrupted syscall points to an adress outside the expected markers in __syscall_cancel_arch. It has been discussed in LKML [1] on how kernel could help userland to accomplish it, but afaik discussion was stalled. Also, since glibc supports i486, the old 'int 0x80' should be used in the syscall wrapper. One option could make minimum default chip to pentium II (which implements sysenter) or add a runtime check on syscall_cancel.S to use 'int 0x80' or sysenter. Similar to x86_64, it also remove bogus arch-specific THREAD_ATOMIC_BIT_SET where it always reference to current thread instead of the one referenced by input 'descr' argument. Checked on i686-linux-gnu. [BZ #12683] * sysdeps/i386/nptl/tls.h (THREAD_ATOMIC_CMPXCHG_VAL, THREAD_ATOMIC_BIT_SET): Remove macro. * sysdeps/unix/sysv/linux/i386/Makefile [$(subdir) = elf] (sysdep-rtld_routines): Add libc-do-syscall object. * sysdeps/unix/sysv/linux/i386/lowlevellock.h (lll_wait_tid): Use cancellable futex syscall macro. * sysdeps/unix/sysv/linux/i386/syscall_cancel.S: New file. * sysdeps/unix/sysv/linux/i386/sigcontextinfo.h (ucontext_get_pc): New function. [1] https://lkml.org/lkml/2016/3/8/1105 --- ChangeLog | 10 +++ sysdeps/i386/nptl/tls.h | 11 --- 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 ++++++++++++++++++++++++++ 6 files changed, 132 insertions(+), 13 deletions(-) create mode 100644 sysdeps/unix/sysv/linux/i386/syscall_cancel.S -- 2.7.4 diff --git a/sysdeps/i386/nptl/tls.h b/sysdeps/i386/nptl/tls.h index fcda135..ae4de89 100644 --- a/sysdeps/i386/nptl/tls.h +++ b/sysdeps/i386/nptl/tls.h @@ -383,17 +383,6 @@ tls_fill_user_desc (union user_desc_init *desc, abort (); }) -/* Atomic set bit. */ -#define THREAD_ATOMIC_BIT_SET(descr, member, bit) \ - (void) ({ if (sizeof ((descr)->member) == 4) \ - asm volatile (LOCK_PREFIX "orl %1, %%gs:%P0" \ - :: "i" (offsetof (struct pthread, member)), \ - "ir" (1 << (bit))); \ - else \ - /* Not necessary for other sizes in the moment. */ \ - abort (); }) - - /* Set the stack guard field in TCB head. */ #define THREAD_SET_STACK_GUARD(value) \ THREAD_SETMEM (THREAD_SELF, header.stack_guard, value) diff --git a/sysdeps/unix/sysv/linux/i386/Makefile b/sysdeps/unix/sysv/linux/i386/Makefile index 4080b8c..bae2e4b 100644 --- a/sysdeps/unix/sysv/linux/i386/Makefile +++ b/sysdeps/unix/sysv/linux/i386/Makefile @@ -6,7 +6,7 @@ sysdep_routines += ioperm iopl vm86 endif ifeq ($(subdir),elf) -sysdep-dl-routines += libc-do-syscall +sysdep-rtld_routines += libc-do-syscall sysdep-others += lddlibc4 install-bin += lddlibc4 endif diff --git a/sysdeps/unix/sysv/linux/i386/lowlevellock.h b/sysdeps/unix/sysv/linux/i386/lowlevellock.h index 38fbc25..072bc11 100644 --- a/sysdeps/unix/sysv/linux/i386/lowlevellock.h +++ b/sysdeps/unix/sysv/linux/i386/lowlevellock.h @@ -230,7 +230,7 @@ extern int __lll_timedlock_elision (int *futex, short *adapt_count, do { \ __typeof (tid) __tid; \ while ((__tid = (tid)) != 0) \ - lll_futex_wait (&(tid), __tid, LLL_SHARED);\ + lll_futex_wait_cancel (&(tid), __tid, LLL_SHARED);\ } while (0) extern int __lll_timedwait_tid (int *tid, const struct timespec *abstime) diff --git a/sysdeps/unix/sysv/linux/i386/sigcontextinfo.h b/sysdeps/unix/sysv/linux/i386/sigcontextinfo.h index a4ed29a..e7a9f17 100644 --- a/sysdeps/unix/sysv/linux/i386/sigcontextinfo.h +++ b/sysdeps/unix/sysv/linux/i386/sigcontextinfo.h @@ -16,6 +16,11 @@ License along with the GNU C Library; if not, see . */ +#ifndef _SIGCONTEXTINFO_H +#define _SIGCONTEXTINFO_H + +#include + #define SIGCONTEXT struct sigcontext #define SIGCONTEXT_EXTRA_ARGS #define GET_PC(ctx) ((void *) ctx.eip) @@ -48,3 +53,11 @@ do { \ "i" (sizeof (struct sigcontext) / 4) \ : "cc", "edi"); \ } while (0) + +static inline uintptr_t +ucontext_get_pc (const ucontext_t *uc) +{ + return uc->uc_mcontext.gregs[REG_EIP]; +} + +#endif /* _SIGCONTEXTINFO_H */ diff --git a/sysdeps/unix/sysv/linux/i386/syscall_cancel.S b/sysdeps/unix/sysv/linux/i386/syscall_cancel.S new file mode 100644 index 0000000..5596b3e --- /dev/null +++ b/sysdeps/unix/sysv/linux/i386/syscall_cancel.S @@ -0,0 +1,107 @@ +/* Cancellable syscall wrapper. Linux/i686 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 + +/* long int [eax] __syscall_cancel_arch (int *cancelhandling [SP], + long int nr [SP+4], + long int arg1 [SP+8], + long int arg2 [SP+12], + long int arg3 [SP+16], + long int arg4 [SP+20], + long int arg5 [SP+24], + long int arg6 [SP+28]) */ + +ENTRY (__syscall_cancel_arch) + pushl %ebp + cfi_def_cfa_offset (8) + cfi_offset (ebp, -8) + pushl %edi + cfi_def_cfa_offset (12) + cfi_offset (edi, -12) + pushl %esi + cfi_def_cfa_offset (16) + cfi_offset (esi, -16) + pushl %ebx + cfi_def_cfa_offset (20) + cfi_offset (ebx, -20) + + .global __syscall_cancel_arch_start + .type __syscall_cancel_arch_start, @function +__syscall_cancel_arch_start: + + /* if (*cancelhandling & CANCELED_BITMASK) + __syscall_do_cancel() */ + testb $4, (%eax) + jne 1f + + /* Issue a 6 argument syscall, the nr [%eax] being the syscall + number. */ + movl 24(%esp), %eax + movl 28(%esp), %ebx + movl 32(%esp), %ecx + movl 36(%esp), %edx + movl 40(%esp), %esi + movl 44(%esp), %edi + movl 48(%esp), %ebp + + /* We can not use the vDSO helper for syscall (__kernel_vsyscall) + because the returned PC from kernel will indicate whether the + interrupted syscall have any side-effects that need to be reported + back to program. And the signal handler (sigcancel_handler at + nptl-init.c) checks the PC agains the __syscall_cancel_arch_* + marks. */ + int $128 + + .global __syscall_cancel_arch_end + .type __syscall_cancel_arch_end, @function +__syscall_cancel_arch_end: + + popl %ebx + cfi_restore (ebx) + cfi_def_cfa_offset (16) + popl %esi + cfi_restore (esi) + cfi_def_cfa_offset (12) + popl %edi + cfi_restore (edi) + cfi_def_cfa_offset (8) + popl %ebp + cfi_restore (ebp) + cfi_def_cfa_offset (4) + ret + +1: + /* Although the __syscall_do_cancel do not return, we need to stack + being set correctly for unwind. */ + popl %ebx + cfi_restore (ebx) + cfi_def_cfa_offset (16) + popl %esi + cfi_restore (esi) + cfi_def_cfa_offset (12) + popl %edi + cfi_restore (edi) + cfi_def_cfa_offset (8) + popl %ebp + cfi_restore (ebp) + cfi_def_cfa_offset (4) + jmp __syscall_do_cancel + +END (__syscall_cancel_arch) +libc_hidden_def (__syscall_cancel_arch) From patchwork Mon Feb 26 21:03:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 129707 Delivered-To: patch@linaro.org Received: by 10.80.172.228 with SMTP id x91csp4290415edc; Mon, 26 Feb 2018 13:04:53 -0800 (PST) X-Google-Smtp-Source: AH8x226UbFPnJK1KaBifFsZWCXp1aAGTNDICOL3dYXT7efnHdiX+YnRgsHtMSfV3BmpUollAcO36 X-Received: by 10.98.247.9 with SMTP id h9mr11880496pfi.212.1519679093885; Mon, 26 Feb 2018 13:04:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519679093; cv=none; d=google.com; s=arc-20160816; b=WiERuojagIV8v2/21iN7zaoCdQSadUJoO4J9Gjv7DL3Vzp0vjkeF4pYupuwTc2agaa QSHuJY6GCcUdbKEcqsXNnIGFwHJnuwbUL139Tkpw/YTJ6kh/xGeNjqfNBRwJIFTEDUr4 y0/lIZv609LS/0x1ebF3f1qehfwCaSIohS7SO5jNuTfCibBWJHTyms0D+YK0IlE4cQLm 9HEE15kj5hWs23wKa46lNeHZ8KAysF21zPEJq5G8CgvU4g40sivg/Ia2KvO8s1VAd79W qpUEj8QGe1ir9+McqsHpCbBJ08E85r3BS63Lud2zm8zL9fFPIjO3RrL0v3Ji45Kzd5RA c9Pg== 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=1fH9Xga2PMgKXeCAB0Z/gXJbmF0E+eqe1UFTyzWmLmQ=; b=DTlbxekWDgmR9AugoDwP4/0D2xi+ZNbcCDXoCWWw9EtnlrF62rVQjbFqyOX2D0IIN2 DrN8cUQGXJxHKrw2jQjuvlJJkB4bJGhXI3l8pk0TEaz5y1SDDClBHcDu5VXGVvQclzqy xT4kKlIIcJ7vqAy+idl+wfNlpRAP6pMcwfeSeHCxkTk6GTRv6B8vrXD/sSMnbw+XfraD iKhpUaaybW6wRIrNI7I6RtIp9+pHJ/HKc5vMcHEoaTP/YZf86Bl2eHbuEr2Q/mTUYQ6f 6viDr0LcJ0t6w3KvBZCDWjIqGFhmWP3SQC1hAXbNVA7mQ9w2gigReFLlVFebqA2ymLS4 zwfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=jJ8T5zhy; spf=pass (google.com: domain of libc-alpha-return-90622-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-90622-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 a21si5979807pgw.213.2018.02.26.13.04.53 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Feb 2018 13:04:53 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-90622-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=jJ8T5zhy; spf=pass (google.com: domain of libc-alpha-return-90622-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-90622-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=bIqhPewLXTTgilIgftU/yT1jJuWWc5L 2ITs4L4UnRfy/OlvyfuOydLoSZkIfVx6vjMb1q8MvGLhHe38BC3dEG/BDshO4+tL 7y8/6oxk0KP8O0Xpzta1aac2ahMTFNM3l/qyFQHiPQQVQoNG25XLzqqTik1ylxDZ eXfvXBsV+Fik= 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=ojDDoqrW/Wiak1HtV43RgyZ12p0=; b=jJ8T5 zhywKwYaCWeCW69GxIS7EcUk9S5RjkI7ga+X/liuP33LjHp5HV7q89Opuq9k6Ykt GwZtYJTKakaKzCpXVo8y3kJ8dVJKdOmP5jZGuI0SefN35ZbciWLF4kYeXS34mGlm /f+KE/ZHt36tTEgxNSIuYzwRma+Zp30OPQ4Z9k= Received: (qmail 75485 invoked by alias); 26 Feb 2018 21:03:58 -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 75362 invoked by uid 89); 26 Feb 2018 21:03:57 -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= X-HELO: mail-qt0-f194.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=1fH9Xga2PMgKXeCAB0Z/gXJbmF0E+eqe1UFTyzWmLmQ=; b=nQTnJSViOCAbeC5QeyMdamF5bO+4Vpo2Va4vZhWp1EquWR7nNaHyYjSFJEJbVDroH8 TwJIa5ihsi7Zm8uRc4I1oxL6eQ4GeGE2w978iKznsoiCm/H1gCWEk3jooMe2mZUi74lx eOS1gUqc8FBVljCS6Xd0zArxFf1xoyqX1HxbN4rU/hk9prv/ttuEiDShao4f1ePNF6o7 9qZEU51by/QaqcHAyhI6v4POBMSjs4FDURltSgpPaQe3yQtGEL9S4iM10HVQwUr87M0c hl0zCOoCczwMY0RJ0z3zOyatLPohvC2yy4VD21sOp6lY9c5+f4A0HZbnpSqnD1sYebQL s/Og== X-Gm-Message-State: APf1xPAdqJb47Gbd9ED+Evck1pfaErRUHbaSZQoy1Z1URNUxEpKPF9Tv /juXNvrAeNb8POeO0+JuVjD19/P1czQ= X-Received: by 10.200.12.68 with SMTP id l4mr3822436qti.71.1519679033645; Mon, 26 Feb 2018 13:03:53 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH v2 07/21] nptl: powerpc: Fix Race conditions in pthread cancellation (BZ#12683) Date: Mon, 26 Feb 2018 18:03:22 -0300 Message-Id: <1519679016-12241-8-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 patches adds the powerpc64 modification required for the BZ#12683. It basically adds the required __pthread_get_pc function and a arch specific syscall_cancel implementation. The powerpc requires an arch-specific syscall_cancel because INTERNAL_SYSCALL_NCS adds a mfcr just after the sc instruction to get the CR0.SO bit information from kernel (which signals the error return status). So for cancelled syscalls with side effects, __pthread_get_pc will point to mcfr and thus invalidating the checks on sigcancel_handler. Checked on powerpc64le-linux-gnu and powerpc-linux-gnu. [BZ #12683] * sysdeps/unix/sysv/linux/powerpc/syscall_cancel.S: New file. * sysdeps/unix/sysv/linux/powerpc/sysdep-cancel.h (__pthread_get_pc): New function. --- ChangeLog | 5 ++ sysdeps/unix/sysv/linux/powerpc/sigcontextinfo.h | 16 ++++++ sysdeps/unix/sysv/linux/powerpc/syscall_cancel.S | 64 ++++++++++++++++++++++++ 3 files changed, 85 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/powerpc/syscall_cancel.S -- 2.7.4 diff --git a/sysdeps/unix/sysv/linux/powerpc/sigcontextinfo.h b/sysdeps/unix/sysv/linux/powerpc/sigcontextinfo.h index 72381e3..3be71f7 100644 --- a/sysdeps/unix/sysv/linux/powerpc/sigcontextinfo.h +++ b/sysdeps/unix/sysv/linux/powerpc/sigcontextinfo.h @@ -15,7 +15,11 @@ License along with the GNU C Library; if not, see . */ +#ifndef _SIGCONTEXTINFO_H +#define _SIGCONTEXTINFO_H + #include +#include #define SIGCONTEXT struct sigcontext * #define SIGCONTEXT_EXTRA_ARGS @@ -24,3 +28,15 @@ #define GET_STACK(ctx) ((void *)((ctx)->regs->gpr[1])) #define CALL_SIGHANDLER(handler, signo, ctx) \ (handler)((signo), SIGCONTEXT_EXTRA_ARGS (ctx)) + +static inline uintptr_t +ucontext_get_pc (const ucontext_t *uc) +{ +#ifdef __powerpc64__ + return uc->uc_mcontext.gp_regs[PT_NIP]; +#else + return uc->uc_mcontext.uc_regs->gregs[PT_NIP]; +#endif +} + +#endif /* _SIGCONTEXTINFO_H */ diff --git a/sysdeps/unix/sysv/linux/powerpc/syscall_cancel.S b/sysdeps/unix/sysv/linux/powerpc/syscall_cancel.S new file mode 100644 index 0000000..2e56c72 --- /dev/null +++ b/sysdeps/unix/sysv/linux/powerpc/syscall_cancel.S @@ -0,0 +1,64 @@ +/* Cancellable syscall wrapper. Linux/powerpc 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 + +/* long int [r3] __syscall_cancel_arch (int *cancelhandling [r3], + long int nr [r4], + long int arg1 [r5], + long int arg2 [r6], + long int arg3 [r7], + long int arg4 [r8], + long int arg5 [r9], + long int arg6 [r10]) */ + +ENTRY (__syscall_cancel_arch) + + .globl __syscall_cancel_arch_start + .type __syscall_cancel_arch_start,@function +__syscall_cancel_arch_start: + + /* if (*cancelhandling & CANCELED_BITMASK) + __syscall_do_cancel() */ + lwz r0,0(r3) + rldicl. r0,r0,62,63 + beq 1f + b __syscall_do_cancel + nop +1: + ABORT_TRANSACTION + /* Issue a 6 argument syscall, the nr [r4] being the syscall + number. */ + mr r0,r4 + mr r3,r5 + mr r4,r6 + mr r5,r7 + mr r6,r8 + mr r7,r9 + mr r8,r10 + sc + + .globl __syscall_cancel_arch_end + .type __syscall_cancel_arch_end,@function +__syscall_cancel_arch_end: + + bnslr+ + neg r3,r3 + blr +END (__syscall_cancel_arch) +libc_hidden_def (__syscall_cancel_arch) From patchwork Mon Feb 26 21:03:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 129709 Delivered-To: patch@linaro.org Received: by 10.80.172.228 with SMTP id x91csp4290781edc; Mon, 26 Feb 2018 13:05:13 -0800 (PST) X-Google-Smtp-Source: AH8x2263viTCXWjI1wY3CFP5qh2vNLaOSGVBcBhEaLcqAMc6sZAeKYPKc9aod6ZwTiuT6NLg+S+s X-Received: by 2002:a17:902:22f:: with SMTP id 44-v6mr11728881plc.418.1519679113761; Mon, 26 Feb 2018 13:05:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519679113; cv=none; d=google.com; s=arc-20160816; b=jeyfEhnRaw00McW33BjlbMa2WBEFMliC4ku3zbAjLvJWnMav+/JrQTSGoNMmYnTWgt IhccZ+YQWl1jtXIMbJIcmvR2mrHs0gF4hI7pdcVNBK6xRtgp+qioZoY7jKF3oQkUiaB8 vRhXwnoS9KinAoGkn47N1/G2C28xoobO2qmohMdodJYjMEaWH+Jz7eYXZUIMO9fAtsb4 ++m9pXvBHc3RFqju7TfoNvcWqU75J4oAv7PbeyZWNU0Mj7AuL+eVVkoJZQlzQ8DZ82xT exhRewhRYZIUHccl+OMOwl+BeBJImY/AlDHGgjeoMZyjiTsArHjLkj3yZ1hw0qWEjjNM a8kg== 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=rIKASI/xqygYPeVZN0MZuyA4i3E0zGIlkJOiUFa81Ow=; b=0C0+1s342vbeQ2qbs5YA/gmKMrYvXW2rBFnfLyJdvAbyl9lphRTbn6w2R91gLT1tO9 SWUSZ2oV2dRK7gSxLABec8rz0Y3ECPL+xSrDY8KtmXMnveh+MuJOVL6RzWloytvtVMJ7 5jMRSnuxA40D2yQJoChW1fWCi9ShcxqNf7rHd8l5y4qAn1srC4RyM879D/QdRmYEsndG fYgnch8nageLWuO+ofXl0kc7OdaBtyi+uWkgs3YnbDklUVHyWgF9blfg7mXb2iqhcDDH g7Ed5UFZZBD/7hv5hLJKCsqUspHF54ILPZEVtJG+WbfOTOobtpkLkM2Uf9z+xznCtYSJ o3Hg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=CKcTVNpg; spf=pass (google.com: domain of libc-alpha-return-90624-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-90624-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 x4-v6si7300479pln.652.2018.02.26.13.05.13 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Feb 2018 13:05:13 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-90624-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=CKcTVNpg; spf=pass (google.com: domain of libc-alpha-return-90624-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-90624-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=ChU1q61/pnpa2KCRdqJjIJndeL3NBe3 0yleJmflUqUdZ3R0LyuSiRQDgrEb0x8YPx+geKIVT8qrKvz/vXPuxlyk5ueyVS9V mKRv8toGVx/USzhTrIEsfZ4iOrypgi5GDFOWIQs09Mo7Xv63w3fJeciTdL0p/0vx AkG0EseOVUq0= 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=rSZ/EArDPWhdQrytvqpNDL96XB8=; b=CKcTV NpgnLif1yC733pfRVOQT082/ffH4ZvFJVvlOPJbM1UclOYvHMfeFgHYw5UFnm/ri c6jcQz+iOOL3/RcghWrPZ4FF82G2rJ6K2rj/jrsw6KE6w4g18893kicPqDMv+dta N21GHn7OBNOOC1fHZjbtlU/hxr9M3StXt0FBus= Received: (qmail 75828 invoked by alias); 26 Feb 2018 21:04:00 -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 75698 invoked by uid 89); 26 Feb 2018 21:03:59 -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= X-HELO: mail-qt0-f193.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=rIKASI/xqygYPeVZN0MZuyA4i3E0zGIlkJOiUFa81Ow=; b=hDPEPeWiE+v06NYlGxKZg4I7YskWycJlEFNa0HWJo9gw2gYidC+k5BlkuI5PDd9aht x3L0prs1LsRJ9NISM2sDsw5G+Kk/dEmtSL2cWH/Dnvmqi6Uiiviw/0bOvh+a+Ni9TegG 27uuY4Ngpxuy7zbpUvgoRHNAEAxHDvlh28rwy9Wu17uJgBPPul+N9+UHTLKX5FFeXf5v z8KtODl2cqiMiCReVBVWXzpwG3IEArk1KiABNO6jUWxv4dcSWcNNdbc/7aXlKDCi24Ij zREiUilsrya2NQPfjkF5Tw23bFybkK1P2p2igVgjHQT5LKEivvxyHXej2DnjCtVFYNku rb9w== X-Gm-Message-State: APf1xPD9Ou0z0SVLtJnDfihJraqkxp2ADy/ZYgOqxrQ7Ghn3yBXrtw5Z NNofxb38czz/3MBxdt+5CsF63yQSQ2k= X-Received: by 10.200.24.46 with SMTP id q43mr20235726qtj.309.1519679036167; Mon, 26 Feb 2018 13:03:56 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH v2 08/21] nptl: aarch64: Fix Race conditions in pthread cancellation (BZ#12683) Date: Mon, 26 Feb 2018 18:03:23 -0300 Message-Id: <1519679016-12241-9-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 aarch64 modifications required for the BZ#12683. It basically adds the required ucontext_get_pc function. The built cancelable syscall wrapper for aarch64 using GCC 7.2.1 and default configuration flags shows an expected optimized version: --- __GI___syscall_cancel_arch: .LFB38: .cfi_startproc .global __syscall_cancel_arch_start .type __syscall_cancel_arch_start,@function __syscall_cancel_arch_start: ldr w9, [x0] tbnz x9, 2, .L7 mov x8, x1 mov x0, x2 mov x1, x3 mov x2, x4 mov x3, x5 mov x4, x6 mov x5, x7 svc 0 // syscall nr .global __syscall_cancel_arch_end .type __syscall_cancel_arch_end,@function __syscall_cancel_arch_end: ret --- A similar code is obtained with GCC 5.3.1, so I see to need to provide an arch-specific syscall_cancel.S for aarch64. Checked on aarch64-linux-gnu. [BZ #12683] * sysdeps/unix/sysv/linux/aarch64/sysdep-cancel.h (PSEUDO): Redefine to call __syscall_cancel function for cancellable syscalls. (__pthread_get_ip): Add implementation. * sysdeps/unix/sysv/linux/aarch64/sysdep.h (SYSCALL_CANCEL_ERROR): Add definition. (SYSCALL_CANCEL_ERRNO): Likewise. --- ChangeLog | 4 ++++ sysdeps/unix/sysv/linux/aarch64/sigcontextinfo.h | 11 +++++++++++ 2 files changed, 15 insertions(+) -- 2.7.4 diff --git a/sysdeps/unix/sysv/linux/aarch64/sigcontextinfo.h b/sysdeps/unix/sysv/linux/aarch64/sigcontextinfo.h index 04596ef..d9822dc 100644 --- a/sysdeps/unix/sysv/linux/aarch64/sigcontextinfo.h +++ b/sysdeps/unix/sysv/linux/aarch64/sigcontextinfo.h @@ -16,6 +16,9 @@ License along with the GNU C Library; if not, see . */ +#ifndef _SIGCONTEXTINFO_H +#define _SIGCONTEXTINFO_H + #include #include @@ -33,3 +36,11 @@ (act)->sa_flags |= SA_SIGINFO; \ (sigaction) (sig, act, oact); \ }) + +static inline uintptr_t +ucontext_get_pc (const ucontext_t *uc) +{ + return uc->uc_mcontext.pc; +} + +#endif From patchwork Mon Feb 26 21:03:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 129710 Delivered-To: patch@linaro.org Received: by 10.80.172.228 with SMTP id x91csp4290925edc; Mon, 26 Feb 2018 13:05:23 -0800 (PST) X-Google-Smtp-Source: AH8x225u9WW77FwXIMrnZM6ecv7/RVRWW+Qokoyob1ZKWh1QPnHpiRQN/WtXcXtQo4mM9PusUI4a X-Received: by 2002:a17:902:ba95:: with SMTP id k21-v6mr12123293pls.111.1519679123567; Mon, 26 Feb 2018 13:05:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519679123; cv=none; d=google.com; s=arc-20160816; b=M1m/1w4zk1e6JcgLVyrayi/68t9ZVce3Jsz2AaosW14PLSgXgDmk/SX+d8Kshrib8t 2hhXZkMTPj0+Oc65laSFS2hspqlBNWOOOojFeivsd/tdeHrpnkBknIh2Q9D9DMjzilI1 nuyNyzcrFxNVDEBI4wNTky1xyptHLLfK+mk8ucDZ/iNpWwZkUSB5OHkGRZmxU+a42McQ yIuSZLEKscN+paG3L66wH0ZE/gNQkmZ7U1Q0ImNpPa+R4sB3oU1XDeWX1z6SC+dqEAYL N2g2VmtfYWvTe2xwxd8wJMvtpWicHJ1WpXxxz4pk59ja9LE24+56Y4po0bZia9yZ7mGi ZihQ== 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=rAUuEneS+qPytZgXsnbUyy6v3Qv7It8G30fXgEteDVA=; b=RYMCwS4an/8dsL0ktQraEYKKDyBi2kwCtRe1v2FNX6thjxLZRJSRcQCfWvU3VvOB76 Gk5QvJAkPn/Q2NmDluSj6MaYEQnbvcodyC2z1Fz8ZwbNcDA8Bze5RhcDb5ECFN0eQSDa yQBuZFFzJt5LibTPliiTx9yH4XNY/aGsroZMWb6thgubTIq4RAFO1HcQBgfTxHvKXukv v+5tgprzJbDVYY19TOtOpHwznmFU25qf5SpvpIvWzdLuQcnVqxULfqrfZXBYBMkV720u xD/T76/GVejduFKBF1O3H79jJVXBnHFyx3dRdlmyvCYFYOoEAa86SCrUxFBWOTC9RZVB II+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=hPuLtDvv; spf=pass (google.com: domain of libc-alpha-return-90625-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-90625-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 n8si6033033pgt.427.2018.02.26.13.05.23 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Feb 2018 13:05:23 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-90625-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=hPuLtDvv; spf=pass (google.com: domain of libc-alpha-return-90625-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-90625-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=voS/vWlSSGYDMze5wcg1BqP3gn40ImC dkh2MKzS/9iwYLCADO8ok5MF36wNLpoeFsEVBtSowSF4e7brFIgWmE8lx1R1EFir IvSbXqGlIYOfAYs/lM7xUkpSuW8MRPXpCI+WrRvJA5TCHjeZbDWuQPg5uFDGaOmH pqs7f+t7tQsA= 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=fm9fvVCTOvPK3pngXKGk+zK/byE=; b=hPuLt DvvJBhCl6XVayjJE1tFCcOl/NotxcVamiiUrAeK3O+auwcUy597AOuVN8xFdHNow TtoH/5H2WbcqL4x4I1m7yxhG1LsRUJOgMnIqLFoZ4UU9Jt54dsVjTesXYmqngVbr DTNiG5PFmsjY+gMQ6SGG+VHHQqlT0N82pFg4YM= Received: (qmail 76049 invoked by alias); 26 Feb 2018 21:04:02 -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 75884 invoked by uid 89); 26 Feb 2018 21:04:01 -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= X-HELO: mail-qt0-f195.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=rAUuEneS+qPytZgXsnbUyy6v3Qv7It8G30fXgEteDVA=; b=EblDODW7SY/a4dlEBiLY1mXQ9FMOuxpBstH7vzcEwrFZ/v7M+571I6Bv9++WIeumhT iP9FfCQmgfTOUmwoukI0uO+vTD+G3LpkB968Q6OUTzHdEE5JFGNWPVmciTWoUcaO6GeZ imaWEJQ8Xywh1wWaO3CHQugafpqgzBCpO26gpmS3Ohcf4nlNusKahWpvo8iCs+Ki4FME jqeuuDoEgmR8xR5qACXVMeSyJhSDsa1MGPboTD7ddEK6JwqboZtsNzNqF0KiFCVhDvtU nVSAjOfodFBx4GDBlqP4Paz1Wbf/ui8VzyUaen6Z/VaX9MbqFayHMc+Ntg2+pPGYZGMp pYZw== X-Gm-Message-State: APf1xPBknFqfKn6mlybWeEpe3L1i/gcgeo51yppy/feij9ZlUJIb21GU yKIII/+uw9p7jF+Sx5gGuBBp7Wf39sA= X-Received: by 10.200.49.28 with SMTP id g28mr19193317qtb.279.1519679037602; Mon, 26 Feb 2018 13:03:57 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH v2 09/21] nptl: arm: Fix Race conditions in pthread cancellation (BZ#12683) Date: Mon, 26 Feb 2018 18:03:24 -0300 Message-Id: <1519679016-12241-10-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 ARM modifications required for the BZ#12683. It basically adds the required ucontext_get_pc function and adjust the generic syscall_cancel build. For ARM we need to build syscall_cancel in ARM mode (-marm) to avoid INTERNAL_SYSCALL to issue the syscall through the helper gate __libc_do_syscall (which invalidates the mark checks on SIGCANCEL handler). Checked on arm-linux-gnueabihf. [BZ #12683] * sysdeps/unix/sysv/linux/arm/Makefile (CFLAGS-syscall_cancel.c): New rule. * sysdeps/unix/sysv/linux/arm/sigcontextinfo.h (ucontext_get_pc): New function. --- ChangeLog | 6 ++++++ sysdeps/unix/sysv/linux/arm/Makefile | 3 +++ sysdeps/unix/sysv/linux/arm/sigcontextinfo.h | 12 ++++++++++++ 3 files changed, 21 insertions(+) -- 2.7.4 diff --git a/sysdeps/unix/sysv/linux/arm/Makefile b/sysdeps/unix/sysv/linux/arm/Makefile index 4adc35d..8f01b52 100644 --- a/sysdeps/unix/sysv/linux/arm/Makefile +++ b/sysdeps/unix/sysv/linux/arm/Makefile @@ -30,6 +30,9 @@ endif ifeq ($(subdir),nptl) libpthread-sysdep_routines += libc-do-syscall libpthread-shared-only-routines += libc-do-syscall + +# INLINE_SYSCALL uses the helper __libc_do_syscall in thumb mode. +CFLAGS-syscall_cancel.c += -marm endif ifeq ($(subdir),resolv) diff --git a/sysdeps/unix/sysv/linux/arm/sigcontextinfo.h b/sysdeps/unix/sysv/linux/arm/sigcontextinfo.h index daf9bd3..3d4eb2f 100644 --- a/sysdeps/unix/sysv/linux/arm/sigcontextinfo.h +++ b/sysdeps/unix/sysv/linux/arm/sigcontextinfo.h @@ -16,6 +16,10 @@ License along with the GNU C Library. If not, see . */ +#ifndef _SIGCONTEXTINFO_H +#define _SIGCONTEXTINFO_H + +#include #include #define SIGCONTEXT siginfo_t *_si, ucontext_t * @@ -46,3 +50,11 @@ (act)->sa_flags |= SA_SIGINFO; \ (sigaction) (sig, act, oact); \ }) + +static inline uintptr_t +ucontext_get_pc (const ucontext_t *uc) +{ + return uc->uc_mcontext.arm_pc; +} + +#endif /* _SIGCONTEXTINFO_H */ From patchwork Mon Feb 26 21:03:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 129712 Delivered-To: patch@linaro.org Received: by 10.80.172.228 with SMTP id x91csp4291352edc; Mon, 26 Feb 2018 13:05:50 -0800 (PST) X-Google-Smtp-Source: AH8x226dAtQk+LFCtKzpYHH+B4nCpp2irAJRPyuOGaeWO/TR51L7KhcdI7fv5iF59Y098fQ63QkN X-Received: by 2002:a17:902:9a41:: with SMTP id x1-v6mr11681450plv.256.1519679150490; Mon, 26 Feb 2018 13:05:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519679150; cv=none; d=google.com; s=arc-20160816; b=g6/m22JkxqJhyYCmWpNzKfTx1LMb1MG3B+r1N8IoAfaKD3qMG72VDI8O3O3Zn+rcdg OKhys6cNRmdkAoc2aJ+C85cFCpcqj1STq9LEUAyVQsjoHuZL53W3Odd+eWK8uAZs+CIk a582twEnY8SrOLFHlIRPPf72Gl3IVTJUgw0nhQV4z3f1wGhk3/MdEvyFuxZsLGnypBGc SbtfMcaExAmqbgztCpzt32vqqNy4wFnsUbBICHsavdz29Bp0r96zcN1VLeRBoHtrrBYc lrkuXVZd1jkxS+8sXSDvb0+Bp2cu5jeXyWxsRnBKWP5L0cT7BL/dnn8UfPgpTJ9wbv3X /jLQ== 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:cc: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=Hfqb4riE7MSKiPugo9tCu8rbfM5T4BR4JnxqyvmSmnc=; b=VKtTLSmGIe2dIOsq5NfvRk0AeZxlZ+hh5UdAtiYAEHmPj9VJs75Q3NKwfUaSodbxO4 3CwjsaSzoaCVfyXiZ6k/WAjQGPcTJEF2hud5XDYbNGiqviPVtj7vn6ghl6D6bMO/tBgb ubVoMCAfktybeev+ssNhkIm9a3rMnNpmqeJKROx+8V6nAK46iYqrZ7vn3tse8jITyg8a D9kIMEeFL5MTF+8g2Gav5GgYWHbvZL+3UQYeQhE+aCWCDZPZCVQTds3U3wgYEMOTCwQq 9+Mi0Vg8ToMcTPVn569OUTEpUgZWuGTs+1j+9EgGXJ6YjuspzcbUmOCoogmfo7Q7CcW4 FGwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=xbqQeAzf; spf=pass (google.com: domain of libc-alpha-return-90627-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-90627-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 x5si6007555pgq.437.2018.02.26.13.05.50 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Feb 2018 13:05:50 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-90627-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=xbqQeAzf; spf=pass (google.com: domain of libc-alpha-return-90627-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-90627-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:cc:subject:date:message-id:in-reply-to :references; q=dns; s=default; b=mqBrz5T78Pzu+/NcFrRl1k6TGTl3Dd+ yEgm/q14hH+V9b+Yw+mRO/lkFXLAYCtedb/x5TeZIZkiIA6qRzwTRimAC6IO8WIh DYWOcCm5VPOLmn+lKYcVh3xGGAX1BT8Mw84JcEB/UWG6J4coQcUxJr8l/aZWstE3 FevINcKTZD4E= 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:cc:subject:date:message-id:in-reply-to :references; s=default; bh=ffhvcb1vl2mLoEvF+DVdWmTkKqw=; b=xbqQe AzftOCp+CtY8/Fx/Rnz9KwZNQnFbPhDDR8uQH5eZxgMy2VFNaEl2tMPOgmqbxaVG T/7d0+0VignOYf4qASRTYWcxmPBnD8GOysOAxxo1WTm0LK7D49BjA3ZH2+YCmAv5 ATE4bnGLphdh46XegmAJCjCO8Vx+JOvSBjXzd8= Received: (qmail 76450 invoked by alias); 26 Feb 2018 21:04:04 -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 76243 invoked by uid 89); 26 Feb 2018 21:04:03 -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= X-HELO: mail-qt0-f175.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:cc:subject:date:message-id:in-reply-to :references; bh=Hfqb4riE7MSKiPugo9tCu8rbfM5T4BR4JnxqyvmSmnc=; b=MImxgBrshO+LLwzLhrQNXv+QYj0wSZIVkwG4vPSZfbTgb1SS+QMPUku4t+1z8abn72 VwWZZ0+WtMFtTjA3svO1ld3Cu5ppHdue/MSTBlrhStjgBuH92GSLOriiGyocFdxmPkdJ vAQwUftqbmYQpu011yxptVIQdOfcJTpXxXBF661o8RdEOjyLu3qNyhXwmhk5nUGLqsSg 3RCY/riLCX5BQ++gIQohdAoCG2RSYuazgNOhB4Bfe7mU7QBvEAQyqQW/UYEOAt2JdRhC bfpJqBuYmicxFJslhzpviHpMwDJiJrb/fiTsM+tbKg36d3bjS99nXspw9fpgB5WL1M1G wOoQ== X-Gm-Message-State: APf1xPDCUS/1p8uEfbYtvZlUBpds+Ot4IVJXKqHYb/bWUUOKD2Q4cjdx KQkF4zKXd9P4lrHbQuohoxFntMKH7X4= X-Received: by 10.200.43.21 with SMTP id 21mr18868516qtu.98.1519679039193; Mon, 26 Feb 2018 13:03:59 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Adhemerval Zanella Subject: [PATCH v2 10/21] nptl: s390: Fix Race conditions in pthread cancellation (BZ#12683) Date: Mon, 26 Feb 2018 18:03:25 -0300 Message-Id: <1519679016-12241-11-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> From: Adhemerval Zanella This patch adds the s390 modifications required for the BZ#12683 fix. It basically adds the required ucontext_get_pc function. The built cancelable syscall wrapper for s390 using GCC 7.2.1 and default configuration flags shows the wrappers on expected corrected places: --- __GI___syscall_cancel_arch: .LFB39: .cfi_startproc stm %r6,%r15,24(%r15) .cfi_offset 6, -72 .cfi_offset 7, -68 .cfi_offset 8, -64 .cfi_offset 9, -60 .cfi_offset 10, -56 .cfi_offset 11, -52 .cfi_offset 12, -48 .cfi_offset 13, -44 .cfi_offset 14, -40 .cfi_offset 15, -36 ahi %r15,-96 .cfi_def_cfa_offset 192 .global __syscall_cancel_arch_start .type __syscall_cancel_arch_start,@function __syscall_cancel_arch_start: l %r0,0(%r2) tml %r0,4 jne .L5 lr %r1,%r3 lr %r2,%r4 lr %r3,%r5 lr %r4,%r6 l %r5,192(%r15) l %r6,196(%r15) l %r7,200(%r15) svc 0 .global __syscall_cancel_arch_end .type __syscall_cancel_arch_end,@function __syscall_cancel_arch_end: l %r4,152(%r15) lm %r6,%r15,120(%r15) .cfi_remember_state .cfi_restore 15 .cfi_restore 14 .cfi_restore 13 .cfi_restore 12 .cfi_restore 11 .cfi_restore 10 .cfi_restore 9 .cfi_restore 8 .cfi_restore 7 .cfi_restore 6 .cfi_def_cfa_offset 96 br %r4 .L5: .cfi_restore_state brasl %r14,__syscall_do_cancel .cfi_endproc --- The s390x version also shows similar placement: --- __GI___syscall_cancel_arch: .cfi_startproc stmg %r6,%r15,48(%r15) .cfi_offset 6, -112 .cfi_offset 7, -104 .cfi_offset 8, -96 .cfi_offset 9, -88 .cfi_offset 10, -80 .cfi_offset 11, -72 .cfi_offset 12, -64 .cfi_offset 13, -56 .cfi_offset 14, -48 .cfi_offset 15, -40 aghi %r15,-160 .cfi_def_cfa_offset 320 .global __syscall_cancel_arch_start .type __syscall_cancel_arch_start,@function __syscall_cancel_arch_start: l %r0,0(%r2) tmll %r0,4 jne .L5 lgr %r1,%r3 lgr %r2,%r4 lgr %r3,%r5 lgr %r4,%r6 lg %r5,320(%r15) lg %r6,328(%r15) lg %r7,336(%r15) svc 0 .global __syscall_cancel_arch_end .type __syscall_cancel_arch_end,@function __syscall_cancel_arch_end: lg %r4,272(%r15) lmg %r6,%r15,208(%r15) .cfi_remember_state .cfi_restore 15 .cfi_restore 14 .cfi_restore 13 .cfi_restore 12 .cfi_restore 11 .cfi_restore 10 .cfi_restore 9 .cfi_restore 8 .cfi_restore 7 .cfi_restore 6 .cfi_def_cfa_offset 160 br %r4 .L5: .cfi_restore_state brasl %r14,__syscall_do_cancel .cfi_endproc --- Checked with a s390-linux-gnu and s390x-linux-gnu build with run-tests-built=no. [BZ #12683] * sysdeps/unix/sysv/linux/s390/sigcontextinfo.h (ucontext_get_pc): New function. --- ChangeLog | 5 ++++- sysdeps/unix/sysv/linux/s390/sigcontextinfo.h | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) -- 2.7.4 diff --git a/sysdeps/unix/sysv/linux/s390/sigcontextinfo.h b/sysdeps/unix/sysv/linux/s390/sigcontextinfo.h index 2533e63..89e6c47 100644 --- a/sysdeps/unix/sysv/linux/s390/sigcontextinfo.h +++ b/sysdeps/unix/sysv/linux/s390/sigcontextinfo.h @@ -16,7 +16,11 @@ License along with the GNU C Library; if not, see . */ +#ifndef _SIGCONTEXTINFO_H +#define _SIGCONTEXTINFO_H + #include +#include #define SIGCONTEXT struct sigcontext * #define SIGCONTEXT_EXTRA_ARGS @@ -25,3 +29,16 @@ #define GET_STACK(ctx) ((void *)((ctx)->sregs->regs.gprs[15])) #define CALL_SIGHANDLER(handler, signo, ctx) \ (handler)((signo), SIGCONTEXT_EXTRA_ARGS (ctx)) + +static inline uintptr_t +ucontext_get_pc (const ucontext_t *uc) +{ +#ifdef __s390x__ + return uc->uc_mcontext.psw.addr; +#else + /* We have 31bit addresses, remove bit 0. */ + return uc->uc_mcontext.psw.addr & 0x7FFFFFFF; +#endif +} + +#endif 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 Netto 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) From patchwork Mon Feb 26 21:03:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 129714 Delivered-To: patch@linaro.org Received: by 10.80.172.228 with SMTP id x91csp4291789edc; Mon, 26 Feb 2018 13:06:13 -0800 (PST) X-Google-Smtp-Source: AH8x226AmrHGrxwBhqJHoEwb1hrViic3c4r2phC+/lnJkjqmDa4LspY5eIzDhR35A12IFudZzsXs X-Received: by 2002:a17:902:5797:: with SMTP id l23-v6mr11680931pli.56.1519679173021; Mon, 26 Feb 2018 13:06:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519679173; cv=none; d=google.com; s=arc-20160816; b=k4sGyOj9anE+gELyxfaeXi4Ih3Ai53nsfBO535q4bmEVKFV9/s+fRJ/dcgna8/fUaz GERZMqQ1EkO+4k1JQI16fr9cwv3cP6lN9OktaokCGH/8iUCWynk+FoLuCF7zZmPnRylV ufOzM/n9Cvwerqnz/kBzF76l9+ay2WxwipA6CIuw8Sjv63Jd/KN7wbs4NleQaqDokbJi P6TRCl/aEnyxUwKOVFPnjM7jfly9gEQvU9cb8AHdYqX+k4vb8SNo8lICq47dhvjeAAEu ZHNSM4GUx2j3e9RXldmpRW+1RN5Hv6z1N4QKHZM5PzK4Ivtd5kDSuuKyMncwT+kDc37A OCpQ== 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=VVQell1oQ7MntDbjEHsRILnAWhnsUxWeKxijv+xVJlc=; b=Vr6j3WVK9r9bIfcjUtA+7Cv/3gHrgFJ0iOItBxV5PVVigkIxClFFOVfl3Km8/tu5cP E4VTywYMaDC49nTaC9p3iHo33nsXl40yeAz628IDj7Z/4AXFd6SMkH7MhHK3HEgeU6nP ZdaE0P2e7sFZhHttYi+jPzKFe1CFhiV5SOcnDH/lG7sKhI7dUrmvyNsXDQK6XB9Nk6BH YiJyKXF4qP6zx7sAlyXqBKCkFtUc+PK/pOymyxs5kppiBJwMwnzjCRdIG+utQnpciWXr bo/C9X+ubXssKh3L09YZasOptSoiAf5qvy8Ttzxt/HMmNUtEFdnT79Tkh2uo+/3/oe5B CImw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=Pv3m0eSx; spf=pass (google.com: domain of libc-alpha-return-90629-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-90629-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 x21-v6si7309511pln.416.2018.02.26.13.06.12 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Feb 2018 13:06:13 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-90629-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=Pv3m0eSx; spf=pass (google.com: domain of libc-alpha-return-90629-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-90629-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=sXWgw7g7A79h6YHPTPoQL3Hsc13CgVq k4dBbN1g7OwkuxFgi7M3N6BTTqVVgNj2SorSdvBNcbk3m6lVqOn5QRNpkCKt0v8T v+MbJgcQ2prQrcHvWRZHx4GXMVFfUnpa6imSYgms1SPCt3RbnNUJsyrV2w4bShjR nZ72Gww5fZgg= 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=oys5eqV9saQ3ChiK8qB1BXbn4es=; b=Pv3m0 eSxpKb64D/ZHhhdPQt6N2cELUyViwZbO1bui1VskXf8nL4V8Kg7tONVYdXVUZL0s 2yOgzLg0FCq8EhYJ/yWoN+dldm4SzYcKenIbZkcgOz4if1xpoW68b6NAR6xZmfNl pjmBb935sLAQXmTbzDO8fvJCGAXAafFBJNahMk= Received: (qmail 77120 invoked by alias); 26 Feb 2018 21:04:09 -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 76695 invoked by uid 89); 26 Feb 2018 21:04:06 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=cod X-HELO: mail-qt0-f181.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=VVQell1oQ7MntDbjEHsRILnAWhnsUxWeKxijv+xVJlc=; b=kWMoUuhaw9bWBrqHBmw8ebPS0lvWPnZtCy8b2qwC7GyQAOvYjiKtW4AZFWzq25OaB0 HiQm2BhOZqZY6QQLx/bTO/rBn+p0DX4+jpJNBoslvLNP481K+jhvOqo0aMYhCsuZ8Ols GEE1s+8VlMkuVbm5n26uCuExlW4XuKzV7k/DhZORqs3CR1GicyRm+gUhc2+qLBQB7Qan YOxPQkm8HPQLkDGBjiv4UJUwsAts1QhgvjbV9B+TV0B8K4Li2xPccBXfDhA01UPr5zfV EvhZtaPyO60fwb7DeZC+gFaHbK+Gw1W5zoXWkPnL2JfcOLzpWbwSF52ZBgDcZWtT2L4L wDww== X-Gm-Message-State: APf1xPAGfX99e42Dudh29PI86jy5GMzSIUUR+Jc3lGFvcMgYcF8AopKW 4YLOIoxWB/yCjWJecPmR23mGVxCOZVc= X-Received: by 10.200.34.209 with SMTP id g17mr18745066qta.93.1519679042634; Mon, 26 Feb 2018 13:04:02 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH v2 12/21] nptl: alpha: Fix Race conditions in pthread cancellation (BZ#12683) Date: Mon, 26 Feb 2018 18:03:27 -0300 Message-Id: <1519679016-12241-13-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 alpha modifications required for the BZ#12683. It basically adds the required ucontext_get_pc function The default syscall_cancel.c should be fine for alpha and GCC 6.1 generates the following cod for syscall_cancel.os: --- 0000000000000000 <__GI___syscall_cancel_arch>: 0: 00 00 bb 27 ldah gp,0(t12) 4: 00 00 bd 23 lda gp,0(gp) 8: f0 ff de 23 lda sp,-16(sp) c: 00 04 f1 47 mov a1,v0 10: 00 00 5e b7 stq ra,0(sp) 0000000000000014 <__syscall_cancel_arch_start>: 14: 00 00 30 a0 ldl t0,0(a0) 18: 01 00 e1 43 sextl t0,t0 1c: 01 90 20 44 and t0,0x4,t0 20: 0f 00 20 f4 bne t0,60 <__syscall_cancel_arch_end+0x20> 24: 10 04 f2 47 mov a2,a0 28: 11 04 f3 47 mov a3,a1 2c: 12 04 f4 47 mov a4,a2 30: 10 00 9e a6 ldq a4,16(sp) 34: 13 04 f5 47 mov a5,a3 38: 18 00 be a6 ldq a5,24(sp) 3c: 83 00 00 00 callsys 0000000000000040 <__syscall_cancel_arch_end>: 40: 21 05 e0 43 negq v0,t0 44: 00 00 5e a7 ldq ra,0(sp) 48: c0 04 61 46 cmovne a3,t0,v0 4c: 10 00 de 23 lda sp,16(sp) 50: 01 80 fa 6b ret 54: 00 00 fe 2f unop 58: 1f 04 ff 47 nop 5c: 00 00 fe 2f unop 60: 00 00 7d a7 ldq t12,0(gp) 64: 00 40 5b 6b jsr ra,(t12),68 <__syscall_cancel_arch_end+0x28> 68: 1f 04 ff 47 nop 6c: 00 00 fe 2f unop --- Checked on alpha-linux-gnu, no regression found. [BZ #12683] * sysdeps/unix/sysv/linux/alpha/sigcontextinfo.h (ucontext_get_pc): New function. --- ChangeLog | 4 ++++ sysdeps/unix/sysv/linux/alpha/sigcontextinfo.h | 13 +++++++++++++ 2 files changed, 17 insertions(+) -- 2.7.4 diff --git a/sysdeps/unix/sysv/linux/alpha/sigcontextinfo.h b/sysdeps/unix/sysv/linux/alpha/sigcontextinfo.h index 23f66d0..f762fff 100644 --- a/sysdeps/unix/sysv/linux/alpha/sigcontextinfo.h +++ b/sysdeps/unix/sysv/linux/alpha/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 int _code, struct sigcontext * #define SIGCONTEXT_EXTRA_ARGS _code, #define GET_PC(ctx) ((void *) (ctx)->sc_pc) @@ -22,3 +27,11 @@ #define GET_STACK(ctx) ((void *) (ctx)->sc_regs[30]) #define CALL_SIGHANDLER(handler, signo, ctx) \ (handler)((signo), SIGCONTEXT_EXTRA_ARGS (ctx)) + +static inline uintptr_t +ucontext_get_pc (const ucontext_t *uc) +{ + return uc->uc_mcontext.sc_pc; +} + +#endif /* _SIGCONTEXTINFO_H */ From patchwork Mon Feb 26 21:03:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 129715 Delivered-To: patch@linaro.org Received: by 10.80.172.228 with SMTP id x91csp4291959edc; Mon, 26 Feb 2018 13:06:22 -0800 (PST) X-Google-Smtp-Source: AH8x224irUV2wZ8NYSmufaExj9b7TN6bI1xJ4k/l8q/WCO2oeQut5g4T8KbuHR8+0mMWXFpbjizs X-Received: by 2002:a17:902:a50d:: with SMTP id s13-v6mr11986348plq.191.1519679182607; Mon, 26 Feb 2018 13:06:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519679182; cv=none; d=google.com; s=arc-20160816; b=XWd+tQ1rsyt6S+vJDVao+pMRxsLKio5INBesbbuG44DhmxEvJpSpXoceYJrdmKvOHe skB0pF9R/mk4SjydowRr/L/djQ2JG4UXO9lDPkgst0UcJeqk7On/p0s47FCV2kZY2pPd TwodCnf2q8eRUvwggAIV4iIS3MLycuYV/3YvOrAT99YeBtKL2w+1jNewprettjN+0Fwe 4p2EqPfgZZDcYVEWeXI78M0EFdvIU3lC4C8ZPdBmTHW1TLZ4U82KJvkx0BMC/jSewORx ZShtWJ2czlDBhpweE+xd4vTzX3E7QsOFnOJdTvV2RwXX8saLbZgEcTNsYg7p/XNIuWx5 firw== 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=5G4t+OFEO1NvZp5Gn83xbqY8FcxTZ/wHvoWIDSR+aCk=; b=GhKNxDDxZjSDddsQ3qIZFmEtJJW1WvC6L0h0A1DL0DHcC7bGjLyTvaxwFFrmCuPsMd +MCPHdnZ2goaCodf+LGD0x8ODq43Lh1rtb5uaet1ut3XVHL2rRtNutGVEh69kAsCSEYj T0GMbjO3A4/lmeAvZkUDPLzcnZ2wkgxmyslM3A9G+ZB5ZqswSh0psV6JfVHnfyszZ3An VMZPbFiNwGF7seHFT7TbqOLaQzNKFtSTuZsm9oNaxvYyTp0LKLT7zHxM5/E43odT1xL8 Q5v8t2t6okuq8zI1kx4OJwxwmiQAt+WL4X/pY17iTpEcfiP8T1oQrj4NVbDkv6cTE8DA JNnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=SB8Afzow; spf=pass (google.com: domain of libc-alpha-return-90630-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-90630-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 j62si6015851pgc.583.2018.02.26.13.06.22 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Feb 2018 13:06:22 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-90630-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=SB8Afzow; spf=pass (google.com: domain of libc-alpha-return-90630-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-90630-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=JfdnZ1LVe25EknGtWby7NJTYWfvhY9+ AlASVWUORGGt5Mv4o70Y9jU6aX2WouG0en1RNCtZpKgxrWxjZQAHSBQwi15lW19K DPiqsT/zVBB8LnBkOGEuW+2dBucPeMqvgeezDTcUqmtRi9wm86MJNq5n9pm0gC+P 6ZTJ7uc4kybE= 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=VUO53K1ELUulmR6GDJVVl0L2Gkw=; b=SB8Af zowsKXGzfBZxwn5kS6Uzs5uKxe8mnkZB7vW3m81fstCTbWe2KvTlY6AyADyVp3py ACj1McthuXXCDAgk2SFa2+Z2z/yQ8Qx2Qe/d2TXDQDAxKdU3d4/DWOPnI7vSbefv nEcS+4qubKMIYmuPVKByD1yTffb38272IhLAcs= Received: (qmail 77595 invoked by alias); 26 Feb 2018 21:04:12 -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 76886 invoked by uid 89); 26 Feb 2018 21:04:07 -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=Hx-languages-length:2208, 0002 X-HELO: mail-qk0-f193.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=5G4t+OFEO1NvZp5Gn83xbqY8FcxTZ/wHvoWIDSR+aCk=; b=MkAzVzw0XTUuWwluhap5dL5zeWgKElPoySBX5/DBJfq4Lov358GT0hOkuVNco9PzV1 aHhLoC2dW+v38nRdnAwJWGb449EPS+Vr/4ZAVdQiypHTUUf8XvZsJIdwqcTCcr/7POFu 34IuyTPKsrcAFcOH7oCpGSb94cfer7Oz2swg0Jg0ymLUN6H659Nhzfsja/4Gyo8ivaTa /tjrAgcJoxZUYuWnVbzfGZGXXOZUxN5jbt1Qa7p9pGhsZ92+1y2FAh0qNDWx/RQPISyv 8xSYwxpNqV3YgWfd9nN5mM3ytAMLNE8XmPn6y3ZR/KR904KbNP5iBwZbjK+YstjtnASo b6tQ== X-Gm-Message-State: APf1xPCCycH5U08aWtu9H20/g4yvCPy1bcDvtEanv5mJj9kFib1wrlDD SeUKoz7AD6544OXAH/aKPFEwyUx4w3Q= X-Received: by 10.55.207.82 with SMTP id e79mr15192467qkj.219.1519679044051; Mon, 26 Feb 2018 13:04:04 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH v2 13/21] nptl: m68k: Fix Race conditions in pthread cancellation (BZ#12683) Date: Mon, 26 Feb 2018 18:03:28 -0300 Message-Id: <1519679016-12241-14-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 m68k modifications required for the BZ#12683. It basically adds the required ucontext_get_pc function The default syscall_cancel.c should is as expected for m68k with GCC 6.2.1. It generates the following code for syscall_cancel.os: --- 00000000 <__GI___syscall_cancel_arch>: 0: 4e56 0000 linkw %fp,#0 4: 48e7 3c00 moveml %d2-%d5,%sp@- 00000008 <__syscall_cancel_arch_start>: 8: 206e 0008 moveal %fp@(8),%a0 c: 2010 movel %a0@,%d0 e: 0800 0002 btst #2,%d0 12: 6628 bnes 3c <__syscall_cancel_arch_end+0xa> 14: 206e 0024 moveal %fp@(36),%a0 18: 2a2e 0020 movel %fp@(32),%d5 1c: 282e 001c movel %fp@(28),%d4 20: 262e 0018 movel %fp@(24),%d3 24: 242e 0014 movel %fp@(20),%d2 28: 222e 0010 movel %fp@(16),%d1 2c: 202e 000c movel %fp@(12),%d0 30: 4e40 trap #0 00000032 <__syscall_cancel_arch_end>: 32: 4cee 003c fff0 moveml %fp@(-16),%d2-%d5 38: 4e5e unlk %fp 3a: 4e75 rts 3c: 61ff 0000 0000 bsrl 3e <__syscall_cancel_arch_end+0xc> --- Checked against a build and make check run-built-tests=no for m68k-linux-gnu. [BZ #12683] * sysdeps/unix/sysv/linux/m68k/sigcontextinfo.h (ucontext_get_pc): New function. --- ChangeLog | 4 ++++ sysdeps/unix/sysv/linux/m68k/sigcontextinfo.h | 13 +++++++++++++ 2 files changed, 17 insertions(+) -- 2.7.4 diff --git a/sysdeps/unix/sysv/linux/m68k/sigcontextinfo.h b/sysdeps/unix/sysv/linux/m68k/sigcontextinfo.h index 58374ed..3a288ea 100644 --- a/sysdeps/unix/sysv/linux/m68k/sigcontextinfo.h +++ b/sysdeps/unix/sysv/linux/m68k/sigcontextinfo.h @@ -16,6 +16,11 @@ License along with the GNU C Library. If not, see . */ +#ifndef _SIGCONTEXTINFO_H +#define _SIGCONTEXTINFO_H + +#include + #define SIGCONTEXT int _code, struct sigcontext * #define SIGCONTEXT_EXTRA_ARGS _code, #define GET_PC(ctx) ((void *) (ctx)->sc_pc) @@ -23,3 +28,11 @@ #define GET_STACK(ctx) ((void *) (ctx)->sc_usp) #define CALL_SIGHANDLER(handler, signo, ctx) \ (handler)((signo), SIGCONTEXT_EXTRA_ARGS (ctx)) + +static inline uintptr_t +ucontext_get_pc (const ucontext_t *uc) +{ + return uc->uc_mcontext.gregs[R_PC]; +} + +#endif /* _SIGCONTEXTINFO_H */ From patchwork Mon Feb 26 21:03:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 129716 Delivered-To: patch@linaro.org Received: by 10.80.172.228 with SMTP id x91csp4292095edc; Mon, 26 Feb 2018 13:06:32 -0800 (PST) X-Google-Smtp-Source: AH8x226SLXynF+4N3ymBg6uUg64UVo+myPmyphQ1VnLmUJnhMeJRuuChVxEFxtHb8tSbEECrvYxW X-Received: by 2002:a17:902:2b84:: with SMTP id l4-v6mr11974448plb.338.1519679192508; Mon, 26 Feb 2018 13:06:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519679192; cv=none; d=google.com; s=arc-20160816; b=tnRbN9d66t8OJ6QTGTRU8T/04cfrz1mAfbLoAJ45tBK1dMxvqEOwTwIX3St5h55gef zZiBhKBOtAcLlXFdFLogML9QAMCYYuZbRRtGDCuxSzSIdFNVZm3orCrq1PljqL5CGR+i 53d58NaHct20cfMqQHknn21FRlfF0R4Qvuc6n8ti2vmb73Hy4Ub/gx9XxAUt9l9WbWZc spkx2h6gz6G12kQEwRHveJy6luygvgibIFDrUjctFB+89L+u3XfRAMWGWSGqq6VlZhJj rrRr0TLnTBYzR4mUNVK6qJpUALae8EVbRm4wg7nS29FUJ/D2FyNOPoitxiGAsP3pY6Pc GWng== 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=36vmF1UBuyft13pJd4buutC6GdHaCmVgbHI0pKWKCaQ=; b=IhLRNX0q+EKTPqIybMuFqNxtWIDNR+RPcqSW6RMe3EbAltgPdDI4ReKcasWfm0JYcu 7wlzwQYyDOxbb90wgkqrrsuXXIV13yDCI0jAdml9b2v7gPD6Hvuk3w9pGrcEU1ncni9d iKEBB2YUATdYliGi8R78oqozPnrE9C2Kx4g26pAxVddNyF7xp9M50VcfuzZ9BIMALdFL 0XBsKuFRXfUI2R/ad3iPKAkGAUdT4sBv17dPib51nVJou0y2fxHjT4tSyskEK0EbNBwC c9gNfUWe81dIasbfLYPHTxAIcrAisPL2W1sEUBCvHa4noiXN0m7xTv6XlMVwDnAqNpqk iZIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=gJ5uhqr4; spf=pass (google.com: domain of libc-alpha-return-90631-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-90631-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 i6-v6si7186824plt.437.2018.02.26.13.06.32 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Feb 2018 13:06:32 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-90631-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=gJ5uhqr4; spf=pass (google.com: domain of libc-alpha-return-90631-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-90631-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=RPV2Zwo8zsFSR2Lgfvz/CfMtZWpnsbb w9ujSlZvOmqTfoG70uR3ZTRiINDfPcvDE9NctaequdtRl0x9we6P0zylKy1DTZg4 3e/b6h2646yjkgqfcQWAR4RQCCYIvGEwXJ+cZcvAZ+QPIsVz5trzPgLeXEovl3br zRtKdA25Chwo= 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=Lv8Jdvyada9qpoIDj3IK4krzAuM=; b=gJ5uh qr48YTvCgFrB237fLGIde6ioJwzVmnsuORSryOjX7pqQsjKonwKNNwLtOFeHkdar 52i7PLD0hi9DGbaWhHn9s5tUvz+HGbqsW8LlkFcvFMTPwrcMZ/Y/WjH+OM32kKpW WI1UCY0aI2IJJoRPZa32B5cC9pcGaBY+JXI1ms= Received: (qmail 78410 invoked by alias); 26 Feb 2018 21:04:19 -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 77192 invoked by uid 89); 26 Feb 2018 21:04:09 -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= X-HELO: mail-qt0-f195.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=36vmF1UBuyft13pJd4buutC6GdHaCmVgbHI0pKWKCaQ=; b=ffbtHxhRi/SaFiLa7+SHFc6obO5a7bk8h3L6kDVEWMeTXI7yNPNhiTkas+yPyAIGRQ dWSdDuKrXMtRYYRp9i12XC3DpkFr8IuuBqkPL6PC0S/xLz9M0FS/n0G144sQaojVsbri 1ai6jGpush6w+SSItDPNa3N+RTtpVVZ9rpwgfVTYR4RholuEARj8LgnyAd7NZjqK8MF6 QxAsYuz3d/oLzz95h5Dra4/aQUDSl3EY3v1L8MJEXku4xbKauuVUs75XJwr+Zue5hVi+ DVB9sA6Ot1AD7AeKADd58eqnCDc01dWuRoz2Oh/LjPBVUCA1LD0hlPaXUj7rB6ER/RcG m17A== X-Gm-Message-State: APf1xPBcH1DRTSlzW1dZxqXjd89sDVwxKCOivzvMeBQilwYbLvrB4vD0 H44PrwV2E5mnKkSXWUMD0jsYKvDAQJM= X-Received: by 10.200.55.233 with SMTP id e38mr19680884qtc.158.1519679045644; Mon, 26 Feb 2018 13:04:05 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH v2 14/21] nptl: microblaze: Fix Race conditions in pthread cancellation (BZ#12683) Date: Mon, 26 Feb 2018 18:03:29 -0300 Message-Id: <1519679016-12241-15-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 microblaze modifications required for the BZ#12683. It basically adds the required ucontext_get_pc function. Microblaze requires an arch specific assembly implementation because the archicture INTERNAL_SYSCALL_NCS implementation adds a nop after the brki instruction because the instruction expect a delay branch slot. I based this implementation on generated assembly using GCC 6.1. Checked against a build and make check run-built-tests=no for microblaze-linux-gnu. [BZ #12683] * sysdeps/unix/sysv/linux/microblaze/syscall_cancel.S: New file. * sysdeps/unix/sysv/linux/microblaze/sigcontextinfo.h (ucontext_get_pc): New function. --- ChangeLog | 5 ++ .../unix/sysv/linux/microblaze/sigcontextinfo.h | 13 +++++ .../unix/sysv/linux/microblaze/syscall_cancel.S | 62 ++++++++++++++++++++++ 3 files changed, 80 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/microblaze/syscall_cancel.S -- 2.7.4 diff --git a/sysdeps/unix/sysv/linux/microblaze/sigcontextinfo.h b/sysdeps/unix/sysv/linux/microblaze/sigcontextinfo.h index 64d8f2f..fae7144 100644 --- a/sysdeps/unix/sysv/linux/microblaze/sigcontextinfo.h +++ b/sysdeps/unix/sysv/linux/microblaze/sigcontextinfo.h @@ -16,6 +16,11 @@ License along with the GNU C Library; if not, see . */ +#ifndef _SIGCONTEXTINFO_H +#define _SIGCONTEXTINFO_H + +#include + #define SIGCONTEXT int _code, ucontext_t * #define SIGCONTEXT_EXTRA_ARGS _code, #define GET_PC(ctx) ((void *) (ctx)->uc_mcontext.regs.pc) @@ -23,3 +28,11 @@ #define GET_STACK(ctx) ((void *) (ctx)->uc_mcontext.regs.sp) #define CALL_SIGHANDLER(handler, signo, ctx) \ (handler)((signo), SIGCONTEXT_EXTRA_ARGS (ctx)) + +static inline uintptr_t +ucontext_get_pc (const ucontext_t *uc) +{ + return uc->uc_mcontext.regs.pc; +} + +#endif /* _SIGCONTEXTINFO_H */ diff --git a/sysdeps/unix/sysv/linux/microblaze/syscall_cancel.S b/sysdeps/unix/sysv/linux/microblaze/syscall_cancel.S new file mode 100644 index 0000000..d892362 --- /dev/null +++ b/sysdeps/unix/sysv/linux/microblaze/syscall_cancel.S @@ -0,0 +1,62 @@ +/* Cancellable syscall wrapper. Linux/microblaze 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 + +/* 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) + + .globl __syscall_cancel_arch_start +__syscall_cancel_arch_start: + + lwi r3,r5,0 + andi r3,r3,4 #and1 + bneid r3,1f + addk r12,r6,r0 + + addk r5,r7,r0 + addk r6,r8,r0 + addk r7,r9,r0 + addk r8,r10,r0 + lwi r9,r1,56 + lwi r10,r1,60 + brki r14,8 + + .globl __syscall_cancel_arch_end +__syscall_cancel_arch_end: + + nop + lwi r15,r1,0 + rtsd r15,8 + addik r1,r1,28 + +1: + brlid r15, __syscall_do_cancel + nop + +END (__syscall_cancel_arch) +libc_hidden_def (__syscall_cancel_arch) + From patchwork Mon Feb 26 21:03:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 129717 Delivered-To: patch@linaro.org Received: by 10.80.172.228 with SMTP id x91csp4292239edc; Mon, 26 Feb 2018 13:06:42 -0800 (PST) X-Google-Smtp-Source: AH8x226DsEVsZTcY9BjPLRvD18tJsjOBIw0Bdv8L0ta0gHC2Ins2KX6+XphNMyoATy4PtDZHspMU X-Received: by 10.101.102.2 with SMTP id w2mr9523260pgv.326.1519679202377; Mon, 26 Feb 2018 13:06:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519679202; cv=none; d=google.com; s=arc-20160816; b=KrQWlsaJ8PtIQbhy5FEsNyItbC9jlzMztoiEIt0baey6kpsZwPrMwij3TlaEA+BerN mSAkIiIHP8gBWknyWXpb2DYn3+XMyfdpV+yktgJ5EKPNDmlWVAko0er5rBDRlwB6tNsU 3wmJhL6n7nQalXTX01WmIfNojsR7ka1waN/27FtKKCJxTNNyM987jCJ54RMtrEhnG4KK h1wmzz30cm1F57pA/J5PveXsn2I2JeqzOJSP7GYxWd6ZIVgoQmY3rfvnxBGR0z0qfh1d JbgNSR2dwyGXlH0WLKx9nq2p2q+hsgMikPQahi5NS6sZNVjaeO/UJYOE/Ug0XQGCvVor 49Ww== 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=gbUKQcwr0l+3ALAHxiNqnmowkWI4eohyGwGNmRecVdI=; b=w9IOphb9ekh/RzpuiIDy7p/7FM6sPjF/nyHMnwu2BwS7AwW2SJ2EfDudi2HHFeAg1X skt0n+9/0/ucUbb+wHByV+wgsPOQOUSQX8yXChcGGq2V6cIv79eg6v48HLnqElflfkbz /3TgkWdKXo5UL0haXRAyoyJy7BL7hBR62OmB6MvZ6xgGplDSADe+8xWpBRJrf7B29uxp W8LRrMYmjmtone+Q8F6Vsucvh4VSy6MTyMI9VdMO4DvUcqqdxgdfhhdK7rtSneiSRgTO yF2AUQkcLlYFxAadHIrjvXbhzOnLR9TQ12WSAP59iTrVmEyG8Q4YG1Ca8nlCreZS2FcV X8eQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=b6wMg//p; spf=pass (google.com: domain of libc-alpha-return-90632-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-90632-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 z3si6008124pgr.744.2018.02.26.13.06.41 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Feb 2018 13:06:42 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-90632-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=b6wMg//p; spf=pass (google.com: domain of libc-alpha-return-90632-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-90632-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=RAhffT55vxGq+lhP8gOcvaeam07ozyu 2sJUesssYarGDp+fs26uD3Zmxi5xviBRLV4CYpieDGMwOMbVNJtv9sbaZiLGVmrS xUiQKgRNOQCaPK97/CB9DJ9xaXlLo3+PqQPHyzRACIGxcIWpnRsZRAYLkdPuLzQj Qe5XK+fuz0nk= 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=5X7qODlrgiDOoLxnHel2hMC8j0k=; b=b6wMg //p6duUNxBgLcjL8te1YrCrdSuGaazl/1jLKXso+vbCp6beWDyLHdt/0yG5TzSEN urV413WLJcANiuTg8EtmWyKVITIjcB8j30Oy8DNi+ly2+qHuassqv4fmNYzs6gD4 tJgRFkU4bjAqEwDbF1XH8gJr7T8dbszwXjfgis= Received: (qmail 78876 invoked by alias); 26 Feb 2018 21:04:23 -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 77319 invoked by uid 89); 26 Feb 2018 21:04:10 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.1 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= X-HELO: mail-qt0-f195.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=gbUKQcwr0l+3ALAHxiNqnmowkWI4eohyGwGNmRecVdI=; b=jsMthy8pQ07STyKVv+JWUYxp2IJqmYiqSgKXtxgxyOC1bKcBGCciBRqH48bPWVm8OI bV2OfMRvUv0Z4YIaeB/5SBaI989NOi1oxF9UJ+7lK+0jL6wJuy9rFXVdkluNMQ9DN+5F ES3xCgUugC90ogQ5zskjIEx2YdnFUEowSvK8TOiu6FmLvXprsvF/Y3F7rkV09ZO1FiN+ a8TtXSBhfL9/3Ae4JqsEEVo6QwqvzcUshx4ILM+Vw1jeRyHKoyMOqPKFy/YhRhMGEHYZ N0iS0x1+3G7qPVt363PiH1wkobJHc+MQ+B0xMadSol+YBQ0qJ3meXDQqRuvvkOwK+p3x dq8g== X-Gm-Message-State: APf1xPAvPRjFVj6HoveV3sYsQ9tADCJ+3fFlBY4CFxdIOlBS8zn2t2sD OLJaA6cqai0SUAm0R4+TeN8FhQ3Zu90= X-Received: by 10.237.43.226 with SMTP id e89mr20099698qtd.17.1519679046975; Mon, 26 Feb 2018 13:04:06 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH v2 15/21] nptl: tile: Fix Race conditions in pthread cancellation (BZ#12683) Date: Mon, 26 Feb 2018 18:03:30 -0300 Message-Id: <1519679016-12241-16-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 tile modifications required for the BZ#12683. It basically adds the required ucontext_get_pc function The default syscall_cancel.c should be as expected for TILE. With GCC 6.1 syscall_cancel.c generates the following code: * TILEGX 0000000000000000 <__GI___syscall_cancel_arch>: 0: c7bf46ce576bfd9d { move r29, sp ; addi r28, sp, -24 ; st sp, lr } 8: 283bf825401e0db6 { addi sp, sp, -32 ; move r10, r1 } 10: eeedf85b85c18d9b { addi r27, sp, 24 ; move lr, r2 ; st r28, r29 } 18: eef5f88155bbf0c1 { move r1, r3 ; move r2, r4 ; st r27, r30 } 20: 283bf8c25107f143 { move r3, r5 ; move r4, r6 } 28: 283bf8e2d1483000 { move r5, r7 } 0000000000000030 <__syscall_cancel_arch_start>: 30: 9c5e4000340c3000 { ld4s r11, r0 } 38: 18182165d1483000 { andi r11, r11, 4 } 40: 17c00163d1483000 { bnez r11, 78 <__syscall_cancel_arch_end+0x20> } 48: 283bfee051483000 { move r0, lr } 50: 286b180051485000 { swint1 } 0000000000000058 <__syscall_cancel_arch_end>: 58: 180906ced1401ff7 { subx lr, zero, r1 ; addi r29, sp, 32 } 60: 87b8c6ce4dd77040 { cmovnez r0, r1, lr ; addi r28, sp, 24 ; ld lr, r29 } 68: 9ef6400035cc3000 { ld r30, r28 } 70: 286a6ee040120db6 { addi sp, sp, 32 ; jrp lr } 78: 2000000051483000 { jal 78 <__syscall_cancel_arch_end+0x20> } * TILEGX32 00000000 <__GI___syscall_cancel_arch>: 0: cbbfc6ce576bfd9d { move r29, sp ; addxi r28, sp, -8 ; st sp, lr } 8: 283bf825402f0db6 { addxi sp, sp, -16 ; move r10, r1 } 10: eeedf860d5cbf0b7 { move lr, r2 ; move r1, r3 ; st r28, r29 } 18: 283bf8a1d107f102 { move r2, r4 ; move r3, r5 } 20: 283bf8e2d107f184 { move r4, r6 ; move r5, r7 } 00000028 <__syscall_cancel_arch_start>: 28: 9c5e4000340c3000 { ld4s r11, r0 } 30: 18182165d1483000 { andi r11, r11, 4 } 38: 17c0016351483000 { bnez r11, 68 <__syscall_cancel_arch_end+0x18> } 40: 283bfee051483000 { move r0, lr } 48: 286b180051485000 { swint1 } 00000050 <__syscall_cancel_arch_end>: 50: 28660fe540210d9d { addxi r29, sp, 16 ; subx r10, zero, r1 } 58: 9fbe40004dd4a040 { cmovnez r0, r1, r10 ; ld lr, r29 } 60: 286a6ee040210db6 { addxi sp, sp, 16 ; jrp lr } 68: 2000000051483000 { jal 68 <__syscall_cancel_arch_end+0x18> } Checked with build and make check run-built-tests=no for tilegx{32}-linux-gnu. [BZ #12683] * sysdeps/unix/sysv/linux/tile/sigcontextinfo.h (ucontext_get_pc): New function. --- ChangeLog | 4 ++++ sysdeps/unix/sysv/linux/tile/sigcontextinfo.h | 12 ++++++++++++ 2 files changed, 16 insertions(+) -- 2.7.4 diff --git a/sysdeps/unix/sysv/linux/tile/sigcontextinfo.h b/sysdeps/unix/sysv/linux/tile/sigcontextinfo.h index 82bc0c7..c6edd2a 100644 --- a/sysdeps/unix/sysv/linux/tile/sigcontextinfo.h +++ b/sysdeps/unix/sysv/linux/tile/sigcontextinfo.h @@ -16,6 +16,10 @@ License along with the GNU C Library. If not, see . */ +#ifndef _SIGCONTEXTINFO_H +#define _SIGCONTEXTINFO_H + +#include #include #define SIGCONTEXT siginfo_t *_si, ucontext_t * @@ -25,3 +29,11 @@ #define GET_STACK(ctx) ((void *) (long) ctx->uc_mcontext.sp) #define CALL_SIGHANDLER(handler, signo, ctx) \ (handler)((signo), SIGCONTEXT_EXTRA_ARGS (ctx)) + +static inline uintptr_t +ucontext_get_pc (const ucontext_t *uc) +{ + return uc->uc_mcontext.pc; +} + +#endif /* _SIGCONTEXTINFO_H */ From patchwork Mon Feb 26 21:03:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 129719 Delivered-To: patch@linaro.org Received: by 10.80.172.228 with SMTP id x91csp4292608edc; Mon, 26 Feb 2018 13:07:02 -0800 (PST) X-Google-Smtp-Source: AG47ELtWWqbn2WP39ea0IwMFtvQzLavwXoUpgcdlQ9usxlAH8+JOk/2eeh2aOyS34l5ZBzk+UJ3E X-Received: by 10.101.74.74 with SMTP id a10mr3610079pgu.32.1519679222800; Mon, 26 Feb 2018 13:07:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519679222; cv=none; d=google.com; s=arc-20160816; b=tAlIJ+YDRX/QGt80Yv3XUGQBp5IV9yH0/pmRYe6QHZJT67h6p/HtOjy/ZZ1Q9mMuOd fcteMMdml/daUZC/io0Po54UP9oAFixKSBrg91dpuVIIxrimnrbo1QANWDNaQkYH/exS 6shbjvqllKWF62F08nyzahlj58Gco+TauQ12nrq1hByyH1L3sy4HAfnCMQVO6432J6gd vVH6CLZ5GJN4MTH0p3vJOPZgc7Tcy7VuwtnXghBss9b6cOIdcp5XA+KdJSgDFvDqRdpH HTSgv0OP7WzU85hWZS2czvWeJEfanAfR1EoeGVnFmsDrCHJjWwQ3QJz7zPq6F2cSn9VX t9wg== 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=fDjQ5OUa2soFgyRdhn2SoufZT3BrNbhlmpMoS+lUuNk=; b=wXO+dWanusaPOKlN0eUgaUzZgVu6pV3nQcBXt5EQqboHw1hSCO2iT2c3mnMmtPZet9 xmwM1UkOQYLqAg72G7t0s+0gKE4SYeWZYx3IFxJ0bT+MJpkf0mFg5b+oKbm57jsaXVFo dgFJvc0YbSwvkNszpzj1XWlXpLWixbvENrTaK5yTo8XO4y0UgxIODn2Ile1SrsqM2oXc YWWczQkUlPBJHSJonSgIH3BSSTR1NN17Ph8k3lDQ7dAjmwG90pDFuIioecsIltuExC6f SlHj0yFnHtznh2NOJ/kkUtejrxH+3B6C9NGdVyvJnNfUeqsuVrfIVJaqUFiwGmJP3tu8 /PAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=LZ2ypxjv; spf=pass (google.com: domain of libc-alpha-return-90634-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-90634-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 v12si5925012pgs.356.2018.02.26.13.07.02 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Feb 2018 13:07:02 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-90634-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=LZ2ypxjv; spf=pass (google.com: domain of libc-alpha-return-90634-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-90634-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=nPYRv3s3dzLNbesPslWGqwf30VvjNJo B6Q9P5FF9dHJXaP8ZlMpxUJdKYmLoX/0/SvAnCogV9dz7e32to26t2LVfw9wDBMD LMu0kQ9+vw2caL9caCi7H0xF0TLGNSnh/X55dpee+hRQSwDHXyqZgfjRvj57I0/m x7NaAd3v5az8= 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=sG+BtDdFQulwUvgiDxwDw492IQM=; b=LZ2yp xjvEtvFQTZwOw+rzOh80l/7QZoXjEE1EXz18rNImm2Yw7fy1m6Neco+5DhFddRf6 z8OCUlXNGjR7gyavLXrmd9WQIdsLxIm1vMz45E3yGtblYfNjbtCnKwsdhApPjxJ4 m9fB0hRXw1ct/0LStKBqhItKHrTQhOWYzZ29V8= Received: (qmail 79570 invoked by alias); 26 Feb 2018 21:04:28 -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 77816 invoked by uid 89); 26 Feb 2018 21:04:14 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.1 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=sk:advance, sk:ADVANCE X-HELO: mail-qt0-f193.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=fDjQ5OUa2soFgyRdhn2SoufZT3BrNbhlmpMoS+lUuNk=; b=SVkxrPDkRCkHpE/FkXARXvgEZ2oko7YZ8wQCYqx9QCHJ3rDaa6s8IqQxY1e34fcEiN DpKb0XyuQaQDGbCY+98gDQcJRI7ruQjxYR2OD4v9ZiheIav3EVk4rc1mS+QYs217wGsC Tm4k85hL7z2nWnRdWIMUcAWyUKmxNlmgFToeaMODJqCo+jTiTrqoY1ljTASlmaZfSbOm RQr4y81LWpJtjw8CeJ7pVQWH57U/lOF/xTdk0/U3qUfiPhbLVfdYjrr7bUUx49wLKuGb fy8Cja7LGRis3YO/Kg3dz2xT7OqRPx45rG36Ge2UbBfLbq6LkaqmVAaKSU+68MIExXjc f8ew== X-Gm-Message-State: APf1xPCRGB0T5PHIVluATj2+kbjxF0+T1I06xklzrcNbQ5fPsT1e8WVd ZqxvqC7qzmNy4TCtcQ6m0yBfaXeIwwU= X-Received: by 10.200.25.134 with SMTP id u6mr18688823qtj.221.1519679048288; Mon, 26 Feb 2018 13:04:08 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH v2 16/21] nptl: sparc: Fix Race conditions in pthread cancellation (BZ#12683) Date: Mon, 26 Feb 2018 18:03:31 -0300 Message-Id: <1519679016-12241-17-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 sparc modifications required for the BZ#12683. It basically adds the required ucontext_get_pc function, cancellable syscall wrappers, and a fix for pause. Sparc requires arch-specific syscall_cancel implementation because INLINE_SYSCALL_NCS uses the __SYSCALL_STRING (defined different for sparc32 and sparc64) and it issues additional instructions after the syscall one to check the resulting error code. When used in the default syscall_cancel.c implementation the label __syscall_cancel_arch_end is not placed just after the syscall as expected. Both 32 and 64 bits version were based on default C version built with GCC 6.1. Also, different than other architectures, SPARC passes the sigcontext_t struct pointer as third argument in the signal handler set with SA_SIGINFO (some info at [1]) for 64 bits and the pt_regs in 32 bits. >From Linux code: * arch/sparc/kernel/signal_64.c 428 /* 3. signal handler back-trampoline and parameters */ 429 regs->u_regs[UREG_FP] = ((unsigned long) sf) - STACK_BIAS; 430 regs->u_regs[UREG_I0] = ksig->sig; 431 regs->u_regs[UREG_I1] = (unsigned long) &sf->info; 432 433 /* The sigcontext is passed in this way because of how it 434 * is defined in GLIBC's /usr/include/bits/sigcontext.h 435 * for sparc64. It includes the 128 bytes of siginfo_t. 436 */ 437 regs->u_regs[UREG_I2] = (unsigned long) &sf->info; * arch/sparc/kernel/signal_32.c: 392 regs->u_regs[UREG_FP] = (unsigned long) sf; 393 regs->u_regs[UREG_I0] = ksig->sig; 394 regs->u_regs[UREG_I1] = (unsigned long) &sf->info; 395 regs->u_regs[UREG_I2] = (unsigned long) &sf->regs; 396 397 regs->pc = (unsigned long) ksig->ka.sa.sa_handler; 398 regs->npc = (regs->pc + 4); So to access the signal mask in the signal frame, a arch-specific ucontext_get_mask is defined which obtain the sa_mask from the context. Checked on a SPARC T5 for sparc64-linux-gnu and sparcv9-linux-gnu. [BZ #12683] * sysdeps/unix/sysv/linux/sparc/sparc32/sigcontextinfo.h (ucontext_get_pc): New function. * sysdeps/unix/sysv/linux/sparc/sparc64/sigcontextinfo.h (ucontext_get_pc): Likewise. * sysdeps/unix/sysv/linux/sparc/sparc32/syscall_cancel.S: New file. * sysdeps/unix/sysv/linux/sparc/sparc64/syscall_cancel.S: Likwise. * sysdeps/unix/sysv/linux/sparc/sparc64/pause.c: New file. [1] https://www.spinics.net/lists/sparclinux/msg05037.html --- ChangeLog | 9 +++ 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 ++++++++++++++++++++++ sysdeps/unix/sysv/linux/sparc/sparc64/pause.c | 25 ++++++++ .../unix/sysv/linux/sparc/sparc64/sigcontextinfo.h | 40 ++++++++++++ .../unix/sysv/linux/sparc/sparc64/syscall_cancel.S | 74 ++++++++++++++++++++++ 7 files changed, 275 insertions(+), 1 deletion(-) create mode 100644 sysdeps/unix/sysv/linux/sparc/sparc32/syscall_cancel.S create mode 100644 sysdeps/unix/sysv/linux/sparc/sparc64/pause.c create mode 100644 sysdeps/unix/sysv/linux/sparc/sparc64/syscall_cancel.S -- 2.7.4 diff --git a/sysdeps/unix/sysv/linux/sparc/lowlevellock.h b/sysdeps/unix/sysv/linux/sparc/lowlevellock.h index e2c0b2a..ed2e746 100644 --- a/sysdeps/unix/sysv/linux/sparc/lowlevellock.h +++ b/sysdeps/unix/sysv/linux/sparc/lowlevellock.h @@ -117,7 +117,7 @@ __lll_timedlock (int *futex, const struct timespec *abstime, int private) { \ __typeof (tid) __tid; \ while ((__tid = (tid)) != 0) \ - lll_futex_wait (&(tid), __tid, LLL_SHARED); \ + lll_futex_wait_cancel (&(tid), __tid, LLL_SHARED); \ } \ while (0) diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/sigcontextinfo.h b/sysdeps/unix/sysv/linux/sparc/sparc32/sigcontextinfo.h index 91233b8..4114035 100644 --- a/sysdeps/unix/sysv/linux/sparc/sparc32/sigcontextinfo.h +++ b/sysdeps/unix/sysv/linux/sparc/sparc32/sigcontextinfo.h @@ -16,6 +16,11 @@ License along with the GNU C Library; if not, see . */ +#ifndef _SIGCONTEXTINFO_H +#define _SIGCONTEXTINFO_H + +#include + #define SIGCONTEXT struct sigcontext * #define SIGCONTEXT_EXTRA_ARGS #define GET_PC(__ctx) ((void *) ((__ctx)->si_regs.pc)) @@ -29,3 +34,50 @@ #define GET_FRAME(__ctx) ADVANCE_STACK_FRAME (GET_STACK(__ctx)) #define CALL_SIGHANDLER(handler, signo, ctx) \ (handler)((signo), SIGCONTEXT_EXTRA_ARGS (ctx)) + +/* Different that other architectures, SPARC32 pass a pt_regs (or pt_regs32 + in 32 bits compat mode) struct pointer as third argument for sa_sigaction + handler with SA_SIGINFO. + + Also current sparc32 rt signal frame layout is: + + field | size + ---------------------------------------| ---- + struct rt_signal_frame { | + struct sparc_stackf ss; | 96 + siginfo_t info; | 128 + struct pt_regs regs; | 80 + sigset_t mask; | 128 + __siginfo_fpu_t __user *fpu_save; | 4 + unsigned int insns[2]; | 8 + stack_t stack; | 12 + unsigned int extra_size; | 4 + __siginfo_rwin_t __user *rwin_save; | 4 + }; + + So to obtain a pointer to signal mask based on address of pt_regs + we need to add 208. */ + +struct pt_regs32 +{ + unsigned int psr; + unsigned int pc; + unsigned int npc; + unsigned int y; + unsigned int u_regs[16]; +}; + +static inline uintptr_t +ucontext_get_pc (struct pt_regs32 *regs) +{ + return regs->pc; +} + +static inline sigset_t * +ucontext_get_mask (const void *ctx) +{ + return (sigset_t *)((uintptr_t)ctx + 208); +} +#define UCONTEXT_SIGMASK(ctx) ucontext_get_mask (ctx) + +#endif /* _SIGCONTEXTINFO_H */ diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/syscall_cancel.S b/sysdeps/unix/sysv/linux/sparc/sparc32/syscall_cancel.S new file mode 100644 index 0000000..c06f9d1 --- /dev/null +++ b/sysdeps/unix/sysv/linux/sparc/sparc32/syscall_cancel.S @@ -0,0 +1,74 @@ +/* Cancellable syscall wrapper. Linux/sparc32 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 + +/* 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) + save %sp, -104, %sp + + cfi_window_save + cfi_register (15, 31) + cfi_def_cfa_register (30) + + .globl __syscall_cancel_arch_start +__syscall_cancel_arch_start: + + /* if (*cancelhandling & CANCELED_BITMASK) + __syscall_do_cancel() */ + ld [%i0], %g2 + andcc %g2, 4, %g0 + bne,pn %icc, 2f + + /* Issue a 6 argument syscall. */ + mov %i1, %g1 + mov %i2, %o0 + mov %i3, %o1 + mov %i4, %o2 + mov %i5, %o3 + ld [%fp+92], %o4 + ld [%fp+96], %o5 + ta 0x10 + + .globl __syscall_cancel_arch_end +__syscall_cancel_arch_end: + bcc 1f + mov 0,%g1 + sub %g0, %o0, %o0 + mov 1, %g1 + +1: + mov %o0, %i0 + return %i7+8 + nop + +2: + call __syscall_do_cancel, 0 + nop + nop + +END (__syscall_cancel_arch) +libc_hidden_def (__syscall_cancel_arch) diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/pause.c b/sysdeps/unix/sysv/linux/sparc/sparc64/pause.c new file mode 100644 index 0000000..4a0cf4d --- /dev/null +++ b/sysdeps/unix/sysv/linux/sparc/sparc64/pause.c @@ -0,0 +1,25 @@ +/* Linux pause syscall implementation. Linux/sparc64. + 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 + +/* On sparc interrupted pause syscall returns with a PC indicating a + side-effect and this deviates from other architectures. Fall back to + ppool implementation. */ +#undef __NR_pause +#include diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/sigcontextinfo.h b/sysdeps/unix/sysv/linux/sparc/sparc64/sigcontextinfo.h index c9d2685..dc04c42 100644 --- a/sysdeps/unix/sysv/linux/sparc/sparc64/sigcontextinfo.h +++ b/sysdeps/unix/sysv/linux/sparc/sparc64/sigcontextinfo.h @@ -16,6 +16,11 @@ License along with the GNU C Library; if not, see . */ +#ifndef _SIGCONTEXTINFO_H +#define _SIGCONTEXTINFO_H + +#include + #ifndef STACK_BIAS #define STACK_BIAS 2047 #endif @@ -29,3 +34,38 @@ #define GET_FRAME(__ctx) ADVANCE_STACK_FRAME (GET_STACK (__ctx)) #define CALL_SIGHANDLER(handler, signo, ctx) \ (handler)((signo), SIGCONTEXT_EXTRA_ARGS (ctx)) + +/* Different that other architectures, SPARC64 pass a sigcontext_t struct + pointer in third argument for sa_sigaction handler with SA_SIGINFO. + + Also current sparc64 rt signal frame layout is: + + field | size + ---------------------------------------| ---- + struct rt_signal_frame { | + struct sparc_stackf ss; | 192 + siginfo_t info; | 128 + struct pt_regs regs; | 160 + __siginfo_fpu_t __user *fpu_save; | 8 + stack_t stack; | 24 + sigset_t mask; | 128 + __siginfo_rwin_t *rwin_save; | 8 + }; + + So to obtain a pointer to signal mask based on address of info + we need to add 320. */ + +static inline uintptr_t +ucontext_get_pc (const struct sigcontext *sigctx) +{ + return sigctx->sigc_regs.tpc; +} + +static inline sigset_t * +ucontext_get_mask (const void *ctx) +{ + return (sigset_t *)((uintptr_t)ctx + 320); +} +#define UCONTEXT_SIGMASK(ctx) ucontext_get_mask (ctx) + +#endif /* _SIGCONTEXTINFO_H */ diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/syscall_cancel.S b/sysdeps/unix/sysv/linux/sparc/sparc64/syscall_cancel.S new file mode 100644 index 0000000..f3eef78 --- /dev/null +++ b/sysdeps/unix/sysv/linux/sparc/sparc64/syscall_cancel.S @@ -0,0 +1,74 @@ +/* Cancellable syscall wrapper. Linux/sparc64 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 + +/* 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) + save %sp, -176, %sp + + cfi_window_save + cfi_register (15, 31) + cfi_def_cfa_register (30) + + .globl __syscall_cancel_arch_start +__syscall_cancel_arch_start: + + /* if (*cancelhandling & CANCELED_BITMASK) + __syscall_do_cancel() */ + lduw [%i0], %g1 + andcc %g1, 4, %g0 + bne,pn %xcc, 2f + + /* Issue a 6 argument syscall. */ + mov %i1, %g1 + mov %i2, %o0 + mov %i3, %o1 + mov %i4, %o2 + mov %i5, %o3 + ldx [%fp + STACK_BIAS + 176], %o4 + ldx [%fp + STACK_BIAS + 184], %o5 + ta 0x6d + + .global __syscall_cancel_arch_end +__syscall_cancel_arch_end: + + bcc,pt %xcc, 1f + mov 0, %g1 + sub %g0, %o0, %o0 + mov 1, %g1 +1: + mov %o0, %i0 + return %i7+8 + nop + +2: + call __syscall_do_cancel, 0 + nop + nop + +END (__syscall_cancel_arch) +libc_hidden_def (__syscall_cancel_arch) From patchwork Mon Feb 26 21:03:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 129718 Delivered-To: patch@linaro.org Received: by 10.80.172.228 with SMTP id x91csp4292426edc; Mon, 26 Feb 2018 13:06:52 -0800 (PST) X-Google-Smtp-Source: AH8x2274A7nCMkTxV/wniE/iRDtipA4XleDin8m6BT09SLbt9ATNqIfla4A7IXfJ5BEE/cwi654g X-Received: by 2002:a17:902:a504:: with SMTP id s4-v6mr12216918plq.43.1519679212456; Mon, 26 Feb 2018 13:06:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519679212; cv=none; d=google.com; s=arc-20160816; b=zSzZgsBcD4AZqaiFiMM7biDkX4UA/BvDG4gK1lKj3BHXszHW5QEnq5vdjZxToa0HJy XNRXvzklUphfbQHwetZ5Fv6uK+P45Ga2Muvhxo0kX1msEhfJNQZtXx0wLNivtbMLzy9D 0+ZHJHDBkzFD1tgyXoLza975EkmF4CBwO8tqf2yz8KDWxw73ZTcqyPKlMcKr4602pkgm 3wx0KFH8sdgbhfMPa7SH5PYEzfGZz/RbImDFr2AsYxmGtWVGxkr9VIViiT45CAXzhGvv gW6mRtbce84GZhLGI+f1j5j0S/s6UnBBqm6QSiG6ub+EY5XVVoOsmRJbTgP3bvONrBmK i1mA== 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=BTN6rCfFWj0B5lk3A0HUW7Wol1AerOCIQypjTi1gqaA=; b=D2cB6Gx6TNNWYUhcUQFV290qStQdf7in48UYCc27nQ0JX9vPyvMhKK/bLCBbjc0sA7 3xVeGnl8PAaiSqcowf+3gagNCcYP7rh/HzpETgN7oCwSXAWONtj5BRtN+JcMe+Zb3Ksj lbPZMv7DEDpn7fonRQsmpJwjKpHLG4Bwz9aasZHYXWe9CgK54H3w9lDo2p8I+Nppq5S9 g0m3U4kYiCE5lUCFqRtl5rjfVpYA4AjHjR4cUrozBz4ws7SfZLMqBKUymTqrcVWqMEOr okGV9cJdunjchhrQbYzMNdQwZamG7KX32YlEp8HcLRFo24Ep/RV6YU1cRStnnk5dAeCH UFIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=sCyvO06R; spf=pass (google.com: domain of libc-alpha-return-90633-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-90633-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 d4si5973768pgq.337.2018.02.26.13.06.52 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Feb 2018 13:06:52 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-90633-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=sCyvO06R; spf=pass (google.com: domain of libc-alpha-return-90633-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-90633-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=Ugu/SH+M1GrRAlnnMiHdt0TN4YQ7YP5 4zwlM97dDIpm/rH0YDyhtc0W5qQrmakpjWXh/JOlvbJK2wBd0XJxF5kwPe4a1umQ R4zLTAl1ddeaBEudNQ07xDK98VZPIVlfzJn6nQ0hx856rWutuABs3dSkOW5nMC13 9VCo+Fq2hqGQ= 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=VfATniROpP/TgWjc6QYd/wKoveA=; b=sCyvO 06RjJSvPSNGHQrZqu57G87xbehW5ox5ZGigDY6BrceWvfTrICEdOjb1VPmhaoXHG 1AtPg4+g7QXSwhwdktcrlCELS9/wZWMh0ljNnikcKtzOOX/vWn0qXGNpWCATPgwO cjMJaBO7SZCqleTAvSv1ZdN9s0s1ZKmnvu18Kk= Received: (qmail 79039 invoked by alias); 26 Feb 2018 21:04:24 -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 77690 invoked by uid 89); 26 Feb 2018 21:04:13 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.1 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=r2, 0 X-HELO: mail-qt0-f195.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=BTN6rCfFWj0B5lk3A0HUW7Wol1AerOCIQypjTi1gqaA=; b=rITk9NJmzSNd8cYwwh05ZeHTojwco7Uhv6qVX0Jx0mJ2/TJ3Pvm2CoAg2IywbG+ZWz zZejzgeTpOuqXAc2ilid3if1KzAyHsPvkUWKSd4PF2X896MYimmj9Lrw6V9yiZWS+49A lUPLsCyuXXmNyfXbaj9oZqyj4NJdBIei8m/8HmnK/Yh/TsxRpB5roevIJ2MUcD9QRLWI 3JG9Yb3vTpT+ahsIXVY8/17d5dybhCOAHPysVUM3pulqdH5oz2XMz+KwI8+QHjI+Dqul 6Gci4GvCBLYoHNJfmDUgPDw3SZLgWel/RBWHk8t4oiq/UfbEho18vvPD5D6VawbqKusx paTA== X-Gm-Message-State: APf1xPDbfQkwa6nX/oLK3uElfhN6t4bSFUPvpXjKfhl1VuEBy6/bUc9S J69j4IRX4QuCAmaFSrnlc9Lw3j4yW94= X-Received: by 10.200.43.21 with SMTP id 21mr18869332qtu.98.1519679049686; Mon, 26 Feb 2018 13:04:09 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH v2 17/21] nptl: nios2: Fix Race conditions in pthread cancellation (BZ#12683) Date: Mon, 26 Feb 2018 18:03:32 -0300 Message-Id: <1519679016-12241-18-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 nios2 modifications required for the BZ#12683. It basically adds the required ucontext_get_pc function. The default syscall_cancel.c should be as expected for NIOS2. With GCC 6.2.1 syscall_cancel.c generates the following code: --- 00000000 <__GI___syscall_cancel_arch>: 0: defffe04 addi sp,sp,-8 4: dd800015 stw r22,0(sp) 8: 002ce03a nextpc r22 c: 02000034 movhi r8,0 10: 42000004 addi r8,r8,0 14: dfc00115 stw ra,4(sp) 18: b22d883a add r22,r22,r8 0000001c <__syscall_cancel_arch_start>: 1c: 20c00017 ldw r3,0(r4) 20: 18c0010c andi r3,r3,4 24: 18000f1e bne r3,zero,64 <__syscall_cancel_arch_end+0x18> 28: 3015883a mov r10,r6 2c: 2805883a mov r2,r5 30: da400517 ldw r9,20(sp) 34: 380b883a mov r5,r7 38: da000417 ldw r8,16(sp) 3c: d9c00317 ldw r7,12(sp) 40: d9800217 ldw r6,8(sp) 44: 5009883a mov r4,r10 48: 003b683a trap 0 0000004c <__syscall_cancel_arch_end>: 4c: 38000126 beq r7,zero,54 <__syscall_cancel_arch_end+0x8> 50: 0085c83a sub r2,zero,r2 54: dfc00117 ldw ra,4(sp) 58: dd800017 ldw r22,0(sp) 5c: dec00204 addi sp,sp,8 60: f800283a ret 64: b0800017 ldw r2,0(r22) 68: 103ee83a callr r2 --- Checked against a build and make check run-built-tests=no for nios2-linux-gnu. [BZ #12683] * sysdeps/unix/sysv/linux/nios2/sigcontextinfo.h (ucontext_get_pc): New function. --- ChangeLog | 4 ++++ sysdeps/unix/sysv/linux/nios2/sigcontextinfo.h | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) -- 2.7.4 diff --git a/sysdeps/unix/sysv/linux/nios2/sigcontextinfo.h b/sysdeps/unix/sysv/linux/nios2/sigcontextinfo.h index 57b9b50..7ae735f 100644 --- a/sysdeps/unix/sysv/linux/nios2/sigcontextinfo.h +++ b/sysdeps/unix/sysv/linux/nios2/sigcontextinfo.h @@ -16,6 +16,11 @@ License along with the GNU C Library; if not, see . */ +#ifndef _SIGCONTEXTINFO_H +#define _SIGCONTEXTINFO_H + +#include + #include #include "kernel-features.h" @@ -33,3 +38,14 @@ (act)->sa_flags |= SA_SIGINFO; \ (sigaction) (sig, act, oact); \ }) + +static inline uintptr_t +ucontext_get_pc (const ucontext_t *uc) +{ + /* rt_restore_ucontext (arch/nios/kernel/signal.c) sets this position + to 'ea' register which is stated as exception return address (pc) + at arch/nios2/include/asm/ptrace.h. */ + return uc->uc_mcontext.regs[27]; +} + +#endif /* _SIGCONTEXTINFO_H */ From patchwork Mon Feb 26 21:03:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 129720 Delivered-To: patch@linaro.org Received: by 10.80.172.228 with SMTP id x91csp4292762edc; Mon, 26 Feb 2018 13:07:12 -0800 (PST) X-Google-Smtp-Source: AH8x225bf9j9TOajf1Xel61hpB6l1Yntfn6cKmOFDSVYnCo5k9iJBPjqAIV/ta0GDv6LagmjIkiS X-Received: by 10.167.131.199 with SMTP id j7mr11637851pfn.99.1519679232693; Mon, 26 Feb 2018 13:07:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519679232; cv=none; d=google.com; s=arc-20160816; b=Olhplu4EkmNlO3OWL5sTQ9htYYmMjNku0krgB35n7xFk25Tsl2icq6cbkBT6NWRCph AmIo9CKZjFdBzjhU+C+/g2mCgW1qO8lvgkKZfZY7/P0g4jjRKYbgBy1cw1lJJFKfKV9I 7xwty6AKpmcDGe9lyHXAoQpgnKp0Axr8eRflUcQ/467FTmOKPZiWoO+fVN/mv1aULbcs Dip1lQVuLYo5afIIDAcoIlx4T2UgTBZRoSX81hgEQ1A9oWG4rap104GOY57ktKvd0oLv pXdrXeSgYDx2HBEWljC/wUQDCJX+z+L9zBfvu8ZVWSSBYrH9POC2hiCDUJ8NeGGJICbI Rm9Q== 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=hb8UvkBJfeaG645t3Gab0kwORa9VQxOXJFikOnbpdm0=; b=fBd8Fntw5VEABj2ehIugfwRtILQyoLRWl2tr7QH0Jh8E21hPu8HkTbBEL3R14fnnvu cAH0vPs0OjXSNWNikrsF1Waah9hPHU4VduIyJtG9WSnC0Eq4LIWcuSIqqY54Z9PEKRZi xjnN1pw4wHA4wdNjQiNOlLj7A2r+ADSW2oZc3qqBl+pHRbjnzvyI4ngyaKhcHH+Qzhs5 pb4NJlolOr6m7IV4yQzhEnqUxHjwvV6N3QviLOjf17ExZPLPlJctpc7jzNJUus+IXV+f cRkC/UCA7kTaRB5XPvxsGCLMR7sWsAt6+cA3J/XsXwzyK3Gb+sMUr5fZh7Vz7DKCM0u8 k0kw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=SXnwBY20; spf=pass (google.com: domain of libc-alpha-return-90635-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-90635-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 e9-v6si7434489pln.492.2018.02.26.13.07.12 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Feb 2018 13:07:12 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-90635-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=SXnwBY20; spf=pass (google.com: domain of libc-alpha-return-90635-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-90635-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=gfEeetSsmdrXdGTCQSTXtNL2bsCgV9m 01Q1toHItM/Gu0WAfJ58EGrcsTBULFsJAjzawUJAcs4EM3ug5/bCU/Wvg0/reC8v eUQOmMkuh5eVuy9BaMoLUkDZ+ktKnC7tnlhoscitB7Zx1b0dUu0ODkZnuSGeViga 6KjPEx6ibQIo= 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=svdX8CE2tJ84XY5uRpIpFZngc3A=; b=SXnwB Y20qCTOObXpcBfu/s3cWcJCjr6TDdE0OpHKlz1OXP2Rk9srKbi9CnWaosKd0V56/ yqZ2GZj4VSXi2iqq7rdegtmvYrYsjSYhmG6ande0P2D2rdCrnIl/RCUz47Ift54e WnRsOFKvLy50IOX53RqzRqQjwwzNJ/I80K2NM0= Received: (qmail 79714 invoked by alias); 26 Feb 2018 21:04:29 -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 77903 invoked by uid 89); 26 Feb 2018 21:04:15 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.1 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= X-HELO: mail-qk0-f195.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=hb8UvkBJfeaG645t3Gab0kwORa9VQxOXJFikOnbpdm0=; b=lT/G0JptlFPO4Ce/Q8ywnMlwFsEQEe/PcdN8J/6zV/eaCfRtPIBnwmGW4jLbcMX2jB +SwUopzhzTzikxZ4Wx0plPjY1Fj8iRmHHDVxn8vHPU/76HKrhZ8bRIlDpmSmwUE90Nmb ZUR4R+ppVL+Fe3PHXUy+XHjNRSTSaDMlTtMCul1vc4xxbfL710J9OBXDZWy8eY0kSkIy UpU/qgeU+/1pKRDh/M79b3isjUL96eUQMk7T0BHQVr2uUkrLma828Ntx6yd4wBefB/6I weAL6tmstHaIl3EimzBf+RMLBLE6ocpa1qzpuA3v+Czsl8yg7VbIiGUcrgHYn9wzFYgC K+3w== X-Gm-Message-State: APf1xPBpnvpAmw+KOQhzWU6Jg0VEEL7uxWq/oM4FuK8hCQ5Hpq+Nmzl3 elrvM+ZwgzpfkotyqZ61XjpAep0Sr6s= X-Received: by 10.55.18.135 with SMTP id 7mr19578352qks.7.1519679051007; Mon, 26 Feb 2018 13:04:11 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH v2 18/21] nptl: sh: Fix Race conditions in pthread cancellation (BZ#12683) Date: Mon, 26 Feb 2018 18:03:33 -0300 Message-Id: <1519679016-12241-19-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 sh modifications required for the BZ#12683. It basically adds the required ucontext_get_pc function and a cancellable syscall wrapper. SH requires an arch-specific syscall_cancel because the INTERNAL_SYSCALL_NCS adds the required or instruction to workaround a hardware bug [1]. The implementation were based on on default C version built with GCC 6.2.1. Checked against a build and make check run-built-tests=no for sh4-linux-gnu. [BZ #12683] * sysdeps/unix/sysv/linux/sh/syscall_cancel.S: New file. * sysdeps/unix/sysv/linux/sh/sigcontextinfo.h (ucontext_get_pc): New function. [1] http://documentation.renesas.com/eng/products/mpumcu/tu/tnsh7456ae.pdf --- ChangeLog | 6 ++ sysdeps/sh/sysdep.h | 1 + sysdeps/unix/sysv/linux/sh/sigcontextinfo.h | 11 +++ sysdeps/unix/sysv/linux/sh/syscall_cancel.S | 125 ++++++++++++++++++++++++++++ 4 files changed, 143 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/sh/syscall_cancel.S -- 2.7.4 diff --git a/sysdeps/sh/sysdep.h b/sysdeps/sh/sysdep.h index 37889fb..df34c4c 100644 --- a/sysdeps/sh/sysdep.h +++ b/sysdeps/sh/sysdep.h @@ -24,6 +24,7 @@ #define ALIGNARG(log2) log2 #define ASM_SIZE_DIRECTIVE(name) .size name,.-name +#define L(label) .L##label #ifdef SHARED #define PLTJMP(_x) _x##@PLT diff --git a/sysdeps/unix/sysv/linux/sh/sigcontextinfo.h b/sysdeps/unix/sysv/linux/sh/sigcontextinfo.h index d6dd48d..239f931 100644 --- a/sysdeps/unix/sysv/linux/sh/sigcontextinfo.h +++ b/sysdeps/unix/sysv/linux/sh/sigcontextinfo.h @@ -16,6 +16,9 @@ License along with the GNU C Library; if not, see . */ +#ifndef _SIGCONTEXTINFO_H +#define _SIGCONTEXTINFO_H + #define SIGCONTEXT int _a2, int _a3, int _a4, struct sigcontext #define SIGCONTEXT_EXTRA_ARGS _a2, _a3, _a4, @@ -24,3 +27,11 @@ #define GET_STACK(ctx) ((void *) ctx.sc_regs[15]) #define CALL_SIGHANDLER(handler, signo, ctx) \ (handler)((signo), SIGCONTEXT_EXTRA_ARGS (ctx)) + +static inline uintptr_t +ucontext_get_pc (const ucontext_t *uc) +{ + return uc->uc_mcontext.pc; +} + +#endif /* _SIGCONTEXTINFO_H */ diff --git a/sysdeps/unix/sysv/linux/sh/syscall_cancel.S b/sysdeps/unix/sysv/linux/sh/syscall_cancel.S new file mode 100644 index 0000000..02a050d --- /dev/null +++ b/sysdeps/unix/sysv/linux/sh/syscall_cancel.S @@ -0,0 +1,125 @@ +/* Cancellable syscall wrapper. Linux/sh 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 + +/* 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) + +#ifdef SHARED + mov.l r12,@-r15 + cfi_def_cfa_offset (4) + cfi_offset (12, -4) + mova L(GT),r0 + mov.l L(GT),r12 + sts.l pr,@-r15 + cfi_def_cfa_offset (8) + cfi_offset (17, -8) + add r0,r12 +#else + sts.l pr,@-r15 + cfi_def_cfa_offset (4) + cfi_offset (17, -4) +#endif + + .globl __syscall_cancel_arch_start +__syscall_cancel_arch_start: + + /* if (*cancelhandling & CANCELED_BITMASK) + __syscall_do_cancel() */ + mov.l @r4,r0 + tst #4,r0 + bf/s 1f + + /* Issue a 6 argument syscall. */ + mov r5,r3 + mov r6,r4 + mov r7,r5 +#ifdef SHARED + mov.l @(8,r15),r6 + mov.l @(12,r15),r7 + mov.l @(16,r15),r0 + mov.l @(20,r15),r1 +#else + mov.l @(4,r15),r6 + mov.l @(8,r15),r7 + mov.l @(12,r15),r0 + mov.l @(16,r15),r1 +#endif + trapa #0x16 + +/* The additional or is a workaround for a hardware issue: + http://documentation.renesas.com/eng/products/mpumcu/tu/tnsh7456ae.pdf */ + .globl __syscall_cancel_arch_end +__syscall_cancel_arch_end: + + or r0,r0 + or r0,r0 + or r0,r0 + or r0,r0 + or r0,r0 + + lds.l @r15+,pr + cfi_remember_state + cfi_restore (17) +#ifdef SHARED + cfi_def_cfa_offset (4) + rts + mov.l @r15+,r12 + cfi_def_cfa_offset (0) + cfi_restore (12) + .align 1 +1: + cfi_restore_state + mov.l L(SC),r1 + bsrf r1 +L(M): + nop + + .align 2 +L(GT): + .long _GLOBAL_OFFSET_TABLE_ +L(SC): + .long __syscall_do_cancel-(L(M)+2) +#else + cfi_def_cfa_offset (0) + rts + nop + + .align 1 +1: + cfi_restore_state + mov.l 2f,r1 + jsr @r1 + nop + + .align 2 +2: + .long __syscall_do_cancel +#endif + +END (__syscall_cancel_arch) +libc_hidden_def (__syscall_cancel_arch) From patchwork Mon Feb 26 21:03:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 129723 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp643773lja; Mon, 26 Feb 2018 13:07:43 -0800 (PST) X-Google-Smtp-Source: AH8x225zGUrJlIE5ohXQp8mz1G+zYrdRE5N+/20JPpWBE/j6PmBVCJg0DXGm+9VfugFQ2b1fjdIy X-Received: by 2002:a17:902:e85:: with SMTP id 5-v6mr11943438plx.208.1519679263325; Mon, 26 Feb 2018 13:07:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519679263; cv=none; d=google.com; s=arc-20160816; b=YiNfQ1eKyFJzZ54oL3dXAa4NtSKoVfXyNcXy+xpJErEDfNuEP04dyNbIIOI4u56O05 jcedzVZhxu9C55ax550inQZK9wI4cYmhnPI7pEgL43CIQ9jMDz+rdD6ygB/HqSNABnzV dXOUPUsSFrogmuOOs3uhU6+ItAYfEYgWJkag5gNyO1UJKpfgjXxGfBr6+tP9okEyMerF bWnu7gB7oPzR6rMPFuxlZKfyWU+DmQ4IjM2JPRLCVqoq4CvdRG6TJedWP2f4W/5Clt2v 75g+3/5KOKd6R+DS5apD4qOeVj1Y8ahY8jnF9ijjPVnQ3joegVa0V9aagC4mrBpAQKJ5 6Q8Q== 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=JLo3wp3BnEwAwjeeDPPFI8lxnv6XHwbggPVGbI6mcZ0=; b=a9dZofcQK+c6nsU+c1899ImAj6LvHp7O1VBos2YKvmWGK3f3B0S0asehb6FTw+73PU Wg5Gvgbk4acT48xU8MsCNUte0yb1uSncbzD8PHhw60f37a1lvZAjYjHHkuoacfEND1WQ KbeqfHmKic2LSv3S0R7HtkNcXz/G16MJ+6tCPDkkaAnm07aFG0Aal2FD/GSnUdFUeuOU BD5CZ4HS0QxhfR3mjqlyqWRWdQKMFlhWN5AIEz1g4g5+AJjBjkfGwS69tph+DiJfWapl EsFoPAmrCYA2IHToGEiST8cRknCA7AUr5B+/dqgL53RZ6HwHxMht1pd9pdZgpgfp08SU WeFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=cEW03qvT; spf=pass (google.com: domain of libc-alpha-return-90638-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-90638-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 c5-v6si7380815pll.90.2018.02.26.13.07.42 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Feb 2018 13:07:43 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-90638-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=cEW03qvT; spf=pass (google.com: domain of libc-alpha-return-90638-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-90638-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=dkFGSWDQmReCbuYEZiMBdBBeDUUZ8mN /exdeqMzFWg2Mn150timefH7S4c9dKk65nq+UxjzPL91V0OQgcMF379x5xaMJi+f oXJ3YS5R/wCIJWyvPtULt93mHbH4rut0GP4tYtgUBW59cMPGgWJhrynNguNzhEiA yH/tXdwq8iRw= 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=zTGdmYikGcZbh7cMzBzkiRuGo3g=; b=cEW03 qvTi6FWHmwdGkpKWFrdd7FgJoYe404bMnM8y9pBzyI10UWEWse2ME+gIXOp8KhUF mo2fNFwY3WQoLEqn+y1qp1wwkiZQpk0F5w5JrUYJ3gM75vih69vaU74IIsuZAVNi KMMtfjQMHocJdyx8Bxvt9qSpo7vBIjlCx3qv/8= Received: (qmail 80086 invoked by alias); 26 Feb 2018 21:04:31 -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 78453 invoked by uid 89); 26 Feb 2018 21:04:19 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.1 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= X-HELO: mail-qk0-f195.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=JLo3wp3BnEwAwjeeDPPFI8lxnv6XHwbggPVGbI6mcZ0=; b=X750nj/8tNGP01Z1yJkoeo9HFQTCskiQfzxp+mncC1OkRoAzcPPCcYcs3liXBmX6kb 4/AZC71pS/CowzXNXdk63SADEnOp8JBTfwsvX7/Teq8xT72bMKBlp+bqXLpE/189JN48 27k1fN2NoQNSSyxNpVxHcsaCL8MOjRpp23qewg9Fo6s2hdKPayRZLyI4RuWPXt4Vk5Bb lYC81UD42EoR3GXSN2nsWcKXogyoLUgwqA6tIMbvc0GjXx7GV9LiaCC3sF+8fwsrW1Jk C9J8bnlKXwb/fuPFY0rV/jSC29e2PrHUuSZWcF4J/wIMbdJQrcxcaHG2PX1rg1/whvEP 9zKA== X-Gm-Message-State: APf1xPC/DtucO8X/I0u+uaZU+mhaDt3vZOTgz+jlP4aSqroyCU3dgFNN Xfn9jtalPOyhxRAx9vsAjCHdw7uE2n4= X-Received: by 10.55.72.203 with SMTP id v194mr19705058qka.170.1519679052320; Mon, 26 Feb 2018 13:04:12 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH v2 19/21] nptl: mips: Fix Race conditions in pthread cancellation (BZ#12683) Date: Mon, 26 Feb 2018 18:03:34 -0300 Message-Id: <1519679016-12241-20-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 mips modifications required for the BZ#12683. It adds the required ucontext_get_pc function, a mips32 cancellable syscall wrapper and 7 argument cancellable syscall support. To avoid code pessimization and add a requirement on all architectures to support {INLINE,INTERNAL)_SYSCALL with 7 argument, its support is added through a flag, HAVE_CANCELABLE_SYSCALL_WITH_7_ARGS, which changes the signature and prototype of the requires macros and functions (SYSCALL_CANCEL, __syscall_cancel and __syscall_cancel_arch). As default 6 arguments cancellable syscalls are use. MIPS o32 requires an arch-specific implementation because INTERNAL_SYSCALL_NCS adds an 'addiu' just after the syscall instruction which invalidates the checks on sigcancel_handler. Checked against a build and make check run-built-tests=no for mips-gnu-linux, mips64-linux-gnu, mips64-n32-linux-gnu. I also ran some basic o32 and n64 cancellation tests on a simulated mips64 qemu system. [BZ #12683] * nptl/libc-cancellation.c (__syscall_cancel): Define and use 7 argument syscall if architecture requires it. * nptl/pthreadP.h (__syscall_cancel_arch): Likewise. * sysdeps/unix/sysdep.h (__syscall_cancel, __SYSCALL_CANCEL*): Define with 7 argument if architecture requires it. (__SYSCALL_CANCEL7_ARG_DEF): New macro. (__SYSCALL_CANCEL7_ARG): Likewise. (__SYSCALL_CANCEL7_ARG7): Likewise. * sysdeps/unix/sysv/linux/syscall_cancel.c (__syscall_cancel_arch): Likewise. * sysdeps/mips/nptl/tls.h (READ_THREAD_POINTER): Check __mips_isa_rev existance for macro definition. * sysdeps/unix/sysv/linux/mips/sigcontextinfo.h (ucontext_get_pc): New function. * sysdeps/unix/sysv/linux/mips/mips32/syscall_cancel.S: New file. * sysdeps/unix/sysv/linux/mips/mips32/sysdep.h (HAVE_CANCELABLE_SYSCALL_WITH_7_ARGS): Define. --- ChangeLog | 19 +++ nptl/libc-cancellation.c | 7 +- nptl/pthreadP.h | 3 +- sysdeps/mips/nptl/tls.h | 2 +- sysdeps/unix/sysdep.h | 38 ++++-- .../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/syscall_cancel.c | 6 +- 9 files changed, 204 insertions(+), 16 deletions(-) create mode 100644 sysdeps/unix/sysv/linux/mips/mips32/syscall_cancel.S -- 2.7.4 diff --git a/nptl/libc-cancellation.c b/nptl/libc-cancellation.c index 9b054aa..beb433c 100644 --- a/nptl/libc-cancellation.c +++ b/nptl/libc-cancellation.c @@ -25,7 +25,7 @@ long int __syscall_cancel (__syscall_arg_t nr, __syscall_arg_t a1, __syscall_arg_t a2, __syscall_arg_t a3, __syscall_arg_t a4, __syscall_arg_t a5, - __syscall_arg_t a6) + __syscall_arg_t a6 __SYSCALL_CANCEL7_ARG_DEF) { pthread_t self = (pthread_t) THREAD_SELF; volatile struct pthread *pd = (volatile struct pthread *) self; @@ -35,7 +35,8 @@ __syscall_cancel (__syscall_arg_t nr, __syscall_arg_t a1, if (pd->cancelhandling & CANCELSTATE_BITMASK) { INTERNAL_SYSCALL_DECL (err); - result = INTERNAL_SYSCALL_NCS_CALL (nr, err, a1, a2, a3, a4, a5, a6); + result = INTERNAL_SYSCALL_NCS_CALL (nr, err, a1, a2, a3, a4, a5, a6 + __SYSCALL_CANCEL7_ARG7); if (INTERNAL_SYSCALL_ERROR_P (result, err)) return -INTERNAL_SYSCALL_ERRNO (result, err); return result; @@ -44,7 +45,7 @@ __syscall_cancel (__syscall_arg_t nr, __syscall_arg_t a1, /* Call the arch-specific entry points that contains the globals markers to be checked by SIGCANCEL handler. */ result = __syscall_cancel_arch (&pd->cancelhandling, nr, a1, a2, a3, a4, a5, - a6); + a6 __SYSCALL_CANCEL7_ARG7); if ((result == -EINTR) && (pd->cancelhandling & CANCELED_BITMASK) diff --git a/nptl/pthreadP.h b/nptl/pthreadP.h index bb7ff81..448abea 100644 --- a/nptl/pthreadP.h +++ b/nptl/pthreadP.h @@ -317,7 +317,8 @@ __do_cancel (void) extern long int __syscall_cancel_arch (volatile int *, __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); + __syscall_arg_t arg4, __syscall_arg_t arg5, __syscall_arg_t arg6 + __SYSCALL_CANCEL7_ARG_DEF); libc_hidden_proto (__syscall_cancel_arch); extern void __syscall_do_cancel (void) diff --git a/sysdeps/mips/nptl/tls.h b/sysdeps/mips/nptl/tls.h index 5f8cd21..d037cb8 100644 --- a/sysdeps/mips/nptl/tls.h +++ b/sysdeps/mips/nptl/tls.h @@ -35,7 +35,7 @@ # define READ_THREAD_POINTER() (__builtin_thread_pointer ()) #else /* Note: rd must be $v1 to be ABI-conformant. */ -# if __mips_isa_rev >= 2 +# if defined __mips_isa_rev && __mips_isa_rev >= 2 # define READ_THREAD_POINTER() \ ({ void *__result; \ asm volatile ("rdhwr\t%0, $29" : "=v" (__result)); \ diff --git a/sysdeps/unix/sysdep.h b/sysdeps/unix/sysdep.h index cea81a5..42720c5 100644 --- a/sysdeps/unix/sysdep.h +++ b/sysdeps/unix/sysdep.h @@ -121,29 +121,51 @@ typedef long int __syscall_arg_t; # define __SSC(__x) ((__syscall_arg_t) (__x)) #endif +/* Adjust both the __syscall_cancel and the SYSCALL_CANCEL macro to support + 7 arguments instead of default 6 (for some architectures like mip32). + We need it because using 7 arguments for all architecture would require + then to implement both {INTERNAL,INLINE}_SYSCALL and __syscall_cancel_arch + to accept 7 arguments. */ +#ifdef HAVE_CANCELABLE_SYSCALL_WITH_7_ARGS +# define __SYSCALL_CANCEL7_ARG_DEF , __syscall_arg_t arg7 +# define __SYSCALL_CANCEL7_ARG , 0 +# define __SYSCALL_CANCEL7_ARG7 , arg7 +#else +# define __SYSCALL_CANCEL7_ARG_DEF +# define __SYSCALL_CANCEL7_ARG +# define __SYSCALL_CANCEL7_ARG7 +#endif + long int __syscall_cancel (__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); + __syscall_arg_t arg6 __SYSCALL_CANCEL7_ARG_DEF); libc_hidden_proto (__syscall_cancel); #define __SYSCALL_CANCEL0(name) \ - (__syscall_cancel)(__NR_##name, 0, 0, 0, 0, 0, 0) + (__syscall_cancel)(__NR_##name, 0, 0, 0, 0, 0, 0 \ + __SYSCALL_CANCEL7_ARG) #define __SYSCALL_CANCEL1(name, a1) \ - (__syscall_cancel)(__NR_##name, __SSC(a1), 0, 0, 0, 0, 0) + (__syscall_cancel)(__NR_##name, __SSC(a1), 0, 0, 0, 0, 0 \ + __SYSCALL_CANCEL7_ARG) #define __SYSCALL_CANCEL2(name, a1, a2) \ - (__syscall_cancel)(__NR_##name, __SSC(a1), __SSC(a2), 0, 0, 0, 0) + (__syscall_cancel)(__NR_##name, __SSC(a1), __SSC(a2), 0, 0, 0, 0 \ + __SYSCALL_CANCEL7_ARG) #define __SYSCALL_CANCEL3(name, a1, a2, a3) \ - (__syscall_cancel)(__NR_##name, __SSC(a1), __SSC(a2), __SSC(a3), 0, 0, 0) + (__syscall_cancel)(__NR_##name, __SSC(a1), __SSC(a2), __SSC(a3), 0, 0, 0 \ + __SYSCALL_CANCEL7_ARG) #define __SYSCALL_CANCEL4(name, a1, a2, a3, a4) \ (__syscall_cancel)(__NR_##name, __SSC(a1), __SSC(a2), __SSC(a3), \ - __SSC(a4), 0, 0) + __SSC(a4), 0, 0 __SYSCALL_CANCEL7_ARG) #define __SYSCALL_CANCEL5(name, a1, a2, a3, a4, a5) \ (__syscall_cancel)(__NR_##name, __SSC(a1), __SSC(a2), __SSC(a3), \ - __SSC(a4), __SSC(a5), 0) + __SSC(a4), __SSC(a5), 0 __SYSCALL_CANCEL7_ARG) #define __SYSCALL_CANCEL6(name, a1, a2, a3, a4, a5, a6) \ (__syscall_cancel)(__NR_##name, __SSC(a1), __SSC(a2), __SSC(a3), \ - __SSC(a4), __SSC(a5), __SSC(a6)) + __SSC(a4), __SSC(a5), __SSC(a6) __SYSCALL_CANCEL7_ARG) +#define __SYSCALL_CANCEL7(name, a1, a2, a3, a4, a5, a6, a7) \ + (__syscall_cancel)(__NR_##name, __SSC(a1), __SSC(a2), __SSC(a3), \ + __SSC(a4), __SSC(a5), __SSC(a6), __SSC(a7)) #define __SYSCALL_CANCEL_NARGS_X(a,b,c,d,e,f,g,h,n,...) n #define __SYSCALL_CANCEL_NARGS(...) \ diff --git a/sysdeps/unix/sysv/linux/mips/mips32/syscall_cancel.S b/sysdeps/unix/sysv/linux/mips/mips32/syscall_cancel.S new file mode 100644 index 0000000..75c4390 --- /dev/null +++ b/sysdeps/unix/sysv/linux/mips/mips32/syscall_cancel.S @@ -0,0 +1,128 @@ +/* Cancellable syscall wrapper. Linux/mips32 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 +#include + +/* long int __syscall_cancel_arch (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, + __syscall_arg_t arg7) */ + +#define FRAME_SIZE 56 + +NESTED (__syscall_cancel_arch, FRAME_SIZE, fp) + .mask 0xc0070000,-SZREG + .fmask 0x00000000,0 + + PTR_ADDIU sp, -FRAME_SIZE + cfi_def_cfa_offset (FRAME_SIZE) + + sw fp,48(sp) + sw ra,52(sp) + sw s2,44(sp) + sw s1,40(sp) + sw s0,36(sp) +#ifdef __PIC__ + .cprestore 16 +#endif + cfi_offset (31, -4) + cfi_offset (30, -8) + cfi_offset (18, -12) + cfi_offset (17, -16) + cfi_offset (16, -20) + move fp,sp + cfi_def_cfa_register (30) + + .globl __syscall_cancel_arch_start + .type __syscall_cancel_arch_start, @function +__syscall_cancel_arch_start: + + lw v0,0(a0) + andi v0,v0,0x4 + bne v0,zero,2f + + addiu sp,sp,-16 + addiu v0,sp,16 + sw v0,24(fp) + + move s0,a1 + move a0,a2 + move a1,a3 + lw a2,72(fp) + lw a3,76(fp) + lw v0,84(fp) + lw s1,80(fp) + lw s2,88(fp) + + .set noreorder + subu sp, 32 + sw s1, 16(sp) + sw v0, 20(sp) + sw s2, 24(sp) + move v0, $16 + syscall + + .globl __syscall_cancel_arch_end + .type __syscall_cancel_arch_end, @function +__syscall_cancel_arch_end: + addiu sp, 32 + .set reorder + + beq a3,zero,1f + subu v0,zero,v0 +1: + move sp,fp + cfi_remember_state + cfi_def_cfa_register (29) + lw ra,52(fp) + lw fp,48(sp) + lw s2,44(sp) + lw s1,40(sp) + lw s0,36(sp) + .set noreorder + .set nomacro + jr ra + addiu sp,sp,FRAME_SIZE + + .set macro + .set reorder + + cfi_def_cfa_offset (0) + cfi_restore (16) + cfi_restore (17) + cfi_restore (18) + cfi_restore (30) + cfi_restore (31) + +2: + cfi_restore_state +#ifdef __PIC__ + PTR_LA t9, __syscall_do_cancel + jalr t9 +#else + jal __syscall_do_cancel +#endif + +END (__syscall_cancel_arch) +libc_hidden_def (__syscall_cancel_arch) diff --git a/sysdeps/unix/sysv/linux/mips/mips32/sysdep.h b/sysdeps/unix/sysv/linux/mips/mips32/sysdep.h index cbe9cd2..5417c43 100644 --- a/sysdeps/unix/sysv/linux/mips/mips32/sysdep.h +++ b/sysdeps/unix/sysv/linux/mips/mips32/sysdep.h @@ -18,6 +18,10 @@ #ifndef _LINUX_MIPS_MIPS32_SYSDEP_H #define _LINUX_MIPS_MIPS32_SYSDEP_H 1 +/* mips32 have cancelable syscalls with 7 arguments (currently only + sync_file_range). */ +#define HAVE_CANCELABLE_SYSCALL_WITH_7_ARGS 1 + /* There is some commonality. */ #include #include diff --git a/sysdeps/unix/sysv/linux/mips/sigcontextinfo.h b/sysdeps/unix/sysv/linux/mips/sigcontextinfo.h index d183a33..7da55f5 100644 --- a/sysdeps/unix/sysv/linux/mips/sigcontextinfo.h +++ b/sysdeps/unix/sysv/linux/mips/sigcontextinfo.h @@ -16,7 +16,10 @@ License along with the GNU C Library. If not, see . */ +#ifndef _SIGCONTEXTINFO_H +#define _SIGCONTEXTINFO_H +#include #include #if _MIPS_SIM == _ABIO32 @@ -39,4 +42,12 @@ #define CALL_SIGHANDLER(handler, signo, ctx) \ (handler)((signo), SIGCONTEXT_EXTRA_ARGS (ctx)) -#endif +#endif /* _MIPS_SIM == _ABIO32 */ + +static inline uintptr_t +ucontext_get_pc (const ucontext_t *uc) +{ + return uc->uc_mcontext.pc; +} + +#endif /* _SIGCONTEXTINFO_H */ diff --git a/sysdeps/unix/sysv/linux/syscall_cancel.c b/sysdeps/unix/sysv/linux/syscall_cancel.c index ac08bb7..5a3d383 100644 --- a/sysdeps/unix/sysv/linux/syscall_cancel.c +++ b/sysdeps/unix/sysv/linux/syscall_cancel.c @@ -46,14 +46,16 @@ long int __syscall_cancel_arch (volatile int *ch, __syscall_arg_t nr, __syscall_arg_t a1, __syscall_arg_t a2, __syscall_arg_t a3, __syscall_arg_t a4, - __syscall_arg_t a5, __syscall_arg_t a6) + __syscall_arg_t a5, __syscall_arg_t a6 + __SYSCALL_CANCEL7_ARG_DEF) { ADD_LABEL ("__syscall_cancel_arch_start"); if (__glibc_unlikely (*ch & CANCELED_BITMASK)) __syscall_do_cancel(); INTERNAL_SYSCALL_DECL(err); - long int result = INTERNAL_SYSCALL_NCS (nr, err, 6, a1, a2, a3, a4, a5, a6); + long int result = INTERNAL_SYSCALL_NCS_CALL (nr, err, a1, a2, a3, a4, a5, + a6 __SYSCALL_CANCEL7_ARG7); ADD_LABEL ("__syscall_cancel_arch_end"); if (INTERNAL_SYSCALL_ERROR_P (result, err)) return -INTERNAL_SYSCALL_ERRNO (result, err); From patchwork Mon Feb 26 21:03:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 129722 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp643613lja; Mon, 26 Feb 2018 13:07:32 -0800 (PST) X-Google-Smtp-Source: AH8x226XRdmSjuI6bbqlwbdGOOCJF4e/28yk/nz4K8mCXw9WjKHQSdr1OUUN9/O92vthhn8L6c4Q X-Received: by 10.99.36.70 with SMTP id k67mr9690340pgk.48.1519679252627; Mon, 26 Feb 2018 13:07:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519679252; cv=none; d=google.com; s=arc-20160816; b=o8PH4FIL6jC8uL6RsTphNot76TgaKA0/58bpHwL4vFwcxNqmadsSb3QHvZShQL8fAr kwG+2oH3ZVUgct26urLRQvWsqTRLl7cWfD1owQHL97u3FvV1/6S4XgFBmp+P4oXlZcvS KkBKUwwT+VonZASZJ3q0G9qX4X9ILns6MPj7mlq1u/ZFo/t4bJJwAhiBjMRvs7pWfpsd T33w+rcdpy1boD9Conhp7qk7xySeVh+pIpuAmbJbF5c8oU0sI9cnG9gYLb2Jguz7zCK9 6sJxfYFGB6i+aZnH0HsUP+wYK0XjBGTfbfK7oJuEYoMyE7K8efmcInv0KfTXUuBLa8EK 48/w== 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=7b0HtQeUonKE2pL+UgmZQxBlL0tys2Gld8rAWGKMtqM=; b=rwvicsg372gOCVwQS+qebXisS71JXlp2ci+UbRjFAhKYUDUgSrTjTpfRj0gobewH+5 pH+/oY0NxRVgjGSQThvgRomY83IKc4KlECxmuxNBNqqiKymZlOmEsvnPqtay8Etu30wf ltTzbaPW9T4EvFGLirYIeiV2MvOs/8d53VOvJKuiXYHQyMyZwbBstYGIXT7R2FdLyoIk 22xoDKcmk2pw9M2ucDEQsWL1Y7EUOHT+kthwv1Ly/2RMGyF4R16nX+9CKQHN+X4Ok3MM IHTjbBH8Rjv04Y6TXTUW/byerSHLgVe0AI0nhjOs4DJq+2RsQMcVNPRL3ZUIH1teggxp qlWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=uCp+cZc7; spf=pass (google.com: domain of libc-alpha-return-90637-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-90637-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 l19si6007007pgo.629.2018.02.26.13.07.32 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Feb 2018 13:07:32 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-90637-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=uCp+cZc7; spf=pass (google.com: domain of libc-alpha-return-90637-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-90637-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=C72ghnzfGFEsQymVeg2BkHkvYPfuDmz aKxexCyGAzpw2cKug3Qd5ykpEDOY686AT5RhTsYS79mZ7+Jeg29hQQFQyABsGZnB Ijj2PkfKpg3Y4Evs5p150p47eNBbU2M2WaUII2dU7oNzK+kQqIgAKRO9uxny90eU uj4nSE41DiX8= 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=BTfOIduRJm88sZvXTNytm+e/o7M=; b=uCp+c Zc7XdmE3YMoB9ouaCDMqBVRGnrJUlSyjux7LeegN3oJcpChsEzMRz1SDw3BnMMqm hjPdW9KPqu5V+Wh2svwmCtWNYVPl2Hmr5cKlGBwLBx4A1I+p9QJW1lTm+u8jXMzM W4IOkDVnduCKF0z9U2oP/FuCKCiFbf4Oxq8rNA= Received: (qmail 79950 invoked by alias); 26 Feb 2018 21:04:30 -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 78443 invoked by uid 89); 26 Feb 2018 21:04:19 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.1 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=ldo X-HELO: mail-qk0-f193.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=7b0HtQeUonKE2pL+UgmZQxBlL0tys2Gld8rAWGKMtqM=; b=ZFo/EQBAbKgSKI5qBEIYE6JbHLh6e13hMudcuTxNagR/Vjx20aCDKPFqQ/r9/2JyAI 4r34gHBWPTeMRBXGA1t+zVA3VmJ8UynhaNsU0VWyAVAcR011rCU0v3ydUtb1bxm31dbj jo1VuDdsTcO+3dgu9Y14YzHbgTFTi2X7QEXA6bixG4Y7WK86gKT9ngT5fdwD55NIOiBR B2gUQCETcCsOz0dHVnNsuc++KBVSHVeOVb1Ugf3xY+33YSKG4CbZ/OnHEe5QcvCSUuZh OZa+gsoICPkcz00zHYueAxmFM9GhEig57WsgEF5k1QBz2FIk+ihAyN799YiOCJlxHgwI oBIA== X-Gm-Message-State: APf1xPABdfs9CcLjk6bZlLmePeQzk9UkENwl4023oLZ7zlhkemIVRn0h MHiv6YjschqCBu2BxgcLy9EtgL8cXF0= X-Received: by 10.55.42.132 with SMTP id q4mr17961603qkq.77.1519679053563; Mon, 26 Feb 2018 13:04:13 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH v2 20/21] nptl: hppa: Fix Race conditions in pthread cancellation (BZ#12683) Date: Mon, 26 Feb 2018 18:03:35 -0300 Message-Id: <1519679016-12241-21-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 hppa modifications required for the BZ#12683. It basically adds the required __pthread_get_pc function. HPPA requires an arch-specific syscall_cancel because the INTERNAL_SYSCALL_NCS adds some instruction to fetch the returned syscalls value. The implementation were based on on default C version built with GCC 6.1 Checked on hppa-linux-gnu. [BZ #12683] * sysdeps/unix/sysv/linux/hppa/sigcontextinfo.h: New file. * sysdeps/unix/sysv/linux/hppa/syscall_cancel.S: Likewise. --- ChangeLog | 4 ++ sysdeps/unix/sysv/linux/hppa/sigcontextinfo.h | 38 +++++++++++++ sysdeps/unix/sysv/linux/hppa/syscall_cancel.S | 82 +++++++++++++++++++++++++++ 3 files changed, 124 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/hppa/sigcontextinfo.h create mode 100644 sysdeps/unix/sysv/linux/hppa/syscall_cancel.S -- 2.7.4 diff --git a/sysdeps/unix/sysv/linux/hppa/sigcontextinfo.h b/sysdeps/unix/sysv/linux/hppa/sigcontextinfo.h new file mode 100644 index 0000000..4f59c1e --- /dev/null +++ b/sysdeps/unix/sysv/linux/hppa/sigcontextinfo.h @@ -0,0 +1,38 @@ +/* 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 + . */ + +#ifndef _SIGCONTEXTINFO_H +#define _SIGCONTEXTINFO_H + +#include + +/* In general we cannot provide any information. */ +#define SIGCONTEXT struct sigcontext * +#define SIGCONTEXT_EXTRA_ARGS +#define GET_PC(ctx) ((void *) 0) +#define GET_FRAME(ctx) ((void *) 0) +#define GET_STACK(ctx) ((void *) 0) +#define CALL_SIGHANDLER(handler, signo, ctx) \ + (handler)((signo), SIGCONTEXT_EXTRA_ARGS (ctx)) + +static inline uintptr_t +ucontext_get_pc (const ucontext_t *uc) +{ + return uc->uc_mcontext.sc_iaoq[0] & ~0x3; +} + +#endif /* _SIGCONTEXTINFO_H */ diff --git a/sysdeps/unix/sysv/linux/hppa/syscall_cancel.S b/sysdeps/unix/sysv/linux/hppa/syscall_cancel.S new file mode 100644 index 0000000..552ba2f --- /dev/null +++ b/sysdeps/unix/sysv/linux/hppa/syscall_cancel.S @@ -0,0 +1,82 @@ +/* Cancellable syscall wrapper. Linux/hppa 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 + +/* 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) */ + + .text +ENTRY(__syscall_cancel_arch) + stw %r2,-20(%r30) + ldo 128(%r30),%r30 + cfi_def_cfa_offset (-128) + cfi_offset (2, -20) + ldw -180(%r30),%r28 + copy %r24,%r31 + stw %r28,-104(%r30) + ldw -184(%r30),%r28 + stw %r28,-108(%r30) + ldw -188(%r30),%r28 + stw %r28,-112(%r30) + ldw -192(%r30),%r28 + stw %r4,-100(%r30) + stw %r28,-116(%r30) + copy %r25,%r28 + copy %r23,%r25 + stw %r19,-32(%r30) + cfi_offset (4, 28) + + .global __syscall_cancel_arch_start +.type __syscall_cancel_arch_start,@function +__syscall_cancel_arch_start: + + ldw 0(%r26),%r20 + stw %r20,-120(%r30) + ldw -120(%r30),%r20 + bb,< %r20,29,1f + ldw -116(%r30),%r21 + ldw -112(%r30),%r22 + copy %r31,%r26 + ldw -108(%r30),%r23 + ldw -104(%r30),%r24 + copy %r19, %r4 + ble 0x100(%sr2, %r0) + + .global __syscall_cancel_arch_end +.type __syscall_cancel_arch_end,@function +__syscall_cancel_arch_end: + + copy %r28, %r20 + copy %r4, %r19 + ldw -148(%r30),%r2 + ldw -100(%r30),%r4 + bv %r0(%r2) + ldo -128(%r30),%r30 +1: + bl __syscall_do_cancel,%r2 + nop + nop +END(__syscall_cancel_arch) +libc_hidden_def (__syscall_cancel_arch) From patchwork Mon Feb 26 21:03:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 129721 Delivered-To: patch@linaro.org Received: by 10.80.172.228 with SMTP id x91csp4292905edc; Mon, 26 Feb 2018 13:07:22 -0800 (PST) X-Google-Smtp-Source: AH8x225wv5TKsFG5h0JkTVJqAPnSYIEgjb22dBaV988oCgeWjZGYCC+wvK6sAgIEPvLkQMtG6nPW X-Received: by 2002:a17:902:7182:: with SMTP id b2-v6mr11745077pll.331.1519679242215; Mon, 26 Feb 2018 13:07:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519679242; cv=none; d=google.com; s=arc-20160816; b=u13xb6KQgDR5sQON0Lcvn731q67FEyJMCYAz6bExtXWnEHvhw4uoBqWhcaTwqt3+Iw WEAHJ/sHnMrZ3pavaWTJh1zhhsO190T7l123raBRqwK6Zy4qZrIXiHgqaB4d1uKpfHfx T3AeTuQkI90SELBWeDgwetF7OqsChIPnkB9L01BQ4Ypv+8hAmFROvb+Y8WmOf2AbrXS/ knFEg+o70ml/D428zFCbYljjliCkFjkY8kh1R9zclJBKr5O12kGYltn+nU70+TwoxJM2 yVMOLn7ECVvhnRhxHt51C3VPFvj5L77Vl1dr+GC19h2ecqmRo4cIS8zE192MA3aY2P2i Kq7w== 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=pGdS7T+J55IdDF3aeWRNChY7iBlsxXKcS9ef8mp1vl0=; b=jgmV/jPW7eQsc/DLoNUYCgbUuceSh0aU6B4qTOuCgh98ICFN0CtUGFjvIYuB6qyVBN lksYb50FYNhNX7K/whlAL/AJIth7gJy9C1EFCWAV3Uw9R8ep/qrRV35vt/X5OcVA3BmP GIP8X1PBrc0aAVOE20p8VqHnmBlnyvh3XYjQeJBoApD/GWSsH+3pXAihX95os/QJK24H 9Lb/RBgP4SnIeIZnHWYEMAFVGQUtFFEDYX0y9nvBa/mzB/cgeNDKJzCvsGzHgwctimEs wYTDNHA4fIKLXI86txuTClVBIDVpxZcqdI8sshl6hBIGbGLMz1GrbGVCxpwTMBqoveT6 DDEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=Ads7qRg3; spf=pass (google.com: domain of libc-alpha-return-90636-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-90636-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 c26si6010813pgn.716.2018.02.26.13.07.21 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Feb 2018 13:07:22 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-90636-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=Ads7qRg3; spf=pass (google.com: domain of libc-alpha-return-90636-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-90636-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=qJ1hjJePwdSBAWDPSRa5Dp6KM1WGJbs ZKsUWqshZuw/IdUI8M2bDSeuxIAHrR1SohgCD/P4ja4fgQxkd2O2gCauFdYqZlLK jF+b0mvEIRuMeV1aea8gic7HZnQ9fY1daJkh9egt3N7/PxOezDoYNj5BMxoV8K9V AZWnhAj9dgl0= 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=H0SMIxWra6sJcQ8yC2ouGN+E6iU=; b=Ads7q Rg3eEcF7VRwPS/X9OX7iRwbZ//AYeWQLoAWvEb+WCL8vhwn1dRtWGDsTv6rbw/Sk 2cckKZ5miBdrVU2uYcfZbc3wHyA68Q7hqaP46OkUJg7CiWWAaAMQExDlyVdKOUka oAjcIeRfuE47AdaMsmBUgg3segmOnHs37GxdjU= Received: (qmail 79821 invoked by alias); 26 Feb 2018 21:04:29 -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 78439 invoked by uid 89); 26 Feb 2018 21:04:19 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.1 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=ecall X-HELO: mail-qt0-f177.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=pGdS7T+J55IdDF3aeWRNChY7iBlsxXKcS9ef8mp1vl0=; b=lNkuGlNSy4Nkxtk4oIP25mUVx7lNpWCOePv48xTqpUbKYRR4SLjXoyH/+4/XVu9aG8 bnpciebjzGuCr176uxoCUdHeaFBT2ll7VUHUJwBSR2Es6XVq4nt8B1J4YDI71R+IDRQB slum5lGDzfFKONCBIbHrmth6gCsojBKD3/TsVAfxJ96yZ2UgagX2ohQCeRWj/GkvCchd NQ7hquDrXOSTlMUCNI/66GCZJoN579TluljBaw7g9zCnIWSmOFd/ZoiJkspxyOaOpRcd +8sDwc/H+qgMpB9TtN6Mz/Zxc0BI3bbWfWKinHd9qH/M+bxqhEerS+ljU64dy03R4Pre PL+g== X-Gm-Message-State: APf1xPD8wA5VEt3vJGAY/35H/+bx9aBT8hW0+DJ0bnKvk4UJSqicXyja 0NHNC4ZSLd9gFCjCnZT0HF4ZILiXgfk= X-Received: by 10.200.34.209 with SMTP id g17mr18745953qta.93.1519679054721; Mon, 26 Feb 2018 13:04:14 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH v2 21/21] nptl: riscv: Fix Race conditions in pthread cancellation (BZ#12683) Date: Mon, 26 Feb 2018 18:03:36 -0300 Message-Id: <1519679016-12241-22-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 riscv modifications required for the BZ#12683. It basically adds the required ucontext_get_pc function. The default syscall_cancel.c should be as expected for RISCV. With GCC 7.3.1 syscall_cancel.c generates the following code: 0000000000000000 <__GI___syscall_cancel_arch>: 0: 8346 mv t1,a7 0000000000000002 <__syscall_cancel_arch_start>: 2: 00052883 lw a7,0(a0) 6: 0048f893 andi a7,a7,4 a: 00089c63 bnez a7,22 <.L0 > e: 88ae mv a7,a1 10: 8532 mv a0,a2 12: 85b6 mv a1,a3 14: 863a mv a2,a4 16: 86be mv a3,a5 18: 8742 mv a4,a6 1a: 879a mv a5,t1 1c: 00000073 ecall 0000000000000020 <__syscall_cancel_arch_end>: 20: 8082 ret 22: 1141 addi sp,sp,-16 24: e406 sd ra,8(sp) 26: 00000097 auipc ra,0x0 2a: 000080e7 jalr ra # 26 <.L0 > Checked with a build for riscv64-linux-gnu with run-built-tests=no. [BZ #12683] * sysdeps/unix/sysv/linux/riscv/sigcontextinfo.h (ucontext_get_pc): New fuction. --- ChangeLog | 4 ++++ sysdeps/unix/sysv/linux/riscv/sigcontextinfo.h | 12 ++++++++++++ 2 files changed, 16 insertions(+) -- 2.7.4 diff --git a/sysdeps/unix/sysv/linux/riscv/sigcontextinfo.h b/sysdeps/unix/sysv/linux/riscv/sigcontextinfo.h index 3ca8a80..5a68ff8 100644 --- a/sysdeps/unix/sysv/linux/riscv/sigcontextinfo.h +++ b/sysdeps/unix/sysv/linux/riscv/sigcontextinfo.h @@ -16,6 +16,10 @@ License along with the GNU C Library. If not, see . */ +#ifndef _SIGCONTEXTINFO_H +#define _SIGCONTEXTINFO_H + +#include #include #define SIGCONTEXT siginfo_t *_si, ucontext_t * @@ -26,3 +30,11 @@ #define CALL_SIGHANDLER(handler, signo, ctx) \ (handler)((signo), SIGCONTEXT_EXTRA_ARGS (ctx)) + +static inline uintptr_t +ucontext_get_pc (const ucontext_t *uc) +{ + return uc->uc_mcontext.__gregs[REG_PC]; +} + +#endif /* _SIGCONTEXTINFO_H */