[PATCH] x86/tsc: Fix misplaced seqcount_latch_init() in cyc2ns_init_secondary_cpus()
"Bo Li" <[email protected]> Tue, 4 Aug 2026 15:11:28 +0800
| Newsgroups | org.kernel.vger.stable,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <[email protected]> |
In cyc2ns_init_secondary_cpus(), seqcount_latch_init(&c2n->seq) is
called _before_ c2n is advanced to the next CPU via per_cpu_ptr().
As a result:
1. On the first iteration, c2n still points at the BSP's struct, so
the BSP's seqcount_latch is re-initialized. cyc2ns_init_boot_cpu()
already did this correctly, so it happens to work by accident
because no concurrent readers are live at __init time.
2. On subsequent iterations, seqcount_latch_init() initializes the
previous CPU's seqcount (because c2n was advanced by the prior
per_cpu_ptr()), so all CPUs except the last one in the for_each
loop happen to get initialized. The last secondary CPU's seqcount
is left uninitialized.
Move seqcount_latch_init() _after_ c2n is pointed at the target CPU's
struct, so each secondary CPU's seqcount is correctly initialized.
Fixes: e2a9ca29b5ed ("x86/tsc: Initialize cyc2ns when tsc frequency is determined")
Cc: [email protected]
Signed-off-by: Bo Li <[email protected]>
---
arch/x86/kernel/tsc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
index ce10ae4b298b..84fb80492b01 100644
--- a/arch/x86/kernel/tsc.c
+++ b/arch/x86/kernel/tsc.c
@@ -223,8 +223,8 @@ static void __init cyc2ns_init_secondary_cpus(void)
for_each_possible_cpu(cpu) {
if (cpu != this_cpu) {
- seqcount_latch_init(&c2n->seq);
c2n = per_cpu_ptr(&cyc2ns, cpu);
+ seqcount_latch_init(&c2n->seq);
c2n->data[0] = data[0];
c2n->data[1] = data[1];
}
--
2.20.1