Skip to content

Commit

Permalink
requests: Split up requests.rs
Browse files Browse the repository at this point in the history
To facilitate platform abstraction, split requests.rs into:

- kernel/src/sev/caa.rs: implementation for the SVSM Calling Area
- kernel/src/platform/snp_requests.rs: SEV-specific request processing

No functional change intended.

Signed-off-by: Peter Fang <[email protected]>
  • Loading branch information
peterfang committed Dec 13, 2024
1 parent b50c35d commit 10c2df4
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 52 deletions.
2 changes: 1 addition & 1 deletion kernel/src/cpu/apic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::error::SvsmError;
use crate::mm::GuestPtr;
use crate::platform::guest_cpu::GuestCpuState;
use crate::platform::SVSM_PLATFORM;
use crate::requests::SvsmCaa;
use crate::sev::caa::SvsmCaa;
use crate::sev::hv_doorbell::HVExtIntStatus;
use crate::types::GUEST_VMPL;

Expand Down
4 changes: 1 addition & 3 deletions kernel/src/cpu/smp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +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::SvsmPlatform;
use crate::platform::SVSM_PLATFORM;
use crate::requests::{request_loop, request_processing_main};
use crate::platform::{request_loop, request_processing_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
1 change: 0 additions & 1 deletion kernel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ pub mod locking;
pub mod mm;
pub mod platform;
pub mod protocols;
pub mod requests;
pub mod serial;
pub mod sev;
pub mod string;
Expand Down
2 changes: 2 additions & 0 deletions kernel/src/platform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ pub mod snp;
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
2 changes: 1 addition & 1 deletion kernel/src/platform/snp_fw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

extern crate alloc;

use super::snp_requests::update_mappings;
use crate::address::PhysAddr;
use crate::config::SvsmConfig;
use crate::cpu::cpuid::copy_cpuid_table_to;
use crate::cpu::percpu::{current_ghcb, this_cpu, this_cpu_shared};
use crate::error::SvsmError;
use crate::mm::PerCPUPageMappingGuard;
use crate::platform::PageStateChangeOp;
use crate::requests::update_mappings;
use crate::sev::{pvalidate, rmp_adjust, secrets_page, PvalidateOp, RMPFlags};
use crate::types::{PageSize, GUEST_VMPL, PAGE_SIZE};
use crate::utils::fw_meta::{find_table, RawMetaBuffer, Uuid};
Expand Down
44 changes: 1 addition & 43 deletions kernel/src/requests.rs → kernel/src/platform/snp_requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::mm::GuestPtr;
use crate::protocols::apic::apic_protocol_request;
use crate::protocols::core::core_protocol_request;
use crate::protocols::errors::{SvsmReqError, SvsmResultCode};
use crate::sev::caa::SvsmCaa;
use crate::sev::ghcb::switch_to_vmpl;

#[cfg(all(feature = "vtpm", not(test)))]
Expand All @@ -21,49 +22,6 @@ use crate::types::GUEST_VMPL;
use crate::utils::halt;
use cpuarch::vmsa::GuestVMExit;

/// The SVSM Calling Area (CAA)
#[repr(C, packed)]
#[derive(Debug, Clone, Copy)]
pub struct SvsmCaa {
call_pending: u8,
mem_available: u8,
pub no_eoi_required: u8,
_rsvd: [u8; 5],
}

impl SvsmCaa {
/// Returns a copy of the this CAA with the `call_pending` field cleared.
#[inline]
const fn serviced(self) -> Self {
Self {
call_pending: 0,
..self
}
}

/// Returns a copy of the this CAA with the `no_eoi_required` flag updated
#[inline]
pub const fn update_no_eoi_required(self, no_eoi_required: u8) -> Self {
Self {
no_eoi_required,
..self
}
}

/// A CAA with all of its fields set to zero.
#[inline]
pub const fn zeroed() -> Self {
Self {
call_pending: 0,
mem_available: 0,
no_eoi_required: 0,
_rsvd: [0; 5],
}
}
}

const _: () = assert!(core::mem::size_of::<SvsmCaa>() == 8);

/// Returns true if there is a valid VMSA mapping
pub fn update_mappings() -> Result<(), SvsmError> {
let cpu = this_cpu();
Expand Down
2 changes: 1 addition & 1 deletion kernel/src/protocols/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::mm::{valid_phys_address, writable_phys_addr, GuestPtr};
use crate::protocols::apic::{APIC_PROTOCOL, APIC_PROTOCOL_VERSION_MAX, APIC_PROTOCOL_VERSION_MIN};
use crate::protocols::errors::SvsmReqError;
use crate::protocols::RequestParams;
use crate::requests::SvsmCaa;
use crate::sev::caa::SvsmCaa;
use crate::sev::utils::{
pvalidate, rmp_clear_guest_vmsa, rmp_grant_guest_access, rmp_revoke_guest_access,
rmp_set_guest_vmsa, PvalidateOp, RMPFlags, SevSnpError,
Expand Down
48 changes: 48 additions & 0 deletions kernel/src/sev/caa.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
//
// Copyright (c) 2022-2023 SUSE LLC
//
// Author: Joerg Roedel <[email protected]>

const _: () = assert!(core::mem::size_of::<SvsmCaa>() == 8);

/// The SVSM Calling Area (CAA)
#[repr(C, packed)]
#[derive(Debug, Clone, Copy)]
pub struct SvsmCaa {
pub call_pending: u8,
mem_available: u8,
pub no_eoi_required: u8,
_rsvd: [u8; 5],
}

impl SvsmCaa {
/// Returns a copy of the this CAA with the `call_pending` field cleared.
#[inline]
pub const fn serviced(self) -> Self {
Self {
call_pending: 0,
..self
}
}

/// Returns a copy of the this CAA with the `no_eoi_required` flag updated
#[inline]
pub const fn update_no_eoi_required(self, no_eoi_required: u8) -> Self {
Self {
no_eoi_required,
..self
}
}

/// A CAA with all of its fields set to zero.
#[inline]
pub const fn zeroed() -> Self {
Self {
call_pending: 0,
mem_available: 0,
no_eoi_required: 0,
_rsvd: [0; 5],
}
}
}
1 change: 1 addition & 0 deletions kernel/src/sev/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//
// Author: Joerg Roedel <[email protected]>

pub mod caa;
pub mod ghcb;
pub mod hv_doorbell;
pub mod msr_protocol;
Expand Down
5 changes: 3 additions & 2 deletions kernel/src/svsm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ 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, SvsmPlatformCell, SVSM_PLATFORM};
use svsm::requests::{request_loop, request_processing_main};
use svsm::platform::{
init_platform_type, request_loop, request_processing_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

0 comments on commit 10c2df4

Please sign in to comment.