From patchwork Thu Dec 7 18:13:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepa Dinamani X-Patchwork-Id: 10100761 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 20DA0602BF for ; Thu, 7 Dec 2017 18:14:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 17C6E285A7 for ; Thu, 7 Dec 2017 18:14:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0C9E2285B9; Thu, 7 Dec 2017 18:14:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 26775285B0 for ; Thu, 7 Dec 2017 18:14:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753051AbdLGSNo (ORCPT ); Thu, 7 Dec 2017 13:13:44 -0500 Received: from mail-pg0-f66.google.com ([74.125.83.66]:42977 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754219AbdLGSNV (ORCPT ); Thu, 7 Dec 2017 13:13:21 -0500 Received: by mail-pg0-f66.google.com with SMTP id e14so5003125pgr.9; Thu, 07 Dec 2017 10:13:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=xyh3U1rJzNN8eHbbahrUi5j8MJa5N424fug5P/JbYBc=; b=KOB+dg5w7AJqMGIWNOfhA8wKZ4Wf/+kdaC01vBBPjRcqgz6cHEOvX/fOFsYPQWuL84 gukFJA3ngCtc+eto4RP1Ou77QrLQ0Ym+wNxTCj4VCwvZo/L2GgjE9OmNgPxmQ+Pr3NYU tGsIPEVh8UeLRr8dBy9PikQ2YSFz+2VQ3k+wkTCkb0mKEd4gh0eZzK4nIELWQPqeWmjp DkS7bnCghJcA9UmMAAXwjVPIK25zVKVSP0zRUuy6ASjw/wAe/yZxmV5aYzjFaBih28cH Il8Gm4jOKRJ9UrrKDn5jD9bhzU+GR4TMAXJpCEjPIsCkIhf887UClb41IhA4s5pCBZ9b qgSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=xyh3U1rJzNN8eHbbahrUi5j8MJa5N424fug5P/JbYBc=; b=NgDjz37+bfIynsLh+ToUfu4z8EGDrPxJGnAGKK4Gbuhys/zuVtt4N0bav0eGsNTD2z 0EuQ44yyybiaoAbN/TcXDrJ1o7rLl9JpnbRShyo1i73rFY6WOJDxgNS1P1NFN3d8BNIB mfJIavlSecrxGIKPQmKyOd5rbtNY+6F++a1xtL2wZr8sULKCheIhdw2GrVl1gf/xdXE/ c39xmQYWh7ZbvuwLnFMny7IlBpHvDu+DnhGIvG1ZB6BBPacjBp7d9yxca9VVObDlJywV nTQFkjEVrOnQHWk49qQ9SKS7eiSS13SYB+FeRs21rkoOKYzEfgKFMAifvBAczXFKBlDO W03g== X-Gm-Message-State: AJaThX5c+nT6LC7NVrB69WE+Qf8t5AmO7hqhRTIu5c9mArXWJH/jOfcE t+N/LAgHu2M6myP+F5nKq3s= X-Google-Smtp-Source: AGs4zMYwtoyKKEVx+FfPTqWNI2OCatsHu260s8i7wxSTRVAxG8HwJ8BpMNoZjTpKgtNU6Y20116a0g== X-Received: by 10.99.95.70 with SMTP id t67mr26342172pgb.49.1512670400994; Thu, 07 Dec 2017 10:13:20 -0800 (PST) Received: from deepa-ubuntu.hsd1.ca.comcast.net ([2601:647:5000:6620:8c9c:e0f7:c7ba:c1de]) by smtp.gmail.com with ESMTPSA id t202sm8634299pgb.75.2017.12.07.10.13.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Dec 2017 10:13:20 -0800 (PST) From: Deepa Dinamani To: dmitry.torokhov@gmail.com, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Cc: peter.hutterer@who-t.net, arnd@arndb.de, y2038@lists.linaro.org Subject: [PATCH v4 3/4] input: Deprecate real timestamps beyond year 2106 Date: Thu, 7 Dec 2017 10:13:05 -0800 Message-Id: <20171207181306.5623-4-deepa.kernel@gmail.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171207181306.5623-1-deepa.kernel@gmail.com> References: <20171207181306.5623-1-deepa.kernel@gmail.com> Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP struct timeval is not y2038 safe. All usage of timeval in the kernel will be replaced by y2038 safe structures. The change is also necessary as glibc is introducing support for 32 bit applications to use 64 bit time_t. Without this change, many applications would incorrectly interpret values in the struct input_event. More details about glibc at https://sourceware.org/glibc/wiki/Y2038ProofnessDesign . struct input_event maintains time for each input event. Real time timestamps are not ideal for input as this time can go backwards as noted in the patch a80b83b7b8 by John Stultz. Hence, having the input_event.time fields only big enough for monotonic and boot times are sufficient. The change leaves the representation of struct input_event as is on 64 bit architectures. But uses 2 unsigned long values on 32 bit machines to support real timestamps until year 2106. This intentionally breaks the ABI on 32 bit architectures and compat handling on 64 bit architectures. This is as per maintainer's preference to introduce compile time errors rather than run into runtime incompatibilities. The change requires any 32 bit userspace utilities reading or writing from event nodes to update their reading format to match the new input_event. The changes to the popular libraries will be posted once we agree on the kernel change. Suggested-by: Arnd Bergmann Signed-off-by: Deepa Dinamani --- drivers/input/evdev.c | 14 ++++++++------ drivers/input/input-compat.c | 11 ++++++----- drivers/input/input-compat.h | 3 ++- drivers/input/misc/uinput.c | 4 ++-- include/uapi/linux/input.h | 12 +++++++++++- 5 files changed, 29 insertions(+), 15 deletions(-) diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c index e5dbfc5ff1b0..6172af6476c0 100644 --- a/drivers/input/evdev.c +++ b/drivers/input/evdev.c @@ -135,7 +135,8 @@ static void __evdev_flush_queue(struct evdev_client *client, unsigned int type) continue; } else if (head != i) { /* move entry to fill the gap */ - client->buffer[head].time = ev->time; + client->buffer[head].input_event_sec = ev->input_event_sec; + client->buffer[head].input_event_usec = ev->input_event_usec; client->buffer[head].type = ev->type; client->buffer[head].code = ev->code; client->buffer[head].value = ev->value; @@ -170,8 +171,8 @@ static void __evdev_queue_syn_dropped(struct evdev_client *client) break; } - ev.time.tv_sec = ts.tv_sec; - ev.time.tv_usec = ts.tv_nsec / NSEC_PER_USEC; + ev.input_event_sec = ts.tv_sec; + ev.input_event_usec = ts.tv_nsec / NSEC_PER_USEC; ev.type = EV_SYN; ev.code = SYN_DROPPED; ev.value = 0; @@ -248,7 +249,8 @@ static void __pass_event(struct evdev_client *client, */ client->tail = (client->head - 2) & (client->bufsize - 1); - client->buffer[client->tail].time = event->time; + client->buffer[client->tail].input_event_sec = event->input_event_sec; + client->buffer[client->tail].input_event_usec = event->input_event_usec; client->buffer[client->tail].type = EV_SYN; client->buffer[client->tail].code = SYN_DROPPED; client->buffer[client->tail].value = 0; @@ -276,8 +278,8 @@ static void evdev_pass_values(struct evdev_client *client, return; ts = ev_time[client->clk_type]; - event.time.tv_sec = ts.tv_sec; - event.time.tv_usec = ts.tv_nsec / NSEC_PER_USEC; + event.input_event_sec = ts.tv_sec; + event.input_event_usec = ts.tv_nsec / NSEC_PER_USEC; /* Interrupts are disabled, just acquire the lock. */ spin_lock(&client->buffer_lock); diff --git a/drivers/input/input-compat.c b/drivers/input/input-compat.c index 2186f71c9fe5..419e40b68486 100644 --- a/drivers/input/input-compat.c +++ b/drivers/input/input-compat.c @@ -24,14 +24,15 @@ int input_event_from_user(const char __user *buffer, sizeof(struct input_event_compat))) return -EFAULT; - event->time.tv_sec = compat_event.time.tv_sec; - event->time.tv_usec = compat_event.time.tv_usec; + event->input_event_sec = compat_event.sec; + event->input_event_usec = compat_event.usec; event->type = compat_event.type; event->code = compat_event.code; event->value = compat_event.value; } else { - if (copy_from_user(event, buffer, sizeof(struct input_event))) + if (copy_from_user(event, buffer, + sizeof(struct input_event))) return -EFAULT; } @@ -44,8 +45,8 @@ int input_event_to_user(char __user *buffer, if (in_compat_syscall() && !COMPAT_USE_64BIT_TIME) { struct input_event_compat compat_event; - compat_event.time.tv_sec = event->time.tv_sec; - compat_event.time.tv_usec = event->time.tv_usec; + compat_event.sec = event->input_event_sec; + compat_event.usec = event->input_event_usec; compat_event.type = event->type; compat_event.code = event->code; compat_event.value = event->value; diff --git a/drivers/input/input-compat.h b/drivers/input/input-compat.h index 1563160a7af3..08cd755e73fd 100644 --- a/drivers/input/input-compat.h +++ b/drivers/input/input-compat.h @@ -18,7 +18,8 @@ #ifdef CONFIG_COMPAT struct input_event_compat { - struct compat_timeval time; + compat_ulong_t sec; + compat_ulong_t usec; __u16 type; __u16 code; __s32 value; diff --git a/drivers/input/misc/uinput.c b/drivers/input/misc/uinput.c index d521aecbc078..cb4bdbd3e9e2 100644 --- a/drivers/input/misc/uinput.c +++ b/drivers/input/misc/uinput.c @@ -90,8 +90,8 @@ static int uinput_dev_event(struct input_dev *dev, udev->buff[udev->head].code = code; udev->buff[udev->head].value = value; ktime_get_ts64(&ts); - udev->buff[udev->head].time.tv_sec = ts.tv_sec; - udev->buff[udev->head].time.tv_usec = ts.tv_nsec / NSEC_PER_USEC; + udev->buff[udev->head].input_event_sec = ts.tv_sec; + udev->buff[udev->head].input_event_usec = ts.tv_nsec / NSEC_PER_USEC; udev->head = (udev->head + 1) % UINPUT_BUFFER_SIZE; wake_up_interruptible(&udev->waitq); diff --git a/include/uapi/linux/input.h b/include/uapi/linux/input.h index 8c5a0bf6ee35..9c5105ff5cc6 100644 --- a/include/uapi/linux/input.h +++ b/include/uapi/linux/input.h @@ -21,10 +21,20 @@ /* * The event structure itself + * Note that __USE_TIME_BITS64 is defined by libc based on + * application's request to use 64 bit time_t. */ - struct input_event { +#if (__BITS_PER_LONG != 32 || !defined(__USE_TIME_BITS64)) && !defined(__KERNEL) struct timeval time; +#define input_event_sec time.tv_sec +#define input_event_usec time.tv_usec +#else + __kernel_ulong_t __sec; + __kernel_ulong_t __usec; +#define input_event_sec __sec +#define input_event_usec __usec +#endif __u16 type; __u16 code; __s32 value;