From patchwork Mon Apr 10 19:58:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 67577 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B0A13385B527 for ; Mon, 10 Apr 2023 20:00:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B0A13385B527 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1681156826; bh=NBvyRT0FIFiY4IeHSSzNRDmxGdNoFqmST9xLLCl5Xt8=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=I6miKHXHUDB4HO1BOITCOBlFi6vKmo9+quGn9jYUYjiNsMaLG4gGnyr26db8rpTUp 7NjzCPpsxMV3D4tqmKmOCv1RqbGag66pIKYrBNs6VTbu83xDknXcUQfV0SU08f1Ro/ 0brgOw4WIsrlKvwYviWUw4SJfTDx5rrp5VbUbAzs= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x332.google.com (mail-ot1-x332.google.com [IPv6:2607:f8b0:4864:20::332]) by sourceware.org (Postfix) with ESMTPS id 597AF3858C5E for ; Mon, 10 Apr 2023 19:59:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 597AF3858C5E Received: by mail-ot1-x332.google.com with SMTP id bu14-20020a0568300d0e00b0069fab3f4cafso2819424otb.9 for ; Mon, 10 Apr 2023 12:59:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681156755; x=1683748755; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NBvyRT0FIFiY4IeHSSzNRDmxGdNoFqmST9xLLCl5Xt8=; b=6g20tuz30j+01VEqC5+ThRbSFHjrKZLBhD2EUnbJhbFLKIzOZDfX7AtqCQ9I4H5r6W vIp5RTqBbzoL0jhLHsKnrsn1F7cBvTKZUEErFKs50b1gg5XZdYCCgh+Ykk+xl3JVtcEH Ybd0G4kSXrzjoLRvQjrmu5GFtKR6+57eIx993AN7xq0p+sxX7kGE6oRE5yTbNhZPsQMp D5xLiWkD8EPGcPvm7jd2Mlq4fIEn5FHqHKyg5t0AljyPI8Ojsr1H9kpFImxyMiEoJszj bIfYwI3XQrFnYNrVPHlkfk/WATh0cT8jAgIMZKQ7jZlpDrp13f1diEs1pljdRi6bdBpy oBNw== X-Gm-Message-State: AAQBX9f9dL/ZzMAgFyTvMlpI8hIYlA9tQDu1lbBuN4mEbk08o9BBaNzQ qvdFLRdWdCPtUjY1RQgMV5CR3X6lHa/UOe6aycZyJA== X-Google-Smtp-Source: AKy350ZtmT7zOle/S5c9uDkjX6qsPifu29NVQGbnHsdkG+Ji+zGTc2d9jGpjCiTQxmZNkmk/oNWFLw== X-Received: by 2002:a9d:7a56:0:b0:69f:6620:8702 with SMTP id z22-20020a9d7a56000000b0069f66208702mr5300876otm.27.1681156753768; Mon, 10 Apr 2023 12:59:13 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c2:55a1:d59a:609a:284:6ed]) by smtp.gmail.com with ESMTPSA id r7-20020a9d7507000000b006a30260ccfdsm4673293otk.11.2023.04.10.12.59.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Apr 2023 12:59:12 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v5 01/22] nptl: Fix Race conditions in pthread cancellation [BZ#12683] Date: Mon, 10 Apr 2023 16:58:46 -0300 Message-Id: <20230410195907.4123869-2-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230410195907.4123869-1-adhemerval.zanella@linaro.org> References: <20230410195907.4123869-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" The current racy approach is to enable asynchronous cancellation before making the syscall and restore the previous cancellation type once the syscall returns, and check if cancellation has happen during the cancellation entrypoint. As described in BZ#12683, this approach shows 2 problems: 1. Cancellation can act after the syscall has returned from the kernel, but before userspace saves the return value. It might result in a resource leak if the syscall allocated a resource or a side effect (partial read/write), and there is no way to program handle it with cancellation handlers. 2. If a signal is handled while the thread is blocked at a cancellable syscall, the entire signal handler runs with asynchronous cancellation enabled. This can lead to issues if the signal handler call functions which are async-signal-safe but not async-cancel-safe. For the cancellation to work correctly, there are 5 points at which the cancellation signal could arrive: 1. Before the final "testcancel" and before the syscall is made. 2. Between the "testcancel" and the syscall. 3. While the syscall is blocked and no side effects have yet taken place. 4. While the syscall is blocked but with some side effects already having taken place (e.g. a partial read or write). 5. After the syscall has returned. And libc wants to act on cancellation in cases 1, 2, and 3 but not in cases 4 or 5. For the 4 and 5 cases, the cancellation will eventually happen in the next cancellable entrypoint without any further external event. The proposed solution for each case is: 1. Do a conditional branch based on whether the thread has received a cancellation request; 2. It can be caught by the signal handler determining that the saved program counter (from the ucontext_t) is in some address range beginning just before the "testcancel" and ending with the syscall instruction. 3. In this case, except for certain syscalls that ALWAYS fail with EINTR even for non-interrupting signals, the kernel will reset the program counter to point at the syscall instruction during signal handling, so that the syscall is restarted when the signal handler returns. So, from the signal handler's standpoint, this looks the same as case 2, and thus it's taken care of. 4. For syscalls with side-effects, the kernel cannot restart the syscall; when it's interrupted by a signal, the kernel must cause the syscall to return with whatever partial result is obtained (e.g. partial read or write). 5. The saved program counter points just after the syscall instruction, so the signal handler won't act on cancellation. This is similar to 4. since the program counter is past the syscall instruction. So The proposed fixes are: 1. Remove the enable_asynccancel/disable_asynccancel function usage in cancellable syscall definition and instead make them call a common symbol that will check if cancellation is enabled (__syscall_cancel at nptl/cancellation.c), call the arch-specific cancellable entry-point (__syscall_cancel_arch), and cancel the thread when required. 2. Provide an arch-specific generic system call wrapper function that contains global markers. These markers will be used in SIGCANCEL signal handler to check if the interruption has been called in a valid syscall and if the syscalls has side-effects. A reference implementation sysdeps/unix/sysv/linux/syscall_cancel.c is provided. However, the markers may not be set on correct expected places depending on how INTERNAL_SYSCALL_NCS is implemented by the architecture. It is expected that all architectures add an arch-specific implementation. 3. Rewrite SIGCANCEL asynchronous handler to check for both canceling type and if current IP from signal handler falls between the global markers and act accordingly. 4. Adjust libc code to replace LIBC_CANCEL_ASYNC/LIBC_CANCEL_RESET to appropriated cancelable syscalls. 5. Adjust 'lowlevellock-futex.h' arch-specific implementations to provide cancelable futex calls. This patch adds the proposed changes to NPTL common code and the following patches add the requires arch-specific bits. The build for ia64-linux-gnu, mips-*, and x86_64-* are broken without the arch-specific patches. --- elf/Makefile | 5 +- nptl/Makefile | 11 +- nptl/cancellation.c | 112 +++++++++--------- nptl/cleanup_defer.c | 5 +- nptl/descr-const.sym | 6 + nptl/descr.h | 18 +++ nptl/libc-cleanup.c | 5 +- nptl/pthread_cancel.c | 78 +++++-------- nptl/pthread_exit.c | 4 +- nptl/pthread_setcancelstate.c | 2 +- nptl/pthread_setcanceltype.c | 2 +- nptl/pthread_testcancel.c | 5 +- nptl/tst-cancel31.c | 100 ++++++++++++++++ sysdeps/generic/syscall_types.h | 25 ++++ sysdeps/nptl/cancellation-pc-check.h | 54 +++++++++ sysdeps/nptl/lowlevellock-futex.h | 20 +--- sysdeps/nptl/pthreadP.h | 11 +- sysdeps/unix/sysdep.h | 140 +++++++++++++++++------ sysdeps/unix/sysv/linux/socketcall.h | 35 ++++-- sysdeps/unix/sysv/linux/syscall_cancel.c | 71 ++++++++++++ sysdeps/unix/sysv/linux/sysdep-cancel.h | 12 -- 21 files changed, 525 insertions(+), 196 deletions(-) create mode 100644 nptl/descr-const.sym create mode 100644 nptl/tst-cancel31.c create mode 100644 sysdeps/generic/syscall_types.h create mode 100644 sysdeps/nptl/cancellation-pc-check.h create mode 100644 sysdeps/unix/sysv/linux/syscall_cancel.c diff --git a/elf/Makefile b/elf/Makefile index 396ec51424..b684e5d44c 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -1252,11 +1252,8 @@ $(objpfx)dl-allobjs.os: $(all-rtld-routines:%=$(objpfx)%.os) # discovery mechanism is not compatible with the libc implementation # when compiled for libc. rtld-stubbed-symbols = \ - __GI___pthread_disable_asynccancel \ - __GI___pthread_enable_asynccancel \ + __syscall_cancel \ __libc_assert_fail \ - __pthread_disable_asynccancel \ - __pthread_enable_asynccancel \ calloc \ free \ malloc \ diff --git a/nptl/Makefile b/nptl/Makefile index 8cec6faee3..bce033179e 100644 --- a/nptl/Makefile +++ b/nptl/Makefile @@ -204,6 +204,7 @@ routines = \ sem_timedwait \ sem_unlink \ sem_wait \ + syscall_cancel \ tpp \ unwind \ vars \ @@ -234,7 +235,8 @@ CFLAGS-pthread_setcanceltype.c += -fexceptions -fasynchronous-unwind-tables # These are internal functions which similar functionality as setcancelstate # and setcanceltype. -CFLAGS-cancellation.c += -fasynchronous-unwind-tables +CFLAGS-cancellation.c += -fexceptions -fasynchronous-unwind-tables +CFLAGS-syscall_cancel.c += -fexceptions -fasynchronous-unwind-tables # Calling pthread_exit() must cause the registered cancel handlers to # be executed. Therefore exceptions have to be thrown through this @@ -286,7 +288,7 @@ tests = tst-attr2 tst-attr3 tst-default-attr \ tst-sem17 \ tst-tsd3 tst-tsd4 \ tst-cancel4_1 tst-cancel4_2 \ - tst-cancel7 tst-cancel17 tst-cancel24 \ + tst-cancel7 tst-cancel17 tst-cancel24 tst-cancel31 \ tst-signal3 \ tst-exec4 tst-exec5 \ tst-stack2 tst-stack3 tst-stack4 \ @@ -339,7 +341,10 @@ xtests += tst-eintr1 test-srcs = tst-oddstacklimit -gen-as-const-headers = unwindbuf.sym +gen-as-const-headers = \ + descr-const.sym \ + unwindbuf.sym \ + # gen-as-const-headers gen-py-const-headers := nptl_lock_constants.pysym pretty-printers := nptl-printers.py diff --git a/nptl/cancellation.c b/nptl/cancellation.c index 765511d66d..eee5b6b758 100644 --- a/nptl/cancellation.c +++ b/nptl/cancellation.c @@ -18,74 +18,78 @@ #include #include #include "pthreadP.h" -#include - -/* The next two functions are similar to pthread_setcanceltype() but - more specialized for the use in the cancelable functions like write(). - They do not need to check parameters etc. These functions must be - AS-safe, with the exception of the actual cancellation, because they - are called by wrappers around AS-safe functions like write().*/ -int -__pthread_enable_asynccancel (void) +/* Called by the INTERNAL_SYSCALL_CANCEL macro, check for cancellation and + returns the syscall value or its negative error code. */ +long int +__internal_syscall_cancel (__syscall_arg_t a1, __syscall_arg_t a2, + __syscall_arg_t a3, __syscall_arg_t a4, + __syscall_arg_t a5, __syscall_arg_t a6, + __syscall_arg_t nr) { - struct pthread *self = THREAD_SELF; - int oldval = atomic_load_relaxed (&self->cancelhandling); + long int result; + struct pthread *pd = THREAD_SELF; - while (1) + /* If cancellation is not enabled, call the syscall directly and also + for thread terminatation to avoid call __syscall_do_cancel while + executing cleanup handlers. */ + int ch = atomic_load_relaxed (&pd->cancelhandling); + if (SINGLE_THREAD_P || !cancel_enabled (ch) || cancel_exiting (ch)) { - int newval = oldval | CANCELTYPE_BITMASK; - - if (newval == oldval) - break; + result = INTERNAL_SYSCALL_NCS_CALL (nr, a1, a2, a3, a4, a5, a6); + if (INTERNAL_SYSCALL_ERROR_P (result)) + return -INTERNAL_SYSCALL_ERRNO (result); + return result; + } - if (atomic_compare_exchange_weak_acquire (&self->cancelhandling, - &oldval, newval)) - { - if (cancel_enabled_and_canceled_and_async (newval)) - { - self->result = PTHREAD_CANCELED; - __do_cancel (); - } + /* Call the arch-specific entry points that contains the globals markers + to be checked by SIGCANCEL handler. */ + result = __syscall_cancel_arch (&pd->cancelhandling, nr, a1, a2, a3, a4, a5, + a6); - break; - } - } + /* If the cancellable syscall was interrupted by SIGCANCEL and it has not + side-effect, cancel the thread if cancellation is enabled. */ + ch = atomic_load_relaxed (&pd->cancelhandling); + if (result == -EINTR && cancel_enabled_and_canceled (ch)) + __syscall_do_cancel (); - return oldval; + return result; } -libc_hidden_def (__pthread_enable_asynccancel) -/* See the comment for __pthread_enable_asynccancel regarding - the AS-safety of this function. */ -void -__pthread_disable_asynccancel (int oldtype) +/* Called by the SYSCALL_CANCEL macro, check for cancellation and return the + syscall expected success value (usually 0) or, in case of failure, -1 and + sets errno to syscall return value. */ +long int +__syscall_cancel (__syscall_arg_t a1, __syscall_arg_t a2, + __syscall_arg_t a3, __syscall_arg_t a4, + __syscall_arg_t a5, __syscall_arg_t a6, + __syscall_arg_t nr) { - /* If asynchronous cancellation was enabled before we do not have - anything to do. */ - if (oldtype & CANCELTYPE_BITMASK) - return; + int r = __internal_syscall_cancel (a1, a2, a3, a4, a5, a6, nr); + return __glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (r)) + ? SYSCALL_ERROR_LABEL (INTERNAL_SYSCALL_ERRNO (r)) + : r; +} +/* Called by __syscall_cancel_arch or function above start the thread + cancellation. */ +_Noreturn void +__syscall_do_cancel (void) +{ struct pthread *self = THREAD_SELF; - int newval; + + /* Disable thread cancellation to avoid cancellable entrypoints to call + __syscall_do_cancel recursively. */ int oldval = atomic_load_relaxed (&self->cancelhandling); - do + while (1) { - newval = oldval & ~CANCELTYPE_BITMASK; + int newval = oldval | CANCELSTATE_BITMASK; + if (oldval == newval) + break; + if (atomic_compare_exchange_weak_acquire (&self->cancelhandling, + &oldval, newval)) + break; } - while (!atomic_compare_exchange_weak_acquire (&self->cancelhandling, - &oldval, newval)); - /* 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); - } + __do_cancel (PTHREAD_CANCELED); } -libc_hidden_def (__pthread_disable_asynccancel) diff --git a/nptl/cleanup_defer.c b/nptl/cleanup_defer.c index eef87f9a9c..d04227722b 100644 --- a/nptl/cleanup_defer.c +++ b/nptl/cleanup_defer.c @@ -82,10 +82,7 @@ ___pthread_unregister_cancel_restore (__pthread_unwind_buf_t *buf) &cancelhandling, newval)); if (cancel_enabled_and_canceled (cancelhandling)) - { - self->result = PTHREAD_CANCELED; - __do_cancel (); - } + __do_cancel (PTHREAD_CANCELED); } } versioned_symbol (libc, ___pthread_unregister_cancel_restore, diff --git a/nptl/descr-const.sym b/nptl/descr-const.sym new file mode 100644 index 0000000000..8608248354 --- /dev/null +++ b/nptl/descr-const.sym @@ -0,0 +1,6 @@ +#include + +-- Not strictly offsets, these values are using thread cancellation by arch +-- specific cancel entrypoint. +TCB_CANCELED_BIT CANCELED_BIT +TCB_CANCELED_BITMASK CANCELED_BITMASK diff --git a/nptl/descr.h b/nptl/descr.h index f8b5ac7c22..142470f3f3 100644 --- a/nptl/descr.h +++ b/nptl/descr.h @@ -415,6 +415,24 @@ struct pthread (sizeof (struct pthread) - offsetof (struct pthread, end_padding)) } __attribute ((aligned (TCB_ALIGNMENT))); +static inline bool +cancel_enabled (int value) +{ + return (value & CANCELSTATE_BITMASK) == 0; +} + +static inline bool +cancel_async_enabled (int value) +{ + return (value & CANCELTYPE_BITMASK) != 0; +} + +static inline bool +cancel_exiting (int value) +{ + return (value & EXITING_BITMASK) != 0; +} + static inline bool cancel_enabled_and_canceled (int value) { diff --git a/nptl/libc-cleanup.c b/nptl/libc-cleanup.c index 4c7bcda302..252006060a 100644 --- a/nptl/libc-cleanup.c +++ b/nptl/libc-cleanup.c @@ -69,10 +69,7 @@ __libc_cleanup_pop_restore (struct _pthread_cleanup_buffer *buffer) &cancelhandling, newval)); if (cancel_enabled_and_canceled (cancelhandling)) - { - self->result = PTHREAD_CANCELED; - __do_cancel (); - } + __do_cancel (PTHREAD_CANCELED); } } libc_hidden_def (__libc_cleanup_pop_restore) diff --git a/nptl/pthread_cancel.c b/nptl/pthread_cancel.c index 87c9ef69ad..fc5ca8b3d4 100644 --- a/nptl/pthread_cancel.c +++ b/nptl/pthread_cancel.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -40,31 +41,16 @@ sigcancel_handler (int sig, siginfo_t *si, void *ctx) || si->si_code != SI_TKILL) return; + /* Check if asynchronous cancellation mode is set or if interrupted + instruction pointer falls within the cancellable syscall bridge. For + interruptable syscalls with external side-effects (i.e. partial reads), + the kernel will set the IP to after __syscall_cancel_arch_end, thus + disabling the cancellation and allowing the process to handle such + conditions. */ struct pthread *self = THREAD_SELF; - int oldval = atomic_load_relaxed (&self->cancelhandling); - while (1) - { - /* We are canceled now. When canceled by another thread this flag - is already set but if the signal is directly send (internally or - from another process) is has to be done here. */ - int newval = oldval | CANCELING_BITMASK | CANCELED_BITMASK; - - if (oldval == newval || (oldval & EXITING_BITMASK) != 0) - /* Already canceled or exiting. */ - break; - - if (atomic_compare_exchange_weak_acquire (&self->cancelhandling, - &oldval, newval)) - { - self->result = PTHREAD_CANCELED; - - /* Make sure asynchronous cancellation is still enabled. */ - if ((oldval & CANCELTYPE_BITMASK) != 0) - /* Run the registered destructors and terminate the thread. */ - __do_cancel (); - } - } + if (cancel_async_enabled (oldval) || cancellation_pc_check (ctx)) + __syscall_do_cancel (); } int @@ -106,15 +92,13 @@ __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 cannot send SIGCANCEL unless the cancellation - 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) + is enabled. + In this case the target thread is set as 'cancelled' (CANCELED_BITMASK) by atomically setting 'cancelhandling' and the cancelation will be acted upon on next cancellation entrypoing in the target thread. - It also requires to atomically check if cancellation is enabled and - asynchronous, so both cancellation state and type are tracked on - 'cancelhandling'. */ + It also requires to atomically check if cancellation is enabled, so the + state are also tracked on 'cancelhandling'. */ int result = 0; int oldval = atomic_load_relaxed (&pd->cancelhandling); @@ -122,19 +106,17 @@ __pthread_cancel (pthread_t th) do { again: - newval = oldval | CANCELING_BITMASK | CANCELED_BITMASK; + newval = oldval | CANCELED_BITMASK; if (oldval == newval) break; - /* If the cancellation is handled asynchronously just send a - signal. We avoid this if possible since it's more - expensive. */ - if (cancel_enabled_and_canceled_and_async (newval)) + /* Only send the SIGANCEL signal is cancellation is enabled, since some + syscalls are never restarted even with SA_RESTART. The signal + will act iff async cancellation is enabled. */ + if (cancel_enabled (newval)) { - /* Mark the cancellation as "in progress". */ - int newval2 = oldval | CANCELING_BITMASK; if (!atomic_compare_exchange_weak_acquire (&pd->cancelhandling, - &oldval, newval2)) + &oldval, newval)) goto again; if (pd == THREAD_SELF) @@ -143,9 +125,8 @@ __pthread_cancel (pthread_t th) pthread_create, so the signal handler may not have been set up for a self-cancel. */ { - pd->result = PTHREAD_CANCELED; - if ((newval & CANCELTYPE_BITMASK) != 0) - __do_cancel (); + if (cancel_async_enabled (newval)) + __do_cancel (PTHREAD_CANCELED); } else /* The cancellation handler will take care of marking the @@ -154,19 +135,18 @@ __pthread_cancel (pthread_t th) break; } - - /* A single-threaded process should be able to kill itself, since - there is nothing in the POSIX specification that says that it - cannot. So we set multiple_threads to true so that cancellation - points get executed. */ - THREAD_SETMEM (THREAD_SELF, header.multiple_threads, 1); -#ifndef TLS_MULTIPLE_THREADS_IN_TCB - __libc_single_threaded_internal = 0; -#endif } while (!atomic_compare_exchange_weak_acquire (&pd->cancelhandling, &oldval, newval)); + /* A single-threaded process should be able to kill itself, since there is + nothing in the POSIX specification that says that it cannot. So we set + multiple_threads to true so that cancellation points get executed. */ + THREAD_SETMEM (THREAD_SELF, header.multiple_threads, 1); +#ifndef TLS_MULTIPLE_THREADS_IN_TCB + __libc_single_threaded_internal = 0; +#endif + return result; } versioned_symbol (libc, __pthread_cancel, pthread_cancel, GLIBC_2_34); diff --git a/nptl/pthread_exit.c b/nptl/pthread_exit.c index 9f48dcc5d0..125f44b78a 100644 --- a/nptl/pthread_exit.c +++ b/nptl/pthread_exit.c @@ -31,9 +31,7 @@ __pthread_exit (void *value) " must be installed for pthread_exit to work\n"); } - THREAD_SETMEM (THREAD_SELF, result, value); - - __do_cancel (); + __do_cancel (value); } libc_hidden_def (__pthread_exit) weak_alias (__pthread_exit, pthread_exit) diff --git a/nptl/pthread_setcancelstate.c b/nptl/pthread_setcancelstate.c index 7f81d812dd..ffb482a83d 100644 --- a/nptl/pthread_setcancelstate.c +++ b/nptl/pthread_setcancelstate.c @@ -48,7 +48,7 @@ __pthread_setcancelstate (int state, int *oldstate) &oldval, newval)) { if (cancel_enabled_and_canceled_and_async (newval)) - __do_cancel (); + __do_cancel (PTHREAD_CANCELED); break; } diff --git a/nptl/pthread_setcanceltype.c b/nptl/pthread_setcanceltype.c index 7dfeee4364..9fe7c0029b 100644 --- a/nptl/pthread_setcanceltype.c +++ b/nptl/pthread_setcanceltype.c @@ -48,7 +48,7 @@ __pthread_setcanceltype (int type, int *oldtype) if (cancel_enabled_and_canceled_and_async (newval)) { THREAD_SETMEM (self, result, PTHREAD_CANCELED); - __do_cancel (); + __do_cancel (PTHREAD_CANCELED); } break; diff --git a/nptl/pthread_testcancel.c b/nptl/pthread_testcancel.c index 38b5a2d4bc..b574c0f001 100644 --- a/nptl/pthread_testcancel.c +++ b/nptl/pthread_testcancel.c @@ -25,10 +25,7 @@ ___pthread_testcancel (void) struct pthread *self = THREAD_SELF; int cancelhandling = atomic_load_relaxed (&self->cancelhandling); if (cancel_enabled_and_canceled (cancelhandling)) - { - self->result = PTHREAD_CANCELED; - __do_cancel (); - } + __do_cancel (PTHREAD_CANCELED); } versioned_symbol (libc, ___pthread_testcancel, pthread_testcancel, GLIBC_2_34); libc_hidden_ver (___pthread_testcancel, __pthread_testcancel) diff --git a/nptl/tst-cancel31.c b/nptl/tst-cancel31.c new file mode 100644 index 0000000000..4e93cc5ae1 --- /dev/null +++ b/nptl/tst-cancel31.c @@ -0,0 +1,100 @@ +/* Check side-effect act for cancellable syscalls (BZ #12683). + Copyright (C) 2023 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 + . */ + +/* This testcase checks if there is resource leakage if the syscall has + returned from kernelspace, but before userspace saves the return + value. The 'leaker' thread should be able to close the file descriptor + if the resource is already allocated, meaning that if the cancellation + signal arrives *after* the open syscal return from kernel, the + side-effect should be visible to application. */ + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +static void * +writeopener (void *arg) +{ + int fd; + for (;;) + { + fd = open (arg, O_WRONLY); + xclose (fd); + } + return NULL; +} + +static void * +leaker (void *arg) +{ + int fd = open (arg, O_RDONLY); + TEST_VERIFY_EXIT (fd > 0); + pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, 0); + xclose (fd); + return NULL; +} + +static int +do_test (void) +{ + enum { + iter_count = 1000 + }; + + char *dir = support_create_temp_directory ("tst-cancel28"); + char *name = xasprintf ("%s/fifo", dir); + TEST_COMPARE (mkfifo (name, 0600), 0); + add_temp_file (name); + + struct support_descriptors *descrs = support_descriptors_list (); + + srand (1); + + xpthread_create (NULL, writeopener, name); + for (int i = 0; i < iter_count; i++) + { + pthread_t td = xpthread_create (NULL, leaker, name); + struct timespec ts = + { .tv_nsec = rand () % 100000, .tv_sec = 0 }; + nanosleep (&ts, NULL); + /* Ignore pthread_cancel result because it might be the + case when pthread_cancel is called when thread is already + exited. */ + pthread_cancel (td); + xpthread_join (td); + } + + support_descriptors_check (descrs); + + support_descriptors_free (descrs); + + free (name); + + return 0; +} + +#include diff --git a/sysdeps/generic/syscall_types.h b/sysdeps/generic/syscall_types.h new file mode 100644 index 0000000000..2ddeaa2b5f --- /dev/null +++ b/sysdeps/generic/syscall_types.h @@ -0,0 +1,25 @@ +/* Types and macros used for syscall issuing. + Copyright (C) 2023 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 + . */ + +#ifndef _SYSCALL_TYPES_H +#define _SYSCALL_TYPES_H + +typedef long int __syscall_arg_t; +#define __SSC(__x) ((__syscall_arg_t) (__x)) + +#endif diff --git a/sysdeps/nptl/cancellation-pc-check.h b/sysdeps/nptl/cancellation-pc-check.h new file mode 100644 index 0000000000..cb38ad6819 --- /dev/null +++ b/sysdeps/nptl/cancellation-pc-check.h @@ -0,0 +1,54 @@ +/* Architecture specific code for pthread cancellation handling. + Copyright (C) 2023 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 + . */ + +#ifndef _NPTL_CANCELLATION_PC_CHECK +#define _NPTL_CANCELLATION_PC_CHECK + +#include + +/* For syscalls with side-effects (e.g read that might return partial read), + the kernel cannot restart the syscall when interrupted by a signal, it must + return from the call with whatever partial result. In this case, the saved + program counter is set just after the syscall instruction, so the SIGCANCEL + handler should not act on cancellation. + + The __syscall_cancel_arch function, used for all cancellable syscalls, + contains two extra markers, __syscall_cancel_arch_start and + __syscall_cancel_arch_end. The former points to just before the initial + conditional branch that checks if the thread has received a cancellation + request, while former points to the instruction after the one responsible + to issue the syscall. + + The function check if the program counter (PC) from ucontext_t CTX is + within the start and then end boundary from the __syscall_cancel_arch + bridge. Return TRUE if the PC is within the boundary, meaning the + syscall does not have any side effects; or FALSE otherwise. */ + +static __always_inline bool +cancellation_pc_check (void *ctx) +{ + /* Both are defined in syscall_cancel.S. */ + extern const char __syscall_cancel_arch_start[1]; + extern const char __syscall_cancel_arch_end[1]; + + uintptr_t pc = sigcontext_get_pc (ctx); + return pc >= (uintptr_t) __syscall_cancel_arch_start + && pc < (uintptr_t) __syscall_cancel_arch_end; +} + +#endif diff --git a/sysdeps/nptl/lowlevellock-futex.h b/sysdeps/nptl/lowlevellock-futex.h index 0392b5c04f..bd57913b6f 100644 --- a/sysdeps/nptl/lowlevellock-futex.h +++ b/sysdeps/nptl/lowlevellock-futex.h @@ -21,7 +21,6 @@ #ifndef __ASSEMBLER__ # include -# include # include #endif @@ -120,21 +119,10 @@ nr_wake, nr_move, mutex, val) /* Like lll_futex_wait, but acting as a cancellable entrypoint. */ -# define lll_futex_wait_cancel(futexp, val, private) \ - ({ \ - int __oldtype = LIBC_CANCEL_ASYNC (); \ - long int __err = lll_futex_wait (futexp, val, LLL_SHARED); \ - LIBC_CANCEL_RESET (__oldtype); \ - __err; \ - }) - -/* Like lll_futex_timed_wait, but acting as a cancellable entrypoint. */ -# define lll_futex_timed_wait_cancel(futexp, val, timeout, private) \ - ({ \ - int __oldtype = LIBC_CANCEL_ASYNC (); \ - long int __err = lll_futex_timed_wait (futexp, val, timeout, private); \ - LIBC_CANCEL_RESET (__oldtype); \ - __err; \ +# define lll_futex_wait_cancel(futexp, val, private) \ + ({ \ + int __op = __lll_private_flag (FUTEX_WAIT, private); \ + INTERNAL_SYSCALL_CANCEL (futex, futexp, __op, val, NULL); \ }) #endif /* !__ASSEMBLER__ */ diff --git a/sysdeps/nptl/pthreadP.h b/sysdeps/nptl/pthreadP.h index 54f9198681..15a7a063e5 100644 --- a/sysdeps/nptl/pthreadP.h +++ b/sysdeps/nptl/pthreadP.h @@ -261,10 +261,12 @@ libc_hidden_proto (__pthread_unregister_cancel) /* Called when a thread reacts on a cancellation request. */ static inline void __attribute ((noreturn, always_inline)) -__do_cancel (void) +__do_cancel (void *result) { struct pthread *self = THREAD_SELF; + self->result = result; + /* Make sure we get no more cancellations. */ atomic_fetch_or_relaxed (&self->cancelhandling, EXITING_BITMASK); @@ -272,6 +274,13 @@ __do_cancel (void) THREAD_GETMEM (self, cleanup_jmp_buf)); } +extern long int __syscall_cancel_arch (volatile int *, __syscall_arg_t nr, + __syscall_arg_t arg1, __syscall_arg_t arg2, __syscall_arg_t arg3, + __syscall_arg_t arg4, __syscall_arg_t arg5, __syscall_arg_t arg6) + attribute_hidden; + +extern _Noreturn void __syscall_do_cancel (void) attribute_hidden; + /* Internal prototypes. */ diff --git a/sysdeps/unix/sysdep.h b/sysdeps/unix/sysdep.h index 1ba4de99db..32bc85592e 100644 --- a/sysdeps/unix/sysdep.h +++ b/sysdeps/unix/sysdep.h @@ -24,6 +24,9 @@ #define SYSCALL__(name, args) PSEUDO (__##name, name, args) #define SYSCALL(name, args) PSEUDO (name, name, args) +#ifndef __ASSEMBLER__ +# include + #define __SYSCALL_CONCAT_X(a,b) a##b #define __SYSCALL_CONCAT(a,b) __SYSCALL_CONCAT_X (a, b) @@ -108,42 +111,115 @@ #define INLINE_SYSCALL_CALL(...) \ __INLINE_SYSCALL_DISP (__INLINE_SYSCALL, __VA_ARGS__) +#define __INTERNAL_SYSCALL_NCS0(name) \ + INTERNAL_SYSCALL_NCS (name, 0) +#define __INTERNAL_SYSCALL_NCS1(name, a1) \ + INTERNAL_SYSCALL_NCS (name, 1, a1) +#define __INTERNAL_SYSCALL_NCS2(name, a1, a2) \ + INTERNAL_SYSCALL_NCS (name, 2, a1, a2) +#define __INTERNAL_SYSCALL_NCS3(name, a1, a2, a3) \ + INTERNAL_SYSCALL_NCS (name, 3, a1, a2, a3) +#define __INTERNAL_SYSCALL_NCS4(name, a1, a2, a3, a4) \ + INTERNAL_SYSCALL_NCS (name, 4, a1, a2, a3, a4) +#define __INTERNAL_SYSCALL_NCS5(name, a1, a2, a3, a4, a5) \ + INTERNAL_SYSCALL_NCS (name, 5, a1, a2, a3, a4, a5) +#define __INTERNAL_SYSCALL_NCS6(name, a1, a2, a3, a4, a5, a6) \ + INTERNAL_SYSCALL_NCS (name, 6, a1, a2, a3, a4, a5, a6) +#define __INTERNAL_SYSCALL_NCS7(name, a1, a2, a3, a4, a5, a6, a7) \ + INTERNAL_SYSCALL_NCS (name, 7, a1, a2, a3, a4, a5, a6, a7) + +/* Issue a syscall defined by syscall number plus any other argument required. + It is similar to INTERNAL_SYSCALL_NCS macro, but without the need to pass + the expected argument number as third parameter. */ +#define INTERNAL_SYSCALL_NCS_CALL(...) \ + __INTERNAL_SYSCALL_DISP (__INTERNAL_SYSCALL_NCS, __VA_ARGS__) + +/* Cancellation macros. */ +#include + +long int __internal_syscall_cancel (__syscall_arg_t a1, __syscall_arg_t a2, + __syscall_arg_t a3, __syscall_arg_t a4, + __syscall_arg_t a5, __syscall_arg_t a6, + __syscall_arg_t nr) attribute_hidden; + +long int __syscall_cancel (__syscall_arg_t nr, __syscall_arg_t arg1, + __syscall_arg_t arg2, __syscall_arg_t arg3, + __syscall_arg_t arg4, __syscall_arg_t arg5, + __syscall_arg_t arg6) attribute_hidden; + +#define __SYSCALL_CANCEL0(name) \ + __syscall_cancel (0, 0, 0, 0, 0, 0, __NR_##name) +#define __SYSCALL_CANCEL1(name, a1) \ + __syscall_cancel (__SSC (a1), 0, 0, 0, 0, 0, __NR_##name) +#define __SYSCALL_CANCEL2(name, a1, a2) \ + __syscall_cancel (__SSC (a1), __SSC (a2), 0, 0, 0, 0, __NR_##name) +#define __SYSCALL_CANCEL3(name, a1, a2, a3) \ + __syscall_cancel (__SSC (a1), __SSC (a2), __SSC (a3), 0, 0, 0, \ + __NR_##name) +#define __SYSCALL_CANCEL4(name, a1, a2, a3, a4) \ + __syscall_cancel (__SSC (a1), __SSC (a2), __SSC (a3), \ + __SSC(a4), 0, 0, __NR_##name) +#define __SYSCALL_CANCEL5(name, a1, a2, a3, a4, a5) \ + __syscall_cancel (__SSC (a1), __SSC (a2), __SSC (a3), __SSC(a4), \ + __SSC (a5), 0, __NR_##name) +#define __SYSCALL_CANCEL6(name, a1, a2, a3, a4, a5, a6) \ + __syscall_cancel (__SSC (a1), __SSC (a2), __SSC (a3), __SSC (a4), \ + __SSC (a5), __SSC (a6), __NR_##name) + +#define __SYSCALL_CANCEL_NARGS_X(a,b,c,d,e,f,g,h,n,...) n +#define __SYSCALL_CANCEL_NARGS(...) \ + __SYSCALL_CANCEL_NARGS_X (__VA_ARGS__,7,6,5,4,3,2,1,0,) +#define __SYSCALL_CANCEL_CONCAT_X(a,b) a##b +#define __SYSCALL_CANCEL_CONCAT(a,b) __SYSCALL_CANCEL_CONCAT_X (a, b) +#define __SYSCALL_CANCEL_DISP(b,...) \ + __SYSCALL_CANCEL_CONCAT (b,__SYSCALL_CANCEL_NARGS(__VA_ARGS__))(__VA_ARGS__) + +/* Issue a cancellable syscall defined first argument plus any other argument + required. If and error occurs its value, the macro returns -1 and sets + errno accordingly. */ +#define __SYSCALL_CANCEL_CALL(...) \ + __SYSCALL_CANCEL_DISP (__SYSCALL_CANCEL, __VA_ARGS__) + +#define __INTERNAL_SYSCALL_CANCEL0(name) \ + __internal_syscall_cancel (0, 0, 0, 0, 0, 0, __NR_##name) +#define __INTERNAL_SYSCALL_CANCEL1(name, a1) \ + __internal_syscall_cancel (__SSC (a1), 0, 0, 0, 0, 0, __NR_##name) +#define __INTERNAL_SYSCALL_CANCEL2(name, a1, a2) \ + __internal_syscall_cancel (__SSC (a1), __SSC (a2), 0, 0, 0, 0, \ + __NR_##name) +#define __INTERNAL_SYSCALL_CANCEL3(name, a1, a2, a3) \ + __internal_syscall_cancel (__SSC (a1), __SSC (a2), __SSC (a3), 0, \ + 0, 0, __NR_##name) +#define __INTERNAL_SYSCALL_CANCEL4(name, a1, a2, a3, a4) \ + __internal_syscall_cancel (__SSC (a1), __SSC (a2), __SSC (a3), \ + __SSC(a4), 0, 0, __NR_##name) +#define __INTERNAL_SYSCALL_CANCEL5(name, a1, a2, a3, a4, a5) \ + __internal_syscall_cancel (__SSC (a1), __SSC (a2), __SSC (a3), \ + __SSC(a4), __SSC (a5), 0, __NR_##name) +#define __INTERNAL_SYSCALL_CANCEL6(name, a1, a2, a3, a4, a5, a6) \ + __internal_syscall_cancel (__SSC (a1), __SSC (a2), __SSC (a3), \ + __SSC (a4), __SSC (a5), __SSC (a6), \ + __NR_##name) + +/* Issue a cancellable syscall defined by syscall number NAME plus any other + argument required. If an error occurs its value is returned as an negative + number unmodified and errno is not set. */ +#define __INTERNAL_SYSCALL_CANCEL_CALL(...) \ + __SYSCALL_CANCEL_DISP (__INTERNAL_SYSCALL_CANCEL, __VA_ARGS__) + #if IS_IN (rtld) -/* All cancellation points are compiled out in the dynamic loader. */ -# define NO_SYSCALL_CANCEL_CHECKING 1 +/* The loader does not need to handle thread cancellation, use direct + syscall instead. */ +# define INTERNAL_SYSCALL_CANCEL(...) INTERNAL_SYSCALL_CALL(__VA_ARGS__) +# define SYSCALL_CANCEL(...) INLINE_SYSCALL_CALL (__VA_ARGS__) #else -# define NO_SYSCALL_CANCEL_CHECKING SINGLE_THREAD_P +# define INTERNAL_SYSCALL_CANCEL(...) \ + __INTERNAL_SYSCALL_CANCEL_CALL (__VA_ARGS__) +# define SYSCALL_CANCEL(...) \ + __SYSCALL_CANCEL_CALL (__VA_ARGS__) #endif -#define SYSCALL_CANCEL(...) \ - ({ \ - long int sc_ret; \ - if (NO_SYSCALL_CANCEL_CHECKING) \ - sc_ret = INLINE_SYSCALL_CALL (__VA_ARGS__); \ - else \ - { \ - int sc_cancel_oldtype = LIBC_CANCEL_ASYNC (); \ - sc_ret = INLINE_SYSCALL_CALL (__VA_ARGS__); \ - LIBC_CANCEL_RESET (sc_cancel_oldtype); \ - } \ - sc_ret; \ - }) - -/* Issue a syscall defined by syscall number plus any other argument - required. Any error will be returned unmodified (including errno). */ -#define INTERNAL_SYSCALL_CANCEL(...) \ - ({ \ - long int sc_ret; \ - if (NO_SYSCALL_CANCEL_CHECKING) \ - sc_ret = INTERNAL_SYSCALL_CALL (__VA_ARGS__); \ - else \ - { \ - int sc_cancel_oldtype = LIBC_CANCEL_ASYNC (); \ - sc_ret = INTERNAL_SYSCALL_CALL (__VA_ARGS__); \ - LIBC_CANCEL_RESET (sc_cancel_oldtype); \ - } \ - sc_ret; \ - }) +#endif /* __ASSEMBLER__ */ /* Machine-dependent sysdep.h files are expected to define the macro PSEUDO (function_name, syscall_name) to emit assembly code to define the diff --git a/sysdeps/unix/sysv/linux/socketcall.h b/sysdeps/unix/sysv/linux/socketcall.h index d1a173277e..19a6c17a86 100644 --- a/sysdeps/unix/sysv/linux/socketcall.h +++ b/sysdeps/unix/sysv/linux/socketcall.h @@ -88,14 +88,33 @@ sc_ret; \ }) - -#define SOCKETCALL_CANCEL(name, args...) \ - ({ \ - int oldtype = LIBC_CANCEL_ASYNC (); \ - long int sc_ret = __SOCKETCALL (SOCKOP_##name, args); \ - LIBC_CANCEL_RESET (oldtype); \ - sc_ret; \ - }) +#define __SOCKETCALL_CANCEL1(__name, __a1) \ + SYSCALL_CANCEL (socketcall, __name, \ + ((long int [1]) { (long int) __a1 })) +#define __SOCKETCALL_CANCEL2(__name, __a1, __a2) \ + SYSCALL_CANCEL (socketcall, __name, \ + ((long int [2]) { (long int) __a1, (long int) __a2 })) +#define __SOCKETCALL_CANCEL3(__name, __a1, __a2, __a3) \ + SYSCALL_CANCEL (socketcall, __name, \ + ((long int [3]) { (long int) __a1, (long int) __a2, (long int) __a3 })) +#define __SOCKETCALL_CANCEL4(__name, __a1, __a2, __a3, __a4) \ + SYSCALL_CANCEL (socketcall, __name, \ + ((long int [4]) { (long int) __a1, (long int) __a2, (long int) __a3, \ + (long int) __a4 })) +#define __SOCKETCALL_CANCEL5(__name, __a1, __a2, __a3, __a4, __a5) \ + SYSCALL_CANCEL (socketcall, __name, \ + ((long int [5]) { (long int) __a1, (long int) __a2, (long int) __a3, \ + (long int) __a4, (long int) __a5 })) +#define __SOCKETCALL_CANCEL6(__name, __a1, __a2, __a3, __a4, __a5, __a6) \ + SYSCALL_CANCEL (socketcall, __name, \ + ((long int [6]) { (long int) __a1, (long int) __a2, (long int) __a3, \ + (long int) __a4, (long int) __a5, (long int) __a6 })) + +#define __SOCKETCALL_CANCEL(...) __SOCKETCALL_DISP (__SOCKETCALL_CANCEL,\ + __VA_ARGS__) + +#define SOCKETCALL_CANCEL(name, args...) \ + __SOCKETCALL_CANCEL (SOCKOP_##name, args) #endif /* sys/socketcall.h */ diff --git a/sysdeps/unix/sysv/linux/syscall_cancel.c b/sysdeps/unix/sysv/linux/syscall_cancel.c new file mode 100644 index 0000000000..260680c99f --- /dev/null +++ b/sysdeps/unix/sysv/linux/syscall_cancel.c @@ -0,0 +1,71 @@ +/* Pthread cancellation syscall bridge. Default Linux version. + Copyright (C) 2023 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 + . */ + +#include +#include + +#warning "This implementation should be use just as reference or for bootstrapping" + +/* This is the generic version of the cancellable syscall code which + adds the label guards (__syscall_cancel_arch_{start,end}) used on SIGCANCEL + handler to check if the cancelled syscall have side-effects that need to be + returned to the caller. + + This implementation should be used as a reference one to document the + implementation constraints: + + 1. The __syscall_cancel_arch_start should point just before the test + that thread is already cancelled, + 2. The __syscall_cancel_arch_end should point to the immediate next + instruction after the syscall one. + 3. It should return the syscall value or a negative result if is has + failed, similar to INTERNAL_SYSCALL_CALL. + + The __syscall_cancel_arch_end one is because the kernel will signal + interrupted syscall with side effects by setting the signal frame program + counter (on the ucontext_t third argument from SA_SIGINFO signal handler) + right after the syscall instruction. + + For some architecture, the INTERNAL_SYSCALL_NCS macro use more instructions + to get the error condition from kernel (as for powerpc and sparc that + checks for the conditional register), or uses an out of the line helper + (ARM thumb), or uses a kernel helper gate (i686 or ia64). In this case + the architecture should either adjust the macro or provide a custom + __syscall_cancel_arch implementation. */ + +long int +__syscall_cancel_arch (volatile int *ch, __syscall_arg_t nr, + __syscall_arg_t a1, __syscall_arg_t a2, + __syscall_arg_t a3, __syscall_arg_t a4, + __syscall_arg_t a5, __syscall_arg_t a6) +{ +#define ADD_LABEL(__label) \ + asm volatile ( \ + ".global " __label "\t\n" \ + __label ":\n"); + + ADD_LABEL ("__syscall_cancel_arch_start"); + if (__glibc_unlikely (*ch & CANCELED_BITMASK)) + __syscall_do_cancel(); + + long int result = INTERNAL_SYSCALL_NCS_CALL (nr, a1, a2, a3, a4, a5, a6); + ADD_LABEL ("__syscall_cancel_arch_end"); + if (__glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (result))) + return -INTERNAL_SYSCALL_ERRNO (result); + return result; +} diff --git a/sysdeps/unix/sysv/linux/sysdep-cancel.h b/sysdeps/unix/sysv/linux/sysdep-cancel.h index 102682c5ee..1b686d53a9 100644 --- a/sysdeps/unix/sysv/linux/sysdep-cancel.h +++ b/sysdeps/unix/sysv/linux/sysdep-cancel.h @@ -21,17 +21,5 @@ #define _SYSDEP_CANCEL_H #include -#include -#include - -/* Set cancellation mode to asynchronous. */ -extern int __pthread_enable_asynccancel (void); -libc_hidden_proto (__pthread_enable_asynccancel) -#define LIBC_CANCEL_ASYNC() __pthread_enable_asynccancel () - -/* Reset to previous cancellation mode. */ -extern void __pthread_disable_asynccancel (int oldtype); -libc_hidden_proto (__pthread_disable_asynccancel) -#define LIBC_CANCEL_RESET(oldtype) __pthread_disable_asynccancel (oldtype) #endif From patchwork Mon Apr 10 19:58:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 67573 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 92DE03857717 for ; Mon, 10 Apr 2023 19:59:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 92DE03857717 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1681156779; bh=TDUqa1KFRgWXwQiFuIC/388RyAU957ehsxXfSDRO3dw=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=AT6NH2ivyKgkgj282r2R3+d5ajr+XfH8/L5ivAyLAztYcwHcKuAQ7jpSh/KfLIxVx ycBqJZyejGgTWCd6GeMt+U809fNvmpWK7vjK1eJf+k6DmoBsKtvAbJqgWxJJ6Z4ptX ujya59cy2EyXJGsSOpnFinyOyvdWJLP/HiLh72cY= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x32f.google.com (mail-ot1-x32f.google.com [IPv6:2607:f8b0:4864:20::32f]) by sourceware.org (Postfix) with ESMTPS id 5DEE63858C62 for ; Mon, 10 Apr 2023 19:59:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5DEE63858C62 Received: by mail-ot1-x32f.google.com with SMTP id f10-20020a9d2c0a000000b006a13f728172so701946otb.3 for ; Mon, 10 Apr 2023 12:59:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681156755; x=1683748755; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TDUqa1KFRgWXwQiFuIC/388RyAU957ehsxXfSDRO3dw=; b=D1jP/h1y7Lgz6nvSJvIBalbugAriD7q7mya6cqpLw0snfoQxTOBMxe82J4JqIShAMv YWL0LikTbCXzfcKVWTpdlIsmOaMnYG9OyMehhevC9KOe3OOr5ftA8/C1OusEcDz6C7Wk AABW8q8pmbxUTEi2ZHVukokxWTpOkiTp7HdEMqoKt9k0EAdP6xR4LQVbeZoO71q6+EG/ 1LcQI/rrutKGseWEcne7puRKbAMPaJ8dLjQ3qCcQgbd9HxbVuhAPmTHynWuYGCAAli/M 2IDeg4eUK5LnJifxMnG5y3D3JtEog19RHk0lny6qS3BhdQnIdntZsZxsZAQmEyoOGYY6 nV3Q== X-Gm-Message-State: AAQBX9cvnaPmRLR3EsSL4lTAi7owThp5p2BI3l0ePP0v6K91Prb/GmvN gKstAGSyKGHpSL54meqkLQR4NXCQaCgskP7WQw6fJQ== X-Google-Smtp-Source: AKy350ajyNauUbNQP+Of0yvks1ca2r77fRIYF3WovPYTKFXHDmvTfc8qrYHcg6cUx3jXyVu9fLnHxA== X-Received: by 2002:a9d:6c57:0:b0:69f:a6f8:37ec with SMTP id g23-20020a9d6c57000000b0069fa6f837ecmr248628otq.29.1681156755394; Mon, 10 Apr 2023 12:59:15 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c2:55a1:d59a:609a:284:6ed]) by smtp.gmail.com with ESMTPSA id r7-20020a9d7507000000b006a30260ccfdsm4673293otk.11.2023.04.10.12.59.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Apr 2023 12:59:14 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v5 02/22] x86_64: Fix Race conditions in pthread cancellation [BZ#12683] Date: Mon, 10 Apr 2023 16:58:47 -0300 Message-Id: <20230410195907.4123869-3-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230410195907.4123869-1-adhemerval.zanella@linaro.org> References: <20230410195907.4123869-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" By adding the required syscall_cancel.S. Checked on x86_64-linux-gnu. --- .../unix/sysv/linux/x86_64/syscall_cancel.S | 57 +++++++++++++++++++ sysdeps/x86_64/nptl/tcb-offsets.sym | 3 - 2 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 sysdeps/unix/sysv/linux/x86_64/syscall_cancel.S diff --git a/sysdeps/unix/sysv/linux/x86_64/syscall_cancel.S b/sysdeps/unix/sysv/linux/x86_64/syscall_cancel.S new file mode 100644 index 0000000000..cda9d20a83 --- /dev/null +++ b/sysdeps/unix/sysv/linux/x86_64/syscall_cancel.S @@ -0,0 +1,57 @@ +/* Cancellable syscall wrapper. Linux/x86_64 version. + Copyright (C) 2023 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 + . */ + +#include +#include + +/* long int [rax] __syscall_cancel_arch (volatile int *cancelhandling [%rdi], + __syscall_arg_t nr [%rsi], + __syscall_arg_t arg1 [%rdx], + __syscall_arg_t arg2 [%rcx], + __syscall_arg_t arg3 [%r8], + __syscall_arg_t arg4 [%r9], + __syscall_arg_t arg5 [SP+8], + __syscall_arg_t arg6 [SP+16]) */ + +ENTRY (__syscall_cancel_arch) + .globl __syscall_cancel_arch_start +__syscall_cancel_arch_start: + + /* if (*cancelhandling & CANCELED_BITMASK) + __syscall_do_cancel() */ + mov (%rdi),%eax + testb $TCB_CANCELED_BITMASK, (%rdi) + jne __syscall_do_cancel + + /* Issue a 6 argument syscall, the nr [%rax] being the syscall + number. */ + mov %rdi,%r11 + mov %rsi,%rax + mov %rdx,%rdi + mov %rcx,%rsi + mov %r8,%rdx + mov %r9,%r10 + mov 8(%rsp),%r8 + mov 16(%rsp),%r9 + mov %r11,8(%rsp) + syscall + + .globl __syscall_cancel_arch_end +__syscall_cancel_arch_end: + ret +END (__syscall_cancel_arch) diff --git a/sysdeps/x86_64/nptl/tcb-offsets.sym b/sysdeps/x86_64/nptl/tcb-offsets.sym index 2bbd563a6c..988a4b8593 100644 --- a/sysdeps/x86_64/nptl/tcb-offsets.sym +++ b/sysdeps/x86_64/nptl/tcb-offsets.sym @@ -13,6 +13,3 @@ MULTIPLE_THREADS_OFFSET offsetof (tcbhead_t, multiple_threads) POINTER_GUARD offsetof (tcbhead_t, pointer_guard) FEATURE_1_OFFSET offsetof (tcbhead_t, feature_1) SSP_BASE_OFFSET offsetof (tcbhead_t, ssp_base) - --- Not strictly offsets, but these values are also used in the TCB. -TCB_CANCELED_BITMASK CANCELED_BITMASK From patchwork Mon Apr 10 19:58:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 67574 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0E5E83857353 for ; Mon, 10 Apr 2023 19:59:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0E5E83857353 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1681156784; bh=gH+wsHrA4aMuqPAMIldW3Gv+a4Cx9un1/WXpgvqZQto=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=sdj3/+JogLC6BhZNQnm2tAT1XM9pLQMc8EWtxIY55GDb1kKNA88s7MMY7C5J6co6q 5yureqv97oHoPk3tA12qkxu8D/D9CNbYbvG/cQVt/8E+cnLaJRUvwX/WR/5vZFlBvC 5gDhNrsU2zJW2fzoue7VlJPdBRev4/qTlhm3D9XA= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x335.google.com (mail-ot1-x335.google.com [IPv6:2607:f8b0:4864:20::335]) by sourceware.org (Postfix) with ESMTPS id 704E43858C1F for ; Mon, 10 Apr 2023 19:59:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 704E43858C1F Received: by mail-ot1-x335.google.com with SMTP id bu14-20020a0568300d0e00b0069fab3f4cafso2819470otb.9 for ; Mon, 10 Apr 2023 12:59:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681156757; x=1683748757; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gH+wsHrA4aMuqPAMIldW3Gv+a4Cx9un1/WXpgvqZQto=; b=0sDD38LsXVTEg2waJ6o2umassqLH7RgV+MAubCnckv9l0p6DDqD1QITM/1DYgRBLxA 0sAb1gon4wpueP6D+ZbwGS0Rxirb1jrwvc60rMkqsBAsY1UjbVhWA5w6QjFQfRpA7Gbv qS6ViLUA/DqDbKdHsQX+YZTgRuC4wORs8EuCZ+CIhW7KErsEKvRzRBtUWAsL1BvWoRdo 2bUEF2MekSiFX+gq39V2Or6R2eL7ykZziwnfV2Vh4sdUT1iCEO97xLuIpxKyZojigAIF iz6U90UFZSHflqJNv7w8774wlOG1GMpEDI94CHM+7efj9Pz+3s9ATV/3HPRrajPzr1F3 vtWw== X-Gm-Message-State: AAQBX9cie6FywOfb1iBFLqgO0Yzgk1Di3th04Y6cLQ/4bzsQE7D+Mz+1 XLpLuNJb0N+caD7qfaKq2+MzmPYSGpz5kywZA9D1TQ== X-Google-Smtp-Source: AKy350ZNNNqaw/cWefe1LT4rxONkFeuaqXuwXnPpw4anq9BiVlBYalW4iy69TfOFxFQ4U5O3RzfPIQ== X-Received: by 2002:a05:6830:1bf4:b0:69f:91eb:87da with SMTP id k20-20020a0568301bf400b0069f91eb87damr4853007otb.16.1681156757198; Mon, 10 Apr 2023 12:59:17 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c2:55a1:d59a:609a:284:6ed]) by smtp.gmail.com with ESMTPSA id r7-20020a9d7507000000b006a30260ccfdsm4673293otk.11.2023.04.10.12.59.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Apr 2023 12:59:16 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v5 03/22] x32: Fix Race conditions in pthread cancellation [BZ#12683] Date: Mon, 10 Apr 2023 16:58:48 -0300 Message-Id: <20230410195907.4123869-4-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230410195907.4123869-1-adhemerval.zanella@linaro.org> References: <20230410195907.4123869-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" By adding a x86_64-x32 __SSC macro. Checked on x86_64-linux-gnu-x32. --- .../sysv/linux/x86_64/x32/syscall_types.h | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/x86_64/x32/syscall_types.h diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/syscall_types.h b/sysdeps/unix/sysv/linux/x86_64/x32/syscall_types.h new file mode 100644 index 0000000000..ac2019751d --- /dev/null +++ b/sysdeps/unix/sysv/linux/x86_64/x32/syscall_types.h @@ -0,0 +1,34 @@ +/* Types and macros used for syscall issuing. x86_64/x32 version. + Copyright (C) 2023 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 + . */ + +#ifndef _SYSCALL_TYPES_H +#define _SYSCALL_TYPES_H + +#include + +typedef long long int __syscall_arg_t; + +/* Syscall arguments for x32 follows x86_64 ABI, however pointers are 32 bits + should be zero extended. */ +#define __SSC(__x) \ + ({ \ + TYPEFY (__x, __tmp) = ARGIFY (__x); \ + (__syscall_arg_t) __tmp; \ + }) + +#endif From patchwork Mon Apr 10 19:58:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 67578 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 209C0385F029 for ; Mon, 10 Apr 2023 20:00:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 209C0385F029 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1681156827; bh=GVQEBa9ng8mhI6DdcMlkMkW2RxwFkSWH1iQKneaACTM=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=p/HmFu1IhVdHlyTAU9iKkwKzD1qYz4Ht7ZVZXeE+/RtEOUcRhawNRjUVwre3WJItl yH78C8NEl9Do4Cq+/GTV4JaRyubAVkXXCHYNyMd4qcc1CjHInqVZE1H7p1Rmonzr8+ RLzPlpCb+8Z7JZwS9gbeENt5zGFmnhy+Paq4jmo0= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x32e.google.com (mail-ot1-x32e.google.com [IPv6:2607:f8b0:4864:20::32e]) by sourceware.org (Postfix) with ESMTPS id 292CA3858C20 for ; Mon, 10 Apr 2023 19:59:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 292CA3858C20 Received: by mail-ot1-x32e.google.com with SMTP id cp25-20020a056830661900b00693ce5a2f3eso2825204otb.8 for ; Mon, 10 Apr 2023 12:59:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681156759; x=1683748759; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GVQEBa9ng8mhI6DdcMlkMkW2RxwFkSWH1iQKneaACTM=; b=aJPW16VbGzsY20yj9q6ldKxCyOu8Kydp9ZKFwtrYVl3ezGdsxPCSqmEs1hRMAhUhlw EpEnpqFVDNWoXpO/6TlTb4uBwH1yqcivKJMD14XtMo/ZqaYWtZegYJ0h0DFuAPTntkbY Gra2HKDApfcgRnyOxsUn/C74EkIGn1qjo7NBvSyhO35PzkbCeo/vixrroB1t1Q1rlDxk rt2qDVFFs9ZWWAT2Od66DZGyIlYv53obhWo9fG+HG/erFCRQWQI1tromGTUlt+txAuY+ 6fHHGoD9rhMlzvskOFFUuzvsrs8ftSc+k6GKP/4P4S4TDqYXBPii+Pq2XOzO3w8RGkt3 oS7A== X-Gm-Message-State: AAQBX9cqGs2QTSRBCjJbXEEoNo5fXqq0AKfHDUoFqm+9EPqTbhcHeNvY j7fiVKJ4DnTePeBKf3rGPONRFmrGakmpq9JRClf3CQ== X-Google-Smtp-Source: AKy350aLJpr52hA2nIykvC9OeY0OSP7cYt1iY8bAswSkbuTYGVOXEy0zHIgYwBbF3ajJHaRTxTpYkQ== X-Received: by 2002:a05:6830:111:b0:6a1:3101:8e2e with SMTP id i17-20020a056830011100b006a131018e2emr4560083otp.29.1681156758881; Mon, 10 Apr 2023 12:59:18 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c2:55a1:d59a:609a:284:6ed]) by smtp.gmail.com with ESMTPSA id r7-20020a9d7507000000b006a30260ccfdsm4673293otk.11.2023.04.10.12.59.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Apr 2023 12:59:18 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v5 04/22] i386: Fix Race conditions in pthread cancellation [BZ#12683] Date: Mon, 10 Apr 2023 16:58:49 -0300 Message-Id: <20230410195907.4123869-5-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230410195907.4123869-1-adhemerval.zanella@linaro.org> References: <20230410195907.4123869-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" The syscall bridge uses the old int80 instruction because by using the optimized vDSO symbol the resulting PC value for an interrupted syscall points to an adress outside the expected markers in __syscall_cancel_arch. It has been discussed in LKML [1] on how kernel could help userland to accomplish it, but afaik discussion has stalled. Also, sysenter should not be used directly by libc since its calling convention is set by the kernel depending of the underlying x86 chip (check kernel commit 30bfa7b3488bfb1bb75c9f50a5fcac1832970c60). Checked on i686-linux-gnu. [1] https://lkml.org/lkml/2016/3/8/1105 --- sysdeps/unix/sysv/linux/i386/syscall_cancel.S | 103 ++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/i386/syscall_cancel.S diff --git a/sysdeps/unix/sysv/linux/i386/syscall_cancel.S b/sysdeps/unix/sysv/linux/i386/syscall_cancel.S new file mode 100644 index 0000000000..7d1560e18f --- /dev/null +++ b/sysdeps/unix/sysv/linux/i386/syscall_cancel.S @@ -0,0 +1,103 @@ +/* Cancellable syscall wrapper. Linux/i686 version. + Copyright (C) 2023 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 + . */ + +#include +#include + +/* long int [eax] __syscall_cancel_arch (int *cancelhandling [SP], + long int nr [SP+4], + long int arg1 [SP+8], + long int arg2 [SP+12], + long int arg3 [SP+16], + long int arg4 [SP+20], + long int arg5 [SP+24], + long int arg6 [SP+28]) */ + +ENTRY (__syscall_cancel_arch) + pushl %ebp + cfi_def_cfa_offset (8) + cfi_offset (ebp, -8) + pushl %edi + cfi_def_cfa_offset (12) + cfi_offset (edi, -12) + pushl %esi + cfi_def_cfa_offset (16) + cfi_offset (esi, -16) + pushl %ebx + cfi_def_cfa_offset (20) + cfi_offset (ebx, -20) + + .global __syscall_cancel_arch_start +__syscall_cancel_arch_start: + + /* if (*cancelhandling & CANCELED_BITMASK) + __syscall_do_cancel() */ + testb $TCB_CANCELED_BITMASK, (%eax) + jne 1f + + /* Issue a 6 argument syscall, the nr [%eax] being the syscall + number. */ + movl 24(%esp), %eax + movl 28(%esp), %ebx + movl 32(%esp), %ecx + movl 36(%esp), %edx + movl 40(%esp), %esi + movl 44(%esp), %edi + movl 48(%esp), %ebp + + /* We can not use the vDSO helper for syscall (__kernel_vsyscall) + because the returned PC from kernel will point to the vDSO page + instead of the expected __syscall_cancel_arch_{start,end} + marks. */ + int $128 + + .global __syscall_cancel_arch_end +__syscall_cancel_arch_end: + + popl %ebx + cfi_restore (ebx) + cfi_def_cfa_offset (16) + popl %esi + cfi_restore (esi) + cfi_def_cfa_offset (12) + popl %edi + cfi_restore (edi) + cfi_def_cfa_offset (8) + popl %ebp + cfi_restore (ebp) + cfi_def_cfa_offset (4) + ret + +1: + /* Although the __syscall_do_cancel do not return, we need to stack + being set correctly for unwind. */ + popl %ebx + cfi_restore (ebx) + cfi_def_cfa_offset (16) + popl %esi + cfi_restore (esi) + cfi_def_cfa_offset (12) + popl %edi + cfi_restore (edi) + cfi_def_cfa_offset (8) + popl %ebp + cfi_restore (ebp) + cfi_def_cfa_offset (4) + jmp __syscall_do_cancel + +END (__syscall_cancel_arch) From patchwork Mon Apr 10 19:58:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 67576 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4C34E3853564 for ; Mon, 10 Apr 2023 20:00:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4C34E3853564 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1681156825; bh=K8OFJakccglc5ylB7sxR7mrnDfCUY/95k9NJwF3I62w=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=tmfDajhZweoh0XDYrZ9+HuKfhzJ7rbr5rdbKX5TQQLzy253cjx8sBnczXUtimx7SE 0+PLGdjNV4zCb0vj7HjjpUIrhRGfy04s75RnYBTdcByf6BbukoZGPx8wDBMgB39Cav Jl7ZMvYD4KzFUS+dQELJahDQGbx6OV3Ay6xj4IP8= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x32d.google.com (mail-ot1-x32d.google.com [IPv6:2607:f8b0:4864:20::32d]) by sourceware.org (Postfix) with ESMTPS id 013E63858428 for ; Mon, 10 Apr 2023 19:59:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 013E63858428 Received: by mail-ot1-x32d.google.com with SMTP id 6-20020a9d0106000000b006a177038dfeso16295606otu.7 for ; Mon, 10 Apr 2023 12:59:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681156760; x=1683748760; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=K8OFJakccglc5ylB7sxR7mrnDfCUY/95k9NJwF3I62w=; b=tGwzN2kzXdyb1rE3kZfDHgL4wKV5pfRvoTl9LEyyQHMViEZmL67u4+NHKWmd9PSmF5 n9oHgOaj59VqgP7/IueKE7jKquij/dCjhw9zliSh5N6OAyrTO0n2PiKxbIxiXzktgjVO jj+FFzNfZpULZoMSLdEOzEB1gJTdcqKuoUDJJJiIc5ARf3u2D84QFwQsgdH76Tuhz/m9 dBI6hBuiqSqXrKxpTXsxqrZOmH75PKdGoTyPwU6oUz+3LhIHEJa8UrtxH/+t6izsfYnJ NoQ5cEcfp423eh9fj3TZs8iiZhni4KuOcn88N3FShUzmnOSXKttIjqouIb3vn/W/X67s FZmg== X-Gm-Message-State: AAQBX9eJltyzevs697KZowZvkBO3g+T2AIVqKLuQhBrU2DJQR8sv5AHq uGFr7u6IPb4SiOHjgYl5tUn8w/3ZV27XPy0/zv9pWg== X-Google-Smtp-Source: AKy350ZJ9uNH2oTRXjSQSvJrghqVd2Mc4NZ0+swoqT3xfBqVHgB9fwXeJIBOyV6Y+s9/N0qNISYI6g== X-Received: by 2002:a9d:5c06:0:b0:6a1:7f69:ffbf with SMTP id o6-20020a9d5c06000000b006a17f69ffbfmr224822otk.36.1681156760464; Mon, 10 Apr 2023 12:59:20 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c2:55a1:d59a:609a:284:6ed]) by smtp.gmail.com with ESMTPSA id r7-20020a9d7507000000b006a30260ccfdsm4673293otk.11.2023.04.10.12.59.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Apr 2023 12:59:19 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v5 05/22] aarch64: Fix Race conditions in pthread cancellation [BZ#12683] Date: Mon, 10 Apr 2023 16:58:50 -0300 Message-Id: <20230410195907.4123869-6-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230410195907.4123869-1-adhemerval.zanella@linaro.org> References: <20230410195907.4123869-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" By adding the required syscall_cancel.S. Checked on aarch64-linux-gnu. --- .../unix/sysv/linux/aarch64/syscall_cancel.S | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/aarch64/syscall_cancel.S diff --git a/sysdeps/unix/sysv/linux/aarch64/syscall_cancel.S b/sysdeps/unix/sysv/linux/aarch64/syscall_cancel.S new file mode 100644 index 0000000000..e91a431b36 --- /dev/null +++ b/sysdeps/unix/sysv/linux/aarch64/syscall_cancel.S @@ -0,0 +1,59 @@ +/* Cancellable syscall wrapper. Linux/AArch64 version. + Copyright (C) 2023 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 + . */ + +#include +#include + +/* long int [x0] __syscall_cancel_arch (int *cancelhandling [x0], + long int nr [x1], + long int arg1 [x2], + long int arg2 [x3], + long int arg3 [x4], + long int arg4 [x5], + long int arg5 [x6], + long int arg6 [x7]) */ + +ENTRY (__syscall_cancel_arch) + + .globl __syscall_cancel_arch_start +__syscall_cancel_arch_start: + + /* if (*cancelhandling & CANCELED_BITMASK) + __syscall_do_cancel() */ + ldr w0, [x0] + tbnz w0, TCB_CANCELED_BIT, 1f + + /* Issue a 6 argument syscall, the nr [x1] being the syscall + number. */ + mov x8, x1 + mov x0, x2 + mov x1, x3 + mov x2, x4 + mov x3, x5 + mov x4, x6 + mov x5, x7 + svc 0x0 + + .globl __syscall_cancel_arch_end +__syscall_cancel_arch_end: + ret + +1: + b __syscall_do_cancel + +END (__syscall_cancel_arch) From patchwork Mon Apr 10 19:58:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 67575 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B24523856DE0 for ; Mon, 10 Apr 2023 20:00:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B24523856DE0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1681156806; bh=4c1Cdq3y3Z3nLFCWo1PuNDPNGFCLuoukjw+2JSxH5Dc=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=JJ1bZNo2IyeMbxRlLotO2jd9MHxlsAGV6LDXy6NbId+y7EKGazdJMm2hN1+nns7cz VsjSvyZophI8rI+xVK4ZqloGH/dCcIPvOGCNIegWpCR6UbycIOZl/ob6lXVTff/igf qFm/L8H76gFNtSgIZmkUrPopfUWoYPrf6AhK749E= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org 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 31B2A385772F for ; Mon, 10 Apr 2023 19:59:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 31B2A385772F Received: by mail-oa1-x2a.google.com with SMTP id 586e51a60fabf-1842cddca49so7410740fac.1 for ; Mon, 10 Apr 2023 12:59:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681156763; x=1683748763; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4c1Cdq3y3Z3nLFCWo1PuNDPNGFCLuoukjw+2JSxH5Dc=; b=VbtDJgXf2zH5/xots6B3Q0Bn+yTKxHZGU0EbcNmAcLn9Y++cDJyRU8RBj9odk5jDjE mqIZCcEPCC78LuK5MHOw7VNGSxTowZHucAy9OcnfZby7LkCl98vuTUwqWmbs0Ut0bKi/ vXvy1enOfq3e62uMCUBBAadPHnmze8mNPF3f6NAFjM9qf7HzVfvo7wVNlvSy4USFgYil hBPl36fkdaisMBSsPRK7UuTg3RIiZ4vlYbb33uCpPfRNPxCpdVFaB9FnHQWxESObZt++ yRAyhD3HcjHuYv7kUQksLw7vFIFjk+1/Uk3mA2n+k7AhOa7SqVfm21kGTLS6j3EWTrBd MsBA== X-Gm-Message-State: AAQBX9cUmw9VHr8iHSe92WJPCf2Cg/+VLysk9z3nUXVT91qHYBt02KId Nq+Uxfy8qa77DWSgqhvGAMhgvl9DLdA2L3/h17EdQA== X-Google-Smtp-Source: AKy350b+uZTbM8DSjd1GTH65g7zxWzhEstFlwr+NkwHwIJC9POCZmwj6qBk0bo9DGi69olTxEeFfuw== X-Received: by 2002:a05:6870:241b:b0:177:88c7:eff7 with SMTP id n27-20020a056870241b00b0017788c7eff7mr6637651oap.48.1681156762488; Mon, 10 Apr 2023 12:59:22 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c2:55a1:d59a:609a:284:6ed]) by smtp.gmail.com with ESMTPSA id r7-20020a9d7507000000b006a30260ccfdsm4673293otk.11.2023.04.10.12.59.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Apr 2023 12:59:21 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v5 06/22] arm: Fix Race conditions in pthread cancellation [BZ#12683] Date: Mon, 10 Apr 2023 16:58:51 -0300 Message-Id: <20230410195907.4123869-7-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230410195907.4123869-1-adhemerval.zanella@linaro.org> References: <20230410195907.4123869-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" By adding the required syscall_cancel.S. Checked on arm-linux-gnueabihf. --- sysdeps/unix/sysv/linux/arm/syscall_cancel.S | 78 ++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/arm/syscall_cancel.S diff --git a/sysdeps/unix/sysv/linux/arm/syscall_cancel.S b/sysdeps/unix/sysv/linux/arm/syscall_cancel.S new file mode 100644 index 0000000000..6b899306e3 --- /dev/null +++ b/sysdeps/unix/sysv/linux/arm/syscall_cancel.S @@ -0,0 +1,78 @@ +/* Cancellable syscall wrapper. Linux/arm version. + Copyright (C) 2023 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 + . */ + +#include +#include + +/* long int [r0] __syscall_cancel_arch (int *cancelhandling [r0], + long int nr [r1], + long int arg1 [r2], + long int arg2 [r3], + long int arg3 [SP], + long int arg4 [SP+4], + long int arg5 [SP+8], + long int arg6 [SP+12]) */ + + .syntax unified + +ENTRY (__syscall_cancel_arch) + .fnstart + mov ip, sp + stmfd sp!, {r4, r5, r6, r7, lr} + .save {r4, r5, r6, r7, lr} + + cfi_adjust_cfa_offset (20) + cfi_rel_offset (r4, 0) + cfi_rel_offset (r5, 4) + cfi_rel_offset (r6, 8) + cfi_rel_offset (r7, 12) + cfi_rel_offset (lr, 16) + + .globl __syscall_cancel_arch_start +__syscall_cancel_arch_start: + + /* if (*cancelhandling & CANCELED_BITMASK) + __syscall_do_cancel() */ + ldr r0, [r0] + tst r0, #TCB_CANCELED_BITMASK + bne 1f + + /* Issue a 6 argument syscall, the nr [r1] being the syscall + number. */ + mov r7, r1 + mov r0, r2 + mov r1, r3 + ldmfd ip, {r2, r3, r4, r5, r6} + svc 0x0 + + .globl __syscall_cancel_arch_end +__syscall_cancel_arch_end: + ldmfd sp!, {r4, r5, r6, r7, lr} + cfi_adjust_cfa_offset (-20) + cfi_restore (r4) + cfi_restore (r5) + cfi_restore (r6) + cfi_restore (r7) + cfi_restore (lr) + BX (lr) + +1: + ldmfd sp!, {r4, r5, r6, r7, lr} + b __syscall_do_cancel + .fnend +END (__syscall_cancel_arch) From patchwork Mon Apr 10 19:58:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 67579 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3076738555A8 for ; Mon, 10 Apr 2023 20:00:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3076738555A8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1681156849; bh=4De80TwHo20PxnsZL/o7uF3ZonEhm0AW3+M3iyQSSCk=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=leU+OyxOuBnRdOC1U5RQc7nZLiptvmCwwIDnDqCB0QSLoM0NRV4wHo3HfQDNEZGMT Z0FcomLiTnl48LBJ8//K5Nb2W7G0FC7AeAplaCS/clexT4lMPOkdQhx84jf7oxrYr0 4ptj5U5mJlR/KjKc6wudlMT4/TJmjY+S43uuiWdY= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x334.google.com (mail-ot1-x334.google.com [IPv6:2607:f8b0:4864:20::334]) by sourceware.org (Postfix) with ESMTPS id F28E93857712 for ; Mon, 10 Apr 2023 19:59:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F28E93857712 Received: by mail-ot1-x334.google.com with SMTP id q5-20020a056830232500b006a11eb19f8eso2147425otg.5 for ; Mon, 10 Apr 2023 12:59:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681156764; x=1683748764; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4De80TwHo20PxnsZL/o7uF3ZonEhm0AW3+M3iyQSSCk=; b=QSiJXX1TtQo37hfhoRtdpS4Go+mQ77zo6mII4qVRGPgVvmiTSQyZWX/zPCyxDPffTu LndFKEG81m8+9rhQ5ujieXNizscbCN1duDvDvWUjzfHBNtxBu7mOyyC9FY35zdyDiJVz EIoWrfLK0cs/L+iytlwQGcTiqFsnT2An90Pv9icOVK5bWM5cox91TiLLUbzqTZJK5sUl oSsIifKF8AJ2xEU9bXeGRJF2ES7yT+DW53tP9cMhH3Rbju27zI8EQSvCnWLi3vBcBJA7 yyPElhfDVvBz8oHkl9vmRWrh+Enw/3ajY3EQXF09UjorOQkw4LXm6r7k375dM0/8sRWg 4BPA== X-Gm-Message-State: AAQBX9eISgF13HaoMJTqwDQFFh/BJq3nvV1gzN8PTd8TRFFo2f6c0wLK 5fsloGLdwj+j+dejnr1EuDjDnbbjOeVj8YQiJumQog== X-Google-Smtp-Source: AKy350a0GdUYv7V9uWwq2T3XEKBFHETaO7MJmKXtEi7cKZZ2qj18oIb0E3mqYpwd91RxAw1HkxHzMA== X-Received: by 2002:a9d:4e8d:0:b0:697:a381:a8f8 with SMTP id v13-20020a9d4e8d000000b00697a381a8f8mr317757otk.3.1681156764527; Mon, 10 Apr 2023 12:59:24 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c2:55a1:d59a:609a:284:6ed]) by smtp.gmail.com with ESMTPSA id r7-20020a9d7507000000b006a30260ccfdsm4673293otk.11.2023.04.10.12.59.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Apr 2023 12:59:23 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v5 07/22] powerpc: Fix Race conditions in pthread cancellation [BZ#12683] Date: Mon, 10 Apr 2023 16:58:52 -0300 Message-Id: <20230410195907.4123869-8-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230410195907.4123869-1-adhemerval.zanella@linaro.org> References: <20230410195907.4123869-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" By adding the required syscall_cancel.S. Checked on powerpc64le-linux-gnu, powerpc64-linux-gnu and powerpc-linux-gnu. Reviewed-by: Paul E. Murphy --- sysdeps/powerpc/powerpc32/sysdep.h | 3 + sysdeps/powerpc/powerpc64/sysdep.h | 19 ++++++ .../unix/sysv/linux/powerpc/syscall_cancel.S | 65 +++++++++++++++++++ 3 files changed, 87 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/powerpc/syscall_cancel.S diff --git a/sysdeps/powerpc/powerpc32/sysdep.h b/sysdeps/powerpc/powerpc32/sysdep.h index 095a726765..df67e3516a 100644 --- a/sysdeps/powerpc/powerpc32/sysdep.h +++ b/sysdeps/powerpc/powerpc32/sysdep.h @@ -104,6 +104,9 @@ GOT_LABEL: ; \ # define JUMPTARGET(name) name #endif +#define TAIL_CALL_NO_RETURN(__func) \ + b __func@local + #if defined SHARED && defined PIC && !defined NO_HIDDEN # undef HIDDEN_JUMPTARGET # define HIDDEN_JUMPTARGET(name) __GI_##name##@local diff --git a/sysdeps/powerpc/powerpc64/sysdep.h b/sysdeps/powerpc/powerpc64/sysdep.h index ce92d8b3d2..1815131dc2 100644 --- a/sysdeps/powerpc/powerpc64/sysdep.h +++ b/sysdeps/powerpc/powerpc64/sysdep.h @@ -352,6 +352,25 @@ LT_LABELSUFFIX(name,_name_end): ; \ ENTRY (name); \ DO_CALL (SYS_ify (syscall_name)) +#ifdef SHARED +# define TAIL_CALL_NO_RETURN(__func) \ + b JUMPTARGET(__func) +#else +# define TAIL_CALL_NO_RETURN(__func) \ + .ifdef .Local ## __func; \ + b .Local ## __func; \ + .else; \ +.Local ## __func: \ + mflr 0; \ + std 0,FRAME_LR_SAVE(1); \ + stdu 1,-FRAME_MIN_SIZE(1); \ + cfi_adjust_cfa_offset(FRAME_MIN_SIZE); \ + cfi_offset(lr,FRAME_LR_SAVE); \ + bl JUMPTARGET(__func); \ + nop; \ + .endif +#endif + #ifdef SHARED #define TAIL_CALL_SYSCALL_ERROR \ b JUMPTARGET (NOTOC (__syscall_error)) diff --git a/sysdeps/unix/sysv/linux/powerpc/syscall_cancel.S b/sysdeps/unix/sysv/linux/powerpc/syscall_cancel.S new file mode 100644 index 0000000000..7aa2b77caa --- /dev/null +++ b/sysdeps/unix/sysv/linux/powerpc/syscall_cancel.S @@ -0,0 +1,65 @@ +/* Cancellable syscall wrapper. Linux/powerpc version. + Copyright (C) 2023 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 + . */ + +#include +#include + +/* long int [r3] __syscall_cancel_arch (int *cancelhandling [r3], + long int nr [r4], + long int arg1 [r5], + long int arg2 [r6], + long int arg3 [r7], + long int arg4 [r8], + long int arg5 [r9], + long int arg6 [r10]) */ + +ENTRY (__syscall_cancel_arch) + + .globl __syscall_cancel_arch_start +__syscall_cancel_arch_start: + + /* if (*cancelhandling & CANCELED_BITMASK) + __syscall_do_cancel() */ + lwz r0,0(r3) + andi. r0,r0,TCB_CANCELED_BITMASK + bne- 1f + + /* Issue a 6 argument syscall, the nr [r4] being the syscall + number. */ + mr r0,r4 + mr r3,r5 + mr r4,r6 + mr r5,r7 + mr r6,r8 + mr r7,r9 + mr r8,r10 + sc + + .globl __syscall_cancel_arch_end +__syscall_cancel_arch_end: + + bnslr+ + neg r3,r3 + blr + + /* Although the __syscall_do_cancel do not return, we need to stack + being set correctly for unwind. */ +1: + TAIL_CALL_NO_RETURN (__syscall_do_cancel) + +END (__syscall_cancel_arch) From patchwork Mon Apr 10 19:58:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 67580 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 63504385697A for ; Mon, 10 Apr 2023 20:01:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 63504385697A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1681156891; bh=vuz0tFwOarGWknGLvIQpj2ojEdwLGgk7PSoRumb7nA4=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=AJ/3M7fXu/0DHqXnYD18U9X170eM+W0UeeCBQNkcVmqXqyJFXUHTQ0RR0GIudWviA qx3+GS4K7oM1zDVPkRpBiA4CaBRuFeBQLesXLnPaq24gv08+JsC/8Pnqk//+bv1tw1 r/I96zEI3IyvDiC40/iQP1z6jDlYs8rKNKxq3gmI= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x333.google.com (mail-ot1-x333.google.com [IPv6:2607:f8b0:4864:20::333]) by sourceware.org (Postfix) with ESMTPS id 08D3E385771B for ; Mon, 10 Apr 2023 19:59:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 08D3E385771B Received: by mail-ot1-x333.google.com with SMTP id cg19-20020a056830631300b0069f922cd5ceso2793445otb.12 for ; Mon, 10 Apr 2023 12:59:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681156767; x=1683748767; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vuz0tFwOarGWknGLvIQpj2ojEdwLGgk7PSoRumb7nA4=; b=18yG0g6exYak1z93IiPuqUGDVBsKp3jcBGLw8QRHnfWsu8ODcbyHcEcUfN9/nvjQZL C4aTTMBSH439qQJZz2JuOBdBGgLjN/YQ/FLuCUZusOkIsxt7A8EbhFwwLsHq8FdWXnPf ArHqh7cn9da4uXi74GWM/EEHRRwSPtIXVNwONhPHvfgxq5cPW7X3DJnv7SzPSt7IZ6xV zNt6iyOz6YesSHVTTbxEYRd4HeOFlM9iy0wktCAHmZVqGFVfpCgLN/V/OHWXZqpgF6KQ ft9S17A2eAjixbs0H88J1fnYyYuRqUsqhpR0TMQ9bgao/tYv68bj7V/QL+2SORpmjGTp 4NlA== X-Gm-Message-State: AAQBX9cZ8p6ozFCWaDANHv94tJ2LAHA6K95bjFLsWSC+l0ub6mV4aNOz tYWl6hSt78IOW9OQdJ+RYYMUB2Iyz/h2UDjfTKu1HQ== X-Google-Smtp-Source: AKy350Z4McA3+Qi9zINJcX2RSj4jT1h+g0Qt40aMN1ir7rkl+7otHRRUChaog5+b3lTec4Lgw6qztA== X-Received: by 2002:a05:6830:10cd:b0:6a1:3d16:1c69 with SMTP id z13-20020a05683010cd00b006a13d161c69mr260149oto.22.1681156766466; Mon, 10 Apr 2023 12:59:26 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c2:55a1:d59a:609a:284:6ed]) by smtp.gmail.com with ESMTPSA id r7-20020a9d7507000000b006a30260ccfdsm4673293otk.11.2023.04.10.12.59.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Apr 2023 12:59:25 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v5 08/22] sparc: Fix Race conditions in pthread cancellation [BZ#12683] Date: Mon, 10 Apr 2023 16:58:53 -0300 Message-Id: <20230410195907.4123869-9-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230410195907.4123869-1-adhemerval.zanella@linaro.org> References: <20230410195907.4123869-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" By adding the required syscall_cancel.S. Checked on sparc64-linux-gnu and sparcv9-linux-gnu. --- .../sysv/linux/sparc/sparc32/syscall_cancel.S | 71 ++++++++++++++++++ .../sysv/linux/sparc/sparc64/syscall_cancel.S | 74 +++++++++++++++++++ 2 files changed, 145 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/sparc/sparc32/syscall_cancel.S create mode 100644 sysdeps/unix/sysv/linux/sparc/sparc64/syscall_cancel.S diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/syscall_cancel.S b/sysdeps/unix/sysv/linux/sparc/sparc32/syscall_cancel.S new file mode 100644 index 0000000000..aa5c658ce1 --- /dev/null +++ b/sysdeps/unix/sysv/linux/sparc/sparc32/syscall_cancel.S @@ -0,0 +1,71 @@ +/* Cancellable syscall wrapper. Linux/sparc32 version. + Copyright (C) 2023 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 + . */ + +#include +#include + +/* long int __syscall_cancel_arch (int *cancelhandling, + long int nr, + long int arg1, + long int arg2, + long int arg3, + long int arg4, + long int arg5, + long int arg6) */ + +ENTRY (__syscall_cancel_arch) + save %sp, -96, %sp + + cfi_window_save + cfi_register (%o7, %i7) + cfi_def_cfa_register (%fp) + + .globl __syscall_cancel_arch_start +__syscall_cancel_arch_start: + + /* if (*cancelhandling & CANCELED_BITMASK) + __syscall_do_cancel() */ + ld [%i0], %g2 + andcc %g2, TCB_CANCELED_BITMASK, %g0 + bne,pn %icc, 2f + /* Issue a 6 argument syscall. */ + mov %i1, %g1 + mov %i2, %o0 + mov %i3, %o1 + mov %i4, %o2 + mov %i5, %o3 + ld [%fp+92], %o4 + ld [%fp+96], %o5 + ta 0x10 + + .globl __syscall_cancel_arch_end +__syscall_cancel_arch_end: + bcc 1f + nop + sub %g0, %o0, %o0 +1: + mov %o0, %i0 + return %i7+8 + nop + +2: + call __syscall_do_cancel, 0 + nop + nop + +END (__syscall_cancel_arch) diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/syscall_cancel.S b/sysdeps/unix/sysv/linux/sparc/sparc64/syscall_cancel.S new file mode 100644 index 0000000000..21b0728d5a --- /dev/null +++ b/sysdeps/unix/sysv/linux/sparc/sparc64/syscall_cancel.S @@ -0,0 +1,74 @@ +/* Cancellable syscall wrapper. Linux/sparc64 version. + Copyright (C) 2023 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 + . */ + +#include +#include + + .register %g2, #scratch + +/* long int __syscall_cancel_arch (int *cancelhandling, + long int nr, + long int arg1, + long int arg2, + long int arg3, + long int arg4, + long int arg5, + long int arg6) */ + +ENTRY (__syscall_cancel_arch) + save %sp, -176, %sp + + cfi_window_save + cfi_register (%o7, %i7) + cfi_def_cfa_register (%fp) + + .globl __syscall_cancel_arch_start +__syscall_cancel_arch_start: + + /* if (*cancelhandling & CANCELED_BITMASK) + __syscall_do_cancel() */ + lduw [%i0], %g2 + andcc %g2, TCB_CANCELED_BITMASK, %g0 + bne,pn %xcc, 2f + /* Issue a 6 argument syscall. */ + mov %i1, %g1 + mov %i2, %o0 + mov %i3, %o1 + mov %i4, %o2 + mov %i5, %o3 + ldx [%fp + STACK_BIAS + 176], %o4 + ldx [%fp + STACK_BIAS + 184], %o5 + ta 0x6d + + .global __syscall_cancel_arch_end +__syscall_cancel_arch_end: + + bcc,pt %xcc, 1f + nop + sub %g0, %o0, %o0 +1: + mov %o0, %i0 + return %i7+8 + nop + +2: + call __syscall_do_cancel, 0 + nop + nop + +END (__syscall_cancel_arch) From patchwork Mon Apr 10 20:46:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 67581 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 590D53857355 for ; Mon, 10 Apr 2023 20:46:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 590D53857355 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1681159609; bh=K/VBgc9zznEiY2NV0YnyGInj4MHJsCE33/YMLfAVCy4=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=foKIh3p2OR0D3JSiFxMUz8njmseh/fpiNiasbawmIIhB/G/TMF94podioPcZ1SkEx VHpEqoe9pRZAv8HBSL6ozInjKAqpZPxspGMHmI4eFsNoUN0rJ8LYJSmC706VAPQaWA lf7WJCw+fnxHfXRk+NjQ1/bteYVQ6PwOqa7iihrc= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oi1-x229.google.com (mail-oi1-x229.google.com [IPv6:2607:f8b0:4864:20::229]) by sourceware.org (Postfix) with ESMTPS id 537893858D38 for ; Mon, 10 Apr 2023 20:46:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 537893858D38 Received: by mail-oi1-x229.google.com with SMTP id bh10so4124421oib.1 for ; Mon, 10 Apr 2023 13:46:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681159582; x=1683751582; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=K/VBgc9zznEiY2NV0YnyGInj4MHJsCE33/YMLfAVCy4=; b=Xe/+WpvqXkbfDyBMXqTKSYPuEZueo+nAnYNNxU/34tuAhGdaulE/h1ug7Kaj7nkJSZ 9FmUWTtzFxtSV6vyYCGCbSLOD2jauvP18ohr2AYwX2Z7u0t+IhSHahs6xbCF/5K+381c H28mlA3soIHWYI9m37wNXSWJ5ZEDZrOsGcSy3m+UCfhik0EQekUx+SRd7upWIcFlJG/N vKGObW/lOU/Ys/Zy8ep6zsoNdY734lVfrK5Uu4vz4WA5QAhSPK4XP0YtLFrqVOlEfev7 v1pMknpYVmd6bkOyR0+2S/Q7O/rsBgO5kIzw3dEMjoYziivzdqO+kAM401Pp6DAh/SLt xK4w== X-Gm-Message-State: AAQBX9e7p03l7hwBRud0jaL/05zVRYNw66lj68AFITTqXNrQX4c/a/nJ zeo+UD50sNVzkmfEBbp9cOT4PW2aT27PUCWRrpTwBA== X-Google-Smtp-Source: AKy350ZUJnH6xbwZucprFnKGsLKTuw61plxx2nsYaAoaInzjztEO/TmE3xzWtDz9ciuZXXals740cA== X-Received: by 2002:a54:470c:0:b0:38b:d8a9:9db1 with SMTP id k12-20020a54470c000000b0038bd8a99db1mr301059oik.43.1681159580332; Mon, 10 Apr 2023 13:46:20 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c2:55a1:d59a:609a:284:6ed]) by smtp.gmail.com with ESMTPSA id p5-20020acabf05000000b003896f132821sm4865732oif.41.2023.04.10.13.46.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Apr 2023 13:46:19 -0700 (PDT) To: libc-alpha@sourceware.org Cc: Stefan Liebler Subject: [PATCH v5 09/22] s390: Fix Race conditions in pthread cancellation [BZ#12683] Date: Mon, 10 Apr 2023 17:46:01 -0300 Message-Id: <20230410204614.4129551-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230410195907.4123869-1-adhemerval.zanella@linaro.org> References: <20230410195907.4123869-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" By adding the required syscall_cancel.S. Checked on s390-linux-gnu and s390x-linux-gnu. Co-authored-by: Stefan Liebler --- .../sysv/linux/s390/s390-32/syscall_cancel.S | 62 +++++++++++++++++++ .../sysv/linux/s390/s390-64/syscall_cancel.S | 62 +++++++++++++++++++ 2 files changed, 124 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/s390/s390-32/syscall_cancel.S create mode 100644 sysdeps/unix/sysv/linux/s390/s390-64/syscall_cancel.S diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/syscall_cancel.S b/sysdeps/unix/sysv/linux/s390/s390-32/syscall_cancel.S new file mode 100644 index 0000000000..9e0ad2a635 --- /dev/null +++ b/sysdeps/unix/sysv/linux/s390/s390-32/syscall_cancel.S @@ -0,0 +1,62 @@ +/* Cancellable syscall wrapper. Linux/s390 version. + Copyright (C) 2023 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 + . */ + +#include +#include + +/* long int __syscall_cancel_arch (int *cancelhandling, + __syscall_arg_t nr, + __syscall_arg_t arg1, + __syscall_arg_t arg2, + __syscall_arg_t arg3, + __syscall_arg_t arg4, + __syscall_arg_t arg5, + __syscall_arg_t arg6) */ + +ENTRY (__syscall_cancel_arch) + stm %r6,%r7,24(%r15) + cfi_offset (%r6, -72) + cfi_offset (%r7, -68) + + .globl __syscall_cancel_arch_start +__syscall_cancel_arch_start: + /* if (*cancelhandling & CANCELED_BITMASK) + __syscall_do_cancel() */ + tm 3(%r2),TCB_CANCELED_BITMASK + jne 1f + + /* Issue a 6 argument syscall, the nr [%r1] being the syscall + number. */ + lr %r1,%r3 + lr %r2,%r4 + lr %r3,%r5 + lr %r4,%r6 + lm %r5,%r7,96(%r15) + svc 0 + + .globl __syscall_cancel_arch_end +__syscall_cancel_arch_end: + lm %r6,%r7,24(%r15) + cfi_remember_state + cfi_restore (%r7) + cfi_restore (%r6) + br %r14 +1: + cfi_restore_state + jg __syscall_do_cancel +END (__syscall_cancel_arch) diff --git a/sysdeps/unix/sysv/linux/s390/s390-64/syscall_cancel.S b/sysdeps/unix/sysv/linux/s390/s390-64/syscall_cancel.S new file mode 100644 index 0000000000..e1620add6a --- /dev/null +++ b/sysdeps/unix/sysv/linux/s390/s390-64/syscall_cancel.S @@ -0,0 +1,62 @@ +/* Cancellable syscall wrapper. Linux/s390x version. + Copyright (C) 2023 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 + . */ + +#include +#include + +/* long int __syscall_cancel_arch (int *cancelhandling, + __syscall_arg_t nr, + __syscall_arg_t arg1, + __syscall_arg_t arg2, + __syscall_arg_t arg3, + __syscall_arg_t arg4, + __syscall_arg_t arg5, + __syscall_arg_t arg6) */ + +ENTRY (__syscall_cancel_arch) + stmg %r6,%r7,48(%r15) + cfi_offset (%r6, -112) + cfi_offset (%r7, -104) + + .globl __syscall_cancel_arch_start +__syscall_cancel_arch_start: + /* if (*cancelhandling & CANCELED_BITMASK) + __syscall_do_cancel() */ + tm 3(%r2),TCB_CANCELED_BITMASK + jne 1f + + /* Issue a 6 argument syscall, the nr [%r1] being the syscall + number. */ + lgr %r1,%r3 + lgr %r2,%r4 + lgr %r3,%r5 + lgr %r4,%r6 + lmg %r5,%r7,160(%r15) + svc 0 + + .globl __syscall_cancel_arch_end +__syscall_cancel_arch_end: + lmg %r6,%r7,48(%r15) + cfi_remember_state + cfi_restore (%r7) + cfi_restore (%r6) + br %r14 +1: + cfi_restore_state + jg __syscall_do_cancel +END (__syscall_cancel_arch) From patchwork Mon Apr 10 20:46:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 67582 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6F7D93856947 for ; Mon, 10 Apr 2023 20:46:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6F7D93856947 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1681159610; bh=G2KtuY6ABrOdTmyYx3FKChSr/BBKWFQ+inuuVnqWZMQ=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=e6gFPcprZH/Bpjz1pPUsUMFe6ADuEWNoFnceT/X/gHrJxcxtT6lImVjHyHnetIJSk PJt3WleQEELWPcjnJ9fxhMe/ht80tXELJVJy8EWXxY/0a4Nl/hmokGWhu5PAFIIwBv 8TxfB3cCC7IUUjXh0T7A2MMBWS7eRdf8pWvKfdWM= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oi1-x22f.google.com (mail-oi1-x22f.google.com [IPv6:2607:f8b0:4864:20::22f]) by sourceware.org (Postfix) with ESMTPS id C10803858C5E for ; Mon, 10 Apr 2023 20:46:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C10803858C5E Received: by mail-oi1-x22f.google.com with SMTP id f14so22454778oiw.10 for ; Mon, 10 Apr 2023 13:46:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681159583; x=1683751583; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=G2KtuY6ABrOdTmyYx3FKChSr/BBKWFQ+inuuVnqWZMQ=; b=GdXH6uf3ZN564z/2UxAmyUxhHAbGf892n2tF81fdvOzyLO99TeBSjHKFHjsd+OMP5V WWyR3oWfV9ZHML1hTlLJa56dQ/Zpo5ZrQbXVKNZUPhj0nDGIdOQiLaYim2ds88Zqenh4 b4kPfSfJNJ4X/kIdAc0Hff3wEjdly5mR0ufwDJUN5LQVCTVeGskRKFjiD12wWwi0vLpC Ln1zjBBfhAecjo4DlrN5p3Fe+T7VWaB1kBZBu24cCO5nrK8e2/9r0/RXf4RQAmjInact QK35HzwgLxJjJLwZ7j878dN6Ug+aKbEUe1r3nBJWFcrPjUllpF8QZTNchqqSv9EUI6YF rY6w== X-Gm-Message-State: AAQBX9dGFuxL0/ifMDs7YSYHLyJnH7e4N7kuMrtvZ4ETyPWZaXkyGlw+ EyULaxcJkv2NbEuS6RXmTDuOel40sxMPNZyvH1mcxg== X-Google-Smtp-Source: AKy350Y+4fTrQ3jNn/X2Zcz89v2Cuy9m2YigzniYGtL9erhaszruwGzZZg9FGuGlO4nzxw8mv30DZg== X-Received: by 2002:a05:6808:919:b0:388:f18a:37db with SMTP id w25-20020a056808091900b00388f18a37dbmr5661579oih.0.1681159582067; Mon, 10 Apr 2023 13:46:22 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c2:55a1:d59a:609a:284:6ed]) by smtp.gmail.com with ESMTPSA id p5-20020acabf05000000b003896f132821sm4865732oif.41.2023.04.10.13.46.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Apr 2023 13:46:21 -0700 (PDT) To: libc-alpha@sourceware.org Cc: Andrew Waterman Subject: [PATCH v5 10/22] riscv: Fix Race conditions in pthread cancellation [BZ#12683] Date: Mon, 10 Apr 2023 17:46:02 -0300 Message-Id: <20230410204614.4129551-2-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230410204614.4129551-1-adhemerval.zanella@linaro.org> References: <20230410195907.4123869-1-adhemerval.zanella@linaro.org> <20230410204614.4129551-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" By adding the required syscall_cancel.S. Reviewed-by: Andrew Waterman --- .../unix/sysv/linux/riscv/syscall_cancel.S | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/riscv/syscall_cancel.S diff --git a/sysdeps/unix/sysv/linux/riscv/syscall_cancel.S b/sysdeps/unix/sysv/linux/riscv/syscall_cancel.S new file mode 100644 index 0000000000..742c748d09 --- /dev/null +++ b/sysdeps/unix/sysv/linux/riscv/syscall_cancel.S @@ -0,0 +1,67 @@ +/* Cancellable syscall wrapper. Linux/riscv version. + Copyright (C) 2023 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 + . */ + +#include +#include + +/* long int __syscall_cancel_arch (int *cancelhandling, + __syscall_arg_t nr, + __syscall_arg_t arg1, + __syscall_arg_t arg2, + __syscall_arg_t arg3, + __syscall_arg_t arg4, + __syscall_arg_t arg5, + __syscall_arg_t arg6) */ + +#ifdef SHARED + .option pic +#else + .option nopic +#endif + +ENTRY (__syscall_cancel_arch) + + .globl __syscall_cancel_arch_start +__syscall_cancel_arch_start: + lw t1, 0(a0) + /* if (*ch & CANCELED_BITMASK) */ + andi t1, t1, TCB_CANCELED_BITMASK + bne t1, zero, 1f + + mv t3, a1 + mv a0, a2 + mv a1, a3 + mv a2, a4 + mv a3, a5 + mv a4, a6 + mv a5, a7 + mv a7, t3 + scall + + .globl __syscall_cancel_arch_end +__syscall_cancel_arch_end: + ret + +1: + addi sp, sp, -16 + cfi_def_cfa_offset (16) + REG_S ra, (16-SZREG)(sp) + cfi_offset (ra, -SZREG) + call __syscall_do_cancel + +END (__syscall_cancel_arch) From patchwork Mon Apr 10 20:46:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 67586 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0B53D3856973 for ; Mon, 10 Apr 2023 20:47:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0B53D3856973 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1681159653; bh=X8hQ9l79CLZQ+5d5bwfqB6Kl4hUTqaolhYhB2jWtcBA=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=bdf1TybG6nXPIpCEuBzlvDwlBvadMsWBX7HH9/QZdi5jtXVLvK72XOqicNYF45Qsl 0YetIPl3H1DUJcWBTPfbz8FcE/YSRIpWCUY5sSiVwE70Iupv9C3EUau8jpMTM8DyRD k+iZBCsBEyvb/2i2Ez1+Sd2pWyOHrKEPlA/irFSQ= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oi1-x233.google.com (mail-oi1-x233.google.com [IPv6:2607:f8b0:4864:20::233]) by sourceware.org (Postfix) with ESMTPS id 700C73858C62 for ; Mon, 10 Apr 2023 20:46:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 700C73858C62 Received: by mail-oi1-x233.google.com with SMTP id bf5so4072924oib.8 for ; Mon, 10 Apr 2023 13:46:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681159584; x=1683751584; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=X8hQ9l79CLZQ+5d5bwfqB6Kl4hUTqaolhYhB2jWtcBA=; b=7NX22pF/SZxHxRVZXxgXyGKlTyNiBuErWPtF/34znKEbrGg4DRn9BUiVYHa6slxrL3 ZGs8Cp92QCVvwQFPRn6k5wKN2i5NXQi2b/ftezbs4+TpplD17dx5Cr1D41z5OuZ+yf59 PwZ/W/In/qrEWH4LcKGAHUlgUGO0VmYkUD0Cf13hHwY5AQTPZSkb3KFTKTVLKdDCpcFV RVKWS3NHiPYzjeES7PbaIVr/Z2BhQq0tLFFaB1HS6FWEzaq0WU9eUNVha+0Tv4ojoWqC IUEdXzg1E7Ky7WhS7bdsw62gmZjo9J47aVspzpEtOrV5WnXLuY39WWkhLM0Ch2ROU9sv Szig== X-Gm-Message-State: AAQBX9djFKfdWsb5NG4eLEoEDUeYf7EpQxdIYr74Bad6Ufcktp5HUTut uxRlp0a1M0Q188bjN1HQA74VHizsPypG5BX3OlNrVA== X-Google-Smtp-Source: AKy350Z2N2g25Ouqtku451bZaPlx6+ipzY6AbamX+edsmrU6yhYzxwwubNHPN1chmLpCmCx9xwzyaw== X-Received: by 2002:a05:6808:1805:b0:389:6b98:32db with SMTP id bh5-20020a056808180500b003896b9832dbmr5824456oib.14.1681159583740; Mon, 10 Apr 2023 13:46:23 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c2:55a1:d59a:609a:284:6ed]) by smtp.gmail.com with ESMTPSA id p5-20020acabf05000000b003896f132821sm4865732oif.41.2023.04.10.13.46.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Apr 2023 13:46:23 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v5 11/22] arc: Fix Race conditions in pthread cancellation [BZ #12683] Date: Mon, 10 Apr 2023 17:46:03 -0300 Message-Id: <20230410204614.4129551-3-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230410204614.4129551-1-adhemerval.zanella@linaro.org> References: <20230410195907.4123869-1-adhemerval.zanella@linaro.org> <20230410204614.4129551-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" By adding the required syscall_cancel.S. Checked against a build and make check run-built-tests=no for arc-linux-gnu, arc-linux-gnuhf, and arceb-linux-gnu. --- sysdeps/unix/sysv/linux/arc/syscall_cancel.S | 56 ++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/arc/syscall_cancel.S diff --git a/sysdeps/unix/sysv/linux/arc/syscall_cancel.S b/sysdeps/unix/sysv/linux/arc/syscall_cancel.S new file mode 100644 index 0000000000..fa02af4163 --- /dev/null +++ b/sysdeps/unix/sysv/linux/arc/syscall_cancel.S @@ -0,0 +1,56 @@ +/* Cancellable syscall wrapper. Linux/ARC version. + Copyright (C) 2023 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 + . */ + +#include +#include + +/* long int __syscall_cancel_arch (int *cancelhandling, + __syscall_arg_t nr, + __syscall_arg_t arg1, + __syscall_arg_t arg2, + __syscall_arg_t arg3, + __syscall_arg_t arg4, + __syscall_arg_t arg5, + __syscall_arg_t arg6) */ + +ENTRY (__syscall_cancel_arch) + + .globl __syscall_cancel_arch_start +__syscall_cancel_arch_start: + ld_s r12,[r0] + bbit1 r12, TCB_CANCELED_BITMASK, 1f + mov_s r8, r1 + mov_s r0, r2 + mov_s r1, r3 + mov_s r2, r4 + mov_s r3, r5 + mov_s r4, r6 + mov_s r5, r7 + trap_s 0 + + .globl __syscall_cancel_arch_end +__syscall_cancel_arch_end: + j_s [blink] + + .align 4 +1: push_s blink + cfi_def_cfa_offset (4) + cfi_offset (31, -4) + bl @__syscall_do_cancel + +END (__syscall_cancel_arch) From patchwork Mon Apr 10 20:46:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 67589 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7BD53385380E for ; Mon, 10 Apr 2023 20:48:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7BD53385380E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1681159695; bh=n7wxa6s7iaJNdj/idNrqx354NeTtAmAHFFfdpcN8hwM=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=VDBqFTgvPVE4fYHW4Sc/66MuxDopXAS22B8eiYEJoX8u2LB3Sl1RINIk/gUFBIiqf QDAGNhcD6X2VihZUcCIZ/M6LiiVPyHe4ADHu9fLzDp90w/gGZU85CEQr7XSNMAQhdV nxoDEQrdU+lKUPnZgyD6+HaZNgq8y2ZNebA+9HkI= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oi1-x234.google.com (mail-oi1-x234.google.com [IPv6:2607:f8b0:4864:20::234]) by sourceware.org (Postfix) with ESMTPS id 610BE3858C5E for ; Mon, 10 Apr 2023 20:46:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 610BE3858C5E Received: by mail-oi1-x234.google.com with SMTP id w19so4030099oiv.13 for ; Mon, 10 Apr 2023 13:46:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681159587; x=1683751587; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=n7wxa6s7iaJNdj/idNrqx354NeTtAmAHFFfdpcN8hwM=; b=XQ6RmbDSZDQe9yl8Lb7Z15h5fZNm0ZYwDnC3jkZuLhlq8YVY83DnchG19djr4GWm+v CjIaStqa4hr9h7/RgSfFgUKgADMsgF2Wa1Hviy57w2alpyqjjVBtYf1ncIHyKh7LkUFl 0pplQtlQWZuA1vRxm1k6cspJtN0f6C32GuB6+zbRds5lcUKb66c5AE2UsSFrVGblUwCA NIEqsWT+fkDppN5RVEGMBIsUS2AiicgIuNjyCPSpqPY4zMpnHKVibpgUr0u3/hlt4omf SmO8A4ihxCp569y62fOmJniyVruJlLUF7Fra9Ca8ZRuDNw9hPzf/pso8RyG80GS09r7D 7psw== X-Gm-Message-State: AAQBX9cLxq6Euti7UzANi60kwVgid13TQAa8hAutYKkRFEx3gBfXkWEX Zg/SHbfLjlqwG+cVaT8j/nzMBzi93XJfFdJ8Ao7IkA== X-Google-Smtp-Source: AKy350ZBeQsvbodoSnIIc8vNE/U3SkyhKzTdtgglSNlclOULDTnPJANTWR3+tCdZT9+v8kdcrb8TnQ== X-Received: by 2002:a05:6808:2002:b0:389:92d0:c073 with SMTP id q2-20020a056808200200b0038992d0c073mr7093829oiw.23.1681159585567; Mon, 10 Apr 2023 13:46:25 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c2:55a1:d59a:609a:284:6ed]) by smtp.gmail.com with ESMTPSA id p5-20020acabf05000000b003896f132821sm4865732oif.41.2023.04.10.13.46.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Apr 2023 13:46:24 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v5 12/22] ia64: Fix Race conditions in pthread cancellation [BZ#12683] Date: Mon, 10 Apr 2023 17:46:04 -0300 Message-Id: <20230410204614.4129551-4-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230410204614.4129551-1-adhemerval.zanella@linaro.org> References: <20230410195907.4123869-1-adhemerval.zanella@linaro.org> <20230410204614.4129551-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" The syscall bridge uses the old brk 0x10000 instruction because by using the vDSO gate the resulting PC value for an interrupted syscall points to an address outside the expected markers in __syscall_cancel_arch. This is similar to i686 issue. Also the __syscall_cancel_arch issues the 'break 0x100000' on its own bundle, and __syscall_cancel_arch_end points to end of the previous one. It requires an arch-specific ucontext_check_pc_boundary to check for the ri value (embedded in the sc_ip by the kernel) to check if the syscall had any side-effects. Checked on ia64-linux-gnu. --- .../sysv/linux/ia64/cancellation-pc-check.h | 48 +++++++++++ sysdeps/unix/sysv/linux/ia64/syscall_cancel.S | 81 +++++++++++++++++++ 2 files changed, 129 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/ia64/cancellation-pc-check.h create mode 100644 sysdeps/unix/sysv/linux/ia64/syscall_cancel.S diff --git a/sysdeps/unix/sysv/linux/ia64/cancellation-pc-check.h b/sysdeps/unix/sysv/linux/ia64/cancellation-pc-check.h new file mode 100644 index 0000000000..24f05f9759 --- /dev/null +++ b/sysdeps/unix/sysv/linux/ia64/cancellation-pc-check.h @@ -0,0 +1,48 @@ +/* Architecture specific bits for cancellation handling. + Copyright (C) 2023 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 + . */ + +#ifndef _NPTL_CANCELLATION_PC_CHECK +#define _NPTL_CANCELLATION_PC_CHECK 1 + +/* Check if the program counter (PC) from ucontext CTX is within the start and + then end boundary from the __syscall_cancel_arch bridge. Return TRUE if + the PC is within the boundary, meaning the syscall does not have any side + effects; or FALSE otherwise. */ +static bool +cancellation_pc_check (void *ctx) +{ + /* Both are defined in syscall_cancel.S for each architecture. */ + extern const char __syscall_cancel_arch_start[1]; + extern const char __syscall_cancel_arch_end[1]; + + uintptr_t sc_ip = ((struct sigcontext *) (ctx))->sc_ip; + uintptr_t cr_iip = sc_ip & ~0x3ull; + uintptr_t ri = sc_ip & 0x3ull; + + /* IA64 __syscall_cancel_arch issues the 'break 0x100000' on its own bundle, + and __syscall_cancel_arch_end points to end of the previous bundle. + To check if the syscall had any side-effects we need to check the slot + number. */ + if (cr_iip == (uintptr_t) __syscall_cancel_arch_end) + return ri == 0; + + return cr_iip >= (uintptr_t) __syscall_cancel_arch_start + && cr_iip < (uintptr_t) __syscall_cancel_arch_end; +} + +#endif diff --git a/sysdeps/unix/sysv/linux/ia64/syscall_cancel.S b/sysdeps/unix/sysv/linux/ia64/syscall_cancel.S new file mode 100644 index 0000000000..732bf60185 --- /dev/null +++ b/sysdeps/unix/sysv/linux/ia64/syscall_cancel.S @@ -0,0 +1,81 @@ +/* Cancellable syscall wrapper. Linux/IA64 version. + Copyright (C) 2023 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 + . */ + +#include +#include +#undef ret + +/* long int __syscall_cancel_arch (int *cancelhandling, long int nr, + long int arg1, long int arg2, long int arg3, + long int arg4, long int arg5, long int arg6) +*/ + +ENTRY (__syscall_cancel_arch) + .prologue ASM_UNW_PRLG_RP | ASM_UNW_PRLG_PFS, ASM_UNW_PRLG_GRSAVE (8) + .mmi + .save ar.pfs, r41 + alloc r41=ar.pfs,8,3,8,0 + mov r15=r33 + .save rp, r40 + mov r40=b0 + .body + .mmi + mov r43=r34 + mov r44=r35 + mov r45=r36 + ;; + .mmi + mov r46=r37 + mov r47=r38 + mov r48=r39 + ;; + + .global __syscall_cancel_arch_start +__syscall_cancel_arch_start: + ;; + .mmi + nop 0 + ld4.acq r14=[r32] + nop 0 + ;; + .mib + nop 0 + tbit.z p6, p7=r14, TCB_CANCELED_BIT + .pred.safe_across_calls p1-p63 +(p7) br.call.dpnt.many b0 = __syscall_do_cancel# + .pred.safe_across_calls p1-p5,p16-p63 + ;; + + /* Due instruction bundle ia64 has the end marker before the syscall + instruction. Check IA64 ucontext_check_pc_boundary on how the PC + is checked. */ + .global __syscall_cancel_arch_end +__syscall_cancel_arch_end: + break 0x100000 + ;; + .mmi + cmp.ne p6, p7=-1, r10 + nop 0 + mov b0=r40 + ;; + .mib +(p7) sub r8=r0, r8 + mov ar.pfs=r41 + br.ret.sptk.many b0 + +END (__syscall_cancel_arch) From patchwork Mon Apr 10 20:46:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 67592 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0FACD3853576 for ; Mon, 10 Apr 2023 20:48:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0FACD3853576 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1681159738; bh=3rzjIFQAh7ffRIXJWFsd38p8X5+bNqSgxmEMKtMonZE=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=Zj2PDSWLhSIE6/FRTF3DNrKXxAy5vnjowa3KBrSXswQdFee5PlCAn7LqMOkKMw8wG m/elmXSdTuzLDFQtiH1BTvhECPs/lXCItB8nhNXNxCDpYDdulkNiXMFDPz1ekdKgZD x+0f2jY/pbsQ75LgWiQd7hBdUTF8Mog2GbrhaSj8= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oi1-x229.google.com (mail-oi1-x229.google.com [IPv6:2607:f8b0:4864:20::229]) by sourceware.org (Postfix) with ESMTPS id 0A4D53857705 for ; Mon, 10 Apr 2023 20:46:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0A4D53857705 Received: by mail-oi1-x229.google.com with SMTP id r14so30341271oiw.12 for ; Mon, 10 Apr 2023 13:46:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681159589; x=1683751589; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3rzjIFQAh7ffRIXJWFsd38p8X5+bNqSgxmEMKtMonZE=; b=rCfFXbEbqKL6ZvW+PfW3gBwc2D3Wr/nQ1YkXNV4hMHqi/DRRiGVStKwlbhY9CE7Ut+ cvw55p5k2D4SAwNrg0TxkYmVTcZZhnK3K4zbZ9wArgGPSdCtd34q2pu/IEAnNiENcdl8 aSsS+5TJkpav/ClpyeZoIRmeva1/y2X82MhI3+FSPBkLQOPHd8v8XNV05PYJ8e35LFNm AyrN7CDzEz3CJ8m2tfKo707kuOZ68rtQ1BcuEEpAjCMtp83pdhUOw6HmxpJe26vw8r/K aVcPFJ8G4LaoMge38PVD38VQUdDt6QSNewdLVAzj3dKFR2KXhcxtB9FfMHGM8VGiQ3jG wh9w== X-Gm-Message-State: AAQBX9czl92UhRV4epnEvqZNbwJmXBTNm10Ex4gbyHLqvWC1ADjMmHxK v9L8O/DhZTUbhYac8uLYHvzJB3sUNOzG7AqJbEdlmg== X-Google-Smtp-Source: AKy350YhgXmXN8mLJVU7noF1G9kbPqbdEvByagBJNpf6/5BCsEbA/swTAD6e8+06XG3dEyhKnfpY8Q== X-Received: by 2002:a05:6808:16a7:b0:386:9af9:96db with SMTP id bb39-20020a05680816a700b003869af996dbmr5308658oib.38.1681159587245; Mon, 10 Apr 2023 13:46:27 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c2:55a1:d59a:609a:284:6ed]) by smtp.gmail.com with ESMTPSA id p5-20020acabf05000000b003896f132821sm4865732oif.41.2023.04.10.13.46.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Apr 2023 13:46:26 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v5 13/22] sh: Fix Race conditions in pthread cancellation [BZ#12683] Date: Mon, 10 Apr 2023 17:46:05 -0300 Message-Id: <20230410204614.4129551-5-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230410204614.4129551-1-adhemerval.zanella@linaro.org> References: <20230410195907.4123869-1-adhemerval.zanella@linaro.org> <20230410204614.4129551-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" By adding the required syscall_cancel.S. Checked against a build and make check run-built-tests=no for sh4-linux-gnu. --- sysdeps/sh/sysdep.h | 1 + sysdeps/unix/sysv/linux/sh/syscall_cancel.S | 126 ++++++++++++++++++++ 2 files changed, 127 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/sh/syscall_cancel.S diff --git a/sysdeps/sh/sysdep.h b/sysdeps/sh/sysdep.h index 003b05fa25..60fd06188c 100644 --- a/sysdeps/sh/sysdep.h +++ b/sysdeps/sh/sysdep.h @@ -24,6 +24,7 @@ #define ALIGNARG(log2) log2 #define ASM_SIZE_DIRECTIVE(name) .size name,.-name +#define L(label) .L##label #ifdef SHARED #define PLTJMP(_x) _x##@PLT diff --git a/sysdeps/unix/sysv/linux/sh/syscall_cancel.S b/sysdeps/unix/sysv/linux/sh/syscall_cancel.S new file mode 100644 index 0000000000..2afd23928d --- /dev/null +++ b/sysdeps/unix/sysv/linux/sh/syscall_cancel.S @@ -0,0 +1,126 @@ +/* Cancellable syscall wrapper. Linux/sh version. + Copyright (C) 2023 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 + . */ + +#include +#include + +/* long int __syscall_cancel_arch (int *cancelhandling, + long int nr, + long int arg1, + long int arg2, + long int arg3, + long int arg4, + long int arg5, + long int arg6) */ + +ENTRY (__syscall_cancel_arch) + +#ifdef SHARED + mov.l r12,@-r15 + cfi_def_cfa_offset (4) + cfi_offset (12, -4) + mova L(GT),r0 + mov.l L(GT),r12 + sts.l pr,@-r15 + cfi_def_cfa_offset (8) + cfi_offset (17, -8) + add r0,r12 +#else + sts.l pr,@-r15 + cfi_def_cfa_offset (4) + cfi_offset (17, -4) +#endif + + .globl __syscall_cancel_arch_start +__syscall_cancel_arch_start: + + /* if (*cancelhandling & CANCELED_BITMASK) + __syscall_do_cancel() */ + mov.l @r4,r0 + tst #TCB_CANCELED_BITMASK,r0 + bf/s 1f + + /* Issue a 6 argument syscall. */ + mov r5,r3 + mov r6,r4 + mov r7,r5 +#ifdef SHARED + mov.l @(8,r15),r6 + mov.l @(12,r15),r7 + mov.l @(16,r15),r0 + mov.l @(20,r15),r1 +#else + mov.l @(4,r15),r6 + mov.l @(8,r15),r7 + mov.l @(12,r15),r0 + mov.l @(16,r15),r1 +#endif + trapa #0x16 + + .globl __syscall_cancel_arch_end +__syscall_cancel_arch_end: + + /* The additional or is a workaround for a hardware issue: + http://documentation.renesas.com/eng/products/mpumcu/tu/tnsh7456ae.pdf + */ + or r0,r0 + or r0,r0 + or r0,r0 + or r0,r0 + or r0,r0 + + lds.l @r15+,pr + cfi_remember_state + cfi_restore (17) +#ifdef SHARED + cfi_def_cfa_offset (4) + rts + mov.l @r15+,r12 + cfi_def_cfa_offset (0) + cfi_restore (12) + .align 1 +1: + cfi_restore_state + mov.l L(SC),r1 + bsrf r1 +L(M): + nop + + .align 2 +L(GT): + .long _GLOBAL_OFFSET_TABLE_ +L(SC): + .long __syscall_do_cancel-(L(M)+2) +#else + cfi_def_cfa_offset (0) + rts + nop + + .align 1 +1: + cfi_restore_state + mov.l 2f,r1 + jsr @r1 + nop + + .align 2 +2: + .long __syscall_do_cancel +#endif + +END (__syscall_cancel_arch) From patchwork Mon Apr 10 20:46:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 67583 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8B1653856249 for ; Mon, 10 Apr 2023 20:46:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8B1653856249 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1681159617; bh=0zhXmpXeeV0xUTqi6HqdyHwlPgZM86eBOqBRCdA+MHw=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=d1fTPENKGcLm0fHMY1WRqlmhD+86JZmSP/QjOohuNK2Jzg2sNDwPDWRjqwAAFumLI Se1ayi77/LBngWwLZR4ER5+PVb4a5JKirQCYVG64DKt8TvlOpsyG2JAg2O9ZQ8GN44 gkHu40IDl8MJf/Q5LMZSqK1SV/V3O/88jc0u9CVU= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oi1-x234.google.com (mail-oi1-x234.google.com [IPv6:2607:f8b0:4864:20::234]) by sourceware.org (Postfix) with ESMTPS id 5D1673857701 for ; Mon, 10 Apr 2023 20:46:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5D1673857701 Received: by mail-oi1-x234.google.com with SMTP id w19so4030204oiv.13 for ; Mon, 10 Apr 2023 13:46:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681159590; x=1683751590; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0zhXmpXeeV0xUTqi6HqdyHwlPgZM86eBOqBRCdA+MHw=; b=kdrdrq+a1SrVr6TvnTStqhROqfbr0ioF0omgLNjX4G3w1yT0DDSkBmLMbx3CN8wbgl xn/H5JOuhsZEzQSWxZNSQPd7Q2WSJFt5jFx4EUkLsZcmWVHEovW/xw2TLZGyzQsf6v9A mXGOu7XN1ljfkR15dkR/IEXIvj6bQnHhTb1F1D7SSq3BZohKKNDnnYQ/3wfy68sDsYyW 31oCzZYucxwOPiqnWbdW0144TO20yB1jQGf6Lm9WQDL+CMzOgLTssY79eDjLx/88V4NK +QKF5rFP2WwvguQfTKZ1JhwjXmN9ggJst0K3mR9CDCQLhsjEDEVi8QHqIN1kFatpy/2B pgXQ== X-Gm-Message-State: AAQBX9frrCQTiP/GAt2EGOmomjK16+WZRg9lLkj5x5oHFWulCoSmYRmF 8tNzx5u/T8DC2gJms9+ZcMvbGFlSDnqMMwGLH3k2Kg== X-Google-Smtp-Source: AKy350ahrXrO5ttzIrwTOHcyir2wbC2t35IlVMO+ONFEy0q459xWhHHJslxIOr4kUWT63yMI/SkeLA== X-Received: by 2002:aca:1b0a:0:b0:38b:5349:e112 with SMTP id b10-20020aca1b0a000000b0038b5349e112mr4844286oib.46.1681159588986; Mon, 10 Apr 2023 13:46:28 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c2:55a1:d59a:609a:284:6ed]) by smtp.gmail.com with ESMTPSA id p5-20020acabf05000000b003896f132821sm4865732oif.41.2023.04.10.13.46.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Apr 2023 13:46:28 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v5 14/22] nios2: Fix Race conditions in pthread cancellation [BZ#12683] Date: Mon, 10 Apr 2023 17:46:06 -0300 Message-Id: <20230410204614.4129551-6-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230410204614.4129551-1-adhemerval.zanella@linaro.org> References: <20230410195907.4123869-1-adhemerval.zanella@linaro.org> <20230410204614.4129551-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" By adding the required syscall_cancel.S. Checked against a build and make check run-built-tests=no for nios2-linux-gnu. --- .../unix/sysv/linux/nios2/syscall_cancel.S | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/nios2/syscall_cancel.S diff --git a/sysdeps/unix/sysv/linux/nios2/syscall_cancel.S b/sysdeps/unix/sysv/linux/nios2/syscall_cancel.S new file mode 100644 index 0000000000..19d0795886 --- /dev/null +++ b/sysdeps/unix/sysv/linux/nios2/syscall_cancel.S @@ -0,0 +1,95 @@ +/* Cancellable syscall wrapper. Linux/nios2 version. + Copyright (C) 2023 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 + . */ + +#include +#include + +/* long int __syscall_cancel_arch (int *cancelhandling, + __syscall_arg_t nr, + __syscall_arg_t arg1, + __syscall_arg_t arg2, + __syscall_arg_t arg3, + __syscall_arg_t arg4, + __syscall_arg_t arg5, + __syscall_arg_t arg6) */ + +ENTRY (__syscall_cancel_arch) +#ifdef SHARED + addi sp, sp, -8 + stw r22, 0(sp) + nextpc r22 +1: + movhi r8, %hiadj(_gp_got - 1b) + addi r8, r8, %lo(_gp_got - 1b) + stw ra, 4(sp) + add r22, r22, r8 +#else + addi sp, sp, -4 + cfi_def_cfa_offset (4) + stw ra, 0(sp) + cfi_offset (31, -4) +#endif + + .globl __syscall_cancel_arch_start +__syscall_cancel_arch_start: + ldw r3, 0(r4) + andi r3, r3, TCB_CANCELED_BITMASK + bne r3, zero, 3f + mov r10, r6 + mov r2, r5 +#ifdef SHARED +# define STACK_ADJ 4 +#else +# define STACK_ADJ 0 +#endif + ldw r9, (16 + STACK_ADJ)(sp) + mov r5, r7 + ldw r8, (12 + STACK_ADJ)(sp) + ldw r7, (8 + STACK_ADJ)(sp) + ldw r6, (4 + STACK_ADJ)(sp) + mov r4, r10 + trap + + .globl __syscall_cancel_arch_end +__syscall_cancel_arch_end: + beq r7, zero, 2f + sub r2, zero, r2 +2: +#ifdef SHARED + ldw ra, 4(sp) + ldw r22, 0(sp) + addi sp, sp, 8 +#else + ldw ra, (0 + STACK_ADJ)(sp) + cfi_remember_state + cfi_restore (31) + addi sp, sp, 4 + cfi_def_cfa_offset (0) +#endif + ret + +3: +#ifdef SHARED + ldw r2, %call(__syscall_do_cancel)(r22) + callr r2 +#else + cfi_restore_state + call __syscall_do_cancel +#endif + +END (__syscall_cancel_arch) From patchwork Mon Apr 10 20:46:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 67584 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9222A3855585 for ; Mon, 10 Apr 2023 20:47:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9222A3855585 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1681159622; bh=9fyv7rH6GBBig5q7kjCTLj3SqeAYQEVEkSFYW4Z1y08=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=m6enfIsc+72P6NuCJQzLIKx7Q3yRoP7qiuhr38kRM0JrnOqSUxHmm+7r7VYOOB9uK vIAIoxsBtOf3hY4kE0aO6WEQABguhVtQs+XVxXL8D7uLlrwqmXkTXnbGb2fSIiS78q X4n2kWYyFUz9bGCAdtq7c8kQGymow/c230dso4do= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oi1-x235.google.com (mail-oi1-x235.google.com [IPv6:2607:f8b0:4864:20::235]) by sourceware.org (Postfix) with ESMTPS id 484F03857716 for ; Mon, 10 Apr 2023 20:46:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 484F03857716 Received: by mail-oi1-x235.google.com with SMTP id be34so3988690oib.4 for ; Mon, 10 Apr 2023 13:46:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681159592; x=1683751592; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9fyv7rH6GBBig5q7kjCTLj3SqeAYQEVEkSFYW4Z1y08=; b=IM7fqgB18At0upUgigoLvWLk4tT4r+K/8ZwTB9tDe3fgQKIKvlknXkt0hDMnDOSjcS e3Z+IArmu+eBwVMoYYx/njni381JlPPsL8YCMv2K5rzbifnoAQonSPFc4Gw8+AMxlolh 3U22pxERxSj28arPBdD+3vtJpBtyRAkdR3nEWVjEQP4JsW9QBD72Fn8+qBaE5kyAa8yp NRYBn/Uy1SG7ZXdXcsXXxnaunTe/SV364Ti0qXwbRoFwOXKGR5A0789N3MR2+NmNSdFW Ovm43tANWIY82aPVar15hp7OTRSq5wZLBxE0Y9y7lDQ91DgZ2TvizDq7MCy/obgPPTJI nLQA== X-Gm-Message-State: AAQBX9cmaJixQesKlrdaCwB/j0imnGzwyynXwI9dES33gV3m6HnqLesq lbrl6TXd3o5I8y8zVyvnjYHPkUSEzWYhxnUFIsOlCA== X-Google-Smtp-Source: AKy350aFfBUagxzG76FRsU43V5uOEI5KXGVftkOL/LydzeieTUWadipegcMwp8qiO4CYNvbcHHis+A== X-Received: by 2002:a54:4115:0:b0:38b:5e4:9d3b with SMTP id l21-20020a544115000000b0038b05e49d3bmr5033233oic.4.1681159590587; Mon, 10 Apr 2023 13:46:30 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c2:55a1:d59a:609a:284:6ed]) by smtp.gmail.com with ESMTPSA id p5-20020acabf05000000b003896f132821sm4865732oif.41.2023.04.10.13.46.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Apr 2023 13:46:29 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v5 15/22] microblaze: Fix Race conditions in pthread cancellation [BZ#12683] Date: Mon, 10 Apr 2023 17:46:07 -0300 Message-Id: <20230410204614.4129551-7-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230410204614.4129551-1-adhemerval.zanella@linaro.org> References: <20230410195907.4123869-1-adhemerval.zanella@linaro.org> <20230410204614.4129551-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" By adding the required syscall_cancel.S. Checked against a build and make check run-built-tests=no for microblaze-linux-gnu. --- .../sysv/linux/microblaze/syscall_cancel.S | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/microblaze/syscall_cancel.S diff --git a/sysdeps/unix/sysv/linux/microblaze/syscall_cancel.S b/sysdeps/unix/sysv/linux/microblaze/syscall_cancel.S new file mode 100644 index 0000000000..1f9d202bf5 --- /dev/null +++ b/sysdeps/unix/sysv/linux/microblaze/syscall_cancel.S @@ -0,0 +1,61 @@ +/* Cancellable syscall wrapper. Linux/microblaze version. + Copyright (C) 2023 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 + . */ + +#include +#include + +/* long int __syscall_cancel_arch (int *cancelhandling, + long int nr, + long int arg1, + long int arg2, + long int arg3, + long int arg4, + long int arg5, + long int arg6) */ + +ENTRY (__syscall_cancel_arch) + + .globl __syscall_cancel_arch_start +__syscall_cancel_arch_start: + + lwi r3,r5,0 + andi r3,r3,TCB_CANCELED_BITMASK + bneid r3,1f + addk r12,r6,r0 + + addk r5,r7,r0 + addk r6,r8,r0 + addk r7,r9,r0 + addk r8,r10,r0 + lwi r9,r1,56 + lwi r10,r1,60 + brki r14,8 + + .globl __syscall_cancel_arch_end +__syscall_cancel_arch_end: + + nop + lwi r15,r1,0 + rtsd r15,8 + addik r1,r1,28 + +1: + brlid r15, __syscall_do_cancel + nop + +END (__syscall_cancel_arch) From patchwork Mon Apr 10 20:46:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 67593 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 147003855590 for ; Mon, 10 Apr 2023 20:49:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 147003855590 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1681159780; bh=ZBOTIHpi8964eClgb9gmLoPglCk2l+9EdjCO+WdN6FU=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=o43cMdbLS54wTyBX5h2FZ15duIRz/85LOGZyBXJuKMjWfk+xK+LOiJPkmvuThVVzV cEt6K4Ain10jmDSdtloB+WGJnMEZzQqCJ0EEQ2pUD/WXl8vn+XO3Z26FrVKu8FOcQ5 icrz8zUJ9TmdJ78s1YvD9ogu1juIUT1UxN+vSV6Q= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oi1-x234.google.com (mail-oi1-x234.google.com [IPv6:2607:f8b0:4864:20::234]) by sourceware.org (Postfix) with ESMTPS id 744693857733 for ; Mon, 10 Apr 2023 20:46:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 744693857733 Received: by mail-oi1-x234.google.com with SMTP id w19so4030281oiv.13 for ; Mon, 10 Apr 2023 13:46:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681159592; x=1683751592; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZBOTIHpi8964eClgb9gmLoPglCk2l+9EdjCO+WdN6FU=; b=ImdN7+kBVC5IfdhZO8H9Fn9zNJ3+xFUCVUV/2D6CnAQ3Qy6sCNkr1EkRP4rqOVZfy5 0ePJdF6rmOTEdshrvo4p1QvmR0vrQjC8hvnEe2U7hjDJal6b9N3oosKab/Xn65i8dZVE nkPVVpdcYSc0US0m4mKkDH+zSdCKXoWbLLKeispDqYj8Fus1amW3KGYF40oIVOI1qU1u WFmIZB5FRllhMSksb4Te5SAXbCx+tgxWVrL8JkxBXJHzP2yu3Bi8Cd8fiMEZn21DngSq B3UycyPbctx9vakl5IQt3PTAMIsjLT1DeCH5sOw7FL65vCGN0YF3gHpOjXnmmQEFdh6p KWYg== X-Gm-Message-State: AAQBX9cqW1LIHvNxVqEuZqY9m4UImXlNccM8nuJZR1jcohvIjX08swqA 4q46y1D0gwnK8XiOkGukF6c4OkbKg7hgzeYD/M6m1A== X-Google-Smtp-Source: AKy350aYrikO0WGBUjY965206+xqeDdIzKbA3RaJaLBfJx/FzleOikjmF/jFyssrePeBTeKmJq2BIw== X-Received: by 2002:a05:6808:20d:b0:38b:7122:9e78 with SMTP id l13-20020a056808020d00b0038b71229e78mr3393075oie.41.1681159592282; Mon, 10 Apr 2023 13:46:32 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c2:55a1:d59a:609a:284:6ed]) by smtp.gmail.com with ESMTPSA id p5-20020acabf05000000b003896f132821sm4865732oif.41.2023.04.10.13.46.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Apr 2023 13:46:31 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v5 16/22] hppa: Fix Race conditions in pthread cancellation [BZ#12683] Date: Mon, 10 Apr 2023 17:46:08 -0300 Message-Id: <20230410204614.4129551-8-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230410204614.4129551-1-adhemerval.zanella@linaro.org> References: <20230410195907.4123869-1-adhemerval.zanella@linaro.org> <20230410204614.4129551-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SCC_5_SHORT_WORD_LINES, SPF_HELO_NONE, SPF_PASS, TXREP 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-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" By adding the required syscall_cancel.S. Checked on hppa-linux-gnu. --- sysdeps/unix/sysv/linux/hppa/syscall_cancel.S | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/hppa/syscall_cancel.S diff --git a/sysdeps/unix/sysv/linux/hppa/syscall_cancel.S b/sysdeps/unix/sysv/linux/hppa/syscall_cancel.S new file mode 100644 index 0000000000..b9c19747ea --- /dev/null +++ b/sysdeps/unix/sysv/linux/hppa/syscall_cancel.S @@ -0,0 +1,81 @@ +/* Cancellable syscall wrapper. Linux/hppa version. + Copyright (C) 2023 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 + . */ + +#include +#include + +/* long int __syscall_cancel_arch (int *cancelhandling, + long int nr, + long int arg1, + long int arg2, + long int arg3, + long int arg4, + long int arg5, + long int arg6) */ + + .text +ENTRY(__syscall_cancel_arch) + stw %r2,-20(%r30) + ldo 128(%r30),%r30 + cfi_def_cfa_offset (-128) + cfi_offset (2, -20) + ldw -180(%r30),%r28 + copy %r26,%r20 + stw %r28,-108(%r30) + ldw -184(%r30),%r28 + copy %r24,%r26 + stw %r28,-112(%r30) + ldw -188(%r30),%r28 + stw %r28,-116(%r30) + ldw -192(%r30),%r28 + stw %r4,-104(%r30) + stw %r28,-120(%r30) + copy %r25,%r28 + copy %r23,%r25 +#ifdef __PIC__ + stw %r19,-32(%r30) +#endif + cfi_offset (4, 24) + + .global __syscall_cancel_arch_start +__syscall_cancel_arch_start: + ldw 0(%r20),%r20 + bb,< %r20,31-TCB_CANCELED_BIT,1f + ldw -120(%r30),%r21 + ldw -116(%r30),%r22 + ldw -112(%r30),%r23 + ldw -108(%r30),%r24 + copy %r19, %r4 + ble 0x100(%sr2, %r0) + + .global __syscall_cancel_arch_end +__syscall_cancel_arch_end: + + copy %r28,%r20 + copy %r4,%r19 + + ldw -148(%r30),%r2 + ldw -104(%r30),%r4 + bv %r0(%r2) + ldo -128(%r30),%r30 +1: + bl __syscall_do_cancel,%r2 + nop + nop + +END(__syscall_cancel_arch) From patchwork Mon Apr 10 20:46:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 67588 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CAA9F385022A for ; Mon, 10 Apr 2023 20:47:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CAA9F385022A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1681159664; bh=8IyP/V3j9Ll0MaikZsCGxuGjKDgV3MkJ66J9ZZ1Bqvk=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=Bv55+dEOGzM6yk/BBg+jXe2CtKVu1coFB49lHx/T8mk1VbrbvAU52KBtH+WQQWaP9 8Xbo+B8ndn4jQ7XSs7XPrYgipUx8Cz69r/2QAlzSK8OKiiSGn/VFV/CM77f91Z2e8k OB1Tftna6Wlin1N76eGDEONso90Acx2gsTALanck= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oi1-x22d.google.com (mail-oi1-x22d.google.com [IPv6:2607:f8b0:4864:20::22d]) by sourceware.org (Postfix) with ESMTPS id 1DA26385734C for ; Mon, 10 Apr 2023 20:46:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1DA26385734C Received: by mail-oi1-x22d.google.com with SMTP id z16so3701335oib.9 for ; Mon, 10 Apr 2023 13:46:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681159596; x=1683751596; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8IyP/V3j9Ll0MaikZsCGxuGjKDgV3MkJ66J9ZZ1Bqvk=; b=MKGkVjhciK/TiAqdSZXLFaiox27IatFYEZ9X1qJQPc42UsUUqbh/P5F+Jb+mx9Ewer tUGjYv2I/rCt38NkrI5H6P74wewN+XSZyeoeWSr3AIme7JcwVc0dh48nHZqQWWR6fC5A Mtd40dbo+9xqMFsgA+7s4zZXrQT2rgtQRNoaQHtz+6I1JHxL/dHqgjN2Em0xG3qGFU9m ymqHqoZuDTf3WjiNX4Cq3qaS/3xblv8Z2gs4uCk6Z1Ipz/32mdYl+srDxvaGLHvLGiE0 Qr5BjzNKrRAwkzn6ZnjdyLD4FTXHXbH7wyFU48vM+wvQPkLjk1zzWbeE6jh6vF42Yu7t AI5Q== X-Gm-Message-State: AAQBX9epC5vmYgYBWzSLhSRKfR4bnbcpLU7csHcYbo8lCJ5QaLVjbMDp D8iLW9NcWwbI1lDm/Svi9WGJfNjsmngaEDgrO/4uqQ== X-Google-Smtp-Source: AKy350bBr1HbpmCXIM/g3p5H0YgqXVoO2gu7MT8ZlOjgB9vRzYkgzsKSv2jHXhtbkW/HhcPf+b6BWg== X-Received: by 2002:aca:2b13:0:b0:389:8a25:1897 with SMTP id i19-20020aca2b13000000b003898a251897mr177210oik.12.1681159594289; Mon, 10 Apr 2023 13:46:34 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c2:55a1:d59a:609a:284:6ed]) by smtp.gmail.com with ESMTPSA id p5-20020acabf05000000b003896f132821sm4865732oif.41.2023.04.10.13.46.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Apr 2023 13:46:33 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v5 17/22] m68k: Fix Race conditions in pthread cancellation [BZ#12683] Date: Mon, 10 Apr 2023 17:46:09 -0300 Message-Id: <20230410204614.4129551-9-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230410204614.4129551-1-adhemerval.zanella@linaro.org> References: <20230410195907.4123869-1-adhemerval.zanella@linaro.org> <20230410204614.4129551-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" By adding the required syscall_cancel.S. Checked on m68k-linux-gnu. --- sysdeps/unix/sysv/linux/m68k/syscall_cancel.S | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/m68k/syscall_cancel.S diff --git a/sysdeps/unix/sysv/linux/m68k/syscall_cancel.S b/sysdeps/unix/sysv/linux/m68k/syscall_cancel.S new file mode 100644 index 0000000000..8923bcc71c --- /dev/null +++ b/sysdeps/unix/sysv/linux/m68k/syscall_cancel.S @@ -0,0 +1,84 @@ +/* Cancellable syscall wrapper. Linux/m68k version. + Copyright (C) 2023 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 + . */ + +#include +#include + +/* long int __syscall_cancel_arch (int *cancelhandling, + __syscall_arg_t nr, + __syscall_arg_t arg1, + __syscall_arg_t arg2, + __syscall_arg_t arg3, + __syscall_arg_t arg4, + __syscall_arg_t arg5, + __syscall_arg_t arg6) */ + + +ENTRY (__syscall_cancel_arch) +#ifdef __mcoldfire__ + lea (-16,%sp),%sp + movem.l %d2-%d5,(%sp) +#else + movem.l %d2-%d5,-(%sp) +#endif + cfi_def_cfa_offset (20) + cfi_offset (2, -20) + cfi_offset (3, -16) + cfi_offset (4, -12) + cfi_offset (5, -8) + + .global __syscall_cancel_arch_start +__syscall_cancel_arch_start: + + move.l 20(%sp),%a0 + move.l (%a0),%d0 +#ifdef __mcoldfire__ + move.w %d0,%ccr + jeq 1f +#else + btst #TCB_CANCELED_BIT,%d0 + jne 1f +#endif + + move.l 48(%sp),%a0 + move.l 44(%sp),%d5 + move.l 40(%sp),%d4 + move.l 36(%sp),%d3 + move.l 32(%sp),%d2 + move.l 28(%sp),%d1 + move.l 24(%sp),%d0 + trap #0 + + .global __syscall_cancel_arch_end +__syscall_cancel_arch_end: + +#ifdef __mcoldfire__ + movem.l (%sp),%d2-%d5 + lea (16,%sp),%sp +#else + movem.l (%sp)+,%d2-%d5 +#endif + rts + +1: +#ifdef PIC + bsr.l __syscall_do_cancel +#else + jsr __syscall_do_cancel +#endif +END (__syscall_cancel_arch) From patchwork Mon Apr 10 20:46:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 67587 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 218F73850216 for ; Mon, 10 Apr 2023 20:47:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 218F73850216 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1681159660; bh=Q9/OzF41t/hnLX/UiDn0uS6FT6/k9tfzshk1uCTwA18=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=asQaUdO/PA8f5IWMAjbAANHwaLbZ2CkW9dkQHMLy+gaTtWHCfbpoNi6ruCZJ6Xk2u BzENlUgt15fgZq9mB9AfIm3DAKAhMMXGAhBhifbYk7P+QXSkzX1qSJ2wAjHgpsSjRw b5ZiMUbIs7N7YLIW4oZ8e2VQOaNswjvWDklMyCAQ= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oi1-x229.google.com (mail-oi1-x229.google.com [IPv6:2607:f8b0:4864:20::229]) by sourceware.org (Postfix) with ESMTPS id 17D983857437 for ; Mon, 10 Apr 2023 20:46:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 17D983857437 Received: by mail-oi1-x229.google.com with SMTP id bh10so4124873oib.1 for ; Mon, 10 Apr 2023 13:46:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681159596; x=1683751596; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Q9/OzF41t/hnLX/UiDn0uS6FT6/k9tfzshk1uCTwA18=; b=coe7lcUDrrtO4/u3u7kktdPlsPJ1FF/SVo0ZV8fyIKb0hd0mAcjuBvwzhRwm1PI/q4 ClSisYRaPz7m+7YXcn8ERI7sqnROiVlh4yX51o5YDCrLtfS8N3NgMKVQSOdCWL4Ogyy6 7AYJv67SjykQJWhPm3CzVCoTfohCzav6x2j9+2VCRa9NL1wqUDc4KIvkijI9qX+sNY2u UOc71bt2zC0K+e1nj+f50ZACMb10pAfEnNrK6jX8CDI1z06byMMTrcy047OLbSyM8TDY PxD64AQUoThI6S3FsL5sx1eKqLbMDebAbHksX6o5Jfap2DYzNA5YPnEamDyt8dgIsVlA CkfA== X-Gm-Message-State: AAQBX9d+l0nO4VviiZ6a2fYd46m+zoysKvdFvHjKr/gNYtLYB8WPcpAF v8tvyAaQslpzJZjBucmg5zvrl4pVxWOMr1UKHuiJ2g== X-Google-Smtp-Source: AKy350ZSdDTb2TEZ4GmHvlUdHJEdbD/gO+msv9kY3CPOuV4w7wu+uGr9TJtYmWnNsfvwUvlMr6XN3A== X-Received: by 2002:aca:2414:0:b0:389:9592:b4d0 with SMTP id n20-20020aca2414000000b003899592b4d0mr134699oic.53.1681159596012; Mon, 10 Apr 2023 13:46:36 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c2:55a1:d59a:609a:284:6ed]) by smtp.gmail.com with ESMTPSA id p5-20020acabf05000000b003896f132821sm4865732oif.41.2023.04.10.13.46.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Apr 2023 13:46:35 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v5 18/22] alpha: Fix Race conditions in pthread cancellation [BZ#12683] Date: Mon, 10 Apr 2023 17:46:10 -0300 Message-Id: <20230410204614.4129551-10-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230410204614.4129551-1-adhemerval.zanella@linaro.org> References: <20230410195907.4123869-1-adhemerval.zanella@linaro.org> <20230410204614.4129551-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" By adding the required syscall_cancel.S. Checked on alpha-linux-gnu. --- .../unix/sysv/linux/alpha/syscall_cancel.S | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/alpha/syscall_cancel.S diff --git a/sysdeps/unix/sysv/linux/alpha/syscall_cancel.S b/sysdeps/unix/sysv/linux/alpha/syscall_cancel.S new file mode 100644 index 0000000000..377eef48be --- /dev/null +++ b/sysdeps/unix/sysv/linux/alpha/syscall_cancel.S @@ -0,0 +1,80 @@ +/* Cancellable syscall wrapper. Linux/alpha version. + Copyright (C) 2023 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 + . */ + +#include +#include + +/* long int __syscall_cancel_arch (int *ch, + __syscall_arg_t nr, + __syscall_arg_t arg1, + __syscall_arg_t arg2, + __syscall_arg_t arg3, + __syscall_arg_t arg4, + __syscall_arg_t arg5, + __syscall_arg_t arg6) */ + + .set noreorder + .set noat + .set nomacro +ENTRY (__syscall_cancel_arch) + .frame sp, 16, ra, 0 + .mask 0x4000000,-16 + cfi_startproc + ldah gp, 0(t12) + lda gp, 0(gp) + lda sp, -16(sp) + cfi_def_cfa_offset (16) + mov a1, v0 + stq ra, 0(sp) + cfi_offset (26, -16) + .prologue 1 + + .global __syscall_cancel_arch_start +__syscall_cancel_arch_start: + ldl t0, 0(a0) + addl zero, t0, t0 + /* if (*ch & CANCELED_BITMASK) */ + and t0, TCB_CANCELED_BITMASK, t0 + bne t0, 1f + mov a2, a0 + mov a3, a1 + mov a4, a2 + ldq a4, 16(sp) + mov a5, a3 + ldq a5, 24(sp) + .set macro + callsys + .set nomacro + + .global __syscall_cancel_arch_end +__syscall_cancel_arch_end: + subq zero, v0, t0 + ldq ra, 0(sp) + cmovne a3, t0, v0 + lda sp, 16(sp) + cfi_remember_state + cfi_restore (26) + cfi_def_cfa_offset (0) + ret zero, (ra), 1 + .align 4 +1: + cfi_restore_state + ldq t12, __syscall_do_cancel(gp) !literal!2 + jsr ra, (t12), __syscall_do_cancel !lituse_jsr!2 + cfi_endproc +END (__syscall_cancel_arch) From patchwork Mon Apr 10 20:46:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 67585 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 64B343852776 for ; Mon, 10 Apr 2023 20:47:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 64B343852776 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1681159652; bh=q1AGQ+SE4nqhInGBfY6sD2yxZ8/6qI6BGMz3rZFMNI8=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=K1ombqErXKt4ejLdxD5bkVNB9I52zPQgsJQNunxHftQw6xAQSQ0VlC+5pksmW2078 arPSBBq0l7LDSRd9jMaBsNG78PrQprNRSeCrG+rZjNBrZ3gemyJpqrX8JXSNt+Sw+d 9vAu5UWSfaBINCQv5rTIv0556txIaXE/aCSj5tso= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oi1-x22f.google.com (mail-oi1-x22f.google.com [IPv6:2607:f8b0:4864:20::22f]) by sourceware.org (Postfix) with ESMTPS id 3A93D3858409 for ; Mon, 10 Apr 2023 20:46:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3A93D3858409 Received: by mail-oi1-x22f.google.com with SMTP id f14so22455255oiw.10 for ; Mon, 10 Apr 2023 13:46:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681159599; x=1683751599; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=q1AGQ+SE4nqhInGBfY6sD2yxZ8/6qI6BGMz3rZFMNI8=; b=7WD8UPdtperr6a4df5RD8iLG6s4ktM2iQPxHIS9O7/TJcjeKbQe/APswR/8ovsSAiE mXjsYw1XZQj6ngSgBvbyhtKu2MzXvO3dikWS368eTaU+f7i/UlZruuB7254SiMKO+Cfd 380qVY4XlXRPEEOYebuaLL+JJ8k9ErrTUO5eAtRQYC3X+got5l1hFVDT9IO3hL1nbvLy sulqeF9USC2RPwvFZg6LZz4ScrrNqUBG15KwBwuClpAHW9ROldgYL3lUnRdCG9ZBBy5Y SDMd56GZtNc6eqQ1wocHksqtD4OQFBa6iCeIauL8wrr6D/lde3ZyKQyL82xJL7AzHoXS Tqrg== X-Gm-Message-State: AAQBX9ct54lDp9NVHaXjyjd/roimC+JT0zDl5ROGtK8GsMOjru+WYumS yfjG45IPZL/Mpk1g+bGzRw5Os3tp0Z8GgSvWwThjFg== X-Google-Smtp-Source: AKy350ZfxyUzrs9m1R6tKBVpQkofTqloHYBGp4rAIAJ6BgFrNcLMaoR+OhycIblk0Fpzp5VJbeDB4g== X-Received: by 2002:aca:6745:0:b0:389:7b6b:7a2d with SMTP id b5-20020aca6745000000b003897b6b7a2dmr124032oiy.50.1681159597864; Mon, 10 Apr 2023 13:46:37 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c2:55a1:d59a:609a:284:6ed]) by smtp.gmail.com with ESMTPSA id p5-20020acabf05000000b003896f132821sm4865732oif.41.2023.04.10.13.46.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Apr 2023 13:46:37 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v5 19/22] csky: Fix Race conditions in pthread cancellation [BZ#12683] Date: Mon, 10 Apr 2023 17:46:11 -0300 Message-Id: <20230410204614.4129551-11-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230410204614.4129551-1-adhemerval.zanella@linaro.org> References: <20230410195907.4123869-1-adhemerval.zanella@linaro.org> <20230410204614.4129551-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" By adding the required syscall_cancel.S. Checked against a build and make check run-built-tests=no for csky-linux-gnuabiv2. --- sysdeps/unix/sysv/linux/csky/syscall_cancel.S | 114 ++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/csky/syscall_cancel.S diff --git a/sysdeps/unix/sysv/linux/csky/syscall_cancel.S b/sysdeps/unix/sysv/linux/csky/syscall_cancel.S new file mode 100644 index 0000000000..2989765f8c --- /dev/null +++ b/sysdeps/unix/sysv/linux/csky/syscall_cancel.S @@ -0,0 +1,114 @@ +/* Cancellable syscall wrapper. Linux/csky version. + Copyright (C) 2023 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 + . */ + +#include +#include + +/* long int __syscall_cancel_arch (int *cancelhandling, + __syscall_arg_t nr, + __syscall_arg_t arg1, + __syscall_arg_t arg2, + __syscall_arg_t arg3, + __syscall_arg_t arg4, + __syscall_arg_t arg5, + __syscall_arg_t arg6) */ + +#ifdef SHARED +# define STACK_ADJ 4 +#else +# define STACK_ADJ 0 +#endif + +ENTRY (__syscall_cancel_arch) + subi sp, sp, 16 + STACK_ADJ + cfi_def_cfa_offset (16 + STACK_ADJ) +#ifdef SHARED + st.w gb, (sp, 16) + lrw t1, 1f@GOTPC + cfi_offset (gb, -4) + grs gb, 1f +1: +#endif + st.w lr, (sp, 12) + st.w l3, (sp, 8) + st.w l1, (sp, 4) + st.w l0, (sp, 0) +#ifdef SHARED + addu gb, gb, t1 +#endif + subi sp, sp, 16 + cfi_def_cfa_offset (32 + STACK_ADJ) + cfi_offset (lr, -( 4 + STACK_ADJ)) + cfi_offset (l3, -( 8 + STACK_ADJ)) + cfi_offset (l1, -(12 + STACK_ADJ)) + cfi_offset (l0, -(16 + STACK_ADJ)) + + mov l3, a1 + mov a1, a3 + ld.w a3, (sp, 32 + STACK_ADJ) + st.w a3, (sp, 0) + ld.w a3, (sp, 36 + STACK_ADJ) + st.w a3, (sp, 4) + ld.w a3, (sp, 40 + STACK_ADJ) + st.w a3, (sp, 8) + ld.w a3, (sp, 44 + STACK_ADJ) + st.w a3, (sp, 12) + + .globl __syscall_cancel_arch_start +__syscall_cancel_arch_start: + ld.w t0, (a0, 0) + andi t0, t0, TCB_CANCELED_BITMASK + jbnez t0, 2f + mov a0, a2 + ld.w a3, (sp, 4) + ld.w a2, (sp, 0) + ld.w l0, (sp, 8) + ld.w l1, (sp, 12) + trap 0 + + .globl __syscall_cancel_arch_end +__syscall_cancel_arch_end: + addi sp, sp, 16 + cfi_remember_state + cfi_def_cfa_offset (16 + STACK_ADJ) +#ifdef SHARED + ld.w gb, (sp, 16) + cfi_restore (gb) +#endif + ld.w lr, (sp, 12) + cfi_restore (lr) + ld.w l3, (sp, 8) + cfi_restore (l3) + ld.w l1, (sp, 4) + cfi_restore (l1) + ld.w l0, (sp, 0) + cfi_restore (l0) + addi sp, sp, 16 + cfi_def_cfa_offset (0) + rts + +2: + cfi_restore_state +#ifdef SHARED + lrw a3, __syscall_do_cancel@GOTOFF + addu a3, a3, gb + jsr a3 +#else + jbsr __syscall_do_cancel +#endif +END (__syscall_cancel_arch) From patchwork Mon Apr 10 20:46:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 67590 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 89DEA38768B0 for ; Mon, 10 Apr 2023 20:48:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 89DEA38768B0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1681159703; bh=29PHTplQNOS5RrJ+3dP2DQybI8fVakMcif4d7thzSGo=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=UKVL1SVxeRl6nxBTzIJ2xuXp1yKzOQshI/1mC/n/9EVaXN4mTYF1qpA7+oYOJ16NN HZ/iK44kCNnZvQ7tkgDCMAXt0PHQvss5tc4r3YBsBh6zAnIbuU3eodrYIUGFAqOgdD E3lx9PuiOC27o1ukigS9+g8j9Fr9Kx2QXvCQKDuI= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oi1-x229.google.com (mail-oi1-x229.google.com [IPv6:2607:f8b0:4864:20::229]) by sourceware.org (Postfix) with ESMTPS id 9FE5A3856DD6 for ; Mon, 10 Apr 2023 20:46:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9FE5A3856DD6 Received: by mail-oi1-x229.google.com with SMTP id r14so30341716oiw.12 for ; Mon, 10 Apr 2023 13:46:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681159601; x=1683751601; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=29PHTplQNOS5RrJ+3dP2DQybI8fVakMcif4d7thzSGo=; b=xccaIJTBZGfdY1JelotToMJT/0xLdRS988CJBLBbNM+UOMN0DKLWDnqeQSz+nd7ahn OaAUCzaclwsrPHv32tnVjVYYdzcsDanvLZUjs2qJLJwMhXD03JSCqJLCucKD0ilki/lQ h/xtOT1k+Jf+30F16QujCUyrgLKNxdNWA+J+KoKk7M3nL1MP+YBIATXPo/qbI7omsltM rF3LQEyQaWkRJ49bMIb1J3uB5iRvvLRcSMv0INYsKnnKTJyfZykYHQEHoHKojI0AH08k Zfl1bdRt03Zz5dR8aTrfDO9EUutS8Cc9iZLAxhTe/joipDI42GfsByZoHmeVhcXvr2k0 wo4g== X-Gm-Message-State: AAQBX9fJPEed9KkG78hN9AKZMFPIbp88REPm0oLJS7z4Y3nhjZ0Vvm/0 WrJWme+VPxjTuuf9G3Wje4cpjz0snUJcPVLCiI92gw== X-Google-Smtp-Source: AKy350Zc07Cl07Kwu+TQeOqIdfxyOQbtfPjgcEtBTJIvvin9H3gtDtG6Ts4Bxr+WWTWpvHl/GmkDsw== X-Received: by 2002:a05:6808:a8b:b0:389:5164:9db2 with SMTP id q11-20020a0568080a8b00b0038951649db2mr5369797oij.48.1681159599447; Mon, 10 Apr 2023 13:46:39 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c2:55a1:d59a:609a:284:6ed]) by smtp.gmail.com with ESMTPSA id p5-20020acabf05000000b003896f132821sm4865732oif.41.2023.04.10.13.46.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Apr 2023 13:46:38 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v5 20/22] mips: Fix Race conditions in pthread cancellation [BZ#12683] Date: Mon, 10 Apr 2023 17:46:12 -0300 Message-Id: <20230410204614.4129551-12-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230410204614.4129551-1-adhemerval.zanella@linaro.org> References: <20230410195907.4123869-1-adhemerval.zanella@linaro.org> <20230410204614.4129551-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SCC_5_SHORT_WORD_LINES, SPF_HELO_NONE, SPF_PASS, TXREP 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-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" It adds the arch-specific cancellation syscall bridge and adjust the cancellable syscall bridge to accept 7 arguments (as required by mips o32). To avoid add a requirement on all architectures to support {INLINE,INTERNAL)_SYSCALL with 7 argument, mips support is added through a flag, HAVE_CANCELABLE_SYSCALL_WITH_7_ARGS, which changes the signature and prototype of the requires macros and functions (SYSCALL_CANCEL, __syscall_cancel and __syscall_cancel_arch). Checked on mips-linux-gnu, mips64-linux-gnu, and mips64-n32-linux-gnu. --- nptl/cancellation.c | 11 +- sysdeps/nptl/pthreadP.h | 4 +- sysdeps/unix/sysdep.h | 69 +++++++--- .../sysv/linux/mips/mips32/syscall_cancel.S | 128 ++++++++++++++++++ sysdeps/unix/sysv/linux/mips/mips32/sysdep.h | 4 + .../linux/mips/mips64/n32/syscall_types.h | 28 ++++ .../sysv/linux/mips/mips64/syscall_cancel.S | 108 +++++++++++++++ sysdeps/unix/sysv/linux/mips/mips64/sysdep.h | 52 +++---- sysdeps/unix/sysv/linux/syscall_cancel.c | 6 +- 9 files changed, 354 insertions(+), 56 deletions(-) create mode 100644 sysdeps/unix/sysv/linux/mips/mips32/syscall_cancel.S create mode 100644 sysdeps/unix/sysv/linux/mips/mips64/n32/syscall_types.h create mode 100644 sysdeps/unix/sysv/linux/mips/mips64/syscall_cancel.S diff --git a/nptl/cancellation.c b/nptl/cancellation.c index eee5b6b758..3162492b80 100644 --- a/nptl/cancellation.c +++ b/nptl/cancellation.c @@ -25,6 +25,7 @@ long int __internal_syscall_cancel (__syscall_arg_t a1, __syscall_arg_t a2, __syscall_arg_t a3, __syscall_arg_t a4, __syscall_arg_t a5, __syscall_arg_t a6, + __SYSCALL_CANCEL7_ARG_DEF __syscall_arg_t nr) { long int result; @@ -36,7 +37,8 @@ __internal_syscall_cancel (__syscall_arg_t a1, __syscall_arg_t a2, int ch = atomic_load_relaxed (&pd->cancelhandling); if (SINGLE_THREAD_P || !cancel_enabled (ch) || cancel_exiting (ch)) { - result = INTERNAL_SYSCALL_NCS_CALL (nr, a1, a2, a3, a4, a5, a6); + result = INTERNAL_SYSCALL_NCS_CALL (nr, a1, a2, a3, a4, a5, a6 + __SYSCALL_CANCEL7_ARCH_ARG7); if (INTERNAL_SYSCALL_ERROR_P (result)) return -INTERNAL_SYSCALL_ERRNO (result); return result; @@ -45,7 +47,7 @@ __internal_syscall_cancel (__syscall_arg_t a1, __syscall_arg_t a2, /* Call the arch-specific entry points that contains the globals markers to be checked by SIGCANCEL handler. */ result = __syscall_cancel_arch (&pd->cancelhandling, nr, a1, a2, a3, a4, a5, - a6); + a6 __SYSCALL_CANCEL7_ARCH_ARG7); /* If the cancellable syscall was interrupted by SIGCANCEL and it has not side-effect, cancel the thread if cancellation is enabled. */ @@ -63,9 +65,10 @@ long int __syscall_cancel (__syscall_arg_t a1, __syscall_arg_t a2, __syscall_arg_t a3, __syscall_arg_t a4, __syscall_arg_t a5, __syscall_arg_t a6, - __syscall_arg_t nr) + __SYSCALL_CANCEL7_ARG_DEF __syscall_arg_t nr) { - int r = __internal_syscall_cancel (a1, a2, a3, a4, a5, a6, nr); + int r = __internal_syscall_cancel (a1, a2, a3, a4, a5, a6, + __SYSCALL_CANCEL7_ARG nr); return __glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (r)) ? SYSCALL_ERROR_LABEL (INTERNAL_SYSCALL_ERRNO (r)) : r; diff --git a/sysdeps/nptl/pthreadP.h b/sysdeps/nptl/pthreadP.h index 15a7a063e5..a9d351b9b8 100644 --- a/sysdeps/nptl/pthreadP.h +++ b/sysdeps/nptl/pthreadP.h @@ -276,8 +276,8 @@ __do_cancel (void *result) extern long int __syscall_cancel_arch (volatile int *, __syscall_arg_t nr, __syscall_arg_t arg1, __syscall_arg_t arg2, __syscall_arg_t arg3, - __syscall_arg_t arg4, __syscall_arg_t arg5, __syscall_arg_t arg6) - attribute_hidden; + __syscall_arg_t arg4, __syscall_arg_t arg5, __syscall_arg_t arg6 + __SYSCALL_CANCEL7_ARCH_ARG_DEF) attribute_hidden; extern _Noreturn void __syscall_do_cancel (void) attribute_hidden; diff --git a/sysdeps/unix/sysdep.h b/sysdeps/unix/sysdep.h index 32bc85592e..1cb1f1d9b7 100644 --- a/sysdeps/unix/sysdep.h +++ b/sysdeps/unix/sysdep.h @@ -137,34 +137,59 @@ /* Cancellation macros. */ #include +/* Adjust both the __syscall_cancel and the SYSCALL_CANCEL macro to support + 7 arguments instead of default 6 (curently only mip32). It avoid add + the requirement to each architecture to support 7 argument macros + {INTERNAL,INLINE}_SYSCALL. */ +#ifdef HAVE_CANCELABLE_SYSCALL_WITH_7_ARGS +# define __SYSCALL_CANCEL7_ARG_DEF __syscall_arg_t a7, +# define __SYSCALL_CANCEL7_ARCH_ARG_DEF ,__syscall_arg_t a7 +# define __SYSCALL_CANCEL7_ARG 0, +# define __SYSCALL_CANCEL7_ARG7 a7, +# define __SYSCALL_CANCEL7_ARCH_ARG7 , a7 +#else +# define __SYSCALL_CANCEL7_ARG_DEF +# define __SYSCALL_CANCEL7_ARCH_ARG_DEF +# define __SYSCALL_CANCEL7_ARG +# define __SYSCALL_CANCEL7_ARG7 +# define __SYSCALL_CANCEL7_ARCH_ARG7 +#endif long int __internal_syscall_cancel (__syscall_arg_t a1, __syscall_arg_t a2, __syscall_arg_t a3, __syscall_arg_t a4, __syscall_arg_t a5, __syscall_arg_t a6, + __SYSCALL_CANCEL7_ARG_DEF __syscall_arg_t nr) attribute_hidden; -long int __syscall_cancel (__syscall_arg_t nr, __syscall_arg_t arg1, - __syscall_arg_t arg2, __syscall_arg_t arg3, - __syscall_arg_t arg4, __syscall_arg_t arg5, - __syscall_arg_t arg6) attribute_hidden; +long int __syscall_cancel (__syscall_arg_t arg1, __syscall_arg_t arg2, + __syscall_arg_t arg3, __syscall_arg_t arg4, + __syscall_arg_t arg5, __syscall_arg_t arg6, + __SYSCALL_CANCEL7_ARG_DEF + __syscall_arg_t nr) attribute_hidden; #define __SYSCALL_CANCEL0(name) \ - __syscall_cancel (0, 0, 0, 0, 0, 0, __NR_##name) + __syscall_cancel (0, 0, 0, 0, 0, 0, __SYSCALL_CANCEL7_ARG __NR_##name) #define __SYSCALL_CANCEL1(name, a1) \ - __syscall_cancel (__SSC (a1), 0, 0, 0, 0, 0, __NR_##name) + __syscall_cancel (__SSC (a1), 0, 0, 0, 0, 0, \ + __SYSCALL_CANCEL7_ARG __NR_##name) #define __SYSCALL_CANCEL2(name, a1, a2) \ - __syscall_cancel (__SSC (a1), __SSC (a2), 0, 0, 0, 0, __NR_##name) + __syscall_cancel (__SSC (a1), __SSC (a2), 0, 0, 0, 0, \ + __SYSCALL_CANCEL7_ARG __NR_##name) #define __SYSCALL_CANCEL3(name, a1, a2, a3) \ __syscall_cancel (__SSC (a1), __SSC (a2), __SSC (a3), 0, 0, 0, \ - __NR_##name) + __SYSCALL_CANCEL7_ARG __NR_##name) #define __SYSCALL_CANCEL4(name, a1, a2, a3, a4) \ __syscall_cancel (__SSC (a1), __SSC (a2), __SSC (a3), \ - __SSC(a4), 0, 0, __NR_##name) + __SSC(a4), 0, 0, __SYSCALL_CANCEL7_ARG __NR_##name) #define __SYSCALL_CANCEL5(name, a1, a2, a3, a4, a5) \ __syscall_cancel (__SSC (a1), __SSC (a2), __SSC (a3), __SSC(a4), \ - __SSC (a5), 0, __NR_##name) + __SSC (a5), 0, __SYSCALL_CANCEL7_ARG __NR_##name) #define __SYSCALL_CANCEL6(name, a1, a2, a3, a4, a5, a6) \ __syscall_cancel (__SSC (a1), __SSC (a2), __SSC (a3), __SSC (a4), \ - __SSC (a5), __SSC (a6), __NR_##name) + __SSC (a5), __SSC (a6), __SYSCALL_CANCEL7_ARG \ + __NR_##name) +#define __SYSCALL_CANCEL7(name, a1, a2, a3, a4, a5, a6, a7) \ + __syscall_cancel (__SSC (a1), __SSC (a2), __SSC (a3), __SSC (a4), \ + __SSC (a5), __SSC (a6), __SSC (a7), __NR_##name) #define __SYSCALL_CANCEL_NARGS_X(a,b,c,d,e,f,g,h,n,...) n #define __SYSCALL_CANCEL_NARGS(...) \ @@ -181,25 +206,33 @@ long int __syscall_cancel (__syscall_arg_t nr, __syscall_arg_t arg1, __SYSCALL_CANCEL_DISP (__SYSCALL_CANCEL, __VA_ARGS__) #define __INTERNAL_SYSCALL_CANCEL0(name) \ - __internal_syscall_cancel (0, 0, 0, 0, 0, 0, __NR_##name) + __internal_syscall_cancel (0, 0, 0, 0, 0, 0, __SYSCALL_CANCEL7_ARG \ + __NR_##name) #define __INTERNAL_SYSCALL_CANCEL1(name, a1) \ - __internal_syscall_cancel (__SSC (a1), 0, 0, 0, 0, 0, __NR_##name) + __internal_syscall_cancel (__SSC (a1), 0, 0, 0, 0, 0, \ + __SYSCALL_CANCEL7_ARG __NR_##name) #define __INTERNAL_SYSCALL_CANCEL2(name, a1, a2) \ __internal_syscall_cancel (__SSC (a1), __SSC (a2), 0, 0, 0, 0, \ - __NR_##name) + __SYSCALL_CANCEL7_ARG __NR_##name) #define __INTERNAL_SYSCALL_CANCEL3(name, a1, a2, a3) \ __internal_syscall_cancel (__SSC (a1), __SSC (a2), __SSC (a3), 0, \ - 0, 0, __NR_##name) + 0, 0, __SYSCALL_CANCEL7_ARG __NR_##name) #define __INTERNAL_SYSCALL_CANCEL4(name, a1, a2, a3, a4) \ __internal_syscall_cancel (__SSC (a1), __SSC (a2), __SSC (a3), \ - __SSC(a4), 0, 0, __NR_##name) + __SSC(a4), 0, 0, \ + __SYSCALL_CANCEL7_ARG __NR_##name) #define __INTERNAL_SYSCALL_CANCEL5(name, a1, a2, a3, a4, a5) \ __internal_syscall_cancel (__SSC (a1), __SSC (a2), __SSC (a3), \ - __SSC(a4), __SSC (a5), 0, __NR_##name) + __SSC(a4), __SSC (a5), 0, \ + __SYSCALL_CANCEL7_ARG __NR_##name) #define __INTERNAL_SYSCALL_CANCEL6(name, a1, a2, a3, a4, a5, a6) \ __internal_syscall_cancel (__SSC (a1), __SSC (a2), __SSC (a3), \ __SSC (a4), __SSC (a5), __SSC (a6), \ - __NR_##name) + __SYSCALL_CANCEL7_ARG __NR_##name) +#define __INTERNAL_SYSCALL_CANCEL7(name, a1, a2, a3, a4, a5, a6, a7) \ + __internal_syscall_cancel (__SSC (a1), __SSC (a2), __SSC (a3), \ + __SSC (a4), __SSC (a5), __SSC (a6), \ + __SSC (a7), __NR_##name) /* Issue a cancellable syscall defined by syscall number NAME plus any other argument required. If an error occurs its value is returned as an negative diff --git a/sysdeps/unix/sysv/linux/mips/mips32/syscall_cancel.S b/sysdeps/unix/sysv/linux/mips/mips32/syscall_cancel.S new file mode 100644 index 0000000000..eb3b2ed005 --- /dev/null +++ b/sysdeps/unix/sysv/linux/mips/mips32/syscall_cancel.S @@ -0,0 +1,128 @@ +/* Cancellable syscall wrapper. Linux/mips32 version. + Copyright (C) 2023 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 + . */ + +#include +#include +#include + +/* long int __syscall_cancel_arch (int *cancelhandling, + __syscall_arg_t nr, + __syscall_arg_t arg1, + __syscall_arg_t arg2, + __syscall_arg_t arg3, + __syscall_arg_t arg4, + __syscall_arg_t arg5, + __syscall_arg_t arg6, + __syscall_arg_t arg7) */ + +#define FRAME_SIZE 56 + +NESTED (__syscall_cancel_arch, FRAME_SIZE, fp) + .mask 0xc0070000,-SZREG + .fmask 0x00000000,0 + + PTR_ADDIU sp, -FRAME_SIZE + cfi_def_cfa_offset (FRAME_SIZE) + + sw fp, 48(sp) + sw ra, 52(sp) + sw s2, 44(sp) + sw s1, 40(sp) + sw s0, 36(sp) +#ifdef __PIC__ + .cprestore 16 +#endif + cfi_offset (ra, -4) + cfi_offset (fp, -8) + cfi_offset (s2, -12) + cfi_offset (s1, -16) + cfi_offset (s0, -20) + + move fp ,sp + cfi_def_cfa_register (fp) + + .globl __syscall_cancel_arch_start +__syscall_cancel_arch_start: + + lw v0, 0(a0) + andi v0, v0, TCB_CANCELED_BITMASK + bne v0, zero, 2f + + addiu sp, sp, -16 + addiu v0, sp, 16 + sw v0, 24(fp) + + move s0, a1 + move a0, a2 + move a1, a3 + lw a2, 72(fp) + lw a3, 76(fp) + lw v0, 84(fp) + lw s1, 80(fp) + lw s2, 88(fp) + + .set noreorder + subu sp, 32 + sw s1, 16(sp) + sw v0, 20(sp) + sw s2, 24(sp) + move v0, s0 + syscall + + .globl __syscall_cancel_arch_end +__syscall_cancel_arch_end: + addiu sp, sp, 32 + .set reorder + + beq a3, zero, 1f + subu v0, zero, v0 +1: + move sp, fp + cfi_remember_state + cfi_def_cfa_register (sp) + lw ra, 52(fp) + lw fp, 48(sp) + lw s2, 44(sp) + lw s1, 40(sp) + lw s0, 36(sp) + + .set noreorder + .set nomacro + jr ra + addiu sp,sp,FRAME_SIZE + + .set macro + .set reorder + + cfi_def_cfa_offset (0) + cfi_restore (s0) + cfi_restore (s1) + cfi_restore (s2) + cfi_restore (fp) + cfi_restore (ra) + +2: + cfi_restore_state +#ifdef __PIC__ + PTR_LA t9, __syscall_do_cancel + jalr t9 +#else + jal __syscall_do_cancel +#endif + +END (__syscall_cancel_arch) diff --git a/sysdeps/unix/sysv/linux/mips/mips32/sysdep.h b/sysdeps/unix/sysv/linux/mips/mips32/sysdep.h index 1318083195..3ba5334d66 100644 --- a/sysdeps/unix/sysv/linux/mips/mips32/sysdep.h +++ b/sysdeps/unix/sysv/linux/mips/mips32/sysdep.h @@ -18,6 +18,10 @@ #ifndef _LINUX_MIPS_MIPS32_SYSDEP_H #define _LINUX_MIPS_MIPS32_SYSDEP_H 1 +/* mips32 have cancelable syscalls with 7 arguments (currently only + sync_file_range). */ +#define HAVE_CANCELABLE_SYSCALL_WITH_7_ARGS 1 + /* There is some commonality. */ #include #include diff --git a/sysdeps/unix/sysv/linux/mips/mips64/n32/syscall_types.h b/sysdeps/unix/sysv/linux/mips/mips64/n32/syscall_types.h new file mode 100644 index 0000000000..b3a8b0b634 --- /dev/null +++ b/sysdeps/unix/sysv/linux/mips/mips64/n32/syscall_types.h @@ -0,0 +1,28 @@ +/* Types and macros used for syscall issuing. MIPS64n32 version. + Copyright (C) 2023 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 + . */ + +#ifndef _SYSCALL_TYPES_H +#define _SYSCALL_TYPES_H + +typedef long long int __syscall_arg_t; + +/* Convert X to a long long, without losing any bits if it is one + already or warning if it is a 32-bit pointer. */ +#define __SSC(__x) ((__syscall_arg_t) (__typeof__ ((__x) - (__x))) (__x)) + +#endif diff --git a/sysdeps/unix/sysv/linux/mips/mips64/syscall_cancel.S b/sysdeps/unix/sysv/linux/mips/mips64/syscall_cancel.S new file mode 100644 index 0000000000..f172041324 --- /dev/null +++ b/sysdeps/unix/sysv/linux/mips/mips64/syscall_cancel.S @@ -0,0 +1,108 @@ +/* Cancellable syscall wrapper. Linux/mips64 version. + Copyright (C) 2023 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 + . */ + +#include +#include +#include + +/* long int __syscall_cancel_arch (int *cancelhandling, + __syscall_arg_t nr, + __syscall_arg_t arg1, + __syscall_arg_t arg2, + __syscall_arg_t arg3, + __syscall_arg_t arg4, + __syscall_arg_t arg5, + __syscall_arg_t arg6, + __syscall_arg_t arg7) */ + +#define FRAME_SIZE 32 + + .text +NESTED (__syscall_cancel_arch, FRAME_SIZE, ra) + .mask 0x90010000, -SZREG + .fmask 0x00000000, 0 + LONG_ADDIU sp, sp, -FRAME_SIZE + cfi_def_cfa_offset (FRAME_SIZE) + sd gp, 16(sp) + cfi_offset (gp, -16) + lui gp, %hi(%neg(%gp_rel(__syscall_cancel_arch))) + LONG_ADDU gp, gp, t9 + sd ra, 24(sp) + sd s0, 8(sp) + cfi_offset (ra, -8) + cfi_offset (s0, -24) + LONG_ADDIU gp, gp, %lo(%neg(%gp_rel(__syscall_cancel_arch))) + + .global __syscall_cancel_arch_start +__syscall_cancel_arch_start: + + lw v0, 0(a0) + andi v0, v0, TCB_CANCELED_BITMASK + .set noreorder + .set nomacro + bne v0, zero, 2f + move s0, a1 + .set macro + .set reorder + + move a0, a2 + move a1, a3 + move a2, a4 + move a3, a5 + move a4, a6 + move a5, a7 + + .set noreorder + move v0, s0 + syscall + .set reorder + + .global __syscall_cancel_arch_end +__syscall_cancel_arch_end: + + .set noreorder + .set nomacro + bnel a3, zero, 1f + SUBU v0, zero, v0 + .set macro + .set reorder + +1: + ld ra, 24(sp) + ld gp, 16(sp) + ld s0, 8(sp) + + .set noreorder + .set nomacro + jr ra + LONG_ADDIU sp, sp, FRAME_SIZE + .set macro + .set reorder + + cfi_remember_state + cfi_def_cfa_offset (0) + cfi_restore (s0) + cfi_restore (gp) + cfi_restore (ra) + .align 3 +2: + cfi_restore_state + LONG_L t9, %got_disp(__syscall_do_cancel)(gp) + .reloc 3f, R_MIPS_JALR, __syscall_do_cancel +3: jalr t9 +END (__syscall_cancel_arch) diff --git a/sysdeps/unix/sysv/linux/mips/mips64/sysdep.h b/sysdeps/unix/sysv/linux/mips/mips64/sysdep.h index d7ae60f596..db27bd9e4d 100644 --- a/sysdeps/unix/sysv/linux/mips/mips64/sysdep.h +++ b/sysdeps/unix/sysv/linux/mips/mips64/sysdep.h @@ -44,15 +44,7 @@ #undef HAVE_INTERNAL_BRK_ADDR_SYMBOL #define HAVE_INTERNAL_BRK_ADDR_SYMBOL 1 -#if _MIPS_SIM == _ABIN32 -/* Convert X to a long long, without losing any bits if it is one - already or warning if it is a 32-bit pointer. */ -# define ARGIFY(X) ((long long int) (__typeof__ ((X) - (X))) (X)) -typedef long long int __syscall_arg_t; -#else -# define ARGIFY(X) ((long int) (X)) -typedef long int __syscall_arg_t; -#endif +#include /* Note that the original Linux syscall restart convention required the instruction immediately preceding SYSCALL to initialize $v0 with the @@ -120,7 +112,7 @@ typedef long int __syscall_arg_t; long int _sys_result; \ \ { \ - __syscall_arg_t _arg1 = ARGIFY (arg1); \ + __syscall_arg_t _arg1 = __SSC (arg1); \ register __syscall_arg_t __s0 asm ("$16") __attribute__ ((unused))\ = (number); \ register __syscall_arg_t __v0 asm ("$2"); \ @@ -144,8 +136,8 @@ typedef long int __syscall_arg_t; long int _sys_result; \ \ { \ - __syscall_arg_t _arg1 = ARGIFY (arg1); \ - __syscall_arg_t _arg2 = ARGIFY (arg2); \ + __syscall_arg_t _arg1 = __SSC (arg1); \ + __syscall_arg_t _arg2 = __SSC (arg2); \ register __syscall_arg_t __s0 asm ("$16") __attribute__ ((unused))\ = (number); \ register __syscall_arg_t __v0 asm ("$2"); \ @@ -170,9 +162,9 @@ typedef long int __syscall_arg_t; long int _sys_result; \ \ { \ - __syscall_arg_t _arg1 = ARGIFY (arg1); \ - __syscall_arg_t _arg2 = ARGIFY (arg2); \ - __syscall_arg_t _arg3 = ARGIFY (arg3); \ + __syscall_arg_t _arg1 = __SSC (arg1); \ + __syscall_arg_t _arg2 = __SSC (arg2); \ + __syscall_arg_t _arg3 = __SSC (arg3); \ register __syscall_arg_t __s0 asm ("$16") __attribute__ ((unused))\ = (number); \ register __syscall_arg_t __v0 asm ("$2"); \ @@ -199,10 +191,10 @@ typedef long int __syscall_arg_t; long int _sys_result; \ \ { \ - __syscall_arg_t _arg1 = ARGIFY (arg1); \ - __syscall_arg_t _arg2 = ARGIFY (arg2); \ - __syscall_arg_t _arg3 = ARGIFY (arg3); \ - __syscall_arg_t _arg4 = ARGIFY (arg4); \ + __syscall_arg_t _arg1 = __SSC (arg1); \ + __syscall_arg_t _arg2 = __SSC (arg2); \ + __syscall_arg_t _arg3 = __SSC (arg3); \ + __syscall_arg_t _arg4 = __SSC (arg4); \ register __syscall_arg_t __s0 asm ("$16") __attribute__ ((unused))\ = (number); \ register __syscall_arg_t __v0 asm ("$2"); \ @@ -229,11 +221,11 @@ typedef long int __syscall_arg_t; long int _sys_result; \ \ { \ - __syscall_arg_t _arg1 = ARGIFY (arg1); \ - __syscall_arg_t _arg2 = ARGIFY (arg2); \ - __syscall_arg_t _arg3 = ARGIFY (arg3); \ - __syscall_arg_t _arg4 = ARGIFY (arg4); \ - __syscall_arg_t _arg5 = ARGIFY (arg5); \ + __syscall_arg_t _arg1 = __SSC (arg1); \ + __syscall_arg_t _arg2 = __SSC (arg2); \ + __syscall_arg_t _arg3 = __SSC (arg3); \ + __syscall_arg_t _arg4 = __SSC (arg4); \ + __syscall_arg_t _arg5 = __SSC (arg5); \ register __syscall_arg_t __s0 asm ("$16") __attribute__ ((unused))\ = (number); \ register __syscall_arg_t __v0 asm ("$2"); \ @@ -261,12 +253,12 @@ typedef long int __syscall_arg_t; long int _sys_result; \ \ { \ - __syscall_arg_t _arg1 = ARGIFY (arg1); \ - __syscall_arg_t _arg2 = ARGIFY (arg2); \ - __syscall_arg_t _arg3 = ARGIFY (arg3); \ - __syscall_arg_t _arg4 = ARGIFY (arg4); \ - __syscall_arg_t _arg5 = ARGIFY (arg5); \ - __syscall_arg_t _arg6 = ARGIFY (arg6); \ + __syscall_arg_t _arg1 = __SSC (arg1); \ + __syscall_arg_t _arg2 = __SSC (arg2); \ + __syscall_arg_t _arg3 = __SSC (arg3); \ + __syscall_arg_t _arg4 = __SSC (arg4); \ + __syscall_arg_t _arg5 = __SSC (arg5); \ + __syscall_arg_t _arg6 = __SSC (arg6); \ register __syscall_arg_t __s0 asm ("$16") __attribute__ ((unused))\ = (number); \ register __syscall_arg_t __v0 asm ("$2"); \ diff --git a/sysdeps/unix/sysv/linux/syscall_cancel.c b/sysdeps/unix/sysv/linux/syscall_cancel.c index 260680c99f..5fa0706486 100644 --- a/sysdeps/unix/sysv/linux/syscall_cancel.c +++ b/sysdeps/unix/sysv/linux/syscall_cancel.c @@ -52,7 +52,8 @@ long int __syscall_cancel_arch (volatile int *ch, __syscall_arg_t nr, __syscall_arg_t a1, __syscall_arg_t a2, __syscall_arg_t a3, __syscall_arg_t a4, - __syscall_arg_t a5, __syscall_arg_t a6) + __syscall_arg_t a5, __syscall_arg_t a6 + __SYSCALL_CANCEL7_ARG_DEF) { #define ADD_LABEL(__label) \ asm volatile ( \ @@ -63,7 +64,8 @@ __syscall_cancel_arch (volatile int *ch, __syscall_arg_t nr, if (__glibc_unlikely (*ch & CANCELED_BITMASK)) __syscall_do_cancel(); - long int result = INTERNAL_SYSCALL_NCS_CALL (nr, a1, a2, a3, a4, a5, a6); + long int result = INTERNAL_SYSCALL_NCS_CALL (nr, a1, a2, a3, a4, a5, a6 + __SYSCALL_CANCEL7_ARG7); ADD_LABEL ("__syscall_cancel_arch_end"); if (__glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (result))) return -INTERNAL_SYSCALL_ERRNO (result); From patchwork Mon Apr 10 20:46:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 67594 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1B76F38708B0 for ; Mon, 10 Apr 2023 20:50:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1B76F38708B0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1681159822; bh=n+scPVh0AMfi+z8F+ULlnmVmFD1YNzH6BNcSZIF/OPg=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=uf235DRi8zwvy6IKU5vEebiR8806+jpnlxSc+Bu2LKfTxQDwqInkqMDvPjnG2JWND 22pW4OIfRIufqcYrWVDjXu3MmeCWNmwiNiqYFZIcxiE+lxwsSB8v1z192mprCWi5Rj PeMHuf7Tr0GcE64oUZyWeyKqUYEcodU/wiwQFeR0= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oi1-x22f.google.com (mail-oi1-x22f.google.com [IPv6:2607:f8b0:4864:20::22f]) by sourceware.org (Postfix) with ESMTPS id 6B4863856DD0 for ; Mon, 10 Apr 2023 20:46:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6B4863856DD0 Received: by mail-oi1-x22f.google.com with SMTP id e9so3997013oig.7 for ; Mon, 10 Apr 2023 13:46:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681159601; x=1683751601; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=n+scPVh0AMfi+z8F+ULlnmVmFD1YNzH6BNcSZIF/OPg=; b=LKfX3HUh23a/inVwabRUiUYsKpnlL+CK39c6VORU97FKar9+eldcWMGcYA75bIuUCG ajEAD4G0sd1zXuQzcPJnb6gbApcIgqhnrj4cNhJb9Ou0ZILc5/u7X12AJQCb3NNuAdst CsjX3XyoinZKD6+BZ59qCKLcRDOkMATuY+T9nMGbVWOuOZRFLQ+At98bRk1WVD1Q5LGH CsZaMcH6jlItr4n4fGn747XGhATKbWatAUBZerH+OXjpK7wdUq3W1zusd/GweVrIs7LH 2idIRsGJ3CfftfEGWD/c7A/DfbYm1NeLrVrEHMIfyq1XyJEibEz4FMU7/jZQvFmi1lEa d8qQ== X-Gm-Message-State: AAQBX9cHJ3YAyYAo+1ZVrXkANrwxAgdTCGwn63N5/zlFAshMRsZUz27S UIrefhWVt3kBjIU5ANK054j1b2guBV8t8p/tIf6KEA== X-Google-Smtp-Source: AKy350ZtlRPD23rKJjH/jtBD26XG+qlGij/z6MfmpzJhpcBtn+QlTTWGyAVxpjNs/BH60X5YSq2aHQ== X-Received: by 2002:a05:6808:2a83:b0:389:f9b:2171 with SMTP id fc3-20020a0568082a8300b003890f9b2171mr149927oib.35.1681159601089; Mon, 10 Apr 2023 13:46:41 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c2:55a1:d59a:609a:284:6ed]) by smtp.gmail.com with ESMTPSA id p5-20020acabf05000000b003896f132821sm4865732oif.41.2023.04.10.13.46.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Apr 2023 13:46:40 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v5 21/22] or1k: Fix Race conditions in pthread cancellation [BZ#12683] Date: Mon, 10 Apr 2023 17:46:13 -0300 Message-Id: <20230410204614.4129551-13-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230410204614.4129551-1-adhemerval.zanella@linaro.org> References: <20230410195907.4123869-1-adhemerval.zanella@linaro.org> <20230410204614.4129551-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SCC_5_SHORT_WORD_LINES, SPF_HELO_NONE, SPF_PASS, TXREP 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-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" By adding the required syscall_cancel.S. Checked against a build and make check run-built-tests=no for or1k-linux-gnu-soft. --- sysdeps/unix/sysv/linux/or1k/syscall_cancel.S | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/or1k/syscall_cancel.S diff --git a/sysdeps/unix/sysv/linux/or1k/syscall_cancel.S b/sysdeps/unix/sysv/linux/or1k/syscall_cancel.S new file mode 100644 index 0000000000..284029b244 --- /dev/null +++ b/sysdeps/unix/sysv/linux/or1k/syscall_cancel.S @@ -0,0 +1,63 @@ +/* Cancellable syscall wrapper. Linux/or1k version. + Copyright (C) 2023 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 + . */ + +#include +#include + +ENTRY (__syscall_cancel_arch) + l.addi r1, r1, -4 + cfi_def_cfa_offset (4) + l.sw 0(r1), r9 + cfi_offset (9, -4) + + .global __syscall_cancel_arch_start +__syscall_cancel_arch_start: + + /* if (*cancelhandling & CANCELED_BITMASK) + __syscall_do_cancel() */ + l.movhi r19, hi(0) + l.lwz r17, 0(r3) + l.andi r17, r17, 8 + l.sfeq r17, r19 + l.bnf 1f + + /* Issue a 6 argument syscall. */ + l.or r11, r4, r4 + l.or r3, r5, r5 + l.or r4, r6, r6 + l.or r5, r7, r7 + l.or r6, r8, r8 + l.lwz r7, 4(r1) + l.lwz r8, 8(r1) + l.sys 1 + l.nop + + .global __syscall_cancel_arch_end +__syscall_cancel_arch_end: + + l.lwz r9, 0(r1) + l.jr r9 + l.addi r1, r1, 4 + cfi_remember_state + cfi_def_cfa_offset (0) + cfi_restore (9) +1: + cfi_restore_state + l.jal __syscall_do_cancel + l.nop +END (__syscall_cancel_arch) From patchwork Mon Apr 10 20:46:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 67591 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 518043834684 for ; Mon, 10 Apr 2023 20:48:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 518043834684 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1681159707; bh=AsTeusHYh3gPGXyOTH+U5eHT2trnNdZH7CplkDr7av0=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=ZawPPCJulG/d2q2MzZsFv0d9n/6N5GzbeItUasmLCu0rMoFr3IqEgErrQ3k8lcRFF GDs+5j0ouJF4lzu335Swv2hlc1R5VWvFeehbv5GDvs53JZISaTtE/xBzoGq1JswWTC OonyZ7O/p0HnXNWU9OOXlImWpkQ4XlViYkKlKaHI= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oi1-x233.google.com (mail-oi1-x233.google.com [IPv6:2607:f8b0:4864:20::233]) by sourceware.org (Postfix) with ESMTPS id 4ED56385773A for ; Mon, 10 Apr 2023 20:46:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4ED56385773A Received: by mail-oi1-x233.google.com with SMTP id bf5so4073583oib.8 for ; Mon, 10 Apr 2023 13:46:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681159603; x=1683751603; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AsTeusHYh3gPGXyOTH+U5eHT2trnNdZH7CplkDr7av0=; b=CQwtB0V9y+VEr50Fk9YnDi75OH7ig3Oeeikc4eIh29x2IqrWm3IYQP1TQ/g5WsO3ZG yD+r7HZYW56ul0ZudQq2aAEpZA+QyNULlhL26GV7rh84b8t+oiCNCW/f4jmzWljbODBP mu3+9bVGpbn9nkU2jMVAzbvgNcrmos1mAI+5doLQRzvFuKihqWIrvDd155R5tqSyOoGZ Pv9jDQeNRMMk8K9XYWrlPhfBR5GBFkvgVhExlDKcVGfR1nC6YNEy/L9WGGG8bSo9cNSk 4notfM4TYg1f7NsB4pMPOiaqncADSg0U+jqWHpireCxqQl/T4057tyqui/GUmSLBQoYV edPg== X-Gm-Message-State: AAQBX9dT2Ou7C1F109I2iIayk277r7tUziEjbjcpgaaXHc2Y/P7ucYxw mt0mJy1LJ+xBqhTZN1KRmsLiej7TV76JphkVKdQizQ== X-Google-Smtp-Source: AKy350auYyenYzU/tgJOQ6NrU8ZLnyKJCrsJXAKmpUYou4pS2FfVILWHiFcbpq8iNwU54pwf76LIbQ== X-Received: by 2002:a05:6808:4244:b0:384:1793:90cf with SMTP id dp4-20020a056808424400b00384179390cfmr3817056oib.0.1681159603332; Mon, 10 Apr 2023 13:46:43 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c2:55a1:d59a:609a:284:6ed]) by smtp.gmail.com with ESMTPSA id p5-20020acabf05000000b003896f132821sm4865732oif.41.2023.04.10.13.46.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Apr 2023 13:46:42 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v5 22/22] loongarch: Fix Race conditions in pthread cancellation [BZ#12683] Date: Mon, 10 Apr 2023 17:46:14 -0300 Message-Id: <20230410204614.4129551-14-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230410204614.4129551-1-adhemerval.zanella@linaro.org> References: <20230410195907.4123869-1-adhemerval.zanella@linaro.org> <20230410204614.4129551-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" By adding the required syscall_cancel.S. Checked against a build and make check run-built-tests=no for loongarch64-linux-gnu-lp64d. --- .../sysv/linux/loongarch/syscall_cancel.S | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/loongarch/syscall_cancel.S diff --git a/sysdeps/unix/sysv/linux/loongarch/syscall_cancel.S b/sysdeps/unix/sysv/linux/loongarch/syscall_cancel.S new file mode 100644 index 0000000000..574252fec1 --- /dev/null +++ b/sysdeps/unix/sysv/linux/loongarch/syscall_cancel.S @@ -0,0 +1,54 @@ +/* Cancellable syscall wrapper. Linux/loongarch version. + Copyright (C) 2023 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 + . */ + +#include +#include + +ENTRY (__syscall_cancel_arch) + + .global __syscall_cancel_arch_start +__syscall_cancel_arch_start: + + /* if (*cancelhandling & CANCELED_BITMASK) + __syscall_do_cancel() */ + ldptr.w $r12,$r4,0 + andi $r12,$r12,TCB_CANCELED_BITMASK + bnez $r12,1f + + /* Issue a 6 argument syscall. */ + or $r13,$r5,$r0 + or $r4,$r6,$r0 + or $r5,$r7,$r0 + or $r6,$r8,$r0 + or $r7,$r9,$r0 + or $r8,$r10,$r0 + or $r9,$r11,$r0 + or $r11,$r13,$r0 + syscall 0 + + .global __syscall_cancel_arch_end +__syscall_cancel_arch_end: + jr $r1 +1: + addi.d $r3,$r3,-16 + cfi_def_cfa_offset (16) + st.d $r1,$r3,8 + cfi_offset (1, -8) + bl __syscall_do_cancel + +END (__syscall_cancel_arch)