From patchwork Thu Sep 30 20:00:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 45636 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 ADC613857C60 for ; Thu, 30 Sep 2021 20:11:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ADC613857C60 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1633032688; bh=6V+Nku939b083NtMm1HRkepbf9cojg+PAEbJXALEf3k=; 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=e9NQqF6AxU7OGJV0LlY1U/ZJMjuXVColJrwLcu6ZCzij4/LyGxEF5aDAL5JXGHMaY 9M6ED0OEvP3sV21uo0Eh5bnzE5gTq+LamXfObbuK2vGRtLO8dALQQ10Shf00NfpEIe j85npixdqPV0CNVSX5YQXYM06McLW7f+taylNQP8= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qt1-x829.google.com (mail-qt1-x829.google.com [IPv6:2607:f8b0:4864:20::829]) by sourceware.org (Postfix) with ESMTPS id CB7DD3857C6C for ; Thu, 30 Sep 2021 20:01:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CB7DD3857C6C Received: by mail-qt1-x829.google.com with SMTP id e16so6906032qts.4 for ; Thu, 30 Sep 2021 13:01:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6V+Nku939b083NtMm1HRkepbf9cojg+PAEbJXALEf3k=; b=QlbPWROtW/f/7tGmInQNFIE3NbwPw2WvkxcHR0zA6kXfSCVVO9viNdjTnk/5FdtA0g CVOG+2pGGPg92r95FqLReK5TAGNTQJRArcswWg+/K+WW5Zq6k25IkayYFjCO2KOqyg/U /bdgq2SZRZ0mdGkPlMsoz3CfjcIw6og7Vu7xpaX5DA7qtBQGARjf2gwQ2oZb0H2z8rSO ZlY3BSmnWuGZSlRmv8YrIwEZ74MZ9QUjPVjO5WlDK4V9kqjat/yGjcBuMtmlSqb8RIrw P4kZR1O6j3qICZhohVhpgvwgthpcPEeAn8AWNqSCkX8uduMWznjlInqneXpiPAZQLx1g rtpw== X-Gm-Message-State: AOAM532vYwhFGBGfIqqw0RfiJ8OdWFPdx/42QwYHANR33X5odHdp+z/1 Z1IxU6hMZ6kPoH28CK9zx+g9gwv6a95HYg== X-Google-Smtp-Source: ABdhPJx+fC+y+zzgbjjg4dzhVSG0nxSNFckAB5SGvOO2lqrIybl/YHMreTt7KDkXNl9EJiHDBnnd+A== X-Received: by 2002:ac8:538a:: with SMTP id x10mr8524861qtp.251.1633032072236; Thu, 30 Sep 2021 13:01:12 -0700 (PDT) Received: from birita.. ([2804:431:c7cb:b338:b20e:53f8:8b5:1bb2]) by smtp.gmail.com with ESMTPSA id r196sm1910203qka.119.2021.09.30.13.01.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Sep 2021 13:01:11 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH 14/15] nptl: Use exit_lock when accessing TID on pthread_setschedprio Date: Thu, 30 Sep 2021 17:00:50 -0300 Message-Id: <20210930200051.1017457-15-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210930200051.1017457-1-adhemerval.zanella@linaro.org> References: <20210930200051.1017457-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.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 Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Checked on x86_64-linux-gnu --- nptl/pthread_setschedprio.c | 45 +++++++++++++++------------- sysdeps/pthread/tst-pthread-exited.c | 5 ++++ 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/nptl/pthread_setschedprio.c b/nptl/pthread_setschedprio.c index c095e346c8..65cf8912ca 100644 --- a/nptl/pthread_setschedprio.c +++ b/nptl/pthread_setschedprio.c @@ -15,25 +15,13 @@ License along with the GNU C Library; if not, see . */ -#include -#include -#include -#include -#include "pthreadP.h" -#include +#include +#include #include -int -__pthread_setschedprio (pthread_t threadid, int prio) +static int +setschedprio (struct pthread *pd, int prio) { - struct pthread *pd = (struct pthread *) threadid; - - /* Make sure the descriptor is valid. */ - if (INVALID_TD_P (pd)) - /* Not a valid thread handle. */ - return ESRCH; - - int result = 0; struct sched_param param; param.sched_priority = prio; @@ -42,13 +30,12 @@ __pthread_setschedprio (pthread_t threadid, int prio) /* If the thread should have higher priority because of some PTHREAD_PRIO_PROTECT mutexes it holds, adjust the priority. */ - if (__builtin_expect (pd->tpp != NULL, 0) && pd->tpp->priomax > prio) + if (pd->tpp != NULL && pd->tpp->priomax > prio) param.sched_priority = pd->tpp->priomax; /* Try to set the scheduler information. */ - if (__glibc_unlikely (__sched_setparam (pd->tid, ¶m) == -1)) - result = errno; - else + int r = INTERNAL_SYSCALL_CALL (sched_setparam, pd->tid, ¶m); + if (r == 0) { /* We succeeded changing the kernel information. Reflect this change in the thread descriptor. */ @@ -59,6 +46,24 @@ __pthread_setschedprio (pthread_t threadid, int prio) lll_unlock (pd->lock, LLL_PRIVATE); + return -r; +} + +int +__pthread_setschedprio (pthread_t threadid, int prio) +{ + struct pthread *pd = (struct pthread *) threadid; + + /* Block all signals, as required by pd->exit_lock. */ + sigset_t old_mask; + __libc_signal_block_all (&old_mask); + __libc_lock_lock (pd->exit_lock); + + int result = pd->tid != 0 ? setschedprio (pd, prio) : ESRCH; + + __libc_lock_unlock (pd->exit_lock); + __libc_signal_restore_set (&old_mask); + return result; } versioned_symbol (libc, __pthread_setschedprio, pthread_setschedprio, diff --git a/sysdeps/pthread/tst-pthread-exited.c b/sysdeps/pthread/tst-pthread-exited.c index bfb3870cb6..03cf2e21a1 100644 --- a/sysdeps/pthread/tst-pthread-exited.c +++ b/sysdeps/pthread/tst-pthread-exited.c @@ -88,6 +88,11 @@ do_test (void) TEST_COMPARE (r, ESRCH); } + { + int r = pthread_setschedprio (thr, 0); + TEST_COMPARE (r, ESRCH); + } + xpthread_join (thr); return 0;