lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240910-mgtime-v1-1-35fb64bd0af5@kernel.org>
Date: Tue, 10 Sep 2024 07:17:32 -0400
From: Jeff Layton <jlayton@...nel.org>
To: John Stultz <jstultz@...gle.com>, Thomas Gleixner <tglx@...utronix.de>, 
 Stephen Boyd <sboyd@...nel.org>
Cc: Vadim Fedorenko <vadim.fedorenko@...ux.dev>, 
 linux-kernel@...r.kernel.org, Jeff Layton <jlayton@...nel.org>
Subject: [PATCH RFC] timekeeping: don't use seqcount loop in
 ktime_mono_to_any on 64-bit arch

ktime_mono_to_any only fetches the offset inside the loop. This is a
single word on 64-bit arch, and seqcount_read_begin implies a full SMP
barrier. While we do want to use the latest offset value available, a
full seqcount loop is overkill on 64-bit, where there is no possibility
of torn reads. Just do a READ_ONCE for that and don't bother with the
seqcount.

Cc: Vadim Fedorenko <vadim.fedorenko@...ux.dev>
Signed-off-by: Jeff Layton <jlayton@...nel.org>
---
 kernel/time/timekeeping.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index 5391e4167d60..0693f44e064e 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -924,6 +924,15 @@ EXPORT_SYMBOL_GPL(ktime_get_coarse_with_offset);
  * @tmono:	time to convert.
  * @offs:	which offset to use
  */
+#if BITS_PER_LONG == 64
+ktime_t ktime_mono_to_any(ktime_t tmono, enum tk_offsets offs)
+{
+	ktime_t *offset = offsets[offs];
+
+	return ktime_add(tmono, READ_ONCE(*offset));
+}
+EXPORT_SYMBOL_GPL(ktime_mono_to_any);
+#else /* BITS_PER_LONG == 64 */
 ktime_t ktime_mono_to_any(ktime_t tmono, enum tk_offsets offs)
 {
 	ktime_t *offset = offsets[offs];
@@ -938,6 +947,7 @@ ktime_t ktime_mono_to_any(ktime_t tmono, enum tk_offsets offs)
 	return tconv;
 }
 EXPORT_SYMBOL_GPL(ktime_mono_to_any);
+#endif /* BITS_PER_LONG == 64 */
 
 /**
  * ktime_get_raw - Returns the raw monotonic time in ktime_t format

---
base-commit: 79d4f9eb4a3c4c68736d500025423e96e212b13d
change-id: 20240910-mgtime-731eace7cca5

Best regards,
-- 
Jeff Layton <jlayton@...nel.org>


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