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 | 461 | coconut-svsm | Freax13 | @@ -561,6 +581,73 @@ impl PageTable {
Self::walk_addr_lvl3(&mut self.root, vaddr)
}
+ /// Calculate the virtual address of a PTE in the self-map, which maps a
+ /// specified virtual address.
+ ///
+ /// # Parameters
+ /// - `vaddr': The virtual address whose PTE should be located.
+ /... | ```suggestion
SVSM_PTE_BASE + ((usize::from(vaddr) & 0x0000_FFFF_FFFF_F000) >> 9)
```
The same change can be applied to the return statements in `virt_to_phys` below. |
svsm | github_2023 | others | 461 | coconut-svsm | Freax13 | @@ -561,6 +581,73 @@ impl PageTable {
Self::walk_addr_lvl3(&mut self.root, vaddr)
}
+ /// Calculate the virtual address of a PTE in the self-map, which maps a
+ /// specified virtual address.
+ ///
+ /// # Parameters
+ /// - `vaddr': The virtual address whose PTE should be located.
+ /... | This function needs to synchronize with the other functions modifying the page tables to prevent stale/use-after-free accesses. |
svsm | github_2023 | others | 461 | coconut-svsm | Freax13 | @@ -82,11 +88,22 @@ pub trait SvsmPlatform {
op: PageStateChangeOp,
) -> Result<(), SvsmError>;
- /// Marks a range of pages as valid for use as private pages.
- fn validate_page_range(&self, region: MemoryRegion<VirtAddr>) -> Result<(), SvsmError>;
+ /// Marks a physical range of pages as vali... | > Not usable in stage2.
Can we enforce this at compile time? |
svsm | github_2023 | others | 461 | coconut-svsm | Freax13 | @@ -140,14 +143,11 @@ fn map_and_validate(
let mut pgtbl = this_cpu().get_pgtable();
pgtbl.map_region(vregion, paddr, flags)?;
+ let pregion = MemoryRegion::new(paddr, vregion.len());
if config.page_state_change_required() {
- platform.page_state_change(
- MemoryRegion::new(paddr, ... | This change isn't needed anymore. |
svsm | github_2023 | others | 461 | coconut-svsm | Freax13 | @@ -361,6 +362,11 @@ impl PTEntry {
let addr = PhysAddr::from(self.0.bits() & 0x000f_ffff_ffff_f000);
strip_confidentiality_bits(addr)
}
+
+ /// Read a page table entry from the specified virtual address.
+ pub fn read_pte(vaddr: VirtAddr) -> Self {
+ unsafe { *vaddr.as_ptr::<Self>()... | ```suggestion
pub unsafe fn read_pte(vaddr: VirtAddr) -> Self {
*vaddr.as_ptr::<Self>()
}
```
That was the more important part of my [suggestion](https://github.com/coconut-svsm/svsm/pull/461#discussion_r1771258416) regarding this function :D |
svsm | github_2023 | others | 451 | coconut-svsm | msft-jlange | @@ -63,10 +63,9 @@ fn init_percpu(platform: &mut dyn SvsmPlatform) -> Result<(), SvsmError> {
Ok(())
}
-fn shutdown_percpu() {
- this_cpu()
- .shutdown()
- .expect("Failed to shut down percpu data (including GHCB)");
+unsafe fn shutdown_percpu() { | Why is this function `unsafe`? At a minimum, there should be a Safety comment here. But there is also nothing about the function declaration that suggests that it can only be called from unsafe code. My understanding of the convention we have been using is that a function should only be declared `unsafe` if it is no... |
svsm | github_2023 | others | 451 | coconut-svsm | msft-jlange | @@ -37,3 +37,54 @@ pub unsafe fn write_bytes(dst: usize, size: usize, value: u8) {
);
}
}
+
+/// Returns whether there are `size` null-bytes at `src`.
+///
+/// # Safety
+///
+/// This function has all the safety requirements of `core::ptr::read` except
+/// that data races are explicitly permitted.
+#[i... | This appears to be used only by test code. Should it therefore be within the test module so it is not accidentally referenced by non-test code? |
svsm | github_2023 | others | 451 | coconut-svsm | msft-jlange | @@ -4,25 +4,38 @@
//
// Author: Jon Lange (jlange@microsoft.com)
+use core::mem::MaybeUninit;
+use core::ptr::NonNull;
+
use crate::address::VirtAddr;
use crate::cpu::flush_tlb_global_sync;
+use crate::cpu::mem::{copy_bytes, is_clear, write_bytes};
use crate::cpu::percpu::this_cpu;
use crate::error::SvsmError;
... | Typo: `unsychronized` => `unsynchronized`. |
svsm | github_2023 | others | 451 | coconut-svsm | msft-jlange | @@ -160,7 +162,28 @@ impl GhcbPage {
impl Drop for GhcbPage {
fn drop(&mut self) {
- self.0.shutdown().expect("Could not shut down GHCB");
+ let vaddr = self.0.vaddr();
+ let paddr = virt_to_phys(vaddr);
+
+ // Re-encrypt page
+ this_cpu()
+ .get_pgtable()
+ ... | This is not guaranteed to succeed, because the VMM is not required to accept NULL as a valid GHCB page. |
svsm | github_2023 | others | 451 | coconut-svsm | msft-jlange | @@ -160,7 +162,28 @@ impl GhcbPage {
impl Drop for GhcbPage {
fn drop(&mut self) { | Is there any scenario for which dropping a GHCB is not associated with a fatal termination of the SVSM? The process of restoring a GHCB page to the private state is fragile, and I believe it would be best to avoid any attempt to do so unless we were aware of a valid use case for this. If we cannot come up with one, t... |
svsm | github_2023 | others | 451 | coconut-svsm | msft-jlange | @@ -317,33 +334,10 @@ impl GHCB {
Ok(register_ghcb_gpa_msr(paddr)?)
}
- pub fn shutdown(&self) -> Result<(), SvsmError> {
- let vaddr = VirtAddr::from(ptr::from_ref(self));
- let paddr = virt_to_phys(vaddr);
-
- // Re-encrypt page
- this_cpu().get_pgtable().set_encrypted_4... | The GHCB page is not manipulated across processors, so there is no reason for expensive memory barriers when modifying its contents. The only race conditions we might expect are between the SVSM environment and the host running on the same processor; this possibility for interruption means that atomic operations are n... |
svsm | github_2023 | others | 451 | coconut-svsm | msft-jlange | @@ -78,3 +91,139 @@ pub fn make_page_private(vaddr: VirtAddr) -> Result<(), SvsmError> {
Ok(())
}
+
+/// SharedBox is a safe wrapper around memory pages shared with the host.
+pub struct SharedBox<T> { | This structure appears to have nothing to do with GHCB - the `GhcbPage` structure doesn't even make use of it - and thus it should be in its own source file and not stuck in the GHCB sources. In addition, the notion of `SharedBox` will be used on other confidential platforms (like TDX) and definitely should not be in ... |
svsm | github_2023 | others | 451 | coconut-svsm | msft-jlange | @@ -47,51 +46,28 @@ pub struct HVExtIntInfo {
pub isr: [AtomicU32; 8],
}
-/// An allocation containing the `#HV` doorbell page.
-#[derive(Debug)]
-pub struct HVDoorbellPage(PageBox<HVDoorbell>);
-
-impl HVDoorbellPage {
- /// Allocates a new HV doorbell page and registers it on the hypervisor
- /// using ... | Why does this function not use `SharedBox`? It seems that `SharedBox` is designed to do exactly the sort of assignment and visibility management expected here, and unlike the GHCB, there is no chicken-and-egg problem because `SharedBox` only requires the existence of a GHCB, not of a doorbell page. |
svsm | github_2023 | others | 465 | coconut-svsm | stefano-garzarella | @@ -436,6 +436,65 @@ of these limitations may be addressed in future updates.
* Debugging is currently limited to the SVSM kernel itself. OVMF and the guest
OS cannot be debugged using the SVSM GDB stub.
+Coconut-SVSM CI
+-------------
+ | A description of what the next steps are for would be appreciated. At first glance it is not clear what they are for. |
svsm | github_2023 | others | 465 | coconut-svsm | stefano-garzarella | @@ -436,6 +436,65 @@ of these limitations may be addressed in future updates.
* Debugging is currently limited to the SVSM kernel itself. OVMF and the guest
OS cannot be debugged using the SVSM GDB stub.
+Coconut-SVSM CI
+-------------
+
+## SVSM - Using the Script Utility
+
+Download the sev_utils script:
+```
+... | Wait, does this install stuff in the host?
What kind of system does it need to be?
I would put a big warning, I don't know if people are happy to install stuff in the host, so I would explain well what you install. |
svsm | github_2023 | others | 465 | coconut-svsm | stefano-garzarella | @@ -8,10 +8,18 @@ set -e
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
+
+ | Unrelated changes |
svsm | github_2023 | others | 465 | coconut-svsm | stefano-garzarella | @@ -82,6 +105,7 @@ if [ ! -z $IMAGE ]; then
-device scsi-hd,drive=disk0,bootindex=0"
fi
+ | ditto |
svsm | github_2023 | others | 465 | coconut-svsm | stefano-garzarella | @@ -8,10 +8,18 @@ set -e
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
+
+
: "${QEMU:=qemu-system-x86_64}"
: "${IGVM:=$SCRIPT_DIR/../bin/coconut-qemu.igvm}"
+: "${KERNEL_BIN:="${guest_kernel}"}"
+: "${INITRD_BIN:="${GENERATED_INITRD_BIN}"}"
+
+GUEST_ROOT_LABEL="${GUEST_ROOT_LABE... | Why commenting this line? |
svsm | github_2023 | others | 465 | coconut-svsm | stefano-garzarella | @@ -8,10 +8,18 @@ set -e
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
+
+
: "${QEMU:=qemu-system-x86_64}"
: "${IGVM:=$SCRIPT_DIR/../bin/coconut-qemu.igvm}"
+: "${KERNEL_BIN:="${guest_kernel}"}"
+: "${INITRD_BIN:="${GENERATED_INITRD_BIN}"}" | I don't understand these definitions, usually this way is used to provide a default, but here you're putting the default to other environment variables not defined anywhere, what's the point? |
svsm | github_2023 | others | 465 | coconut-svsm | stefano-garzarella | @@ -115,6 +142,9 @@ $SUDO_CMD \
$IMAGE_DISK \
-nographic \
-monitor none \
+ -kernel ${KERNEL_BIN} \
+ -initrd ${INITRD_BIN} \
+ -append "${GUEST_KERNEL_APPEND}" | By adding these parameters do we preserve the previous behavior of booting from disk? |
svsm | github_2023 | others | 465 | coconut-svsm | stefano-garzarella | @@ -10,6 +10,11 @@ SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
: "${QEMU:=qemu-system-x86_64}"
: "${IGVM:=$SCRIPT_DIR/../bin/coconut-qemu.igvm}"
+: "${KERNEL_BIN:="${guest_kernel}"}" ## Incase your work environment is ubuntu, guest_kernel is your ubuntu kernel image "vmlinuz-6.8.... | Again, I still don't understand the meaning of these definitions. Why do the default of these two new variables depend on other variables? |
svsm | github_2023 | others | 462 | coconut-svsm | Freax13 | @@ -306,25 +303,27 @@ pub mod svsm_gdbstub {
});
}
- struct GdbStubConnection;
+ struct GdbStubConnection<'a> {
+ serial_port: SerialPort<'a>,
+ }
- impl GdbStubConnection {
- const fn new() -> Self {
- Self {}
+ impl GdbStubConnection<'_> {
+ fn new(plat... | ```suggestion
impl<'a> GdbStubConnection<'a> {
fn new(platform: &'a dyn SvsmPlatform) -> Self {
```
Or just change the lifetime of the `serial_port` field to `'static`. |
svsm | github_2023 | others | 464 | coconut-svsm | p4zuu | @@ -523,6 +583,32 @@ fn ioio_perm<I: InsnMachineCtx>(mctx: &I, port: u16, size: Bytes, io_read: bool)
}
}
+#[inline]
+fn read_bytereg<I: InsnMachineCtx>(mctx: &I, reg: Register, lhbr: bool) -> u8 {
+ let data = mctx.read_reg(reg); | I guess you can cast to `u8` at the beginning to avoid cast duplicate:
```suggestion
let data = mctx.read_reg(reg) as u8;
``` |
svsm | github_2023 | others | 464 | coconut-svsm | p4zuu | @@ -275,6 +279,59 @@ pub mod test_utils {
Ok(())
}
+
+ fn translate_linear_addr(
+ &self,
+ la: usize,
+ _write: bool,
+ _fetch: bool,
+ ) -> Result<(usize, bool), InsnError> {
+ Ok((la, false))
+ }
+
+ fn handle_... | Is there a reason why not returning `Ok(data)` here? |
svsm | github_2023 | others | 464 | coconut-svsm | p4zuu | @@ -275,6 +279,59 @@ pub mod test_utils {
Ok(())
}
+
+ fn translate_linear_addr(
+ &self,
+ la: usize,
+ _write: bool,
+ _fetch: bool,
+ ) -> Result<(usize, bool), InsnError> {
+ Ok((la, false))
+ }
+
+ fn handle_... | Same about `Ok(data)`? |
svsm | github_2023 | others | 456 | coconut-svsm | Freax13 | @@ -0,0 +1,108 @@
+// SPDX-License-Identifier: MIT OR Apache-2.0
+//
+// Copyright (c) 2024 Intel Corporation.
+//
+// Author: Chuanxiao Dong <chuanxiao.dong@intel.com>
+
+extern crate alloc;
+
+use crate::cpu::percpu::current_task;
+use crate::error::SvsmError;
+use alloc::sync::Arc;
+
+#[derive(Clone, Copy, Debug)]
+... | I'm not a big fan of the name `ObjPointer`. The word "pointer" reminds me too much of raw pointers and this is not a raw pointer. How about `ObjReference` (or just `Arc<dyn Obj>)`? |
svsm | github_2023 | others | 456 | coconut-svsm | Freax13 | @@ -0,0 +1,113 @@
+// SPDX-License-Identifier: MIT OR Apache-2.0
+//
+// Copyright (c) 2024 Intel Corporation.
+//
+// Author: Chuanxiao Dong <chuanxiao.dong@intel.com>
+
+extern crate alloc;
+
+use crate::cpu::percpu::current_task;
+use crate::error::SvsmError;
+use alloc::sync::Arc;
+
+#[derive(Clone, Copy, Debug)]
+... | Let's call this `InvalidHandle` (since we already use `ObjHandle`, not `ObjId`). |
svsm | github_2023 | others | 456 | coconut-svsm | joergroedel | @@ -139,6 +141,9 @@ pub struct Task {
/// Link to scheduler run queue
runlist_link: LinkedListAtomicLink,
+
+ /// Objects shared among threads within the same process
+ objs: Arc<RWLock<BTreeMap<ObjHandle, Arc<dyn Obj>>>>, | Why is the outer `Arc` needed? Could as well be a `Box`, no? |
svsm | github_2023 | others | 453 | coconut-svsm | Freax13 | @@ -0,0 +1,506 @@
+# Background
+
+The syscalls design philosophy is to provide a unified interface for the user to
+access system resources, which are represented by object handles. This makes
+objects a fundamental concept in the COCONUT-SVSM kernel
+
+This document describes the object and object handle from both th... | Why can't the `Obj` just implement `Drop` instead of implementing this method? |
svsm | github_2023 | others | 453 | coconut-svsm | Freax13 | @@ -0,0 +1,506 @@
+# Background
+
+The syscalls design philosophy is to provide a unified interface for the user to
+access system resources, which are represented by object handles. This makes
+objects a fundamental concept in the COCONUT-SVSM kernel
+
+This document describes the object and object handle from both th... | What would this method do? Why can't we do this at the time the object is constructed? |
svsm | github_2023 | others | 453 | coconut-svsm | Freax13 | @@ -0,0 +1,506 @@
+# Background
+
+The syscalls design philosophy is to provide a unified interface for the user to
+access system resources, which are represented by object handles. This makes
+objects a fundamental concept in the COCONUT-SVSM kernel
+
+This document describes the object and object handle from both th... | ```suggestion
current_task()
.add_obj_handle(Arc::new(ObjHandle::new(id, obj)?))?;
Ok(id)
``` |
svsm | github_2023 | others | 453 | coconut-svsm | Freax13 | @@ -0,0 +1,506 @@
+# Background
+
+The syscalls design philosophy is to provide a unified interface for the user to
+access system resources, which are represented by object handles. This makes
+objects a fundamental concept in the COCONUT-SVSM kernel
+
+This document describes the object and object handle from both th... | Why are we not reporting errors to userspace here? |
svsm | github_2023 | others | 453 | coconut-svsm | Freax13 | @@ -0,0 +1,506 @@
+# Background
+
+The syscalls design philosophy is to provide a unified interface for the user to
+access system resources, which are represented by object handles. This makes
+objects a fundamental concept in the COCONUT-SVSM kernel
+
+This document describes the object and object handle from both th... | Storing the object id in the map keys and in the map values (inside `ObjHandle`) is redundant. Can we remove it from `ObjHandle` (or just remove `ObjHandle` altogether and just pass around `Arc<Obj>`? |
svsm | github_2023 | others | 453 | coconut-svsm | Freax13 | @@ -0,0 +1,506 @@
+# Background
+
+The syscalls design philosophy is to provide a unified interface for the user to
+access system resources, which are represented by object handles. This makes
+objects a fundamental concept in the COCONUT-SVSM kernel
+
+This document describes the object and object handle from both th... | ```suggestion
trait EventObj {
``` |
svsm | github_2023 | others | 453 | coconut-svsm | Freax13 | @@ -0,0 +1,408 @@
+# Background
+
+The syscalls design philosophy is to provide a unified interface for the user to
+access system resources, which are represented by object handles. This makes
+objects a fundamental concept in the COCONUT-SVSM kernel
+
+This document describes the object and object handle from both th... | This comment is no longer accurate. |
svsm | github_2023 | others | 453 | coconut-svsm | Freax13 | @@ -0,0 +1,408 @@
+# Background
+
+The syscalls design philosophy is to provide a unified interface for the user to
+access system resources, which are represented by object handles. This makes
+objects a fundamental concept in the COCONUT-SVSM kernel
+
+This document describes the object and object handle from both th... | Can we move the allocation of the object id into this method? Now that we no longer need to maintain a global id, we can just use any available id in the map. Allocating the id in `add_obj` has the advantage that `add_obj` can no longer fail because the id is already in use. |
svsm | github_2023 | others | 453 | coconut-svsm | Freax13 | @@ -0,0 +1,408 @@
+# Background
+
+The syscalls design philosophy is to provide a unified interface for the user to
+access system resources, which are represented by object handles. This makes
+objects a fundamental concept in the COCONUT-SVSM kernel
+
+This document describes the object and object handle from both th... | Can we also add a newtype `pub struct ObjectHandle(u32);` (without a `Drop` impl) in the kernel and use it here? Personally, I'd prefer this to passing around untyped integers and I expect us to use this type a lot when implementing syscalls. |
svsm | github_2023 | others | 453 | coconut-svsm | Freax13 | @@ -0,0 +1,427 @@
+# Background
+
+The syscalls design philosophy is to provide a unified interface for the user to
+access system resources, which are represented by object handles. This makes
+objects a fundamental concept in the COCONUT-SVSM kernel
+
+This document describes the object and object handle from both th... | ```suggestion
- `remove_obj(&self, id: ObjHandle) -> Result<Arc<dyn Obj>, SvsmError>;` It
removes the object from the BTreeMap. This method will be used by the CLOSE
syscall to remove the corresponding object from process and drop it.
- `get_obj(&self, id: ObjHandle) -> Result<Arc<dyn Obj>, SvsmError>;` It ge... |
svsm | github_2023 | others | 453 | coconut-svsm | Freax13 | @@ -0,0 +1,427 @@
+# Background
+
+The syscalls design philosophy is to provide a unified interface for the user to
+access system resources, which are represented by object handles. This makes
+objects a fundamental concept in the COCONUT-SVSM kernel
+
+This document describes the object and object handle from both th... | There may be an object with id `objs.len()`. Consider the following sequence:
1. An object is added -> `len()` is 0, so id is 0
2. Another object is added -> `len()` is 1, id is 1
3. The object with id 0 is removed.
4. Another object is added -> `len()` is 1, so id is 1
In step 4 a second object with id 1 was cr... |
svsm | github_2023 | others | 453 | coconut-svsm | Freax13 | @@ -0,0 +1,427 @@
+# Background
+
+The syscalls design philosophy is to provide a unified interface for the user to
+access system resources, which are represented by object handles. This makes
+objects a fundamental concept in the COCONUT-SVSM kernel
+
+This document describes the object and object handle from both th... | Let's rename this to `obj_add`. We no longer call any `.open()` methods on the object, so the name doesn't quite fit anymore. |
svsm | github_2023 | others | 450 | coconut-svsm | 00xc | @@ -932,47 +933,89 @@ impl PageRef {
pub fn try_copy_page(&self) -> Result<Self, SvsmError> {
let virt_addr = allocate_file_page()?;
+
+ let src = self.virt_addr.bits();
+ let dst = virt_addr.bits();
+ let size = PAGE_SIZE;
unsafe {
- let src = self.virt_addr.as_... | Shouldn't we do a `cld` beforehand, since we do not know the status of the direction flag? We have the same in [`do_movsb()`](https://github.com/coconut-svsm/svsm/blob/6d8a3e90944e6fb3727fcb17fc1b21693bfe76c0/kernel/src/mm/guestmem.rs#L165). Same comment about `rep_movsb()` a few lines below. |
svsm | github_2023 | others | 450 | coconut-svsm | joergroedel | @@ -932,47 +933,89 @@ impl PageRef {
pub fn try_copy_page(&self) -> Result<Self, SvsmError> {
let virt_addr = allocate_file_page()?;
+
+ let src = self.virt_addr.bits();
+ let dst = virt_addr.bits();
+ let size = PAGE_SIZE;
unsafe {
- let src = self.virt_addr.as_... | This function is x86-architecture specific, in order to prepare for future portability to other architectures please place these assembly helpers under cpu/ and give them a more generic name. |
svsm | github_2023 | others | 450 | coconut-svsm | joergroedel | @@ -932,47 +933,89 @@ impl PageRef {
pub fn try_copy_page(&self) -> Result<Self, SvsmError> {
let virt_addr = allocate_file_page()?;
+
+ let src = self.virt_addr.bits();
+ let dst = virt_addr.bits();
+ let size = PAGE_SIZE;
unsafe {
- let src = self.virt_addr.as_... | Same here, please move to cpu/ module and give it a more generic name. |
svsm | github_2023 | others | 447 | coconut-svsm | roy-hopkins | @@ -149,6 +149,10 @@ impl GpaMap {
// Place the kernel area at 64 MB with a size of 16 MB.
GpaRange::new(0x04000000, 0x01000000)?
}
+ Hypervisor::Vanadium => {
+ // Place the kernel area at 8TiB-2GiB with a size of 16 MB.
+ GpaRange... | As far as I can see this is the only difference between the Qemu and Vanadium configurations. Can you see the two diverging more in the future? Would it make sense to make the Qemu kernel location align with Vanadium? |
svsm | github_2023 | others | 391 | coconut-svsm | p4zuu | @@ -143,6 +146,98 @@ pub trait InsnMachineCtx: core::fmt::Debug {
fn read_cr0(&self) -> u64;
/// Read CR4 register
fn read_cr4(&self) -> u64;
+
+ /// Read a register
+ fn read_reg(&self, _reg: Register) -> usize {
+ panic!("Reading register is not implemented");
+ }
+
+ /// Read rflags... | Very nitpick but you can directly use the `unimplemented!()` macro :) |
svsm | github_2023 | others | 391 | coconut-svsm | p4zuu | @@ -84,6 +92,10 @@ fn init_encrypt_mask(platform: &dyn SvsmPlatform, vtom: usize) -> ImmutAfterInit
guest_phys_addr_size
};
+ PHYS_ADDR_SIZE | I would rather return the Result here instead:
```suggestion
PHYS_ADDR_SIZE.reinit(&phys_addr_size)?;
``` |
svsm | github_2023 | others | 391 | coconut-svsm | p4zuu | @@ -143,7 +143,11 @@ pub fn handle_vc_exception(ctx: &mut X86ExceptionContext, vector: usize) -> Resu
Ok(())
}
(SVM_EXIT_CPUID, Some(DecodedInsn::Cpuid)) => handle_cpuid(ctx),
- (SVM_EXIT_IOIO, Some(ins)) => handle_ioio(ctx, ghcb, ins),
+ (SVM_EXIT_IOIO, Some(_)) => insn_ctx... | I would avoid using `unwrap()` here and return an error instead to let the caller decide to panic or not. This is even a security issue: a user can panic the SVSM kernel by providing buggy raw instructions (so bytes) to the decoder. This should be possible by changing the instructions in userspace that raised the #VC b... |
svsm | github_2023 | others | 391 | coconut-svsm | p4zuu | @@ -797,11 +1016,269 @@ impl DecodedInsnCtx {
DecodedInsn::Out(Operand::rdx(), self.opsize)
}
}
+ OpCodeClass::Ins | OpCodeClass::Outs => {
+ if self.prefix.contains(PrefixFlags::REPZ_P) {
+ // The prefix REPZ(F3h) actually ... | Same comment about `unwrap()` |
svsm | github_2023 | others | 391 | coconut-svsm | p4zuu | @@ -797,11 +1016,269 @@ impl DecodedInsnCtx {
DecodedInsn::Out(Operand::rdx(), self.opsize)
}
}
+ OpCodeClass::Ins | OpCodeClass::Outs => {
+ if self.prefix.contains(PrefixFlags::REPZ_P) {
+ // The prefix REPZ(F3h) actually ... | Same comment about `unwrap()` |
svsm | github_2023 | others | 391 | coconut-svsm | p4zuu | @@ -415,9 +600,39 @@ impl DecodedInsnCtx {
///
/// # Returns
///
- /// The length of the decoded instruction as a `usize`.
+ /// The length of the decoded instruction as a `usize`. If the
+ /// repeat count is greater than 1, then return 0 to indicate not to
+ /// skip this instruction. If th... | We're starting to have divergence here, some handlers return a `VcErrorType::DecodedFailed` if there was an issue while decoding. It would be nice to coordinate errors on this.
I don't think returning a `VcError` here makes sense, but maybe we can convert `InsnError::UnSupportedInsn` to `VcError` in #VC handler the ca... |
svsm | github_2023 | others | 391 | coconut-svsm | joergroedel | @@ -117,6 +127,15 @@ fn make_private_address(paddr: PhysAddr) -> PhysAddr {
PhysAddr::from(paddr.bits() & !shared_pte_mask() | private_pte_mask())
}
+fn shared_address(paddr: PhysAddr) -> bool {
+ if shared_pte_mask() | private_pte_mask() != 0 {
+ (paddr.bits() & shared_pte_mask()) == shared_pte_mask(... | ```suggestion
make_shared_address(paddr) == paddr
```
This is the bug that makes the test-cases fail on AMD. The logic really only works for TDX and causes all pages treated as shared on SNP. As a result the instruction decoder made all of its temporary mappings shared and read the encrypted data. Fixing it lik... |
svsm | github_2023 | others | 391 | coconut-svsm | p4zuu | @@ -143,6 +146,121 @@ pub trait InsnMachineCtx: core::fmt::Debug {
fn read_cr0(&self) -> u64;
/// Read CR4 register
fn read_cr4(&self) -> u64;
+
+ /// Read a register
+ fn read_reg(&self, _reg: Register) -> usize {
+ unimplemented!("Reading register is not implemented");
+ }
+
+ /// Re... | I would rather use a `VirtAddr` as early as possible:
```suggestion
_la: VirtAddr,
``` |
svsm | github_2023 | others | 391 | coconut-svsm | p4zuu | @@ -143,6 +146,121 @@ pub trait InsnMachineCtx: core::fmt::Debug {
fn read_cr0(&self) -> u64;
/// Read CR4 register
fn read_cr4(&self) -> u64;
+
+ /// Read a register
+ fn read_reg(&self, _reg: Register) -> usize {
+ unimplemented!("Reading register is not implemented");
+ }
+
+ /// Re... | Since this method will likely be implemented by reading directly to memory, I would prefer making this function `unsafe`:
```suggestion
unsafe fn mem_read(&self) -> Result<Self::Item, InsnError> {
```
I would also add a Safety comment similar to `GuestPtr::read()` for all the implementations as well, the call... |
svsm | github_2023 | others | 391 | coconut-svsm | p4zuu | @@ -143,6 +146,121 @@ pub trait InsnMachineCtx: core::fmt::Debug {
fn read_cr0(&self) -> u64;
/// Read CR4 register
fn read_cr4(&self) -> u64;
+
+ /// Read a register
+ fn read_reg(&self, _reg: Register) -> usize {
+ unimplemented!("Reading register is not implemented");
+ }
+
+ /// Re... | Same comment than `mem_read()` about `unsafe`:
```suggestion
unsafe fn mem_write(&mut self, _data: Self::Item) -> Result<(), InsnError> {
``` |
svsm | github_2023 | others | 391 | coconut-svsm | p4zuu | @@ -115,3 +159,113 @@ impl Drop for PerCPUPageMappingGuard {
}
}
}
+
+/// Represents a guard for a specific memory range mapping, which will
+/// unmap the specific memory range after being dropped.
+#[derive(Debug)]
+pub struct MemMappingGuard<T> {
+ // The guard of holding the temperary mapping for ... | Similar to `InsnMachineMem::read()`, I would make this function unsafe with a Safety comment |
svsm | github_2023 | others | 391 | coconut-svsm | p4zuu | @@ -115,3 +159,113 @@ impl Drop for PerCPUPageMappingGuard {
}
}
}
+
+/// Represents a guard for a specific memory range mapping, which will
+/// unmap the specific memory range after being dropped.
+#[derive(Debug)]
+pub struct MemMappingGuard<T> {
+ // The guard of holding the temperary mapping for ... | Same comment about `unsafe` |
svsm | github_2023 | others | 391 | coconut-svsm | joergroedel | @@ -71,6 +88,98 @@ impl InsnMachineCtx for X86ExceptionContext {
fn read_cr4(&self) -> u64 {
read_cr4().bits()
}
+
+ fn read_reg(&self, reg: Register) -> usize {
+ match reg {
+ Register::Rax => self.regs.rax,
+ Register::Rdx => self.regs.rdx,
+ Register::Rc... | Most of the checks are done by the hardware already. For kernel-MMIO is no issue at all, as the kernel trusts itself and all permission checks are done in hardware before the #VE/#VC exception is raised. For user-MMIO it is similar, we just need to make sure to set CR0.WP=1 on all CPUs.
The only exception is the che... |
svsm | github_2023 | others | 392 | coconut-svsm | 00xc | @@ -104,3 +104,34 @@ pub fn get_regular_report(buffer: &mut [u8]) -> Result<usize, SvsmReqError> {
pub fn get_extended_report(buffer: &mut [u8], certs: &mut [u8]) -> Result<usize, SvsmReqError> {
get_report(buffer, Some(certs))
}
+
+#[cfg(test)]
+mod tests {
+ extern crate alloc;
+
+ use super::*;
+ use... | Can we make an enum out of this value and place it somewhere like `kernel/src/testing.rs`? Let's also add some documentation there referencing the `scripts/test-in-svsm.sh` script. This way it will be easier for other developers to use this infrastructure. |
svsm | github_2023 | others | 392 | coconut-svsm | 00xc | @@ -104,3 +104,34 @@ pub fn get_regular_report(buffer: &mut [u8]) -> Result<usize, SvsmReqError> {
pub fn get_extended_report(buffer: &mut [u8], certs: &mut [u8]) -> Result<usize, SvsmReqError> {
get_report(buffer, Some(certs))
}
+
+#[cfg(test)]
+mod tests {
+ extern crate alloc;
+
+ use super::*;
+ use... | This will display the error cause:
```suggestion
response.validate().unwrap();
``` |
svsm | github_2023 | others | 392 | coconut-svsm | 00xc | @@ -1,7 +1,65 @@
use log::info;
use test::ShouldPanic;
-use crate::{cpu::percpu::current_ghcb, sev::ghcb::GHCBIOSize};
+use crate::{
+ cpu::percpu::current_ghcb,
+ locking::{LockGuard, SpinLock},
+ serial::{SerialPort, Terminal},
+ sev::ghcb::GHCBIOSize,
+ svsm_console::SVSMIOPort,
+};
+
+use core::s... | This evaluates `$left` and `$right` twice in the error case. I suggest using temporary variables. There is also a typo in the error message ("rigth").
```suggestion
#[macro_export]
macro_rules! assert_eq_warn {
($left:expr, $right:expr) => {
{
let left = $left;
let right = $... |
svsm | github_2023 | others | 432 | coconut-svsm | p4zuu | @@ -142,10 +142,13 @@ global_asm!(
/* Determine the PTE C-bit position from the CPUID page. */
+ /* Locate the table. The pointer to the CPUID page is 12 bytes into
+ * the stage2 startup structure. */
+ movl 12(%ebp), %ecx
/* Read the number of entries. */
- mov CPUI... | I guess you meant the following here:
```suggestion
leal 16(%ecx), %ecx
``` |
svsm | github_2023 | others | 432 | coconut-svsm | roy-hopkins | @@ -67,6 +68,12 @@ startup_32:
leal kernel_elf(%ebp), %edi
pushl %edi
+ /* Push the location of the secrets page. It is always at 9E000 */
+ pushl $0x9F000 | This should be `$0x9E000` in this commit. However, I see the value is replaced in a later commit. |
svsm | github_2023 | others | 432 | coconut-svsm | roy-hopkins | @@ -73,16 +73,15 @@ impl GpaMap {
options: &CmdOptions,
firmware: &Option<Box<dyn Firmware>>,
) -> Result<Self, Box<dyn Error>> {
- // 0x000000-0x00EFFF: zero-filled (must be pre-validated)
- // 0x00F000-0x00FFFF: initial stage 2 stack page
- // 0x010000-0x0nnnnn: stage... | Minor observation: the kernel start address is hardcoded below as 0x8a0000 so the start address can be included in this comment. |
svsm | github_2023 | c | 432 | coconut-svsm | roy-hopkins | @@ -194,15 +194,15 @@ void init_sev_meta(struct svsm_meta_data *svsm_meta)
svsm_meta->version = 1;
svsm_meta->num_desc = NUM_DESCS;
- svsm_meta->descs[0].base = 0;
- svsm_meta->descs[0].len = 632 * 1024;
+ svsm_meta->descs[0].base = 8192 * 1024;
+ svsm_meta->descs[0].len = 8832 * 1024; | I think the length is wrong here.
In fact, unless it's safe to overlap this range with the secrets and CPUID pages then I think we will need to add two SEV_DESC_TYPE_SNP_SEC_MEM sections, the first from 0x800000-0x805FFF and the second from 0x808000 to the end of the stage 2 image (or the maximum stage 2 size which... |
svsm | github_2023 | others | 432 | coconut-svsm | roy-hopkins | @@ -100,8 +106,8 @@ fn setup_env(
set_init_pgtable(PageTableRef::shared(unsafe { addr_of_mut!(pgtable) }));
- // The end of the heap is the base of the secrets page.
- setup_stage2_allocator(0x9e000);
+ // The end of the heap is the base of the kernel image.
+ setup_stage2_allocator(launch_info.ker... | I don't think this works when stage1 is in use. In the stage1 case, the `kernel_elf_start` is still in low memory isn't it?
Although on further review I see this is replaced by a later commit. |
svsm | github_2023 | others | 432 | coconut-svsm | roy-hopkins | @@ -7,48 +7,97 @@
use crate::address::{PhysAddr, VirtAddr};
use crate::utils::immut_after_init::ImmutAfterInitCell;
-#[derive(Copy, Clone)]
+#[derive(Debug, Copy, Clone)]
#[allow(dead_code)]
-struct KernelMapping {
+pub struct FixedAddressMappingRange {
virt_start: VirtAddr,
virt_end: VirtAddr,
phys... | Should be "Invalid _virtual_ address" |
svsm | github_2023 | others | 432 | coconut-svsm | Freax13 | @@ -53,9 +55,17 @@ pub struct Stage2LaunchInfo {
// platform_type must be the second field.
pub platform_type: u32,
+ // cpuid_page must be the third field.
+ pub cpuid_page: u32,
+
+ // secrets_page must be the fourth field.
+ pub secrets_page: u32,
+
+ pub stage2_end: u32,
pub kernel_e... | ```suggestion
```
Structs marked as `#[repr(packed)]` don't need padding fields.
|
svsm | github_2023 | others | 432 | coconut-svsm | Freax13 | @@ -107,35 +105,11 @@ impl GpaMap {
0
};
- let stage2_image = GpaRange::new(0x10000, stage2_len as u64)?;
+ let stage2_image = GpaRange::new(0x808000, stage2_len as u64)?;
- // Calculate the firmware range
- let firmware_range = if let Some(firmware) = firmware {
- ... | ```suggestion
let kernel_address = stage2_image.get_end().next_multiple_of(0x1000);
``` |
svsm | github_2023 | others | 432 | coconut-svsm | Freax13 | @@ -7,48 +7,97 @@
use crate::address::{PhysAddr, VirtAddr};
use crate::utils::immut_after_init::ImmutAfterInitCell;
-#[derive(Copy, Clone)]
+#[derive(Debug, Copy, Clone)]
#[allow(dead_code)]
-struct KernelMapping {
+pub struct FixedAddressMappingRange {
virt_start: VirtAddr,
virt_end: VirtAddr,
phys... | ```suggestion
if (mapping.virt_start..mapping.virt_end).contains(&vaddr) {
let offset = vaddr - mapping.virt_start;
Some(mapping.phys_start + offset)
} else {
None
}
```
or even
```suggestion
(mapping.virt_start..mapping.virt_end)
.contains(&vaddr)
... |
svsm | github_2023 | others | 432 | coconut-svsm | Freax13 | @@ -7,48 +7,97 @@
use crate::address::{PhysAddr, VirtAddr};
use crate::utils::immut_after_init::ImmutAfterInitCell;
-#[derive(Copy, Clone)]
+#[derive(Debug, Copy, Clone)]
#[allow(dead_code)]
-struct KernelMapping {
+pub struct FixedAddressMappingRange {
virt_start: VirtAddr,
virt_end: VirtAddr,
phys... | ```suggestion
panic!("Invalid virtual address {vaddr:#018x}");
```
Here and elsewhere. |
svsm | github_2023 | others | 432 | coconut-svsm | Freax13 | @@ -7,48 +7,97 @@
use crate::address::{PhysAddr, VirtAddr};
use crate::utils::immut_after_init::ImmutAfterInitCell;
-#[derive(Copy, Clone)]
+#[derive(Debug, Copy, Clone)]
#[allow(dead_code)]
-struct KernelMapping {
+pub struct FixedAddressMappingRange {
virt_start: VirtAddr,
virt_end: VirtAddr,
phys... | Using `&` and `ref` is redundant.
```suggestion
if let Some(ref mapping) = FIXED_MAPPING.heap_mapping {
```
or
```suggestion
if let Some(mapping) = &FIXED_MAPPING.heap_mapping {
```
Here and elsewhere. |
svsm | github_2023 | others | 432 | coconut-svsm | Freax13 | @@ -7,48 +7,97 @@
use crate::address::{PhysAddr, VirtAddr};
use crate::utils::immut_after_init::ImmutAfterInitCell;
-#[derive(Copy, Clone)]
+#[derive(Debug, Copy, Clone)]
#[allow(dead_code)]
-struct KernelMapping {
+pub struct FixedAddressMappingRange {
virt_start: VirtAddr,
virt_end: VirtAddr,
phys... | ```suggestion
let size = mapping.virt_end - mapping.virt_start;
if paddr >= mapping.phys_start + size {
None
} else {
let offset = paddr - mapping.phys_start;
```
Here and elsewhere. |
svsm | github_2023 | others | 432 | coconut-svsm | Freax13 | @@ -10,7 +10,8 @@ OUTPUT_ARCH(i386:x86-64)
SECTIONS
{
- . = 64k;
+ /* Base address is 8 MB + 32 KB */
+ . = 8224k; | ```suggestion
. = 8m + 32k;
``` |
svsm | github_2023 | others | 432 | coconut-svsm | Freax13 | @@ -86,16 +83,36 @@ fn setup_env(
.env_setup(debug_serial_port)
.expect("Early environment setup failed");
- init_kernel_mapping_info(
- VirtAddr::null(),
- VirtAddr::from(640 * 1024usize),
- PhysAddr::null(),
+ // Validate the first 640 KB of memory so it can be used if n... | ```suggestion
let cpuid_page = unsafe { &*(launch_info.cpuid_page as *const SnpCpuidTable) };
```
There's no need to go through `VirtAddr`. |
svsm | github_2023 | others | 432 | coconut-svsm | Freax13 | @@ -130,10 +130,15 @@ pub fn invalidate_early_boot_memory(
// invalidate stage 2 memory, unless firmware is loaded into low memory.
// Also invalidate the boot data if required.
if !config.fw_in_low_memory() {
- let stage2_region = MemoryRegion::new(PhysAddr::null(), 640 * 1024);
- invalida... | ```suggestion
let stage2_base = PhysAddr::from(launch_info.stage2_start);
let stage2_end = PhysAddr::from(launch_info.stage2_end);
let stage2_region = MemoryRegion::from_addresses(stage2_base, stage2_end);
``` |
svsm | github_2023 | c | 432 | coconut-svsm | Freax13 | @@ -194,17 +194,21 @@ void init_sev_meta(struct svsm_meta_data *svsm_meta)
svsm_meta->version = 1;
svsm_meta->num_desc = NUM_DESCS;
- svsm_meta->descs[0].base = 0;
- svsm_meta->descs[0].len = 632 * 1024;
- svsm_meta->descs[0].type = SEV_DESC_TYPE_SNP_SEC_MEM;
+ svsm_meta->descs[3].base = 0x800000;
+ svsm_meta->... | Shouldn't we use index `0` here? |
svsm | github_2023 | others | 432 | coconut-svsm | Freax13 | @@ -7,48 +7,97 @@
use crate::address::{PhysAddr, VirtAddr};
use crate::utils::immut_after_init::ImmutAfterInitCell;
-#[derive(Copy, Clone)]
+#[derive(Debug, Copy, Clone)]
#[allow(dead_code)]
-struct KernelMapping {
+pub struct FixedAddressMappingRange {
virt_start: VirtAddr,
virt_end: VirtAddr,
phys... | Have considered making this a function `FixedAddressMappingRange`? |
svsm | github_2023 | c | 432 | coconut-svsm | roy-hopkins | @@ -194,17 +194,21 @@ void init_sev_meta(struct svsm_meta_data *svsm_meta)
svsm_meta->version = 1;
svsm_meta->num_desc = NUM_DESCS;
- svsm_meta->descs[0].base = 0;
- svsm_meta->descs[0].len = 632 * 1024;
+ svsm_meta->descs[0].base = 0x800000;
+ svsm_meta->descs[0].len = 0x6000;
svsm_meta->descs[0].type = SEV... | This should be:
```suggestion
svsm_meta->descs[3].len = 0x8A0000 - 0x808000;
``` |
svsm | github_2023 | others | 445 | coconut-svsm | joergroedel | @@ -0,0 +1,36 @@
+#!/bin/env sh
+# SPDX-License-Identifier: MIT OR Apache-2.0
+#
+# Author: Tom Dohrmann <erbse.13@gmx.de>
+# A script to find functions with excessive stack sizes.
+# Requires yq-go and obj2yaml (bundled with llvm) to be installed.
+
+# Default to displaying functions with a stack size >= 0x400 (1024) ... | Unfortunately the `obj2yaml` tool is not available on openSUSE :(
But some searching found that `llvm-readelf -C --stack-sizes` will also print the stack sizes. Can the script use this tool instead? |
svsm | github_2023 | others | 445 | coconut-svsm | joergroedel | @@ -0,0 +1,27 @@
+#!/bin/env sh
+# SPDX-License-Identifier: MIT OR Apache-2.0
+#
+# Author: Tom Dohrmann <erbse.13@gmx.de>
+# A script to find functions with excessive stack sizes.
+# Requires llvm-readelf (bundled with llvm) to be installed.
+
+# Forcefully enable a nightly toolchain.
+export RUSTUP_TOOLCHAIN=nightly
... | ```suggestion
# Print stack frame sizes, sorted from small to large
llvm-readelf -C --stack-sizes target/x86_64-unknown-none/${TARGET_PATH}/svsm | sort -n
``` |
svsm | github_2023 | others | 441 | coconut-svsm | Freax13 | @@ -0,0 +1,195 @@
+// SPDX-License-Identifier: MIT
+//
+// Copyright (c) 2024 SUSE LLC
+//
+// Author: Joerg Roedel <jroedel@suse.de>
+
+use core::arch::asm;
+
+/// Interrupt flag in RFLAGS register
+const EFLAGS_IF: u64 = 1 << 9;
+
+/// Unconditionally disable IRQs
+///
+/// # Safety
+///
+/// Callers need to take car... | This potentially modifies flags other than IF. I don't know if we currently use any of the other flags (such as AC for SMAP), but it's probably safer to not touch the other flags if we don't need to. |
svsm | github_2023 | others | 441 | coconut-svsm | Freax13 | @@ -0,0 +1,195 @@
+// SPDX-License-Identifier: MIT
+//
+// Copyright (c) 2024 SUSE LLC
+//
+// Author: Joerg Roedel <jroedel@suse.de>
+
+use core::arch::asm;
+
+/// Interrupt flag in RFLAGS register
+const EFLAGS_IF: u64 = 1 << 9;
+
+/// Unconditionally disable IRQs
+///
+/// # Safety
+///
+/// Callers need to take car... | This API can cause some problems if multiple IrqGuards with different lifetimes are used.
```rust
let guard1 = IrqGuard::default(); // This disables interrupts.
let guard2 = IrqGuard::default(); // This does nothing because interrupts are already disabled.
drop(guard1); // This re-enables interrupts.
// At this ... |
svsm | github_2023 | others | 441 | coconut-svsm | Freax13 | @@ -0,0 +1,71 @@
+// SPDX-License-Identifier: MIT
+//
+// Copyright (c) 2024 SUSE LLC
+//
+// Author: Joerg Roedel <jroedel@suse.de>
+use crate::cpu::{irqs_restore, irqs_save};
+
+/// Abstracts IRQ state handling when taking and releasing locks. There are two
+/// implemenations:
+///
+/// * [IrqUnsafeLocking] implem... | ```suggestion
self.state.map(|s| unsafe { irqs_restore(s) });
self.state = None;
```
or
```suggestion
if let Some(state) = self.state {
unsafe {
irqs_restore(s);
}
}
```
|
svsm | github_2023 | others | 441 | coconut-svsm | Freax13 | @@ -4,59 +4,70 @@
//
// Author: Joerg Roedel <jroedel@suse.de>
+use super::common::*;
use core::cell::UnsafeCell;
+use core::marker::PhantomData;
use core::ops::{Deref, DerefMut};
use core::sync::atomic::{AtomicU64, Ordering};
/// A guard that provides read access to the data protected by [`RWLock`]
#[derive... | ```suggestion
/// IRQ state before and after critical section
``` |
svsm | github_2023 | others | 441 | coconut-svsm | 00xc | @@ -0,0 +1,195 @@
+// SPDX-License-Identifier: MIT
+//
+// Copyright (c) 2024 SUSE LLC
+//
+// Author: Joerg Roedel <jroedel@suse.de>
+
+use core::arch::asm;
+
+/// Interrupt flag in RFLAGS register
+const EFLAGS_IF: u64 = 1 << 9;
+
+/// Unconditionally disable IRQs
+///
+/// # Safety
+///
+/// Callers need to take car... | ```suggestion
asm!("cli", options(att_syntax, preserves_flags, nostack));
``` |
svsm | github_2023 | others | 441 | coconut-svsm | 00xc | @@ -0,0 +1,195 @@
+// SPDX-License-Identifier: MIT
+//
+// Copyright (c) 2024 SUSE LLC
+//
+// Author: Joerg Roedel <jroedel@suse.de>
+
+use core::arch::asm;
+
+/// Interrupt flag in RFLAGS register
+const EFLAGS_IF: u64 = 1 << 9;
+
+/// Unconditionally disable IRQs
+///
+/// # Safety
+///
+/// Callers need to take car... | ```suggestion
asm!("sti", options(att_syntax, preserves_flags, nostack));
``` |
svsm | github_2023 | others | 441 | coconut-svsm | 00xc | @@ -0,0 +1,195 @@
+// SPDX-License-Identifier: MIT
+//
+// Copyright (c) 2024 SUSE LLC
+//
+// Author: Joerg Roedel <jroedel@suse.de>
+
+use core::arch::asm;
+
+/// Interrupt flag in RFLAGS register
+const EFLAGS_IF: u64 = 1 << 9;
+
+/// Unconditionally disable IRQs
+///
+/// # Safety
+///
+/// Callers need to take car... | We do not need to force using RAX:
```suggestion
asm!("pushfq",
"popq {}",
out(reg) s,
options(att_syntax, nomem, preserves_flags));
``` |
svsm | github_2023 | others | 441 | coconut-svsm | 00xc | @@ -0,0 +1,195 @@
+// SPDX-License-Identifier: MIT
+//
+// Copyright (c) 2024 SUSE LLC
+//
+// Author: Joerg Roedel <jroedel@suse.de>
+
+use core::arch::asm;
+
+/// Interrupt flag in RFLAGS register
+const EFLAGS_IF: u64 = 1 << 9;
+
+/// Unconditionally disable IRQs
+///
+/// # Safety
+///
+/// Callers need to take car... | This probably needs to be more specific |
svsm | github_2023 | others | 441 | coconut-svsm | 00xc | @@ -0,0 +1,71 @@
+// SPDX-License-Identifier: MIT
+//
+// Copyright (c) 2024 SUSE LLC
+//
+// Author: Joerg Roedel <jroedel@suse.de>
+use crate::cpu::{irqs_restore, irqs_save};
+
+/// Abstracts IRQ state handling when taking and releasing locks. There are two
+/// implemenations:
+///
+/// * [IrqUnsafeLocking] implem... | ```suggestion
Self {}
``` |
svsm | github_2023 | others | 441 | coconut-svsm | 00xc | @@ -149,9 +165,10 @@ impl<T> RWLock<T> {
/// let rwlock = RWLock::new(data);
/// ```
pub const fn new(data: T) -> Self {
- RWLock {
+ RawRWLock { | ```suggestion
Self {
``` |
svsm | github_2023 | others | 441 | coconut-svsm | 00xc | @@ -110,10 +126,11 @@ impl<T> SpinLock<T> {
/// let spin_lock = SpinLock::new(data);
/// ```
pub const fn new(data: T) -> Self {
- SpinLock {
+ RawSpinLock { | ```suggestion
Self {
``` |
svsm | github_2023 | others | 441 | coconut-svsm | Freax13 | @@ -0,0 +1,242 @@
+// SPDX-License-Identifier: MIT
+//
+// Copyright (c) 2024 SUSE LLC
+//
+// Author: Joerg Roedel <jroedel@suse.de>
+
+use crate::cpu::{irqs_disable, irqs_enable};
+use core::arch::asm;
+use core::sync::atomic::{AtomicBool, AtomicIsize, Ordering};
+
+/// Interrupt flag in RFLAGS register
+const EFLAGS... | ```suggestion
asm!("cli", options(att_syntax, preserves_flags, nomem));
``` |
svsm | github_2023 | others | 441 | coconut-svsm | Freax13 | @@ -0,0 +1,242 @@
+// SPDX-License-Identifier: MIT
+//
+// Copyright (c) 2024 SUSE LLC
+//
+// Author: Joerg Roedel <jroedel@suse.de>
+
+use crate::cpu::{irqs_disable, irqs_enable};
+use core::arch::asm;
+use core::sync::atomic::{AtomicBool, AtomicIsize, Ordering};
+
+/// Interrupt flag in RFLAGS register
+const EFLAGS... | ```suggestion
asm!("sti", options(att_syntax, preserves_flags, nomem));
``` |
svsm | github_2023 | others | 441 | coconut-svsm | Freax13 | @@ -0,0 +1,242 @@
+// SPDX-License-Identifier: MIT
+//
+// Copyright (c) 2024 SUSE LLC
+//
+// Author: Joerg Roedel <jroedel@suse.de>
+
+use crate::cpu::{irqs_disable, irqs_enable};
+use core::arch::asm;
+use core::sync::atomic::{AtomicBool, AtomicIsize, Ordering};
+
+/// Interrupt flag in RFLAGS register
+const EFLAGS... | ```suggestion
options(att_syntax, preserves_flags));
```
It's not entirely clear whether [`nomem` implies `nostack`](https://github.com/rust-lang/reference/issues/1350). |
svsm | github_2023 | others | 441 | coconut-svsm | Freax13 | @@ -0,0 +1,242 @@
+// SPDX-License-Identifier: MIT
+//
+// Copyright (c) 2024 SUSE LLC
+//
+// Author: Joerg Roedel <jroedel@suse.de>
+
+use crate::cpu::{irqs_disable, irqs_enable};
+use core::arch::asm;
+use core::sync::atomic::{AtomicBool, AtomicIsize, Ordering};
+
+/// Interrupt flag in RFLAGS register
+const EFLAGS... | ```suggestion
let state: u64;
unsafe {
asm!("pushfq",
"popq {}",
out(reg) state,
options(att_syntax, nomem, preserves_flags));
}
``` |
svsm | github_2023 | others | 441 | coconut-svsm | Freax13 | @@ -0,0 +1,242 @@
+// SPDX-License-Identifier: MIT
+//
+// Copyright (c) 2024 SUSE LLC
+//
+// Author: Joerg Roedel <jroedel@suse.de>
+
+use crate::cpu::{irqs_disable, irqs_enable};
+use core::arch::asm;
+use core::sync::atomic::{AtomicBool, AtomicIsize, Ordering};
+
+/// Interrupt flag in RFLAGS register
+const EFLAGS... | ```suggestion
let val = self.count.fetch_sub(1, Ordering::Relaxed);
self.count.load(Ordering::Relaxed);
assert!(val > 0);
if val == 1 {
``` |
svsm | github_2023 | others | 441 | coconut-svsm | Freax13 | @@ -0,0 +1,242 @@
+// SPDX-License-Identifier: MIT
+//
+// Copyright (c) 2024 SUSE LLC
+//
+// Author: Joerg Roedel <jroedel@suse.de>
+
+use crate::cpu::{irqs_disable, irqs_enable};
+use core::arch::asm;
+use core::sync::atomic::{AtomicBool, AtomicIsize, Ordering};
+
+/// Interrupt flag in RFLAGS register
+const EFLAGS... | ```suggestion
assert_eq!(count, 0);
``` |
svsm | github_2023 | others | 441 | coconut-svsm | Freax13 | @@ -0,0 +1,242 @@
+// SPDX-License-Identifier: MIT
+//
+// Copyright (c) 2024 SUSE LLC
+//
+// Author: Joerg Roedel <jroedel@suse.de>
+
+use crate::cpu::{irqs_disable, irqs_enable};
+use core::arch::asm;
+use core::sync::atomic::{AtomicBool, AtomicIsize, Ordering};
+
+/// Interrupt flag in RFLAGS register
+const EFLAGS... | ```suggestion
pub struct IrqGuard(());
```
Adding a private unit field makes it impossible to create an instance without calling `IrqGuard::new()` (or `IrqGuard::default()`). |
svsm | github_2023 | others | 441 | coconut-svsm | Freax13 | @@ -4,22 +4,27 @@
//
// Author: Joerg Roedel <jroedel@suse.de>
+use super::common::*;
use core::cell::UnsafeCell;
+use core::marker::PhantomData;
use core::ops::{Deref, DerefMut};
use core::sync::atomic::{AtomicU64, Ordering};
/// A guard that provides read access to the data protected by [`RWLock`]
#[derive... | ```suggestion
_irq_state: I,
``` |
svsm | github_2023 | others | 441 | coconut-svsm | Freax13 | @@ -4,22 +4,27 @@
//
// Author: Joerg Roedel <jroedel@suse.de>
+use super::common::*;
use core::cell::UnsafeCell;
+use core::marker::PhantomData;
use core::ops::{Deref, DerefMut};
use core::sync::atomic::{AtomicU64, Ordering};
/// A guard that provides read access to the data protected by [`RWLock`]
#[derive... | ```suggestion
pub struct RawReadLockGuard<'a, T, I> {
```
Generic bounds in type declarations are generally discouraged unless strictly needed (e.g. the [HashMap](https://doc.rust-lang.org/stable/std/collections/struct.HashMap.html) type doesn't have a `Hash` bound on the key type `K`, only the [methods](https://d... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.