Message ID | 20201204180944.3774769-3-adhemerval.zanella@linaro.org |
---|---|
State | Superseded |
Headers |
Return-Path: <libc-alpha-bounces@sourceware.org> 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 6AD663982430; Fri, 4 Dec 2020 18:09:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6AD663982430 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1607105397; bh=8CKJutt4WONGV+x0Br04SKMg6qQzBTzft6/n+7i/uX0=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=wCZa8j3xaI2nRL6ddt1irBNfixscZWLKglmpU4tFcQyy0hcPfbWKUelarRd8KC8Ng pm4trC1DgfbfmCNe4QfHrfSGA1M/FA/V/WLIc8+SXG5SUhXawGuo2z4VBaWAQBsaYI G9uPHOHVftLjkgQgmB/qdRhiIWhLUr/lo6f0bS+A= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x744.google.com (mail-qk1-x744.google.com [IPv6:2607:f8b0:4864:20::744]) by sourceware.org (Postfix) with ESMTPS id 07E91397A013 for <libc-alpha@sourceware.org>; Fri, 4 Dec 2020 18:09:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 07E91397A013 Received: by mail-qk1-x744.google.com with SMTP id q22so6271292qkq.6 for <libc-alpha@sourceware.org>; Fri, 04 Dec 2020 10:09:55 -0800 (PST) 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=8CKJutt4WONGV+x0Br04SKMg6qQzBTzft6/n+7i/uX0=; b=O7+KAI0GG1dlkIIw8FZYjVqS7Y24vRy0mjDNbsgVulEnvF/gKaqYnveILeU+RKA/ps ZvAPgkGnyS7ebR5EfJSQiJcG9lasS2HqAKObCy4j//pKsWwaRnvPtaGeUMEQXEVrMc2N sKuUQ+jL0v9vdijRX+YaYCboS9cNKtrukDBXxOx/xPPuqg47xmDN8VvJoH+niHJz5o/J y5kFdQ1vask7CpBznTEQPICbSig0S670ISWXNDwLeF+KBBlcpPjAck2U+SWvOrFq2Vpq 0f4tTdLHvZhRF6737roF+4qXX5VAGYnXMAaiSrK5LF+2OLSYIJYbn40u3b1Vwa5kU7mF Bpew== X-Gm-Message-State: AOAM530si92I0lMlwM2vkY34484x/MCcUXmkPIRiOT4oBiFguJ6HQj1O lKKpGPoZydrH1vpdN+BY5ERFCmLpVxQelQ== X-Google-Smtp-Source: ABdhPJxRnI8jgQy9cVM18qcy/OjrQBlS/h6VnD2MP89CBRqWHHbfqr2RjR5kGPWQGLKUEbm7yPoCcA== X-Received: by 2002:a05:620a:7ea:: with SMTP id k10mr10091941qkk.292.1607105394025; Fri, 04 Dec 2020 10:09:54 -0800 (PST) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id b33sm6179827qta.62.2020.12.04.10.09.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2020 10:09:53 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH 3/6] nptl: Make pthread_kill async-signal-safe Date: Fri, 4 Dec 2020 15:09:41 -0300 Message-Id: <20201204180944.3774769-3-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201204180944.3774769-1-adhemerval.zanella@linaro.org> References: <20201204180944.3774769-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-13.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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 <libc-alpha.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/libc-alpha>, <mailto:libc-alpha-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/libc-alpha/> List-Post: <mailto:libc-alpha@sourceware.org> List-Help: <mailto:libc-alpha-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/libc-alpha>, <mailto:libc-alpha-request@sourceware.org?subject=subscribe> From: Adhemerval Zanella via Libc-alpha <libc-alpha@sourceware.org> Reply-To: Adhemerval Zanella <adhemerval.zanella@linaro.org> Cc: Florian Weimer <fweimer@redhat.com> Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" <libc-alpha-bounces@sourceware.org> |
Series |
[1/6] nptl: Move Linux pthread_kill to nptl
|
|
Commit Message
Adhemerval Zanella Netto
Dec. 4, 2020, 6:09 p.m. UTC
Simiar to raise (BZ #15368), pthread_kill is also defined as async-signal-safe (POSIX.1-2008 TC1). However, similar to raise it has the same issues relating to signal handling. Different than raise, all the signal are blocked so it would be possible to implement pthread_cancel (which also should be async-cancel safe). Checked on x86_64-linux-gnu. --- nptl/pthread_kill.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
Comments
* Adhemerval Zanella via Libc-alpha: > Simiar to raise (BZ #15368), pthread_kill is also defined as > async-signal-safe (POSIX.1-2008 TC1). However, similar to raise > it has the same issues relating to signal handling. > > Different than raise, all the signal are blocked so it would be > possible to implement pthread_cancel (which also should be > async-cancel safe). What do you mean by implementing pthread_cancel? Patch looks okay as far as I can see, but we'll eventually need a different approach to deal with the TID reuse race.
On 04/12/2020 15:20, Florian Weimer wrote: > * Adhemerval Zanella via Libc-alpha: > >> Simiar to raise (BZ #15368), pthread_kill is also defined as >> async-signal-safe (POSIX.1-2008 TC1). However, similar to raise >> it has the same issues relating to signal handling. >> >> Different than raise, all the signal are blocked so it would be >> possible to implement pthread_cancel (which also should be >> async-cancel safe). > > What do you mean by implementing pthread_cancel? > > Patch looks okay as far as I can see, but we'll eventually need a > different approach to deal with the TID reuse race. > For TID reuse case I don't see a easy way other than add a lock on pthread_kill with synchronizes with pthread_exit. It would require some changes on how we synchronize the TID clear by the kernel.
On 04/12/2020 15:20, Florian Weimer wrote: > * Adhemerval Zanella via Libc-alpha: > >> Simiar to raise (BZ #15368), pthread_kill is also defined as >> async-signal-safe (POSIX.1-2008 TC1). However, similar to raise >> it has the same issues relating to signal handling. >> >> Different than raise, all the signal are blocked so it would be >> possible to implement pthread_cancel (which also should be >> async-cancel safe). > > What do you mean by implementing pthread_cancel? To avoid the second issue of the pthread_cancel async-signal-safe issues [2]. [2] https://sourceware.org/pipermail/libc-alpha/2020-December/120423.html
* Adhemerval Zanella: > On 04/12/2020 15:20, Florian Weimer wrote: >> * Adhemerval Zanella via Libc-alpha: >> >>> Simiar to raise (BZ #15368), pthread_kill is also defined as >>> async-signal-safe (POSIX.1-2008 TC1). However, similar to raise >>> it has the same issues relating to signal handling. >>> >>> Different than raise, all the signal are blocked so it would be >>> possible to implement pthread_cancel (which also should be >>> async-cancel safe). >> >> What do you mean by implementing pthread_cancel? > > To avoid the second issue of the pthread_cancel async-signal-safe > issues [2]. > > [2] https://sourceware.org/pipermail/libc-alpha/2020-December/120423.html I think the signal blocking would have to happen on the target thread. Blocking signals on the signal-sending thread does not help?
diff --git a/nptl/pthread_kill.c b/nptl/pthread_kill.c index 7ef68d1572..c547c5fe58 100644 --- a/nptl/pthread_kill.c +++ b/nptl/pthread_kill.c @@ -36,11 +36,17 @@ __pthread_kill (pthread_t threadid, int signo) /* Not a valid thread handle. */ return ESRCH; + sigset_t set; + __libc_signal_block_all (&set); + /* We have a special syscall to do the work. */ pid_t pid = __getpid (); int val = INTERNAL_SYSCALL_CALL (tgkill, pid, tid, signo); - return (INTERNAL_SYSCALL_ERROR_P (val) - ? INTERNAL_SYSCALL_ERRNO (val) : 0); + val = (INTERNAL_SYSCALL_ERROR_P (val) ? INTERNAL_SYSCALL_ERRNO (val) : 0); + + __libc_signal_restore_set (&set); + + return val; } strong_alias (__pthread_kill, pthread_kill)