x86 does not keep TLB coherent across cores, nor with in-memory page table. And that is why we need explicit TLB flush when some PTE modifications happen (e.g. downgrade RW to RO, clear PTE, etc.). Besides, TLB flush is very important and affect application correctness. I’ve had some really awful debugging experience which was eventually introduced by missed TLB flush. Below is a list of operations that should have TLB flush followed:
munmap(optional, can be optimized by holding the old VA range)
Unfortunately, TLB flush is costly, especially if we need to shootdown TLB entries on remote core. TLB shootdown123 is performed by sending IPI to remote core, and remote core will flush local TLB entries within its handler. Linux optimize this by batching TLB flush until context switch happens. Lego currently does not have this nice feature, we flush TLB one by one for each PTE change (listed as TODO).
Created: Mar 19, 2018
Last Updated: Mar 19, 2018