From b3495cecb24c8e38e1b0c569c69c983b6a2d6d9c Mon Sep 17 00:00:00 2001 From: Deepa Dinamani Date: Mon, 1 Jan 2018 22:27:11 -0800 Subject: Input: uinput - use monotonic times for timestamps struct timeval which is part of struct input_event to maintain the event times is not y2038 safe. Real time timestamps are also not ideal for input_event as this time can go backwards as noted in the patch a80b83b7b8 by John Stultz. The patch switches the timestamps to use monotonic time from realtime time. This is assuming no one is using absolute times from these timestamps. The structure to maintain input events will be changed in a different patch. Signed-off-by: Deepa Dinamani Acked-by: Peter Hutterer Patchwork-Id: 10118255 Signed-off-by: Dmitry Torokhov --- drivers/input/misc/uinput.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'drivers/input/misc/uinput.c') diff --git a/drivers/input/misc/uinput.c b/drivers/input/misc/uinput.c index 39ddd9a73feb..d521aecbc078 100644 --- a/drivers/input/misc/uinput.c +++ b/drivers/input/misc/uinput.c @@ -84,11 +84,14 @@ static int uinput_dev_event(struct input_dev *dev, unsigned int type, unsigned int code, int value) { struct uinput_device *udev = input_get_drvdata(dev); + struct timespec64 ts; udev->buff[udev->head].type = type; udev->buff[udev->head].code = code; udev->buff[udev->head].value = value; - do_gettimeofday(&udev->buff[udev->head].time); + 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->head = (udev->head + 1) % UINPUT_BUFFER_SIZE; wake_up_interruptible(&udev->waitq); -- cgit v1.2.3-59-g8ed1b From 152194fe9c3f03232b9c0d0264793a7fa4af82f8 Mon Sep 17 00:00:00 2001 From: Deepa Dinamani Date: Sun, 7 Jan 2018 17:44:42 -0800 Subject: Input: extend usable life of event timestamps to 2106 on 32 bit systems The input events use struct timeval to store event time, unfortunately this structure is not y2038 safe and is being replaced in kernel with y2038 safe structures. Because of ABI concerns we can not change the size or the layout of structure input_event, so we opt to re-interpreting the 'seconds' part of timestamp as an unsigned value, effectively doubling the range of values, to year 2106. Newer glibc that has support for 32 bit applications to use 64 bit time_t supplies __USE_TIME_BITS64 define [1], that we can use to present the userspace with updated input_event layout. The updated layout will cause the compile time breakage, alerting applications and distributions maintainers to the issue. Existing 32 binaries will continue working without any changes until 2038. Ultimately userspace applications should switch to using monotonic or boot time clocks, as realtime clock is not very well suited for input event timestamps as it can go backwards (see a80b83b7b8 "Input: evdev - add CLOCK_BOOTTIME support" by by John Stultz). With monotonic clock the practical range of reported times will always fit into the pair of 32 bit values, as we do not expect any system to stay up for a hundred years without a single reboot. [1] https://sourceware.org/glibc/wiki/Y2038ProofnessDesign Suggested-by: Arnd Bergmann Signed-off-by: Deepa Dinamani Acked-by: Peter Hutterer Patchwork-Id: 10148083 Signed-off-by: Dmitry Torokhov --- drivers/input/evdev.c | 20 +++++++++++++------- drivers/input/input-compat.c | 8 ++++---- drivers/input/input-compat.h | 3 ++- drivers/input/misc/uinput.c | 4 ++-- include/uapi/linux/input.h | 11 +++++++++++ 5 files changed, 32 insertions(+), 14 deletions(-) (limited to 'drivers/input/misc/uinput.c') diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c index 925571475005..116088fc3621 100644 --- a/drivers/input/evdev.c +++ b/drivers/input/evdev.c @@ -135,10 +135,7 @@ 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].type = ev->type; - client->buffer[head].code = ev->code; - client->buffer[head].value = ev->value; + client->buffer[head] = *ev; } num++; @@ -157,6 +154,7 @@ static void __evdev_queue_syn_dropped(struct evdev_client *client) { struct input_event ev; ktime_t time; + struct timespec64 ts; time = client->clk_type == EV_CLK_REAL ? ktime_get_real() : @@ -164,7 +162,9 @@ static void __evdev_queue_syn_dropped(struct evdev_client *client) ktime_get() : ktime_get_boottime(); - ev.time = ktime_to_timeval(time); + ts = ktime_to_timespec64(time); + 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; @@ -241,7 +241,10 @@ 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; @@ -262,12 +265,15 @@ static void evdev_pass_values(struct evdev_client *client, struct evdev *evdev = client->evdev; const struct input_value *v; struct input_event event; + struct timespec64 ts; bool wakeup = false; if (client->revoked) return; - event.time = ktime_to_timeval(ev_time[client->clk_type]); + ts = ktime_to_timespec64(ev_time[client->clk_type]); + 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..fda8d6d2a268 100644 --- a/drivers/input/input-compat.c +++ b/drivers/input/input-compat.c @@ -24,8 +24,8 @@ 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; @@ -44,8 +44,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..7288a7c573cc 100644 --- a/include/uapi/linux/input.h +++ b/include/uapi/linux/input.h @@ -21,10 +21,21 @@ /* * 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; -- cgit v1.2.3-59-g8ed1b From 141fc3fcfde3ea2b2ec71c037e8d11c1cdea1676 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Tue, 16 Jan 2018 16:43:52 -0800 Subject: Input: remove unneeded MODULE_VERSION() usage in misc input drivers MODULE_VERSION is useless for in-kernel drivers, so just remove all usage of it in the misc input drivers. Along with this, some DRIVER_VERSION macros were removed as they are also pointless. Signed-off-by: Greg Kroah-Hartman Signed-off-by: Dmitry Torokhov --- drivers/input/misc/apanel.c | 2 -- drivers/input/misc/ati_remote2.c | 2 -- drivers/input/misc/uinput.c | 1 - 3 files changed, 5 deletions(-) (limited to 'drivers/input/misc/uinput.c') diff --git a/drivers/input/misc/apanel.c b/drivers/input/misc/apanel.c index aad1df04c854..094bddf56755 100644 --- a/drivers/input/misc/apanel.c +++ b/drivers/input/misc/apanel.c @@ -26,7 +26,6 @@ #include #define APANEL_NAME "Fujitsu Application Panel" -#define APANEL_VERSION "1.3.1" #define APANEL "apanel" /* How often we poll keys - msecs */ @@ -345,7 +344,6 @@ module_exit(apanel_cleanup); MODULE_AUTHOR("Stephen Hemminger "); MODULE_DESCRIPTION(APANEL_NAME " driver"); MODULE_LICENSE("GPL"); -MODULE_VERSION(APANEL_VERSION); MODULE_ALIAS("dmi:*:svnFUJITSU:pnLifeBook*:pvr*:rvnFUJITSU:*"); MODULE_ALIAS("dmi:*:svnFUJITSU:pnLifebook*:pvr*:rvnFUJITSU:*"); diff --git a/drivers/input/misc/ati_remote2.c b/drivers/input/misc/ati_remote2.c index ebf4448b31b9..ded5b84e336d 100644 --- a/drivers/input/misc/ati_remote2.c +++ b/drivers/input/misc/ati_remote2.c @@ -14,10 +14,8 @@ #include #define DRIVER_DESC "ATI/Philips USB RF remote driver" -#define DRIVER_VERSION "0.3" MODULE_DESCRIPTION(DRIVER_DESC); -MODULE_VERSION(DRIVER_VERSION); MODULE_AUTHOR("Ville Syrjala "); MODULE_LICENSE("GPL"); diff --git a/drivers/input/misc/uinput.c b/drivers/input/misc/uinput.c index cb4bdbd3e9e2..a94c5e05006b 100644 --- a/drivers/input/misc/uinput.c +++ b/drivers/input/misc/uinput.c @@ -1088,4 +1088,3 @@ MODULE_ALIAS("devname:" UINPUT_NAME); MODULE_AUTHOR("Aristeu Sergio Rozanski Filho"); MODULE_DESCRIPTION("User level driver support for input subsystem"); MODULE_LICENSE("GPL"); -MODULE_VERSION("0.3"); -- cgit v1.2.3-59-g8ed1b