From 4c0b490db9bf09c5ef1608640178076720ebbd34 Mon Sep 17 00:00:00 2001 From: Taylor R Campbell Date: Thu, 7 Apr 2022 18:14:04 +0000 Subject: [PATCH] x86: Assert SMAP stays put in CR4. Apparently it isn't staying put, so maybe this will help to find where it escaped. --- sys/arch/x86/x86/cpu.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sys/arch/x86/x86/cpu.c b/sys/arch/x86/x86/cpu.c index ba3a634a515f..b6cb761f8282 100644 --- a/sys/arch/x86/x86/cpu.c +++ b/sys/arch/x86/x86/cpu.c @@ -687,6 +687,9 @@ cpu_init(struct cpu_info *ci) lcr4(cr4); } + if (cpu_feature[5] & CPUID_SEF_SMAP) + KASSERT(rcr4() & CR4_SMAP); + /* * Changing CR4 register may change cpuid values. For example, setting * CR4_OSXSAVE sets CPUID2_OSXSAVE. The CPUID2_OSXSAVE is in @@ -700,6 +703,9 @@ cpu_init(struct cpu_info *ci) ci->ci_feat_val[1] = descs[2]; } + if (cpu_feature[5] & CPUID_SEF_SMAP) + KASSERT(rcr4() & CR4_SMAP); + if (x86_fpu_save >= FPU_SAVE_FXSAVE) { fpuinit_mxcsr_mask(); }