From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS3215 2.6.0.0/16 X-Spam-Status: No, score=-4.5 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 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 dcvr.yhbt.net (Postfix) with ESMTPS id 368D21F8C6 for ; Mon, 23 Aug 2021 19:59:00 +0000 (UTC) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6F76D3857C60 for ; Mon, 23 Aug 2021 19:58:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6F76D3857C60 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1629748739; bh=GqFOEHBrTggK3yFLPG9iXsYMM+DKQ7wDeBBswQglChA=; 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=tFlNJSUwO8kyhvbUVPBj84a1kh1cV2gKrqBJzNb0MWb7oSb5UapmdvfRjUAOAAeBV OnsM0vROCUX5RfOz7GrV0hzyuseGue4dDL3yzHphNiJbIo0KRuZ962y9oID+etd4W1 QJfI908P7gq4cx/5fcESpAH4ZicxEZSvlQWjiYck= Received: from mail-qk1-x72a.google.com (mail-qk1-x72a.google.com [IPv6:2607:f8b0:4864:20::72a]) by sourceware.org (Postfix) with ESMTPS id BD4B9385803C for ; Mon, 23 Aug 2021 19:52:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BD4B9385803C Received: by mail-qk1-x72a.google.com with SMTP id c10so17990597qko.11 for ; Mon, 23 Aug 2021 12:52:13 -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:in-reply-to :references:mime-version:content-transfer-encoding; bh=GqFOEHBrTggK3yFLPG9iXsYMM+DKQ7wDeBBswQglChA=; b=DMYcrWbvXx+C1/aJ+VIpA3rwHFq8GiUPkVqvmxexL/h8YeJYZReFvRCuGCV9oMz2IK xojAmlwumwy/n4EZPGYc9NYKweT8TC73BUexiSjz7tpgthxSPOQZLi67PEhWS5gFepWc p9bHfopaklUCsz8LoyhLT/quzyHs/To3j/K9o8PnUz3Q0HpIqA4pYyiDB64FLUM6KbDX ko8FYUC7P30bYUjRIiPlvfC1+Ae/XIMD6fs11GqYSF33O2KeSuwUphCAl+QBDjAf6vxa s2T/L7uBkDZUK60cvVB9rPua/1wQjXWPmag4qzGeeI4XtkWMwaCGEH4lDq+3bCKzBS2a OO2Q== X-Gm-Message-State: AOAM532z1/6PaIby+r8ZSZn8bFfQWTbjYdxvnajYaw+WtoOIx3qWBPx3 idWcoC52iJqASsqY9QbtjMuVA0sXdZBZZw== X-Google-Smtp-Source: ABdhPJz0UFJVjZsmVFO0mk5jm8AedeKCMlJgGnmHJRNq0uiaWH5FmeXhiaXG9bPwBF2o5+hm/UPTmA== X-Received: by 2002:a05:620a:4cf:: with SMTP id 15mr22930183qks.316.1629748333253; Mon, 23 Aug 2021 12:52:13 -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.52.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Aug 2021 12:52:13 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v2 11/19] nptl: Use tidlock when accessing TID on pthread_setaffinity Date: Mon, 23 Aug 2021 16:50:39 -0300 Message-Id: <20210823195047.543237-12-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210823195047.543237-1-adhemerval.zanella@linaro.org> References: <20210823195047.543237-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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: , From: Adhemerval Zanella via Libc-alpha Reply-To: Adhemerval Zanella Cc: Florian Weimer Errors-To: libc-alpha-bounces+e=80x24.org@sourceware.org Sender: "Libc-alpha" Checked on x86_64-linux-gnu. --- nptl/pthread_setaffinity.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/nptl/pthread_setaffinity.c b/nptl/pthread_setaffinity.c index 3bfdc63e19..beb61836a6 100644 --- a/nptl/pthread_setaffinity.c +++ b/nptl/pthread_setaffinity.c @@ -27,15 +27,23 @@ int __pthread_setaffinity_new (pthread_t th, size_t cpusetsize, const cpu_set_t *cpuset) { - const struct pthread *pd = (const struct pthread *) th; - int res; + struct pthread *pd = (struct pthread *) th; - res = INTERNAL_SYSCALL_CALL (sched_setaffinity, pd->tid, cpusetsize, - cpuset); + /* Block all signal, since the lock is recursive and used on pthread_cancel + (which should be async-signal-safe). */ + sigset_t oldmask; + __libc_signal_block_all (&oldmask); + lll_lock (pd->tidlock, LLL_PRIVATE); - return (INTERNAL_SYSCALL_ERROR_P (res) - ? INTERNAL_SYSCALL_ERRNO (res) - : 0); + int res = pd->tid == 0 + ? ESRCH + : INTERNAL_SYSCALL_CALL (sched_setaffinity, pd->tid, cpusetsize, + cpuset); + + lll_unlock (pd->tidlock, LLL_PRIVATE); + __libc_signal_restore_set (&oldmask); + + return res; } versioned_symbol (libc, __pthread_setaffinity_new, pthread_setaffinity_np, GLIBC_2_34); -- 2.30.2