Skip to content

Commit 38c4a4c

Browse files
committed
drm/etnaviv: avoid deprecated timespec
struct timespec is being removed from the kernel because it often leads to code that is not y2038-safe. In the etnaviv driver, monotonic timestamps are used, which do not suffer from overflow, but the usage of timespec here gets in the way of removing the interface completely. Pass down the user-supplied 64-bit value here rather than converting it to an intermediate timespec to avoid the conversion. The conversion is transparent for all regular CLOCK_MONOTONIC values, but is a small change in behavior for excessively large values: the existing code would treat e.g. tv_sec=0x100000000 the same as tv_sec=0 and not block, while the new code it would block for up to 2^31 seconds. The new behavior is more logical here, but if it causes problems, the truncation can be put back. Signed-off-by: Arnd Bergmann <arnd@arndb.de>
1 parent 245595e commit 38c4a4c

6 files changed

Lines changed: 18 additions & 20 deletions

File tree

‎drivers/gpu/drm/etnaviv/etnaviv_drv.c‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,6 @@ static int etnaviv_ioctl_gem_new(struct drm_device *dev, void *data,
282282
args->flags, &args->handle);
283283
}
284284

285-
#define TS(t) ((struct timespec){ \
286-
.tv_sec = (t).tv_sec, \
287-
.tv_nsec = (t).tv_nsec \
288-
})
289-
290285
static int etnaviv_ioctl_gem_cpu_prep(struct drm_device *dev, void *data,
291286
struct drm_file *file)
292287
{
@@ -304,7 +299,7 @@ static int etnaviv_ioctl_gem_cpu_prep(struct drm_device *dev, void *data,
304299
if (!obj)
305300
return -ENOENT;
306301

307-
ret = etnaviv_gem_cpu_prep(obj, args->op, &TS(args->timeout));
302+
ret = etnaviv_gem_cpu_prep(obj, args->op, &args->timeout);
308303

309304
drm_gem_object_put_unlocked(obj);
310305

@@ -357,7 +352,7 @@ static int etnaviv_ioctl_wait_fence(struct drm_device *dev, void *data,
357352
{
358353
struct drm_etnaviv_wait_fence *args = data;
359354
struct etnaviv_drm_private *priv = dev->dev_private;
360-
struct timespec *timeout = &TS(args->timeout);
355+
struct drm_etnaviv_timespec *timeout = &args->timeout;
361356
struct etnaviv_gpu *gpu;
362357

363358
if (args->flags & ~(ETNA_WAIT_NONBLOCK))
@@ -409,7 +404,7 @@ static int etnaviv_ioctl_gem_wait(struct drm_device *dev, void *data,
409404
{
410405
struct etnaviv_drm_private *priv = dev->dev_private;
411406
struct drm_etnaviv_gem_wait *args = data;
412-
struct timespec *timeout = &TS(args->timeout);
407+
struct drm_etnaviv_timespec *timeout = &args->timeout;
413408
struct drm_gem_object *obj;
414409
struct etnaviv_gpu *gpu;
415410
int ret;

‎drivers/gpu/drm/etnaviv/etnaviv_drv.h‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ int etnaviv_gem_prime_pin(struct drm_gem_object *obj);
6161
void etnaviv_gem_prime_unpin(struct drm_gem_object *obj);
6262
void *etnaviv_gem_vmap(struct drm_gem_object *obj);
6363
int etnaviv_gem_cpu_prep(struct drm_gem_object *obj, u32 op,
64-
struct timespec *timeout);
64+
struct drm_etnaviv_timespec *timeout);
6565
int etnaviv_gem_cpu_fini(struct drm_gem_object *obj);
6666
void etnaviv_gem_free_object(struct drm_gem_object *obj);
6767
int etnaviv_gem_new_handle(struct drm_device *dev, struct drm_file *file,
@@ -107,11 +107,12 @@ static inline size_t size_vstruct(size_t nelem, size_t elem_size, size_t base)
107107
* between the specified timeout and the current CLOCK_MONOTONIC time.
108108
*/
109109
static inline unsigned long etnaviv_timeout_to_jiffies(
110-
const struct timespec *timeout)
110+
const struct drm_etnaviv_timespec *timeout)
111111
{
112-
struct timespec64 ts, to;
113-
114-
to = timespec_to_timespec64(*timeout);
112+
struct timespec64 ts, to = {
113+
.tv_sec = timeout->tv_sec,
114+
.tv_nsec = timeout->tv_nsec,
115+
};
115116

116117
ktime_get_ts64(&ts);
117118

‎drivers/gpu/drm/etnaviv/etnaviv_gem.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ static inline enum dma_data_direction etnaviv_op_to_dma_dir(u32 op)
373373
}
374374

375375
int etnaviv_gem_cpu_prep(struct drm_gem_object *obj, u32 op,
376-
struct timespec *timeout)
376+
struct drm_etnaviv_timespec *timeout)
377377
{
378378
struct etnaviv_gem_object *etnaviv_obj = to_etnaviv_bo(obj);
379379
struct drm_device *dev = obj->dev;
@@ -431,7 +431,7 @@ int etnaviv_gem_cpu_fini(struct drm_gem_object *obj)
431431
}
432432

433433
int etnaviv_gem_wait_bo(struct etnaviv_gpu *gpu, struct drm_gem_object *obj,
434-
struct timespec *timeout)
434+
struct drm_etnaviv_timespec *timeout)
435435
{
436436
struct etnaviv_gem_object *etnaviv_obj = to_etnaviv_bo(obj);
437437

‎drivers/gpu/drm/etnaviv/etnaviv_gem.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ struct etnaviv_gem_submit {
112112
void etnaviv_submit_put(struct etnaviv_gem_submit * submit);
113113

114114
int etnaviv_gem_wait_bo(struct etnaviv_gpu *gpu, struct drm_gem_object *obj,
115-
struct timespec *timeout);
115+
struct drm_etnaviv_timespec *timeout);
116116
int etnaviv_gem_new_private(struct drm_device *dev, size_t size, u32 flags,
117117
const struct etnaviv_gem_ops *ops, struct etnaviv_gem_object **res);
118118
void etnaviv_gem_obj_add(struct drm_device *dev, struct drm_gem_object *obj);

‎drivers/gpu/drm/etnaviv/etnaviv_gpu.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,7 +1132,7 @@ static void event_free(struct etnaviv_gpu *gpu, unsigned int event)
11321132
* Cmdstream submission/retirement:
11331133
*/
11341134
int etnaviv_gpu_wait_fence_interruptible(struct etnaviv_gpu *gpu,
1135-
u32 id, struct timespec *timeout)
1135+
u32 id, struct drm_etnaviv_timespec *timeout)
11361136
{
11371137
struct dma_fence *fence;
11381138
int ret;
@@ -1179,7 +1179,8 @@ int etnaviv_gpu_wait_fence_interruptible(struct etnaviv_gpu *gpu,
11791179
* that lock in this function while waiting.
11801180
*/
11811181
int etnaviv_gpu_wait_obj_inactive(struct etnaviv_gpu *gpu,
1182-
struct etnaviv_gem_object *etnaviv_obj, struct timespec *timeout)
1182+
struct etnaviv_gem_object *etnaviv_obj,
1183+
struct drm_etnaviv_timespec *timeout)
11831184
{
11841185
unsigned long remaining;
11851186
long ret;

‎drivers/gpu/drm/etnaviv/etnaviv_gpu.h‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,10 @@ int etnaviv_gpu_debugfs(struct etnaviv_gpu *gpu, struct seq_file *m);
169169
void etnaviv_gpu_recover_hang(struct etnaviv_gpu *gpu);
170170
void etnaviv_gpu_retire(struct etnaviv_gpu *gpu);
171171
int etnaviv_gpu_wait_fence_interruptible(struct etnaviv_gpu *gpu,
172-
u32 fence, struct timespec *timeout);
172+
u32 fence, struct drm_etnaviv_timespec *timeout);
173173
int etnaviv_gpu_wait_obj_inactive(struct etnaviv_gpu *gpu,
174-
struct etnaviv_gem_object *etnaviv_obj, struct timespec *timeout);
174+
struct etnaviv_gem_object *etnaviv_obj,
175+
struct drm_etnaviv_timespec *timeout);
175176
struct dma_fence *etnaviv_gpu_submit(struct etnaviv_gem_submit *submit);
176177
int etnaviv_gpu_pm_get_sync(struct etnaviv_gpu *gpu);
177178
void etnaviv_gpu_pm_put(struct etnaviv_gpu *gpu);

0 commit comments

Comments
 (0)