Skip to content

Commit

Permalink
use vc_terminate helpers directly
Browse files Browse the repository at this point in the history
Since the vc_terminate helpers are now marked as noreturn, we can use
them directly in all places such that the compiler will not complain
that the Err path in the match arm is not returning the same value as
success path.

Signed-off-by: Vikram Narayanan <vikram186@gmail.com>
  • Loading branch information
arkivm committed Nov 23, 2022
1 parent fca5943 commit 901b4fc
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 18 deletions.
8 changes: 4 additions & 4 deletions src/bios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ fn find_bios_guid_entry(bios_info: &mut BiosInfo, guid: &str) -> Option<u64> {

let target_guid: Uuid = match Uuid::parse_str(guid) {
Ok(g) => g,
Err(_e) => vc_terminate(SVSM_REASON_CODE_SET, SVSM_TERM_BIOS_FORMAT),
Err(_e) => vc_terminate_svsm_bios(),
};

unsafe { __find_bios_guid_entry(bios_info, target_guid, &mut avail_len, &mut p) }
Expand Down Expand Up @@ -216,7 +216,7 @@ unsafe fn __find_snp_section(bios_info: &mut BiosInfo, stype: u32, p: u64) -> Op
fn find_snp_section(bios_info: &mut BiosInfo, stype: u32) -> Option<SnpSection> {
let p: u64 = match find_bios_guid_entry(bios_info, OVMF_SNP_ENTRY_GUID) {
Some(p) => p,
None => vc_terminate(SVSM_REASON_CODE_SET, SVSM_TERM_BIOS_FORMAT),
None => vc_terminate_svsm_bios(),
};

unsafe { __find_snp_section(bios_info, stype, p) }
Expand Down Expand Up @@ -328,7 +328,7 @@ fn parse_bios_guid_table(bios_info: &mut BiosInfo) -> bool {
pub fn start_bios() {
let (bios_va, bios_size) = match fwcfg_map_bios() {
Some(t) => t,
None => vc_terminate(SVSM_REASON_CODE_SET, SVSM_TERM_FW_CFG_ERROR),
None => vc_terminate_svsm_fwcfg(),
};

let mut bios_info: BiosInfo = BiosInfo::new(bios_va, bios_size);
Expand All @@ -338,7 +338,7 @@ pub fn start_bios() {

let caa: PhysAddr = match locate_bios_ca_page(&mut bios_info) {
Some(p) => p,
None => vc_terminate(SVSM_REASON_CODE_SET, SVSM_TERM_BIOS_FORMAT),
None => vc_terminate_svsm_bios(),
};

unsafe {
Expand Down
4 changes: 2 additions & 2 deletions src/cpu/percpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ unsafe fn __percpu_init(init_frame: PhysFrame, init_count: u64) -> u64 {
if count != init_count {
frame = match mem_allocate_frames(count) {
Some(f) => f,
None => vc_terminate(SVSM_REASON_CODE_SET, SVSM_TERM_ENOMEM),
None => vc_terminate_svsm_enomem(),
};
} else {
frame = init_frame;
Expand Down Expand Up @@ -456,7 +456,7 @@ pub fn percpu_init() {
let init_count: u64 = PAGE_COUNT!(PERCPU_SIZE);
let init_frame: PhysFrame = match mem_allocate_frames(init_count) {
Some(f) => f,
None => vc_terminate(SVSM_REASON_CODE_SET, SVSM_TERM_ENOMEM),
None => vc_terminate_svsm_enomem(),
};
let count: u64;

Expand Down
6 changes: 3 additions & 3 deletions src/cpu/smp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ fn alloc_vmsa() -> PhysFrame {
// Allocate one frame
let mut frame: PhysFrame = match mem_allocate_frames(1) {
Some(f) => f,
None => vc_terminate(SVSM_REASON_CODE_SET, SVSM_TERM_ENOMEM),
None => vc_terminate_svsm_enomem(),
};

// VMSA pages must not be 2MB aligned, check for that
Expand All @@ -104,7 +104,7 @@ fn alloc_vmsa() -> PhysFrame {
// Allocate two frames and ...
frame = match mem_allocate_frames(2) {
Some(f) => f,
None => vc_terminate(SVSM_REASON_CODE_SET, SVSM_TERM_ENOMEM),
None => vc_terminate_svsm_enomem(),
};

// ... chose a frame which is not 2MB aligned
Expand Down Expand Up @@ -156,7 +156,7 @@ fn create_bios_vmsa() -> VirtAddr {
fn create_svsm_stack() -> VirtAddr {
let frame: PhysFrame = match mem_allocate_frames(SVSM_STACK_PAGES) {
Some(f) => f,
None => vc_terminate(SVSM_REASON_CODE_SET, SVSM_TERM_ENOMEM),
None => vc_terminate_svsm_enomem(),
};

let guard_va: VirtAddr = pgtable_pa_to_va(frame.start_address());
Expand Down
4 changes: 2 additions & 2 deletions src/cpu/tss.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const IST_STACK_PAGES: u64 = 3;
unsafe fn create_tss() -> VirtAddr {
let tss_va: VirtAddr = match mem_allocate(size_of::<TaskStateSegment>()) {
Ok(f) => f,
Err(()) => vc_terminate(SVSM_REASON_CODE_SET, SVSM_TERM_ENOMEM),
Err(()) => vc_terminate_svsm_enomem(),
};

let tss: *mut TaskStateSegment = tss_va.as_mut_ptr();
Expand All @@ -37,7 +37,7 @@ unsafe fn create_tss() -> VirtAddr {

let frame: PhysFrame = match mem_allocate_frames(IST_STACK_PAGES) {
Some(f) => f,
None => vc_terminate(SVSM_REASON_CODE_SET, SVSM_TERM_ENOMEM),
None => vc_terminate_svsm_enomem(),
};

let guard_va: VirtAddr = pgtable_pa_to_va(frame.start_address());
Expand Down
4 changes: 2 additions & 2 deletions src/cpu/vc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ pub fn vc_get_apic_ids(bsp_apic_id: u32) -> Vec<u32> {

let frame: PhysFrame = match mem_allocate_frames(pages) {
Some(f) => f,
None => vc_terminate(SVSM_REASON_CODE_SET, SVSM_TERM_ENOMEM),
None => vc_terminate_svsm_enomem(),
};
let pa: PhysAddr = frame.start_address();
let va: VirtAddr = pgtable_pa_to_va(pa);
Expand Down Expand Up @@ -955,7 +955,7 @@ fn perform_page_state_change(ghcb: *mut Ghcb, begin: PhysFrame, end: PhysFrame,
while op.header.cur_entry <= last_entry {
vc_perform_vmgexit(ghcb, GHCB_NAE_PSC, 0, 0);
if !(*ghcb).is_sw_exit_info_2_valid() || (*ghcb).sw_exit_info_2() != 0 {
vc_terminate(SVSM_REASON_CODE_SET, SVSM_TERM_PSC_ERROR);
vc_terminate_svsm_psc();
}

(*ghcb).shared_buffer(get_bytes, size);
Expand Down
6 changes: 3 additions & 3 deletions src/mem/fwcfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ lazy_static! {
static ref FW_CFG_DMA: SpinLock<&'static mut FwCfgDma> = {
let frame: PhysFrame = match mem_allocate_frame() {
Some(f) => f,
None => vc_terminate(SVSM_REASON_CODE_SET, SVSM_TERM_ENOMEM),
None => vc_terminate_svsm_enomem(),
};
let va: VirtAddr = pgtable_pa_to_va(frame.start_address());

Expand Down Expand Up @@ -219,11 +219,11 @@ fn find_file_selector(fname: &str) -> Option<u16> {
for f in files.iter() {
let nul: usize = match memchr(0, &f.name) {
Some(n) => n,
None => vc_terminate(SVSM_REASON_CODE_SET, SVSM_TERM_FW_CFG_ERROR),
None => vc_terminate_svsm_fwcfg(),
};
let n: &str = match core::str::from_utf8(&f.name[0..nul]) {
Ok(n) => n,
Err(_e) => vc_terminate(SVSM_REASON_CODE_SET, SVSM_TERM_FW_CFG_ERROR),
Err(_e) => vc_terminate_svsm_fwcfg(),
};

if n.eq(fname) {
Expand Down
4 changes: 2 additions & 2 deletions src/mem/ghcb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use crate::cpu::percpu::PERCPU;
use crate::cpu::percpu_count;
use crate::cpu::vc_register_ghcb;
use crate::cpu::vc_terminate;
use crate::cpu::vc_terminate_svsm_enomem;
use crate::globals::*;
use crate::mem::mem_allocate_frames;
use crate::mem::pgtable_make_pages_shared;
Expand Down Expand Up @@ -146,7 +146,7 @@ pub fn ghcb_init() {
let count: usize = percpu_count();
let frame: PhysFrame = match mem_allocate_frames(count as u64) {
Some(f) => f,
None => vc_terminate(SVSM_REASON_CODE_SET, SVSM_TERM_ENOMEM),
None => vc_terminate_svsm_enomem(),
};
let mut va: VirtAddr = pgtable_pa_to_va(frame.start_address());

Expand Down

0 comments on commit 901b4fc

Please sign in to comment.