From 6f97a143984150f85c095ddb9a46b3496d84a267 Mon Sep 17 00:00:00 2001 From: Zide Chen Date: Tue, 8 May 2018 12:35:57 -0700 Subject: [PATCH] HV: Enable CR0.WP Page fault could be raised if writing to read-only pages. This is useful for debugging. Signed-off-by: Zide Chen --- hypervisor/arch/x86/mmu.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/hypervisor/arch/x86/mmu.c b/hypervisor/arch/x86/mmu.c index feff904ff..51007c551 100644 --- a/hypervisor/arch/x86/mmu.c +++ b/hypervisor/arch/x86/mmu.c @@ -485,6 +485,12 @@ uint64_t get_paging_pml4(void) void enable_paging(uint64_t pml4_base_addr) { + uint64_t tmp64 = 0; + + /* Enable Write Protect, inhibiting writing to read-only pages */ + CPU_CR_READ(cr0, &tmp64); + CPU_CR_WRITE(cr0, tmp64 | CR0_WP); + CPU_CR_WRITE(cr3, pml4_base_addr); }