Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

platform/native: require the use of X2APIC #587

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion kernel/src/platform/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use crate::address::{PhysAddr, VirtAddr};
use crate::console::init_svsm_console;
use crate::cpu::cpuid::CpuidResult;
use crate::cpu::msr::write_msr;
use crate::cpu::msr::{read_msr, write_msr};
use crate::cpu::percpu::PerCpu;
use crate::error::SvsmError;
use crate::hyperv;
Expand All @@ -23,6 +23,9 @@ use crate::mm::virt_to_phys;
#[cfg(test)]
use bootlib::platform::SvsmPlatformType;

const MSR_APIC_BASE: u32 = 0x1B;
const APIC_X2_ENABLE_MASK: u64 = 0xC00;

const APIC_MSR_EOI: u32 = 0x80B;
const APIC_MSR_ICR: u32 = 0x830;

Expand All @@ -41,6 +44,11 @@ impl NativePlatform {

impl Default for NativePlatform {
fn default() -> Self {
// Execution is not possible unless X2APIC is supported.
let features = CpuidResult::get(1, 0);
if (features.ecx & 0x200000) == 0 {
panic!("X2APIC is not supported");
}
joergroedel marked this conversation as resolved.
Show resolved Hide resolved
Self::new()
}
}
Expand Down Expand Up @@ -78,6 +86,15 @@ impl SvsmPlatform for NativePlatform {
}

fn setup_percpu_current(&self, _cpu: &PerCpu) -> Result<(), SvsmError> {
// Enable X2APIC mode.
// SAFETY: accesses to the APIC_BASE MSR are safe if the address is not
// being changed.
let apic_base = read_msr(MSR_APIC_BASE);
let apic_base_x2_enabled = apic_base | APIC_X2_ENABLE_MASK;
if apic_base != apic_base_x2_enabled {
write_msr(MSR_APIC_BASE, apic_base_x2_enabled);
}

Ok(())
}

Expand Down
Loading