Re: [PATCH v2] sched/topology: Avoid unsequenced accesses to jiffies in sd_init()
From: Peter Zijlstra
Date: Wed Nov 18 2026 - 04:47:39 EST
On Tue, Nov 17, 2026 at 10:39:15AM -0800, Nick Desaulniers wrote:
> On Tue, Nov 17, 2026 at 10:30 AM Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote:
> >
> > I don't speak enough C legal to actually understand the Changelog, but
> > the actual change seems daft. Is this really needed?
>
> I would imagine a delta of the disassembly here before/after the
> change would make it more obvious (one less volatile access, which be
> have arbitrary ordering between initializing other members).
Could it be fixed by adding an explicit cast? Say:
.last_balance = (unsigned long)jiffies,
> But I guess I'm also curious why jiffies is defined as volatile
> anyway? I thought the usual guidance was to use
> cast-to-volatile-qualified pointer during access, rather than declare
> as volatile?
jiffies is ancient; it stems from before we had READ_ONCE() and friends.
It used to be that task_struct::state was also declared volatile, but
I've since fixed that.
Mostly, you want to always read time, and not have time optimized
'away'. Like lift a jiffies read out of a loop and break the timeout
condition and all that.
Also, the C people are daft and want to get rid of volatile,
irrespective of its many uses, so perhaps this is a subtle act of
sabotage or something and we should get clang to revert this weirdness.
I think the thinking was that with _Atomic there is no further need of
volatile and its fine to break the many billions of lines of
pre-existing C code or something stupid like that :/