Re: [PATCH v3] sched/topology: Avoid unsequenced accesses to jiffies in sd_init()

From: Peter Zijlstra

Date: Thu Nov 26 2026 - 06:50:43 EST


On Wed, Nov 25, 2026 at 01:03:11PM -0700, Nathan Chancellor wrote:
> On Wed, Nov 25, 2026 at 11:32:31AM -0800, Nick Desaulniers wrote:
> > On Wed, Nov 25, 2026 at 1:46 AM Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote:
> > >
> > > On Wed, Nov 25, 2026 at 12:23:35AM -0700, Nathan Chancellor wrote:
> > > > Clang's warning is ultimately pointing out that jiffies may have two
> > > > separate values in this initializer because it is volatile and accessed
> > > > twice and the order of these accesses is not specified. This could
> > > > result in unexpected or inconsistent behavior depending on the code
> > > > author's intent and whether they realized the variable was volatile or
> > > > not.
> > > >
> > > > As two separate accesses is not necessary here, add a local variable to
> > > > hold the value of jiffies before the designated initializer so that a
> > > > consistent value is used for initializing both members, clearing up the
> > > > warning.
> > >
> > > None of this tells me why we should not just disable that warning and
> > > get on with life.
>
> See below, I believe this warning has general value (but maybe not
> here).

Yeah, not here.

> > I think the warning has value generally across the tree, even if this
> > particular single instance "isn't a bug, per se."
>
> Hard agree. Just because this particular instance is not a bug does not
> mean future instances won't be. We pay a small cost to silence the
> initial instances then we get to see what it flags in the future. If it
> turns out there are never bugs, we can just turn the warning off
> globally (we've done it before) but I'd rather have hard evidence of
> that first; to me, these initial instances don't count. No maintainer
> has objected to the other patches I have sent for the other instances of
> this warning and there were not all that many for how much code the
> kernel has.

I just don't understand any of this. Perhaps I'm being super dense, but
calling this UB is utterly stupid IMO. It is trivial to define what
should happen here and make the compiler do it, although perhaps it is
not what people expect -- but at that point you can have a warning about
performance, rather than it being UB.

Most all of this is me being distrustful towards the C committee about
volatile; they hate it while we live by it.

But I really don't see the difference between two jiffie reads in an
initializer vs two jiffie reads in random code. Its just two reads that
cannot be fused, big deal.

So they're making a big deal out of the unsequenced thing; but at the
same time they're eroding actual sequence points; I mean WTF ?!

So function calls used to be a sequence point; but then they allowed
auto inlining (without the use of the inline keyword), and guess what?
An inlined function is explicitly not a sequence point.

So they cannot be both concerned about sequence *and* erode sequence.

All of this just sounds like a whole pile of wankery without actual
merit.

Also; the purported justification of UB has always been room for
optimization, but volatile is the anti-thesis of that, it explicitly
does not allow optimization. Marking something with volatile as UB is
just batshit.

I mean, I suppose I can apply the patch, but I'm not buying any of it.
This is not an improvement, it actively makes clang worse!