repo_name
stringlengths
1
62
dataset
stringclasses
1 value
lang
stringclasses
11 values
pr_id
int64
1
20.1k
owner
stringlengths
2
34
reviewer
stringlengths
2
39
diff_hunk
stringlengths
15
262k
code_review_comment
stringlengths
1
99.6k
svsm
github_2023
others
120
coconut-svsm
joergroedel
@@ -0,0 +1,33 @@ +use log::info; +use test::ShouldPanic; + +use crate::sev::msr_protocol::request_termination_msr; + +pub fn svsm_test_runner(test_cases: &[&test::TestDescAndFn]) { + info!("running {} tests", test_cases.len()); + for mut test_case in test_cases.iter().copied().copied() { + if test_case.des...
I wonder if we can use the qemu exit device here?
svsm
github_2023
others
113
coconut-svsm
joergroedel
@@ -0,0 +1,79 @@ +FUZZING +======= + +The COCONUT SVSM includes several fuzzing harnesses to find bugs in +security-critical interfaces. These do not currently provide coverage +of all interesting interfaces, so contributions are welcome. + +At the moment, fuzzing is done through +[cargo-fuzz](/rust-fuzz/cargo-fuzz). Y...
Can you please add a section describing the dependencies and how install them on openSUSE? For me it was `cargo-fuzz`, `clang` and `lld`.
svsm
github_2023
others
113
coconut-svsm
joergroedel
@@ -125,6 +125,10 @@ impl ACPITable { let content = ptr.get(..size).ok_or(SvsmError::Acpi)?; let mut buf = Vec::<u8>::new(); + #[cfg(fuzzing)] + if size > 0x1000 { + return Err(SvsmError::Mem); + }
Why is that needed?
svsm
github_2023
others
113
coconut-svsm
joergroedel
@@ -176,6 +180,10 @@ impl ACPITableBuffer { let size = file.size() as usize; let mut buf = Vec::<u8>::new(); + #[cfg(fuzzing)] + if size > 0x1000 { + return Err(SvsmError::Mem); + }
Same here, why is that needed?
svsm
github_2023
others
113
coconut-svsm
joergroedel
@@ -286,9 +294,10 @@ pub fn load_acpi_cpu_info(fw_cfg: &FwCfg) -> Result<Vec<ACPICPUInfo>, SvsmError> .content_ptr::<RawMADTEntryHeader>(offset) .ok_or(SvsmError::Acpi)?; let (madt_type, entry_len) = unsafe { ((*entry_ptr).entry_type, (*entry_ptr).entry_len) }; + let entry_len ...
This looks like a fix for an issue found by fuzzing. Can you please submit all such fixes in a separate PR, please? We can merge them independently of the fuzzer itself.
svsm
github_2023
others
113
coconut-svsm
joergroedel
@@ -124,6 +126,11 @@ impl<'a> FwCfg<'a> { self.select(FW_CFG_FILE_DIR); let n: u32 = self.read_be(); + #[cfg(fuzzing)] + if n > 0x1000 { + return Err(SvsmError::FwCfg(FwCfgError::TooManyFiles)); + } +
This does not need to be limited to fuzzing. I think we can safely assume a maximum supported buffer size for the fw_cfg file-list.
svsm
github_2023
others
113
coconut-svsm
Freax13
@@ -0,0 +1,230 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) 2023 SUSE LLC +// +// Author: Carlos López <carlos.lopez@suse.com> + +#![no_main] + +use arbitrary::Arbitrary; +use core::hint::black_box; +use libfuzzer_sys::fuzz_target; +use std::rc::Rc; +use std::sync::OnceLock; +use svsm::fs::Fi...
```suggestion fn get_idx<T>(v: &[T], idx: usize) -> Option<usize> { idx.checked_rem(v.len()) } ```
svsm
github_2023
others
113
coconut-svsm
Freax13
@@ -0,0 +1,230 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) 2023 SUSE LLC +// +// Author: Carlos López <carlos.lopez@suse.com> + +#![no_main] + +use arbitrary::Arbitrary; +use core::hint::black_box; +use libfuzzer_sys::fuzz_target; +use std::rc::Rc; +use std::sync::OnceLock; +use svsm::fs::Fi...
```suggestion /// A handle for a file that also holds its original name #[derive(Debug)] struct Handle<'a> { fd: FileHandle, name: &'a str, } ``` Allocating into an `Rc` is not needed here.
svsm
github_2023
others
113
coconut-svsm
Freax13
@@ -0,0 +1,230 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) 2023 SUSE LLC +// +// Author: Carlos López <carlos.lopez@suse.com> + +#![no_main] + +use arbitrary::Arbitrary; +use core::hint::black_box; +use libfuzzer_sys::fuzz_target; +use std::rc::Rc; +use std::sync::OnceLock; +use svsm::fs::Fi...
All callers except one then go on to use the returned index to index into the slice. Have you considered just returning an `Option<&T>` instead of `Option<usize>`?
svsm
github_2023
others
113
coconut-svsm
Freax13
@@ -245,15 +244,17 @@ fn find_table<'a>(uuid: &Uuid, mem: &'a [u8]) -> Option<&'a [u8]> { None } -pub fn parse_fw_meta_data() -> Result<SevFWMetaData, SvsmError> { +/// Parse the firmware metadata located at the memory page starting at `vstart`. +/// +/// # Safety +/// +/// The caller must ensure that the provi...
Should this function maybe just take a `&RawMetaBuffer` or `&[u8]`?
svsm
github_2023
others
113
coconut-svsm
Freax13
@@ -245,16 +244,18 @@ fn find_table<'a>(uuid: &Uuid, mem: &'a [u8]) -> Option<&'a [u8]> { None } -pub fn parse_fw_meta_data() -> Result<SevFWMetaData, SvsmError> { +/// Parse the firmware metadata from the given slice. +pub fn parse_fw_meta_data(mem: &[u8]) -> Result<SevFWMetaData, SvsmError> { let mut met...
Great job on the safety comments!
svsm
github_2023
others
122
coconut-svsm
roy-hopkins
@@ -37,7 +37,10 @@ pub const SVSM_CS_FLAGS: u16 = 0x29b; pub const SVSM_DS_FLAGS: u16 = 0xc93; pub const SVSM_TR_FLAGS: u16 = 0x89; -pub const GUEST_VMPL: usize = 1; +/// VMPL level the guest OS will be exectued at.
typo: executed
svsm
github_2023
others
126
coconut-svsm
joergroedel
@@ -125,3 +125,40 @@ pub fn free_stack(stack: VirtAddr) { STACK_ALLOC.lock().dealloc(stack); } + +#[cfg(test)] +mod tests { + use crate::mm::stack::*; + + #[test] + fn test_allocate_and_free_stack() { + /* + * For offline testing purposes, we can't + * really map physical memory....
The constant here looks like it can be expressed based on `SVSM_SHARED_STACK_BASE`
svsm
github_2023
others
126
coconut-svsm
joergroedel
@@ -125,3 +125,40 @@ pub fn free_stack(stack: VirtAddr) { STACK_ALLOC.lock().dealloc(stack); } + +#[cfg(test)] +mod tests { + use crate::mm::stack::*; + + #[test] + fn test_allocate_and_free_stack() { + /* + * For offline testing purposes, we can't + * really map physical memory....
And the expected base can be easier calculated using one of the STACK_SIZE or STACK_PAGES constants. Otherwise this test will always need adoption when we change the stack layout.
svsm
github_2023
others
97
coconut-svsm
roy-hopkins
@@ -0,0 +1,74 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) 2022-2023 SUSE LLC +// +// Author: Joerg Roedel <jroedel@suse.de> + +use super::VirtualMapping; +use crate::address::{PhysAddr, VirtAddr}; +use crate::error::SvsmError; +use crate::mm::address_space::{STACK_PAGES, STACK_SIZE}; +use cr...
Why is the guard page count related to the size of the stack itself? Is there some particular attack against the stack that is mitigated by this sizing? If so, then it might be good to put a comment here.
svsm
github_2023
others
97
coconut-svsm
roy-hopkins
@@ -0,0 +1,74 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) 2022-2023 SUSE LLC +// +// Author: Joerg Roedel <jroedel@suse.de> + +use super::VirtualMapping; +use crate::address::{PhysAddr, VirtAddr}; +use crate::error::SvsmError; +use crate::mm::address_space::{STACK_PAGES, STACK_SIZE}; +use cr...
Would it make more sense to pass the stack size in as a parameter? Would there be any situation where some tasks may require a larger kernel stack without having to increase the stack allocation for every task?
svsm
github_2023
others
97
coconut-svsm
roy-hopkins
@@ -0,0 +1,74 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) 2022-2023 SUSE LLC +// +// Author: Joerg Roedel <jroedel@suse.de> + +use super::VirtualMapping; +use crate::address::{PhysAddr, VirtAddr}; +use crate::error::SvsmError; +use crate::mm::address_space::{STACK_PAGES, STACK_SIZE}; +use cr...
Shouldn't this be `(STACK_PAGES + 2 * self.guard_pages).next_power_of_two()`?
svsm
github_2023
others
97
coconut-svsm
roy-hopkins
@@ -0,0 +1,51 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) 2022-2023 SUSE LLC +// +// Author: Joerg Roedel <jroedel@suse.de> + +use crate::address::{Address, PhysAddr}; +use crate::mm::pagetable::PTEntryFlags; + +use super::VirtualMapping; + +#[derive(Default, Debug)] +pub struct VMPhysMem { ...
We're going to need to support executable memory when loading modules.
svsm
github_2023
others
97
coconut-svsm
roy-hopkins
@@ -0,0 +1,257 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) 2022-2023 SUSE LLC +// +// Author: Joerg Roedel <jroedel@suse.de> + +use crate::address::{Address, VirtAddr}; +use crate::cpu::flush_tlb_global_sync; +use crate::error::SvsmError; +use crate::locking::RWLock; +use crate::mm::pagetabl...
Will `flags` ever be anything other than `PTEntryFlags::GLOBAL` or 0? It might make sense to use a boolean instead if that is the case. I guess it might be useful to set `PTEntryFlags::USER` at this level too though.
svsm
github_2023
others
97
coconut-svsm
roy-hopkins
@@ -0,0 +1,257 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) 2022-2023 SUSE LLC +// +// Author: Joerg Roedel <jroedel@suse.de> + +use crate::address::{Address, VirtAddr}; +use crate::cpu::flush_tlb_global_sync; +use crate::error::SvsmError; +use crate::locking::RWLock; +use crate::mm::pagetabl...
Probably ought to also check for `end >= (start + VMR_GRANULE)`. `alloc_page_tables()` arithmetic operations can overflow if end < start.
svsm
github_2023
others
97
coconut-svsm
roy-hopkins
@@ -0,0 +1,257 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) 2022-2023 SUSE LLC +// +// Author: Joerg Roedel <jroedel@suse.de> + +use crate::address::{Address, VirtAddr}; +use crate::cpu::flush_tlb_global_sync; +use crate::error::SvsmError; +use crate::locking::RWLock; +use crate::mm::pagetabl...
Does this need to handle when `vmm.page_size() == PAGE_SIZE_2M`?
svsm
github_2023
others
97
coconut-svsm
Freax13
@@ -745,3 +759,218 @@ impl DerefMut for PageTableRef { unsafe { &mut *self.pgtable_ptr } } } + +/// Represents a sub-tree of a page-table which can be mapped at a top-level index +#[derive(Default, Debug)] +struct RawPageTablePart { + page: PTPage, +} + +impl RawPageTablePart { + fn entry_to_page(e...
This method and the functions it's calling should be unsafe. Freeing up memory is intrinsically unsafe as the caller has to ensure that there are no use-after-free or double-free situations. For similar reasons either `PageTablePart::map_4k` or `PageTablePart::unmap_4k` (or both) have to be unsafe.
svsm
github_2023
others
97
coconut-svsm
Freax13
@@ -0,0 +1,145 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) 2022-2023 SUSE LLC +// +// Author: Joerg Roedel <jroedel@suse.de> + +use crate::address::{PhysAddr, VirtAddr}; +use crate::locking::RWLock; +use crate::mm::pagetable::PTEntryFlags; +use crate::types::{PAGE_SHIFT, PAGE_SIZE}; + +use c...
The `Send` implementation is incorrect as the `Rc` contained within `VMM` isn't `Send`. The `Sync` implementation is incorrect as the `RefCell` contained within `VMM` isn't `Sync`.
svsm
github_2023
others
97
coconut-svsm
Freax13
@@ -745,3 +759,218 @@ impl DerefMut for PageTableRef { unsafe { &mut *self.pgtable_ptr } } } + +/// Represents a sub-tree of a page-table which can be mapped at a top-level index +#[derive(Default, Debug)] +struct RawPageTablePart { + page: PTPage, +} + +impl RawPageTablePart { + fn entry_to_page(e...
The unsafe at the bottom seems dubious. How is it guaranteed that now other references to the page exist?
svsm
github_2023
others
97
coconut-svsm
roy-hopkins
@@ -18,7 +18,7 @@ all: svsm.bin test: cargo test --target=x86_64-unknown-linux-gnu - RUSTFLAGS="--cfg doctest" cargo test --target=x86_64-unknown-linux-gnu --doc +# RUSTFLAGS="--cfg doctest" cargo test --target=x86_64-unknown-linux-gnu --doc
This can be re-enabled now #119 has been merged.
svsm
github_2023
others
97
coconut-svsm
roy-hopkins
@@ -0,0 +1,110 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) 2022-2023 SUSE LLC +// +// Author: Joerg Roedel <jroedel@suse.de> + +use super::VirtualMapping; +use crate::address::{PhysAddr, VirtAddr}; +use crate::error::SvsmError; +use crate::mm::address_space::STACK_SIZE; +use crate::mm::paget...
I'm just looking at rebasing the task code against this and I think we're going to need a way to populate content within the stack pages using a temporary virtual address before the stack is mapped into a tasks's virtual memory space. When a task is first created, a `VMKernelStack` will be created for the task kern...
svsm
github_2023
others
97
coconut-svsm
Freax13
@@ -0,0 +1,218 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) 2022-2023 SUSE LLC +// +// Author: Joerg Roedel <jroedel@suse.de> + +use crate::address::{PhysAddr, VirtAddr}; +use crate::locking::RWLock; +use crate::mm::pagetable::PTEntryFlags; +use crate::types::{PAGE_SHIFT, PAGE_SIZE}; + +use i...
Have you considered using the [`Range`](https://doc.rust-lang.org/core/ops/struct.Range.html) type in the standard library instead?
svsm
github_2023
others
97
coconut-svsm
Freax13
@@ -0,0 +1,218 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) 2022-2023 SUSE LLC +// +// Author: Joerg Roedel <jroedel@suse.de> + +use crate::address::{PhysAddr, VirtAddr}; +use crate::locking::RWLock; +use crate::mm::pagetable::PTEntryFlags; +use crate::types::{PAGE_SHIFT, PAGE_SIZE}; + +use i...
`start` is a virtual page number, not an address.
svsm
github_2023
others
97
coconut-svsm
roy-hopkins
@@ -183,14 +184,23 @@ pub struct PerCpu { guest_vmsa: SpinLock<GuestVmsaRef>, reset_ip: u64, + /// PerCpu Virtual Memory Range + vm_range: VMR,
This is private but the `Tasks` structure needs access to this in order to update the task pagetable when performing a task switch and also to add a range when configuring a new task stack.
svsm
github_2023
others
111
coconut-svsm
00xc
@@ -13,17 +13,34 @@ use alloc::vec::Vec; use core::mem; use log; +/// ACPI Root System Description Pointer (RSDP) +/// used by ACPI programming interface #[derive(Debug, Default)] #[repr(C, packed)] struct RSDPDesc { + /// Signature must contain "RSD PTR" sig: [u8; 8], + /// Checksum to add to all oth...
This use of square brackets does not do anything, sadly. As far as I know, they only work for types, not variable names.
svsm
github_2023
others
111
coconut-svsm
00xc
@@ -764,18 +1164,29 @@ impl Elf64Hdr { } } +/// Program header entry in an ELF64 file #[derive(Debug)] pub struct Elf64Phdr { + /// Type of the program header entry pub p_type: Elf64Word, + /// Flags specifying the attributes of the segment pub p_flags: Elf64PhdrFlags, + /// Offset in the E...
These need to be `///` and be inside the `bitflags!` macro in order to show up in the generated docs.
svsm
github_2023
others
111
coconut-svsm
00xc
@@ -814,6 +1237,12 @@ impl Elf64Phdr { } } + /// Verifies the integrity and validity of the program header. + /// + /// # Returns + /// + /// Returns [`Ok(())`] if the program header is valid; otherwise, an [`Err`]
This should just be `Ok` without the parenthesis. This won't show up in the generated docs because it is a private function, so it is just a nitpick.
svsm
github_2023
others
111
coconut-svsm
00xc
@@ -599,6 +919,28 @@ impl<'a> Elf64File<'a> { } } + /// + /// This function processes dynamic relocations (relas) in the ELF file and applies them + /// to the loaded image. It takes a generic `rela_proc` parameter that should implement the + /// [`Elf64RelocProcessor`] trait, allowing custo...
Again, these won't render properly. Most of these can be fixed by using angle brackets (`<>`). For example: ```rust /// - [`Ok<None>`]: If no relocations ... ``` You may also simplify the doc by not writing out all the types if you wish so.
svsm
github_2023
others
111
coconut-svsm
00xc
@@ -599,6 +919,28 @@ impl<'a> Elf64File<'a> { } } + /// + /// This function processes dynamic relocations (relas) in the ELF file and applies them + /// to the loaded image. It takes a generic `rela_proc` parameter that should implement the + /// [`Elf64RelocProcessor`] trait, allowing custo...
This one still does not render properly
svsm
github_2023
others
111
coconut-svsm
00xc
@@ -1532,22 +2313,37 @@ impl<'a, RP: Elf64RelocProcessor> Elf64AppliedRelaIterator<'a, RP> { impl<'a, RP: Elf64RelocProcessor> Iterator for Elf64AppliedRelaIterator<'a, RP> { type Item = Result<Option<Elf64RelocOp>, ElfError>; + /// Advances the iterator to the next relocation operation, processes it, + /...
These ones as well
svsm
github_2023
others
111
coconut-svsm
00xc
@@ -1215,21 +1815,31 @@ pub struct Elf64ImageLoadSegmentIterator<'a> { impl<'a> Iterator for Elf64ImageLoadSegmentIterator<'a> { type Item = Elf64ImageLoadSegment<'a>; + /// Advances the iterator to the next ELF64 image load segment and returns it. + /// + /// # Returns + /// + /// - [`Some(Elf64...
Also this one.
svsm
github_2023
others
111
coconut-svsm
00xc
@@ -214,6 +288,32 @@ impl convert::TryFrom<(Elf64Addr, Elf64Xword)> for Elf64AddrRange { } } +/// Compares two [`Elf64AddrRange`] instances for partial ordering. It returns +/// [`Some(Ordering)`] if there is a partial order, and [`None`] if there is no +/// order (i.e., if the ranges overlap without being equa...
These `Some`s as well. Although I think they can be omitted as the explanation is already present in the `PartialOrd` documentation, so it is a bit redundant.
svsm
github_2023
others
99
coconut-svsm
00xc
@@ -1605,3 +1605,198 @@ impl<'a, RP: Elf64RelocProcessor> Iterator for Elf64AppliedRelaIterator<'a, RP> Some(Ok(Some(reloc_op))) } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_elf64_shdr_verify_methods() { + // Create a valid Elf64Shdr instance for testing. + ...
This can probably be collapsed to a single statement (instead of having an `assert!(false)`) to something like: ```rust let res = Elf64File::read(&byte_data); assert!(matches!(res, Err(crate::elf::ElfError::InvalidPhdrSize))); ``` You could also use `assert_eq!()` instead of `assert!(matches!())` if you derive...
svsm
github_2023
others
99
coconut-svsm
cclaudio
@@ -1605,3 +1605,192 @@ impl<'a, RP: Elf64RelocProcessor> Iterator for Elf64AppliedRelaIterator<'a, RP> Some(Ok(Some(reloc_op))) } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_elf64_shdr_verify_methods() { + // Create a valid Elf64Shdr instance for testing. + ...
If you use `assert_eq` here, the test case would have a better error message. I was able to do that deriving some structures from PartialEq. ```diff diff --git a/src/elf/mod.rs b/src/elf/mod.rs index f795560f0963..ecec8543c06f 100644 --- a/src/elf/mod.rs +++ b/src/elf/mod.rs @@ -17,7 +17,7 @@ use core::fmt; ...
svsm
github_2023
others
99
coconut-svsm
cclaudio
@@ -1605,3 +1605,192 @@ impl<'a, RP: Elf64RelocProcessor> Iterator for Elf64AppliedRelaIterator<'a, RP> Some(Ok(Some(reloc_op))) } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_elf64_shdr_verify_methods() { + // Create a valid Elf64Shdr instance for testing. + ...
If we hit this expect, will the remaining tests not be executed? If so, we could have something like this ```diff // Construct an Elf64Hdr instance from the byte data - let elf_hdr = Elf64Hdr::read(&byte_data).expect("Failed to read ELF header"); + let elf_hdr = Elf64Hdr::read(&byte_data); +...
svsm
github_2023
others
105
coconut-svsm
Freax13
@@ -155,3 +155,46 @@ impl<T: Debug> RWLock<T> { } } } + +mod tests { + + #[test] + fn test_lock_rw() {
Note that this test fails when run with miri: ``` $ MIRIFLAGS="-Zmiri-permissive-provenance" cargo +nightly miri test --target=x86_64-unknown-linux-gnu test_lock_rw [...] test locking::rwlock::tests::test_lock_rw ... error: Undefined Behavior: trying to retag from <137787> for SharedReadOnly permission at alloc4874...
svsm
github_2023
others
105
coconut-svsm
joergroedel
@@ -89,3 +89,28 @@ impl<T: Debug> SpinLock<T> { None } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_spin_lock() { + let spin_lock = SpinLock::new(0); + + let mut guard = spin_lock.lock(); + *guard += 1; + + // Ensure the locked data is updated....
I don't get what this tests, you are defining a new spinlock, overwriting the old name. Can you explain what this tests and what guard_failed is for?
svsm
github_2023
others
96
coconut-svsm
00xc
@@ -134,43 +188,100 @@ impl ACPITable { Ok(Self { header, buf }) } + /// Get the signature of the ACPI table. + /// + /// This method returns the 4-character signature of the ACPI table, such as "APIC." + #[allow(dead_code)] fn signature(&self) -> FixedString<4> { FixedString...
Aren't we missing the return type here?
svsm
github_2023
others
96
coconut-svsm
00xc
@@ -222,11 +346,37 @@ impl ACPITableBuffer { Ok(()) } + /// Retrieve an ACPI table from a specified offset within the ACPI table buffer. + /// + /// This function attempts to retrieve an ACPI table from the ACPI table buffer starting from the + /// specified offset. It parses the table heade...
Should be "A `Result` containing...". There's a few more of these, just pointing it out once to avoid spamming.
svsm
github_2023
others
108
coconut-svsm
Freax13
@@ -1219,61 +1219,64 @@ impl SvsmAllocator { slab_size_2048: SpinLock::new(Slab::new(2048)), } } -} - -unsafe impl GlobalAlloc for SvsmAllocator { - unsafe fn alloc(&self, layout: Layout) -> *mut u8 { - let ret: Result<VirtAddr, SvsmError>; - let size = layout.size(); + ...
```suggestion let slab = self.get_slab(size).expect("Invalid page info"); ```
svsm
github_2023
others
108
coconut-svsm
Freax13
@@ -1219,61 +1219,64 @@ impl SvsmAllocator { slab_size_2048: SpinLock::new(Slab::new(2048)), } } -} - -unsafe impl GlobalAlloc for SvsmAllocator { - unsafe fn alloc(&self, layout: Layout) -> *mut u8 { - let ret: Result<VirtAddr, SvsmError>; - let size = layout.size(); + ...
This can be shortened to: ```rust let info = result.expect("Freeing unknown memory"); ```
svsm
github_2023
others
89
coconut-svsm
00xc
@@ -250,18 +367,39 @@ impl convert::TryFrom<(Elf64Off, Elf64Xword)> for Elf64FileRange { } } +/// This struct represents a parsed 64-bit ELF file. It contains information +/// about the ELF file's header, load segments, dynamic section, and more. #[derive(Default, Debug)] pub struct Elf64File<'a> { + /// B...
There's a missing closing backtick here. `cargo doc` will warn about it: ``` warning: could not parse code block as Rust code --> src/elf/mod.rs:398:9 | 398 | /// ```rust | _________^ 399 | | /// use your_module::Elf64File; 400 | | /// 401 | | /// let elf_file = Elf64File::read(...
svsm
github_2023
others
85
coconut-svsm
00xc
@@ -309,9 +309,9 @@ fn mapping_info_init(launch_info: &KernelLaunchInfo) { } #[no_mangle] -pub extern "C" fn svsm_start(li: &KernelLaunchInfo, vb_addr: VirtAddr) { +pub extern "C" fn svsm_start(li: &KernelLaunchInfo, vb_addr: usize) { let launch_info: KernelLaunchInfo = *li; - let vb_ptr = vb_addr.as_mut_pt...
Hm. `VirtAddr` is `repr(transparent)` so that it works with external ABIs (i.e. it is a zero-cost abstraction), but making it non-trivial defeats this purpose. I'd rather have a `sign_extend()` method on the type (or on the `Address` trait) and use that conversion here. Another idea is to have a sign-extending construc...
svsm
github_2023
others
76
coconut-svsm
stefano-garzarella
@@ -0,0 +1,38 @@ +#!/bin/bash + +set -x + +CURDIR=$(dirname $(realpath "$0")) +WORKDIR=$(realpath ${CURDIR}/../..) +DOCKER_FILE=$WORKDIR/scripts/docker/opensuse-rust.docker + +IMAGE_NAME=opensuse-rust +CONTAINER_NAME=coconut-build + +if ! command -v docker &> /dev/null ; then + echo "ERR: docker not found" + exit...
What about replacing with just `docker run`: ```suggestion docker run --rm -it --workdir=${WORKDIR} --user ${USER} --userns keep-id --mount type=bind,source=${WORKDIR},target=${WORKDIR} ${IMAGE_NAME} /bin/bash -c "source $HOME/.cargo/env && make clean && make" ``` I added ` --userns keep-id` to properly work with...
svsm
github_2023
others
76
coconut-svsm
stefano-garzarella
@@ -0,0 +1,23 @@ +# Usage example: +# +# git clone https://github.com/coconut-svsm/svsm.git +# cd svsm +# docker build -t fedora-rust -f scripsts/fedora-rust.docker .
s/fedora/opensuse
svsm
github_2023
others
76
coconut-svsm
stefano-garzarella
@@ -0,0 +1,127 @@ +#!/bin/bash + +CURDIR=$(dirname $(realpath "$0")) +WORKDIR=$(realpath ${CURDIR}/../..) +DOCKER_FILE=$WORKDIR/scripts/docker/opensuse-rust.docker + +IMAGE_NAME=opensuse-rust +CONTAINER_NAME=coconut-build + +# Command line arguments +ARG_REUSE=0 + +#### +#### Help function +#### +Help() +{ + echo "B...
Should we add `-a` here? We can also use `${CONTAINER_NAME}` ```suggestion CONTAINER_ID=$(docker ps -q -a -f name=${CONTAINER_NAME}) ```
svsm
github_2023
others
76
coconut-svsm
stefano-garzarella
@@ -0,0 +1,127 @@ +#!/bin/bash + +CURDIR=$(dirname $(realpath "$0")) +WORKDIR=$(realpath ${CURDIR}/../..) +DOCKER_FILE=$WORKDIR/scripts/docker/opensuse-rust.docker + +IMAGE_NAME=opensuse-rust +CONTAINER_NAME=coconut-build + +# Command line arguments +ARG_REUSE=0 + +#### +#### Help function +#### +Help() +{ + echo "B...
After a second thought and a chat with @osteffenrh, if we want to avoid having to download dependencies every time, we can create a volume for the cargo home: ``` --mount type=volume,source=${VOLUME_NAME},target=${HOME}/.cargo \ ``` However, I don't have a strong opinion on this, just a suggestion that cr...
svsm
github_2023
others
81
coconut-svsm
stefano-garzarella
@@ -1,14 +0,0 @@ -{ - "llvm-target": "x86_64-unknown-none", - "data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128", - "arch": "x86_64", - "target-endian": "little", - "target-pointer-width": "64", - "target-c-int-width": "32", - "os": "none", - "executables": true, - "linker-flavor": "gcc",...
Just a question to let me understand better the rust targets ;-) How we are now specifying the `panic-strategy`? Is default to `abort` for `x86_64-unknown-none`? I found something [here](https://doc.rust-lang.org/rustc/platform-support/x86_64-unknown-none.html) for example about the red-zone, but nothing about pani...
svsm
github_2023
others
78
coconut-svsm
00xc
@@ -325,6 +331,46 @@ impl PageTable { PageTable::walk_addr_lvl3(&mut self.root, vaddr) } + fn free_pgtbl_lvl1(page: &PTPage) { + for idx in 0..ENTRY_COUNT { + let entry = page[idx]; + + if PageTable::entry_to_pagetable(entry).is_some() { + free_page(phys_to...
Shouldn't `free_pgtbl_lvl{1,2,3}` be methods on `PTPage` that take `&self`? `PageTable::free()` would then simply be `self.root.free_lvl3()`
svsm
github_2023
others
77
coconut-svsm
00xc
@@ -0,0 +1,204 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) 2022-2023 SUSE LLC +// +// Author: Joerg Roedel <jroedel@suse.de> + +use crate::types::PAGE_SHIFT; +use crate::utils::{align_down, align_up}; +use core::cmp::max; +use intrusive_collections::rbtree::{Link, RBTree}; +use intrusive_col...
Small typo, should be `RangeAdapter`
svsm
github_2023
others
77
coconut-svsm
00xc
@@ -0,0 +1,204 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) 2022-2023 SUSE LLC +// +// Author: Joerg Roedel <jroedel@suse.de> + +use crate::types::PAGE_SHIFT; +use crate::utils::{align_down, align_up}; +use core::cmp::max; +use intrusive_collections::rbtree::{Link, RBTree}; +use intrusive_col...
This is equivalent and avoids an unwrap: ```rust while let Some(node) = cursor.get() { ... } ```
svsm
github_2023
others
77
coconut-svsm
00xc
@@ -0,0 +1,204 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) 2022-2023 SUSE LLC +// +// Author: Joerg Roedel <jroedel@suse.de> + +use crate::types::PAGE_SHIFT; +use crate::utils::{align_down, align_up}; +use core::cmp::max; +use intrusive_collections::rbtree::{Link, RBTree}; +use intrusive_col...
Maybe the return value should be an `Option<VirtAddr>`? Same with the input for `free()` and `get()` taking a `VirtAddr`.
svsm
github_2023
others
79
coconut-svsm
stefano-garzarella
@@ -4,6 +4,9 @@ // // Author: Joerg Roedel <jroedel@suse.de> +// For bitflags definitions +#![allow(clippy::bad_bit_mask)]
Is clippy complains about `RMPFlags`? What about allow it only for that definition?
svsm
github_2023
others
75
coconut-svsm
joergroedel
@@ -19,19 +19,10 @@ use log; pub const MAX_ORDER: usize = 6; pub fn get_order(size: usize) -> usize { - let mut val = (size - 1) >> PAGE_SHIFT; - let mut order: usize = 0; - - loop { - if val == 0 { - break; - } - - order += 1; - val >>= 1; - } - - order + //...
Thanks! Maybe you can change that to Paolo's latest version (using usize::BITS)?
svsm
github_2023
others
73
coconut-svsm
00xc
@@ -121,9 +121,15 @@ bitflags! { } #[repr(C)] -#[derive(Copy, Clone)] +#[derive(Copy, Clone, Debug)] pub struct PTEntry(PhysAddr); +impl Default for PTEntry { + fn default() -> Self { + PTEntry(PhysAddr::new(0)) + } +} +
I think this could be derived as well, since you added Default for PhysAddr.
svsm
github_2023
others
73
coconut-svsm
00xc
@@ -184,6 +198,7 @@ pub enum Mapping<'a> { } #[repr(C)] +#[derive(Default)] pub struct PageTable { root: PTPage, }
Might as well derive Debug here too.
svsm
github_2023
others
73
coconut-svsm
00xc
@@ -24,6 +24,8 @@ pub struct X86GeneralRegs { pub rax: usize, } +impl Copy for X86GeneralRegs {} +
This can also be derived.
svsm
github_2023
others
73
coconut-svsm
00xc
@@ -36,10 +38,13 @@ pub struct X86SegmentRegs { } #[repr(C, packed)] +#[derive(Default, Debug, Clone)] pub struct X86InterruptFrame { pub rip: usize, pub cs: usize, pub flags: usize, pub rsp: usize, pub ss: usize, } + +impl Copy for X86InterruptFrame {}
Same here, could be derived
svsm
github_2023
others
73
coconut-svsm
00xc
@@ -17,8 +17,9 @@ use core::fmt; use core::matches; use core::mem; -#[derive(Debug)] +#[derive(Debug, Default)] pub enum ElfError { + #[default]
Not sure how I feel about this. Does it make sense to have a default `ElfError`? If we had an `Other` variant this would probably be fine but in this case I'm not sure.
svsm
github_2023
others
73
coconut-svsm
00xc
@@ -18,8 +18,9 @@ use packit::PackItError; const MAX_FILENAME_LENGTH: usize = 64; pub type FileName = FixedString<MAX_FILENAME_LENGTH>; -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, Default)] pub enum FsError { + #[default] Inval,
This one I think is fine since EINVAL is usually very generic.
svsm
github_2023
others
33
coconut-svsm
osteffenrh
@@ -0,0 +1,35 @@ +#!/usr/bin/env bash +set -e + +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + +if [[ $1 == "debug" ]]; then + LOG_FILE="ovmf_debug.build" +else + LOG_FILE="ovmf_release.build" +fi +rm -f $LOG_FILE + +pushd $SCRIPT_DIR/../edk2 + +export PYTHON3_ENABLE=TRUE +expo...
Why require gcc 7 explicitly? Ovmf builds fine with versions up to and including gcc 12.
svsm
github_2023
others
25
coconut-svsm
joergroedel
@@ -5,21 +5,17 @@ // Author: Joerg Roedel <jroedel@suse.de> use crate::locking::SpinLock; -use crate::serial::DEFAULT_SERIAL_PORT; +use crate::serial::{DEFAULT_SERIAL_PORT, Terminal}; use crate::utils::immut_after_init::ImmutAfterInitCell; use core::fmt; use log; -pub trait ConsoleWriter { - fn put_byte(&se...
Please factor out the renaming of ConsoleWriter to Terminal to a separate patch.
svsm
github_2023
others
25
coconut-svsm
joergroedel
@@ -0,0 +1,488 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) 2022-2023 SUSE LLC +// +// Author: Roy Hopkins <rhopkins@suse.de> + +// +// For release builds this module should not be compiled into the +// binary. See the bottom of this file for placeholders that are +// used when the gdb stub i...
This can probably be implemented with the exception fixup code that is already available in SVSM.
svsm
github_2023
others
25
coconut-svsm
joergroedel
@@ -203,6 +203,14 @@ impl PageTable { }) } + // When GDB is enabled allow the executable memory to be writable to
I think it is better to use temporary mapping for pages that need to be written to. That way code pages can stay read-only.
svsm
github_2023
others
50
coconut-svsm
00xc
@@ -0,0 +1,186 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) 2022-2023 SUSE LLC +// +// Author: Roy Hopkins <rhopkins@suse.de> + +use crate::cpu::percpu::{this_cpu, this_cpu_mut}; +use crate::error::SvsmError; +use crate::locking::SpinLock; + +use super::INITIAL_TASK_ID; +use super::{task::Tas...
I have not tested this at all, but could we use the [LinkedList](https://doc.rust-lang.org/alloc/collections/linked_list/struct.LinkedList.html) type in the alloc module? It would save us a lot of unsafe code.
svsm
github_2023
others
50
coconut-svsm
00xc
@@ -0,0 +1,186 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) 2022-2023 SUSE LLC +// +// Author: Roy Hopkins <rhopkins@suse.de> + +use crate::cpu::percpu::{this_cpu, this_cpu_mut}; +use crate::error::SvsmError; +use crate::locking::SpinLock; + +use super::INITIAL_TASK_ID; +use super::{task::Tas...
This should probably be a standalone function, no? I find it quite confusing that this is an associated function on `TaskList`, but takes a lock on `TASKLIST`, which itself is a lock around a `TaskList` instance.
svsm
github_2023
others
50
coconut-svsm
00xc
@@ -182,6 +183,8 @@ pub struct PerCpu { pub vrange_4k: VirtualRange, /// Address allocator for per-cpu 2m temporary mappings pub vrange_2m: VirtualRange, + + pub current_task: Option<*mut Task>,
If we are guarding against NULL with an `Option` we could use a [`ptr::NonNull`](https://doc.rust-lang.org/core/ptr/struct.NonNull.html) to improve struct layout.
svsm
github_2023
others
50
coconut-svsm
joergroedel
@@ -0,0 +1,69 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) 2022-2023 SUSE LLC +// +// Author: Roy Hopkins <rhopkins@suse.de> + +#[repr(C, packed)] +pub struct X86Regs {
This struct is unused now, no?
svsm
github_2023
others
50
coconut-svsm
joergroedel
@@ -0,0 +1,20 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) 2022-2023 SUSE LLC +// +// Author: Roy Hopkins <rhopkins@suse.de> + +use core::arch::asm; + +pub fn rdtsc() -> u64 {
No need for a new file, this function can be added to src/cpu/msr.rs.
svsm
github_2023
others
50
coconut-svsm
joergroedel
@@ -0,0 +1,404 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) 2022-2023 SUSE LLC +// +// Author: Roy Hopkins <rhopkins@suse.de> + +extern crate alloc; + +use core::arch::{asm, global_asm}; +use core::mem::size_of; +use core::sync::atomic::{AtomicU32, Ordering}; + +use alloc::boxed::Box; + +use ...
Okay, as I understand this, the code switches a task via a software interrupt to simplify switching the contents of the GPRs. The GPRs are then stored/restored in/from the struct task. Can we instead write some assembly which stores the GPRs directly on the task stack, switches the stack pointer, and restores the GP...
svsm
github_2023
others
50
coconut-svsm
00xc
@@ -0,0 +1,230 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) 2022-2023 SUSE LLC +// +// Author: Roy Hopkins <rhopkins@suse.de> + +extern crate alloc; + +use super::Task; +use super::{task::TaskRuntime, TaskState, INITIAL_TASK_ID}; +use crate::cpu::percpu::{this_cpu, this_cpu_mut}; +use crate::...
This saves us an unwrap: ```rust self.tree.get_or_insert_with(|| RBTree::new(TaskNodeAdapter::new())) ```
svsm
github_2023
others
50
coconut-svsm
00xc
@@ -0,0 +1,230 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) 2022-2023 SUSE LLC +// +// Author: Roy Hopkins <rhopkins@suse.de> + +extern crate alloc; + +use super::Task; +use super::{task::TaskRuntime, TaskState, INITIAL_TASK_ID}; +use crate::cpu::percpu::{this_cpu, this_cpu_mut}; +use crate::...
This saves us an unwrap: ```rust let mut cursor = self.tree().front(); while let Some(node) = cursor.get() { if node.task().id == id { return Some(cursor.clone_pointer().unwrap()) } cursor.move_next(); } None ```
svsm
github_2023
others
50
coconut-svsm
00xc
@@ -0,0 +1,404 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) 2022-2023 SUSE LLC +// +// Author: Roy Hopkins <rhopkins@suse.de> + +extern crate alloc; + +use core::arch::{asm, global_asm}; +use core::mem::size_of; +use core::sync::atomic::{AtomicU32, Ordering}; + +use alloc::boxed::Box; + +use ...
As before, `Option<*mut Task>` could perhaps be switched to `Option<NonNull<Task>>`, since we use `None` to signify null.
svsm
github_2023
others
50
coconut-svsm
00xc
@@ -0,0 +1,230 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) 2022-2023 SUSE LLC +// +// Author: Roy Hopkins <rhopkins@suse.de> + +extern crate alloc; + +use super::Task; +use super::{task::TaskRuntime, TaskState, INITIAL_TASK_ID}; +use crate::cpu::percpu::{this_cpu, this_cpu_mut}; +use crate::...
Not a huge fan of this unsafe, I wonder if we could remove it. If `Task::set_current()` took `&self` instead of `&mut self` we could avoid it I think. There are two things that prevent this: 1. This line in `Task::set_current()`: ```rust let new_task_addr = (self as *mut Task) as u64; ``` But perhaps this could ...
svsm
github_2023
others
50
coconut-svsm
00xc
@@ -0,0 +1,404 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) 2022-2023 SUSE LLC +// +// Author: Roy Hopkins <rhopkins@suse.de> + +extern crate alloc; + +use core::arch::{asm, global_asm}; +use core::mem::size_of; +use core::sync::atomic::{AtomicU32, Ordering}; + +use alloc::boxed::Box; + +use ...
Perhaps this should be `#[repr(transparent)]` so it's guaranteed that it doesn't affect the layout of `Task`, which is `#[repr(C)]`.
svsm
github_2023
others
50
coconut-svsm
00xc
@@ -0,0 +1,404 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) 2022-2023 SUSE LLC +// +// Author: Roy Hopkins <rhopkins@suse.de> + +extern crate alloc; + +use core::arch::{asm, global_asm}; +use core::mem::size_of; +use core::sync::atomic::{AtomicU32, Ordering}; + +use alloc::boxed::Box; + +use ...
Unused, right?
svsm
github_2023
others
50
coconut-svsm
00xc
@@ -0,0 +1,214 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) 2022-2023 SUSE LLC +// +// Author: Roy Hopkins <rhopkins@suse.de> + +extern crate alloc; + +use core::cell::RefCell; + +use super::Task; +use super::{tasks::TaskRuntime, TaskState, INITIAL_TASK_ID}; +use crate::cpu::percpu::{this_cpu...
Just a nitpick, but the reference will automatically be coerced to a pointer, this would do: ``` tl.tree() .cursor_mut_from_ptr(task.as_ref()) ``` Or if you want to be more explicit: ``` tl.tree() .cursor_mut_from_ptr(Rc::as_ptr(&task)) ```
svsm
github_2023
others
50
coconut-svsm
00xc
@@ -0,0 +1,214 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) 2022-2023 SUSE LLC +// +// Author: Roy Hopkins <rhopkins@suse.de> + +extern crate alloc; + +use core::cell::RefCell; + +use super::Task; +use super::{tasks::TaskRuntime, TaskState, INITIAL_TASK_ID}; +use crate::cpu::percpu::{this_cpu...
We can get rid of the unwrap via `Option::filter()`: ```rust if cursor .get() .filter(|ptr| ptr.task.borrow().state == TaskState::TERMINATED) .is_none() { return Err(SvsmError::Task); }
svsm
github_2023
others
50
coconut-svsm
00xc
@@ -0,0 +1,214 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) 2022-2023 SUSE LLC +// +// Author: Roy Hopkins <rhopkins@suse.de> + +extern crate alloc; + +use core::cell::RefCell; + +use super::Task; +use super::{tasks::TaskRuntime, TaskState, INITIAL_TASK_ID}; +use crate::cpu::percpu::{this_cpu...
Same thing here about the reference to pointer coercion.
svsm
github_2023
others
50
coconut-svsm
00xc
@@ -0,0 +1,214 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) 2022-2023 SUSE LLC +// +// Author: Roy Hopkins <rhopkins@suse.de> + +extern crate alloc; + +use core::cell::RefCell; + +use super::Task; +use super::{tasks::TaskRuntime, TaskState, INITIAL_TASK_ID}; +use crate::cpu::percpu::{this_cpu...
This assert can be removed since the unwrap() already would cause a panic. You can use expect to add a message to the panic.
svsm
github_2023
others
50
coconut-svsm
00xc
@@ -0,0 +1,214 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) 2022-2023 SUSE LLC +// +// Author: Roy Hopkins <rhopkins@suse.de> + +extern crate alloc; + +use core::cell::RefCell; + +use super::Task; +use super::{tasks::TaskRuntime, TaskState, INITIAL_TASK_ID}; +use crate::cpu::percpu::{this_cpu...
We should use the `while let Some(node) = cursor.get()` construct we have in other places.
svsm
github_2023
others
50
coconut-svsm
00xc
@@ -0,0 +1,214 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) 2022-2023 SUSE LLC +// +// Author: Roy Hopkins <rhopkins@suse.de> + +extern crate alloc; + +use core::cell::RefCell; + +use super::Task; +use super::{tasks::TaskRuntime, TaskState, INITIAL_TASK_ID}; +use crate::cpu::percpu::{this_cpu...
We can use `Option::filter()` here as well to avoid the unwrap. Or as an alternative, we can use `map()` + `unwrap_or()`: ```rust if candidate_task.state == TaskState::RUNNING && candidate_task .affinity .map(|af| af == this_cpu().get_apic_id()) .unwrap_or(true) { break; } ``...
svsm
github_2023
others
50
coconut-svsm
00xc
@@ -0,0 +1,400 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) 2022-2023 SUSE LLC +// +// Author: Roy Hopkins <rhopkins@suse.de> + +extern crate alloc; + +use core::arch::{asm, global_asm}; +use core::mem::size_of; +use core::sync::atomic::{AtomicU32, Ordering}; + +use alloc::boxed::Box; + +use ...
Maybe we should have this as `TaskIdAllocator::new()`.
svsm
github_2023
others
61
coconut-svsm
00xc
@@ -37,3 +37,30 @@ pub fn write_msr(msr: u32, val: u64) { options(att_syntax)); } } + +pub fn rdtsc() -> u64 { + let eax: u32; + let edx: u32; + + unsafe { + asm!("rdtsc", + out("eax") eax, + out("edx") edx, + options(att_syntax));
We can add `nomem, nostack` to `options()` to help the compiler a bit.
svsm
github_2023
others
61
coconut-svsm
joergroedel
@@ -0,0 +1,404 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) 2022-2023 SUSE LLC +// +// Author: Roy Hopkins <rhopkins@suse.de> + +extern crate alloc; + +use core::arch::{asm, global_asm}; +use core::fmt; +use core::mem::size_of; +use core::sync::atomic::{AtomicU32, Ordering}; + +use alloc::box...
No need to save and restore the segment selectors, as we are switching between SVSM kernel tasks here and they will all run with the same segments. User-space segment switches will happen in the entry/exit code.
svsm
github_2023
others
24
coconut-svsm
joergroedel
@@ -0,0 +1,111 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) 2022-2023 SUSE LLC +// +// Author: Roy Hopkins <rhopkins@suse.de> + +use crate::types::{VirtAddr, PAGE_SHIFT, PAGE_SIZE, PAGE_SIZE_2M, PAGE_SHIFT_2M}; +use crate::locking::SpinLock; +use crate::error::SvsmError; +use crate::utils::bi...
This panic message is the same as above. Can you please add the page-size to each message to make it clear for which size the allocation failed?
svsm
github_2023
others
24
coconut-svsm
joergroedel
@@ -0,0 +1,493 @@ +
Please add a copyright header to each new file.
svsm
github_2023
others
24
coconut-svsm
joergroedel
@@ -0,0 +1,493 @@ + + +pub trait BitmapAllocator { + const CAPACITY: usize; + + fn alloc(&mut self, entries: usize, align: usize) -> Option<usize>; + fn free(&mut self, start: usize, entries: usize); + + fn set(&mut self, start: usize, entries: usize, value: bool); + fn next_free(&self, start: usize) -> ...
The 'return' is not needed.
svsm
github_2023
others
24
coconut-svsm
joergroedel
@@ -0,0 +1,493 @@ + + +pub trait BitmapAllocator { + const CAPACITY: usize; + + fn alloc(&mut self, entries: usize, align: usize) -> Option<usize>; + fn free(&mut self, start: usize, entries: usize); + + fn set(&mut self, start: usize, entries: usize, value: bool); + fn next_free(&self, start: usize) -> ...
'return' and semicolon are not needed.
svsm
github_2023
others
43
coconut-svsm
joergroedel
@@ -81,8 +81,8 @@ kernel_elf_end: kernel_fs_bin: .incbin "stage1/svsm-fs.bin" - .align 4
Right, that was my mistake. Thanks for fixing that.
svsm
github_2023
others
57
coconut-svsm
stefano-garzarella
@@ -41,3 +41,9 @@ jobs: with: command: fmt args: --all -- --check + + - name: Clippy + uses: actions-rs/cargo@v1 + with: + command: clippy + args: --all-features -- -D warnings
What about adding `--locked` ? In this way, we will have an error if `Cargo.lock` is not updated
svsm
github_2023
others
45
coconut-svsm
00xc
@@ -239,6 +240,32 @@ fn core_pvalidate_one(entry: u64, flush: &mut bool) -> Result<(), SvsmReqError> })?; if valid { + // Zero out a page when it is validated and before giving other VMPLs + // access to it. This is necessary to prevent a possible HV attack: + // + // Attack scen...
Is there a valid reason for a guest OS to ask the SVSM for access to the ISA range?
svsm
github_2023
others
2
coconut-svsm
nicstange
@@ -102,7 +118,7 @@ impl<T: Copy> Deref for ImmutAfterInitCell<T> { /// Dereference the wrapped value. Must **only ever** get called on an /// initialized instance! fn deref(&self) -> &T { - unsafe { (&*self.data.get()).assume_init_ref() } + unsafe { self.as_ref() }.unwrap()
Would it perhaps make sense to restrict this misuse tracking to debug builds only? Because there are some values wrapped in `ImmutAfterInitCell<>` whose accesses might be performance-sensitive, like `ENCRYPT_MASK`.
svsm
github_2023
others
27
coconut-svsm
00xc
@@ -75,6 +76,22 @@ impl<const N: usize> PartialEq<&str> for FixedString<N> { } } +impl<const N: usize> PartialEq<FixedString<N>> for FixedString<N> { + fn eq(&self, other: &FixedString<N>) -> bool { + if self.len != other.len { + return false; + } + + for i in 0..self.len { + ...
An iterator would be more conventional here. Something like: ```rust for (a, b) in self.data.iter().zip(&other.data).take(self.len) { ... } ``` Or even: ```rust self.data .iter() .zip(&other.data) .take(self.len) .all(|(a, b)| *a == *b) ```
svsm
github_2023
others
27
coconut-svsm
00xc
@@ -0,0 +1,411 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) 2023 SUSE LLC +// +// Author: Joerg Roedel <jroedel@suse.de> + +use super::ramfs::RamDirectory; +use super::*; + +use crate::error::SvsmError; +use crate::locking::SpinLock; + +use core::cmp::min; + +extern crate alloc; +use alloc::s...
Instead of checking via `is_ok()` and then unwrapping one can do: ```rust if let Ok(result) = self.file.read(buf, self.current) { self.current += result; } ```