From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from hall.aurel32.net (hall.aurel32.net [IPv6:2001:bc8:30d7:100::1]) by sourceware.org (Postfix) with ESMTPS id 6376A3858D28 for ; Fri, 8 Apr 2022 16:48:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6376A3858D28 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=aurel32.net Authentication-Results: sourceware.org; spf=none smtp.mailfrom=aurel32.net DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=aurel32.net ; s=202004.hall; h=In-Reply-To:Content-Type:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Content-Transfer-Encoding:From:Reply-To: Subject:Content-ID:Content-Description:X-Debbugs-Cc; bh=KtMrtQy4XuV9XAPclvTc4SfkmTtAwC12AwsUuIyPgyQ=; b=DQdXiUfaGCFJGThKxxZA0eA6mX n5MQxQAGlKvAUf0qyb+d6unKTsZ0XgfqfMkMlbjFXElMeJw3s1LeL2diZHoQPuH5Lj72Asu+5c445 x6zHqEwEFdrAuJdqLSmIE64oe4jOT5cxC1T4kFIQHAG3tys3/IyHoeyKIhtTF1HfZR8eFFMtFlzok O5nmvgTTCaTWlglxkMoVfaLn+hCQz+85U4mfWy6RYYNuTcU1RtSufz/Qzcz3Q1yueWRav79vNXANz kjRNG0a3nvoja6/iz811pO1uIceN9xu77rT7uTmDLua61coypU/0HVImSObbHseZn0zwq99NZXDRS rJwaLglQ==; Received: from [2a01:e34:ec5d:a741:8a4c:7c4e:dc4c:1787] (helo=ohm.rr44.fr) by hall.aurel32.net with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1ncrmK-009iZF-3U; Fri, 08 Apr 2022 18:48:08 +0200 Received: from aurel32 by ohm.rr44.fr with local (Exim 4.95) (envelope-from ) id 1ncrmJ-00HBvb-HW; Fri, 08 Apr 2022 18:48:07 +0200 Date: Fri, 8 Apr 2022 18:48:07 +0200 From: Aurelien Jarno To: Adhemerval Zanella Cc: libc-alpha@sourceware.org, Florian Weimer Subject: Re: [PATCH] nptl: Handle spurious EINTR when thread cancellation is disabled (BZ#29029) Message-ID: Mail-Followup-To: Adhemerval Zanella , libc-alpha@sourceware.org, Florian Weimer References: <20220407132602.1689442-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220407132602.1689442-1-adhemerval.zanella@linaro.org> User-Agent: Mutt/2.1.4 (2021-12-11) X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_SHORT, SPF_HELO_PASS, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 08 Apr 2022 16:48:12 -0000 On 2022-04-07 10:26, Adhemerval Zanella wrote: > Some Linux interfaces never restart after being interrupted by a signal > handler, regardless of the use of SA_RESTART [1]. It means that for > pthread cancellation, if the target thread disables cancellation with > pthread_setcancelstate and calls such interfaces (like poll or select), > it should not see spurious EINTR failures due the internal SIGCANCEL. > > However recent changes made pthread_cancel to always sent the internal > signal, regardless of the target thread cancellation status or type. > To fix it, the previous semantic is restored, where the cancel signal > is only sent if the target thread has cancelation enabled in > asynchronous mode. > > The cancel state and cancel type is moved back to cancelhandling > and atomic operation are used to synchronize between threads. The > patch essentially revert the following commits: > > 8c1c0aae20 nptl: Move cancel type out of cancelhandling > 2b51742531 nptl: Move cancel state out of cancelhandling > 26cfbb7162 nptl: Remove CANCELING_BITMASK > > However I changed the atomic operation to follow the internal C11 > semantic and removed the MACRO usage, it simplifies a bit the > resulting code (and removes another usage of the old atomic macros). > > Checked on x86_64-linux-gnu, i686-linux-gnu, aarch64-linux-gnu, > and powerpc64-linux-gnu. > > [1] https://man7.org/linux/man-pages/man7/signal.7.html > --- > manual/process.texi | 3 +- > nptl/allocatestack.c | 2 - > nptl/cancellation.c | 50 ++++++-- > nptl/cleanup_defer.c | 42 ++++++- > nptl/descr.h | 33 ++++-- > nptl/libc-cleanup.c | 39 ++++++- > nptl/pthread_cancel.c | 106 ++++++++++++----- > nptl/pthread_join_common.c | 7 +- > nptl/pthread_setcancelstate.c | 26 ++++- > nptl/pthread_setcanceltype.c | 31 ++++- > nptl/pthread_testcancel.c | 9 +- > sysdeps/nptl/dl-tls_init_tp.c | 3 - > sysdeps/pthread/Makefile | 1 + > sysdeps/pthread/tst-cancel29.c | 207 +++++++++++++++++++++++++++++++++ > 14 files changed, 473 insertions(+), 86 deletions(-) > create mode 100644 sysdeps/pthread/tst-cancel29.c Thanks a lot for providing a fix so quickly. I confirm the patch works as expected. Tested-by: Aurelien Jarno -- Aurelien Jarno GPG: 4096R/1DDD8C9B aurelien@aurel32.net http://www.aurel32.net