Skip to content

Commit

Permalink
platform: Add abstractions for request processing
Browse files Browse the repository at this point in the history
Add new abstractions to SvsmPlatform:

- request_task() is the kernel task for request processing
- request_loop() is the main vCPU request loop

Only SEV-SNP platforms do useful things in their implementations right
now.

Signed-off-by: Peter Fang <[email protected]>
  • Loading branch information
peterfang committed Dec 13, 2024
1 parent 10c2df4 commit fd4346e
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 12 deletions.
6 changes: 3 additions & 3 deletions kernel/src/cpu/smp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::cpu::shadow_stack::{is_cet_ss_supported, SCetFlags, MODE_64BIT, S_CET
use crate::cpu::sse::sse_init;
use crate::enable_shadow_stacks;
use crate::error::SvsmError;
use crate::platform::{request_loop, request_processing_main, SvsmPlatform, SVSM_PLATFORM};
use crate::platform::{request_task_main, SvsmPlatform, SVSM_PLATFORM};
use crate::task::{schedule_init, start_kernel_task};
use crate::utils::immut_after_init::immut_after_init_set_multithreaded;

Expand Down Expand Up @@ -72,8 +72,8 @@ fn start_ap() {

#[no_mangle]
pub extern "C" fn ap_request_loop() {
start_kernel_task(request_processing_main, String::from("request-processing"))
start_kernel_task(request_task_main, String::from("request-processing"))
.expect("Failed to launch request processing task");
request_loop();
SVSM_PLATFORM.request_loop();
panic!("Returned from request_loop!");
}
11 changes: 10 additions & 1 deletion kernel/src/platform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ pub mod tdp;
mod snp_fw;
mod snp_requests;
pub use snp_fw::{parse_fw_meta_data, SevFWMetaData};
pub use snp_requests::{request_loop, request_processing_main};

use native::NativePlatform;
use snp::SnpPlatform;
Expand Down Expand Up @@ -168,6 +167,12 @@ pub trait SvsmPlatform {
cpu: &PerCpu,
context: &hyperv::HvInitialVpContext,
) -> Result<(), SvsmError>;

/// Entry point for the kernel request task.
fn request_task(&self) {}

/// Enter the main vCPU loop.
fn request_loop(&self);
}

//FIXME - remove Copy trait
Expand Down Expand Up @@ -225,3 +230,7 @@ pub fn halt() {
SvsmPlatformType::Tdp => TdpPlatform::halt(),
}
}

pub extern "C" fn request_task_main() {
SVSM_PLATFORM.request_task();
}
2 changes: 2 additions & 0 deletions kernel/src/platform/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,6 @@ impl SvsmPlatform for NativePlatform {

todo!();
}

fn request_loop(&self) {}
}
10 changes: 9 additions & 1 deletion kernel/src/platform/snp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use super::snp_fw::{
copy_tables_to_fw, launch_fw, prepare_fw_launch, print_fw_meta, validate_fw, validate_fw_memory,
};
use super::{snp_requests, PageEncryptionMasks, PageStateChangeOp, PageValidateOp, SvsmPlatform};
use crate::address::{Address, PhysAddr, VirtAddr};
use crate::config::SvsmConfig;
use crate::console::init_svsm_console;
Expand All @@ -19,7 +20,6 @@ use crate::hyperv;
use crate::io::IOPort;
use crate::mm::memory::write_guest_memory_map;
use crate::mm::{PerCPUPageMappingGuard, PAGE_SIZE, PAGE_SIZE_2M};
use crate::platform::{PageEncryptionMasks, PageStateChangeOp, PageValidateOp, SvsmPlatform};
use crate::sev::ghcb::GHCBIOSize;
use crate::sev::hv_doorbell::current_hv_doorbell;
use crate::sev::msr_protocol::{
Expand Down Expand Up @@ -330,6 +330,14 @@ impl SvsmPlatform for SnpPlatform {

current_ghcb().ap_create(vmsa_pa, cpu.get_apic_id().into(), 0, sev_features)
}

fn request_task(&self) {
snp_requests::request_processing_main();
}

fn request_loop(&self) {
snp_requests::request_loop();
}
}

#[derive(Clone, Copy, Debug, Default)]
Expand Down
3 changes: 1 addition & 2 deletions kernel/src/platform/snp_requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,7 @@ pub fn request_loop() {
}
}

#[no_mangle]
pub extern "C" fn request_processing_main() {
pub fn request_processing_main() {
let apic_id = this_cpu().get_apic_id();

log::info!("Launching request-processing task on CPU {}", apic_id);
Expand Down
4 changes: 4 additions & 0 deletions kernel/src/platform/tdp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ impl SvsmPlatform for TdpPlatform {
) -> Result<(), SvsmError> {
todo!();
}

fn request_loop(&self) {
todo!();
}
}

#[derive(Clone, Copy, Debug, Default)]
Expand Down
8 changes: 3 additions & 5 deletions kernel/src/svsm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ use svsm::mm::pagetable::paging_init;
use svsm::mm::virtualrange::virt_log_usage;
use svsm::mm::{init_kernel_mapping_info, FixedAddressMappingRange};
use svsm::platform;
use svsm::platform::{
init_platform_type, request_loop, request_processing_main, SvsmPlatformCell, SVSM_PLATFORM,
};
use svsm::platform::{init_platform_type, request_task_main, SvsmPlatformCell, SVSM_PLATFORM};
use svsm::sev::secrets_page_mut;
use svsm::svsm_paging::{init_page_table, invalidate_early_boot_memory};
use svsm::task::exec_user;
Expand Down Expand Up @@ -324,7 +322,7 @@ pub extern "C" fn svsm_main() {
panic!("Failed to launch FW: {e:#?}");
}

start_kernel_task(request_processing_main, String::from("request-processing"))
start_kernel_task(request_task_main, String::from("request-processing"))
.expect("Failed to launch request processing task");

#[cfg(test)]
Expand All @@ -335,7 +333,7 @@ pub extern "C" fn svsm_main() {
Err(e) => log::info!("Failed to launch /init: {e:#?}"),
}

request_loop();
SVSM_PLATFORM.request_loop();

panic!("Road ends here!");
}
Expand Down

0 comments on commit fd4346e

Please sign in to comment.