diff --git a/Cargo.toml b/Cargo.toml index 4fb31bd1b4..ba146c4ab2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,7 +45,7 @@ raw-cpuid = "10.2.0" x86 = { version = "0.47.0", default-features = false } [features] -default = ["acpi", "multi_core", "graphical_debug", "serial_debug", "x86_smap"] +default = ["acpi", "multi_core", "graphical_debug", "serial_debug"] acpi = [] doc = [] graphical_debug = [] @@ -58,12 +58,6 @@ serial_debug = [] system76_ec_debug = [] slab = ["slab_allocator"] -# TODO: Either wait for LLVM 12 and use target_feature, or use another system for cpu features -x86_fsgsbase = [] - -# Enables SMAP if available, on x86_64. Ignored on other architectures. -x86_smap = [] - [profile.dev] # Avoids having to define the eh_personality lang item and reduces kernel size panic = "abort" diff --git a/src/arch/x86_64/gdt.rs b/src/arch/x86_64/gdt.rs index b0bf641481..db76e89354 100644 --- a/src/arch/x86_64/gdt.rs +++ b/src/arch/x86_64/gdt.rs @@ -206,7 +206,7 @@ pub unsafe fn init_paging(stack_offset: usize, cpu_id: LogicalCpuId) { }) }); - if cfg!(feature = "x86_fsgsbase") { + if cfg!(cpu_feature_always = "fsgsbase") { assert!(cpu_supports_fsgsbase, "running kernel with features not supported by the current CPU"); x86::controlregs::cr4_write(x86::controlregs::cr4() | x86::controlregs::Cr4::CR4_ENABLE_FSGSBASE); diff --git a/src/arch/x86_64/misc.rs b/src/arch/x86_64/misc.rs index 29b191d8f4..33f3268b50 100644 --- a/src/arch/x86_64/misc.rs +++ b/src/arch/x86_64/misc.rs @@ -23,7 +23,7 @@ pub unsafe fn init(cpu_id: LogicalCpuId) { // obvious reasons. x86::controlregs::cr4_write(x86::controlregs::cr4() | Cr4::CR4_ENABLE_SMEP); } - if has_ext_feat(|feat| feat.has_smap()) && cfg!(feature = "x86_smap") { + if has_ext_feat(|feat| feat.has_smap()) && cfg!(cpu_feature_always = "smap") { // SMAP (Supervisor-Mode Access Prevention) forbids the kernel from accessing any // userspace-accessible pages, with the necessary exception of RFLAGS.AC = 1. This limits // user-memory accesses to the UserSlice wrapper, so that no code outside of usercopy diff --git a/src/arch/x86_64/mod.rs b/src/arch/x86_64/mod.rs index 704ca0eac0..ddc149b236 100644 --- a/src/arch/x86_64/mod.rs +++ b/src/arch/x86_64/mod.rs @@ -64,7 +64,7 @@ pub mod flags { pub unsafe extern "C" fn arch_copy_to_user(dst: usize, src: usize, len: usize) -> u8 { // TODO: LFENCE (spectre_v1 mitigation)? - #[cfg(not(feature = "x86_smap"))] + #[cfg(cpu_feature_never = "smap")] core::arch::asm!(" xor eax, eax mov rcx, rdx @@ -72,7 +72,7 @@ pub unsafe extern "C" fn arch_copy_to_user(dst: usize, src: usize, len: usize) - ret ", options(noreturn)); - #[cfg(feature = "x86_smap")] + #[cfg(cpu_feature_always = "smap")] core::arch::asm!(" xor eax, eax mov rcx, rdx diff --git a/src/arch/x86_64/start.rs b/src/arch/x86_64/start.rs index ca538cd88a..bdeed30134 100644 --- a/src/arch/x86_64/start.rs +++ b/src/arch/x86_64/start.rs @@ -285,7 +285,7 @@ macro_rules! inner_pit_unmap( } ); -#[cfg(not(feature = "x86_fsgsbase"))] +#[cfg(cpu_feature_never = "fsgsbase")] macro_rules! save_fsgsbase( () => { " @@ -303,7 +303,7 @@ macro_rules! save_fsgsbase( " } ); -#[cfg(feature = "x86_fsgsbase")] +#[cfg(cpu_feature_always = "fsgsbase")] macro_rules! save_fsgsbase( () => { " @@ -314,7 +314,7 @@ macro_rules! save_fsgsbase( } ); -#[cfg(feature = "x86_fsgsbase")] +#[cfg(cpu_feature_always = "fsgsbase")] macro_rules! restore_fsgsbase( () => { " @@ -324,7 +324,7 @@ macro_rules! restore_fsgsbase( } ); -#[cfg(not(feature = "x86_fsgsbase"))] +#[cfg(cpu_feature_never = "fsgsbase")] macro_rules! restore_fsgsbase( () => { " diff --git a/src/context/arch/x86_64.rs b/src/context/arch/x86_64.rs index 2f9900d147..33774682aa 100644 --- a/src/context/arch/x86_64.rs +++ b/src/context/arch/x86_64.rs @@ -146,7 +146,7 @@ pub unsafe fn switch_to(prev: &mut super::Context, next: &mut super::Context) { // This is so much shorter in Rust! - if cfg!(feature = "x86_fsgsbase") { + if cfg!(cpu_feature_always = "fsgsbase") { prev.arch.fsbase = rdfsbase() as usize; wrfsbase(next.arch.fsbase as u64); swapgs(); diff --git a/src/scheme/proc.rs b/src/scheme/proc.rs index 3eb7519de7..71d64dc0d3 100644 --- a/src/scheme/proc.rs +++ b/src/scheme/proc.rs @@ -421,14 +421,14 @@ impl ProcScheme { #[cfg(target_arch = "x86_64")] fn read_env_regs(&self, info: &Info) -> Result { let (fsbase, gsbase) = if info.pid == context::context_id() { - #[cfg(not(feature = "x86_fsgsbase"))] + #[cfg(cpu_feature_never = "fsgsbase")] unsafe { ( x86::msr::rdmsr(x86::msr::IA32_FS_BASE), x86::msr::rdmsr(x86::msr::IA32_KERNEL_GSBASE), ) } - #[cfg(feature = "x86_fsgsbase")] + #[cfg(cpu_feature_always = "fsgsbase")] unsafe { use x86::bits64::segmentation::*; @@ -504,7 +504,7 @@ impl ProcScheme { } if info.pid == context::context_id() { - #[cfg(not(feature = "x86_fsgsbase"))] + #[cfg(cpu_feature_never = "fsgsbase")] unsafe { x86::msr::wrmsr(x86::msr::IA32_FS_BASE, regs.fsbase as u64); // We have to write to KERNEL_GSBASE, because when the kernel returns to @@ -518,7 +518,7 @@ impl ProcScheme { } } } - #[cfg(feature = "x86_fsgsbase")] + #[cfg(cpu_feature_always = "fsgsbase")] unsafe { use x86::bits64::segmentation::*;