From: "Guido Günther" <agx@sigxcpu.org>
To: Arnd Bergmann <arnd@arndb.de>
Cc: Lucas Stach <l.stach@pengutronix.de>,
Russell King <linux+etnaviv@armlinux.org.uk>,
Christian Gmeiner <christian.gmeiner@gmail.com>,
David Airlie <airlied@linux.ie>, Daniel Vetter <daniel@ffwll.ch>,
Philipp Zabel <p.zabel@pengutronix.de>,
Sam Ravnborg <sam@ravnborg.org>, Rob Herring <robh@kernel.org>,
Emil Velikov <emil.velikov@collabora.com>,
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
Date: Tue, 21 Jan 2020 13:55:46 +0100 [thread overview]
Message-ID: <20200121125546.GA71415@bogon.m.sigxcpu.org> (raw)
In-Reply-To: <20200121114553.2667556-1-arnd@arndb.de>
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 <agx@sigxcpu.org>
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 <agx@sigxcpu.org>
> Link: https://patchwork.kernel.org/patch/11291089/
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
> 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
>
next prev parent reply other threads:[~2020-01-21 12:55 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-21 11:45 [PATCH] drm/etnaviv: only reject timeouts with tv_nsec >= 2 seconds Arnd Bergmann
2020-01-21 12:55 ` Guido Günther [this message]
2020-01-21 13:02 ` Russell King - ARM Linux admin
2020-01-21 16:09 ` Lucas Stach
2020-01-21 19:05 ` Arnd Bergmann
2020-01-22 10:30 ` Guido Günther
2020-01-22 10:35 ` Russell King - ARM Linux admin
2020-01-24 8:56 ` Guido Günther
2020-01-28 13:07 ` Arnd Bergmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200121125546.GA71415@bogon.m.sigxcpu.org \
--to=agx@sigxcpu.org \
--cc=airlied@linux.ie \
--cc=arnd@arndb.de \
--cc=christian.gmeiner@gmail.com \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=emil.velikov@collabora.com \
--cc=etnaviv@lists.freedesktop.org \
--cc=l.stach@pengutronix.de \
--cc=linux+etnaviv@armlinux.org.uk \
--cc=linux-kernel@vger.kernel.org \
--cc=p.zabel@pengutronix.de \
--cc=robh@kernel.org \
--cc=sam@ravnborg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).