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: AS31976 209.132.180.0/23 X-Spam-Status: No, score=-3.9 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS, 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 (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id B476620248 for ; Tue, 5 Mar 2019 16:48:56 +0000 (UTC) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:subject:to:references:from:message-id:date :mime-version:in-reply-to:content-type :content-transfer-encoding; q=dns; s=default; b=ud9V8OjiHrTcD7qK otST+L1klayE7CMU6dP5ut7w17hFDVQS86jZNvL++tSZgtclASzSt+hMtOOIwm7l kw8pC4I0GxWTwOomP/5E/CFGg5u81D/6wqNACABkI3OHiFdLHUZobf9Sx1wKEJeL s8etPvz0RqRslLyFLiOOhEyJtHc= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:subject:to:references:from:message-id:date :mime-version:in-reply-to:content-type :content-transfer-encoding; s=default; bh=hiDnUpMYDR2OVqDGsBKlPN bYRzQ=; b=Ft6+TGgPxsALadyRf8o7BTko7BAwHLm3Jm6e5bV0FxrsthgDBLX4Md wopUeaDvdG8/PR8paWMxcp1263ENlgVhUxg0K+2MfLrz+Nz7HAlyN2o6g4EcQa/M 0AFPS8dXahxhAiqBttCHqes+m+ABWfwhof/9mKnucyIbSEd/sR7xI= Received: (qmail 30765 invoked by alias); 5 Mar 2019 16:48:54 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Received: (qmail 30745 invoked by uid 89); 5 Mar 2019 16:48:53 -0000 Authentication-Results: sourceware.org; auth=none X-HELO: mail-qk1-f194.google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=subject:to:references:from:openpgp:autocrypt:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=TvE2l6WIsfsD1v5m9QVTqtfYMC0jSrl066FgnOXEy8Q=; b=fcEIIiAekRXZU7QnKIk5vyOdQn8diLoReBhCF6CBmsakzGXBP1QrkzSrwxiFyOmJLQ q34b1ZmdgeqORQTdtK6mdHh7ZYNdbQ2YGBWvBMCxpZUl0G0RgFjpcCBbd9nxNDuCLoWI cJ1qS4lRPjXHUoQRbCTZL/0n0y6474kK6T9Pq4GMx//v0pPySByNnKEGJ4z8K2CqDiUV FhegNtY46pjrBzBCj8K9XYXx8vZ1LNfImfyIEdVEtLI7/qj9pxD3YG+WGdXjM+iEFydq V5X8AP1AOVbYJbDqkdQT/tE5YBl8f6pvUrRGRrYvK/UTrYIExiUfCOhr3KtybKLedSaP HCog== Subject: Re: [PATCH 4/7] nptl: pthread_rwlock: Move timeout validation into _full functions To: libc-alpha@sourceware.org References: <5292325009aa674d78d114d85bdbce94c3aec909.1551291557.git-series.mac@mcrowe.com> From: Adhemerval Zanella Openpgp: preference=signencrypt Message-ID: <094879a0-cb7f-a3a1-f614-f4c7d29e1389@linaro.org> Date: Tue, 5 Mar 2019 13:48:46 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.1 MIME-Version: 1.0 In-Reply-To: <5292325009aa674d78d114d85bdbce94c3aec909.1551291557.git-series.mac@mcrowe.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit On 27/02/2019 15:23, Mike Crowe wrote: > As recommended by the comments in the implementations of > pthread_rwlock_timedrdlock and pthread_rwlock_timedwrlock, let's move the > timeout validity checks into the corresponding pthread_rwlock_rdlock_full > and pthread_rwlock_wrlock_full functions. Since these functions may be > called with abstime == NULL, an extra check for that is necessary too. > --- > nptl/pthread_rwlock_common.c | 20 ++++++++++++++++++++ > nptl/pthread_rwlock_timedrdlock.c | 10 ---------- > nptl/pthread_rwlock_timedwrlock.c | 10 ---------- > 3 files changed, 20 insertions(+), 20 deletions(-) > > diff --git a/nptl/pthread_rwlock_common.c b/nptl/pthread_rwlock_common.c > index 89ba21a..120b880 100644 > --- a/nptl/pthread_rwlock_common.c > +++ b/nptl/pthread_rwlock_common.c > @@ -282,6 +282,16 @@ __pthread_rwlock_rdlock_full (pthread_rwlock_t *rwlock, > { > unsigned int r; > > + /* Make sure any passed in timeout value is valid. Note that the previous > + implementation assumed that this check *must* not be performed if there > + would in fact be no blocking; however, POSIX only requires that "the > + validity of the abstime parameter need not be checked if the lock can be > + immediately acquired" (i.e., we need not but may check it). */ > + if (abstime > + && __glibc_unlikely (abstime->tv_nsec >= 1000000000 > + || abstime->tv_nsec < 0)) > + return EINVAL; > + Couldn't we create a consolidate implementation for this check instead of duplicate it? > /* Make sure we are not holding the rwlock as a writer. This is a deadlock > situation we recognize and report. */ > if (__glibc_unlikely (atomic_load_relaxed (&rwlock->__data.__cur_writer) > @@ -576,6 +586,16 @@ static __always_inline int > __pthread_rwlock_wrlock_full (pthread_rwlock_t *rwlock, > const struct timespec *abstime) > { > + /* Make sure any passed in timeout value is valid. Note that the previous > + implementation assumed that this check *must* not be performed if there > + would in fact be no blocking; however, POSIX only requires that "the > + validity of the abstime parameter need not be checked if the lock can be > + immediately acquired" (i.e., we need not but may check it). */ > + if (abstime > + && __glibc_unlikely (abstime->tv_nsec >= 1000000000 > + || abstime->tv_nsec < 0)) > + return EINVAL; > + > /* Make sure we are not holding the rwlock as a writer. This is a deadlock > situation we recognize and report. */ > if (__glibc_unlikely (atomic_load_relaxed (&rwlock->__data.__cur_writer) > diff --git a/nptl/pthread_rwlock_timedrdlock.c b/nptl/pthread_rwlock_timedrdlock.c > index aa00530..84c1983 100644 > --- a/nptl/pthread_rwlock_timedrdlock.c > +++ b/nptl/pthread_rwlock_timedrdlock.c > @@ -23,15 +23,5 @@ int > pthread_rwlock_timedrdlock (pthread_rwlock_t *rwlock, > const struct timespec *abstime) > { > - /* Make sure the passed in timeout value is valid. Note that the previous > - implementation assumed that this check *must* not be performed if there > - would in fact be no blocking; however, POSIX only requires that "the > - validity of the abstime parameter need not be checked if the lock can be > - immediately acquired" (i.e., we need not but may check it). */ > - /* ??? Just move this to __pthread_rwlock_rdlock_full? */ > - if (__glibc_unlikely (abstime->tv_nsec >= 1000000000 > - || abstime->tv_nsec < 0)) > - return EINVAL; > - > return __pthread_rwlock_rdlock_full (rwlock, abstime); > } > diff --git a/nptl/pthread_rwlock_timedwrlock.c b/nptl/pthread_rwlock_timedwrlock.c > index 3c92e44..f0b745d 100644 > --- a/nptl/pthread_rwlock_timedwrlock.c > +++ b/nptl/pthread_rwlock_timedwrlock.c > @@ -23,15 +23,5 @@ int > pthread_rwlock_timedwrlock (pthread_rwlock_t *rwlock, > const struct timespec *abstime) > { > - /* Make sure the passed in timeout value is valid. Note that the previous > - implementation assumed that this check *must* not be performed if there > - would in fact be no blocking; however, POSIX only requires that "the > - validity of the abstime parameter need not be checked if the lock can be > - immediately acquired" (i.e., we need not but may check it). */ > - /* ??? Just move this to __pthread_rwlock_wrlock_full? */ > - if (__glibc_unlikely (abstime->tv_nsec >= 1000000000 > - || abstime->tv_nsec < 0)) > - return EINVAL; > - > return __pthread_rwlock_wrlock_full (rwlock, abstime); > } >