From: Florian Weimer <fweimer@redhat.com>
To: Adhemerval Zanella <adhemerval.zanella@linaro.org>
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: Mon, 11 Apr 2022 16:54:35 +0200 [thread overview]
Message-ID: <87y20bk6vo.fsf@oldenburg.str.redhat.com> (raw)
In-Reply-To: <20220407132602.1689442-1-adhemerval.zanella@linaro.org> (Adhemerval Zanella's message of "Thu, 7 Apr 2022 10:26:02 -0300")
* 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?
> 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?
Maybe add a reference to the pthread_cancel comment explaining the need
for this?
> 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]
Test looks okay to me.
Reviewed-by: Florian Weimer <fweimer@redhat.com>
Thanks,
Florian
next prev parent reply other threads:[~2022-04-11 14:54 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 [this message]
2022-04-14 15:49 ` Adhemerval Zanella
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=87y20bk6vo.fsf@oldenburg.str.redhat.com \
--to=fweimer@redhat.com \
--cc=adhemerval.zanella@linaro.org \
--cc=aurelien@aurel32.net \
--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).