Skip to content

Commit

Permalink
cpu: require PGE and NX support
Browse files Browse the repository at this point in the history
All platforms capable of virtualization support PGE and NX, so there is
no reason to make these features optional in the SVSM code base.

Signed-off-by: Jon Lange <[email protected]>
  • Loading branch information
msft-jlange committed Jul 24, 2024
1 parent 33a191e commit ca6fea7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
8 changes: 5 additions & 3 deletions kernel/src/cpu/control_regs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ pub fn cr4_init() {

cr4.insert(CR4Flags::PSE); // Enable Page Size Extensions

if cpu_has_pge() {
cr4.insert(CR4Flags::PGE); // Enable Global Pages
}
// All processors that are capable of virtualization will support global
// page table entries, so there is no reason to support any processor that
// does not enumerate PGE capability.
assert!(cpu_has_pge(), "CPU does not support PGE");

cr4.insert(CR4Flags::PGE); // Enable Global Pages
write_cr4(cr4);
}

Expand Down
8 changes: 5 additions & 3 deletions kernel/src/cpu/efer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ pub fn write_efer(efer: EFERFlags) {
pub fn efer_init() {
let mut efer = read_efer();

if cpu_has_nx() {
efer.insert(EFERFlags::NXE);
}
// All processors that are capable of virtualization will support
// no-execute table entries, so there is no reason to support any processor
// that does not enumerate NX capability.
assert!(cpu_has_nx(), "CPU does not support NX");

efer.insert(EFERFlags::NXE);
write_efer(efer);
}
9 changes: 1 addition & 8 deletions kernel/src/mm/pagetable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use crate::address::{Address, PhysAddr, VirtAddr};
use crate::cpu::control_regs::write_cr3;
use crate::cpu::features::{cpu_has_nx, cpu_has_pge};
use crate::cpu::flush_tlb_global_sync;
use crate::error::SvsmError;
use crate::locking::{LockGuard, SpinLock};
Expand Down Expand Up @@ -57,13 +56,7 @@ pub fn paging_init_early(platform: &dyn SvsmPlatform, vtom: u64) -> ImmutAfterIn
pub fn paging_init(platform: &dyn SvsmPlatform, vtom: u64) -> ImmutAfterInitResult<()> {
init_encrypt_mask(platform, vtom.try_into().unwrap())?;

let mut feature_mask = PTEntryFlags::all();
if !cpu_has_nx() {
feature_mask.remove(PTEntryFlags::NX);
}
if !cpu_has_pge() {
feature_mask.remove(PTEntryFlags::GLOBAL);
}
let feature_mask = PTEntryFlags::all();
FEATURE_MASK.reinit(&feature_mask)
}

Expand Down

0 comments on commit ca6fea7

Please sign in to comment.