From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oa1-x2a.google.com (mail-oa1-x2a.google.com [IPv6:2001:4860:4864:20::2a]) by sourceware.org (Postfix) with ESMTPS id 07F663850201 for ; Wed, 13 Jul 2022 12:57:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 07F663850201 Received: by mail-oa1-x2a.google.com with SMTP id 586e51a60fabf-10bd4812c29so13871494fac.11 for ; Wed, 13 Jul 2022 05:57:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:organization:in-reply-to :content-transfer-encoding; bh=/Up956aPvP6Opij+aGMwfITHssL/T+FPjm0UESGeQjI=; b=NFXaEhPGfousurW/DU5nE5CTjfbxCka94uUaCTyRv2vBRecvg+B1kLDD9ZpHbtELdm AJc4R+LyL+f/aNyweu3jr864qd24u/44VdsFZgD5vdedTu3D7PdeBPLMJSrHpLXMXpka zmsYr1Yn9WcphlJKNK/w4QMIHb/Tnxz9emgql3BfDU490esAHngOoYY/aoBGjqjAFaLI JgX48f9itvEe3VeNtFWk9cpxRjn0TzzAJcy7q6imKGwcfrDrg/qADhuRzP1zbN2+CSRc b4H4OW2CNQuQNjcFQpKspkuvEEFL2zYYsIa083hAbzAEojaU4F02ji215TxOCdj1W0zB +0mw== X-Gm-Message-State: AJIora+kOWU8DJtBNczme3HRkfCR6ItarI7Vkd+ZaAuOMsNJ3qHjsEQp ejVuP8U3vMeve/7MO3YmqM2/og== X-Google-Smtp-Source: AGRyM1tp0s3c0VvEutLNKv4Vb/XMQTZIJNk9D5pRHtubb14xXcJZGAieYH8syr9J6cZgCTjhvNpysA== X-Received: by 2002:a05:6871:b2a:b0:10c:4b7f:423b with SMTP id fq42-20020a0568710b2a00b0010c4b7f423bmr4340900oab.228.1657717048332; Wed, 13 Jul 2022 05:57:28 -0700 (PDT) Received: from ?IPV6:2804:431:c7ca:19c3:4427:c171:4fa9:c3d9? ([2804:431:c7ca:19c3:4427:c171:4fa9:c3d9]) by smtp.gmail.com with ESMTPSA id em31-20020a0568705b9f00b000f5eb6b409bsm5810087oab.45.2022.07.13.05.57.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 13 Jul 2022 05:57:27 -0700 (PDT) Message-ID: <5eb7357d-9c85-4831-9d2f-79461328452b@linaro.org> Date: Wed, 13 Jul 2022 09:57:24 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.0.2 Subject: Re: [PATCH v2] nptl: Handle spurious EINTR when thread cancellation is disabled (BZ#29029) Content-Language: en-US To: Noah Goldstein Cc: GNU C Library , Florian Weimer , Aurelien Jarno References: <20220414154947.2187880-1-adhemerval.zanella@linaro.org> From: Adhemerval Zanella Netto Organization: Linaro In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: Wed, 13 Jul 2022 12:57:30 -0000 On 12/07/22 18:27, Noah Goldstein wrote: >> diff --git a/nptl/cleanup_defer.c b/nptl/cleanup_defer.c >> index f8181a40e8..eb0bc77740 100644 >> --- a/nptl/cleanup_defer.c >> +++ b/nptl/cleanup_defer.c >> @@ -30,9 +30,22 @@ ___pthread_register_cancel_defer (__pthread_unwind_buf_t *buf) >> ibuf->priv.data.prev = THREAD_GETMEM (self, cleanup_jmp_buf); >> ibuf->priv.data.cleanup = THREAD_GETMEM (self, cleanup); >> >> - /* Disable asynchronous cancellation for now. */ >> - ibuf->priv.data.canceltype = THREAD_GETMEM (self, canceltype); >> - THREAD_SETMEM (self, canceltype, PTHREAD_CANCEL_DEFERRED); >> + int cancelhandling = atomic_load_relaxed (&self->cancelhandling); >> + if (__glibc_unlikely (cancelhandling & CANCELTYPE_BITMASK)) >> + { >> + int newval; >> + do >> + { >> + newval = cancelhandling & ~CANCELTYPE_BITMASK; >> + } >> + while (!atomic_compare_exchange_weak_acquire (&self->cancelhandling, >> + &cancelhandling, >> + newval)); >> + } >> + >> + ibuf->priv.data.canceltype = (cancelhandling & CANCELTYPE_BITMASK >> + ? PTHREAD_CANCEL_ASYNCHRONOUS >> + : PTHREAD_CANCEL_DEFERRED); >> >> /* Store the new cleanup handler info. */ >> THREAD_SETMEM (self, cleanup_jmp_buf, (struct pthread_unwind_buf *) buf); >> @@ -54,9 +67,26 @@ ___pthread_unregister_cancel_restore (__pthread_unwind_buf_t *buf) >> >> THREAD_SETMEM (self, cleanup_jmp_buf, ibuf->priv.data.prev); >> >> - THREAD_SETMEM (self, canceltype, ibuf->priv.data.canceltype); >> - if (ibuf->priv.data.canceltype == PTHREAD_CANCEL_ASYNCHRONOUS) >> - __pthread_testcancel (); >> + if (ibuf->priv.data.canceltype == PTHREAD_CANCEL_DEFERRED) >> + return; >> + >> + int cancelhandling = atomic_load_relaxed (&self->cancelhandling); >> + if (cancelhandling & CANCELTYPE_BITMASK) > > should this be: > if((cancelhandling & CANCELTYPE_BITMASK) == 0) > ? Yes, I will fix it.