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 | 243 | coconut-svsm | 00xc | @@ -1262,6 +1541,12 @@ unsafe impl GlobalAlloc for SvsmAllocator {
ret.map_or_else(|_| ptr::null_mut(), |addr| addr.as_mut_ptr::<u8>())
}
+ /// Deallocates memory based on the specified pointer and layout.
+ ///
+ /// # Safety
+ ///
+ /// This function assumes that the pointer and layout ... | Same thing here, no need to document this |
svsm | github_2023 | others | 243 | coconut-svsm | 00xc | @@ -1074,22 +1304,34 @@ impl SlabCommon {
}
}
+/// Represents a slab page for the [`SlabPageSlab`] allocator.
#[derive(Debug)]
struct SlabPageSlab {
common: SlabCommon,
}
impl SlabPageSlab {
+ /// Creates a new [`SlabPageSlab`] with a default [`SlabCommon`].
const fn new() -> Self {
... | This would also be a candidate for removing `# Returns` in my opinion, the function signature is quite clear I would say. |
svsm | github_2023 | others | 243 | coconut-svsm | 00xc | @@ -1324,13 +1611,23 @@ pub struct TestRootMem<'a>(LockGuard<'a, ()>);
#[cfg(any(test, fuzzing))]
impl TestRootMem<'_> {
#[cfg(test_in_svsm)]
+ /// Sets up a test environment, returning a guard to ensure memory is
+ /// held for the test's duration.
+ ///
+ /// # Returns
+ ///
+ /// A guard tha... | These two are the same function with more or less the same idea behind them, so their description should probably be the same or similar enough. It's just that one version of the function requires more setup because it does not run inside the SVSM. |
svsm | github_2023 | others | 243 | coconut-svsm | 00xc | @@ -77,6 +92,17 @@ pub fn init_memory_map(
Ok(())
}
+/// Checks if a physical address is considered valid based on the configured
+/// memory regions. | Perhaps we should explain what "valid" means (i.e. contained within the configured memory regions). |
svsm | github_2023 | others | 243 | coconut-svsm | 00xc | @@ -77,6 +92,17 @@ pub fn init_memory_map(
Ok(())
}
+/// Checks if a physical address is considered valid based on the configured
+/// memory regions.
+///
+/// # Arguments
+///
+/// * `paddr` - The physical address to check for validity.
+///
+/// # Returns
+///
+/// Returns `true` if the provided physical add... | Perhaps too much boilerplate, I'd say the function signature is pretty clear. A few extra works would be enough in my opinion. |
svsm | github_2023 | others | 243 | coconut-svsm | 00xc | @@ -93,9 +119,23 @@ pub fn valid_phys_address(paddr: PhysAddr) -> bool {
.any(|region| region.contains(paddr))
}
+/// The starting address of the ISA range.
const ISA_RANGE_START: PhysAddr = PhysAddr::new(0xa0000);
+
+/// The ending address of the ISA range.
const ISA_RANGE_END: PhysAddr = PhysAddr::new(0... | Same here, too much boilerplate in my opinion. |
svsm | github_2023 | others | 258 | coconut-svsm | joergroedel | @@ -120,6 +120,10 @@ svsm.bin: stage1/stage1
svsm-test.bin: stage1/stage1-test
objcopy -O binary $< $@
+clippy: | `clippy` also needs to be added to the `.PHONY` target. |
svsm | github_2023 | others | 255 | coconut-svsm | roy-hopkins | @@ -353,7 +362,10 @@ impl IgvmBuilder {
gpa_start: u64,
) -> Result<(), Box<dyn Error>> {
let mut gpa = gpa_start;
- let mut in_file = File::open(path).expect("Could not open input file");
+ let mut in_file = File::open(path).map_err(|e| {
+ eprintln!("Could not open inpu... | Missing space between in `file{}`. |
svsm | github_2023 | others | 257 | coconut-svsm | 00xc | @@ -14,6 +14,11 @@ else ifeq ($(V), 2)
CARGO_ARGS += -vv
endif
+ifeq ($(OFFLINE), true)
+CARGO_ARGS += --locked --offline
+endif | Maybe we could use `ifdef` so it's more consistent with other options (e.g. `RELEASE`). |
svsm | github_2023 | others | 245 | coconut-svsm | 00xc | @@ -1,40 +1,66 @@
-[package]
-name = "svsm"
-version = "0.1.0"
-edition = "2021"
+[workspace]
+resolver = "2"
+members = [
+ # repo tooling
+ "igvmbuilder",
+ # binary targets
+ "kernel",
+ # fuzzing
+ "fuzz"
+]
-[[bin]]
-name = "stage2"
-path = "src/stage2.rs"
-test = false
-[[bin]]
-name = "svsm... | These will be fixed with #248 |
svsm | github_2023 | others | 245 | coconut-svsm | stefano-garzarella | @@ -60,7 +60,7 @@ impl CmdOptions {
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum, Debug)]
pub enum Hypervisor {
/// Build an IGVM file compatible with QEMU
- QEMU,
+ Qemu, | I'd suggest doing this change in another commit or PR. |
svsm | github_2023 | others | 245 | coconut-svsm | stefano-garzarella | @@ -178,7 +178,7 @@ impl SvsmFs {
self.root = Some(root.clone());
}
- #[cfg(all(any(test, fuzzing), not(test_in_svsm)))]
+ #[cfg(all(any(test, feature = "fuzzing-hooks"), not(test_in_svsm)))] | Not a strong opinion, but I would have made this change in a separate preparation commit. |
svsm | github_2023 | others | 241 | coconut-svsm | stefano-garzarella | @@ -31,10 +31,14 @@ C_BIT_POS ?= 51
STAGE1_OBJS = stage1/stage1.o stage1/reset.o
IGVM_FILES = bin/coconut-qemu.igvm bin/coconut-hyperv.igvm
IGVMBUILDER = "target/x86_64-unknown-linux-gnu/${TARGET_PATH}/igvmbuilder"
+IGVMBIN = bin/igvmbld | Is there a particular reason for renaming it?
I mean copying it to bin is okay IMO, but I'd leave it with the same name, so there's no confusion. |
svsm | github_2023 | others | 241 | coconut-svsm | stefano-garzarella | @@ -31,10 +31,14 @@ C_BIT_POS ?= 51
STAGE1_OBJS = stage1/stage1.o stage1/reset.o
IGVM_FILES = bin/coconut-qemu.igvm bin/coconut-hyperv.igvm
IGVMBUILDER = "target/x86_64-unknown-linux-gnu/${TARGET_PATH}/igvmbuilder"
+IGVMBIN = bin/igvmbld
all: stage1/kernel.elf svsm.bin igvm
-igvm: $(IGVM_FILES)
+igvm: $(IGVM_FI... | Should we move this line on the target we are adding in this PR (line 40)? |
svsm | github_2023 | others | 241 | coconut-svsm | stefano-garzarella | @@ -31,19 +31,26 @@ C_BIT_POS ?= 51
STAGE1_OBJS = stage1/stage1.o stage1/reset.o
IGVM_FILES = bin/coconut-qemu.igvm bin/coconut-hyperv.igvm
IGVMBUILDER = "target/x86_64-unknown-linux-gnu/${TARGET_PATH}/igvmbuilder"
+IGVMBIN = bin/igvmbld
all: stage1/kernel.elf svsm.bin igvm
-igvm: $(IGVM_FILES)
+igvm: $(IGVM_FI... | So we can remove this now, right? |
svsm | github_2023 | others | 241 | coconut-svsm | stefano-garzarella | @@ -31,19 +31,26 @@ C_BIT_POS ?= 51
STAGE1_OBJS = stage1/stage1.o stage1/reset.o
IGVM_FILES = bin/coconut-qemu.igvm bin/coconut-hyperv.igvm
IGVMBUILDER = "target/x86_64-unknown-linux-gnu/${TARGET_PATH}/igvmbuilder"
+IGVMBIN = bin/igvmbld
all: stage1/kernel.elf svsm.bin igvm
-igvm: $(IGVM_FILES)
+igvm: $(IGVM_FI... | Is this an intentional change? |
svsm | github_2023 | others | 232 | coconut-svsm | 00xc | @@ -458,8 +458,13 @@ impl PerCpu {
self.reset_ip = reset_ip;
}
- pub fn ghcb(&mut self) -> &'static mut GHCB {
- unsafe { self.ghcb.as_mut().unwrap() }
+ /// # Safety
+ ///
+ /// This routine performs no checks on the validity of the current GHCB
+ /// and should only be used by ca... | Getting a pointer is not an unsafe operation in Rust. The unsafety is in using the pointer, like creating a reference (`&*ptr`) or dereferencing it (`*ptr`).
For example, see slices' `as_mut_ptr()` method in the standard library, which is not marked as unsafe:
https://doc.rust-lang.org/std/primitive.slice.html#meth... |
svsm | github_2023 | others | 232 | coconut-svsm | 00xc | @@ -0,0 +1,38 @@
+// SPDX-License-Identifier: MIT OR Apache-2.0
+//
+// Copyright (c) Microsoft Corporation
+//
+// Author: Jon Lange (jlange@microsoft.com)
+
+use crate::cpu::percpu::this_cpu_mut;
+use crate::sev::ghcb::GHCB;
+
+use core::ops::{Deref, DerefMut};
+
+#[derive(Debug)]
+pub struct GHCBRef {
+ ghcb: *mu... | What is this line doing exactly? `cpu_ptr` is already a `&mut PerCpu`. |
svsm | github_2023 | others | 232 | coconut-svsm | joergroedel | @@ -607,12 +622,98 @@ impl PerCpu {
}
}
-pub fn this_cpu() -> &'static PerCpu {
- unsafe { SVSM_PERCPU_BASE.as_ptr::<PerCpu>().as_ref().unwrap() }
+pub fn get_current_apic_id() -> u32 {
+ // The APIC ID never changes once a CPU has been constructed, so it is safe
+ // to reach into the raw CPU storage ... | These assertions need to be warning or error messages for now, at least until we fixed all cases that trigger them. Currently this breaks booting in debug builds. |
svsm | github_2023 | others | 232 | coconut-svsm | 00xc | @@ -612,6 +612,11 @@ impl PerCpu {
}
}
+pub fn get_current_apic_id() -> u32 {
+ let cpu = this_cpu();
+ (*cpu).get_apic_id()
+} | I don't see how this solves anything vs `this_cpu().get_apic_id()`. We are still going through an immutable borrow and the borrow is temporary in both cases. If we *really* want to avoid creating a reference we would need to do a `ptr::read()` from `SVSM_PERCPU_BASE` plus a certain offset. |
svsm | github_2023 | others | 232 | coconut-svsm | 00xc | @@ -613,16 +624,97 @@ impl PerCpu {
}
pub fn get_current_apic_id() -> u32 {
- let cpu = this_cpu();
- (*cpu).get_apic_id()
+ // The APIC ID never changes once a CPU has been constructed, so it is safe
+ // to reach into the raw CPU storage to extract the APIC ID without regard
+ // to borrow safety.
... | Instead of doing all of this accounting manually perhaps `CpuRef` should be something like a `RefCell<*mut PerCpu>` when `debug_assertions` is enabled. |
svsm | github_2023 | others | 218 | coconut-svsm | 00xc | @@ -104,6 +104,7 @@ fn set_c_bit(paddr: PhysAddr) -> PhysAddr {
bitflags! {
#[derive(Copy, Clone, Debug)]
pub struct PTEntryFlags: u64 {
+ const NONE = 0; | The `bitflag` docs explicitly discourage flags with no bits set. Instead we should use `PTEntryFlags::empty()` |
svsm | github_2023 | others | 218 | coconut-svsm | roy-hopkins | @@ -421,6 +428,49 @@ pub unsafe fn current_task_terminated() {
TASKLIST.lock().terminate(task_node.clone());
}
+fn task_pointer(taskptr: TaskPointer) -> *mut Task {
+ let mut guard = taskptr.task.lock_write();
+ let task = guard.as_mut();
+
+ task as *mut Task
+} | This provides mutable access to the task pointer without borrowing or holding a lock. I see it's only used prior to a task switch but the function should probably be marked `unsafe`, perhaps with a `// SAFETY` comment. |
svsm | github_2023 | others | 218 | coconut-svsm | roy-hopkins | @@ -421,6 +428,49 @@ pub unsafe fn current_task_terminated() {
TASKLIST.lock().terminate(task_node.clone());
}
+fn task_pointer(taskptr: TaskPointer) -> *mut Task {
+ let mut guard = taskptr.task.lock_write();
+ let task = guard.as_mut();
+
+ task as *mut Task
+}
+
+fn switch_to(prev: *mut Task, next: ... | `current` and `next` are `Arc<Task>` aren't they? If so, won't this hold a reference count over the task switch, so the task can only be dropped when we switch back to the current task? |
svsm | github_2023 | others | 218 | coconut-svsm | roy-hopkins | @@ -575,17 +573,7 @@ pub mod svsm_gdbstub {
Some(t) => {
let t = t.task.lock_read();
match t.state {
- TaskState::RUNNING => {
- if let Some(allocation) = t.allocation {
- if this_... | The "Running" and "Stopped" strings here are intended to indicate a different state to the actual task state. Due to how the gdbstub works in SVSM, when the gdbstub state machine is in the 'idle' state then all tasks on the CPU that is processing the gdbstub are stopped. All other tasks on other CPUs are still running ... |
svsm | github_2023 | others | 218 | coconut-svsm | 00xc | @@ -74,12 +47,11 @@ impl RunQueue {
.unwrap_or(self.idle_task.get().unwrap().clone())
}
- fn handle_task(&mut self, taskptr: TaskPointer) {
- let task = taskptr.task.lock_read();
+ fn handle_task(&mut self, task: TaskPointer) {
if task.is_running() && !task.is_idle_task() {
- ... | We don't need these `task.clone()` calls since `task` is already passed by value. |
svsm | github_2023 | others | 218 | coconut-svsm | roy-hopkins | @@ -446,20 +445,16 @@ pub mod svsm_gdbstub {
let context = (self.ctx as *const TaskContext).as_ref().unwrap();
*regs = X86_64CoreRegs::from(context);
}
+ } else if let Some(task) = TASKLIST.lock().get_task(tid.get() as u32) {
+ // The ... | The previous code deliberately assigned the task `Option` to a variable before checking if it was `Some` or `None` as otherwise the `TASKLIST` lock is held until the if scope is exited, causing a deadlock in `switch_to_task()`. This is what was causing the thread list to deadlock as GDB queries the register state of ea... |
svsm | github_2023 | others | 218 | coconut-svsm | roy-hopkins | @@ -105,9 +105,8 @@ pub mod svsm_gdbstub {
ret_addr: ctx.frame.rip as u64,
};
- if let Some(task_node) = this_cpu_mut().runqueue().lock_read().get_task(id) {
- task_node.task.lock_write().rsp = &task_ctx as *const TaskContext as u64;
- }
+ // FIXME: current_task()... | I've taken a look at the code and this change doesn't seem to break the switching of threads in gdb. `task.rsp` is only used for reading registers in the non-current thread whereas the disabled code sets `task.rsp` for the current thread only. I think it can safely be removed. |
svsm | github_2023 | others | 218 | coconut-svsm | roy-hopkins | @@ -550,7 +545,7 @@ pub mod svsm_gdbstub {
let mut cursor = tl.list().front_mut();
while cursor.get().is_some() {
- let this_task = cursor.get().unwrap().task.lock_read().id;
+ let this_task = cursor.get().unwrap().get_task_id();
... | The idle task for each CPU is not added to `TASKLIST` which means this loop misses all of the idle tasks. Is there any way we can include the idle tasks here? |
svsm | github_2023 | others | 218 | coconut-svsm | roy-hopkins | @@ -572,21 +567,11 @@ pub mod svsm_gdbstub {
// Get the current task from the stopped CPU so we can mark it as stopped
let tl = TASKLIST.lock();
let str = match tl.get_task(tid.get() as u32) {
- Some(t) => {
- let t = t.task.lock_read();
- ... | Now the idle tasks appear in the task list it has highlighted one last issue where blocked tasks are marked as terminated:
```suggestion
Some(task) => {
if task.is_running() {
"Running".as_bytes()
} else if task.is_terminated() {
... |
svsm | github_2023 | others | 71 | coconut-svsm | cclaudio | @@ -250,7 +250,7 @@ pub fn parse_fw_meta_data() -> Result<SevFWMetaData, SvsmError> {
let ptr = curr.as_ptr::<u16>();
let full_len = ptr.read() as usize;
- let len = full_len - mem::size_of::<u16>() + mem::size_of::<Uuid>();
+ let len = full_len - (mem::size_of::<u16>() + mem::size_of:... | If we have no control over `full_len`, we may want to use `usize::checked_sub()` to detect overflow. |
svsm | github_2023 | others | 71 | coconut-svsm | cclaudio | @@ -223,98 +186,205 @@ const SEV_META_DESC_TYPE_SECRETS: u32 = 2;
const SEV_META_DESC_TYPE_CPUID: u32 = 3;
const SEV_META_DESC_TYPE_CAA: u32 = 4;
+#[derive(Debug, Clone, Copy)]
+#[repr(C, packed)]
+struct RawMetaHeader {
+ len: u16,
+ uuid: [u8; size_of::<Uuid>()],
+}
+
+impl RawMetaHeader {
+ fn data_len(... | Maybe `s,//,///` ? |
svsm | github_2023 | others | 71 | coconut-svsm | cclaudio | @@ -223,98 +186,205 @@ const SEV_META_DESC_TYPE_SECRETS: u32 = 2;
const SEV_META_DESC_TYPE_CPUID: u32 = 3;
const SEV_META_DESC_TYPE_CAA: u32 = 4;
+#[derive(Debug, Clone, Copy)]
+#[repr(C, packed)]
+struct RawMetaHeader {
+ len: u16,
+ uuid: [u8; size_of::<Uuid>()],
+}
+
+impl RawMetaHeader {
+ fn data_len(... | IIRC, with `packed` the compiler can't do field reordering. So, I am wondering if the header should come before the data? If there is an unexpected issue with the data, I think it would still be safe to access the header (at least for debugging) |
svsm | github_2023 | others | 213 | coconut-svsm | 00xc | @@ -9,39 +9,74 @@ extern crate alloc;
use crate::cpu::vc::VcError;
use crate::cpu::vc::VcErrorType;
use crate::error::SvsmError;
+use core::ops::{Index, IndexMut};
pub const MAX_INSN_SIZE: usize = 15;
pub const MAX_INSN_FIELD_SIZE: usize = 3;
-#[derive(Default, Debug, Copy, Clone)]
-pub struct Instruction {
- ... | I think the `Index<usize>` bound is not necessary, as it is always met by any array of size `N`. `Default` is necessary because it is only implemented for certain values of `N` due to some toolchain limitations AFAIK. |
svsm | github_2023 | others | 210 | coconut-svsm | joergroedel | @@ -18,6 +21,21 @@ matches_any() {
return 1
}
+# Check that the body for the given commit is not empty
+nonempty_body() {
+ body=$(git show --no-patch --format="%b" "$1" | sed '/^ *$/d')
+ trailers=$(git show --no-patch --format="%(trailers:only)" "$1")
+
+ # Remove trailers
+ for trailer in "${trailers[@]}"; do
+... | Instead of removing the trailer, can we just count the number of lines for body and trailers and fail if they are equal? |
svsm | github_2023 | others | 207 | coconut-svsm | msft-jlange | @@ -20,6 +20,8 @@ pub struct KernelLaunchInfo {
pub kernel_fs_end: u64,
pub cpuid_page: u64,
pub secrets_page: u64,
+ pub stage2_igvm_params_phys_addr: u64, | I think it would be cleaner if we avoid adding fields to the kernel launch info. That should be possible by changing `SvsmConfig::invalidate_boot_data()` to return a vector of regions to be invalidated instead of a bool. It could take the kernel launch info as its input and then it could add whatever regions are appr... |
svsm | github_2023 | others | 202 | coconut-svsm | joergroedel | @@ -66,6 +94,40 @@ pub fn verify_ghcb_version() {
);
}
+pub fn hypervisor_ghcb_features() -> GHCBHvFeatures {
+ *GHCB_HV_FEATURES
+}
+
+pub fn init_hypervisor_ghcb_features() -> Result<(), GhcbMsrError> {
+ write_msr(SEV_GHCB, GHCBMsr::SNP_HV_FEATURES_REQ);
+ raw_vmgexit();
+ let result = read_msr(S... | This check fails on current KVM because the HV does apparently not report the SEV_SNP_MULTI_VMPL and SEV_PAGE_STATE_CHANGE flags. Can the panic be temporarily removed? We have to fix up KVM first.
Please also report the `features` and `required` fields in the error message and format them with `{:#x}`. |
svsm | github_2023 | c | 201 | coconut-svsm | roy-hopkins | @@ -130,17 +98,31 @@ DATA_OBJ *insert_data_object(DATA_OBJ *data_object)
DATA_OBJ *allocate_data_object(uint64_t address, uint32_t size, uint32_t data_size)
{
+ uint32_t allocation_size;
DATA_OBJ *data_object;
data_object = malloc(sizeof(DATA_OBJ));
data_object->address = address;
data_obje... | This doesn't zero the padding. It is setting the start of the buffer to the first byte of `data_size`.
```suggestion
memset(&((uint8_t *)data_object->data)[data_size], 0, allocation_size - data_size);
``` |
svsm | github_2023 | cpp | 201 | coconut-svsm | roy-hopkins | @@ -0,0 +1,50 @@
+// SPDX-License-Identifier: MIT OR Apache-2.0
+//
+// Copyright (c) Microsoft Corporation
+//
+// Author: Jon Lange (jlange@microsoft.com)
+ | Missing guard to prevent including more than once. |
svsm | github_2023 | others | 201 | coconut-svsm | roy-hopkins | @@ -48,7 +48,11 @@ pub struct IgvmParamBlockFwInfo {
/// no firmware is launched after initialization is complete.
pub size: u32,
- _reserved: u32,
+ /// Indicates that the initial location of firmware is at the base of
+ /// memory and will not be loaded into the ROM range.
+ pub in_low_memory:... | I wonder if it makes more sense to invert this flag and name it something like `in_system_region` (see comment below regarding 'system')? This would then explain the change in behaviour when the firmware uses the ROM region. Or just rename it to `outside_system_region`? |
svsm | github_2023 | others | 201 | coconut-svsm | roy-hopkins | @@ -19,6 +19,44 @@ use crate::serial::SERIAL_PORT;
use crate::utils::MemoryRegion;
use alloc::vec::Vec;
+fn check_ovmf_regions(
+ flash_regions: &[MemoryRegion<PhysAddr>],
+ kernel_region: &MemoryRegion<PhysAddr>,
+) { | Further to our email/call discussion about the name of 'flash' in SVSM, I wonder if this function and parameters should be renamed. I'm not sure what would be a good name for the region from 3GB-4GB. ROM region? System region?
```suggestion
fn check_system_region(
fw_regions: &[MemoryRegion<PhysAddr>],
ke... |
svsm | github_2023 | others | 201 | coconut-svsm | roy-hopkins | @@ -93,12 +131,30 @@ impl<'a> SvsmConfig<'a> {
}
}
- pub fn get_fw_regions(&self) -> Result<Vec<MemoryRegion<PhysAddr>>, SvsmError> {
+ pub fn get_fw_regions(
+ &self,
+ kernel_region: &MemoryRegion<PhysAddr>,
+ ) -> Vec<MemoryRegion<PhysAddr>> {
match self {
... | Renaming `in_low_memory` and `check_ovmf_regions()` as per my above comments would result in something like this, which I think conveys the intent more clearly.
```suggestion
if igvm_params.fw_in_system_region() {
check_system_region(&fw_regions, kernel_region);
... |
svsm | github_2023 | others | 201 | coconut-svsm | roy-hopkins | @@ -199,14 +200,26 @@ impl IgvmParams<'_> {
}
}
- pub fn get_fw_regions(&self) -> Result<Vec<MemoryRegion<PhysAddr>>, SvsmError> {
- if !self.should_launch_fw() {
- Err(Firmware)
- } else {
- Ok(vec![MemoryRegion::new(
- PhysAddr::new(self.igvm_param... | You could use `fw_in_low_memory()` here. |
svsm | github_2023 | c | 201 | coconut-svsm | roy-hopkins | @@ -948,25 +923,51 @@ int main(int argc, const char *argv[])
return 1;
}
- address = (stage2_data->address + stage2_data->size + PAGE_SIZE - 1) &
- ~(PAGE_SIZE - 1);
- if (address > 0x9F000)
+ stage2_top = (stage2_data->address + stage2_data->size + PAGE_SIZE - 1) &
+ ... | This `else` condition can never be executed as it's already in an `if (is_hyperv)`. |
svsm | github_2023 | others | 199 | coconut-svsm | msft-jlange | @@ -19,6 +19,13 @@ KERNEL_ELF = "target/x86_64-unknown-none/${TARGET_PATH}/svsm"
TEST_KERNEL_ELF = target/x86_64-unknown-none/${TARGET_PATH}/svsm-test
FS_FILE ?= none
+FW_FILE ?= none
+ifneq ($(FW_FILE), none)
+BUILD_FW = --firmware ${FW_FILE} --fwtop 100000000 | It seems a little unusual to specify a hex address without the 0x prefix, but it's probably not significant enough to merit updating the parsing logic to recognize the number base. |
svsm | github_2023 | c | 199 | coconut-svsm | msft-jlange | @@ -688,6 +674,65 @@ int generate_igvm_file(const char *filename)
return 0;
}
+static int check_firmware_options()
+{
+ FILE *fp;
+
+ if (!fw_filename)
+ {
+ // Firmware image is optional.
+ return 0;
+ }
+
+ // Get the firmware file size so we can determine the top and bottom addr... | This is going to conflict with Hyper-V requirements. Is there any way to make this check, and the subsequent address validation, specific to QEMU configurations? |
svsm | github_2023 | c | 199 | coconut-svsm | msft-jlange | @@ -785,6 +830,39 @@ int parse_options(int argc, const char *argv[])
{
is_hyperv = 1;
}
+ else if (0 == strcmp(argv[0], "--firmware"))
+ {
+ if (argc == 1)
+ {
+ fprintf(stderr, "missing argument for --firmware\n");
+ retur... | Should add logic to ensure that --firmware cannot be specified twice. |
svsm | github_2023 | c | 199 | coconut-svsm | msft-jlange | @@ -984,6 +1086,24 @@ int main(int argc, const char *argv[])
address += PAGE_SIZE;
}
+ // If a firmware file has been specified then add it and set the relevant
+ // parameter block entries.
+ if (fw_filename)
+ {
+ igvm_parameter_block->firmware.size = fw_size;
+ igvm_paramet... | Perhaps gate this behind a -v or --verbose argument? |
svsm | github_2023 | others | 195 | coconut-svsm | roy-hopkins | @@ -94,29 +95,64 @@ pub fn init_page_table(launch_info: &KernelLaunchInfo, kernel_elf: &elf::Elf64Fi
set_init_pgtable(pgtable);
}
-pub fn invalidate_stage2(config: &SvsmConfig) -> Result<(), SvsmError> {
- let pstart = PhysAddr::null();
- let pend = pstart + (640 * 1024);
- let mut paddr = pstart;
-
- ... | This calls `invalidate_boot_memory_region()` even if the filesystem range is empty. If the config specifies that a page state change is required then this will result in a call to `ghcb().page_state_change()`. Maybe this should only call `invalidate_boot_memory_region()` if `kernel_fs_size` is > 0? |
svsm | github_2023 | others | 189 | coconut-svsm | joergroedel | @@ -114,18 +124,5 @@ pub fn request_loop() {
// Write back results
params.write_back(vmsa);
-
- // Make VMSA runable again by setting EFER.SVME
- vmsa.enable();
-
- flush_tlb_global_sync();
-
- // Check if mappings still valid
- if update_mappings().is_ok() { | I don't see the call to update_mappings() moved, why is it safe to remove it? Also, I think the commit message should explain the reasoning behind this change. |
svsm | github_2023 | others | 177 | coconut-svsm | joergroedel | @@ -171,6 +186,7 @@ impl<T: BitmapAllocator + Debug> BitmapAllocator for BitmapAllocatorTree<T> {
fn alloc_aligned(ba: &mut impl BitmapAllocator, entries: usize, align: usize) -> Option<usize> {
// Iterate through the bitmap checking on each alignment boundary
// for a free range of the requested size
+ a... | I am wondering whether this should be an assert or a `return None`? |
svsm | github_2023 | others | 183 | coconut-svsm | stefano-garzarella | @@ -219,13 +221,14 @@ impl VirtualMapping for VMFileMapping {
write: bool,
) -> Result<VMPageFaultResolution, SvsmError> {
let page_size = self.page_size();
+ let page_size_bytes = usize::from(page_size);
if write {
if let Some(write_copy) = self.write_copy.as_mut() {... | What about adding `PageSize::mask()`?
I mean something like this:
```diff
diff --git a/src/mm/vm/mapping/file_mapping.rs b/src/mm/vm/mapping/file_mapping.rs
index 51540aa..a687442 100644
--- a/src/mm/vm/mapping/file_mapping.rs
+++ b/src/mm/vm/mapping/file_mapping.rs
@@ -222,7 +222,6 @@ impl VirtualMapping for VM... |
svsm | github_2023 | others | 182 | coconut-svsm | stefano-garzarella | @@ -22,8 +22,22 @@ FS_FILE ?= none
C_BIT_POS ?= 51
STAGE1_OBJS = stage1/stage1.o stage1/reset.o
+IGVM_FILES = bin/coconut-qemu.igvm bin/coconut-hyperv.igvm | we have some binaries in the root (e.g. `svsm.bin`) others in `stage1/`, what about place those new binaries in `igvm/`?
This is not a strong opinion, I'm fine also with `bin`, but I'd move all the binaries there, but we can do in another PR ;-) |
svsm | github_2023 | cpp | 182 | coconut-svsm | roy-hopkins | @@ -0,0 +1,86 @@
+// SPDX-License-Identifier: MIT OR Apache-2.0
+//
+// Copyright (c) Microsoft Corporation
+//
+// Author: Jon Lange (jlange@microsoft.com)
+
+typedef enum {
+ IGVM_VHT_SUPPORTED_PLATFORM = 0x1,
+ IGVM_VHT_PARAMETER_AREA = 0x301,
+ IGVM_VHT_PAGE_DATA = 0x302,
+ IGVM_VHT_PARAMETER_INSERT = 0... | It would be nice if we could use the header file generated as part of this PR: https://github.com/microsoft/igvm/pull/3
Or, even better, depend on the C library. Something to consider when that PR gets merged.
But maybe it's not important if this is going to be replace with a rust version soon. |
svsm | github_2023 | c | 182 | coconut-svsm | roy-hopkins | @@ -0,0 +1,892 @@
+// SPDX-License-Identifier: MIT OR Apache-2.0
+//
+// Copyright (c) Microsoft Corporation
+//
+// Author: Jon Lange (jlange@microsoft.com)
+//
+// This module is provided in C as a bootstrapper to permit generation of IGVM
+// files pending creation of a Rust version. The C version should be
+// mai... | Shouldn't this be 0 for SNP, being the highest privilege level activated on the guest? |
svsm | github_2023 | others | 178 | coconut-svsm | joergroedel | @@ -663,17 +663,39 @@ impl MemoryRegion {
self.write_page_info(i, pg);
}
- self.nr_pages[0] = self.page_count - meta_pages;
-
/* Mark all pages as allocated */
for i in meta_pages..self.page_count {
let pg = PageInfo::Allocated(AllocatedInfo { order: 0 });
... | This is a good optimization, thanks. I think there is one thing missing, which is the initializations of the PageInfos for the compound pages that are freed via `free_page_order()`.
The allocator manages one PageInfo per PAGE_SIZE chunk of memory. This means that for pages with `order > 0` there are multiple `PageInfo... |
svsm | github_2023 | others | 178 | coconut-svsm | joergroedel | @@ -663,17 +665,40 @@ impl MemoryRegion {
self.write_page_info(i, pg);
}
- self.nr_pages[0] = self.page_count - meta_pages;
-
/* Mark all pages as allocated */
for i in meta_pages..self.page_count {
let pg = PageInfo::Allocated(AllocatedInfo { order: 0 });
... | Thanks, looks good now. |
svsm | github_2023 | others | 181 | coconut-svsm | msft-jlange | @@ -473,8 +470,7 @@ pub extern "C" fn svsm_main() {
if let Err(e) = copy_tables_to_fw(fw_meta) { | Your PR moves the location of the firmware to the IGVM file (which is good) but there is still a hardcoded assumption that the firmware wants CPUID/secrets information in a particular place (see map_and_parse_fw_meta). Shouldn't this be abstracted in the IGVM as well so that the SVSM is not making assumptions about OV... |
svsm | github_2023 | others | 181 | coconut-svsm | 00xc | @@ -217,7 +217,7 @@ impl<'a> FwCfg<'a> {
// This needs to be &mut self to prevent iterator invalidation, where the caller
// could do fw_cfg.select() while iterating. Having a mutable reference prevents
// other references.
- pub fn iter_flash_regions(&mut self) -> impl Iterator<Item = MemoryRegion<Ph... | This change ignores the comment above the function. Not taking `&mut self` allows potential misbehavior. The comment should be updated or the change reverted. |
svsm | github_2023 | others | 180 | coconut-svsm | stefano-garzarella | @@ -334,6 +330,10 @@ pub extern "C" fn svsm_start(li: &KernelLaunchInfo, vb_addr: usize) {
load_gdt();
early_idt_init();
+ // Capture the debug serial port befure the launch info disappears from | s/befure/before |
svsm | github_2023 | others | 169 | coconut-svsm | stefano-garzarella | @@ -148,7 +148,12 @@ impl ValidBitmap {
/// The number of u64's in the bitmap
fn bitmap_len(&self) -> usize {
let num_pages = self.region.len() / PAGE_SIZE;
- num_pages.div_ceil(u64::BITS as usize)
+ let additional_u64 = if self.region.len() % PAGE_SIZE != 0 {
+ 1
+ } ... | Not a strong opinion, but eventually we can avoid `additional_u64` and do something like this:
```suggestion
if self.region.len() % PAGE_SIZE != 0 {
num_pages + 1
} else {
num_pages
}
``` |
svsm | github_2023 | others | 176 | coconut-svsm | roy-hopkins | @@ -51,6 +51,10 @@ startup_32:
movl $STAGE2_START, %esp
/* Write startup information to stage2 stack */
+ xorl %eax, eax | The second eax should be `%eax`. |
svsm | github_2023 | others | 172 | coconut-svsm | 00xc | @@ -102,3 +102,25 @@ pub fn writable_phys_addr(paddr: PhysAddr) -> bool {
valid_phys_address(paddr)
}
+
+#[cfg(test)]
+#[cfg_attr(test_in_svsm, ignore = "Offline testing")] | Please remove this. Everything else looks good.
```
warning: `#[ignore]` only has an effect on functions
--> src/mm/memory.rs:107:26
|
107 | #[cfg_attr(test_in_svsm, ignore = "Offline testing")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(unused_attributes)]` on ... |
svsm | github_2023 | others | 168 | coconut-svsm | 00xc | @@ -449,31 +449,43 @@ pub extern "C" fn svsm_main() {
start_secondary_cpus(&cpus);
- let fw_meta = map_and_parse_fw_meta()
- .unwrap_or_else(|e| panic!("Failed to parse FW SEV meta-data: {:#?}", e));
+ let fw_metadata: Option<SevFWMetaData>;
+ if config.should_launch_fw() {
+ fw_metadata... | The `fw_metadata` can be constructed directly:
```suggestion
let fw_metadata = if config.should_launch_fw() {
Some(
map_and_parse_fw_meta()
.unwrap_or_else(|e| panic!("Failed to parse FW SEV meta-data: {:#?}", e)),
)
} else {
None
};
```
Or ... |
svsm | github_2023 | others | 170 | coconut-svsm | 00xc | @@ -99,3 +99,23 @@ pub fn writable_phys_addr(paddr: PhysAddr) -> bool {
valid_phys_address(paddr)
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use crate::address::PhysAddr;
+
+ #[test]
+ fn test_valid_phys_address() {
+ let start = PhysAddr::new(0x1000);
+ let end = PhysAddr::new(0... | Please remove the region again from `MEMORY_MAP` so this does not have a chance to interfere with something else when running inside the SVSM. |
svsm | github_2023 | others | 170 | coconut-svsm | 00xc | @@ -222,3 +222,31 @@ impl<T: Sized + Copy> GuestPtr<T> {
unsafe { GuestPtr::from_ptr(self.ptr.offset(count)) }
}
}
+
+mod tests {
+
+ #[test]
+ fn test_read_u8_valid_address() { | This ends up using inline assembly, so Miri cannot handle it.
```suggestion
#[test]
#[cfg_attr(miri, ignore)]
fn test_read_u8_valid_address() {
``` |
svsm | github_2023 | others | 170 | coconut-svsm | 00xc | @@ -222,3 +222,31 @@ impl<T: Sized + Copy> GuestPtr<T> {
unsafe { GuestPtr::from_ptr(self.ptr.offset(count)) }
}
}
+
+mod tests {
+
+ #[test]
+ fn test_read_u8_valid_address() {
+ use crate::mm::guestmem::*;
+ // Create a region to read from
+ let test_buffer: [u8; 6] = [0; 6];... | Nit: instead of using "as" casting, you can simply do:
```suggestion
let test_address = VirtAddr::from(test_buffer.as_ptr());
let result = read_u8(test_address).unwrap();
``` |
svsm | github_2023 | others | 170 | coconut-svsm | 00xc | @@ -222,3 +222,31 @@ impl<T: Sized + Copy> GuestPtr<T> {
unsafe { GuestPtr::from_ptr(self.ptr.offset(count)) }
}
}
+
+mod tests {
+
+ #[test]
+ fn test_read_u8_valid_address() {
+ use crate::mm::guestmem::*;
+ // Create a region to read from
+ let test_buffer: [u8; 6] = [0; 6];... | ```suggestion
#[test]
#[cfg_attr(miri, ignore)]
fn test_write_u8_valid_address() {
``` |
svsm | github_2023 | others | 170 | coconut-svsm | 00xc | @@ -222,3 +222,31 @@ impl<T: Sized + Copy> GuestPtr<T> {
unsafe { GuestPtr::from_ptr(self.ptr.offset(count)) }
}
}
+
+mod tests {
+
+ #[test]
+ fn test_read_u8_valid_address() {
+ use crate::mm::guestmem::*;
+ // Create a region to read from
+ let test_buffer: [u8; 6] = [0; 6];... | Nit: same here, instead of 'as' casting:
```suggestion
let test_address = VirtAddr::from(test_buffer.as_mut_ptr());
let data_to_write = 0x42;
write_u8(test_address, data_to_write).unwrap();
``` |
svsm | github_2023 | others | 170 | coconut-svsm | 00xc | @@ -153,3 +153,67 @@ pub const SVSM_PERTASK_END: VirtAddr = SVSM_PERTASK_BASE.const_add(SIZE_LEVEL3);
/// Kernel stack for a task
pub const SVSM_PERTASK_STACK_BASE: VirtAddr = SVSM_PERTASK_BASE;
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ static KERNEL_MAPPING_TEST: ImmutAfterInitCell<KernelMapping> = Im... | This test fails inside the SVSM when calling `phys_to_virt()` in this panic:
https://github.com/coconut-svsm/svsm/blob/be10d1b5ef8f4365434238e916623f14b59359d5/src/mm/address_space.rs#L43-L47
I suspect some of the other tests might also fail.
|
svsm | github_2023 | others | 143 | coconut-svsm | 00xc | @@ -157,5 +157,68 @@ pub const SVSM_PERTASK_BASE: VirtAddr = virt_from_idx(PGTABLE_LVL3_IDX_PERTASK);
/// End address of task memory region
pub const SVSM_PERTASK_END: VirtAddr = SVSM_PERTASK_BASE.const_add(SIZE_LEVEL3);
-/// Kernel stack for a task
-pub const SVSM_PERTASK_STACK_BASE: VirtAddr = SVSM_PERTASK_BASE;
... | I think this will be problematic when running tests inside the SVSM. If a test runs before `test_init_kernel_mapping_info()`, it will access an uninitialized `KERNEL_MAPPING` (via `phys_to_virt()` or `virt_to_phys()`), leading to undefined behavior.
This does not happen when running tests regularly because `virt_to_... |
svsm | github_2023 | others | 162 | coconut-svsm | 00xc | @@ -0,0 +1,18 @@
+#![no_main]
+
+use libfuzzer_sys::{fuzz_target, Corpus};
+use svsm::cpu::insn::{Instruction, MAX_INSN_SIZE};
+
+fuzz_target!(|input: &[u8]| -> Corpus {
+ if input.len() < MAX_INSN_SIZE {
+ return Corpus::Reject;
+ }
+
+ let mut data = [0u8; MAX_INSN_SIZE];
+ data.copy_from_slice(&in... | You can merge the bounds check and the access into one. This might not look too useful, but since most harnesses are ran with debug assertions enabled this *might* avoid a needless bounds check when doing `&input[..MAX_INSN_SIZE]`.
```suggestion
let Some(input) = input.get(..MAX_INSN_SIZE) else {
retur... |
svsm | github_2023 | others | 162 | coconut-svsm | 00xc | @@ -0,0 +1,18 @@
+#![no_main]
+
+use libfuzzer_sys::{fuzz_target, Corpus};
+use svsm::cpu::insn::{Instruction, MAX_INSN_SIZE};
+
+fuzz_target!(|input: &[u8]| -> Corpus {
+ if input.len() < MAX_INSN_SIZE {
+ return Corpus::Reject;
+ }
+
+ let mut data = [0u8; MAX_INSN_SIZE];
+ data.copy_from_slice(&in... | The compiler might optimize this away depending on compilation flags.
```suggestion
let _ = core::hint::black_box(insn.decode());
``` |
svsm | github_2023 | others | 166 | coconut-svsm | 00xc | @@ -62,20 +62,25 @@ pub mod svsm_gdbstub {
Ok(())
}
- #[derive(PartialEq, Eq)]
+ #[derive(PartialEq, Eq, Debug)]
enum ExceptionType {
Debug,
SwBreakpoint,
PageFault,
}
+ impl From<usize> for ExceptionType {
+ fn from(value: usize) -> Self {
+ ... | And now you can inline this function in the callers in my opinion, since it's only one line :) |
svsm | github_2023 | others | 159 | coconut-svsm | 00xc | @@ -72,15 +72,12 @@ pub mod svsm_gdbstub {
pub fn handle_debug_exception(ctx: &mut X86ExceptionContext, exception: usize) {
let tp = match exception {
BP_VECTOR => ExceptionType::SwBreakpoint,
+ VC_VECTOR => ExceptionType::Debug,
_ => ExceptionType::PageFault,
... | While you are cleaning things up, could you implement `From<usize> for ExceptionType` and do this match case there? |
svsm | github_2023 | others | 134 | coconut-svsm | Freax13 | @@ -152,11 +152,20 @@ impl ValidBitmap {
bitmap_alloc_order(self.pbase, self.pend)
}
- fn migrate(&mut self, new_bitmap: *mut u64) {
- let (count, _) = self.index(self.pend);
+ /// The number of u64's in the bitmap
+ fn bitmap_len(&self) -> usize {
+ let num_pages = self.pend.bits... | Is the check correct? I'd expect it to be `num_pages % u64::BITS as usize != 0`. Note that you may be able to use [`usize::div_ceil`](https://doc.rust-lang.org/std/primitive.usize.html#method.div_ceil) here (which was stabilized very recently). |
svsm | github_2023 | others | 55 | coconut-svsm | joergroedel | @@ -0,0 +1,60 @@
+// SPDX-License-Identifier: MIT OR Apache-2.0
+//
+// Copyright (c) 2022-2023 SUSE LLC
+//
+// Author: Thomas Leroy <tleroy@suse.de> | When you move code to a new file, please also add the original authors to the file header. |
svsm | github_2023 | others | 55 | coconut-svsm | AdamCDunlap | @@ -39,18 +35,22 @@ pub const _HV_VECTOR: usize = 28;
pub const VC_VECTOR: usize = 29;
pub const _SX_VECTOR: usize = 30;
+pub const SVM_EXIT_EXCP_BASE: usize = 0x40;
+pub const X86_TRAP_DB: usize = 0x01;
+
#[repr(C, packed)]
#[derive(Default, Debug)]
pub struct X86ExceptionContext {
pub regs: X86GeneralRegs... | This struct is constructed manually in assembly, and I don't believe this PR adds space for the insn member, meaning that when insn is written it overwrites things on the stack from before the interrupt happens.
I think it'd be better to leave insn out of this context and just have it as a separate variable returned... |
svsm | github_2023 | others | 55 | coconut-svsm | AdamCDunlap | @@ -0,0 +1,136 @@
+// SPDX-License-Identifier: MIT OR Apache-2.0
+//
+// Copyright (c) 2022-2023 SUSE LLC
+//
+// Authors: Joerg Roedel <jroedel@suse.de>
+
+use super::super::control_regs::read_cr2;
+use super::super::extable::handle_exception_table;
+use super::super::tss::IST_DF;
+use super::super::vc::handle_vc_exce... | I believe this is copied from the old code, but still worth changing: This function is called manually from assembly, so it should have extern "C". Otherwise, it uses the rust ABI which may not have the argument be passed in %rdi. |
svsm | github_2023 | others | 55 | coconut-svsm | 00xc | @@ -4,28 +4,266 @@
//
// Author: Joerg Roedel <jroedel@suse.de>
-use super::idt::X86ExceptionContext;
-use crate::cpu::extable::handle_exception_table;
+use super::idt::common::X86ExceptionContext;
+use crate::cpu::cpuid::{cpuid_table_raw, CpuidLeaf};
+use crate::cpu::insn::{insn_fetch, Instruction};
+use crate::cp... | `SVM_EXIT_EXCP_BASE` is duplicated, it could be imported from `src/cpu/idt/common.rs`. |
svsm | github_2023 | others | 55 | coconut-svsm | 00xc | @@ -4,28 +4,266 @@
//
// Author: Joerg Roedel <jroedel@suse.de>
-use super::idt::X86ExceptionContext;
-use crate::cpu::extable::handle_exception_table;
+use super::idt::common::X86ExceptionContext;
+use crate::cpu::cpuid::{cpuid_table_raw, CpuidLeaf};
+use crate::cpu::insn::{insn_fetch, Instruction};
+use crate::cp... | `X86_TRAP_DB` is also duplicate from `src/cpu/idt/common.rs`. |
svsm | github_2023 | others | 55 | coconut-svsm | 00xc | @@ -4,28 +4,266 @@
//
// Author: Joerg Roedel <jroedel@suse.de>
-use super::idt::X86ExceptionContext;
-use crate::cpu::extable::handle_exception_table;
+use super::idt::common::X86ExceptionContext;
+use crate::cpu::cpuid::{cpuid_table_raw, CpuidLeaf};
+use crate::cpu::insn::{insn_fetch, Instruction};
+use crate::cp... | If we are going to panic on error then perhaps `panic!()` should be inside the `_ => ` branch of the match statement. |
svsm | github_2023 | others | 55 | coconut-svsm | 00xc | @@ -4,28 +4,266 @@
//
// Author: Joerg Roedel <jroedel@suse.de>
-use super::idt::X86ExceptionContext;
-use crate::cpu::extable::handle_exception_table;
+use super::idt::common::X86ExceptionContext;
+use crate::cpu::cpuid::{cpuid_table_raw, CpuidLeaf};
+use crate::cpu::insn::{insn_fetch, Instruction};
+use crate::cp... | There's a few places where we panic on `SvsmError`s containing this error and print the RIP and error code, so perhaps these variants should contain information about that error, so that we do not have to explicitly write out all that information. Something like:
```rust
pub enum VcError {
...
DecodeFaile... |
svsm | github_2023 | others | 55 | coconut-svsm | 00xc | @@ -4,28 +4,266 @@
//
// Author: Joerg Roedel <jroedel@suse.de>
-use super::idt::X86ExceptionContext;
-use crate::cpu::extable::handle_exception_table;
+use super::idt::common::X86ExceptionContext;
+use crate::cpu::cpuid::{cpuid_table_raw, CpuidLeaf};
+use crate::cpu::insn::{insn_fetch, Instruction};
+use crate::cp... | Same here, the error handling should be inside the match statement. |
svsm | github_2023 | others | 55 | coconut-svsm | 00xc | @@ -4,28 +4,266 @@
//
// Author: Joerg Roedel <jroedel@suse.de>
-use super::idt::X86ExceptionContext;
-use crate::cpu::extable::handle_exception_table;
+use super::idt::common::X86ExceptionContext;
+use crate::cpu::cpuid::{cpuid_table_raw, CpuidLeaf};
+use crate::cpu::insn::{insn_fetch, Instruction};
+use crate::cp... | ```suggestion
let Some(ret) = cpuid_table_raw(leaf.cpuid_fn, leaf.cpuid_subfn, 0, 0) else {
return Err(SvsmError::Vc(VcError::UnknownCpuidLeaf));
};
``` |
svsm | github_2023 | others | 55 | coconut-svsm | 00xc | @@ -4,28 +4,266 @@
//
// Author: Joerg Roedel <jroedel@suse.de>
-use super::idt::X86ExceptionContext;
-use crate::cpu::extable::handle_exception_table;
+use super::idt::common::X86ExceptionContext;
+use crate::cpu::cpuid::{cpuid_table_raw, CpuidLeaf};
+use crate::cpu::insn::{insn_fetch, Instruction};
+use crate::cp... | ```suggestion
let (size, mask) = if insn.prefixes.nb_bytes > 0 {
// inw instruction has a 0x66 operand-size prefix for word-sized operands
(GHCBIOSize::Size16, u16::MAX as u64)
} else {
(GHCBIOSize::Size32, u32::MAX as u64)
};
``... |
svsm | github_2023 | others | 55 | coconut-svsm | 00xc | @@ -4,28 +4,266 @@
//
// Author: Joerg Roedel <jroedel@suse.de>
-use super::idt::X86ExceptionContext;
-use crate::cpu::extable::handle_exception_table;
+use super::idt::common::X86ExceptionContext;
+use crate::cpu::cpuid::{cpuid_table_raw, CpuidLeaf};
+use crate::cpu::insn::{insn_fetch, Instruction};
+use crate::cp... | ```suggestion
let size = if insn.prefixes.nb_bytes > 0 {
// outw instruction has a 0x66 operand-size prefix for word-sized operands.
GHCBIOSize::Size16
} else {
GHCBIOSize::Size32
};
``` |
svsm | github_2023 | others | 55 | coconut-svsm | 00xc | @@ -4,28 +4,266 @@
//
// Author: Joerg Roedel <jroedel@suse.de>
-use super::idt::X86ExceptionContext;
-use crate::cpu::extable::handle_exception_table;
+use super::idt::common::X86ExceptionContext;
+use crate::cpu::cpuid::{cpuid_table_raw, CpuidLeaf};
+use crate::cpu::insn::{insn_fetch, Instruction};
+use crate::cp... | ```suggestion
// TODO: the instruction fetch will likely to be handled differently when
// #VC exception will be raised from CPL > 0.
``` |
svsm | github_2023 | others | 55 | coconut-svsm | 00xc | @@ -0,0 +1,122 @@
+// SPDX-License-Identifier: MIT OR Apache-2.0
+//
+// Copyright (c) 2022-2023 SUSE LLC
+//
+// Author: Thomas Leroy <tleroy@suse.de>
+
+extern crate alloc;
+
+use crate::cpu::vc::VcError;
+use crate::error::SvsmError;
+use core::ptr;
+
+const MAX_INSN_SIZE: usize = 15;
+const MAX_INSN_FIELD_SIZE: usi... | Let's remove the double negative
```suggestion
/// The caller should validate that `rip` is set to a valid address.
``` |
svsm | github_2023 | others | 55 | coconut-svsm | 00xc | @@ -4,28 +4,266 @@
//
// Author: Joerg Roedel <jroedel@suse.de>
-use super::idt::X86ExceptionContext;
-use crate::cpu::extable::handle_exception_table;
+use super::idt::common::X86ExceptionContext;
+use crate::cpu::cpuid::{cpuid_table_raw, CpuidLeaf};
+use crate::cpu::insn::{insn_fetch, Instruction};
+use crate::cp... | Please add a `// SAFETY:` comment here. In fact I'm not sure this is safe, as RIP could be set close to a boundary to an unmaped page. `insn_fetch` will read `MAX_INSN_SIZE` bytes, which may or may not be in bounds. |
svsm | github_2023 | others | 55 | coconut-svsm | 00xc | @@ -0,0 +1,122 @@
+// SPDX-License-Identifier: MIT OR Apache-2.0
+//
+// Copyright (c) 2022-2023 SUSE LLC
+//
+// Author: Thomas Leroy <tleroy@suse.de>
+
+extern crate alloc;
+
+use crate::cpu::vc::VcError;
+use crate::error::SvsmError;
+use core::ptr;
+
+const MAX_INSN_SIZE: usize = 15;
+const MAX_INSN_FIELD_SIZE: usi... | ```suggestion
pub unsafe fn insn_fetch(rip: *const u8) -> [u8; MAX_INSN_SIZE] {
rip.cast::<[u8; MAX_INSN_SIZE]>.read()
}
``` |
svsm | github_2023 | others | 55 | coconut-svsm | 00xc | @@ -0,0 +1,114 @@
+// SPDX-License-Identifier: MIT OR Apache-2.0
+//
+// Copyright (c) 2022-2023 SUSE LLC
+//
+// Author: Thomas Leroy <tleroy@suse.de>
+
+extern crate alloc;
+
+use crate::cpu::vc::VcError;
+use crate::error::SvsmError;
+
+const MAX_INSN_SIZE: usize = 15;
+const MAX_INSN_FIELD_SIZE: usize = 3;
+
+#[der... | There are several arrays with a field to track length, so how about the following to reduce code duplication:
```rust
#[derive(Debug, Copy, Clone, Default)]
pub(super) struct InsBuffer<const N: usize>
where
[u8; N]: Default,
{
buf: [u8; N],
len: usize,
}
#[derive(Debug, Copy, Clone, Default)]
... |
svsm | github_2023 | others | 55 | coconut-svsm | 00xc | @@ -0,0 +1,114 @@
+// SPDX-License-Identifier: MIT OR Apache-2.0
+//
+// Copyright (c) 2022-2023 SUSE LLC
+//
+// Author: Thomas Leroy <tleroy@suse.de>
+
+extern crate alloc;
+
+use crate::cpu::vc::VcError;
+use crate::error::SvsmError;
+
+const MAX_INSN_SIZE: usize = 15;
+const MAX_INSN_FIELD_SIZE: usize = 3;
+
+#[der... | ```suggestion
opcode: InstructionField::default(), // we'll copy content later
``` |
svsm | github_2023 | others | 55 | coconut-svsm | 00xc | @@ -0,0 +1,114 @@
+// SPDX-License-Identifier: MIT OR Apache-2.0
+//
+// Copyright (c) 2022-2023 SUSE LLC
+//
+// Author: Thomas Leroy <tleroy@suse.de>
+
+extern crate alloc;
+
+use crate::cpu::vc::VcError;
+use crate::error::SvsmError;
+
+const MAX_INSN_SIZE: usize = 15;
+const MAX_INSN_FIELD_SIZE: usize = 3;
+
+#[der... | ```suggestion
/// # Safety
///
/// The caller should validate that `rip` is set to a valid address
/// and that the next [`MAX_INSN_SIZE`] bytes are within valid memory.
``` |
svsm | github_2023 | others | 124 | coconut-svsm | 00xc | @@ -19,6 +19,9 @@ all: svsm.bin
test:
cargo test --target=x86_64-unknown-linux-gnu
+doc:
+ cargo doc --open | We probably also want `--all-features`. Perhaps even `--document-private-items`. |
svsm | github_2023 | others | 124 | coconut-svsm | 00xc | @@ -19,6 +19,9 @@ all: svsm.bin
test:
cargo test --target=x86_64-unknown-linux-gnu
+doc:
+ cargo doc --open --document-private-items | `--all-features` still missing |
svsm | github_2023 | others | 109 | coconut-svsm | 00xc | @@ -46,27 +45,20 @@ impl PerCpuInfo {
// PERCPU areas virtual addresses into shared memory
pub static PERCPU_AREAS: PerCpuAreas = PerCpuAreas::new();
-// We use an UnsafeCell to allow for a static with interior
-// mutability. Normally, we would need to guarantee synchronization
-// on the backing datatype, but thi... | `RWLock` introduces unnecessary overhead in my opinion, so I'd say this change is not needed, as the comment explains. Safety is already documented and limited to private functions. |
svsm | github_2023 | others | 109 | coconut-svsm | joergroedel | @@ -5,62 +5,62 @@
// Author: Joerg Roedel <jroedel@suse.de>
use core::cell::UnsafeCell;
-use core::fmt::Debug;
use core::ops::{Deref, DerefMut};
use core::sync::atomic::{AtomicU64, Ordering};
#[derive(Debug)]
-pub struct ReadLockGuard<'a, T: Debug> {
+pub struct ReadLockGuard<'a, T> {
rwlock: &'a AtomicU6... | Hmm, I don't buy the justification for this. In my thinking, the purpose of `RWLock` is to add `Sync` to any type by:
1. Serializing writes wrt. other writes and readers (there is no reader active when write-lock is aquired)
2. Allowing multiple readers at the same time by using the fact that immutable values are a... |
svsm | github_2023 | others | 109 | coconut-svsm | joergroedel | @@ -5,62 +5,62 @@
// Author: Joerg Roedel <jroedel@suse.de>
use core::cell::UnsafeCell;
-use core::fmt::Debug;
use core::ops::{Deref, DerefMut};
use core::sync::atomic::{AtomicU64, Ordering};
#[derive(Debug)]
-pub struct ReadLockGuard<'a, T: Debug> {
+pub struct ReadLockGuard<'a, T> { | There was some reasoning behind adding those bounds. @00xc might know more, probably because it will make it easier to add a Debug trait to structs containing a lock. |
svsm | github_2023 | others | 109 | coconut-svsm | joergroedel | @@ -129,20 +125,17 @@ impl SvsmFs {
}
}
-static mut FS_ROOT: SvsmFs = SvsmFs::new();
+static FS_ROOT: RWLock<SvsmFs> = RWLock::new(SvsmFs::new()); | Is there another reason for the lock besides removing the `mut`? This change has a significant impact on the scalability of the FS code, so if there is no other reason I'd rather live the the `mut` than introducing a lock. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.