Skip to contentSkip to conversation

x86/init: Initialize wall clock in get_rtc_noop()

PATCH Applied Naman Jain 6 participants 10 messages Aug 31 – Nov 3

Subsystems (4)
lore
Share & tools
lore

Naman Jain

author
#0 lore raw

PATCH 1/1 x86/init: Initialize wall clock in get_rtc_noop()

get_rtc_noop() is used when an RTC is unavailable, but leaves its output argument untouched. When CONFIG_INIT_STACK_ALL_ZERO is not enabled, timekeeping_init() may therefore receive a nonzero invalid persistent clock value and warn:
"Persistent clock returned invalid value"

Initialize the output to zero, the documented representation of an unsupported persistent clock.

Fixes c311ed6183f4 ("x86/init: Allow DT configured systems to disable RTC at boot time")
---
 arch/x86/kernel/x86_init.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/x86_init.c +1 -1
index 252c5827d0634..3b9b41820c84c 100644
@@ -37,7 +37,7 @@ static void iommu_shutdown_noop(void) { }
 bool __init bool_x86_init_noop(void) { return false; }
 void x86_op_int_noop(int cpu) { }
 int set_rtc_noop(const struct timespec64 *now) { return -EINVAL; }
-void get_rtc_noop(struct timespec64 *now) { }
+void get_rtc_noop(struct timespec64 *now) { *now = (struct timespec64){0}; }
 
 static __initconst const struct of_device_id of_cmos_match[] = {
 	{ .compatible = "motorola,mc146818" },
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#3 lore raw
In reply to Naman Jain
Quoted 21 lines · Naman Jain

get_rtc_noop() is used when an RTC is unavailable, but leaves its output argument untouched. When CONFIG_INIT_STACK_ALL_ZERO is not enabled, timekeeping_init() may therefore receive a nonzero invalid persistent clock value and warn:
"Persistent clock returned invalid value"

Initialize the output to zero, the documented representation of an unsupported persistent clock.

Fixes c311ed6183f4 ("x86/init: Allow DT configured systems to disable RTC at boot time")
---
 arch/x86/kernel/x86_init.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/x86_init.c +0 -0
index 252c5827d0634..3b9b41820c84c 100644

arch/x86/kernel/x86_init.c static void iommu_shutdown_noop(void) { } · line 40

Quoted 5 lines
arch/x86/kernel/x86_init.c +1 -1
@@ -37,7 +37,7 @@ static void iommu_shutdown_noop(void) { }
 bool __init bool_x86_init_noop(void) { return false; }
 void x86_op_int_noop(int cpu) { }
 int set_rtc_noop(const struct timespec64 *now) { return -EINVAL; }
-void get_rtc_noop(struct timespec64 *now) { }
+void get_rtc_noop(struct timespec64 *now) { *now = (struct timespec64){0}; }

Hi Naman,

Could be

*now = (struct timespec64){};

to save a byte :)

LGTM.

Quoted 6 lines
arch/x86/kernel/x86_init.c +0 -0
 static __initconst const struct of_device_id of_cmos_match[] = {
 	{ .compatible = "motorola,mc146818" },
Signature · 1 line
2.43.0
author
#4 lore raw
Quoted 30 lines · Roman Kisel
Quoted 21 lines · Naman Jain

get_rtc_noop() is used when an RTC is unavailable, but leaves its output argument untouched. When CONFIG_INIT_STACK_ALL_ZERO is not enabled, timekeeping_init() may therefore receive a nonzero invalid persistent clock value and warn:
"Persistent clock returned invalid value"

Initialize the output to zero, the documented representation of an unsupported persistent clock.

Fixes c311ed6183f4 ("x86/init: Allow DT configured systems to disable RTC at boot time")
---
  arch/x86/kernel/x86_init.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/x86_init.c +0 -0
index 252c5827d0634..3b9b41820c84c 100644

arch/x86/kernel/x86_init.c static void iommu_shutdown_noop(void) { } · line 40

Quoted 5 lines
arch/x86/kernel/x86_init.c +1 -1
@@ -37,7 +37,7 @@ static void iommu_shutdown_noop(void) { }
  bool __init bool_x86_init_noop(void) { return false; }
  void x86_op_int_noop(int cpu) { }
  int set_rtc_noop(const struct timespec64 *now) { return -EINVAL; }
-void get_rtc_noop(struct timespec64 *now) { }
+void get_rtc_noop(struct timespec64 *now) { *now = (struct timespec64){0}; }

Hi Naman,

Quoted 5 lines

Could be

*now = (struct timespec64){};

to save a byte :)

