Linux 6.9 Lowering The Overhead Of CR3 Writes
The x86/entry pull request last week for the Linux 6.9 kernel contained just a single patch but it was a significant one at that in that it helps lower the overhead for CR3 writes and the benefits can be visible for workloads like Linux's perf functionality.
Thomas Gleixner explained in the x86/entry pull request for Linux 6.9:
The pull request was successfully merged ahead of Linux 6.9-rc1 due out this weekend. This patch was written by an Alibaba engineer while Google also has carried a similar patch for their own internal kernel builds to this point.
Thomas Gleixner explained in the x86/entry pull request for Linux 6.9:
"The current CR3 handling for kernel page table isolation in the paranoid return paths which are relevant for #NMI, #MCE, #VC, #DB and #DF is unconditionally writing CR3 with the value retrieved on exception entry.
In the vast majority of cases when returning to the kernel this is a pointless exercise because CR3 was not modified on exception entry. The only situation where this is necessary is when the exception interrupts a entry from user before switching to kernel CR3 or interrupts an exit to user after switching back to user CR3.
As CR3 writes can be expensive on some systems this becomes measurable overhead with high frequency #NMIs such as perf.
Avoid this overhead by checking the CR3 value, which was saved on entry, and write it back to CR3 only when it us a user CR3."
The pull request was successfully merged ahead of Linux 6.9-rc1 due out this weekend. This patch was written by an Alibaba engineer while Google also has carried a similar patch for their own internal kernel builds to this point.
1 Comment