From patchwork Tue Sep 4 20:45:49 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: 145963 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp4124914ljw; Tue, 4 Sep 2018 13:46:41 -0700 (PDT) X-Google-Smtp-Source: ANB0Vda2Okv8IjfUqzk2XYXj32YsGGQWJiJyF+V44aIyEY1BQxILjyBFGGkdRivTI2RbTNn7SkRK X-Received: by 2002:a17:902:6b83:: with SMTP id p3-v6mr35665424plk.133.1536094001573; Tue, 04 Sep 2018 13:46:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536094001; cv=none; d=google.com; s=arc-20160816; b=F+mgLhjy6sGFnKhrsSM3OO2SHZlXzHRh8QrL4pkSFYFJ1o+w3ypKtsz4YYJTtrUgxl fw490ps5le+FzoUt+MIuhE8iGXR30VBn2fLwLx0N1hm0zIFuhr5K+3Y3Z9FTJrgy8qnc JhRixg0R/HsbF9qjBNsoULmTpoPkXi4aOwdgiLMcg7zRU3OQahCe8ms8YBhOMWUX0BlN mX9alsnuXRvWg6UnalkNYuk03xb9KazbwkDEIDPW4+WrctHXdqBI8Rz+K0mz/+z5AGvq SXRs49ehMiuszf6ce1R1VQiyiSHYnOr041P1BrFL6W5/ZKC2HO5yqPQGseGrhSHWpvrm vxSQ== 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 :dkim-signature: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=sHwaooOHDVgMVCIgf5T3xOkXrhPOlcRRg5pvWasicX4=; b=hih+qyP6lH4M6MlHp2iFQF2ZJVUtGHDBD6mJKTEQNIpEA8OSs+Ec/tOvdByrWNR+0U MtejZaib7eK1pyzvIfL+2mZpY/T2vdyjn+6WdZRONEhKOICVxve7DStIHHaUEFseJdLt 6FDQ2LOsszy8O43mvvLAi2zRsew30p9Ju0aUtDAhNEJWonmknroCxTaC0lOFQbkG7ztq irgc8X3V2Tvw+YlYY/X0MmgcIRDrcglC6MAUyZcvLdHDnTg66IT+YW02kM3tAgpmnuun 1LGOhcP/3O13kBQuQ87rw3hVaWcKOiOnrZHCD58gx171dYdCzwJFEPa9tjGthO8XHjqu h3Qw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=szORMA4E; dkim=pass header.i=@linaro.org header.s=google header.b=QPRF5VID; spf=pass (google.com: domain of libc-alpha-return-95670-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="libc-alpha-return-95670-patch=linaro.org@sourceware.org"; dmarc=pass (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 m14-v6si22680135pgc.368.2018.09.04.13.46.41 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Sep 2018 13:46:41 -0700 (PDT) Received-SPF: pass (google.com: domain of libc-alpha-return-95670-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=szORMA4E; dkim=pass header.i=@linaro.org header.s=google header.b=QPRF5VID; spf=pass (google.com: domain of libc-alpha-return-95670-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="libc-alpha-return-95670-patch=linaro.org@sourceware.org"; dmarc=pass (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=n55jTf1gjfFBesBZdhgqOQXQPG0/S1k XjbVS33qhfMUtfMMlyWnXpEJ9fZWun7dmZKSVByeWs4whfv5Rqnx5FYlA2xGB6Nv Vs1ez/UJSmvwZGexZdccAD6FA8xMYqFc6wskxTR6TEjbAHCgWfl6urBn0tsMgbbX UM9lyBh0/pxk= 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=FBJi2oDFWGZLoeXbyfd9w+be9v4=; b=szORM A4EqoVS/2xOkzG77A5XpFA95xnPPfXdm2YSlCD8604Sc4ez6ccFHpTBdBlgiuM5m 2ccD2gAh/9+YbColNxCUWYeoVYUv5FaMwpYpKnXnJyB8cHcBs9pXkHbignN9Bh2G PgP4gQeCqhwDRsDQbrKnkRmb4FAuSS20cVFfs4= Received: (qmail 34145 invoked by alias); 4 Sep 2018 20:46: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 33982 invoked by uid 89); 4 Sep 2018 20:46:08 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SEM_URI, SEM_URIRED, SPF_PASS autolearn=ham version=3.3.2 spammy=blocked, cancelled, sk:arm-lin, sk:armlin X-HELO: mail-qk1-f195.google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=sHwaooOHDVgMVCIgf5T3xOkXrhPOlcRRg5pvWasicX4=; b=QPRF5VIDNZarI86wpZEzd9B9aCSXwVVnEEai7F+Ko1HzCa3a0V/SkGAYLSZyeZKTpC DIP3EgUgBCULqrzU2ykyDXisTA3EIoHAtayXZn5SbwggfHeYOFSEqDzabS6mQ+++EQPU NG4E+uPPcz0kLk0f/XUjGjYaXG7im80NGBs+4= Return-Path: From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Adhemerval Zanella Subject: [PATCH 3/7] nptl: Fix testcases for new pthread cancellation mechanism Date: Tue, 4 Sep 2018 17:45:49 -0300 Message-Id: <20180904204553.6971-4-adhemerval.zanella@linaro.org> In-Reply-To: <20180904204553.6971-1-adhemerval.zanella@linaro.org> References: <20180904204553.6971-1-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 changes the tst-backtrace{5,6} to ignore the cancellable wrappers. 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): Avoid cancellable wrappers in backtrace analysis. * nptl/tst-cancel4.c (tf_write): Handle cancelled syscall with side-effects. (tf_send): Likewise. --- ChangeLog | 6 ++++++ debug/tst-backtrace5.c | 19 ++++++++++--------- nptl/tst-cancel4.c | 8 ++++++++ 3 files changed, 24 insertions(+), 9 deletions(-) -- 2.17.1 diff --git a/debug/tst-backtrace5.c b/debug/tst-backtrace5.c index 0e6fb1a024..dad741e12a 100644 --- a/debug/tst-backtrace5.c +++ b/debug/tst-backtrace5.c @@ -69,17 +69,18 @@ handle_signal (int signum) FAIL (); return; } - /* Do not check name for signal trampoline. */ - i = 2; - if (!match (symbols[i++], "read")) + + /* Do not check name for signal trampoline or cancellable syscall + wrappers (__syscall_cancel*). */ + for (; i < n - 1; i++) + if (match (symbols[i], "read")) + break; + if (i == n - 1) { - /* Perhaps symbols[2] is __kernel_vsyscall? */ - if (!match (symbols[i++], "read")) - { - FAIL (); - return; - } + FAIL (); + return; } + for (; i < n - 1; i++) if (!match (symbols[i], "fn")) { diff --git a/nptl/tst-cancel4.c b/nptl/tst-cancel4.c index 05325385b1..45b3d43c3b 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); + /* The 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);