From bc01491bc91835e631d03812479117ad222e9659 Mon Sep 17 00:00:00 2001 From: Travis Geiselbrecht Date: Tue, 8 Apr 2025 23:46:18 -0700 Subject: [PATCH] [arch][x86][mmu] disable SMAP, add PGE feature 32 and 64 bit: - For now SMAP causes the mmu unit tests to fail, so disable. - Make sure CR4.PGE is set if present. - Make sure the rest of the system knows that user aspaces are available on 32bit. --- arch/x86/32/mmu.c | 14 +++++++++++++- arch/x86/64/mmu.c | 11 +++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/arch/x86/32/mmu.c b/arch/x86/32/mmu.c index e00a28c1..3b2a6a51 100644 --- a/arch/x86/32/mmu.c +++ b/arch/x86/32/mmu.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -411,7 +412,7 @@ int arch_mmu_map(arch_aspace_t * const aspace, const vaddr_t vaddr, const paddr_ bool arch_mmu_supports_nx_mappings(void) { return false; } bool arch_mmu_supports_ns_mappings(void) { return false; } -bool arch_mmu_supports_user_aspaces(void) { return false; } +bool arch_mmu_supports_user_aspaces(void) { return true; } /* called once per cpu as it is brought up */ void x86_mmu_early_init_percpu(void) { @@ -419,6 +420,17 @@ void x86_mmu_early_init_percpu(void) { uint32_t cr0 = x86_get_cr0(); cr0 |= X86_CR0_WP; x86_set_cr0(cr0); + + /* Set some mmu control bits in CR4 */ + uint32_t cr4 = x86_get_cr4(); + if (x86_feature_test(X86_FEATURE_PGE)) + cr4 |= X86_CR4_PGE; + if (x86_feature_test(X86_FEATURE_SMEP)) + cr4 |= X86_CR4_SMEP; + /* TODO: enable SMAP when the rest of the system is ready for it */ + //if (x86_feature_test(X86_FEATURE_SMAP)) + // cr4 |= X86_CR4_SMAP; + x86_set_cr4(cr4); } void x86_mmu_early_init(void) { diff --git a/arch/x86/64/mmu.c b/arch/x86/64/mmu.c index fd08fb1a..3d3c78f9 100644 --- a/arch/x86/64/mmu.c +++ b/arch/x86/64/mmu.c @@ -632,12 +632,15 @@ void x86_mmu_early_init_percpu(void) { cr0 |= X86_CR0_WP; x86_set_cr0(cr0); - /* Setting the SMEP & SMAP bit in CR4 */ - uint64_t cr4 = x86_get_cr4(); + /* Set some mmu control bits in CR4 */ + uint32_t cr4 = x86_get_cr4(); + if (x86_feature_test(X86_FEATURE_PGE)) + cr4 |= X86_CR4_PGE; if (x86_feature_test(X86_FEATURE_SMEP)) cr4 |= X86_CR4_SMEP; - if (x86_feature_test(X86_FEATURE_SMAP)) - cr4 |= X86_CR4_SMAP; + /* TODO: enable SMAP when the rest of the system is ready for it */ + //if (x86_feature_test(X86_FEATURE_SMAP)) + // cr4 |= X86_CR4_SMAP; x86_set_cr4(cr4); /* Set NXE bit in MSR_EFER */