Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp3657786ybl; Tue, 21 Jan 2020 04:57:16 -0800 (PST) X-Google-Smtp-Source: APXvYqy02tHNXOnzOrsrb4pSjYFR2RfTkkMsseXrCrudmNS3R/EkZipn34bjCsjBsA7khOlv+sjM X-Received: by 2002:a9d:811:: with SMTP id 17mr3579726oty.369.1579611436146; Tue, 21 Jan 2020 04:57:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579611436; cv=none; d=google.com; s=arc-20160816; b=sefPLAAmXylcVYgjchVpn1yv9ePmFQATAUPseAJfrj6HoC+qg5R3ZdMe331NRrgYRV Zas8xcCJLf8oOHS4xu/4jlywH1mi8AbxzNk4tcCjQAC8Q1ra+wBPlnvmYTdHJixnf7C4 IGB1Pv7Wglo9VQW+FtSU4NDtbHd82/Jq0TbzYbbRW4FsQQ/TOJjsb8vjgYdA2gjTMq4i gnZXKPmNoffAfM6wmCCA03myOlESFTTcIORtiCXUA2+srclAunbP9kCTyK41krSRfthC jkYR497Qi7fla1KRnWAxPm8tK4zGHivoOXMPK0RRKWGuXf1xPZyLaPgDAk4KIRdbFgvp aoAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=M+N+9fpr0m669tGdPmbK0kCiPpbBGP/VUTDI6qi8uFo=; b=YfIDtGduu40E3jO1ItxAeu3Ww2Ws0CVzHAw6H+fXwWtX5CHkqyk7qyP3k1iLum74De YWfeBg19SNRREMXZbgMmXLNdIpN8w9ytzIpwpxWB6yYf8BiAlyBBjNsvaQIiuSLjLQEZ Ey75Xdy5jU2m6rXBNxbNP+WEbMgXQePyDb0hog8sEwXxSSVDMH7n2RP/k1RvBv/QcMDK 3pYRvUjMJpI0tQb73/fw8WoLvQ3q2jFOLf1poKh2MGabzFaGOjN/8ov/78SWj8wXiEFa wF//mF1xXVb21MUz1K/mZJyaGLadmG7+tQEjWvw3lGf9YIhGRsGcHDfhIOBafAICe9qS nKgA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p19si19847686oic.216.2020.01.21.04.57.03; Tue, 21 Jan 2020 04:57:16 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728803AbgAUMzv (ORCPT + 99 others); Tue, 21 Jan 2020 07:55:51 -0500 Received: from honk.sigxcpu.org ([24.134.29.49]:56578 "EHLO honk.sigxcpu.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725890AbgAUMzv (ORCPT ); Tue, 21 Jan 2020 07:55:51 -0500 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 Cc: Lucas Stach , Russell King , Christian Gmeiner , David Airlie , Daniel Vetter , Philipp Zabel , Sam Ravnborg , Rob Herring , Emil Velikov , etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org 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-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20200121114553.2667556-1-arnd@arndb.de> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On Tue, Jan 21, 2020 at 12:45:25PM +0100, Arnd Bergmann wrote: > As Guido G?nther 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?nther Cheers, -- Guido > > This also addresses the off-by-1 glitch reported by Ben Hutchings. > > Fixes: 172a216ff334 ("drm/etnaviv: reject timeouts with tv_nsec >= NSEC_PER_SEC") > Cc: Guido G?nther > 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/etnaviv/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_device *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 >= (2 * NSEC_PER_SEC)) > return -EINVAL; > > obj = 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 >= (2 * NSEC_PER_SEC)) > return -EINVAL; > > if (args->pipe >= 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 >= (2 * NSEC_PER_SEC)) > return -EINVAL; > > if (args->pipe >= ETNA_MAX_PIPES) > diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.h b/drivers/gpu/drm/etnaviv/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, size_t elem_size, size_t base) > static inline unsigned long etnaviv_timeout_to_jiffies( > const struct drm_etnaviv_timespec *timeout) > { > - struct timespec64 ts, to = { > - .tv_sec = timeout->tv_sec, > - .tv_nsec = 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) <= 0) > -- > 2.25.0 >