x86/init: Initialize wall clock in get_rtc_noop()
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.
--- arch/x86/kernel/x86_init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
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" },
Signature · 1 line
2.43.0
Quoted 2 lines
From: Naman Jain <[email protected]>
Sent: Monday, August 31, 2026 1:25 AM
LGTM.
Quoted 21 lines · Naman Jain
get_rtc_noop()is used when an RTC is unavailable, but leaves its output argument untouched. WhenCONFIG_INIT_STACK_ALL_ZEROis 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")Signed-off-by Naman Jain <[email protected]>--- arch/x86/kernel/x86_init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/x86/kernel/x86_init.c +0
-0
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
-0static __initconst const struct of_device_id of_cmos_match[] = { { .compatible ="motorola,mc146818" },Signature · 1 line
2.43.0
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. WhenCONFIG_INIT_STACK_ALL_ZEROis 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")Signed-off-by Naman Jain <[email protected]>--- arch/x86/kernel/x86_init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/x86/kernel/x86_init.c +0
-0arch/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.
Reviewed-by Roman Kisel <[email protected]>Quoted 6 lines
arch/x86/kernel/x86_init.c +0
-0static __initconst const struct of_device_id of_cmos_match[] = { { .compatible ="motorola,mc146818" },Signature · 1 line
2.43.0
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 voidjailhouse_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,
NamanQuoted 10 lines
LGTM.
Reviewed-by Roman Kisel <[email protected]>Quoted 6 lines
static
__initconstconst structof_device_idof_cmos_match[] = {
{ .compatible = "motorola,mc146818" },Signature · 1 line
2.43.0
Quoted 21 lines · Naman Jain
get_rtc_noop()is used when an RTC is unavailable, but leaves its output argument untouched. WhenCONFIG_INIT_STACK_ALL_ZEROis 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")Signed-off-by Naman Jain <[email protected]>--- arch/x86/kernel/x86_init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/x86/kernel/x86_init.c +0
-0
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
Quoted 6 lines · Naman Jain
get_rtc_noop()is used when an RTC is unavailable, but leaves its output argument untouched. WhenCONFIG_INIT_STACK_ALL_ZEROis 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")Signed-off-by Naman Jain <[email protected]>
Quoted 21 lines · Naman Jain
get_rtc_noop()is used when an RTC is unavailable, but leaves its output argument untouched. WhenCONFIG_INIT_STACK_ALL_ZEROis 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")Signed-off-by Naman Jain <[email protected]>--- arch/x86/kernel/x86_init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/x86/kernel/x86_init.c +0
-0
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
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
@@ -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" },