From c0d0fb067739289dd698ebc680addb8422459026 Mon Sep 17 00:00:00 2001 From: Andrei Vagin Date: Thu, 5 Sep 2024 19:03:56 -0700 Subject: [PATCH] kvm: set CR4.PGE MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ``` CR4.PGE (bit-7) enables Paging Global Extensions (PGE). PGE determines whether moves to CR3 flush all of the PTE's from the TLB, or only those whose G-bit (global bit) is not set. Likewise, for task switches which implicitly set CR3, CR4.PGE controls TLB flushing in the same manner. ``` In case of gvisor, it improves performance of switching to/from the Sentry: │ kvm │ kvm.pge │ │ wall_ns/op │ wall_ns/op vs base │ Getpid 1.774k ± 0% 1.607k ± 1% -9.36% (p=0.000 n=10) GetpidOpt 1.623k ± 1% 1.452k ± 1% -10.54% (p=0.000 n=10) geomean 1.696k 1.528k -9.95% │ kvm │ kvm.pge │ │ cpu_ns/op │ cpu_ns/op vs base │ Getpid 1.749k ± 0% 1.583k ± 1% -9.52% (p=0.000 n=10) GetpidOpt 1.600k ± 0% 1.414k ± 2% -11.62% (p=0.000 n=10) geomean 1.673k 1.496k -10.58% It plays only on hosts without PCID. PiperOrigin-RevId: 671587163 --- pkg/ring0/kernel_amd64.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/ring0/kernel_amd64.go b/pkg/ring0/kernel_amd64.go index a0428460a..1fb6ba6f3 100644 --- a/pkg/ring0/kernel_amd64.go +++ b/pkg/ring0/kernel_amd64.go @@ -186,7 +186,7 @@ func (c *CPU) CR0() uint64 { // //go:nosplit func (c *CPU) CR4() uint64 { - cr4 := uint64(_CR4_PAE | _CR4_PSE | _CR4_OSFXSR | _CR4_OSXMMEXCPT) + cr4 := uint64(_CR4_PAE | _CR4_PSE | _CR4_PGE | _CR4_OSFXSR | _CR4_OSXMMEXCPT) if hasPCID { cr4 |= _CR4_PCIDE }