From patchwork Mon Nov 11 20:38:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 179146 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp7166642ilf; Mon, 11 Nov 2019 12:38:51 -0800 (PST) X-Google-Smtp-Source: APXvYqzKuXqxTuFOAf3WDoEKdIMUUinGY5rJHnueBosvLgZM0QApArc/hWNxZccxIYqNkDRaf82F X-Received: by 2002:a17:906:b310:: with SMTP id n16mr24798610ejz.129.1573504731344; Mon, 11 Nov 2019 12:38:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573504731; cv=none; d=google.com; s=arc-20160816; b=UCMWqpwC4kfdQv6082vCsrluT3S0buFTLVdP6oFpBYbS3zMLsqz+5RSPFvbXgOBHmN 3stDnyRD7uL/eJPq/AvAK5nXwFwUILPYM7zPoDfupD/uiKK0ZfWVlJKqZb2jFh41oCFX jMUC7ygfeNZNVngIZUFkNIIwRdV96sboG/CdrctBQnQuDdAt7rCjerNa3Je8EoJJOQ4q uV/vEL1FcQbCeRBkjuFSioaS91hMybY9IaSx/bGY1NEamF014q6MWhxybUBUiSwaQCTz V0+Wdto3fgIz6mA7uf5dgMxVR3NO0yhkjQTLkPJJfOpTW10Gm6PYLkS1wDk26U968nE7 nepA== 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=FGnEuULmOQEosccT0MbJQIQkxw04fjuhnBMHKGgkags=; b=mz5RsCgY7dvuPvQwy8otTEX2MCAh3WwHp+lR7f7op2/gCULdVhX2pQ/Ua8BE4kaJ0C gxNtOjozauPfCKfhbl6i4Rw/zfY3L250jsKDCozm6GALXJ/MQHLA5TnBf5UoQZ7hzBUO Xnftoo91ko45o9fgpZpzO2R6GFEjQgkr8nyCvp9RwubGlbsbPvynNgIEb56uXBuG+4jK c7gIEETVcbHtka/asZd0nFgCSLigoQM46SKr4TTq+ZXr41nWB87qNM5PYrdklnD6JzUf cqkxDIy8na5PZ6xkPLI/4RO8BgqlyKBn/H8RCnlduIFqwAXDwx92Yi331P5YZs5fO3g4 tBKg== 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 f21si11876735edf.277.2019.11.11.12.38.51; Mon, 11 Nov 2019 12:38:51 -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 S1727493AbfKKUiq (ORCPT + 26 others); Mon, 11 Nov 2019 15:38:46 -0500 Received: from mout.kundenserver.de ([212.227.126.133]:49245 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726821AbfKKUip (ORCPT ); Mon, 11 Nov 2019 15:38:45 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue012 [212.227.15.129]) with ESMTPA (Nemesis) id 1MqqLB-1i7uDG1Fxp-00mv3t; Mon, 11 Nov 2019 21:38:39 +0100 From: Arnd Bergmann To: Mauro Carvalho Chehab , linux-media@vger.kernel.org Cc: Hans Verkuil , linux-kernel@vger.kernel.org, y2038@lists.linaro.org, Arnd Bergmann Subject: [PATCH v4 1/8] media: documentation: fix video_event description Date: Mon, 11 Nov 2019 21:38:28 +0100 Message-Id: <20191111203835.2260382-2-arnd@arndb.de> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20191111203835.2260382-1-arnd@arndb.de> References: <20191111203835.2260382-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:5zY86Zg2X7OpNRN+ymwONVDbgqel0wnkoWEwvm3mpfHV4abDbbv J4JgHP55At7vExyyNfizEhDB3c9UO7e5sChRli0Gskpb1Va8zPq209ZiJY8yAsD4IcxNBAc /K983IG/2HElRxP8bP9w9JzQHaiAwXnPOzDOgyl/DfiaDESZhezreYIJmNTBmJHuoolC0Gj JqY9KOwyRr7WYfJmnOWsA== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:WtBLRW8rGO0=:EJoxFI9//tF52eUhaE/+Ix Gz/ScRgBG4lUhddk/4of/+cdRpakodA7+uWeRf1VbRxW6hJS7UbcMU8Vs32qTHDE9vMp/IZXc Cuj56PjoewPgM36OjOSG62gggxztKsDpOdL3Cp0CvLp2spa9pD6mgkiaPKHApSrNatIa1fZdV lXUUg3796V+loZT6hoe7ibM8SSo646Zk5ED0gl+v09Wj3XHff5gjFcbOGjMIg8GL49h0aNN+Q vDTVu82yTXOoLoeBoPQXpBfm4lERWva1hUIsrTHDS64wo3M7QhAXESbFGDuh3D/jZWmKeYPpJ zYLOjHWxt8disX5RN0SK9E28L7gCY1t0cp5Z9+OkMw3eJXzYXL4IZ7g7ILYvU6PSDVYWkLZoh CzBhCKrsV7rwSDWuUZIrjQ7DIN/t/YZnh4n0gwDpZJLT1Qub+H6bBb+vfNNUDqxjVOymgXp1b +GFuQXyjsnUZxad1RxiES0+p3YSilykybiWA7woW1hG9WGqoa1MWaSQsYSZcJJsv/RoK7K296 N7CycwgcLB2S9QONQGcrzGgsAM0hgS7clZFy2Dw9yFyMEATWdpiCSZxGMrfSVBU1Y1wDnzTNL 0EdzljOVBJY1Vt1GYBoqURDQ/lbOk0vmhFDVrrqMPdOwK1XxsKGiscdTRjPDiNULpQmnTZ04m FPhg/AtXzv5EWQS8XUwDNY3PyovUpq+ZBs6E2En5inMdpodCtqYW9taXRK7+2CWDLXlwx2Yk4 A7dkQCF6mHKxxxXDQCJX3ZmgZkh4Cq4URKUkqe1X5soW0VMyExuVBtHvdeXYMQLAkDqJ863Pz 4ti67AysEwEH9KBu2HTCJ6kvO/pW/eeOGCsHDYtbUsxguvhHue42iH8h5IY9V+mTJeOB9x8qo XmIxbD+IXhMWMyoru8bw== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The type for the timestamp in video_event was changed to 'long' a long time ago, change the documentation to match. Signed-off-by: Arnd Bergmann --- Documentation/media/uapi/dvb/video-get-event.rst | 2 +- Documentation/media/uapi/dvb/video_types.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) -- 2.20.0 diff --git a/Documentation/media/uapi/dvb/video-get-event.rst b/Documentation/media/uapi/dvb/video-get-event.rst index def6c40db601..7f03fbe3d3b0 100644 --- a/Documentation/media/uapi/dvb/video-get-event.rst +++ b/Documentation/media/uapi/dvb/video-get-event.rst @@ -81,7 +81,7 @@ for this ioctl call. #define VIDEO_EVENT_FRAME_RATE_CHANGED 2 #define VIDEO_EVENT_DECODER_STOPPED 3 #define VIDEO_EVENT_VSYNC 4 - __kernel_time_t timestamp; + long timestamp; union { video_size_t size; unsigned int frame_rate; /* in frames per 1000sec */ diff --git a/Documentation/media/uapi/dvb/video_types.rst b/Documentation/media/uapi/dvb/video_types.rst index 479942ce6fb8..2697400ccf62 100644 --- a/Documentation/media/uapi/dvb/video_types.rst +++ b/Documentation/media/uapi/dvb/video_types.rst @@ -170,7 +170,7 @@ VIDEO_GET_EVENT call. #define VIDEO_EVENT_FRAME_RATE_CHANGED 2 #define VIDEO_EVENT_DECODER_STOPPED 3 #define VIDEO_EVENT_VSYNC 4 - __kernel_time_t timestamp; + long timestamp; union { video_size_t size; unsigned int frame_rate; /* in frames per 1000sec */ From patchwork Mon Nov 11 20:38:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 179149 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp7166676ilf; Mon, 11 Nov 2019 12:38:53 -0800 (PST) X-Google-Smtp-Source: APXvYqy3tfX1u8mxavgHHA4BaXtNfj2Qqhg73k7y32HPCmmTApk52zz8tlUa7yVmK1txLbl9ntLi X-Received: by 2002:a50:b536:: with SMTP id y51mr28758510edd.271.1573504732896; Mon, 11 Nov 2019 12:38:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573504732; cv=none; d=google.com; s=arc-20160816; b=r92hsXdolopPXgYT87qHcUiggzhHQElQQtQM45RYyQyxmgFiFPKXcFbYU/j5CbYm6R ClSeEbURXCb9r7I85vJ9kXAMpvln8rcIENg9rUBhNaZWuEmSD+VNRxTS4x+Kpxzoj/rp YlYKHkyTh10/npwfc7Ncm4Wl9FWAhsKzHsZVy+7JmW5PBeV0V8KZrZdbv3ezdzab6GrT B12BhgXk42M/NuiNzWZODZ2u51XW/FNV1qKkCSdljTp2EVk7bPnprjwjnjRCBmxCahRU e6o+h7RjZIWrdTU/GflQMCWkFpnqB4a4rcZYYESjIXdyTECwNQepL2ryApP2tnP/+ZXG N72Q== 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=yEQAnwK5Em5icwcCxuvCQMSgbExm3xK0GnbP+SQuzfQ=; b=RMa9u2Ax6RELcvW3fLR3ivojUdIUNn64O0RuXeslp6z6Iq6a+lneh3+3NcJXEc4iKl LlNjvkX8g481NvsMHouG3mT9lsKDIsmrqhnDuHUm3/y7jSo7ged3yT5zqIFgZ/REe6/l dnKRc3T9CMNtsNbqr2bDSuA/kg+CGKLgfrcWeA4cYq4egjjHeYq9CSYf3aWb/6fhxAXg PQPWuV7MZrDVdMMtXRqw2/dLyIP+rq9etAk3a9HWJzp/BonQOaAxNZDfyqekGLy6Pbq+ Z8czRC9zhILnw1nlXPLItpFb92v70aILV9gRE0Ez7QNaQOmG6OFlHm0683QlZ+cywir8 NDsQ== 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 f21si11876735edf.277.2019.11.11.12.38.52; Mon, 11 Nov 2019 12:38:52 -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 S1727715AbfKKUiu (ORCPT + 26 others); Mon, 11 Nov 2019 15:38:50 -0500 Received: from mout.kundenserver.de ([212.227.126.187]:40109 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727141AbfKKUir (ORCPT ); Mon, 11 Nov 2019 15:38:47 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue012 [212.227.15.129]) with ESMTPA (Nemesis) id 1MuVOM-1hdoC52AuQ-00rVLy; Mon, 11 Nov 2019 21:38:39 +0100 From: Arnd Bergmann To: Mauro Carvalho Chehab , linux-media@vger.kernel.org Cc: Hans Verkuil , linux-kernel@vger.kernel.org, y2038@lists.linaro.org, Arnd Bergmann Subject: [PATCH v4 2/8] media: v4l2: abstract timeval handling in v4l2_buffer Date: Mon, 11 Nov 2019 21:38:29 +0100 Message-Id: <20191111203835.2260382-3-arnd@arndb.de> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20191111203835.2260382-1-arnd@arndb.de> References: <20191111203835.2260382-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:fREgJFYS5c/Ce1W7NJCe9Mi1leEMqglZPNH2zLJm3ACCD5EBqSs DiL6D0tXQy9xsDvMw2UbMWERCHye/X7V/QBKvLXtgbThbxaPM65ILIHbsvqjp8UeWPKyMfr g3O9+Ntw04O76HB/+wLc4evlZ6yXJv7ZN72xutCJi9fOel6sy+DkxFe0VAe3+L8Qv8mjeJZ iL95JvK5GDI3sBO3ippaA== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:eT9LInbvktc=:Jolj81xjQfFEuAUz1T0pgn WBwkR2B98+FlnEbudPfejMmQ+EoXPolujBmtwk9Sx03GNgVSpI85MEoGP4h7JkyJlX9ajQzBz gVOHF2gGT/SeujFxAr3xegiDo0rKZTVn5lq9M/2UtTCrOoNLOi/r+9y0hIAn47enB/XmcC1RZ Iw6j7hJ5lvpzMJc0WAbUMCgOB0v3azL/nR6GNwXAdYJ8ydzAyvjRUux4WMStaVwxXiEI7rI/A scu4Mojmq+dGT33fBQch/BoYqW2cpELNEXuKPLVemYzZ50xTBr2eJKxESs+e2RMM+c9FczKwQ M9/rsuYdsPQPvNQcq4cOoLIvTTqy/4Yarb/xWkieox4TMnGMBR6dzNBC78xwo44+n4xK9hyJk 8tCIbmQT95pbiqhQdFcjcCkn65zwAhzVpMHH2tGsjO9AMs/VFylz32Ec652OZKA6P2lGvPgIR qrYCdkwOQRWqXPSV2FuKyTfl/QUCmW7HLBSHIV9xaRJaqKdhEUO9rSx8Wq8gouagsufitYi6X pk/9OxUEhOT+iA1LrE/XdKvq3KpQcjE7N54AOBWPQERa5aSuLhR30TRQoZSKHaXFKgwE4fjxH SaA5bGMQhzR+QUTnG3NjYlHavT/zl0YfPvZai+31edusW4QphO4ORHhcGDJ7PHxF8kvJ3/HUX u7F9UV4SqgupOpV4bGmg8kTxm++6CezNByp1rsCoyzD8i0s0dE+B8LjNdo+J7VWs/YLL/a7mG nipWylNb1dH7QIYK8UaXDejv0UnAqNFuph1UMWDpdaDWLvlcdOvVGPeeWa7PmGZeie6g9iq3L tfS6hA078F2gpILyFg0eEh/Eo+tgWw88j2nP4YPD356UQn9GDgA956yLkthr0I3+WdIYT2uxC kYD7WTBSacGM5m9EaLlQ== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 may be userspace code relying on it because it is part of the uapi header. Signed-off-by: Arnd Bergmann --- drivers/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 | 4 ++-- include/linux/videodev2.h | 17 ++++++++++++++++- include/trace/events/v4l2.h | 2 +- include/uapi/linux/videodev2.h | 2 ++ 9 files changed, 30 insertions(+), 13 deletions(-) -- 2.20.0 diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c index 5a9ba3846f0a..9ec710878db6 100644 --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c @@ -143,7 +143,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; @@ -476,7 +476,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 cdc66adda755..15a423c5deb7 100644 --- a/drivers/media/usb/usbvision/usbvision-video.c +++ b/drivers/media/usb/usbvision/usbvision-video.c @@ -687,7 +687,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; } @@ -756,7 +756,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..ab650371c151 100644 --- a/drivers/media/v4l2-core/videobuf-core.c +++ b/drivers/media/v4l2-core/videobuf-core.c @@ -364,7 +364,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 +578,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/linux/videodev2.h b/include/linux/videodev2.h index 16c0ed6c50a7..4086036e37d5 100644 --- a/include/linux/videodev2.h +++ b/include/linux/videodev2.h @@ -56,7 +56,22 @@ #ifndef __LINUX_VIDEODEV2_H #define __LINUX_VIDEODEV2_H -#include /* need struct timeval */ +#include #include +static inline u64 v4l2_buffer_get_timestamp(const struct v4l2_buffer *buf) +{ + 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 /* __LINUX_VIDEODEV2_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 530638dffd93..74d3d522f3db 100644 --- a/include/uapi/linux/videodev2.h +++ b/include/uapi/linux/videodev2.h @@ -1010,6 +1010,7 @@ struct v4l2_buffer { }; }; +#ifndef __KERNEL__ /** * v4l2_timeval_to_ns - Convert timeval to nanoseconds * @ts: pointer to the timeval variable to be converted @@ -1021,6 +1022,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 Nov 11 20:38:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 179153 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp7167138ilf; Mon, 11 Nov 2019 12:39:18 -0800 (PST) X-Google-Smtp-Source: APXvYqx07rKbNhd74FHaLmgb/AouXE9F5VMBzZj6n+QSSgjwDjk4AtjHfe+kQX49/npTMKvrwU7A X-Received: by 2002:aa7:cc95:: with SMTP id p21mr28525841edt.189.1573504757906; Mon, 11 Nov 2019 12:39:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573504757; cv=none; d=google.com; s=arc-20160816; b=cMfWmVuOckrsOYJrP/I2beI40iktj/GYbnarjwkraJJLNq032rjciNcBhafBEpgVZL 3OXYhWoq4sxZtxRKeMbn/ofqpT5HISXWXXbq6DWcn8JkYV67jZ+RlQMSUao1JbVD/Oik l3i/T9oo+NbMSYVjGMXCz4wyWFNrHpXjPZ117Dr08hfcv3EYWAS5cpOA9d4SHT+3q5VS sPrIu6sP7lFAgf5Rv78HXhRjcafPhIkRX2A89Zy+gt1gP8vH1cxLXqJzAJOTAZrwtxtZ pWWInhRLWpp+a7s4ORoJWbguyh7HnmVOPUBc66wgd7WdC2fnps8WWqsj4efL11pDyMsm GELA== 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=fePHKKsfOVuGXsKVpbjFMGrnfLohKJaEZUEnVUmAmVY=; b=fxrwaALU9wKn/OX7iO5DT0sC0/UyPy0HfcBaSIskw680omlth9d/PUtHVVLAixokWw v33l0Zwm6VP8Esd9MQYBw9yQ7BPid10sOwu2I6W2sb9FEcu7BfwQ/7GLjF0qevkVzRtR BGCVMcU89oTzSRtyIztJmc4fOOUA9XoMs2u8t6sfuygiQyffR/MpJShPq4DXHDWCY5Qo sb57VZffToU02fvB+g2XsWTfowE/T8hMootVjOMAEMUZHl5t82E6T/83S3zZ0c5GNFMZ e0Rt0R0AfpevzZS/sIZLXZx+CJPOuJkvSFrY2pBumNGIJYfodkWzpfUfn7umuBy3Jli3 9Igg== 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 dt11si10503561ejb.126.2019.11.11.12.39.17; Mon, 11 Nov 2019 12:39:17 -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 S1727824AbfKKUjO (ORCPT + 26 others); Mon, 11 Nov 2019 15:39:14 -0500 Received: from mout.kundenserver.de ([212.227.126.134]:40263 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727148AbfKKUir (ORCPT ); Mon, 11 Nov 2019 15:38:47 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue012 [212.227.15.129]) with ESMTPA (Nemesis) id 1MkW10-1i3DNJ3Bhm-00m72o; Mon, 11 Nov 2019 21:38:39 +0100 From: Arnd Bergmann To: Mauro Carvalho Chehab , linux-media@vger.kernel.org Cc: Hans Verkuil , linux-kernel@vger.kernel.org, y2038@lists.linaro.org, Arnd Bergmann , stable@vger.kernel.org Subject: [PATCH v4 3/8] media: v4l2-core: compat: ignore native command codes Date: Mon, 11 Nov 2019 21:38:30 +0100 Message-Id: <20191111203835.2260382-4-arnd@arndb.de> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20191111203835.2260382-1-arnd@arndb.de> References: <20191111203835.2260382-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:fyeBvHYA9suWzqScK8GDKBtHOFQfaGuN906I46P8WuU4UgsHsED O9Z+377jx/ildXJipI1UYlUnv8VxBay7m8TZyUZYo7Y6dN0vOdcSRaALeJRf4103+brNMGC BrirWitAGwTugaDjGCr4fsl+lLbHof06EhwDhR5bjvWS111KOatsutGVBfrnctONMqj0PKQ rigI8xvzIMOPdOKLAUrqA== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:mbS3DFtEDPA=:10ubdDeIlw7P7s2WSpM0/4 tRWavllTPGFdEGkvIErIRjWAQ6ADStXAQwDIG84GGSwhEjHKNEYGrtz0tk+NOhmJR13tbQyiu nuya9QuCwoWcF3IY1DrlTyniXj+unrt+c2q6V3iJ9R8QJRri+uPRCV/nbohUaM4n2YpSFdJVU IG0PrSf3OC5RnhH3GFjWhj0oxFjxcofpNHBLrxn+49ZcysmBVNyLm4GmvvRcpWVMZ90SldKw4 X+YlNahwwbKA9dvuL/6hf8hm4uLoinNsWRGTlsk1/mueCc6kc+U9g/xUnWcSIAVDs3SDDTSni v+lsKxodr6EFfhcKgaFwIKZKROVRpukVZV4H7T2jL9YJHXFRTdeudXv4h+Q4xUsRg6VFZSDNX kthInn4aM5VXsJXb2HjwjQVz7LTjh4PX0HfDIGXcDdy4JMR9u2avqGQkf3AbCprZpx0yyB2i+ zjzBeWA5c6yjM84lMElwfVUpSLJGAaM20GRoCnGFe1GIZMMJrwWeMHOq4RfCWscxnJjKxSY3r 2VBTRmR89o0zXCA+6iZGCmLGNf56AQ/CgJzaK/h0+tEWBCgMBdZsE3fLhu5+uJtP3mMjajm1b VsbUFUcZzZIZkKhYhwdLvE2OoGP+ct+ymnZisxwCurN/CpQ0R6HrpP5G5vVXJNZphC/DamzgX AeVLBIju/6oISQEuiDrPfMGN2ZxLYaizfo7lgCt27I59ewwUhvsGqDKXjx4KaVVO4HGXVoLVC /2xb6Ifrvc6DffbHEqtCsNydSPRSkeBHHVDekJGUoV3mDhcjtMH9fXnHa4IJxozroYoTKAPbQ 1/5khnK1ED4oPOfWgXgU2hWcvL4Ih5LLPvt17lUf3EePQBoIC/FvolzmsPain6v9bzsLkIuOq lCqIUFc22c+aej6YoSzw== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The do_video_ioctl() compat handler converts the compat command codes into the native ones before processing further, but this causes problems for 32-bit user applications that pass a command code that matches a 64-bit native number, which will then be handled the same way. Specifically, this breaks VIDIOC_DQEVENT_TIME from user space applications with 64-bit time_t, as the structure layout is the same as the native 64-bit layout on many architectures (x86 being the notable exception). Change the handler to use the converted command code only for passing into the native ioctl handler, not for deciding on the conversion, in order to make the compat behavior match the native behavior. Actual support for the 64-bit time_t version of VIDIOC_DQEVENT_TIME and other commands still needs to be added in a separate patch. Cc: stable@vger.kernel.org Signed-off-by: Arnd Bergmann --- drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 148 +++++++++--------- 1 file changed, 75 insertions(+), 73 deletions(-) -- 2.20.0 diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c index e1eaf1135c7f..7ad6db8dd9f6 100644 --- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c +++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c @@ -1183,36 +1183,38 @@ static long do_video_ioctl(struct file *file, unsigned int cmd, unsigned long ar u32 aux_space; int compatible_arg = 1; long err = 0; + unsigned int ncmd; /* * 1. When struct size is different, converts the command. */ switch (cmd) { - case VIDIOC_G_FMT32: cmd = VIDIOC_G_FMT; break; - case VIDIOC_S_FMT32: cmd = VIDIOC_S_FMT; break; - case VIDIOC_QUERYBUF32: cmd = VIDIOC_QUERYBUF; break; - case VIDIOC_G_FBUF32: cmd = VIDIOC_G_FBUF; break; - case VIDIOC_S_FBUF32: cmd = VIDIOC_S_FBUF; break; - case VIDIOC_QBUF32: cmd = VIDIOC_QBUF; break; - case VIDIOC_DQBUF32: cmd = VIDIOC_DQBUF; break; - case VIDIOC_ENUMSTD32: cmd = VIDIOC_ENUMSTD; break; - case VIDIOC_ENUMINPUT32: cmd = VIDIOC_ENUMINPUT; break; - case VIDIOC_TRY_FMT32: cmd = VIDIOC_TRY_FMT; break; - case VIDIOC_G_EXT_CTRLS32: cmd = VIDIOC_G_EXT_CTRLS; break; - case VIDIOC_S_EXT_CTRLS32: cmd = VIDIOC_S_EXT_CTRLS; break; - case VIDIOC_TRY_EXT_CTRLS32: cmd = VIDIOC_TRY_EXT_CTRLS; break; - case VIDIOC_DQEVENT32: cmd = VIDIOC_DQEVENT; break; - case VIDIOC_OVERLAY32: cmd = VIDIOC_OVERLAY; break; - case VIDIOC_STREAMON32: cmd = VIDIOC_STREAMON; break; - case VIDIOC_STREAMOFF32: cmd = VIDIOC_STREAMOFF; break; - case VIDIOC_G_INPUT32: cmd = VIDIOC_G_INPUT; break; - case VIDIOC_S_INPUT32: cmd = VIDIOC_S_INPUT; break; - case VIDIOC_G_OUTPUT32: cmd = VIDIOC_G_OUTPUT; break; - case VIDIOC_S_OUTPUT32: cmd = VIDIOC_S_OUTPUT; break; - case VIDIOC_CREATE_BUFS32: cmd = VIDIOC_CREATE_BUFS; break; - case VIDIOC_PREPARE_BUF32: cmd = VIDIOC_PREPARE_BUF; break; - case VIDIOC_G_EDID32: cmd = VIDIOC_G_EDID; break; - case VIDIOC_S_EDID32: cmd = VIDIOC_S_EDID; break; + case VIDIOC_G_FMT32: ncmd = VIDIOC_G_FMT; break; + case VIDIOC_S_FMT32: ncmd = VIDIOC_S_FMT; break; + case VIDIOC_QUERYBUF32: ncmd = VIDIOC_QUERYBUF; break; + case VIDIOC_G_FBUF32: ncmd = VIDIOC_G_FBUF; break; + case VIDIOC_S_FBUF32: ncmd = VIDIOC_S_FBUF; break; + case VIDIOC_QBUF32: ncmd = VIDIOC_QBUF; break; + case VIDIOC_DQBUF32: ncmd = VIDIOC_DQBUF; break; + case VIDIOC_ENUMSTD32: ncmd = VIDIOC_ENUMSTD; break; + case VIDIOC_ENUMINPUT32: ncmd = VIDIOC_ENUMINPUT; break; + case VIDIOC_TRY_FMT32: ncmd = VIDIOC_TRY_FMT; break; + case VIDIOC_G_EXT_CTRLS32: ncmd = VIDIOC_G_EXT_CTRLS; break; + case VIDIOC_S_EXT_CTRLS32: ncmd = VIDIOC_S_EXT_CTRLS; break; + case VIDIOC_TRY_EXT_CTRLS32: ncmd = VIDIOC_TRY_EXT_CTRLS; break; + case VIDIOC_DQEVENT32: ncmd = VIDIOC_DQEVENT; break; + case VIDIOC_OVERLAY32: ncmd = VIDIOC_OVERLAY; break; + case VIDIOC_STREAMON32: ncmd = VIDIOC_STREAMON; break; + case VIDIOC_STREAMOFF32: ncmd = VIDIOC_STREAMOFF; break; + case VIDIOC_G_INPUT32: ncmd = VIDIOC_G_INPUT; break; + case VIDIOC_S_INPUT32: ncmd = VIDIOC_S_INPUT; break; + case VIDIOC_G_OUTPUT32: ncmd = VIDIOC_G_OUTPUT; break; + case VIDIOC_S_OUTPUT32: ncmd = VIDIOC_S_OUTPUT; break; + case VIDIOC_CREATE_BUFS32: ncmd = VIDIOC_CREATE_BUFS; break; + case VIDIOC_PREPARE_BUF32: ncmd = VIDIOC_PREPARE_BUF; break; + case VIDIOC_G_EDID32: ncmd = VIDIOC_G_EDID; break; + case VIDIOC_S_EDID32: ncmd = VIDIOC_S_EDID; break; + default: ncmd = cmd; break; } /* @@ -1221,11 +1223,11 @@ static long do_video_ioctl(struct file *file, unsigned int cmd, unsigned long ar * argument into it. */ switch (cmd) { - case VIDIOC_OVERLAY: - case VIDIOC_STREAMON: - case VIDIOC_STREAMOFF: - case VIDIOC_S_INPUT: - case VIDIOC_S_OUTPUT: + case VIDIOC_OVERLAY32: + case VIDIOC_STREAMON32: + case VIDIOC_STREAMOFF32: + case VIDIOC_S_INPUT32: + case VIDIOC_S_OUTPUT32: err = alloc_userspace(sizeof(unsigned int), 0, &new_p64); if (!err && assign_in_user((unsigned int __user *)new_p64, (compat_uint_t __user *)p32)) @@ -1233,23 +1235,23 @@ static long do_video_ioctl(struct file *file, unsigned int cmd, unsigned long ar compatible_arg = 0; break; - case VIDIOC_G_INPUT: - case VIDIOC_G_OUTPUT: + case VIDIOC_G_INPUT32: + case VIDIOC_G_OUTPUT32: err = alloc_userspace(sizeof(unsigned int), 0, &new_p64); compatible_arg = 0; break; - case VIDIOC_G_EDID: - case VIDIOC_S_EDID: + case VIDIOC_G_EDID32: + case VIDIOC_S_EDID32: err = alloc_userspace(sizeof(struct v4l2_edid), 0, &new_p64); if (!err) err = get_v4l2_edid32(new_p64, p32); compatible_arg = 0; break; - case VIDIOC_G_FMT: - case VIDIOC_S_FMT: - case VIDIOC_TRY_FMT: + case VIDIOC_G_FMT32: + case VIDIOC_S_FMT32: + case VIDIOC_TRY_FMT32: err = bufsize_v4l2_format(p32, &aux_space); if (!err) err = alloc_userspace(sizeof(struct v4l2_format), @@ -1262,7 +1264,7 @@ static long do_video_ioctl(struct file *file, unsigned int cmd, unsigned long ar compatible_arg = 0; break; - case VIDIOC_CREATE_BUFS: + case VIDIOC_CREATE_BUFS32: err = bufsize_v4l2_create(p32, &aux_space); if (!err) err = alloc_userspace(sizeof(struct v4l2_create_buffers), @@ -1275,10 +1277,10 @@ static long do_video_ioctl(struct file *file, unsigned int cmd, unsigned long ar compatible_arg = 0; break; - case VIDIOC_PREPARE_BUF: - case VIDIOC_QUERYBUF: - case VIDIOC_QBUF: - case VIDIOC_DQBUF: + case VIDIOC_PREPARE_BUF32: + case VIDIOC_QUERYBUF32: + case VIDIOC_QBUF32: + case VIDIOC_DQBUF32: err = bufsize_v4l2_buffer(p32, &aux_space); if (!err) err = alloc_userspace(sizeof(struct v4l2_buffer), @@ -1291,7 +1293,7 @@ static long do_video_ioctl(struct file *file, unsigned int cmd, unsigned long ar compatible_arg = 0; break; - case VIDIOC_S_FBUF: + case VIDIOC_S_FBUF32: err = alloc_userspace(sizeof(struct v4l2_framebuffer), 0, &new_p64); if (!err) @@ -1299,13 +1301,13 @@ static long do_video_ioctl(struct file *file, unsigned int cmd, unsigned long ar compatible_arg = 0; break; - case VIDIOC_G_FBUF: + case VIDIOC_G_FBUF32: err = alloc_userspace(sizeof(struct v4l2_framebuffer), 0, &new_p64); compatible_arg = 0; break; - case VIDIOC_ENUMSTD: + case VIDIOC_ENUMSTD32: err = alloc_userspace(sizeof(struct v4l2_standard), 0, &new_p64); if (!err) @@ -1313,16 +1315,16 @@ static long do_video_ioctl(struct file *file, unsigned int cmd, unsigned long ar compatible_arg = 0; break; - case VIDIOC_ENUMINPUT: + case VIDIOC_ENUMINPUT32: err = alloc_userspace(sizeof(struct v4l2_input), 0, &new_p64); if (!err) err = get_v4l2_input32(new_p64, p32); compatible_arg = 0; break; - case VIDIOC_G_EXT_CTRLS: - case VIDIOC_S_EXT_CTRLS: - case VIDIOC_TRY_EXT_CTRLS: + case VIDIOC_G_EXT_CTRLS32: + case VIDIOC_S_EXT_CTRLS32: + case VIDIOC_TRY_EXT_CTRLS32: err = bufsize_v4l2_ext_controls(p32, &aux_space); if (!err) err = alloc_userspace(sizeof(struct v4l2_ext_controls), @@ -1334,7 +1336,7 @@ static long do_video_ioctl(struct file *file, unsigned int cmd, unsigned long ar } compatible_arg = 0; break; - case VIDIOC_DQEVENT: + case VIDIOC_DQEVENT32: err = alloc_userspace(sizeof(struct v4l2_event), 0, &new_p64); compatible_arg = 0; break; @@ -1352,9 +1354,9 @@ static long do_video_ioctl(struct file *file, unsigned int cmd, unsigned long ar * Otherwise, it will pass the newly allocated @new_p64 argument. */ if (compatible_arg) - err = native_ioctl(file, cmd, (unsigned long)p32); + err = native_ioctl(file, ncmd, (unsigned long)p32); else - err = native_ioctl(file, cmd, (unsigned long)new_p64); + err = native_ioctl(file, ncmd, (unsigned long)new_p64); if (err == -ENOTTY) return err; @@ -1370,13 +1372,13 @@ static long do_video_ioctl(struct file *file, unsigned int cmd, unsigned long ar * the blocks to maximum allowed value. */ switch (cmd) { - case VIDIOC_G_EXT_CTRLS: - case VIDIOC_S_EXT_CTRLS: - case VIDIOC_TRY_EXT_CTRLS: + case VIDIOC_G_EXT_CTRLS32: + case VIDIOC_S_EXT_CTRLS32: + case VIDIOC_TRY_EXT_CTRLS32: if (put_v4l2_ext_controls32(file, new_p64, p32)) err = -EFAULT; break; - case VIDIOC_S_EDID: + case VIDIOC_S_EDID32: if (put_v4l2_edid32(new_p64, p32)) err = -EFAULT; break; @@ -1389,49 +1391,49 @@ static long do_video_ioctl(struct file *file, unsigned int cmd, unsigned long ar * the original 32 bits structure. */ switch (cmd) { - case VIDIOC_S_INPUT: - case VIDIOC_S_OUTPUT: - case VIDIOC_G_INPUT: - case VIDIOC_G_OUTPUT: + case VIDIOC_S_INPUT32: + case VIDIOC_S_OUTPUT32: + case VIDIOC_G_INPUT32: + case VIDIOC_G_OUTPUT32: if (assign_in_user((compat_uint_t __user *)p32, ((unsigned int __user *)new_p64))) err = -EFAULT; break; - case VIDIOC_G_FBUF: + case VIDIOC_G_FBUF32: err = put_v4l2_framebuffer32(new_p64, p32); break; - case VIDIOC_DQEVENT: + case VIDIOC_DQEVENT32: err = put_v4l2_event32(new_p64, p32); break; - case VIDIOC_G_EDID: + case VIDIOC_G_EDID32: err = put_v4l2_edid32(new_p64, p32); break; - case VIDIOC_G_FMT: - case VIDIOC_S_FMT: - case VIDIOC_TRY_FMT: + case VIDIOC_G_FMT32: + case VIDIOC_S_FMT32: + case VIDIOC_TRY_FMT32: err = put_v4l2_format32(new_p64, p32); break; - case VIDIOC_CREATE_BUFS: + case VIDIOC_CREATE_BUFS32: err = put_v4l2_create32(new_p64, p32); break; - case VIDIOC_PREPARE_BUF: - case VIDIOC_QUERYBUF: - case VIDIOC_QBUF: - case VIDIOC_DQBUF: + case VIDIOC_PREPARE_BUF32: + case VIDIOC_QUERYBUF32: + case VIDIOC_QBUF32: + case VIDIOC_DQBUF32: err = put_v4l2_buffer32(new_p64, p32); break; - case VIDIOC_ENUMSTD: + case VIDIOC_ENUMSTD32: err = put_v4l2_standard32(new_p64, p32); break; - case VIDIOC_ENUMINPUT: + case VIDIOC_ENUMINPUT32: err = put_v4l2_input32(new_p64, p32); break; } From patchwork Mon Nov 11 20:38:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 179148 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp7166669ilf; Mon, 11 Nov 2019 12:38:52 -0800 (PST) X-Google-Smtp-Source: APXvYqwLoYjdNgnqoi4wGlbI3y5YGcO5+TQppuWXvq5QzDK/zk0sWBWS2RVU/w1mWyG615av47Dt X-Received: by 2002:a17:906:b310:: with SMTP id n16mr24798676ejz.129.1573504732378; Mon, 11 Nov 2019 12:38:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573504732; cv=none; d=google.com; s=arc-20160816; b=FR4TGigqgHT2pvCjduXW9R3oSa0ZZp8Qfvp2znjCp7MQKXCyGuh4mzudIo3PeS7Cxc Hm1mUqTRxozgXsKLu9V0fhBzgbnoRIBX9d0BephTfDwmhxFSnbX400xWYdH63C5FcgkL rMPJqNzP84A8msjlxwQv43+3+Mfkk6AnmmJAiDGEuAjZVkrs9e4YRGU3K/hautyzzlVo /c85TbiInd8N2Ot69Q6eUzvGRKwwht3eiVybFOQB6ey0bCTKpcxugfbS6QvkM8ws928e epzL2nxJi2vu91SIMe3AUw7nWRKfIqe1jGe8pWmI8LnZaMKqJ3+ZJBxl7ULZcVOgeMCH P0JA== 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=4S7kMddrI4paBaAiJDAbf20WVQ5SQXzc2A4o/uVM+2o=; b=g8R4/7NU6feXDvLZCwR49XXIke7T5OMvD0Jttcd9ksbEQn1F1Y0LXAUcZkBFNiA7AK A/ezfp9EOpDhRP/YFBTYox5c2Hzx1ZmfKUXBwR1OYvh+nniqXWv4BAmpfCTiwWSo55LN YUjfb3Ztl3wga3lWWTwj18kfrPorJ14RdkUW9VTit3C3XjRq0HYs65VHyU8Un4ZksGg8 2sUZ4WEzdNTYLdnM+lgb/h1a4fVfqZ3hpoRSogFMj6PUvo0Ji3friW78RMLMQynFicbM v86t5nyNYDx59bY8l+GQkfKPjmuPEZgk5fOP4a93vQrI1NZn3qWUs5jOsqnvdb7Aaqv1 Pl9A== 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 f21si11876735edf.277.2019.11.11.12.38.52; Mon, 11 Nov 2019 12:38:52 -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 S1727671AbfKKUit (ORCPT + 26 others); Mon, 11 Nov 2019 15:38:49 -0500 Received: from mout.kundenserver.de ([212.227.126.134]:34037 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726821AbfKKUir (ORCPT ); Mon, 11 Nov 2019 15:38:47 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue012 [212.227.15.129]) with ESMTPA (Nemesis) id 1MJnnV-1iA8D31y9p-00K6g9; Mon, 11 Nov 2019 21:38:40 +0100 From: Arnd Bergmann To: Mauro Carvalho Chehab , linux-media@vger.kernel.org Cc: Hans Verkuil , linux-kernel@vger.kernel.org, y2038@lists.linaro.org, Arnd Bergmann Subject: [PATCH v4 6/8] media: v4l2-core: fix v4l2_buffer handling for time64 ABI Date: Mon, 11 Nov 2019 21:38:33 +0100 Message-Id: <20191111203835.2260382-7-arnd@arndb.de> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20191111203835.2260382-1-arnd@arndb.de> References: <20191111203835.2260382-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:M1IfWaVaREKKeSz6uZH9ktXwRHw1ujJdLSY2ajzwuEYJ7PT3uRC ib07toNSyFHa1ozOzOE/JBz73Wxu0UJ4g2qiUX+h/mTnOsY4qbfvw3CN4W/rQrTeh51WMtv GPxFrVCqyQe+0+0wSXUkyk4fcsxXdmAmgWXD7WN3gtmjYDZkSeofpE8wIFfj9QMhKJmWb2s BPKl+uGfl7dhbUJUtDH0g== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:s/dp7Rx2RE8=:gaNGbh/OKM6aK4OqiXrUef DIEk1T73JiE5BlU8+f9oGphJ2slm8s0zFN8HOGkOgDfPIx+p9gBeFe9xExg8Sud/hhLFOoxTL FQecDWbNQxuF0NOuVSv5qUQZfr3cMcizwEpMt+OVsfvKbH+NxbwMw/KJHOMYEDnv6JLfcy2mE vg2ZrA5Kd9Bzzc3vG3lUOfClFw+PUdSD+jd+oHksQy0VxM6S2PcYiGZx2JUAVlFLOx+uBYkb0 rewE1sFVK2xbj87VUKxDrFNZx5D5L0WuePTf3vqwwn3r+sux3s1QF0bAkW0YCeU3qtFaZOxce EWGX4UG8YH6wEzKtR9SinrMGiu5A2y1BMpW2J6w8NGC3h+MFk31qA7UUEtgh5/8OjcAaO+/Cw Hm/e0SkQLvzVgJbQtsDC/dlY4CXD204xKccMEJ4Oe0sZ1zkJjr3l9Y3tlhwH9c0DeywLIYIDI M/LCuXdthurfPoKgS3dRYA7X/1TcOxVqn5h6y6CHCni3Lh6m/MvbhWFr+3TM7SQzQZygvrD8p HKfmMfydCRR8AvAqY6bcSIbzuJphxns3iLrydRiUOfKskIKNpnY1fKWEf1c9JrKMuIw5IG9iR NaNFgbdhvz1NYuDIkEGL5bPpsJ685ZoOsUqWKXGugn8eL29YV5gClhLQ+Ctlk5BsVG9+yMWqV h1CoLD9y+TAEueNj9IZnnkOv9NORPb1vuzp9W2J220JpcN8/lbtqMFrO5FJz7/ZcA2wg2rWKA 2GPheux3i1UNxPbl+DeDjo0OI6UEun+6xow5lPIjrpkzrXV3DMEfu+UYGM+8Em1Ilim507ujr jyCMSK6LgIyHPzqkOiXYESaib0etsSlAJJb1+XbOudB0EO8K893iAp1yLacPYo7gaS6L19H3g fmDXjtjs/qD7a0HyM+hA== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The v4l2_buffer structure contains a 'struct timeval' member that is defined by the user space C library, creating an ABI incompatibility when that gets updated to a 64-bit time_t. As in v4l2_event, handle this with a special case in video_put_user() and video_get_user() to replace the memcpy there. Since the structure also contains a pointer, there are now two native versions (on 32-bit systems) as well as two compat versions (on 64-bit systems), which unfortunately complicates the compat handler quite a bit. Duplicating the existing handlers for the new types is a safe conversion for now, but unfortunately this may turn into a maintenance burden later. A larger-scale rework of the compat code might be a better alternative, but is out of scope of the y2038 work. Sparc64 needs a special case because of their special suseconds_t definition. Signed-off-by: Arnd Bergmann --- drivers/media/v4l2-core/v4l2-ioctl.c | 57 ++++++++++++++++++++++++++-- include/uapi/linux/videodev2.h | 45 ++++++++++++++++++++++ 2 files changed, 98 insertions(+), 4 deletions(-) -- 2.20.0 diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c index 1de939d11628..4ae1bcaec3fa 100644 --- a/drivers/media/v4l2-core/v4l2-ioctl.c +++ b/drivers/media/v4l2-core/v4l2-ioctl.c @@ -474,10 +474,10 @@ static void v4l_print_buffer(const void *arg, bool write_only) const struct v4l2_plane *plane; int i; - pr_cont("%02ld:%02d:%02d.%08ld index=%d, type=%s, request_fd=%d, flags=0x%08x, field=%s, sequence=%d, memory=%s", - p->timestamp.tv_sec / 3600, - (int)(p->timestamp.tv_sec / 60) % 60, - (int)(p->timestamp.tv_sec % 60), + pr_cont("%02d:%02d:%02d.%09ld index=%d, type=%s, request_fd=%d, flags=0x%08x, field=%s, sequence=%d, memory=%s", + (int)p->timestamp.tv_sec / 3600, + ((int)p->timestamp.tv_sec / 60) % 60, + ((int)p->timestamp.tv_sec % 60), (long)p->timestamp.tv_usec, p->index, prt_names(p->type, v4l2_type_names), p->request_fd, @@ -3014,6 +3014,14 @@ static unsigned int video_translate_cmd(unsigned int cmd) #ifdef CONFIG_COMPAT_32BIT_TIME case VIDIOC_DQEVENT_TIME32: return VIDIOC_DQEVENT; + case VIDIOC_QUERYBUF_TIME32: + return VIDIOC_QUERYBUF; + case VIDIOC_QBUF_TIME32: + return VIDIOC_QBUF; + case VIDIOC_DQBUF_TIME32: + return VIDIOC_DQBUF; + case VIDIOC_PREPARE_BUF_TIME32: + return VIDIOC_PREPARE_BUF; #endif } @@ -3032,6 +3040,30 @@ static int video_get_user(void __user *arg, void *parg, unsigned int cmd, } switch (cmd) { +#ifdef COMPAT_32BIT_TIME + case VIDIOC_QUERYBUF_TIME32: + case VIDIOC_QBUF_TIME32: + case VIDIOC_DQBUF_TIME32: + case VIDIOC_PREPARE_BUF_TIME32: { + struct v4l2_buffer_time32 vb32; + struct v4l2_buffer *vb = parg; + + if (copy_from_user(&vb32, arg, sizeof(vb32))) + return -EFAULT; + + memcpy(vb, &vb32, offsetof(struct v4l2_buffer, timestamp)); + vb->timestamp.tv_sec = vb32.timestamp.tv_sec; + vb->timestamp.tv_usec = vb32.timestamp.tv_usec; + memcpy(&vb->timecode, &vb32.timecode, + sizeof(*vb) - offsetof(struct v4l2_buffer, timecode)); + + if (cmd == VIDIOC_QUERYBUF_TIME32) + memset(&vb->length, 0, sizeof(*vb) - + offsetof(struct v4l2_buffer, length)); + + break; + } +#endif default: /* * In some cases, only a few fields are used as input, @@ -3080,6 +3112,23 @@ static int video_put_user(void __user *arg, void *parg, unsigned int cmd) return -EFAULT; break; } + case VIDIOC_QUERYBUF_TIME32: + case VIDIOC_QBUF_TIME32: + case VIDIOC_DQBUF_TIME32: + case VIDIOC_PREPARE_BUF_TIME32: { + struct v4l2_buffer_time32 vb32; + struct v4l2_buffer *vb = parg; + + memcpy(&vb32, vb, offsetof(struct v4l2_buffer, timestamp)); + vb32.timestamp.tv_sec = vb->timestamp.tv_sec; + vb32.timestamp.tv_usec = vb->timestamp.tv_usec; + memcpy(&vb32.timecode, &vb->timecode, + sizeof(*vb) - offsetof(struct v4l2_buffer, timecode)); + + if (copy_to_user(arg, &vb32, sizeof(vb32))) + return -EFAULT; + break; + } #endif default: /* Copy results into user buffer */ diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h index 1d2553d4ed5b..f05c54d63f96 100644 --- a/include/uapi/linux/videodev2.h +++ b/include/uapi/linux/videodev2.h @@ -990,7 +990,47 @@ struct v4l2_buffer { __u32 bytesused; __u32 flags; __u32 field; +#ifdef __KERNEL__ + /* match glibc timeval64 format */ + struct { + long long tv_sec; +# if defined(__sparc__) && defined(__arch64__) + int tv_usec; + int __pad; +# else + long long tv_usec; +# endif + } timestamp; +#else struct timeval timestamp; +#endif + struct v4l2_timecode timecode; + __u32 sequence; + + /* memory location */ + __u32 memory; + union { + __u32 offset; + unsigned long userptr; + struct v4l2_plane *planes; + __s32 fd; + } m; + __u32 length; + __u32 reserved2; + union { + __s32 request_fd; + __u32 reserved; + }; +}; + +#ifdef __KERNEL__ +struct v4l2_buffer_time32 { + __u32 index; + __u32 type; + __u32 bytesused; + __u32 flags; + __u32 field; + struct old_timeval32 timestamp; struct v4l2_timecode timecode; __u32 sequence; @@ -1009,6 +1049,7 @@ struct v4l2_buffer { __u32 reserved; }; }; +#endif #ifndef __KERNEL__ /** @@ -2446,12 +2487,15 @@ struct v4l2_create_buffers { #define VIDIOC_S_FMT _IOWR('V', 5, struct v4l2_format) #define VIDIOC_REQBUFS _IOWR('V', 8, struct v4l2_requestbuffers) #define VIDIOC_QUERYBUF _IOWR('V', 9, struct v4l2_buffer) +#define VIDIOC_QUERYBUF_TIME32 _IOWR('V', 9, struct v4l2_buffer_time32) #define VIDIOC_G_FBUF _IOR('V', 10, struct v4l2_framebuffer) #define VIDIOC_S_FBUF _IOW('V', 11, struct v4l2_framebuffer) #define VIDIOC_OVERLAY _IOW('V', 14, int) #define VIDIOC_QBUF _IOWR('V', 15, struct v4l2_buffer) +#define VIDIOC_QBUF_TIME32 _IOWR('V', 15, struct v4l2_buffer_time32) #define VIDIOC_EXPBUF _IOWR('V', 16, struct v4l2_exportbuffer) #define VIDIOC_DQBUF _IOWR('V', 17, struct v4l2_buffer) +#define VIDIOC_DQBUF_TIME32 _IOWR('V', 17, struct v4l2_buffer_time32) #define VIDIOC_STREAMON _IOW('V', 18, int) #define VIDIOC_STREAMOFF _IOW('V', 19, int) #define VIDIOC_G_PARM _IOWR('V', 21, struct v4l2_streamparm) @@ -2520,6 +2564,7 @@ struct v4l2_create_buffers { #define VIDIOC_UNSUBSCRIBE_EVENT _IOW('V', 91, struct v4l2_event_subscription) #define VIDIOC_CREATE_BUFS _IOWR('V', 92, struct v4l2_create_buffers) #define VIDIOC_PREPARE_BUF _IOWR('V', 93, struct v4l2_buffer) +#define VIDIOC_PREPARE_BUF_TIME32 _IOWR('V', 93, struct v4l2_buffer_time32) #define VIDIOC_G_SELECTION _IOWR('V', 94, struct v4l2_selection) #define VIDIOC_S_SELECTION _IOWR('V', 95, struct v4l2_selection) #define VIDIOC_DECODER_CMD _IOWR('V', 96, struct v4l2_decoder_cmd)