From patchwork Mon Dec 16 14:15:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 181727 Delivered-To: patch@linaro.org Received: by 2002:a92:3001:0:0:0:0:0 with SMTP id x1csp4365090ile; Mon, 16 Dec 2019 06:15:49 -0800 (PST) X-Google-Smtp-Source: APXvYqwPGmR6KvIkDMfV9wnjVQew5SBSwMpk4AzHGIX8fO/YNZYYBX0ClPDxzKGw/HCHVeMVI8gz X-Received: by 2002:a9d:4789:: with SMTP id b9mr30023920otf.247.1576505748954; Mon, 16 Dec 2019 06:15:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576505748; cv=none; d=google.com; s=arc-20160816; b=0urZpcLeMvnkuY32MALPymvhzYtM1dU4ISWFI3O4T0K7GP170btqkZZpxLrRiygLsV dkS4NqsaCnS6hFSCkfpsLOS17WWAvfcZZj46Vu4IYM6w6g4hb7Ns2EfblfPXmm40D7lr eAH2D/zgXEQkGZv6JhBCre+7kkFubtAMlCwcvvaWYq+u/kAxKTDhxHzp8sQLYCNcASRg UHF5x4WnWBCL+jyzyKQQqWK2u4U6wDqlEUsuUbdPlE7PuqX71sq5VTKDxETQBjR+sYjJ ILdcmOpNkGwUeTpr/VZXigG+PsW2keG4CueZW3die8cRD83RHdSndDKt1JIxz5iJFaRh jQwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=QSBW7PfRZ/+vCA/RlSTDd2sdmDUOgJ3DFxB6AogcJTA=; b=VbsHiuRZ6ngzqEHZpeIqCeICZx1w4nmjOXOn+9mZL549CqImPRg5XCC+dZZkMFUol8 QAqKQ/MtZaZAiH5pM5cCR/lscInqpvGgfAtCTfroQVVKdDRQz3cz1sKyoeVvzYUVBIQ+ pnzTCMT+bRzGpVHxjO2+eYEq+KAyYiu27qyCK9s6t5YBQ1JD8lDbNXR0LOFUoGaVm4Kz E6/05TNmecsOmeAFi7PyPO5HeRcOrLKAHlIrd2rNa4mactvKMeyqDZk8Ck22YtglR9Wf f1aj0ryRa4vr9u39Z39aN31VtQbZzQ1l+nvog8SiFHBI1XQ9WWE/t0SWLjm1LD/EAWqx 6gMQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-media-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-media-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 k17si10394599oiw.238.2019.12.16.06.15.48; Mon, 16 Dec 2019 06:15:48 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-media-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-media-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-media-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728223AbfLPOPs (ORCPT + 4 others); Mon, 16 Dec 2019 09:15:48 -0500 Received: from mout.kundenserver.de ([212.227.17.13]:60123 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728071AbfLPOPX (ORCPT ); Mon, 16 Dec 2019 09:15:23 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue106 [212.227.15.145]) with ESMTPA (Nemesis) id 1Mj831-1i1jVJ0K17-00fDhs; Mon, 16 Dec 2019 15:15:16 +0100 From: Arnd Bergmann To: Hans Verkuil Cc: linux-media@vger.kernel.org, mchehab@kernel.org, y2038@lists.linaro.org, linux-kernel@vger.kernel.org, arnd@arndb.de Subject: [PATCH v6 2/8] media: v4l2: abstract timeval handling in v4l2_buffer Date: Mon, 16 Dec 2019 15:15:00 +0100 Message-Id: <20191216141506.121728-3-arnd@arndb.de> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20191216141506.121728-1-arnd@arndb.de> References: <20191216141506.121728-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:VBiiDXfoOh9jfWooojSW6N2tWr2yq+LiAEFTMAtjolltBnI9D3T LoVeDUjwqGfctfp8E6+8OEyH9MoF+FWscZpRdqacf7EcaGGmIwJ1zaigUZB2sIG/VCHQYZk alkXqzKbnXhA1DReWSyK9c+ixsVjS79kNJn7soQ4Vhp5jElSinhxQfneCoCnxAS/xk0S2F2 k758EVGVepnF0R8CfvCfA== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:BV44q3XCE7A=:ruh8DM96iWaQNeDFnNHM9u 3jq+4cbR2wjmIb/awVjkZicVPeRVvjncbV+l6QRb31XtYworWbRcGlctUL307KrvftV1dhVJi 36Eqn36INTYksu70Vs00YPaxu3JCjzndeDp3XXzz1eiIvWuo/OEQoTZiSMqckIJolEAcMWD/L YEQAyFETh40iaM1TAYnd4pIbpcP0tZ+EWpzNXWNDQQQ2dMHeeg4dhzI06V+FDiHXxPUF2Gt6j n/RwAamtcqGre/fQul5Blo+FQ01IZvAiIN7KrlN2juHpH/KNVcUSy2KB/JbYA/BaNv8bO8QLB D2HXvrOxzjEw2CtjbA7wkO230sdJddC/KF2UgdR/xu9AiWeIWkHoHLYF9VubHmX1fqB4ZEtfX OjvT4z8dI2GTRum9zM19uijhEGJbkT1p5Uvs/bbTjUL++QdTZtIuYFfIIfFT9Te8D6oMovVRu 9eLyzeM6HQaS24XWXygiYpbX1RJSq7gjqqm0zl8PY0mrR7vRWGDIkWbF4eHlHMVNGZQVCM+ET 1xjq6AT6Xth6Z0qWkji7usEt+JwQLGd7baLd8hfZoQJoHrXyX8WclKzokesiZB8u685eozXA0 JlUdoN4/LmPUTP9INha8xOS9NIN2TJUyKSI/crLsRf4620aSgPEkcQMjSKgofzeU5QDnhqtuH 0lNg8W0Osejc5bA8BlrPvHzC9AJT+t/xGUy8YqOzSw4p5/ePOUnoQLcXqH47exWs+d4mAUcWX SK7UyZ5LxlGfybEF7DRK3bCdqXVzc7vJ6qNkNgAbdw+2Xw6jACQCW207RoF1sI5E2fKPaAfeT i5ZJ6g08etMvEBvoH5LzHCBhOw7MevUSL/0uXJSlad4URjFiKSCkjIVVZBVa4rTeCaIoqdRhb 5gG4fIBD2QBxT4+A+NSg== Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org As a preparation for adding 64-bit time_t support in the uapi, change the drivers to no longer care about the format of the timestamp field in struct v4l2_buffer. The v4l2_timeval_to_ns() function is no longer needed in the kernel after this, but there is userspace code relying on it to be part of the uapi header. Signed-off-by: Arnd Bergmann --- .../media/common/videobuf2/videobuf2-v4l2.c | 4 ++-- drivers/media/pci/meye/meye.c | 4 ++-- drivers/media/usb/cpia2/cpia2_v4l.c | 4 ++-- drivers/media/usb/stkwebcam/stk-webcam.c | 2 +- drivers/media/usb/usbvision/usbvision-video.c | 4 ++-- drivers/media/v4l2-core/videobuf-core.c | 5 +++-- include/media/v4l2-common.h | 21 +++++++++++++++++++ include/trace/events/v4l2.h | 2 +- include/uapi/linux/videodev2.h | 2 ++ 9 files changed, 36 insertions(+), 12 deletions(-) -- 2.20.0 diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c index e652f4318284..eb5d5db96552 100644 --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c @@ -146,7 +146,7 @@ static void __copy_timestamp(struct vb2_buffer *vb, const void *pb) * and the timecode field and flag if needed. */ if (q->copy_timestamp) - vb->timestamp = v4l2_timeval_to_ns(&b->timestamp); + vb->timestamp = v4l2_buffer_get_timestamp(b); vbuf->flags |= b->flags & V4L2_BUF_FLAG_TIMECODE; if (b->flags & V4L2_BUF_FLAG_TIMECODE) vbuf->timecode = b->timecode; @@ -482,7 +482,7 @@ static void __fill_v4l2_buffer(struct vb2_buffer *vb, void *pb) b->flags = vbuf->flags; b->field = vbuf->field; - b->timestamp = ns_to_timeval(vb->timestamp); + v4l2_buffer_set_timestamp(b, vb->timestamp); b->timecode = vbuf->timecode; b->sequence = vbuf->sequence; b->reserved2 = 0; diff --git a/drivers/media/pci/meye/meye.c b/drivers/media/pci/meye/meye.c index 0e61c81356ef..3a4c29bc0ba5 100644 --- a/drivers/media/pci/meye/meye.c +++ b/drivers/media/pci/meye/meye.c @@ -1266,7 +1266,7 @@ static int vidioc_querybuf(struct file *file, void *fh, struct v4l2_buffer *buf) buf->flags |= V4L2_BUF_FLAG_DONE; buf->field = V4L2_FIELD_NONE; - buf->timestamp = ns_to_timeval(meye.grab_buffer[index].ts); + v4l2_buffer_set_timestamp(buf, meye.grab_buffer[index].ts); buf->sequence = meye.grab_buffer[index].sequence; buf->memory = V4L2_MEMORY_MMAP; buf->m.offset = index * gbufsize; @@ -1332,7 +1332,7 @@ static int vidioc_dqbuf(struct file *file, void *fh, struct v4l2_buffer *buf) buf->bytesused = meye.grab_buffer[reqnr].size; buf->flags = V4L2_BUF_FLAG_MAPPED | V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; buf->field = V4L2_FIELD_NONE; - buf->timestamp = ns_to_timeval(meye.grab_buffer[reqnr].ts); + v4l2_buffer_set_timestamp(buf, meye.grab_buffer[reqnr].ts); buf->sequence = meye.grab_buffer[reqnr].sequence; buf->memory = V4L2_MEMORY_MMAP; buf->m.offset = reqnr * gbufsize; diff --git a/drivers/media/usb/cpia2/cpia2_v4l.c b/drivers/media/usb/cpia2/cpia2_v4l.c index 626264a56517..9d3d05125d7b 100644 --- a/drivers/media/usb/cpia2/cpia2_v4l.c +++ b/drivers/media/usb/cpia2/cpia2_v4l.c @@ -800,7 +800,7 @@ static int cpia2_querybuf(struct file *file, void *fh, struct v4l2_buffer *buf) break; case FRAME_READY: buf->bytesused = cam->buffers[buf->index].length; - buf->timestamp = ns_to_timeval(cam->buffers[buf->index].ts); + v4l2_buffer_set_timestamp(buf, cam->buffers[buf->index].ts); buf->sequence = cam->buffers[buf->index].seq; buf->flags = V4L2_BUF_FLAG_DONE; break; @@ -907,7 +907,7 @@ static int cpia2_dqbuf(struct file *file, void *fh, struct v4l2_buffer *buf) buf->flags = V4L2_BUF_FLAG_MAPPED | V4L2_BUF_FLAG_DONE | V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; buf->field = V4L2_FIELD_NONE; - buf->timestamp = ns_to_timeval(cam->buffers[buf->index].ts); + v4l2_buffer_set_timestamp(buf, cam->buffers[buf->index].ts); buf->sequence = cam->buffers[buf->index].seq; buf->m.offset = cam->buffers[buf->index].data - cam->frame_buffer; buf->length = cam->frame_size; diff --git a/drivers/media/usb/stkwebcam/stk-webcam.c b/drivers/media/usb/stkwebcam/stk-webcam.c index 21f90a887485..b22501f76b78 100644 --- a/drivers/media/usb/stkwebcam/stk-webcam.c +++ b/drivers/media/usb/stkwebcam/stk-webcam.c @@ -1125,7 +1125,7 @@ static int stk_vidioc_dqbuf(struct file *filp, sbuf->v4lbuf.flags &= ~V4L2_BUF_FLAG_QUEUED; sbuf->v4lbuf.flags |= V4L2_BUF_FLAG_DONE; sbuf->v4lbuf.sequence = ++dev->sequence; - sbuf->v4lbuf.timestamp = ns_to_timeval(ktime_get_ns()); + v4l2_buffer_set_timestamp(&sbuf->v4lbuf, ktime_get_ns()); *buf = sbuf->v4lbuf; return 0; diff --git a/drivers/media/usb/usbvision/usbvision-video.c b/drivers/media/usb/usbvision/usbvision-video.c index 93d36aab824f..5ca2c2f35fe2 100644 --- a/drivers/media/usb/usbvision/usbvision-video.c +++ b/drivers/media/usb/usbvision/usbvision-video.c @@ -696,7 +696,7 @@ static int vidioc_querybuf(struct file *file, vb->length = usbvision->curwidth * usbvision->curheight * usbvision->palette.bytes_per_pixel; - vb->timestamp = ns_to_timeval(usbvision->frame[vb->index].ts); + v4l2_buffer_set_timestamp(vb, usbvision->frame[vb->index].ts); vb->sequence = usbvision->frame[vb->index].sequence; return 0; } @@ -765,7 +765,7 @@ static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *vb) V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; vb->index = f->index; vb->sequence = f->sequence; - vb->timestamp = ns_to_timeval(f->ts); + v4l2_buffer_set_timestamp(vb, f->ts); vb->field = V4L2_FIELD_NONE; vb->bytesused = f->scanlength; diff --git a/drivers/media/v4l2-core/videobuf-core.c b/drivers/media/v4l2-core/videobuf-core.c index 939fc11cf080..2686f03b322e 100644 --- a/drivers/media/v4l2-core/videobuf-core.c +++ b/drivers/media/v4l2-core/videobuf-core.c @@ -19,6 +19,7 @@ #include #include +#include #define MAGIC_BUFFER 0x20070728 #define MAGIC_CHECK(is, should) \ @@ -364,7 +365,7 @@ static void videobuf_status(struct videobuf_queue *q, struct v4l2_buffer *b, } b->field = vb->field; - b->timestamp = ns_to_timeval(vb->ts); + v4l2_buffer_set_timestamp(b, vb->ts); b->bytesused = vb->size; b->sequence = vb->field_count >> 1; } @@ -578,7 +579,7 @@ int videobuf_qbuf(struct videobuf_queue *q, struct v4l2_buffer *b) || q->type == V4L2_BUF_TYPE_SDR_OUTPUT) { buf->size = b->bytesused; buf->field = b->field; - buf->ts = v4l2_timeval_to_ns(&b->timestamp); + buf->ts = v4l2_buffer_get_timestamp(b); } break; case V4L2_MEMORY_USERPTR: diff --git a/include/media/v4l2-common.h b/include/media/v4l2-common.h index d8c29e089000..8d0ac0311c84 100644 --- a/include/media/v4l2-common.h +++ b/include/media/v4l2-common.h @@ -14,6 +14,7 @@ #ifndef V4L2_COMMON_H_ #define V4L2_COMMON_H_ +#include #include /* Common printk constructs for v4l-i2c drivers. These macros create a unique @@ -518,4 +519,24 @@ int v4l2_fill_pixfmt(struct v4l2_pix_format *pixfmt, u32 pixelformat, int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, u32 pixelformat, u32 width, u32 height); +static inline u64 v4l2_buffer_get_timestamp(const struct v4l2_buffer *buf) +{ + /* + * When the timestamp comes from 32-bit user space, there may be + * uninitialized data in tv_usec, so cast it to u32. + * Otherwise allow invalid input for backwards compatibility. + */ + return buf->timestamp.tv_sec * NSEC_PER_SEC + + (u32)buf->timestamp.tv_usec * NSEC_PER_USEC; +} + +static inline void v4l2_buffer_set_timestamp(struct v4l2_buffer *buf, + u64 timestamp) +{ + struct timespec64 ts = ns_to_timespec64(timestamp); + + buf->timestamp.tv_sec = ts.tv_sec; + buf->timestamp.tv_usec = ts.tv_nsec / NSEC_PER_USEC; +} + #endif /* V4L2_COMMON_H_ */ diff --git a/include/trace/events/v4l2.h b/include/trace/events/v4l2.h index 83860de120e3..248bc09bfc99 100644 --- a/include/trace/events/v4l2.h +++ b/include/trace/events/v4l2.h @@ -130,7 +130,7 @@ DECLARE_EVENT_CLASS(v4l2_event_class, __entry->bytesused = buf->bytesused; __entry->flags = buf->flags; __entry->field = buf->field; - __entry->timestamp = timeval_to_ns(&buf->timestamp); + __entry->timestamp = v4l2_buffer_get_timestamp(buf); __entry->timecode_type = buf->timecode.type; __entry->timecode_flags = buf->timecode.flags; __entry->timecode_frames = buf->timecode.frames; diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h index 04481c717fee..6ef4a5b787a4 100644 --- a/include/uapi/linux/videodev2.h +++ b/include/uapi/linux/videodev2.h @@ -1017,6 +1017,7 @@ struct v4l2_buffer { }; }; +#ifndef __KERNEL__ /** * v4l2_timeval_to_ns - Convert timeval to nanoseconds * @ts: pointer to the timeval variable to be converted @@ -1028,6 +1029,7 @@ static inline __u64 v4l2_timeval_to_ns(const struct timeval *tv) { return (__u64)tv->tv_sec * 1000000000ULL + tv->tv_usec * 1000; } +#endif /* Flags for 'flags' field */ /* Buffer is mapped (flag) */ From patchwork Mon Dec 16 14:15:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 181725 Delivered-To: patch@linaro.org Received: by 2002:a92:3001:0:0:0:0:0 with SMTP id x1csp4364904ile; Mon, 16 Dec 2019 06:15:40 -0800 (PST) X-Google-Smtp-Source: APXvYqzGHLOZf3hQjFVyCjWSprCNUsA6WjKwJYZh9EhGBrVQpj9P/Q6tS/zRKoxvYtJR3y6hGI+P X-Received: by 2002:a05:6830:1744:: with SMTP id 4mr24119508otz.71.1576505740325; Mon, 16 Dec 2019 06:15:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576505740; cv=none; d=google.com; s=arc-20160816; b=CZCxNCAqLtXunqYHDMBDRWgIxuI+Lqh61W4/59o2g4X+1kwLLjJgpyVkoacKbkb42x 3jqTKFPStRCCpO/NELYDnzacdQYnjVmFlzAliv0sP90b/xdhZwTL1csww49qDZvVdqoC hnJdZGmLn2MTnSrMh1ZfbZipF+Hjp6YYm5uRzoFf+b7LO4QmycpI4pq0AIEN5k+hXAk+ Yi2QSJ+srmxAc84wrIN8n0rLSOAdT20/pM1JozEhd5J5WGewTDvpbBmNMvFiEQTWi1en YFAueH34OuFm364S9mRaT5oDMLEdHZtsKw5oCieh1SEmofUVU33bNOFLGDs2L+mE5WL2 KhOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=d7WlVDnN4GThUstfjWsc+Nh6S7TFZVq1CLHXqZXoDYA=; b=aG4gzBICMT5MMKVK6W+P9YoabtNHLwnE2wD8BEG/AhGfwxToINjI0Du87U9w8WldUT C+OhNDKCtibdv27DWJDZMmWFGfVEmmwksLa7P+01mChlobzf8BhZg9qq+HnUk5r3283v ZAfWUC7kHZhuHnB97/nB1ZczdLjPLfYGTUGQ+eoYqW6lHobHlOUsH3ktPctZ5Vft0qwG yKN8yy3jw6S6H+rfH5FP5lIItORVpoLjIXmi2rl4Ex1WEFiXDXYpKcPqPvqIkswaPfOB PSuae06sOmfjk6f3Dh0RyO+9NF/1FS5shXCQAvtedqhug1E3nkKqk1nddkvYvAZleb9V GRWA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-media-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-media-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 b10si10104815oic.153.2019.12.16.06.15.40; Mon, 16 Dec 2019 06:15:40 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-media-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-media-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-media-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728198AbfLPOPi (ORCPT + 4 others); Mon, 16 Dec 2019 09:15:38 -0500 Received: from mout.kundenserver.de ([212.227.17.24]:57047 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728077AbfLPOPX (ORCPT ); Mon, 16 Dec 2019 09:15:23 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue106 [212.227.15.145]) with ESMTPA (Nemesis) id 1MIxmm-1iQzEM3aBe-00KPMx; Mon, 16 Dec 2019 15:15:16 +0100 From: Arnd Bergmann To: Hans Verkuil Cc: linux-media@vger.kernel.org, mchehab@kernel.org, y2038@lists.linaro.org, linux-kernel@vger.kernel.org, arnd@arndb.de Subject: [PATCH v6 5/8] media: v4l2-core: fix VIDIOC_DQEVENT for time64 ABI Date: Mon, 16 Dec 2019 15:15:03 +0100 Message-Id: <20191216141506.121728-6-arnd@arndb.de> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20191216141506.121728-1-arnd@arndb.de> References: <20191216141506.121728-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:H5H1RmnXaEOuYWn+vsjSxxaTxYeVtdhHvtMBsOQPAVhibas8Uar yLC6PGWFKIqzGjk6x9Z02S+iX/5Q61nF44ZgSb8EMD6vk9wkXZ59zXWP6LnAIAj5+XisIIO yY7255T/9pcitGw+2En4WUw1Pc+P5TUQWJ0Da4eMlaMoPzBGHywC4SL2TrEk0HCox3DLZJ0 nqaZ2y0SSa5mN02ugRwYQ== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:cQFbZyBNSTs=:spZ1js6BwetzI8lokx6pMb x60WvzLkPuFk6oqzIUU4W06UyubKX8BoS70085Pik8ZfqhAn6oy5EdJr4x8mDA4vFL+DRJ9F8 y4k2d78HzsDZBRmqNh+e1xXq4xibaVa9lsP5eeSJL9aFtdWn6jxSODv3tNQGKRiguqGCARE/O yjdXb26zE27Q5aT+OPPWqbxDbWRo6eOtaSBoqY2YW/1Vqw/A3vb5fGgMK8xB24zqfkDI9Our2 cs2xLvDZUp79K/+JxC4d53/ZlPAf5cSL97lfkeWFgCcoUfeg8hP6So9J30/m7PGMLRTbZNw6/ q7/sOX+JzfG6ei5YvZVPGjXQS8P4cI7ht/3Tw0RdCQuUbgE7QXc6y8s7f1DjLnS2lBlm/1IYr blZ0XjVZ4Kyqv81gAi2Gta0b9N3WTuRajrdjLwiYlEK74c1Z5ztISWZwVPTSd0L3npWxsWxIs PVsIHYJ93xdyHwhh65OuvigEHMfv5USnEWwH8Ytse/cH/lIx8WAa6qz31lflEOGh/BP5F1Xn0 QEqfj6DQ98CssEje5Zy0ZgWVMwRLUiJypX7SW5LMBdhhuMrxfBVO630ANWF1XCrqTBNBVGzKM 2BOi1B1A2iZLqKPF5RgnlEmmWj+dOIyjtlyUwBavFPDlhuYGu1hWrVOuKT33FDeVJnDUix4U/ 5Gxly7Yll3BDENiFBI8xPWhx3SCidoKxI6RP94NScLKDEdHs3va8g5pV9kHdzfTP/5HBgGhfs TqNnHBkQZY5ccC6/Zz5Nitl6oexSwEd64aKeeOg9qp7raMtNtSootj8+BhqFX2h0bdGwnIzAx pIBy997tsQqO4m7dlYTD1xvxdNBhuYIUJ6dSu5ohSLye9lfibUoQ6OIC1Sri8JYB2mt97yS7g vkx0nE7GoAA/wkicLnqg== Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The v4l2_event structure contains a 'struct timespec' member that is defined by the user space C library, creating an ABI incompatibility when that gets updated to a 64-bit time_t. While passing a 32-bit time_t here would be sufficient for CLOCK_MONOTONIC timestamps, simply redefining the structure to use the kernel's __kernel_old_timespec would not work for any library that uses a copy of the linux/videodev2.h header file rather than including the copy from the latest kernel headers. This means the kernel has to be changed to handle both versions of the structure layout on a 32-bit architecture. The easiest way to do this is during the copy from/to user space. Signed-off-by: Arnd Bergmann --- drivers/media/v4l2-core/v4l2-event.c | 5 ++++- drivers/media/v4l2-core/v4l2-ioctl.c | 29 ++++++++++++++++++++++++++- drivers/media/v4l2-core/v4l2-subdev.c | 26 +++++++++++++++++++++++- include/media/v4l2-ioctl.h | 25 +++++++++++++++++++++++ include/uapi/linux/videodev2.h | 4 ++++ 5 files changed, 86 insertions(+), 3 deletions(-) -- 2.20.0 diff --git a/drivers/media/v4l2-core/v4l2-event.c b/drivers/media/v4l2-core/v4l2-event.c index 9d673d113d7a..290c6b213179 100644 --- a/drivers/media/v4l2-core/v4l2-event.c +++ b/drivers/media/v4l2-core/v4l2-event.c @@ -27,6 +27,7 @@ static unsigned sev_pos(const struct v4l2_subscribed_event *sev, unsigned idx) static int __v4l2_event_dequeue(struct v4l2_fh *fh, struct v4l2_event *event) { struct v4l2_kevent *kev; + struct timespec64 ts; unsigned long flags; spin_lock_irqsave(&fh->vdev->fh_lock, flags); @@ -44,7 +45,9 @@ static int __v4l2_event_dequeue(struct v4l2_fh *fh, struct v4l2_event *event) kev->event.pending = fh->navailable; *event = kev->event; - event->timestamp = ns_to_timespec(kev->ts); + ts = ns_to_timespec64(kev->ts); + event->timestamp.tv_sec = ts.tv_sec; + event->timestamp.tv_nsec = ts.tv_nsec; kev->sev->first = sev_pos(kev->sev, 1); kev->sev->in_use--; diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c index fe4678965e1b..b066e27e99a2 100644 --- a/drivers/media/v4l2-core/v4l2-ioctl.c +++ b/drivers/media/v4l2-core/v4l2-ioctl.c @@ -821,7 +821,7 @@ static void v4l_print_event(const void *arg, bool write_only) const struct v4l2_event *p = arg; const struct v4l2_event_ctrl *c; - pr_cont("type=0x%x, pending=%u, sequence=%u, id=%u, timestamp=%lu.%9.9lu\n", + pr_cont("type=0x%x, pending=%u, sequence=%u, id=%u, timestamp=%llu.%9.9llu\n", p->type, p->pending, p->sequence, p->id, p->timestamp.tv_sec, p->timestamp.tv_nsec); switch (p->type) { @@ -3025,6 +3025,13 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size, static unsigned int video_translate_cmd(unsigned int cmd) { + switch (cmd) { +#ifdef CONFIG_COMPAT_32BIT_TIME + case VIDIOC_DQEVENT_TIME32: + return VIDIOC_DQEVENT; +#endif + } + return cmd; } @@ -3074,6 +3081,26 @@ static int video_put_user(void __user *arg, void *parg, unsigned int cmd) return 0; switch (cmd) { +#ifdef CONFIG_COMPAT_32BIT_TIME + case VIDIOC_DQEVENT_TIME32: { + struct v4l2_event *ev = parg; + struct v4l2_event_time32 ev32 = { + .type = ev->type, + .pending = ev->pending, + .sequence = ev->sequence, + .timestamp.tv_sec = ev->timestamp.tv_sec, + .timestamp.tv_nsec = ev->timestamp.tv_nsec, + .id = ev->id, + }; + + memcpy(&ev32.u, &ev->u, sizeof(ev->u)); + memcpy(&ev32.reserved, &ev->reserved, sizeof(ev->reserved)); + + if (copy_to_user(arg, &ev32, sizeof(ev32))) + return -EFAULT; + break; + } +#endif default: /* Copy results into user buffer */ if (copy_to_user(arg, parg, _IOC_SIZE(cmd))) diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c index 9e987c0f840e..de926e311348 100644 --- a/drivers/media/v4l2-core/v4l2-subdev.c +++ b/drivers/media/v4l2-core/v4l2-subdev.c @@ -331,8 +331,8 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg) struct v4l2_fh *vfh = file->private_data; #if defined(CONFIG_VIDEO_V4L2_SUBDEV_API) struct v4l2_subdev_fh *subdev_fh = to_v4l2_subdev_fh(vfh); - int rval; #endif + int rval; switch (cmd) { case VIDIOC_QUERYCTRL: @@ -392,6 +392,30 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg) return v4l2_event_dequeue(vfh, arg, file->f_flags & O_NONBLOCK); + case VIDIOC_DQEVENT_TIME32: { + struct v4l2_event_time32 *ev32 = arg; + struct v4l2_event ev; + + if (!(sd->flags & V4L2_SUBDEV_FL_HAS_EVENTS)) + return -ENOIOCTLCMD; + + rval = v4l2_event_dequeue(vfh, &ev, file->f_flags & O_NONBLOCK); + + *ev32 = (struct v4l2_event_time32) { + .type = ev.type, + .pending = ev.pending, + .sequence = ev.sequence, + .timestamp.tv_sec = ev.timestamp.tv_sec, + .timestamp.tv_nsec = ev.timestamp.tv_nsec, + .id = ev.id, + }; + + memcpy(&ev32->u, &ev.u, sizeof(ev.u)); + memcpy(&ev32->reserved, &ev.reserved, sizeof(ev.reserved)); + + return rval; + } + case VIDIOC_SUBSCRIBE_EVENT: return v4l2_subdev_call(sd, core, subscribe_event, vfh, arg); diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h index 4bba65a59d46..05c1ec93a911 100644 --- a/include/media/v4l2-ioctl.h +++ b/include/media/v4l2-ioctl.h @@ -724,4 +724,29 @@ long int video_usercopy(struct file *file, unsigned int cmd, long int video_ioctl2(struct file *file, unsigned int cmd, unsigned long int arg); +/* + * The user space interpretation of the 'v4l2_event' differs + * based on the 'time_t' definition on 32-bit architectures, so + * the kernel has to handle both. + * This is the old version for 32-bit architectures. + */ +struct v4l2_event_time32 { + __u32 type; + union { + struct v4l2_event_vsync vsync; + struct v4l2_event_ctrl ctrl; + struct v4l2_event_frame_sync frame_sync; + struct v4l2_event_src_change src_change; + struct v4l2_event_motion_det motion_det; + __u8 data[64]; + } u; + __u32 pending; + __u32 sequence; + struct old_timespec32 timestamp; + __u32 id; + __u32 reserved[8]; +}; + +#define VIDIOC_DQEVENT_TIME32 _IOR('V', 89, struct v4l2_event_time32) + #endif /* _V4L2_IOCTL_H */ diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h index 6ef4a5b787a4..caf156d45842 100644 --- a/include/uapi/linux/videodev2.h +++ b/include/uapi/linux/videodev2.h @@ -2341,7 +2341,11 @@ struct v4l2_event { } u; __u32 pending; __u32 sequence; +#ifdef __KERNEL__ + struct __kernel_timespec timestamp; +#else struct timespec timestamp; +#endif __u32 id; __u32 reserved[8]; };