From patchwork Thu May 27 17:28:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 1484738 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=kb7zsyHM; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FrZY04xP5z9sT6 for ; Fri, 28 May 2021 03:28:36 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C5AC53838006; Thu, 27 May 2021 17:28:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C5AC53838006 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1622136511; bh=9JsYfJ0bD0PtXrUnf7nG1BJp8WxZ1G4+nM1QUkLk/ZM=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=kb7zsyHMzqRrP9zFFu/gfui8sc9NFHnQxIkCET/44nbbCWyn5K6ueAYLO/QPhUBLI zRofrde0HO2m3qkbv1/2lN+g3RycAKX+B3g/Ro/Nbv+EDZ0H7f3vveW3mqSvSOVvCg YX3A1/PETpp7a0Y/Ea3ezt9OuXChjB22gz0o2pvQ= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x736.google.com (mail-qk1-x736.google.com [IPv6:2607:f8b0:4864:20::736]) by sourceware.org (Postfix) with ESMTPS id AF2BA3844007 for ; Thu, 27 May 2021 17:28:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org AF2BA3844007 Received: by mail-qk1-x736.google.com with SMTP id k4so1464730qkd.0 for ; Thu, 27 May 2021 10:28:28 -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:subject:date:message-id:mime-version :content-transfer-encoding; bh=9JsYfJ0bD0PtXrUnf7nG1BJp8WxZ1G4+nM1QUkLk/ZM=; b=oq7tTrHcUnQ2WcufctwxkUlBIBHTRV2IZN2GIIipfuky8+8a3VlwNZ/y/+W8QFlcKQ ErOOtNLrwtTGb1Ta1j/cP1Qi0iFjhQPFeO1Q9y4MvY3jXDxP1FfXd/H0ifTOBof4BUk8 DQ6hxqpuVLoAK72NTUPyKKYawOGeNuM3Wo+QqVKm6bThnXvHdJBozkTfbgQ0wpatgxHh lhAxYSPyReEhbX5GbKQf+meOoSfE+sztr7OnlgKzN4+RXI9BioxEvsmy3eOkR1sv4QDa WGCKR+OngyNgfaXwLmWJqW4enR6+hMp8u0perX+JWfdRykjAjohiZiO7E+ae/7Lp3CM8 9jEA== X-Gm-Message-State: AOAM532+exRp9UATkeI3oxXMFdbkDfydQPPea/DcDmvBji05GivG6Ncp zLtOX6Xz7tUE4XxlJ1DvLOTbpGoYJywOKg== X-Google-Smtp-Source: ABdhPJxN1qEg2a4G/2ZpsSQVmntF0/IFRHKpg8x7yta8TweZqpAdz96czGGxX6KeLcn+ll/DJIApQQ== X-Received: by 2002:a37:4697:: with SMTP id t145mr4601745qka.188.1622136507904; Thu, 27 May 2021 10:28:27 -0700 (PDT) Received: from birita.. ([177.194.37.86]) by smtp.googlemail.com with ESMTPSA id 25sm1767913qtd.51.2021.05.27.10.28.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 May 2021 10:28:27 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v2 0/9] nptl: pthread cancellation refactor Date: Thu, 27 May 2021 14:28:14 -0300 Message-Id: <20210527172823.3461314-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Spam-Status: No, score=-6.6 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.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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 Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" Changes from v1 [1]: - Moved the __do_cancel call for the BZ #19511 fix to a place where the PD is held by the thread. - Fixed style issues. - Added the BZ#19366 fix. --- This patchset refactor and simplifies the nptl cancellation code. The 1st patch is a NFC change. The 2nd patch fixes an memory leak issue when pthread_create fails to setup either the scheduling or affinity parameter. The asynchronous cancellation is removed in favor of using a member to indicate the setup has failed and letting the created thread to deallocate the memory (similar on how detached threads do). The 3rd patch moves the signal handler setup to pthread_cancel, now that asynchronous cancellation is not used anymore on thread creation. The 4th removes the CANCELING_BITMASK bit, since it is mainly used to signal that a syscall that has returned should be cancelled (which is a wrong assumption, since syscall with side-effects should *not* be cancelled as per BZ#12683). The 5th and 6th patches move both the cancel state and cancel type out of 'cancelhandling' variable, since with CANCELING_BITMASK and pthread_cancel change in previous patch they are not accessed in a concurrent manner. The 7th and 8th patchies consolidates the raise as 'pthread_kill(pthread_self())' and use pthread_kill() on pthread_cancel(). Finally, the 9th fixes another cancellation synchronization issue when async cancellation might early exit the process due wrong __nptl_nthreads update. [1] https://sourceware.org/pipermail/libc-alpha/2021-May/126852.html Adhemerval Zanella (9): nptl: Remove exit-thread.h nptl: Deallocate the thread stack on setup failure (BZ #19511) nptl: Install cancellation handler on pthread_cancel nptl: Remove CANCELING_BITMASK nptl: Move cancel state out of cancelhandling nptl: Move cancel type out of cancelhandling nptl: Implement raise in terms of pthread_kill nptl: Use pthread_kill on pthread_cancel nptl: Avoid async cancellation to wrongly update __nptl_nthreads (BZ #19366) csu/libc-start.c | 1 - include/pthread.h | 5 + manual/pattern.texi | 1 - manual/process.texi | 3 +- nptl/Versions | 3 +- nptl/allocatestack.c | 3 + nptl/cancellation.c | 62 +++-------- nptl/cleanup_defer.c | 46 +------- nptl/descr.h | 32 ++---- nptl/libc-cleanup.c | 46 +------- nptl/pthreadP.h | 24 +---- nptl/pthread_cancel.c | 145 ++++++++------------------ nptl/pthread_create.c | 102 +++++++----------- nptl/pthread_join_common.c | 7 +- nptl/pthread_kill.c | 52 ++++++--- nptl/pthread_self.c | 4 +- nptl/pthread_setcancelstate.c | 36 +------ nptl/pthread_setcanceltype.c | 41 +------- nptl/pthread_testcancel.c | 11 +- sysdeps/generic/exit-thread.h | 28 ----- sysdeps/htl/pthreadP.h | 2 - sysdeps/nptl/dl-tls_init_tp.c | 3 + sysdeps/nptl/libc_start_call_main.h | 5 +- sysdeps/posix/raise.c | 11 +- sysdeps/unix/sysv/linux/exit-thread.h | 37 ------- sysdeps/unix/sysv/linux/raise.c | 52 --------- 26 files changed, 211 insertions(+), 551 deletions(-) delete mode 100644 sysdeps/generic/exit-thread.h delete mode 100644 sysdeps/unix/sysv/linux/exit-thread.h delete mode 100644 sysdeps/unix/sysv/linux/raise.c