Skip to contentSkip to conversation

unreated arch broken by the fixes

MODERATED Vlastimil Babka 3 participants 8 messages Aug 10, 2018 – Aug 11, 2018

lore
Share & tools
lore
#0 lore raw

Hi,

during QA we found that l1tf pile breaks arm64 unexpectedly.

(copy/pasting from our internal bug, the debugging and workaround was done by Yousaf Kaukab and Takashi Iwai and I just wanted to let you know ASAP)

Patch "cpu/hotplug: Boot HT siblings at least once" does this

void __init boot_cpu_state_init(void)
{

-       per_cpu_ptr(&cpuhp_state, smp_processor_id())->state = CPUHP_ONLINE;
+       this_cpu_write(cpuhp_state.booted_once, true);
+       this_cpu_write(cpuhp_state.state, CPUHP_ONLINE);

}

but

this_cpu accessors fails in boot_cpu_state_init() because tpidr_el1 is not initialized at this point. tpidr_el1 (tpidr_el2 in case VHE is enabled) stores the per-cpu offset for per-cpu data for the current cpu.

start_kernel()
{
...

	setup_per_cpu_areas();
	boot_cpu_state_init(); <= this_cpu accessor failure
	smp_prepare_boot_cpu(); <= tpidr_elx initialized

...
}

For now we have the following workaround:

void __init boot_cpu_state_init(void)
{

-       this_cpu_write(cpuhp_state.booted_once, true);
-       this_cpu_write(cpuhp_state.state, CPUHP_ONLINE);
+       per_cpu_ptr(&cpuhp_state, smp_processor_id())->booted_once = true;
+       per_cpu_ptr(&cpuhp_state, smp_processor_id())->state = CPUHP_ONLINE;

}

Should that be applied upstream or is there a better fix?

#1 lore raw
Quoted 10 lines · speck for Vlastimil Babka

Patch "cpu/hotplug: Boot HT siblings at least once" does this

void __init boot_cpu_state_init(void)
{

(quoted diff) +2 -1
-       per_cpu_ptr(&cpuhp_state, smp_processor_id())->state = CPUHP_ONLINE;
+       this_cpu_write(cpuhp_state.booted_once, true);
+       this_cpu_write(cpuhp_state.state, CPUHP_ONLINE);

}

Quoted 4 lines

but

this_cpu accessors fails in boot_cpu_state_init() because tpidr_el1 is not initialized at this point.

I'll send an email to Catalin and Will. We'll need to get arm64 fixed, because otherwise this will keep happening elsewhere too.

Linus

#2 lore raw
Quoted 3 lines · Linus Torvalds

I'll send an email to Catalin and Will. We'll need to get arm64 fixed, because otherwise this will keep happening elsewhere too.

Catalin sees the problem and is thinking of a solution. It's a bit inconvenient, because the arm64 cases use the generic setup_per_cpu_areas() function that do not know to update the percpu base pointer.

On x86, that happens as part of the x86 setup_per_cpu_areas() code. On ARM, right now there's no way to hook into the generic code.

End result: for back-ports, it might be better to continue to use the rather inconvenient syntax of

	per_cpu_ptr(&cpuhp_state, smp_processor_id())->member = value;

in this code.

But I'm trying to convince the arm people to just fix it (and do it so that the fix is simple to backport too).

Linus

#3 lore raw
Quoted 16 lines · speck for Linus Torvalds
Quoted 3 lines · Linus Torvalds

I'll send an email to Catalin and Will. We'll need to get arm64 fixed, because otherwise this will keep happening elsewhere too.

Catalin sees the problem and is thinking of a solution. It's a bit inconvenient, because the arm64 cases use the generic setup_per_cpu_areas() function that do not know to update the percpu base pointer.

On x86, that happens as part of the x86 setup_per_cpu_areas() code. On ARM, right now there's no way to hook into the generic code.

End result: for back-ports, it might be better to continue to use the rather inconvenient syntax of

Quoted 6 lines
	per_cpu_ptr(&cpuhp_state, smp_processor_id())->member = value;

in this code.

But I'm trying to convince the arm people to just fix it (and do it so that the fix is simple to backport too).

Sure, but is that going to happen before Tuesday?

Thanks,

tglx

#4 lore raw
Quoted 17 lines · speck for Thomas Gleixner
Quoted 16 lines · speck for Linus Torvalds
Quoted 3 lines · Linus Torvalds

I'll send an email to Catalin and Will. We'll need to get arm64 fixed, because otherwise this will keep happening elsewhere too.

Catalin sees the problem and is thinking of a solution. It's a bit inconvenient, because the arm64 cases use the generic setup_per_cpu_areas() function that do not know to update the percpu base pointer.

On x86, that happens as part of the x86 setup_per_cpu_areas() code. On ARM, right now there's no way to hook into the generic code.

End result: for back-ports, it might be better to continue to use the rather inconvenient syntax of

Quoted 8 lines
Quoted 6 lines
	per_cpu_ptr(&cpuhp_state, smp_processor_id())->member = value;

in this code.

But I'm trying to convince the arm people to just fix it (and do it so that the fix is simple to backport too).

Sure, but is that going to happen before Tuesday?

Any update on this? I'm trying to finalize the trees for Tuesday.

Thanks,

tglx

#5 lore raw
Quoted 8 lines · speck for Thomas Gleixner
Quoted 5 lines · speck for Thomas Gleixner
Quoted 3 lines

But I'm trying to convince the arm people to just fix it (and do it so that the fix is simple to backport too).

Sure, but is that going to happen before Tuesday?

Any update on this? I'm trying to finalize the trees for Tuesday.

Actually, Catalin has a very simple solution that works for arm: just re-order the calls to boot_cpu_state_init()/smp_prepare_boot_cpu() in start_kernel().

That _smells_ like the right solution.

As Catalin says, "boot_cpuhp_state_init()" is about hotplug, so it's not like smp_prepare_boot_cpu() would depend on it. But the reverse is not
true: the reason that the change caused problems in boot_cpu_state_init() was exactly that boot_cpu_state_init() depended on the architecture having set up the per-cpu base.

So I'll double-check the other architectures, but I think I'll just reverse the two lines as Catalin suggested:

-       boot_cpu_state_init();
        smp_prepare_boot_cpu(); /* arch-specific boot-cpu hooks */

+ boot_cpuhp_state_init();

and that certainly is easy to backport too.

Linus

#6 lore raw

Review

Quoted 7 lines · Linus Torvalds

So I'll double-check the other architectures, but I think I'll just reverse the two lines as Catalin suggested:

(quoted diff) +1 -1
-       boot_cpu_state_init();
        smp_prepare_boot_cpu(); /* arch-specific boot-cpu hooks */
+       boot_cpuhp_state_init();

Doing a visual scan over every single smp_prepare_boot_cpu() case, it really does look like the right thing to do.

It fixes the case where the architecture uses the generic version of 'setup_per_cpu_areas()' (in mm/percpu.c), but then needs to do some arch-specific setup to make it "stick" in smp_prepare_boot_cpu().

arm and arm64 do that with code like

  void __init smp_prepare_boot_cpu(void)
  {
        set_my_cpu_offset(per_cpu_offset(smp_processor_id()));
  }

(arm64 also initializes static keys etc) and most others don't do much of anything (often they do "set_cpu_online/present()" which looks fishy, but whatever) but s390 does something that *may* be related too:

        S390_lowcore.percpu_offset = __per_cpu_offset[0];

so it migth actually be the case that this is needed for s390 too.

And in no case did it look *wrong*. In fact, for the case of x86, it really looks like the right thing too, and we could possibly just remove our current

                /*
                 * Up to this point, the boot CPU has been using .init.data
                 * area.  Reload any changed state for the boot CPU.
                 */
                if (!cpu)
                        switch_to_new_gdt(cpu);

from setup_per_cpu_areas(), because our native_smp_prepare_boot_cpu() does exactly that

        int me = smp_processor_id();
        switch_to_new_gdt(me);

but whatever. It does seem to be duplicated right now, and kind of odd (why do that switch_to_new_gdt() inside the loop?).

I wouldn't actually do that x86 change, because keeping the percpu segment setup earlier for x86 is certainly safer (there are other calls after it anyway, maybe they depend on percpu accesses working), but the point is that _conceptually_ it makes sense for x86 too.

And more importantly, nobody seems to care about the opposite order. All that boot_cpu_state_init() does is about hotplug (which is why Catalin's test patch also renamed it to "boot_cpuhp_state_init()" - note the extra "hp" in there. I think that renaming might be a good idea (except I'd just spell out "hotplug" rather than add "hp" in the middle), but I'm not going to do that either.

End result: keep the sequence as-is, I'll do the re-ordering early in the merge window before I pull anything, and mark it for stable.

Linus

#7 lore raw
Quoted 7 lines · speck for Linus Torvalds

On Sat, 11 Aug 2018, Linus Torvalds wrote:
And more importantly, nobody seems to care about the opposite order. All that boot_cpu_state_init() does is about hotplug (which is why Catalin's test patch also renamed it to "boot_cpuhp_state_init()" - note the extra "hp" in there. I think that renaming might be a good idea (except I'd just spell out "hotplug" rather than add "hp" in the middle), but I'm not going to do that either.

I was staring at exactly the same place and came to the same conclusion today in the afternoon, but I had to hurry back into the camp kitchen to avoid riots of hungry kids.

Quoted 2 lines

End result: keep the sequence as-is, I'll do the re-ordering early in the merge window before I pull anything, and mark it for stable.

Ok. I'll ignore it and start to cobble the pull request together.

Thanks,

tglx