Page MenuHomeFreeBSD

amd64: Fix TLB invalidation routines in !SMP kernels
ClosedPublic

Authored by markj on Jul 29 2023, 3:01 PM.
Tags
None
Referenced Files
Unknown Object (File)
Dec 20 2023, 8:03 AM
Unknown Object (File)
Sep 27 2023, 7:41 AM
Unknown Object (File)
Aug 16 2023, 4:36 AM
Unknown Object (File)
Aug 16 2023, 2:20 AM
Unknown Object (File)
Jul 31 2023, 8:54 PM
Unknown Object (File)
Jul 30 2023, 7:23 PM
Subscribers

Details

Summary

amd64 is special in that its implementation of zpcpu_offset_cpu() is not
the identity transformation, even in !SMP kernels. Because the pm_pcidp
array of amd64's struct pmap is allocated from a pcpu UMA zone, this
means that accessing pm_pcidp directly, as is done in !SMP
implementations of pmap_invalidate_*, does not work. Specifically, I
see occasional unexplicable crashes in userspace when PCIDs are enabled.

Apply a minimal patch to fix the problem. While it would also make
sense to provide separate implementations of zpcpu_* for !SMP kernels,
fixing it this way makes the SMP and !SMP implementations of
pmap_invalidate_* more similar.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

markj requested review of this revision.Jul 29 2023, 3:01 PM

Should we remove SMP option from amd64 at all?

This revision is now accepted and ready to land.Jul 29 2023, 4:48 PM
alc added inline comments.
sys/amd64/amd64/pmap.c
3589

Btw, recent Ryzens support this instruction even when they don't support PCIDs. I suspect that it's faster than what we do for invltlb_glob().

In D41230#939077, @kib wrote:

Should we remove SMP option from amd64 at all?

I am in favour of this. Clearly it is not being tested - on recent Intel CPUs at least - and amd64 atomics and pcpu accessors are not optimized in !SMP kernels. The kernel itself shinks by 0.3% when options SMP is disabled. On amd64 most of the SMP-specific code is in pmap_invalidate_*(), so simply removing the alternate implementations would be a useful step.

In general, SMP is enabled in almost all of the kernel configurations available in main. kern.smp.disabled=1 can be set in the kernel environment at compile time, if needed (e.g., for bringup on new systems). Maybe we should consider dropping the option entirely.