From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qk1-x72a.google.com (mail-qk1-x72a.google.com [IPv6:2607:f8b0:4864:20::72a]) by sourceware.org (Postfix) with ESMTPS id B84303861838 for ; Tue, 15 Jun 2021 23:33:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B84303861838 Received: by mail-qk1-x72a.google.com with SMTP id k11so780131qkk.1 for ; Tue, 15 Jun 2021 16:33:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=UiDpLSAvEeDUF31LunOAbHlcqFgj5nMFxy+De88h4Pc=; b=Ax64LwnqMoMa4IY+etBGMXOJaRYcEEFyB9XVVWehWUYfhPHoGANEX31yq+aONseo6a X2+ncUAy25ZQm+UDAxqqBal8FuGzzAbdO+BJPTk7gMFV1uor44tg3zrus1Mt1YtSLN1Q L1suhhaQH3aMltzN+qPP8UWbhzyhxwIjtoj5B5IuU6O30Qb0PF6dH/s4Ay1xKEdKAmfp uDes7qbaQn3wziK6jbEnFhnKiBmCixtIk0Bh6aOddz3lQcfVeBHvJ1GEb7Loi3ATUw5S LG411A/+2XunJnTHPgzoqOkIlifSuCzF4BCMEExLtj6jzUd6nA351nYxfQl4dX98RZdK TMkQ== X-Gm-Message-State: AOAM530c4c8+y9tVq9lVw5/uACa59Wc4aCmvmgVO+tNBDRCY92gaZauO IL7X8xtyLLfqinyZ85IKBaF8O+n/TwHZSw== X-Google-Smtp-Source: ABdhPJyvF6Wgvom5ofe8k7OBQvXvYQ6NDzAjzfrbDMbvVwkI5cnCrpE1/mPYyAPdO1TQdXMzwIIPIQ== X-Received: by 2002:a37:a793:: with SMTP id q141mr2199212qke.107.1623800004175; Tue, 15 Jun 2021 16:33:24 -0700 (PDT) Received: from [192.168.1.4] ([177.194.59.218]) by smtp.gmail.com with ESMTPSA id d18sm400405qkg.129.2021.06.15.16.33.23 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 15 Jun 2021 16:33:23 -0700 (PDT) Subject: Re: [PATCH 07/11] nptl: Remove CANCELING_BITMASK To: Florian Weimer , Adhemerval Zanella via Libc-alpha References: <20210526165728.1772546-1-adhemerval.zanella@linaro.org> <20210526165728.1772546-8-adhemerval.zanella@linaro.org> <878s3ag4tc.fsf@oldenburg.str.redhat.com> From: Adhemerval Zanella Message-ID: <198b0728-f255-0fc6-6eed-64802e8e5157@linaro.org> Date: Tue, 15 Jun 2021 20:33:21 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: <878s3ag4tc.fsf@oldenburg.str.redhat.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Tue, 15 Jun 2021 23:33:26 -0000 On 15/06/2021 19:07, Florian Weimer wrote: > * Adhemerval Zanella via Libc-alpha: > >> The CANCELING_BITMASK is used as an optimization to avoid sending >> the signal when pthread_cancel is called in a concurrent manner. >> >> This requires then to put both the cancellation state and type on >> a shared state (cancelhandling), since 'pthread_cancel' checks >> whether cancellation is enabled and asynchrnous to either cancel >> itself of sending the signal. >> >> It also requires handle the CANCELING_BITMASK on >> __pthread_disable_asynccancel, however this is incurs in the same >> issues described on BZ#12683: the cancellation is acting even *after* >> the syscalls returns with user visible side-effects. >> >> This patch removes this optimization and simplifies the pthread >> cancellation implementation: pthread_cancel now first check if >> cancellation is already pending and if not always send a signal >> if the target is not itself. The SIGCANCEL handler is also simpified >> since there is not need to setup a CAS loop. >> >> It also alows to move both the cancellation state and mode out of >> 'cancelhadling' (it is done in subsequent patches). > > It looks like this causes sporadic failures in nptl/tst-sem16 because > sem_wait fails with EINTR, revealing that cancellation is implemented > using a signal (something that must not be visible according to POSIX). > > This was not a problem before because pthread_cancel sent the signal > only when asynchronous cancellation was enabled. > > We either have to revert this, or push forward with the transition so > that we can install the SIGCANCEL handler with SA_RESTART. Indeed now that SIGCANCEL is always sent by pthread_cancel we must install the signal handle with SA_RESTART, the signal handle will either act on cancellation or it should be not visible by the application. I don't think there is a need to revert this change, running nptl/tst-sem16 with SA_RESTART I don't see the regression anymore with multiple thousands runs.