From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 20305C3F68F for ; Tue, 21 Jan 2020 12:55:53 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F0D4C2051A for ; Tue, 21 Jan 2020 12:55:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F0D4C2051A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=sigxcpu.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 46EC36ECD6; Tue, 21 Jan 2020 12:55:52 +0000 (UTC) Received: from honk.sigxcpu.org (honk.sigxcpu.org [24.134.29.49]) by gabe.freedesktop.org (Postfix) with ESMTPS id AC47F6ECD6; Tue, 21 Jan 2020 12:55:50 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by honk.sigxcpu.org (Postfix) with ESMTP id 6A6A4FB03; Tue, 21 Jan 2020 13:55:48 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at honk.sigxcpu.org Received: from honk.sigxcpu.org ([127.0.0.1]) by localhost (honk.sigxcpu.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 5hwBqkAmIvg2; Tue, 21 Jan 2020 13:55:46 +0100 (CET) Received: by bogon.sigxcpu.org (Postfix, from userid 1000) id 4A920404A9; Tue, 21 Jan 2020 13:55:46 +0100 (CET) Date: Tue, 21 Jan 2020 13:55:46 +0100 From: Guido =?iso-8859-1?Q?G=FCnther?= To: Arnd Bergmann Subject: Re: [PATCH] drm/etnaviv: only reject timeouts with tv_nsec >= 2 seconds Message-ID: <20200121125546.GA71415@bogon.m.sigxcpu.org> References: <20200121114553.2667556-1-arnd@arndb.de> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200121114553.2667556-1-arnd@arndb.de> User-Agent: Mutt/1.10.1 (2018-07-13) X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: David Airlie , etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Russell King , Emil Velikov , Sam Ravnborg Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Hi, On Tue, Jan 21, 2020 at 12:45:25PM +0100, Arnd Bergmann wrote: > As Guido G=FCnther reported, get_abs_timeout() in the etnaviv user space > sometimes passes timeouts with nanosecond values larger than 1000000000, > which gets rejected after my first patch. > = > To avoid breaking this, while also not allowing completely arbitrary > values, set the limit to 1999999999 and use set_normalized_timespec64() > to get the correct format before comparing it. I'm seeing values up to 5 seconds so I need if (args->timeout.tv_nsec > (5 * NSEC_PER_SEC)) to unbreak rendering. Which seems to match what mesa's get_abs_timeout() does and how it's invoked. with that: Tested-by: Guido G=FCnther Cheers, -- Guido > = > This also addresses the off-by-1 glitch reported by Ben Hutchings. > = > Fixes: 172a216ff334 ("drm/etnaviv: reject timeouts with tv_nsec >=3D NSEC= _PER_SEC") > Cc: Guido G=FCnther > Link: https://patchwork.kernel.org/patch/11291089/ > Signed-off-by: Arnd Bergmann > --- > drivers/gpu/drm/etnaviv/etnaviv_drv.c | 10 +++++++--- > drivers/gpu/drm/etnaviv/etnaviv_drv.h | 6 ++---- > 2 files changed, 9 insertions(+), 7 deletions(-) > = > diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.c b/drivers/gpu/drm/etna= viv/etnaviv_drv.c > index 3eb0f9223bea..d94740c123d3 100644 > --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.c > +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.c > @@ -292,7 +292,11 @@ static int etnaviv_ioctl_gem_cpu_prep(struct drm_dev= ice *dev, void *data, > if (args->op & ~(ETNA_PREP_READ | ETNA_PREP_WRITE | ETNA_PREP_NOSYNC)) > return -EINVAL; > = > - if (args->timeout.tv_nsec > NSEC_PER_SEC) > + /* > + * existing user space passes non-normalized timespecs, but never > + * more than 2 seconds worth of nanoseconds > + */ > + if (args->timeout.tv_nsec >=3D (2 * NSEC_PER_SEC)) > return -EINVAL; > = > obj =3D drm_gem_object_lookup(file, args->handle); > @@ -358,7 +362,7 @@ static int etnaviv_ioctl_wait_fence(struct drm_device= *dev, void *data, > if (args->flags & ~(ETNA_WAIT_NONBLOCK)) > return -EINVAL; > = > - if (args->timeout.tv_nsec > NSEC_PER_SEC) > + if (args->timeout.tv_nsec >=3D (2 * NSEC_PER_SEC)) > return -EINVAL; > = > if (args->pipe >=3D ETNA_MAX_PIPES) > @@ -412,7 +416,7 @@ static int etnaviv_ioctl_gem_wait(struct drm_device *= dev, void *data, > if (args->flags & ~(ETNA_WAIT_NONBLOCK)) > return -EINVAL; > = > - if (args->timeout.tv_nsec > NSEC_PER_SEC) > + if (args->timeout.tv_nsec >=3D (2 * NSEC_PER_SEC)) > return -EINVAL; > = > if (args->pipe >=3D ETNA_MAX_PIPES) > diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.h b/drivers/gpu/drm/etna= viv/etnaviv_drv.h > index efc656efeb0f..3e47050af706 100644 > --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.h > +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.h > @@ -109,12 +109,10 @@ static inline size_t size_vstruct(size_t nelem, siz= e_t elem_size, size_t base) > static inline unsigned long etnaviv_timeout_to_jiffies( > const struct drm_etnaviv_timespec *timeout) > { > - struct timespec64 ts, to =3D { > - .tv_sec =3D timeout->tv_sec, > - .tv_nsec =3D timeout->tv_nsec, > - }; > + struct timespec64 ts, to; > = > ktime_get_ts64(&ts); > + set_normalized_timespec64(&to, timeout->tv_sec, timeout->tv_nsec); > = > /* timeouts before "now" have already expired */ > if (timespec64_compare(&to, &ts) <=3D 0) > -- = > 2.25.0 > = _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel