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
64
coconut-svsm
00xc
@@ -0,0 +1,94 @@ +// 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::TaskState; +use super::{Task, TaskError}; +use crate::error::SvsmError; +use crate::locking::SpinLock; ...
I don't think we need to scope this, no? The lock will be dropped at the end of the function: ```rust ... let node = ...; TASKLIST.lock().push_front(node.clone()); Ok(node) } ```
svsm
github_2023
others
64
coconut-svsm
00xc
@@ -0,0 +1,94 @@ +// 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::TaskState; +use super::{Task, TaskError}; +use crate::error::SvsmError; +use crate::locking::SpinLock; ...
I would add a comment here as requested by clippy. The caller must ensure that the provided pointer comes from the global TASKLIST structure.
svsm
github_2023
others
64
coconut-svsm
00xc
@@ -8,25 +8,156 @@ extern crate alloc; use core::cell::RefCell; -use super::TaskState; +use super::{tasks::TaskRuntime, TaskState, INITIAL_TASK_ID}; use super::{Task, TaskError}; use crate::error::SvsmError; use crate::locking::SpinLock; use alloc::boxed::Box; use alloc::rc::Rc; use intrusive_collections::li...
Returning an `Option<TaskPointer>` is probably more clear since we introduced that typedef.
svsm
github_2023
others
64
coconut-svsm
00xc
@@ -8,25 +8,156 @@ extern crate alloc; use core::cell::RefCell; -use super::TaskState; +use super::{tasks::TaskRuntime, TaskState, INITIAL_TASK_ID}; use super::{Task, TaskError}; use crate::error::SvsmError; use crate::locking::SpinLock; use alloc::boxed::Box; use alloc::rc::Rc; use intrusive_collections::li...
This does not need to be `&mut`, as `tree()` already returns a mutable reference. These two lines can be: ```rust let cursor = self.tree().lower_bound(Bound::Included(&0)); ```
svsm
github_2023
others
64
coconut-svsm
00xc
@@ -8,25 +8,156 @@ extern crate alloc; use core::cell::RefCell; -use super::TaskState; +use super::{tasks::TaskRuntime, TaskState, INITIAL_TASK_ID}; use super::{Task, TaskError}; use crate::error::SvsmError; use crate::locking::SpinLock; use alloc::boxed::Box; use alloc::rc::Rc; use intrusive_collections::li...
We can avoid the unwrap here, plus a level of indentation: ```rust fn update_current_task(&mut self) -> Option<TaskPointer>{ ... let task_ptr = self.current_task.take()?; let mut task_cursor = unsafe { self.tree() .cursor_mut_from_ptr(task_ptr.as_ref()) }; ... Som...
svsm
github_2023
others
64
coconut-svsm
00xc
@@ -8,25 +8,156 @@ extern crate alloc; use core::cell::RefCell; -use super::TaskState; +use super::{tasks::TaskRuntime, TaskState, INITIAL_TASK_ID}; use super::{Task, TaskError}; use crate::error::SvsmError; use crate::locking::SpinLock; use alloc::boxed::Box; use alloc::rc::Rc; use intrusive_collections::li...
I think this is mostly fine since it is a private function, but perhaps we could annotate it with unsafe.
svsm
github_2023
others
64
coconut-svsm
00xc
@@ -277,6 +277,33 @@ pub fn is_current_task(id: u32) -> bool { } } +pub fn current_task_terminated() { + // Restrict the scope of the mutable borrow below otherwise when the task context + // is switched via schedule() the borrow remains in scope. + { + let this_task = this_cpu_mut() + ...
So I'm not sure I fully understand, but isn't this what `TaskScheduler::deallocate()` is already doing? Any reason we're not using that function? Also, I don't see `close_task()` called anywhere, it seems to me that functionality should be done from `TaskScheduler::deallocate()`, which should take `&mut self` (at th...
svsm
github_2023
others
64
coconut-svsm
00xc
@@ -0,0 +1,75 @@ +// 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 crate::error::SvsmError; +use crate::locking::SpinLock; +use alloc::boxed::Box; +use alloc::...
Just a nitpick, but rustc can already figure out this generic, we can simply do: ```rust .get_or_insert_with(|| LinkedList::new(TaskTreeAdapter::new())) ```
svsm
github_2023
others
64
coconut-svsm
00xc
@@ -9,22 +9,170 @@ extern crate alloc; use core::cell::RefCell; use super::Task; +use super::{tasks::TaskRuntime, TaskState, INITIAL_TASK_ID}; use crate::error::SvsmError; use crate::locking::SpinLock; use alloc::boxed::Box; use alloc::rc::Rc; use intrusive_collections::linked_list::Link; -use intrusive_collec...
Same here, the generic in RBTree can be omitted.
svsm
github_2023
others
64
coconut-svsm
00xc
@@ -9,22 +9,170 @@ extern crate alloc; use core::cell::RefCell; use super::Task; +use super::{tasks::TaskRuntime, TaskState, INITIAL_TASK_ID}; use crate::error::SvsmError; use crate::locking::SpinLock; use alloc::boxed::Box; use alloc::rc::Rc; use intrusive_collections::linked_list::Link; -use intrusive_collec...
Unless I'm missing something about the borrowing here, we can get rid of an unwrap by using `Option::filter()`: ```rust if let Some(task_node) = cursor.get().filter(|task_node| Self::is_cpu_candidate(...)) { { let mut t = task_node.task.borrow_mut(); ... } ... } ```
svsm
github_2023
others
64
coconut-svsm
00xc
@@ -220,5 +221,25 @@ pub fn create_task( task: RefCell::new(task), }); TASKLIST.lock().list().push_front(node.clone()); + // Allocate any unallocated tasks (including the newly created one) + // to the current CPU + this_cpu_mut().runqueue.allocate(this_cpu().get_apic_id());
It's unfortunate that we grab the `TASKLIST` lock twice in a row (here and in `RunQueue::allocate()`. I don't think it will be too important for performance so perhaps this is just a nitpick, but I wonder if we could rework this to avoid it, as it seems a bit awkward. Maybe having `allocate()` take a mutable reference ...
svsm
github_2023
others
64
coconut-svsm
00xc
@@ -0,0 +1,296 @@ +// 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 for symmetry I would have this as a method on `TaskList`, just like we have `RunQueue::deallocate()`, so something like: ```rust TASKLIST.lock().terminate(task_node); ```
svsm
github_2023
others
64
coconut-svsm
Freax13
@@ -0,0 +1,316 @@ +// 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::ops::DerefMut; + +use super::Task; +use super::{tasks::TaskRuntime, TaskState, INITIAL_TASK_ID}; +use crate::cpu::percpu::{this_cpu...
```suggestion // Reinsert the node into the tree so the position is updated with the new runtime ```
svsm
github_2023
others
64
coconut-svsm
Freax13
@@ -0,0 +1,316 @@ +// 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::ops::DerefMut; + +use super::Task; +use super::{tasks::TaskRuntime, TaskState, INITIAL_TASK_ID}; +use crate::cpu::percpu::{this_cpu...
https://github.com/Amanieu/intrusive-rs/issues/47 seems to suggest the the default link types from the `intrusive-collections` crate are not meant to be used in multi-thread code. It specifically calls out that two threads could end up inserting the same node into two trees. AFAICT `RunQueue::schedule` is written in s...
svsm
github_2023
others
64
coconut-svsm
Freax13
@@ -0,0 +1,316 @@ +// 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::ops::DerefMut; + +use super::Task; +use super::{tasks::TaskRuntime, TaskState, INITIAL_TASK_ID}; +use crate::cpu::percpu::{this_cpu...
Using `Bound::Unbounded` here (and in a couple other places) is slightly more efficient because the the `RBTree` won't have to get the key while traversing the nodes.
svsm
github_2023
others
64
coconut-svsm
Freax13
@@ -0,0 +1,316 @@ +// 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::ops::DerefMut; + +use super::Task; +use super::{tasks::TaskRuntime, TaskState, INITIAL_TASK_ID}; +use crate::cpu::percpu::{this_cpu...
```suggestion let task_list = &self.list.as_ref()?; let mut cursor = task_list.front(); while let Some(task_node) = cursor.get() { if task_node.task.lock_read().id == id { return cursor.clone_pointer(); } cursor.move_next(); } ...
svsm
github_2023
others
64
coconut-svsm
Freax13
@@ -0,0 +1,316 @@ +// 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::ops::DerefMut; + +use super::Task; +use super::{tasks::TaskRuntime, TaskState, INITIAL_TASK_ID}; +use crate::cpu::percpu::{this_cpu...
How is it guaranteed the `next_task` is not aliased by another vCPU taking the task's lock?
svsm
github_2023
others
64
coconut-svsm
Freax13
@@ -191,19 +215,22 @@ pub struct PerCpu { pub vrange_4k: VirtualRange, /// Address allocator for per-cpu 2m temporary mappings pub vrange_2m: VirtualRange, + + /// Task list that has been assigned for scheduling on this CPU + runqueue: RWLock<RunQueue>, } impl Default for PerCpu { fn defau...
This `Default` implementation is unused. Have you considered just removing it?
svsm
github_2023
others
64
coconut-svsm
Freax13
@@ -156,4 +156,32 @@ impl<T: Debug> RWLock<T> { data: unsafe { &mut *self.data.get() }, } } + + pub fn lock_write_direct(&self) -> *mut T { + // Waiting for current writer to finish + loop { + let val = self.wait_for_writers(); + let (readers, _) = split...
This function should be unsafe.
svsm
github_2023
others
64
coconut-svsm
Freax13
@@ -156,4 +156,32 @@ impl<T: Debug> RWLock<T> { data: unsafe { &mut *self.data.get() }, } } + + pub fn lock_write_direct(&self) -> *mut T { + // Waiting for current writer to finish + loop { + let val = self.wait_for_writers(); + let (readers, _) = split...
```suggestion self.data.get() ```
svsm
github_2023
others
64
coconut-svsm
Freax13
@@ -156,4 +156,32 @@ impl<T: Debug> RWLock<T> { data: unsafe { &mut *self.data.get() }, } } + + pub fn lock_write_direct(&self) -> *mut T {
This function could be implemented in terms of `lock_write`: ```rust let guard = self.lock_write(); core::mem::forget(guard); // Leak the guard. self.data.get() ```
svsm
github_2023
others
64
coconut-svsm
Freax13
@@ -315,19 +296,32 @@ impl Task { } extern "C" fn task_exit() { - panic!("Current task has exited"); + unsafe { + current_task_terminated(); + } + schedule(); } #[allow(unused)] #[no_mangle] extern "C" fn apply_new_context(new_task: *mut Task) -> u64 { unsafe { let mut pt = (*...
```suggestion extern "C" fn on_switch(new_task: &mut Task) { ``` That way no unsafe is required inside the function.
svsm
github_2023
others
64
coconut-svsm
Freax13
@@ -0,0 +1,372 @@ +// 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::ptr::null_mut; + +use super::Task; +use super::{tasks::TaskRuntime, TaskState, INITIAL_TASK_ID}; +use crate::cpu::percpu::{this_cpu...
Why does the lock have to be held until the task switch?
svsm
github_2023
others
69
coconut-svsm
00xc
@@ -21,6 +23,23 @@ pub enum SvsmResultCode { PROTOCOL_BASE(u64), } +impl fmt::Display for SvsmResultCode { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Self::SUCCESS => write!(f, "SUCCESS"), + Self::INCOMPLETE => write!(f, "INCOMPLETE"), + ...
Can't we just use `Debug` for this?
svsm
github_2023
others
69
coconut-svsm
00xc
@@ -44,6 +63,17 @@ pub enum SvsmReqError { FatalError(SvsmError), } +impl fmt::Display for SvsmReqError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Self::RequestError(e) => write!(f, "RequestError({})", e), + // Display is not implemented for a...
Same here, `Debug` is implemented for the type, so why not use it when printing the error instead?
svsm
github_2023
others
69
coconut-svsm
stefano-garzarella
@@ -8,6 +8,9 @@ else TARGET_PATH="debug" endif +ifdef V
`make V=0` also enable the verbose mode, so what about this: ``` ifeq ($(V), 1) CARGO_ARGS += -v else ifeq ($(V), 2) CARGO_ARGS += -vv endif ```
svsm
github_2023
others
69
coconut-svsm
stefano-garzarella
@@ -87,7 +87,7 @@ pub const SIZE_LEVEL0: usize = 1usize << ((9 * 0) + 12); #[cfg(feature = "enable-gdb")] pub const STACK_PAGES: usize = 16;
I don't know the details, but should we increase this as well? Pre existing: maybe it's better to define a base and increment it when the gdb stub is enabled
svsm
github_2023
others
69
coconut-svsm
stefano-garzarella
@@ -0,0 +1,450 @@ +/* SPDX-License-Identifier: MIT */
`cargo clippy` suggests several improvements for this file: ``` warning: you should consider adding a `Default` implementation for `SnpGuestRequestMsgHdr` --> src/psp/guest_request_msg.rs:103:5 | 103 | / pub fn new() -> SnpGuestRequestMsgHdr { 104 | | SnpGuestRequestMsgHdr { 105 | | ...
svsm
github_2023
others
69
coconut-svsm
stefano-garzarella
@@ -15,7 +17,7 @@ pub struct SecretsPage { pub fms: u32, reserved_00c: u32, pub gosvw: [u8; 16], - pub vmpck: [[u8; 32]; VMPL_MAX], + pub vmpck: [[u8; VMPCK_SIZE]; VMPL_MAX],
Perhaps we could make this change in a separate commit.
svsm
github_2023
others
69
coconut-svsm
stefano-garzarella
@@ -0,0 +1,261 @@ +/* SPDX-License-Identifier: MIT */ +/* + * Copyright (C) 2023 IBM + * + * Authors: Claudio Carvalho <cclaudio@linux.ibm.com> + */ + +extern crate alloc; + +use crate::address::VirtAddr; +use crate::cpu::percpu::this_cpu_mut; +use crate::error::SvsmError; +use crate::protocols::errors::SvsmReqError; +...
To understand better, so when we exhaust all the sequence numbers, we will always be in error?
svsm
github_2023
others
69
coconut-svsm
stefano-garzarella
@@ -0,0 +1,134 @@ +/* SPDX-License-Identifier: MIT */ +/* + * Copyright (C) 2023 IBM + * + * Authors: + * Claudio Carvalho <cclaudio@linux.ibm.com> + */ + +extern crate alloc; + +use crate::getter_func; +use crate::protocols::errors::SvsmReqError; + +use alloc::vec::Vec; + +/// 64
Maybe a leftover? If not, we could explain why 64
svsm
github_2023
others
69
coconut-svsm
stefano-garzarella
@@ -0,0 +1,134 @@ +/* SPDX-License-Identifier: MIT */
Some tips from `cargo clippy`: ``` warning: unused import: `crate::types::PAGE_SIZE` --> src/psp/request.rs:17:5 | 17 | use crate::types::PAGE_SIZE; | ^^^^^^^^^^^^^^^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default warning: unused imports: `allocate_pages`, `free_page`, `get_ord...
svsm
github_2023
others
69
coconut-svsm
00xc
@@ -0,0 +1,450 @@ +/* SPDX-License-Identifier: MIT */ +/* + * Copyright (C) 2023 IBM + * + * Authors: Claudio Carvalho <cclaudio@linux.ibm.com> + */ + +extern crate alloc; + +use crate::address::{Address, VirtAddr}; +use crate::cpu::percpu::this_cpu_mut; +use crate::mm::alloc::{allocate_page, allocate_pages, get_order}...
I think setting the `len` field is missing in this method.
svsm
github_2023
others
69
coconut-svsm
stefano-garzarella
@@ -8,6 +8,11 @@ else TARGET_PATH="debug"
nit: if you need to resend, we can update the commit description
svsm
github_2023
others
69
coconut-svsm
00xc
@@ -85,11 +85,11 @@ pub const SIZE_LEVEL0: usize = 1usize << ((9 * 0) + 12); // Stack definitions // The GDB stub requires a larger stack. #[cfg(feature = "enable-gdb")] -pub const STACK_PAGES_GDB: usize = 12; +pub const STACK_PAGES_GDB: usize = 4; #[cfg(not(feature = "enable-gdb"))] pub const STACK_PAGES_GDB: usi...
Have you been able to pinpoint where in the code the stack usage caused the double fault?
svsm
github_2023
others
69
coconut-svsm
roy-hopkins
@@ -4,5 +4,5 @@ build-std-features = ["compiler-builtins-mem"] [build] target = "svsm-target.json" -rustflags = ["-C", "force-frame-pointers"] +rustflags = ["-C", "force-frame-pointers", "--cfg", "aes_force_soft", "--cfg", "polyval_force_soft"]
I assume this is using the software implementation because AES-NI is unavailable due to SSE not being supported/initialised in the svsm? Is this something we can/should address?
svsm
github_2023
others
69
coconut-svsm
roy-hopkins
@@ -0,0 +1,461 @@ +/* SPDX-License-Identifier: MIT OR Apache-2.0 */ +/* + * Copyright (C) 2023 IBM + * + * Authors: Claudio Carvalho <cclaudio@linux.ibm.com> + */ + +/// +/// This file follows the AMD SEV-SNP spec v1.54 +/// +extern crate alloc; + +use crate::address::{Address, VirtAddr}; +use crate::cpu::percpu::this_...
Should this allocation (and the sharing of the page with the host) be released when the `SnpGuestRequestMsg` is dropped?
svsm
github_2023
others
69
coconut-svsm
roy-hopkins
@@ -0,0 +1,461 @@ +/* SPDX-License-Identifier: MIT OR Apache-2.0 */ +/* + * Copyright (C) 2023 IBM + * + * Authors: Claudio Carvalho <cclaudio@linux.ibm.com> + */ + +/// +/// This file follows the AMD SEV-SNP spec v1.54 +/// +extern crate alloc; + +use crate::address::{Address, VirtAddr}; +use crate::cpu::percpu::this_...
As far as I can tell, clearing the C bit will allow the host to read the previous contents of the page, but the page will only contain ciphertext. Should the page be cleared at this point as a precaution though?
svsm
github_2023
others
69
coconut-svsm
deeglaze
@@ -0,0 +1,461 @@ +/* SPDX-License-Identifier: MIT OR Apache-2.0 */ +/* + * Copyright (C) 2023 IBM + * + * Authors: Claudio Carvalho <cclaudio@linux.ibm.com> + */ + +/// +/// This file follows the AMD SEV-SNP spec v1.54 +/// +extern crate alloc; + +use crate::address::{Address, VirtAddr}; +use crate::cpu::percpu::this_...
Can these cryptographic implementations be stubbed into an interface that can be instantiated from the outset? If we (Google) are to use this package, we'll be required to link with BoringSSL and use its aes implementation. I haven't done much Rust programming yet, so I'm not sure the right idiom to do this.
svsm
github_2023
others
69
coconut-svsm
daaltobe
@@ -0,0 +1,196 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (C) 2023 IBM +// +// Authors: Claudio Carvalho <cclaudio@linux.ibm.com> + +/// This files provides an API to request SNP_GUEST_REQUEST services +/// to the AMD Secure Processor (a.k.a. PSP). +/// +/// The PSP accepts only one SNP_GUEST_R...
Could do static assert on REPORT_RESPONSE_SIZE > REPORT_REQUEST_SIZE and only check REPORT_RESPONSE_SIZE
svsm
github_2023
others
69
coconut-svsm
daaltobe
@@ -0,0 +1,196 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (C) 2023 IBM +// +// Authors: Claudio Carvalho <cclaudio@linux.ibm.com> + +/// This files provides an API to request SNP_GUEST_REQUEST services +/// to the AMD Secure Processor (a.k.a. PSP). +/// +/// The PSP accepts only one SNP_GUEST_R...
I might hide the details of SnpReportRequest inside this code and have callers pass in input_data only, which also avoids checking VMPL.
svsm
github_2023
others
69
coconut-svsm
joergroedel
@@ -0,0 +1,305 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (C) 2023 IBM +// +// Authors: Claudio Carvalho <cclaudio@linux.ibm.com> + +/// This driver implements the protocol defined in the AMD SEV-SNP spec v1.54 (chapter 7) +/// to send SNP_GUEST_REQUEST (greq) messages to the AMD Secure Process...
If I checked correctly, none of the underlying types implement the drop trait. The memory allocated in these functions will be leaked if initialization fails. Can you please implement the drop trait for `SnpGuestRequestMsg` and `SnpGuestRequestExtData` so that the pages are freed and set to private again?
svsm
github_2023
others
69
coconut-svsm
deeglaze
@@ -480,6 +482,61 @@ impl GHCB { Ok(()) } + pub fn guest_request( + &mut self, + req_page: VirtAddr, + resp_page: VirtAddr, + ) -> Result<(), SvsmError> { + self.clear(); + + let info1: u64 = u64::from(virt_to_phys(req_page)); + let info2: u64 = u64::from(...
~Not every nonzero sw_exit_info_2 value is fatal, such as 2 << 32, from GHCB section 4.1.7, which indicates the guest should wait and retry.~ Retracted, I see you have this handled at the callsite.
svsm
github_2023
others
69
coconut-svsm
deeglaze
@@ -0,0 +1,539 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (C) 2023 IBM +// +// Authors: Claudio Carvalho <cclaudio@linux.ibm.com> + +//! `SNP_GUEST_REQUEST` message that carries the actual command in the payload + +extern crate alloc; + +use crate::address::{Address, VirtAddr}; +use crate::cpu:...
inbuf is used directly from shared memory instead of from a copy in encrypted memory. Do we know if this decrypt operation is strong against iago attacks, such as if inbuf is read more than once during decryption, and its contents are expected to be constant throughout?
svsm
github_2023
others
69
coconut-svsm
deeglaze
@@ -0,0 +1,348 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (C) 2023 IBM +// +// Authors: Claudio Carvalho <cclaudio@linux.ibm.com> + +//! `SNP_GUEST_REQUEST` driver + +extern crate alloc; + +use crate::address::VirtAddr; +use crate::cpu::percpu::this_cpu_mut; +use crate::error::SvsmError; +use c...
Do we expect `extended` to be false when the host sends back this value? You still need to complete the PSP request for the sequence numbers to stay in sync, so why keep this guarded?
svsm
github_2023
others
69
coconut-svsm
deeglaze
@@ -0,0 +1,539 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (C) 2023 IBM +// +// Authors: Claudio Carvalho <cclaudio@linux.ibm.com> + +//! `SNP_GUEST_REQUEST` message that carries the actual command in the payload + +extern crate alloc; + +use crate::address::{Address, VirtAddr}; +use crate::cpu:...
Similar comment to below about decrypt: is this encryption strong against iago attacks, or can you add the double-buffering mitigation I added to Linux's sev-guest so that all encryption is done in encrypted memory before getting written to shared memory?
svsm
github_2023
others
69
coconut-svsm
joergroedel
@@ -0,0 +1,566 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (C) 2023 IBM +// +// Authors: Claudio Carvalho <cclaudio@linux.ibm.com> + +//! `SNP_GUEST_REQUEST` message that carries the actual command in the payload + +extern crate alloc; + +use crate::address::{Address, VirtAddr}; +use crate::cpu:...
The pages can only be freed when they are set to encrypted, otherwise it is better to leak the memory. Possibly state the leak in the error message.
svsm
github_2023
others
69
coconut-svsm
joergroedel
@@ -0,0 +1,566 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (C) 2023 IBM +// +// Authors: Claudio Carvalho <cclaudio@linux.ibm.com> + +//! `SNP_GUEST_REQUEST` message that carries the actual command in the payload + +extern crate alloc; + +use crate::address::{Address, VirtAddr}; +use crate::cpu:...
The page can only be freed if it was set back to encrypted state. We can not leak a shared page back into the allocator.
svsm
github_2023
others
69
coconut-svsm
Freax13
@@ -0,0 +1,566 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (C) 2023 IBM +// +// Authors: Claudio Carvalho <cclaudio@linux.ibm.com> + +//! `SNP_GUEST_REQUEST` message that carries the actual command in the payload + +extern crate alloc; + +use crate::address::{Address, VirtAddr}; +use crate::cpu:...
In it's current state, this data structure doesn't seem sound to me: 1. There's nothing stopping the user from calling `init` multiple times and leaking memory. 2. `set_len` allows the user to freely set any value. We can no longer rely on `len` being accurate. `set_len` should either be made unsafe or removed. 3. `...
svsm
github_2023
others
69
coconut-svsm
Freax13
@@ -0,0 +1,566 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (C) 2023 IBM +// +// Authors: Claudio Carvalho <cclaudio@linux.ibm.com> + +//! `SNP_GUEST_REQUEST` message that carries the actual command in the payload + +extern crate alloc; + +use crate::address::{Address, VirtAddr}; +use crate::cpu:...
This function should take a `tag: &[u8; 32]` (or `&[u8]`).
svsm
github_2023
others
69
coconut-svsm
Freax13
@@ -0,0 +1,101 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (C) 2023 IBM +// +// Authors: Claudio Carvalho <cclaudio@linux.ibm.com> + +//! RustCrypto implementation + +use aes_gcm::{ + aead::{Aead, Payload}, + Aes256Gcm, Key, KeyInit, Nonce, +}; +use core::ptr::copy_nonoverlapping; + +use c...
```suggestion let buffer = result.map_err(|_| SvsmReqError::invalid_format())?; ```
svsm
github_2023
others
69
coconut-svsm
Freax13
@@ -0,0 +1,184 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (C) 2023 IBM +// +// Authors: Claudio Carvalho <cclaudio@linux.ibm.com> + +//! API to send `SNP_GUEST_REQUEST` commands to the PSP + +extern crate alloc; + +use crate::address::{Address, VirtAddr}; +use crate::greq::driver::{SnpGuestRequ...
```suggestion log::error!("SNP_GUEST_REQUEST driver failed to initialize, e={e:?}"); ```
svsm
github_2023
others
69
coconut-svsm
Freax13
@@ -0,0 +1,81 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (C) 2023 IBM +// +// Authors: Claudio Carvalho <cclaudio@linux.ibm.com> + +//! RustCrypto implementation + +use aes_gcm::{ + aead::{Aead, Payload}, + Aes256Gcm, Key, KeyInit, Nonce, +}; +use core::ptr::copy_nonoverlapping; + +use cr...
```suggestion let outbuf = outbuf .get_mut(..buffer.len()) .ok_or_else(SvsmReqError::invalid_parameter)?; outbuf.copy_from_slice(&buffer); ```
svsm
github_2023
others
69
coconut-svsm
Freax13
@@ -0,0 +1,523 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (C) 2023 IBM +// +// Authors: Claudio Carvalho <cclaudio@linux.ibm.com> + +//! Driver to send `SNP_GUEST_REQUEST` commands to the PSP. It can be any of the +//! request or response command types defined in the SEV-SNP spec, regardless if...
This code probably belongs somewhere in the mm module, this doesn't seem specific to snp guest requests. These functions should be unsafe.
svsm
github_2023
others
69
coconut-svsm
Freax13
@@ -0,0 +1,523 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (C) 2023 IBM +// +// Authors: Claudio Carvalho <cclaudio@linux.ibm.com> + +//! Driver to send `SNP_GUEST_REQUEST` commands to the PSP. It can be any of the +//! request or response command types defined in the SEV-SNP spec, regardless if...
We call `disable_vmpck0` for a bunch of error cases. Have you considered additionally calling `disable_vmpck0` in the SVSM's panic handler?
svsm
github_2023
others
69
coconut-svsm
Freax13
@@ -0,0 +1,523 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (C) 2023 IBM +// +// Authors: Claudio Carvalho <cclaudio@linux.ibm.com> + +//! Driver to send `SNP_GUEST_REQUEST` commands to the PSP. It can be any of the +//! request or response command types defined in the SEV-SNP spec, regardless if...
```suggestion .expect("SnpGuestRequestDriver failed to initialize") ```
svsm
github_2023
others
69
coconut-svsm
Freax13
@@ -0,0 +1,438 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (C) 2023 IBM +// +// Authors: Claudio Carvalho <cclaudio@linux.ibm.com> + +//! Message that carries an encrypted `SNP_GUEST_REQUEST` command in the payload + +extern crate alloc; + +use crate::{ + crypto::aead::{Aes256Gcm, Aes256GcmTr...
```suggestion self.data .get_mut(..n) .ok_or_else(SvsmReqError::invalid_parameter)? .fill(0); ``` Also applies to `copy_to_slice` and `is_nclear`.
svsm
github_2023
others
69
coconut-svsm
Freax13
@@ -0,0 +1,199 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (C) 2023 IBM +// +// Authors: Claudio Carvalho <cclaudio@linux.ibm.com> + +//! `SNP_GUEST_REQUEST` command to request an attestation report. + +extern crate alloc; + +use crate::protocols::errors::SvsmReqError; + +use core::{mem::size_of...
```suggestion let request = unsafe { &*buffer.as_ptr().cast::<SnpReportRequest>() }; ```
svsm
github_2023
others
69
coconut-svsm
Freax13
@@ -0,0 +1,199 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (C) 2023 IBM +// +// Authors: Claudio Carvalho <cclaudio@linux.ibm.com> + +//! `SNP_GUEST_REQUEST` command to request an attestation report. + +extern crate alloc; + +use crate::protocols::errors::SvsmReqError; + +use core::{mem::size_of...
```suggestion let response: &SnpReportResponse = unsafe { &*buffer.as_ptr().cast::<SnpReportResponse>() }; ```
svsm
github_2023
others
69
coconut-svsm
Freax13
@@ -0,0 +1,199 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (C) 2023 IBM +// +// Authors: Claudio Carvalho <cclaudio@linux.ibm.com> + +//! `SNP_GUEST_REQUEST` command to request an attestation report. + +extern crate alloc; + +use crate::protocols::errors::SvsmReqError; + +use core::{mem::size_of...
This needs to be `repr(C, packed)` if we want to create references from unaligned byte slices.
svsm
github_2023
others
69
coconut-svsm
Freax13
@@ -0,0 +1,572 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (C) 2023 IBM +// +// Authors: Claudio Carvalho <cclaudio@linux.ibm.com> + +//! Message that carries an encrypted `SNP_GUEST_REQUEST` command in the payload + +extern crate alloc; + +use alloc::{ + alloc::{alloc, Layout}, + boxed::B...
I don't think this is related to the actual content of the page. I also get error 22 if I replace `alloc` with `allocate_page`.
svsm
github_2023
others
69
coconut-svsm
roy-hopkins
@@ -0,0 +1,572 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (C) 2023 IBM +// +// Authors: Claudio Carvalho <cclaudio@linux.ibm.com> + +//! Message that carries an encrypted `SNP_GUEST_REQUEST` command in the payload + +extern crate alloc; + +use alloc::{ + alloc::{alloc, Layout}, + boxed::B...
I cannot see where the hypervisor is informed of the encrypted state change for this memory. On my test system this resulted in a lockup when the memory contents were written. I fixed it with the following temporary code: ```suggestion let vaddr = VirtAddr::from(self as *mut Self); this_cpu_mut() ...
svsm
github_2023
others
69
coconut-svsm
Freax13
@@ -0,0 +1,375 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (C) 2023 IBM +// +// Authors: Claudio Carvalho <cclaudio@linux.ibm.com> + +//! Driver to send `SNP_GUEST_REQUEST` commands to the PSP. It can be any of the +//! request or response command types defined in the SEV-SNP spec, regardless if...
This is technically unsound. Rust assumes that the memory pointed to in those `Box`es behave according to it's ownership rules, but given that they are shared, the host can mess with the memory in a way that Rust doesn't allow.
svsm
github_2023
others
69
coconut-svsm
Freax13
@@ -0,0 +1,572 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (C) 2023 IBM +// +// Authors: Claudio Carvalho <cclaudio@linux.ibm.com> + +//! Message that carries an encrypted `SNP_GUEST_REQUEST` command in the payload + +extern crate alloc; + +use alloc::{ + alloc::{alloc, Layout}, + boxed::B...
If we derive `Clone` & `Copy` for `SnpGuestRequestMsg`, we can get rid of the unsafe by simply doing `*self = *src`.
svsm
github_2023
others
69
coconut-svsm
Freax13
@@ -0,0 +1,572 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (C) 2023 IBM +// +// Authors: Claudio Carvalho <cclaudio@linux.ibm.com> + +//! Message that carries an encrypted `SNP_GUEST_REQUEST` command in the payload + +extern crate alloc; + +use alloc::{ + alloc::{alloc, Layout}, + boxed::B...
This doesn't do anything, does it?
svsm
github_2023
others
69
coconut-svsm
Freax13
@@ -0,0 +1,572 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (C) 2023 IBM +// +// Authors: Claudio Carvalho <cclaudio@linux.ibm.com> + +//! Message that carries an encrypted `SNP_GUEST_REQUEST` command in the payload + +extern crate alloc; + +use alloc::{ + alloc::{alloc, Layout}, + boxed::B...
Do we really need to avoid copying from the stack here? I replaced this function's body with ```rust Ok(Box::new(Self { hdr: Default::default(), pld: [0; MSG_PAYLOAD_SIZE], })) ``` and didn't hit any errors.
svsm
github_2023
others
112
coconut-svsm
00xc
@@ -1605,3 +1605,197 @@ 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. + ...
Instead of asserting with `is_ok()` or `is_err()` and then unwrapping, the whole thing can be collapsed to a single `assert_eq!()` by destructuring the `Result`. So I would suggest something like the following: ```diff diff --git a/src/elf/mod.rs b/src/elf/mod.rs index 80bca2c..3bd3ba3 100644 --- a/src/elf/mod.rs...
svsm
github_2023
others
112
coconut-svsm
00xc
@@ -155,3 +155,46 @@ impl<T: Debug> RWLock<T> { } } } + +mod tests { + + #[test] + fn test_lock_rw() { + use crate::locking::*; + let rwlock = RWLock::new(42); + + // Acquire a read lock and check the initial value + let read_guard = rwlock.lock_read(); + assert_e...
Just a suggestion, but maybe it would make sense to split this test up. The part about two concurrent readers seems separate.
svsm
github_2023
others
131
coconut-svsm
Freax13
@@ -0,0 +1,205 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) 2022-2023 SUSE LLC +// +// Author: Carlos López <carlos.lopez@suse.com> + +use crate::address::Address; +use crate::types::PageSize; + +/// An abstraction over a memory region, expressed in terms of physical +/// ([`PhysAddr`](crate:...
The addresses returned by this function are not necessarily aligned to the page size. We should probably either fix this or document it.
svsm
github_2023
others
131
coconut-svsm
Freax13
@@ -0,0 +1,205 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) 2022-2023 SUSE LLC +// +// Author: Carlos López <carlos.lopez@suse.com> + +use crate::address::Address; +use crate::types::PageSize; + +/// An abstraction over a memory region, expressed in terms of physical +/// ([`PhysAddr`](crate:...
Have you considered creating two type aliases for virtual and physical addresses? This could be a bit easier to read. ```rust pub type PhysMemoryRegion = MemoryRegion<PhysAddr>; pub type VirtMemoryRegion = MemoryRegion<VirtAddr>; ```
svsm
github_2023
others
131
coconut-svsm
Freax13
@@ -154,14 +155,17 @@ impl<'a> FwCfg<'a> { } fn read_memory_region(&self) -> MemoryRegion { - let start: u64 = self.read_le(); - let size: u64 = self.read_le(); - let end = start.saturating_add(size); + let start = PhysAddr::from(self.read_le::<u64>()); + let size = self.r...
Did some of the changes in this file end up in the wrong commit? I don't see to connection to changing the return type of `max_phys_addr`.
svsm
github_2023
others
131
coconut-svsm
Freax13
@@ -55,7 +55,7 @@ pub trait Address: self.is_aligned(PAGE_SIZE) } - fn checked_offset(&self, off: InnerAddr) -> Option<Self> { + fn checked_add(&self, off: InnerAddr) -> Option<Self> {
FWIW this also matches the function names of pointers in the standard library: [`pointer::add`](https://doc.rust-lang.org/std/primitive.pointer.html#method.add) takes a `usize` (like the function here), whereas [`pointer::offset`](https://doc.rust-lang.org/std/primitive.pointer.html#method.offset) takes an `isize`.
svsm
github_2023
others
131
coconut-svsm
Freax13
@@ -40,37 +39,31 @@ pub fn init_memory_map(fwcfg: &FwCfg, launch_info: &KernelLaunchInfo) -> Result< regions.remove(i); // 2. Insert a region up until the start of SVSM memory (if non-empty). - let region_before_start = region.start; - let region_before_end = launch_info.kernel_region_...
Should we maybe just implement `Debug` or `Display` for `MemoryRange`?
svsm
github_2023
others
131
coconut-svsm
Freax13
@@ -157,8 +157,8 @@ pub extern "C" fn stage2_main(launch_info: &Stage1LaunchInfo) { log::info!("COCONUT Secure Virtual Machine Service Module (SVSM) Stage 2 Loader"); - let kernel_region_phys_start = PhysAddr::from(r.start); - let kernel_region_phys_end = PhysAddr::from(r.end); + let kernel_region_phy...
Maybe outside of the scope of this pr, but it seems to me that maybe `init_valid_bitmap_alloc` should take a `MemoryRange`.
svsm
github_2023
others
138
coconut-svsm
00xc
@@ -9,79 +9,165 @@ use core::fmt::Debug; use core::ops::{Deref, DerefMut}; use core::sync::atomic::{AtomicU64, Ordering}; +/// A guard that provides read access to the data protected by [`RWLock`] #[derive(Debug)] #[must_use = "if unused the RWLock will immediately unlock"] pub struct ReadLockGuard<'a, T: Debug>...
These imports are not needed. ```suggestion /// use svsm::locking::RWLock; ```
svsm
github_2023
others
138
coconut-svsm
00xc
@@ -9,43 +9,107 @@ use core::fmt::Debug; use core::ops::{Deref, DerefMut}; use core::sync::atomic::{AtomicU64, Ordering}; +/// A lock guard used in conjunction with [`SpinLock`]. This lock guard
I'd make it explicit that one obtains this type from a `SpinLock`: ```suggestion /// A lock guard obtained from a [`SpinLock`]. This lock guard ```
svsm
github_2023
others
138
coconut-svsm
00xc
@@ -9,43 +9,107 @@ use core::fmt::Debug; use core::ops::{Deref, DerefMut}; use core::sync::atomic::{AtomicU64, Ordering}; +/// A lock guard used in conjunction with [`SpinLock`]. This lock guard +/// provides exclusive access to the data protected by a [`SpinLock`], +/// ensuring that the lock is released when it g...
```suggestion /// use svsm::locking::SpinLock; ```
svsm
github_2023
others
138
coconut-svsm
00xc
@@ -9,43 +9,107 @@ use core::fmt::Debug; use core::ops::{Deref, DerefMut}; use core::sync::atomic::{AtomicU64, Ordering}; +/// A lock guard used in conjunction with [`SpinLock`]. This lock guard +/// provides exclusive access to the data protected by a [`SpinLock`], +/// ensuring that the lock is released when it g...
```suggestion /// protected data. That is, it allows the data to be accessed/modified /// while enforcing the locking mechanism. ```
svsm
github_2023
others
141
coconut-svsm
joergroedel
@@ -48,3 +48,51 @@ before allowing them to be committed. It can be installed by running ``` from the projects root directory. + +Documentation Style +------------------- + +In this project, code documentation is generated using Rustdoc, which +automatically generates interactive web documentation. Here are some +gu...
Can you please add examples for best practices here? It makes it much easier for contributors.
svsm
github_2023
others
141
coconut-svsm
00xc
@@ -58,7 +58,8 @@ Contributing Contributing to the project is as easy as sending a pull-request via GitHub. For detailed instructions on patch formatting and contribution -guidelines please have a look at [CONTRIBUTING.md](CONTRIBUTING.md). +guidelines please have a look at [CONTRIBUTING.md](CONTRIBUTING.md) and +f...
```suggestion guidelines please have a look at [CONTRIBUTING.md](CONTRIBUTING.md). For documentation guidelines consult [DOC-GUIDELINES.md](Documentation/DOC-GUIDELINES.md). ```
svsm
github_2023
others
141
coconut-svsm
00xc
@@ -0,0 +1,109 @@ +Documentation Style +=================== + +In this project, code documentation is generated using Rustdoc, which +automatically generates interactive web documentation. Here are some +guidelines for documenting code effectively: + +- Follow [Rust's official indications.](https://doc.rust-lang.org/ru...
This example does not really match the point it follows. I'd suggest moving this point below the next one ("use triple slashes..."), and have this example exemplify both points.
svsm
github_2023
others
141
coconut-svsm
00xc
@@ -0,0 +1,109 @@ +Documentation Style +=================== + +In this project, code documentation is generated using Rustdoc, which +automatically generates interactive web documentation. Here are some +guidelines for documenting code effectively: + +- Follow [Rust's official indications.](https://doc.rust-lang.org/ru...
This example would benefit from a `pub fn...` at the end
svsm
github_2023
others
141
coconut-svsm
00xc
@@ -0,0 +1,109 @@ +Documentation Style +=================== + +In this project, code documentation is generated using Rustdoc, which +automatically generates interactive web documentation. Here are some +guidelines for documenting code effectively: + +- Follow [Rust's official indications.](https://doc.rust-lang.org/ru...
Same thing, I would make it explicit that this goes before a function declaration.
svsm
github_2023
others
141
coconut-svsm
00xc
@@ -0,0 +1,109 @@ +Documentation Style +=================== + +In this project, code documentation is generated using Rustdoc, which +automatically generates interactive web documentation. Here are some +guidelines for documenting code effectively: + +- Follow [Rust's official indications.](https://doc.rust-lang.org/ru...
I would mention `cargo doc` here.
svsm
github_2023
others
141
coconut-svsm
00xc
@@ -0,0 +1,129 @@ +Documentation Style +=================== + +In this project, code documentation is generated using Rustdoc, which +automatically generates interactive web documentation. Here are some +guidelines for documenting code effectively: + +- Follow [Rust's official indications.](https://doc.rust-lang.org/ru...
```suggestion /// This function does A, takes parameter of type [`M`]. /// It returns [`B`], keep in mind C fn main(a: M) -> B { // Some code here } ``` Note there is also an extra newline that we do not need.
svsm
github_2023
others
141
coconut-svsm
00xc
@@ -0,0 +1,129 @@ +Documentation Style +=================== + +In this project, code documentation is generated using Rustdoc, which +automatically generates interactive web documentation. Here are some +guidelines for documenting code effectively: + +- Follow [Rust's official indications.](https://doc.rust-lang.org/ru...
```suggestion /// 1. `src` and `dst` must point to valid memory. ```
svsm
github_2023
others
141
coconut-svsm
00xc
@@ -0,0 +1,129 @@ +Documentation Style +=================== + +In this project, code documentation is generated using Rustdoc, which +automatically generates interactive web documentation. Here are some +guidelines for documenting code effectively: + +- Follow [Rust's official indications.](https://doc.rust-lang.org/ru...
```suggestion /// 2. The length `len` must accurately represent the number of bytes in /// `data`. ```
svsm
github_2023
others
141
coconut-svsm
00xc
@@ -0,0 +1,129 @@ +Documentation Style +=================== + +In this project, code documentation is generated using Rustdoc, which +automatically generates interactive web documentation. Here are some +guidelines for documenting code effectively: + +- Follow [Rust's official indications.](https://doc.rust-lang.org/ru...
```suggestion /// 3. `src` must be correctly initialized. ```
svsm
github_2023
others
141
coconut-svsm
00xc
@@ -0,0 +1,129 @@ +Documentation Style +=================== + +In this project, code documentation is generated using Rustdoc, which +automatically generates interactive web documentation. Here are some +guidelines for documenting code effectively: + +- Follow [Rust's official indications.](https://doc.rust-lang.org/ru...
The function should have a `# Panics` section in this case. We can even merge this example with the one below.
svsm
github_2023
others
141
coconut-svsm
00xc
@@ -0,0 +1,129 @@ +Documentation Style +=================== + +In this project, code documentation is generated using Rustdoc, which +automatically generates interactive web documentation. Here are some +guidelines for documenting code effectively: + +- Follow [Rust's official indications.](https://doc.rust-lang.org/ru...
The function is already unsafe, so there is no need for this unsafe block as far as I know.
svsm
github_2023
others
141
coconut-svsm
00xc
@@ -0,0 +1,129 @@ +Documentation Style +=================== + +In this project, code documentation is generated using Rustdoc, which +automatically generates interactive web documentation. Here are some +guidelines for documenting code effectively: + +- Follow [Rust's official indications.](https://doc.rust-lang.org/ru...
I would simply say: ```suggestion /// The function will panic if the provided length exceeds the buffer's capacity. ```
svsm
github_2023
others
145
coconut-svsm
Freax13
@@ -0,0 +1,199 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) 2023 SUSE LLC +// +// Author: Roy Hopkins <rhopkins@suse.de> + +extern crate alloc; + +use core::slice::from_raw_parts_mut; + +use alloc::sync::Arc; + +use super::{Mapping, RawAllocMapping, VMPageFaultResolution, VMPhysMem, VirtualMa...
AFAICT this function and none of the function it calling end up calling `get_file_page`, so there reference count for the page is never increased. Am I missing something here?
svsm
github_2023
others
145
coconut-svsm
Freax13
@@ -86,4 +106,22 @@ impl RawAllocMapping { pub fn unmap(&self, _offset: usize) { // Nothing to do for now } + + /// Check if a page has been allocated + /// + /// # Arguments + /// + /// * 'offset' - Byte offset into the mapping + /// + /// # Returns + /// + /// 'true' if t...
```suggestion self.pages.get(pfn).and_then(|r| r.as_ref()).is_some() ```
svsm
github_2023
others
148
coconut-svsm
vsntk18
@@ -0,0 +1,154 @@ +// 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::alloc::{GlobalAlloc, Layout, LayoutError}; +use core::num::NonZeroUsize; +use libfuzzer_sys::fuzz_target; +use ...
Did you forget to free the memory chunks that might still be left in the _ptrs_ vector after exiting for loop?
svsm
github_2023
others
148
coconut-svsm
vsntk18
@@ -0,0 +1,164 @@ +// 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 libfuzzer_sys::fuzz_target; +use std::collections::BTreeSet; +use svsm::address::VirtAddr; +use svsm::mm::alloc::{ + ...
_get_file_page_() and _put_file_page()_ can also be called for a wider coverage?
svsm
github_2023
others
153
coconut-svsm
00xc
@@ -46,3 +46,46 @@ pub fn zero_mem_region(start: VirtAddr, end: VirtAddr) { // Zero region unsafe { start.as_mut_ptr::<u8>().write_bytes(0, size) } } + +#[cfg(test)] +mod tests { + + use crate::utils::util::*; + + #[test] + fn test_mem_utils() { + // Align up + assert_eq!(align_up(7, 4...
```suggestion let start = VirtAddr::from(data.as_mut_ptr()); let end = start + core::mem::size_of_val(&data); ```
svsm
github_2023
others
136
coconut-svsm
joergroedel
@@ -183,12 +170,12 @@ pub struct TaskContext { pub struct Task { pub rsp: u64, - /// Information about the task stack - pub stack: TaskStack, - /// Page table that is loaded when the task is scheduled pub page_table: SpinLock<PageTableRef>, + /// Task virtual memory range + vm_range: VMR...
This needs a more specific name, as it covers the kernel VMR. We will get another VMR for user-space in the same structure. Maybe `vm_kernel_range`?
svsm
github_2023
others
136
coconut-svsm
joergroedel
@@ -171,6 +171,29 @@ impl GuestVmsaRef { } } +/// Insert a mapping into the current PerCpu range and manage its lifecycle +#[derive(Debug)] +pub struct PerCpuMapping(VirtAddr); + +impl PerCpuMapping { + pub fn new(mapping: Arc<Mapping>) -> Result<Self, SvsmError> { + this_cpu_mut().vm_range.insert(map...
Maybe we can look into making this more generic to work with any VMR instance. This requires taking a reference to the VMR within the struct and lifetime annotations. But this is just a note, no requirement for this PR.
svsm
github_2023
others
120
coconut-svsm
roy-hopkins
@@ -9,7 +9,17 @@ TARGET_PATH="debug" endif STAGE2_ELF = "target/x86_64-unknown-none/${TARGET_PATH}/stage2" +ifdef TEST +KERNEL_ELF = "target/x86_64-unknown-none/${TARGET_PATH}/deps/svsm-0651abaef6a489bb"
I'm not sure the metadata hash can be hardcoded here. I think it can change based on compiler version and other parameters.
svsm
github_2023
others
120
coconut-svsm
roy-hopkins
@@ -2,22 +2,28 @@ FEATURES ?= "default" CARGO_ARGS = --features ${FEATURES} ifdef RELEASE -TARGET_PATH="release" +TARGET_PATH=release CARGO_ARGS += --release else -TARGET_PATH="debug" +TARGET_PATH=debug endif STAGE2_ELF = "target/x86_64-unknown-none/${TARGET_PATH}/stage2" ifdef TEST -KERNEL_ELF = "target/x86...
That's a great solution!