hi Roman,
Thanks for reviewing.

Tianyu pointed out offline that this is handled in yet another way in jailhouse code:

arch/x86/kernel/jailhouse.c
static void jailhouse_get_wallclock(struct timespec64 *now)

{
      memset(now, 0, sizeof(now));
}

Regards,
Naman

Quoted 10 lines

LGTM.

Quoted 6 lines
arch/x86/kernel/x86_init.c +0 -0
  static __initconst const struct of_device_id of_cmos_match[] = {
  	{ .compatible = "motorola,mc146818" },
Signature · 1 line
2.43.0
#5 lore raw
Quoted 6 lines · PDT Naman Jain
Quoted 1 line · Roman Kisel

On Mon, Aug 31, 2026 at 08:25:28AM +0000, Naman Jain wrote:

[...]

Quoted 13 lines
Quoted 9 lines
Quoted 1 line

+void get_rtc_noop(struct timespec64 *now) { *now = (struct timespec64){0}; }

Hi Naman,

Could be

*now = (struct timespec64){};

to save a byte :)

hi Roman,
Thanks for reviewing.

Quoted 8 lines

Tianyu pointed out offline that this is handled in yet another way in jailhouse code:

arch/x86/kernel/jailhouse.c
static void jailhouse_get_wallclock(struct timespec64 *now)

{
       memset(now, 0, sizeof(now));
}

Appreciate sharing! Makes sense to me, looks way more explicit. Most importantly imo, the memset isn't actually producing a call here so the clock no-op stays cheap when choosing memset over = {}.

One can see that the kernel build compiles = {0}, = {} into

pxor ...
movups ...

on x64 in the above. I made sure the memset "call" is relaxed/optimized away into the same sequence pxor ...; movups ....

Quoted 14 lines

Regards,
Naman

Quoted 10 lines

LGTM.

Quoted 6 lines

