* [PATCH] nptl: Fix __libc_cleanup_pop_restore asynchronous restore (BZ#29214)
@ 2022-05-31 20:28 Adhemerval Zanella
2022-06-07 10:27 ` Andreas Schwab
0 siblings, 1 reply; 4+ messages in thread
From: Adhemerval Zanella @ 2022-05-31 20:28 UTC (permalink / raw)
To: libc-alpha
This was due a wrong revert done on 404656009b459658.
Checked on x86_64-linux-gnu.
---
nptl/libc-cleanup.c | 3 +-
sysdeps/pthread/Makefile | 1 +
sysdeps/pthread/tst-cancel30.c | 75 ++++++++++++++++++++++++++++++++++
3 files changed, 78 insertions(+), 1 deletion(-)
create mode 100644 sysdeps/pthread/tst-cancel30.c
diff --git a/nptl/libc-cleanup.c b/nptl/libc-cleanup.c
index c4a83591bf..2ce59388d4 100644
--- a/nptl/libc-cleanup.c
+++ b/nptl/libc-cleanup.c
@@ -57,7 +57,8 @@ __libc_cleanup_pop_restore (struct _pthread_cleanup_buffer *buffer)
THREAD_SETMEM (self, cleanup, buffer->__prev);
int cancelhandling = atomic_load_relaxed (&self->cancelhandling);
- if (cancelhandling & CANCELTYPE_BITMASK)
+ if (buffer->__canceltype != PTHREAD_CANCEL_DEFERRED
+ && (cancelhandling & CANCELTYPE_BITMASK) == 0)
{
int newval;
do
diff --git a/sysdeps/pthread/Makefile b/sysdeps/pthread/Makefile
index 8cebe7a784..7d1670da87 100644
--- a/sysdeps/pthread/Makefile
+++ b/sysdeps/pthread/Makefile
@@ -126,6 +126,7 @@ tests += tst-cnd-basic tst-mtx-trylock tst-cnd-broadcast \
tst-pthread-raise-blocked-self \
tst-pthread_kill-exited \
tst-pthread_kill-exiting \
+ tst-cancel30 \
# tests
tests-time64 += \
diff --git a/sysdeps/pthread/tst-cancel30.c b/sysdeps/pthread/tst-cancel30.c
new file mode 100644
index 0000000000..ef3f187e71
--- /dev/null
+++ b/sysdeps/pthread/tst-cancel30.c
@@ -0,0 +1,75 @@
+/* Check if printf like functions does not disable asynchronous cancellation
+ mode (BZ#29214).
+
+ Copyright (C) 2022 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include <support/check.h>
+#include <support/xthread.h>
+#include <support/xstdio.h>
+
+static pthread_barrier_t b;
+
+static void *
+tf (void *arg)
+{
+ int old;
+
+ TEST_COMPARE (pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, NULL), 0);
+
+ TEST_COMPARE (pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, &old), 0);
+ TEST_COMPARE (old, PTHREAD_CANCEL_ASYNCHRONOUS);
+
+ /* Check if internal lock cleanup routines restore the cancellation type
+ correctly. */
+ printf ("...\n");
+ TEST_COMPARE (pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, &old), 0);
+ TEST_COMPARE (old, PTHREAD_CANCEL_ASYNCHRONOUS);
+
+ xpthread_barrier_wait (&b);
+
+ /* Wait indefinitely for cancellation, which only works if asynchronous
+ cancellation is enabled. */
+#ifdef SYS_futex
+ syscall (SYS_futex, &(int){0}, FUTEX_WAIT_PRIVATE, 0, NULL, NULL, 0);
+#else
+ for (;;);
+#endif
+
+ return 0;
+}
+
+static int
+do_test (void)
+{
+ xpthread_barrier_init (&b, NULL, 2);
+
+ pthread_t th = xpthread_create (NULL, tf, NULL);
+
+ xpthread_barrier_wait (&b);
+
+ xpthread_cancel (th);
+
+ void *status = xpthread_join (th);
+ TEST_VERIFY (status == PTHREAD_CANCELED);
+
+ return 0;
+}
+
+/* There is no need to wait full TIMEOUT if asynchronous is not working. */
+#define TIMEOUT 3
+#include <support/test-driver.c>
--
2.34.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] nptl: Fix __libc_cleanup_pop_restore asynchronous restore (BZ#29214)
2022-05-31 20:28 [PATCH] nptl: Fix __libc_cleanup_pop_restore asynchronous restore (BZ#29214) Adhemerval Zanella
@ 2022-06-07 10:27 ` Andreas Schwab
2022-06-07 11:20 ` Florian Weimer
0 siblings, 1 reply; 4+ messages in thread
From: Andreas Schwab @ 2022-06-07 10:27 UTC (permalink / raw)
To: Adhemerval Zanella via Libc-alpha
On Mai 31 2022, Adhemerval Zanella via Libc-alpha wrote:
> diff --git a/sysdeps/pthread/tst-cancel30.c b/sysdeps/pthread/tst-cancel30.c
> new file mode 100644
> index 0000000000..ef3f187e71
> --- /dev/null
> +++ b/sysdeps/pthread/tst-cancel30.c
> @@ -0,0 +1,75 @@
> +/* Check if printf like functions does not disable asynchronous cancellation
> + mode (BZ#29214).
> +
> + Copyright (C) 2022 Free Software Foundation, Inc.
> + This file is part of the GNU C Library.
> +
> + The GNU C Library is free software; you can redistribute it and/or
> + modify it under the terms of the GNU Lesser General Public
> + License as published by the Free Software Foundation; either
> + version 2.1 of the License, or (at your option) any later version.
> +
> + The GNU C Library is distributed in the hope that it will be useful,
> + but WITHOUT ANY WARRANTY; without even the implied warranty of
> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> + Lesser General Public License for more details.
> +
> + You should have received a copy of the GNU Lesser General Public
> + License along with the GNU C Library; if not, see
> + <https://www.gnu.org/licenses/>. */
> +
> +#include <support/check.h>
> +#include <support/xthread.h>
> +#include <support/xstdio.h>
> +
> +static pthread_barrier_t b;
> +
> +static void *
> +tf (void *arg)
> +{
> + int old;
> +
> + TEST_COMPARE (pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, NULL), 0);
> +
> + TEST_COMPARE (pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, &old), 0);
> + TEST_COMPARE (old, PTHREAD_CANCEL_ASYNCHRONOUS);
> +
> + /* Check if internal lock cleanup routines restore the cancellation type
> + correctly. */
> + printf ("...\n");
> + TEST_COMPARE (pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, &old), 0);
> + TEST_COMPARE (old, PTHREAD_CANCEL_ASYNCHRONOUS);
> +
> + xpthread_barrier_wait (&b);
> +
> + /* Wait indefinitely for cancellation, which only works if asynchronous
> + cancellation is enabled. */
> +#ifdef SYS_futex
> + syscall (SYS_futex, &(int){0}, FUTEX_WAIT_PRIVATE, 0, NULL, NULL, 0);
> +#else
> + for (;;);
> +#endif
Should that handle SYS_futex_time64?
--
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE 1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] nptl: Fix __libc_cleanup_pop_restore asynchronous restore (BZ#29214)
2022-06-07 10:27 ` Andreas Schwab
@ 2022-06-07 11:20 ` Florian Weimer
2022-06-07 12:47 ` Adhemerval Zanella
0 siblings, 1 reply; 4+ messages in thread
From: Florian Weimer @ 2022-06-07 11:20 UTC (permalink / raw)
To: Andreas Schwab via Libc-alpha; +Cc: Andreas Schwab
* Andreas Schwab via Libc-alpha:
>> + /* Wait indefinitely for cancellation, which only works if asynchronous
>> + cancellation is enabled. */
>> +#ifdef SYS_futex
>> + syscall (SYS_futex, &(int){0}, FUTEX_WAIT_PRIVATE, 0, NULL, NULL, 0);
>> +#else
>> + for (;;);
>> +#endif
>
> Should that handle SYS_futex_time64?
syscall (SYS_pause) should be architecture-agnostic, and like any
syscall-invoked system call, it's not a cancellation point.
Thanks,
Florian
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] nptl: Fix __libc_cleanup_pop_restore asynchronous restore (BZ#29214)
2022-06-07 11:20 ` Florian Weimer
@ 2022-06-07 12:47 ` Adhemerval Zanella
0 siblings, 0 replies; 4+ messages in thread
From: Adhemerval Zanella @ 2022-06-07 12:47 UTC (permalink / raw)
To: Florian Weimer, Andreas Schwab via Libc-alpha; +Cc: Andreas Schwab
On 07/06/2022 08:20, Florian Weimer via Libc-alpha wrote:
> * Andreas Schwab via Libc-alpha:
>
>>> + /* Wait indefinitely for cancellation, which only works if asynchronous
>>> + cancellation is enabled. */
>>> +#ifdef SYS_futex
>>> + syscall (SYS_futex, &(int){0}, FUTEX_WAIT_PRIVATE, 0, NULL, NULL, 0);
>>> +#else
>>> + for (;;);
>>> +#endif
>>
>> Should that handle SYS_futex_time64?
Indeed, riscv32 for instance is using the loop instead.
>
> syscall (SYS_pause) should be architecture-agnostic, and like any
> syscall-invoked system call, it's not a cancellation point.
It is not in unfortunately:
$ python3 ./sysdeps/unix/sysv/linux/glibcsyscalls.py query-syscall pause
pause:
defined: arm hppa i386 m68k microblaze mips/mips32 mips/mips64/n32 mips/mips64/n64 powerpc/powerpc32 powerpc/powerpc64 s390/s390-32 s390/s390-64 sh sparc/s
parc32 sparc/sparc64 x86_64/64 x86_64/x32
undefined: aarch64 alpha arc csky ia64 nios2 or1k riscv/rv32 riscv/rv64
So we will need to use ppoll and also ppoll_time64. I think it would
be better to add a libspport to abstract and use glibc internal definition
that handle the ppoll/poll_time64 (since there is no need to handle the
timeout here).
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-06-07 12:47 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-31 20:28 [PATCH] nptl: Fix __libc_cleanup_pop_restore asynchronous restore (BZ#29214) Adhemerval Zanella
2022-06-07 10:27 ` Andreas Schwab
2022-06-07 11:20 ` Florian Weimer
2022-06-07 12:47 ` Adhemerval Zanella
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).