From patchwork Tue Jan 21 11:45:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 182905 Delivered-To: patch@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp3752937ile; Tue, 21 Jan 2020 03:46:27 -0800 (PST) X-Google-Smtp-Source: APXvYqz3lXWqJHXJg6fx1BWOb+xp1ONylu5kWf5oxCY7RcUp4h2Wvs/RGCpIP4GGdioJzi/1C/I9 X-Received: by 2002:a17:902:5a85:: with SMTP id r5mr5110364pli.222.1579607187089; Tue, 21 Jan 2020 03:46:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579607187; cv=none; d=google.com; s=arc-20160816; b=GPocA/GYCnbJTzwaB9Q5KJaSUZhhao7J/dvv1cSLMU3w3f74puq8URI/CQXT8fOrWh d7PmWnMxQPFJ/Pnb7ZpQsiNPa/+2F+jGm2ukAzbfwRBLy96eET7BPGtpLL8JSv70HDt1 0RT/ASJBK0zZMRcbVu7I+WPl2USGuz8k8JmpauRFL5Ns+TzDFzjiujVeHvJmlQwoAMs2 Yi/xecJm4oEKPypBEJ5MFjNojG47QAqewTDwpEzeLz/Bn/mrqFpux/CdLUGbKcfg8odr r5HhkCP01Q+Nt29u/9+80sLYO1bwQJ7GpGjsy+UqGG/kVPYtv4PA9mtEIQWaAJIKnFc3 v1qg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:mime-version:message-id:date:subject:to:from :delivered-to; bh=k/TUfNMA2TIuYUm7a5yjbt+AG12Y2jYz+R3L6eL53n8=; b=qdzAyn7ditlLc5efuW8nskugKkNo4kP6D8b3EWI3qEGH0Hon+IZO9ypN00bz9sVldb hgbBU4RW2F29OlEcO+/ieuz1ez/8SI3J406EF07/j38vwbMb+JYCPOX9+mdY8iCmSz8k hdBe8aOEzOG1rCBth66ra6yPzfqKhAPf8u5azim9hZ8B3xCMdYdJswYXusXP0UWvUavA UtBVR0i651nookG9vmob7PqwI9nqvEnIcTL7zi+Gzi4AEUj3o8uAVvRZ8mK/r/+rHmpk V+j1fjXlUxj7hwcNlM+WW8eItcmFpgYEtenhaKuKkyWxwy+jDiCkg4pDomuQ7sirGkas o7fw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Return-Path: Received: from gabe.freedesktop.org (gabe.freedesktop.org. [131.252.210.177]) by mx.google.com with ESMTPS id t3si35012944pgv.54.2020.01.21.03.46.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jan 2020 03:46:27 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) client-ip=131.252.210.177; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) 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 224726EC8A; Tue, 21 Jan 2020 11:46:26 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mout.kundenserver.de (mout.kundenserver.de [217.72.192.74]) by gabe.freedesktop.org (Postfix) with ESMTPS id BB5656EC7A for ; Tue, 21 Jan 2020 11:46:22 +0000 (UTC) Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1N5mSj-1jhyoV2BSN-017CgH; Tue, 21 Jan 2020 12:46:00 +0100 From: Arnd Bergmann To: Lucas Stach Subject: [PATCH] drm/etnaviv: only reject timeouts with tv_nsec >= 2 seconds Date: Tue, 21 Jan 2020 12:45:25 +0100 Message-Id: <20200121114553.2667556-1-arnd@arndb.de> X-Mailer: git-send-email 2.25.0 MIME-Version: 1.0 X-Provags-ID: V03:K1:mC7FeQHazeOL/EsiloGVwenBqO1CqSzKh9a3azedjzvSyEdynvt PTIDkCtpkmSAi0hqrYtN76EzktImZwsEkh0+c9a1+oN67MRE439lpwzjVi5IyhqBMsix/Vx ifIKxKovG+T653zcUc8vdD0nVKWHd8AxwwkoaF51DpPrCMvQ6d624FEzGnKgvuIAkIAFp4Y KI3camDDhBDgIB75lVIAA== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:9P78OmeT3W0=:SH2hT2Gyde3yA/AfdHEewi 9UYWvun/XZNKgNXHoEQkKw8tmTTgY1IFjtViM9tiCn20dQzXqDeKTUnw4/puATqhanXuGAjml 4mqXuyhHPbPPmXmfKN7n14u1uY+0OHeWBp1ZAaUkkxdRYLeOjJfq57z2VhNnP813Dzhvoie0A ix6fxh9pb9aEyR9Z541+Vr9l5s+a/gX6TS2+0VuZrx4MhpEgsSYpkqFpXOCFN2kljTVjrYSA0 SQSC24h5OGcq2HD2Y7GDBWzWkfWpABo5qm66hilTrfGxm89HZ3EHc01W3pe91YZ7U3hMSR3OW D62+2Itr5NXjtNhvjidNeBd2UcqLfu7VoymS0X895yV92hwNnZQOqVhOdawxYAcihXzeZOzov 1UKwsZv9IFebv9faPCPdHG2CRkOsFbhx+kZK8ZOwddoaHS3/KePFQZE3i9675NdwnrUzvmq9N y0brONYTtiRHLfC079hEng50khqQG9Q3+9YicMrlQQwMTw2Tt2mncuQbXaAk1rPQjmm1enOLQ C70OKrGiQNCaR8YsPOTa48OJhh2syTB1wgi1WGrgScEyZpTmTTWCL2Sh9rkfUmPPEVbNJT26G XxlELPJs4QaCLaT26iGicdw0SKgPb2TEkO8cpAI51ghu0+XpVXgcUJW+A4J6smoNcq3GeX/J6 WCCrlkbTCr0lY2B8MrgypKacuQjDqXPif5uwJmd2grONww6wMfrzoTFAqdyJxjVEOnPbNbrmD lFlPnGjmwnS/3xsCLTZrrR9u3EyM7Y1DVXMwe9LwSFzapRaJayFC9kqXk9KzLNQJhbD1SpdsD q4TN7NSZfSOQZoCHf32AOxAfg/6l5nStTyKH3Txx+cF3PkFqo7A8ZCeF5LJeJ094CiUhNKfc9 oyoLcIVRJgqFsOVsDiDg== 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: Arnd Bergmann , David Airlie , =?utf-8?q?Guido_G=C3=BCnther?= , etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Russell King , Sam Ravnborg , Emil Velikov Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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. 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 Tested-by: Guido Günther --- 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)