static __initconst const struct of_device_id of_cmos_match[] = {
{ .compatible = "motorola,mc146818" },

Signature · 1 line
2.43.0
author
#6 lore raw
In reply to Naman Jain
Quoted 21 lines · Naman Jain

get_rtc_noop() is used when an RTC is unavailable, but leaves its output argument untouched. When CONFIG_INIT_STACK_ALL_ZERO is not enabled, timekeeping_init() may therefore receive a nonzero invalid persistent clock value and warn:
"Persistent clock returned invalid value"

Initialize the output to zero, the documented representation of an unsupported persistent clock.

Fixes c311ed6183f4 ("x86/init: Allow DT configured systems to disable RTC at boot time")
---
  arch/x86/kernel/x86_init.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/x86_init.c +0 -0
index 252c5827d0634..3b9b41820c84c 100644

arch/x86/kernel/x86_init.c static void iommu_shutdown_noop(void) { } · line 43

Quoted 8 lines
arch/x86/kernel/x86_init.c +1 -1
@@ -37,7 +37,7 @@ static void iommu_shutdown_noop(void) { }
  bool __init bool_x86_init_noop(void) { return false; }
  void x86_op_int_noop(int cpu) { }
  int set_rtc_noop(const struct timespec64 *now) { return -EINVAL; }
-void get_rtc_noop(struct timespec64 *now) { }
+void get_rtc_noop(struct timespec64 *now) { *now = (struct timespec64){0}; }
 
  static __initconst const struct of_device_id of_cmos_match[] = {
  	{ .compatible = "motorola,mc146818" },

Hi Maintainers,
Gentle ping on this patch. Please let me know if there are any comments or if any changes are needed from my side.

Regards,
Naman

maintainer Reviewed-by on v1 1/1
#7 lore raw
In reply to Naman Jain
Quoted 6 lines · Naman Jain

get_rtc_noop() is used when an RTC is unavailable, but leaves its output argument untouched. When CONFIG_INIT_STACK_ALL_ZERO is not enabled, timekeeping_init() may therefore receive a nonzero invalid persistent clock value and warn:
"Persistent clock returned invalid value"

Quoted 6 lines

Initialize the output to zero, the documented representation of an unsupported persistent clock.

Fixes c311ed6183f4 ("x86/init: Allow DT configured systems to disable RTC at boot time")
author
#8 lore raw
In reply to Naman Jain
Quoted 21 lines · Naman Jain

get_rtc_noop() is used when an RTC is unavailable, but leaves its output argument untouched. When CONFIG_INIT_STACK_ALL_ZERO is not enabled, timekeeping_init() may therefore receive a nonzero invalid persistent clock value and warn:
"Persistent clock returned invalid value"

Initialize the output to zero, the documented representation of an unsupported persistent clock.

Fixes c311ed6183f4 ("x86/init: Allow DT configured systems to disable RTC at boot time")
---
  arch/x86/kernel/x86_init.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/x86_init.c +0 -0
index 252c5827d0634..3b9b41820c84c 100644

arch/x86/kernel/x86_init.c static void iommu_shutdown_noop(void) { } · line 43

Quoted 8 lines
arch/x86/kernel/x86_init.c +1 -1
@@ -37,7 +37,7 @@ static void iommu_shutdown_noop(void) { }
  bool __init bool_x86_init_noop(void) { return false; }
  void x86_op_int_noop(int cpu) { }
  int set_rtc_noop(const struct timespec64 *now) { return -EINVAL; }
-void get_rtc_noop(struct timespec64 *now) { }
+void get_rtc_noop(struct timespec64 *now) { *now = (struct timespec64){0}; }
 
  static __initconst const struct of_device_id of_cmos_match[] = {
  	{ .compatible = "motorola,mc146818" },

Hi all,

Gentle ping on this patch. Would it be possible to pick this change up through the x86 tree?

Thanks,
Naman

merge bot Applied
#9 lore raw
In reply to Naman Jain
The following commit has been merged into the x86/urgent branch of tip:

The following commit has been merged into the x86/urgent branch of tip:

Commit-ID:     7d5af1f256fdecff6a7986bbc9146b69cb355bb5
Gitweb:        https://git.kernel.org/tip/7d5af1f256fdecff6a7986bbc9146b69cb355bb5
Author:        Naman Jain <[email protected]>
AuthorDate:    Mon, 31 Aug 2026 08:25:28 
Committer:     Borislav Petkov (AMD) <[email protected]>
CommitterDate: Mon, 02 Nov 2026 21:38:37 -08:00

x86/init: Initialize wall clock in get_rtc_noop()

get_rtc_noop() is used when an RTC is unavailable, but leaves its output argument untouched. When CONFIG_INIT_STACK_ALL_ZERO is not enabled, timekeeping_init() may therefore receive a nonzero invalid persistent clock value and warn:

"Persistent clock returned invalid value"

Initialize the output to zero, the documented representation of an unsupported persistent clock.

---
 arch/x86/kernel/x86_init.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/x86_init.c +1 -1
index 252c582..3b9b418 100644
@@ -37,7 +37,7 @@ static void iommu_shutdown_noop(void) { }
 bool __init bool_x86_init_noop(void) { return false; }
 void x86_op_int_noop(int cpu) { }
 int set_rtc_noop(const struct timespec64 *now) { return -EINVAL; }
-void get_rtc_noop(struct timespec64 *now) { }
+void get_rtc_noop(struct timespec64 *now) { *now = (struct timespec64){0}; }
 
 static __initconst const struct of_device_id of_cmos_match[] = {
 	{ .compatible = "motorola,mc146818" },