From patchwork Tue Nov 26 16:18:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 180222 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp4851292ilf; Tue, 26 Nov 2019 08:19:13 -0800 (PST) X-Google-Smtp-Source: APXvYqwX5TTLG4wmiQccpLxEgTJ+t0cce5G+qLqla1I9RHV6L/wGpzIt/qbDgD+ZZ5aLfjTSc5LN X-Received: by 2002:a05:6402:1ac4:: with SMTP id ba4mr844251edb.201.1574785153187; Tue, 26 Nov 2019 08:19:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574785153; cv=none; d=google.com; s=arc-20160816; b=j9oLvpMFcJ4cnG0lM0GqIqUDz0NjzdJVX/u5zH0VKrTNpleIaM485KPYVvIzRHmGPo iI0IvjuFG0USTQdooOaB0+/IO7zlN05OCRFHOBeijq4zTx++n1LQ5ha6IXTaC5flpS/u r+Ale3Oj9tCZfAx+A73VBIpB4+RWkbiLaZjhRBelpz3vXX6pEm3L9T1XK9VY0Z5ps/Zi XQgiHqm0XKLRn3zQRzJSyfhldO7HFmVzcItExvDFVGAIUOqog/LxzZUN/Gt7pB8nvpI5 u7YuAswv9BroiapMW28HbVjoqrN4jnjOwvDIsk/j/qzGwEe7GiaAWShAOFNJHtMrED1f 1egA== 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=txkq25OEHf+TdFooSVBnyiUK7ilLS5z0TvQYHSSSknI=; b=g0XBz5W04QD6qMSQ512DeTlrPvh3exFuOcnJNdO8QnEUS3q/l1ObP/7yoCt5KLhFlv ZZB9nGiy887ZQvzBOrVx4jsWKUZSEEbdTQV0gLg5sIJel4vc2nwzqUy1dcsrut0fINCk fJ2FBjtzhi4tX6mflJm7DqE9VEXUa3tccK0xuevaH6SrFtbc7481skK3R+1kRuv6eMRr LLcxvVeCUPBhYu//4gQzQp0xdoCPN6PivEH8sgGY0Miv0HW0BinjRUMIqJClf71D00HV ZOr35a8iK/4u744dnx/JneCJOFRZ6LxdpEunrbzT7lHVLGvWrbIasnq747aDS5Ju0J+b xn8g== 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 b29si8743643ede.118.2019.11.26.08.19.12; Tue, 26 Nov 2019 08:19:13 -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 S1728807AbfKZQS7 (ORCPT + 26 others); Tue, 26 Nov 2019 11:18:59 -0500 Received: from mout.kundenserver.de ([212.227.17.10]:49401 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728736AbfKZQSm (ORCPT ); Tue, 26 Nov 2019 11:18:42 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue106 [212.227.15.145]) with ESMTPA (Nemesis) id 1MkpvV-1i6P0X3prb-00mMHc; Tue, 26 Nov 2019 17:18:34 +0100 From: Arnd Bergmann To: linux-media@vger.kernel.org, Hans Verkuil , Mauro Carvalho Chehab Cc: y2038@lists.linaro.org, linux-kernel@vger.kernel.org, Arnd Bergmann Subject: [PATCH v5 5/8] media: v4l2-core: fix VIDIOC_DQEVENT for time64 ABI Date: Tue, 26 Nov 2019 17:18:21 +0100 Message-Id: <20191126161824.337724-6-arnd@arndb.de> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20191126161824.337724-1-arnd@arndb.de> References: <20191126161824.337724-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:wkgRxtQA2JMregiwL6hSMY9oukvaH+tLG6uRYJ+QQU6deycwLFW OJkb9MDnuw3lm4y4OMQT0gltJ26h4xHU2/atWaqRkpUhq3Shp0Piwov4qNrsCIKWAa2G9AS JGEf2pt0n2hjrG5nTBWrwSX5k8ZLXV9MTWeDig2zzwiKG1IFrICbX5o/feNIBJhz179YuLg LER7vA16ObgXZRxwC++LA== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:ZmXBWwy9Psg=:6JoRMFo9SGexQszH7tkr7p UMBj2wK63k6e50z0+PSmRtDl7s4naauXpJdMV8vef7iNzB5wy5VkFdp82yBF8baaUkXsmXL2Y L/lkuXGRFzjBvgNpKKXGaOX+vYYGN1P/maw8dnaTaamwpXyyMLeAjYMliioX3Z1lLEwVR43zg oJp5nzzZqyAB13hl25/lePGZDGRTKaSVgv7UVtk4xkOA5UWyj6T88X8z6GCvgjFbJEUDd9lHI ESgzkUT8tvc2FeIvzyPZGBAkSLDHeKibMsd7R1vSGm60Ch2uib6HCgj40EZdO90JBZoxMyWgi cPlEdjfxqCoff9vAqHJW2NSIhKH3tUbSjc9wgb0NAFw7dU3UqtyUviQXhwUgpaKdSo1ORbq6Q L5/4qavSweE8K31bOc2OWNzwQBdZoGquqhhspHoRGd4f976JAuzPpb3bOHXOezZNbXte/uN0c PnuVNMGOIXxaUhx1eits6evu8hesTDBP0YZVh6GGVGP58QviiXQSGrsNSOnn3bYF//hpybxoo tFcDM5oAchj22Slm9wpBeTrtnyVElj2SYVNKpFCETQU7V19h7ZAy/C5+vkOG0sdbT7ITQpQpP k+nqJMOAdyrwITTh9Zs1oOneDi31Rt3DHmOBd74tOmfUgQ7kuf2FU/WxxnUCbFsEyWtdmSOwz PdJsublY7CkeV3uCtJCMG9sTSRPHf/ui2Ko6nbZmcPNfyW0TS/gpu8RrYtbyVyrjeyNALEfwH E0+wnAehXqqoxrdeIHg+bzFNzZ+lz/03tE/X09M16kx8yTQqrhLS4IEsKGW6n873wegFAM0Zi Z6Df1DRGhoeD5xMPtMO7ag02DKFLnZSters6GDn9WUDve1qFBgPARj9AEFFHaHdHOwkS6NTCz Iv4teznMneinnT6P9QbQ== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 2ce91f88369b..96aafb659783 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]; };