From patchwork Mon Aug 23 19:50:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 44748 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 AC5923858022 for ; Mon, 23 Aug 2021 19:52:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AC5923858022 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1629748369; bh=rl7CPImmCOQ2k9L7VZsxPxcdXaAwOMjTXpuupAnd5jU=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=lgN0vompsMokQtEM5Z+ktyEfBTy60VYkDj6D8QOH3LR2Lty4ocIGiVbIyvDPKJtM+ 8ssPSwg0Va+KxnTD7ZhnQCuKLm3DL2S4YjnvH+CPjhO0Z06qNpAHqEyn1W5ttyeytd RPM2O73BkHaxIu/52fZlKvB3qMyIJgTiybHhvAVc= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x735.google.com (mail-qk1-x735.google.com [IPv6:2607:f8b0:4864:20::735]) by sourceware.org (Postfix) with ESMTPS id 96CFE3858C2C for ; Mon, 23 Aug 2021 19:50:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 96CFE3858C2C Received: by mail-qk1-x735.google.com with SMTP id t4so6140501qkb.9 for ; Mon, 23 Aug 2021 12:50:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=rl7CPImmCOQ2k9L7VZsxPxcdXaAwOMjTXpuupAnd5jU=; b=hrdkDYWRCy5D+kycaEeXKjRLkgBjU+7rTgq2G/TRG+1m1R2cXSJLKAx1XL14rKVBb/ FAHjbBvWdrFYcGzlgBFhhj5/okXMjRryDdTnu4x1hVrBEGk2hkNRALSTmdvHRwjXIiAP pzJ7x1nKx7BAmy8aYVN7K2VHbX4pqkrf7DfoyuA6/s6+AJ42kzjsQXnw/w2kffI9BTSb E9qnmp2p/WkXZ16TMDiufFuNVSeTRCN/RYe2snIw1z43RnWndjSBDeqnBZ4sQCKlElCZ REQ17OtSzAn+ZXacz3Zms3lDVtHP+Ye8Be4rb3OnP8oZAuZtZedKoRIJkq/TzjUDYWpH EIQw== X-Gm-Message-State: AOAM530FTuberH9xH6RwU1MZvDz2e4TyBLfoHJYWGnh2MaJ4b6Rh8YWP ZsLmC6mHXAotLwSa4cgekT3/tBlA9hFCGA== X-Google-Smtp-Source: ABdhPJyex0w6Q37lcIMRoR/sCBInKn0xDbjm1MUfG8mY+w2SIgj9HgXR1pDiiWLBJn/q5Xvx6NQuLA== X-Received: by 2002:a37:4141:: with SMTP id o62mr1722851qka.380.1629748250978; Mon, 23 Aug 2021 12:50:50 -0700 (PDT) Received: from birita.. ([2804:431:c7ca:cd83:c38b:b50d:5d9a:43d4]) by smtp.gmail.com with ESMTPSA id s10sm9210935qko.134.2021.08.23.12.50.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Aug 2021 12:50:50 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v2 00/19] Fix various NPTL synchronization issues Date: Mon, 23 Aug 2021 16:50:28 -0300 Message-Id: <20210823195047.543237-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Spam-Status: No, score=-5.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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 Cc: Florian Weimer Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" This is an update of my previous set to fix some NPTL issues [1]. The main changes are: - Rebased against master and adjusted the __clone_internal usage. - Adapted Florian's ESRCH fixes [2] - Add fixes for various function that access the 'tid'. Patch 01 to 03 are general nptl fixes and they are independent of the other fixes. Patch 04 is the main change of this patchset, it uses a different field instead of the pthread 'tid' to synchrnonize the internal thread state (BZ#19951). It allows to both move the thread setxid internal state out of 'cancelhandling' (used on setuid() call in multi-thread information), and remove the EXITING_BIT and TERMINATED_BIT (since 'joinstate' now track such it). This is done on patch 05 and 06. Patches 08 and 09 fixes two long standing issues regarding pthread_kill() and thread exit (BZ#12889 and BZ#19193). Now that] 'tid' is setting explicitly by pthread_create(), a simple lock can be used instead of more complex futex operation. Patches 10 to 18 extend the same 'tid' access fix to other pthread functions that uses the member. [1] https://patchwork.sourceware.org/project/glibc/list/?series=2304 [2] https://patchwork.sourceware.org/project/glibc/list/?series=2696 Adhemerval Zanella (16): nptl: Fix tst-cancel7 and tst-cancelx7 race condition (BZ #14232) nptl: Set cancellation type and state on pthread_exit nptl: Handle robust PI mutexes for !__ASSUME_SET_ROBUST_LIST nptl: Do not use pthread set_tid_address as state synchronization (BZ #19951) nptl: Move setxid flag out of cancelhandling nptl: Replace struct thread cancelhandling field nptl: Use tidlock when accessing TID on pthread_getaffinity_np nptl: Use tidlock when accessing TID on pthread_setaffinity nptl: Use tidlock when accessing TID on pthread_getcpuclockid nptl: Use tidlock when accessing TID on pthread_getschedparam nptl: Use tidlock when accessing TID on pthread_setschedparam nptl: Use tidlock when accessing TID on pthread_getname_np nptl: Use tidlock when accessing TID on pthread_setname_np nptl: Use tidlock when accessing TID on pthread_sigqueue nptl: Use tidlock when accessing TID on pthread_setschedprio nptl: Remove INVALID_TD_P Florian Weimer (3): support: Add support_wait_for_thread_exit nptl: pthread_kill, pthread_cancel should fail after exit (bug 19193) nptl: Fix race between pthread_kill and thread exit (bug 12889) nptl/Makefile | 3 +- nptl/Versions | 1 + nptl/allocatestack.c | 6 +- nptl/cancellation.c | 17 +- nptl/descr.h | 48 +++--- nptl/nptl-stack.h | 2 +- nptl/nptl_free_tcb.c | 22 +-- nptl/nptl_setxid.c | 49 ++---- nptl/pthread_cancel.c | 20 +-- nptl/pthread_clockjoin.c | 2 +- nptl/pthread_create.c | 124 ++++++++------ nptl/pthread_detach.c | 36 ++-- nptl/pthread_exit.c | 4 +- nptl/pthread_getaffinity.c | 22 ++- nptl/pthread_getattr_np.c | 2 +- nptl/pthread_getcpuclockid.c | 27 +-- nptl/pthread_getname.c | 45 +++-- nptl/pthread_getschedparam.c | 16 +- nptl/pthread_join.c | 2 +- nptl/pthread_join_common.c | 126 +++++--------- nptl/pthread_kill.c | 21 ++- nptl/pthread_setaffinity.c | 22 ++- nptl/pthread_setname.c | 34 ++-- nptl/pthread_setschedparam.c | 16 +- nptl/pthread_setschedprio.c | 17 +- nptl/pthread_sigqueue.c | 52 +++--- nptl/pthread_testcancel.c | 11 +- nptl/pthread_timedjoin.c | 2 +- nptl/pthread_tryjoin.c | 18 +- nptl/tst-cancel7.c | 114 ++++++------- nptl/tst-cleanup5.c | 157 ++++++++++++++++++ nptl_db/structs.def | 2 +- nptl_db/td_thr_get_info.c | 16 +- nptl_db/td_thr_getfpregs.c | 9 +- nptl_db/td_thr_getgregs.c | 9 +- nptl_db/td_thr_setfpregs.c | 9 +- nptl_db/td_thr_setgregs.c | 9 +- support/Makefile | 3 +- support/support.h | 4 + support/support_wait_for_thread_exit.c | 72 ++++++++ sysdeps/hppa/nptl/tcb-offsets.sym | 1 - sysdeps/i386/nptl/tcb-offsets.sym | 1 - sysdeps/nptl/dl-tls_init_tp.c | 4 +- sysdeps/nptl/libc_start_call_main.h | 7 + sysdeps/nptl/pthreadP.h | 27 +-- sysdeps/pthread/Makefile | 7 +- sysdeps/pthread/tst-kill4.c | 90 ---------- sysdeps/pthread/tst-pthread_cancel-exited.c | 45 +++++ .../pthread/tst-pthread_cancel-select-loop.c | 87 ++++++++++ sysdeps/pthread/tst-pthread_kill-exited.c | 46 +++++ sysdeps/pthread/tst-pthread_kill-exiting.c | 110 ++++++++++++ sysdeps/pthread/tst-thrd-detach.c | 16 +- sysdeps/sh/nptl/tcb-offsets.sym | 1 - sysdeps/x86_64/nptl/tcb-offsets.sym | 4 - 54 files changed, 1037 insertions(+), 580 deletions(-) create mode 100644 nptl/tst-cleanup5.c create mode 100644 support/support_wait_for_thread_exit.c delete mode 100644 sysdeps/pthread/tst-kill4.c create mode 100644 sysdeps/pthread/tst-pthread_cancel-exited.c create mode 100644 sysdeps/pthread/tst-pthread_cancel-select-loop.c create mode 100644 sysdeps/pthread/tst-pthread_kill-exited.c create mode 100644 sysdeps/pthread/tst-pthread_kill-exiting.c