From: "Kornel Dulęba" <korneld@google.com>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
"Kornel Dulęba" <korneld@google.com>
Subject: [PATCH 2/2] input: evdev: Read clock directly in __evdev_queue_syn_dropped()
Date: Thu, 22 Oct 2026 13:39:13 +0000 [thread overview]
Message-ID: <20261022-evdev_syndropped_fix-v1-2-b5400740e1f7@google.com> (raw)
In-Reply-To: <20261022-evdev_syndropped_fix-v1-0-b5400740e1f7@google.com>
Currently, __evdev_queue_syn_dropped() calls input_get_timestamp() on
the underlying input_dev to obtain the event timestamp. If no timestamp
is set, input_get_timestamp() caches the current time and returns it;
otherwise, it returns the cached value.
There are two problems with this approach:
1. Locking. The timestamp is obtained in the same way in
evdev_events(), which is called with dev->event_lock held. Calls to
__evdev_queue_syn_dropped() are only serialized with
client->buffer_lock. This makes both accesses likely racy.
2. If no timestamp is cached yet, the subsequent hardware event
generated after __evdev_queue_syn_dropped() is called will receive
the stale cached timestamp.
Fix this by reading the current time directly based on the value of
client->clk_type. Open-coding this is not the prettiest solution, but I
couldn't figure out anything better.
I initially thought about fixing this by resetting the input timestamp
in this function instead, similarly to how INPUT_FLUSH handles it.
However, I decided against it, as that would require non-trivial
locking changes.
Signed-off-by: Kornel Dulęba <korneld@google.com>
---
drivers/input/evdev.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c
index c6da2601480f..da7396c19188 100644
--- a/drivers/input/evdev.c
+++ b/drivers/input/evdev.c
@@ -145,11 +145,18 @@ static void __evdev_flush_queue(struct evdev_client *client, unsigned int type)
static void __evdev_queue_syn_dropped(struct evdev_client *client)
{
- ktime_t *ev_time = input_get_timestamp(client->evdev->handle.dev);
- struct timespec64 ts = ktime_to_timespec64(ev_time[client->clk_type]);
unsigned int buf_mask = client->bufsize - 1;
struct input_event ev;
+ ktime_t time;
+ struct timespec64 ts;
+
+ time = client->clk_type == INPUT_CLK_REAL ?
+ ktime_get_real() :
+ client->clk_type == INPUT_CLK_MONO ?
+ ktime_get() :
+ ktime_get_boottime();
+ ts = ktime_to_timespec64(time);
memset(&ev, 0, sizeof(ev));
ev.input_event_sec = ts.tv_sec;
ev.input_event_usec = ts.tv_nsec / NSEC_PER_USEC;
--
2.56.0.307.g5fe7bd680c-goog
prev parent reply other threads:[~2026-10-22 13:39 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-22 13:39 [PATCH 0/2] input: evdev: Fix how SYN_DROPPED is generated Kornel Dulęba
2026-10-22 13:39 ` [PATCH 1/2] input: evdev: Always terminate SYN_DROPPED with SYN_REPORT Kornel Dulęba
2026-10-22 13:39 ` Kornel Dulęba [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261022-evdev_syndropped_fix-v1-2-b5400740e1f7@google.com \
--to=korneld@google.com \
--cc=dmitry.torokhov@gmail.com \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®