Page MenuHomeFreeBSD

Optimize context switch for PTI on PCID pmap.
ClosedPublic

Authored by kib on Apr 4 2018, 4:57 PM.
Tags
None
Referenced Files
F106135201: D14961.id41238.diff
Wed, Dec 25, 11:46 PM
F106106560: D14961.diff
Wed, Dec 25, 12:25 PM
Unknown Object (File)
Oct 3 2024, 12:19 AM
Unknown Object (File)
Oct 2 2024, 10:06 PM
Unknown Object (File)
Oct 1 2024, 12:13 PM
Unknown Object (File)
Oct 1 2024, 8:40 AM
Unknown Object (File)
Sep 8 2024, 6:44 PM
Unknown Object (File)
Sep 8 2024, 4:17 PM
Subscribers

Details

Summary

In pti-enabled pmap, the PCID allocation scheme assigns temporal id for the kernel page table, and user page table twin PCID is calculating by setting high bit in the kernel PCID. So the kernel AS is mapped with per-vmspace PCID, and we must completely shut down all mappings in KVA when switching contexts, so that newly switched thread would see all changes in KVA occured while it was not executing. After all, KVA is same between all threads.

I coded the pti context switch so that user part of the page table gets its TLB entries flushed too. Now I think it is excessive. The same PCID flushing algorithm that is used for non-pti pmap, seems to correctly work for the UVA mappings. The only shared TLB entries are the pages from KVA accessed by the kernel entry trampoline. All of them are static except per-thread TSS and LDT. For TSS and LDT, the lifetime of newly allocated entries is the whole thread life, so it should be fine as well. If not fine, then explicit shutdowns for current pmap of the newly allocated LDT and TSS pages would be enough.

Test Plan

I did a buildworld on the machine which implements INVPCID. More testing would be requried if the review is positive.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

kib retitled this revision from Optimize context switch for PTI on INVPCID pmap. to Optimize context switch for PTI on PCID pmap..Apr 4 2018, 5:00 PM
sys/amd64/amd64/pmap.c
7386 ↗(On Diff #41100)

Don't we still want this inc in the !pti case?

kib marked an inline comment as done.

If pmap_pcid_alloc() enabled TLS save, always increment pm_save_cnt.

I can't see any problem with this.

This revision is now accepted and ready to land.Apr 5 2018, 6:05 PM
sys/amd64/amd64/pmap.c
7396 ↗(On Diff #41140)

I don't think that this is an appropriate use of "which". I think that you should instead write "... table. They are ...".

kib marked an inline comment as done.Apr 7 2018, 5:10 PM

Conceptually, this seems correct. Please proceed with the additional testing that you mentioned.

Do not rotate pm_pcid for kernel pmap when pti is enabled. This is believed to be innocent since kernel page tables are unconditionally flushed on context switch.

Fix grammar.

This revision now requires review to proceed.Apr 7 2018, 5:12 PM
In D14961#315761, @alc wrote:

Conceptually, this seems correct. Please proceed with the additional testing that you mentioned.

Peter tested the current version of the patch, both on machine with INVPCID and without. No problems seen.

This revision was not accepted when it landed; it landed in state Needs Review.Apr 12 2018, 7:59 PM
This revision was automatically updated to reflect the committed changes.