From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
To: Florian Weimer <fweimer@redhat.com>
Cc: libc-alpha@sourceware.org, Aurelien Jarno <aurelien@aurel32.net>
Subject: Re: [PATCH] nptl: Handle spurious EINTR when thread cancellation is disabled (BZ#29029)
Date: Thu, 14 Apr 2022 12:49:58 -0300 [thread overview]
Message-ID: <44695f1d-0a88-9557-9ffc-673b49b0c3b3@linaro.org> (raw)
In-Reply-To: <87y20bk6vo.fsf@oldenburg.str.redhat.com>
On 11/04/2022 11:54, Florian Weimer wrote:
> * Adhemerval Zanella:
>
>> @@ -56,10 +63,29 @@ __pthread_disable_asynccancel (int oldtype)
>> {
>
>> + /* 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 (__glibc_unlikely ((newval & (CANCELING_BITMASK | CANCELED_BITMASK))
>> + == CANCELING_BITMASK))
>> + {
>> + futex_wait_simple ((unsigned int *) &self->cancelhandling, newval,
>> + FUTEX_PRIVATE);
>> + newval = atomic_load_relaxed (&self->cancelhandling);
>> + }
>
> Is there no FUTEX_WAKE in the patch because futex_wait_simple already
> fails with EINTR once the signal finally arrives?
My understanding is it tries to handle interrupted syscall with side
effects on thread with async cancellation enabled where pthread_cancel
was issued, but SIGCANCEL has not yet arrived. In this case the
cancellation handler will handle thread cancellation.
This restores the previous semantic, which I think it not fully correct
(the old BZ#12683).
>
>> diff --git a/nptl/descr.h b/nptl/descr.h
>> index ea8aca08e6..58e3849a63 100644
>> --- a/nptl/descr.h
>> +++ b/nptl/descr.h
>> @@ -279,6 +279,15 @@ struct pthread
>>
>> /* Flags determining processing of cancellation. */
>> int cancelhandling;
>> + /* Bit set if cancellation is disabled. */
>> +#define CANCELSTATE_BIT 0
>> +#define CANCELSTATE_BITMASK (0x01 << CANCELSTATE_BIT)
>> + /* 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
>> #define CANCELED_BITMASK (0x01 << CANCELED_BIT)
>
> 0x01 looks like a shifted bit pattern. Maybe a plain 1 is enough?
Ack.
>
> Maybe add a reference to the pthread_cancel comment explaining the need
> for this?
Right, I will extend the comment below to add why we need both the
cancellation type and mode to be modified atomically along cancellation
status.
>
>> diff --git a/nptl/pthread_cancel.c b/nptl/pthread_cancel.c
>> index 7524c7ce4d..5aad1bab78 100644
>> --- a/nptl/pthread_cancel.c
>> +++ b/nptl/pthread_cancel.c
>
>> @@ -92,29 +103,66 @@ __pthread_cancel (pthread_t th)
>
>> + /* Some syscalls are never restarted after being interrupted by a signal
>> + handler, regardless of the use of SA_RESTART (they always fail with
>> + EINTR). So pthread_cancel can not send SIGCANCEL unless the cancellation
>
> typo: can[]not
>
>> + is enabled and set as asynchronous (in this case the cancellation will
>> + be acted in the cancellation handler instead by the syscall wrapper).
>> + Otherwise the target thread is set as 'cancelling' (CANCELING_BITMASK)
>> + by atomically set 'cancelhandling' and the cancelation will be acted
>
> typo: atomically set[ting]
>
>> + uppon on next cancellation entrypoing in the target thread. */
>
> typos: up[]on, cancellation [point]
Ack.
>
> Test looks okay to me.
>
> Reviewed-by: Florian Weimer <fweimer@redhat.com>
>
> Thanks,
> Florian
>
next prev parent reply other threads:[~2022-04-14 15:50 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-07 13:26 Adhemerval Zanella
2022-04-08 16:48 ` Aurelien Jarno
2022-04-11 14:54 ` Florian Weimer
2022-04-14 15:49 ` Adhemerval Zanella [this message]
2022-04-14 15:55 ` Florian Weimer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=44695f1d-0a88-9557-9ffc-673b49b0c3b3@linaro.org \
--to=adhemerval.zanella@linaro.org \
--cc=aurelien@aurel32.net \
--cc=fweimer@redhat.com \
--cc=libc-alpha@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).