linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Antonios Salios <antonios@mwa.re>, Arnd Bergmann <arnd@arndb.de>,
	Deepa Dinamani <deepa.kernel@gmail.com>
Cc: rydberg@bitmath.org, linux-input@vger.kernel.org,
	linux-kernel@vger.kernel.org, "Jan Henrik Weinstock" <jan@mwa.re>,
	"Lukas Jünger" <lukas@mwa.re>
Subject: Re: element sizes in input_event struct on riscv32
Date: Mon, 18 Dec 2023 18:50:48 -0800	[thread overview]
Message-ID: <ZYEFCHBC75rjCE0n@google.com> (raw)
In-Reply-To: <c812ea74dd02d1baf85dc6fb32701e103984d25d.camel@mwa.re>

Hi Antonious,

On Thu, Dec 14, 2023 at 11:11:18AM +0100, Antonios Salios wrote:
> Hi all.
> 
> I'm having trouble getting evdev to run in a simulated Buildroot
> environment on riscv32. Evtest (and the x11 driver) seems to be
> receiving garbage data from input devices.
> 
> Analyzing the input_event struct shows that the kernel uses 32-bit (aka
> __kernel_ulong_t) values for __sec & __usec.
> Evtest on the other hand interprets these variables as 64-bit time_t
> values in a timeval struct, resulting in a mismatch between the kernel
> and userspace.
> 
> What would be the correct size for these values on a 32-bit
> architecture that uses 64-bit time_t values?

I think there is misunderstanding - we do not have *2* 64-bit values on
32-but architectures. Here is what was done:

commit 152194fe9c3f03232b9c0d0264793a7fa4af82f8
Author: Deepa Dinamani <deepa.kernel@gmail.com>
Date:   Sun Jan 7 17:44:42 2018 -0800

    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

I'll let Arnd and Deepa to comment further.

Thanks.

-- 
Dmitry

  reply	other threads:[~2023-12-19  2:50 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-14 10:11 element sizes in input_event struct on riscv32 Antonios Salios
2023-12-19  2:50 ` Dmitry Torokhov [this message]
2023-12-19 13:53   ` Arnd Bergmann
2023-12-21  8:56     ` Antonios Salios
2023-12-21 12:28       ` Arnd Bergmann
2023-12-21 13:38         ` Antonios Salios
2024-01-15 15:46           ` Antonios Salios
2024-01-15 16:11             ` Arnd Bergmann

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=ZYEFCHBC75rjCE0n@google.com \
    --to=dmitry.torokhov@gmail.com \
    --cc=antonios@mwa.re \
    --cc=arnd@arndb.de \
    --cc=deepa.kernel@gmail.com \
    --cc=jan@mwa.re \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lukas@mwa.re \
    --cc=rydberg@bitmath.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;
as well as URLs for NNTP newsgroup(s).