Skip to content

Commit

Permalink
Merge pull request #494 from msft-jlange/ap_hv_doorbell
Browse files Browse the repository at this point in the history
platform: move AP #HV doorbell initialization to platform
  • Loading branch information
joergroedel authored Oct 24, 2024
2 parents cb198e7 + 9cf6b5e commit 934d044
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
5 changes: 0 additions & 5 deletions kernel/src/cpu/smp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ fn start_ap() {
.setup_on_cpu(SVSM_PLATFORM.as_dyn_ref())
.expect("setup_on_cpu() failed");

// Configure the #HV doorbell page as required.
this_cpu()
.configure_hv_doorbell()
.expect("configure_hv_doorbell() failed");

this_cpu()
.setup_idle_task(ap_request_loop)
.expect("Failed to allocated idle task for AP");
Expand Down
13 changes: 12 additions & 1 deletion kernel/src/platform/snp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ use crate::utils::MemoryRegion;
#[cfg(debug_assertions)]
use crate::mm::virt_to_phys;

use core::sync::atomic::{AtomicU32, Ordering};
use core::sync::atomic::{AtomicBool, AtomicU32, Ordering};

static SVSM_ENV_INITIALIZED: AtomicBool = AtomicBool::new(false);

static GHCB_IO_DRIVER: GHCBIOPort = GHCBIOPort::new();

Expand Down Expand Up @@ -112,6 +114,7 @@ impl SvsmPlatform for SnpPlatform {
fn env_setup_svsm(&self) -> Result<(), SvsmError> {
this_cpu().configure_hv_doorbell()?;
guest_request_driver_init();
SVSM_ENV_INITIALIZED.store(true, Ordering::Relaxed);
Ok(())
}

Expand All @@ -122,6 +125,14 @@ impl SvsmPlatform for SnpPlatform {

fn setup_percpu_current(&self, cpu: &PerCpu) -> Result<(), SvsmError> {
cpu.register_ghcb()?;

// #HV doorbell allocation can only occur if the SVSM environment has
// already been initialized. Skip allocation if not; it will be done
// during environment initialization.
if SVSM_ENV_INITIALIZED.load(Ordering::Relaxed) {
cpu.configure_hv_doorbell()?;
}

Ok(())
}

Expand Down

0 comments on commit 934d044

Please sign in to comment.