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
533
coconut-svsm
stefano-garzarella
@@ -259,3 +275,99 @@ pub fn get_vp_register(name: hyperv::HvRegisterName) -> Result<u64, SvsmError> { Ok(reg) } + +#[repr(C)] +#[derive(Clone, Copy, Debug, Default)] +struct HvInputEnableVpVtl { + partition_id: u64, + vp_index: u32, + vtl: u8, + _rsvd: [u8; 3], + context: hyperv::HvInitialVpConte...
Ditto
svsm
github_2023
others
533
coconut-svsm
stefano-garzarella
@@ -438,6 +450,30 @@ impl PerCpu { self.ghcb.get() } + /// Allocates hypercall input/output pages for this CPU. + pub fn allocate_hypercall_pages(&self) -> Result<(), SvsmError> { + let vaddr = allocate_pages(2)?; + let pages = ( + VirtPhysPair::new(vaddr), + Vi...
This should be the last block to be fixed, then the rest seems okay to me. Thank you!
svsm
github_2023
others
525
coconut-svsm
vijaydhanraj
@@ -51,18 +52,34 @@ pub fn exec_user(binary: &str) -> Result<(), SvsmError> { for seg in elf_bin.image_load_segment_iter(virt_base) { let virt_start = VirtAddr::from(seg.vaddr_range.vaddr_begin); let virt_end = VirtAddr::from(seg.vaddr_range.vaddr_end).align_up(PAGE_SIZE); + let virt_len =...
ELF spec states that `file_len` (`p_filesz`)may not be larger than ` virt_len`(`p_memsz`), so it may be better to check for this error condition.
svsm
github_2023
others
525
coconut-svsm
vijaydhanraj
@@ -51,18 +52,34 @@ pub fn exec_user(binary: &str) -> Result<(), SvsmError> { for seg in elf_bin.image_load_segment_iter(virt_base) { let virt_start = VirtAddr::from(seg.vaddr_range.vaddr_begin); let virt_end = VirtAddr::from(seg.vaddr_range.vaddr_end).align_up(PAGE_SIZE); + let virt_len =...
While we are at it, it is also better to fix the `virt_start` alignment requirement. ELF spec doesn't seem to mandate that `virt_start` (or in other words `p_vaddr`) should be page aligned.
svsm
github_2023
others
510
coconut-svsm
Freax13
@@ -90,7 +90,16 @@ impl VMFileMapping { .mapping(offset + page_index * PAGE_SIZE) .ok_or(SvsmError::Mem)?; if flags.contains(VMFileMappingFlags::Private) { - pages.push(page_ref.try_copy_page()?); + let private_page_ref = page_ref.try_copy_pag...
Why do we need to check if the page is writable?
svsm
github_2023
others
510
coconut-svsm
Freax13
@@ -53,14 +54,32 @@ pub fn exec_user(binary: &str) -> Result<(), SvsmError> { let virt_end = VirtAddr::from(seg.vaddr_range.vaddr_end).align_up(PAGE_SIZE); let file_offset = seg.file_range.offset_begin; let len = virt_end - virt_start; + let file_size = seg.file_range.offset_end - seg....
We don't need this if-block here, do we? The calculations also work out if we always use `virt_start.page_align()`, `file_offset - virt_start.page_offset()`, and `file_size + virt_start.page_offset()`, don't they?
svsm
github_2023
others
510
coconut-svsm
joergroedel
@@ -90,7 +90,13 @@ impl VMFileMapping { .mapping(offset + page_index * PAGE_SIZE) .ok_or(SvsmError::Mem)?; if flags.contains(VMFileMappingFlags::Private) { - pages.push(page_ref.try_copy_page()?); + let private_page_ref = page_ref.try_copy_pag...
I wonder why this is necessary. File pages are zeroed out on allocation and try_copy_page() always copies full pages. The truncate operation on files also zeroes out all content after new EOF. So anything in the page after EOF should already be zero.
svsm
github_2023
others
510
coconut-svsm
joergroedel
@@ -53,14 +54,26 @@ pub fn exec_user(binary: &str) -> Result<(), SvsmError> { let virt_end = VirtAddr::from(seg.vaddr_range.vaddr_end).align_up(PAGE_SIZE); let file_offset = seg.file_range.offset_begin; let len = virt_end - virt_start; + let file_size = seg.file_range.offset_end - seg....
Okay, I missed that and have a similar fix in #525 (As I have seen you just noticed as well :) ).
svsm
github_2023
others
518
coconut-svsm
vijaydhanraj
@@ -0,0 +1,32 @@ +{ + "igvm": { + "output": "coconut-qemu.igvm", + "target": "qemu", + "platforms": ["snp", "tdp"], + "policy": "0x30000", + "measure": "print", + "check-kvm": true + }, + + "kernel": { + "tdx-stage1": { + "type": "make", + "file": "bin/s...
Would it be better to rename it explicitly as `output_file`?
svsm
github_2023
others
518
coconut-svsm
vijaydhanraj
@@ -0,0 +1,32 @@ +{ + "igvm": { + "output": "coconut-qemu.igvm", + "target": "qemu", + "platforms": ["snp", "tdp"], + "policy": "0x30000", + "measure": "print", + "check-kvm": true + }, + + "kernel": { + "tdx-stage1": { + "type": "make", + "file": "bin/s...
Build recipes documentation specifies default value for `features` is empty but here we have added `default`. Is this necessary? Also, for other attributes like `policy` which seems to have a default value of `0x30000`. Should this be explicitly added?
svsm
github_2023
others
518
coconut-svsm
vijaydhanraj
@@ -0,0 +1,167 @@ +# COCONUT Build Recipes Format + +This document describes the format of COCONUT build recipes as consumed by the +`scripts/build.py` script. The script takes a build recipe as input and builds +all tooling and component to generate an IGVM output file. + +Build recipes, as IGVM files, are hypervisor ...
`build` -> `built`?
svsm
github_2023
python
518
coconut-svsm
stefano-garzarella
@@ -0,0 +1,565 @@ +#!/usr/bin/env python3 +# + +import subprocess +import argparse +import platform +import json +import os + +class CargoRunner: + """ + A class for running cargo to build specific packages from the workspace. + """ + + def __init__(self, package): + self.package = package + s...
`s/target/elf_target`
svsm
github_2023
python
518
coconut-svsm
stefano-garzarella
@@ -0,0 +1,565 @@ +#!/usr/bin/env python3 +# + +import subprocess +import argparse +import platform +import json +import os + +class CargoRunner: + """ + A class for running cargo to build specific packages from the workspace. + """ + + def __init__(self, package): + self.package = package + s...
Maybe a leftover, IIUC this function doesn't return anything, right?
svsm
github_2023
others
518
coconut-svsm
stefano-garzarella
@@ -0,0 +1,167 @@ +# COCONUT Build Recipes Format + +This document describes the format of COCONUT build recipes as consumed by the +`scripts/build.py` script. The script takes a build recipe as input and builds +all tooling and component to generate an IGVM output file. + +Build recipes, as IGVM files, are hypervisor ...
What about avoiding defaults? When I was reading the json, I was a bit confused seeing `type` just for `make`. Not a strong opinion, just my feeling.
svsm
github_2023
others
526
coconut-svsm
stefano-garzarella
@@ -15,25 +15,19 @@ const EFLAGS_IF: u64 = 1 << 9; /// Unconditionally disable IRQs /// -/// # Safety -/// /// Callers need to take care of re-enabling IRQs. -#[inline(always)]
Is removing `#[inline(always)]` intentional? Not sure if we really need it or not, just asking ;-)
svsm
github_2023
others
526
coconut-svsm
stefano-garzarella
@@ -15,25 +15,19 @@ const EFLAGS_IF: u64 = 1 << 9; /// Unconditionally disable IRQs /// -/// # Safety -/// /// Callers need to take care of re-enabling IRQs. -#[inline(always)] -pub unsafe fn raw_irqs_disable() { +pub fn raw_irqs_disable() { unsafe { asm!("cli", options(att_syntax, preserves_flags, n...
Ditto.
svsm
github_2023
others
526
coconut-svsm
stefano-garzarella
@@ -455,9 +455,7 @@ pub extern "C" fn stage2_main(launch_info: &Stage2LaunchInfo) { // Shut down the GHCB unsafe { shutdown_percpu(); - }
I am not sure if this is a good practice, there is also a lint, to eventually enable, to discourage this: https://rust-lang.github.io/rust-clippy/master/index.html#multiple_unsafe_ops_per_block That said, I don't have a strong opinion since we already do this in several places, but maybe in the future we could avoi...
svsm
github_2023
others
524
coconut-svsm
msft-jlange
@@ -10,24 +10,39 @@ use crate::error::SvsmError; pub enum TdxError { Unknown(u64), Unimplemented, + OperandBusy, PageAlreadyAccepted, PageSizeMismatch, } +#[derive(Clone, Copy, Debug, PartialEq)] +pub enum TdVmcallError { + Unknown(u64), +} + impl From<TdxError> for SvsmError { fn fr...
The TDX architecture defines results codes less than 0x8000_0000_0000_0000 as non-fatal conditions. We can't treat a non-zero success condition as an error. This is why this function is defined to return a `u64` in the `Ok` variant of the result - to provide a specific value of the success return in case it is a non-...
svsm
github_2023
others
524
coconut-svsm
msft-jlange
@@ -50,14 +50,28 @@ unsafe fn tdg_mem_page_accept(frame: PageFrame) -> u64 { let mut ret: u64; unsafe { asm!("tdcall", - in("rax") TDCALL_TDG_MEM_PAGE_ACCEPT, + in("rax") TDG_MEM_PAGE_ACCEPT, in("rcx") EptMappingInfo::from(frame).into_bits(), lateout("rax") ret, ...
My understanding is that TDX_OPERAND_BUSY only applies to TDH operations and not TDG operations. When a TDG operation encounters a busy state, the TDX module will simply not advance RIP past the `tdcall` instruction, so the TD will naturally just reattempt the same call again.
svsm
github_2023
others
524
coconut-svsm
msft-jlange
@@ -50,14 +50,28 @@ unsafe fn tdg_mem_page_accept(frame: PageFrame) -> u64 { let mut ret: u64; unsafe { asm!("tdcall", - in("rax") TDCALL_TDG_MEM_PAGE_ACCEPT, + in("rax") TDG_MEM_PAGE_ACCEPT, in("rcx") EptMappingInfo::from(frame).into_bits(), lateout("rax") ret, ...
What makes 10000 - or any other arbitrary constant - a reasonable retry count? Any retry count needs to be justified with on an architectural basis.
svsm
github_2023
others
524
coconut-svsm
msft-jlange
@@ -50,14 +50,28 @@ unsafe fn tdg_mem_page_accept(frame: PageFrame) -> u64 { let mut ret: u64; unsafe { asm!("tdcall", - in("rax") TDCALL_TDG_MEM_PAGE_ACCEPT, + in("rax") TDG_MEM_PAGE_ACCEPT, in("rcx") EptMappingInfo::from(frame).into_bits(), lateout("rax") ret, ...
Assuming my statement about retries on `tdcall` operations is correct, this function is not needed at all.
svsm
github_2023
others
524
coconut-svsm
msft-jlange
@@ -10,24 +10,39 @@ use crate::error::SvsmError; pub enum TdxError { Unknown(u64), Unimplemented, + OperandBusy, PageAlreadyAccepted, PageSizeMismatch, } +#[derive(Clone, Copy, Debug, PartialEq)] +pub enum TdVmcallError {
I don't see any conversion path from `TdVmcallError` to `SvsmError`. We want to ensure that all defined error types can be represented in `SvsmError`. I suspect that the best way to do this is not to define `TdVmcallError` as a separate class, but rather as an element of `TdxError`. Then your ` tdvmcall_result` func...
svsm
github_2023
others
524
coconut-svsm
msft-jlange
@@ -216,35 +222,41 @@ pub unsafe fn td_accept_virtual_memory(region: MemoryRegion<VirtAddr>) -> Result pub fn tdvmcall_halt() { let pass_regs = (1 << 10) | (1 << 11) | (1 << 12); + let mut ret: u64; unsafe { asm!("tdcall", in("rax") TDG_VP_TDVMCALL, in("rcx") pass_re...
R10 isn't trusted so it isn't guaranteed to be anything. However, there's nothing this code can do based on the contents of R10. It may be more helpful to change the comment to indicate this: R10 is *expected* to be zero but the untrusted host can do anything it wants, so we assert in case we want to be aware of some...
svsm
github_2023
others
486
coconut-svsm
Freax13
@@ -0,0 +1,387 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) Microsoft Corporation +// +// Author: Ziqiao Zhou <ziqiaozhou@microsoft.com> +use vstd::arithmetic::power2::pow2; +use vstd::bits::low_bits_mask; +use vstd::prelude::*; + +#[macro_export] +macro_rules! POW2_VALUE { + (0) => { + ...
```suggestion #(if n == N { POW2_VALUE!(N) } else)* { 0 } ``` Does this maybe work?
svsm
github_2023
others
486
coconut-svsm
Freax13
@@ -0,0 +1,387 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) Microsoft Corporation +// +// Author: Ziqiao Zhou <ziqiaozhou@microsoft.com> +use vstd::arithmetic::power2::pow2; +use vstd::bits::low_bits_mask; +use vstd::prelude::*; + +#[macro_export] +macro_rules! POW2_VALUE {
Why do we need this rather than just doing a bitshift `1 << N`? Is this a performance optimization or is this because the proofs in `bit_shl_values` depend on this macro?
svsm
github_2023
others
486
coconut-svsm
joergroedel
@@ -0,0 +1,4 @@ +builtin=`cargo metadata --format-version 1 | jq -r '.packages[] | select(.name == "builtin_macros") | .targets[].src_path'` +verus=`dirname $builtin`/../../../ +verus=`realpath $verus` +export VERUS_PATH=$verus
Scripts need license-headers as well.
svsm
github_2023
others
486
coconut-svsm
joergroedel
@@ -0,0 +1,13 @@ +#!/bin/bash +VERISMO_REV=5186244 +cargo install --git https://github.com/microsoft/verismo/ --rev $VERISMO_REV cargo-v +builtin=`cargo metadata --format-version 1 | jq -r '.packages[] | select(.name == "builtin_macros") | .targets[].src_path'` +verus=`dirname $builtin`/../../../source/target-verus/rel...
What are these packages needed for? If they are truely needed this needs to be aware of the distribution. Please make sure the installation works on Debian/Ubuntu, Fedora, and openSUSE. If none of these distros are detected, just print a warning and instruct the user what to install manually.
svsm
github_2023
others
486
coconut-svsm
joergroedel
@@ -0,0 +1,13 @@ +#!/bin/bash +VERISMO_REV=5186244 +cargo install --git https://github.com/microsoft/verismo/ --rev $VERISMO_REV cargo-v +builtin=`cargo metadata --format-version 1 | jq -r '.packages[] | select(.name == "builtin_macros") | .targets[].src_path'` +verus=`dirname $builtin`/../../../source/target-verus/rel...
Please ask the user before downloading and executing a script from the internet. Even better would be if you could commit this script directly to the SVSM repository.
svsm
github_2023
others
519
coconut-svsm
Freax13
@@ -79,14 +79,16 @@ pub fn sse_init() { /// no other part of the code is accessing this memory at the same time. pub unsafe fn sse_save_context(addr: u64) { let save_bits = XCR0_X87_ENABLE | XCR0_SSE_ENABLE | XCR0_YMM_ENABLE; - asm!( + unsafe { + asm!(
rustfmt seems to choke on the multi-line asm! block. Could you please fix the indentation levels of these?
svsm
github_2023
others
515
coconut-svsm
Freax13
@@ -0,0 +1,206 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) Microsoft Corporation +// +// Author: Jon Lange <jlange@microsoft.com> + +use super::error::{tdx_result, TdxError}; +use crate::address::{Address, PhysAddr, VirtAddr}; +use crate::error::SvsmError; +use crate::mm::{virt_to_frame, Per...
The host can modify these. We should use `inout("r10d") 0 => _,` (or `lateout("r10") _`) etc. The same applies to `tdvmcall_io`.
svsm
github_2023
others
515
coconut-svsm
Freax13
@@ -0,0 +1,206 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) Microsoft Corporation +// +// Author: Jon Lange <jlange@microsoft.com> + +use super::error::{tdx_result, TdxError}; +use crate::address::{Address, PhysAddr, VirtAddr}; +use crate::error::SvsmError; +use crate::mm::{virt_to_frame, Per...
```suggestion // The caller is expected not to accept a page twice unless ```
svsm
github_2023
others
515
coconut-svsm
Freax13
@@ -0,0 +1,206 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) Microsoft Corporation +// +// Author: Jon Lange <jlange@microsoft.com> + +use super::error::{tdx_result, TdxError}; +use crate::address::{Address, PhysAddr, VirtAddr}; +use crate::error::SvsmError; +use crate::mm::{virt_to_frame, Per...
This method, `tdg_mem_page_accept`, `td_accept_virtual_4k`, `td_accept_virtual_2m`, and `td_accept_virtual_memory` should be marked as unsafe.
svsm
github_2023
others
515
coconut-svsm
Freax13
@@ -0,0 +1,206 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) Microsoft Corporation +// +// Author: Jon Lange <jlange@microsoft.com> + +use super::error::{tdx_result, TdxError}; +use crate::address::{Address, PhysAddr, VirtAddr}; +use crate::error::SvsmError; +use crate::mm::{virt_to_frame, Per...
Can we introduce a constant named `TDCALL_TDG_VMCALL` here?`
svsm
github_2023
others
515
coconut-svsm
Freax13
@@ -0,0 +1,206 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) Microsoft Corporation +// +// Author: Jon Lange <jlange@microsoft.com> + +use super::error::{tdx_result, TdxError}; +use crate::address::{Address, PhysAddr, VirtAddr}; +use crate::error::SvsmError; +use crate::mm::{virt_to_frame, Per...
Can we split `gpa_info` into `gpa` and `level`? I don't think we need to expose to the caller that these are passed as a single value in a single register.
svsm
github_2023
others
515
coconut-svsm
Freax13
@@ -0,0 +1,206 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) Microsoft Corporation +// +// Author: Jon Lange <jlange@microsoft.com> + +use super::error::{tdx_result, TdxError}; +use crate::address::{Address, PhysAddr, VirtAddr}; +use crate::error::SvsmError; +use crate::mm::{virt_to_frame, Per...
```suggestion ``` `T` must be `Sized` by default unless there's a `?Sized` bound. `From<T>` also implies that `T` is `Sized`. This also applies to `tdvmcall_io_read`.
svsm
github_2023
others
515
coconut-svsm
Freax13
@@ -187,26 +166,26 @@ impl GHCIIOPort { impl IOPort for GHCIIOPort { fn outb(&self, port: u16, value: u8) { - tdvmcall_io_write_8(port, value); + tdvmcall_io_write::<u8>(port, value);
```suggestion tdvmcall_io_write(port, value); ```
svsm
github_2023
others
515
coconut-svsm
Freax13
@@ -0,0 +1,206 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) Microsoft Corporation +// +// Author: Jon Lange <jlange@microsoft.com> + +use super::error::{tdx_result, TdxError}; +use crate::address::{Address, PhysAddr, VirtAddr}; +use crate::error::SvsmError; +use crate::mm::{virt_to_frame, Per...
Information about errors could still be useful for debugging. We could use the `debug_assert!` family of macros. These are only active in development mode and don't do anything in release mode.
svsm
github_2023
others
515
coconut-svsm
Freax13
@@ -0,0 +1,234 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) Microsoft Corporation +// +// Author: Jon Lange <jlange@microsoft.com> + +use super::error::{tdx_result, TdxError}; +use crate::address::{Address, PhysAddr, VirtAddr}; +use crate::error::SvsmError; +use crate::mm::pagetable::PageFram...
Out of curiosity, you've mentioned "gpa info" a couple of times, but I can't find this anywhere in the ABI spec. Where did you find this? ABI spec 1.0: ![image](https://github.com/user-attachments/assets/20cfdd38-bb4e-40d1-98de-276f00a3fba0) ABI spec 1.5: ![image](https://github.com/user-attachments/assets/cd28...
svsm
github_2023
others
515
coconut-svsm
Freax13
@@ -0,0 +1,234 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) Microsoft Corporation +// +// Author: Jon Lange <jlange@microsoft.com> + +use super::error::{tdx_result, TdxError}; +use crate::address::{Address, PhysAddr, VirtAddr}; +use crate::error::SvsmError; +use crate::mm::pagetable::PageFram...
```suggestion debug_assert_eq!(u64::from(frame.address()) & (frame.size() - 1) as u64, 0); ``` If the value is not `0`, it'd be useful to know what it was. What's the reasoning behind using `debug_assert!` rather than just `assert!`. Is see that we're already checking the alignment in `td_accept_physical_memo...
svsm
github_2023
others
515
coconut-svsm
Freax13
@@ -0,0 +1,234 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) Microsoft Corporation +// +// Author: Jon Lange <jlange@microsoft.com> + +use super::error::{tdx_result, TdxError}; +use crate::address::{Address, PhysAddr, VirtAddr}; +use crate::error::SvsmError; +use crate::mm::pagetable::PageFram...
Can we also check the alignment of `end`? This also applies to `td_accept_virtual_memory`.
svsm
github_2023
others
515
coconut-svsm
ereshetova
@@ -0,0 +1,268 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) Microsoft Corporation +// +// Author: Jon Lange <jlange@microsoft.com> + +use super::error::{tdx_result, TdxError}; +use crate::address::{Address, PhysAddr, VirtAddr}; +use crate::error::SvsmError; +use crate::mm::pagetable::PageFram...
What is the usecase to allow such behavior, i.e. why we don't treat PageAlreadyAccepted as a bug condition?
svsm
github_2023
others
514
coconut-svsm
cclaudio
@@ -1,6 +1,6 @@ -[submodule "libmstpm/deps/openssl"] - path = libmstpm/deps/openssl +[submodule "libvtcgtpm/deps/openssl"]
There seems to have a typo here (`v` not needed)
svsm
github_2023
others
415
coconut-svsm
stefano-garzarella
@@ -62,12 +62,24 @@ QEMU_MINOR=${QEMU_MINOR%%.$QEMU_BUILD} # The QEMU machine and memory command line changed after QEMU 8.2.0 from # the coconut-svsm git repository. -if (( (QEMU_MAJOR > 8) || ((QEMU_MAJOR == 8) && (QEMU_MINOR >= 2)) )); then +if (( QEMU_MAJOR >= 9 )); then + MACHINE=q35,confidential-guest-suppor...
I guess it's a left over. Can we remove this line (67)?
svsm
github_2023
others
415
coconut-svsm
stefano-garzarella
@@ -103,7 +115,8 @@ $SUDO_CMD \ -cpu EPYC-v4 \ -machine $MACHINE \ -object $MEMORY \ - -object sev-snp-guest,id=sev0,cbitpos=$C_BIT_POS,reduced-phys-bits=1,init-flags=5,igvm-file=$IGVM \ + -object sev-snp-guest,id=sev0,cbitpos=$C_BIT_POS,reduced-phys-bits=1$INIT_FLAGS$IGVM_FILE \
Not a strong opinion, but what about defining an `SEV_SNP_OBJECT` and assign it for each QEMU version, so it's a bit clear also for the reader the differences between the versions? I mean something like this: ``` if (( QEMU_MAJOR >= 9 )); then ... SEV_SNP_OBJECT="-object sev-snp-guest,id=sev0,cbitpos=$C_...
svsm
github_2023
others
455
coconut-svsm
joergroedel
@@ -431,5 +468,63 @@ global_asm!( ret "#, + // TODO: Replace this with a `const` operand once we upgrade the MSRV to 1.82. + CONTEXT_SWITCH_RESTORE_TOKEN = sym CONTEXT_SWITCH_RESTORE_TOKEN, options(att_syntax) ); + +/// The location of a shadow stack restore token that's mapped into every se...
There is another issue around the task-switch code which needs fixing, and that might help for shadow stacks as well. The problem currently is that the task-switch assembly is not safe against exceptions (like #HV and #NMI) that can occur at any time. The unsafe part come from the fact that the code can not switch p...
svsm
github_2023
others
455
coconut-svsm
msft-jlange
@@ -182,6 +201,15 @@ restart_hv: movq 2*8(%rsp), %rax movq %rax, -2*8(%rcx) leaq -4*8(%rcx), %rsp + .if CFG_SHADOW_STACKS + // Pop the current stack frame, so that the previous stack frame sits + // on top of the shadow stack. + cmpb $0, {IS_CET_SUPPORTED}(%rip) + je 2f + movq $3, %rax
Prefer `movl $3, %eax`. This instruction is 4 bytes shorter since it moves a 32-bit constant instead of a 64-bit constant, and since `rax` is a 64-bit extension of `eax`, the subsequent instruction will be guaranteed to observe the correct value.
svsm
github_2023
others
455
coconut-svsm
msft-jlange
@@ -100,6 +111,14 @@ asm_entry_hv: // RIP is in the return window, so update RIP to the cancel point. leaq switch_vmpl_cancel(%rip), %rbx movq %rbx, 0x20(%rsp) + .if CFG_SHADOW_STACKS + // Update RIP on the shadow stack to the cancel point. + cmpb $0, {IS_CET_SUPPORTED}(%rip) + je 2f + rdsspq %rax + ...
Prefer `wrssq` because it makes the operand size more explicit.
svsm
github_2023
others
455
coconut-svsm
msft-jlange
@@ -29,6 +29,17 @@ HV_DOORBELL_ADDR: pushq %r13 pushq %r14 pushq %r15 + pushq $0 + .if CFG_SHADOW_STACKS + cmpb $0, {IS_CET_SUPPORTED}(%rip) + je 2f + rdsspq %rax
RDSSPQ is in the NOP space so it will behave as a NOP if CET is not enabled. That means you can simplify this sequence to remove the jump by doing this instead: ``` xorl %eax, %eax // prefer the 32-bit form because it eliminates one instruction byte but has the same effect rdsspq %rax pushq %rax ```
svsm
github_2023
others
455
coconut-svsm
msft-jlange
@@ -29,6 +29,12 @@ HV_DOORBELL_ADDR: pushq %r13 pushq %r14 pushq %r15 + pushq $0 + # rdsspq is a nop when shadow stacks are not supported. Make sure that + # rax is 0 if that's the case. + xorl %eax, %eax + rdsspq %rax + push %rax
Prefer `pushq` so the size is explicit.
svsm
github_2023
others
455
coconut-svsm
msft-jlange
@@ -199,6 +231,12 @@ continue_hv: pushq %r13 pushq %r14 pushq %r15 + pushq $0 + # rdsspq is a nop when shadow stacks are not supported. Make sure that + # rdx is 0 if that's the case. + xorl %edx, %edx + rdsspq %rdx + push %rdx
Prefer `pushq` so the size is explicit.
svsm
github_2023
others
496
coconut-svsm
joergroedel
@@ -27,6 +27,10 @@ impl NativePlatform { pub fn new() -> Self { Self {} } + + pub fn halt() { + halt() + }
SNP and native use the same method, it is better to put this as the default implementation directly into the trait and avoid the duplication.
svsm
github_2023
others
496
coconut-svsm
joergroedel
@@ -481,6 +490,10 @@ fn panic(info: &PanicInfo<'_>) -> ! { loop { debug_break(); - halt(); + + // Use a platform-specific halt. However, the SVSM_PLATFORM global + // may not yet be initialized, so go choose the halt implementation + // based on the platform-specific halt in...
A general comment on the direction of the platform abstraction (not a change request to **this** PR): I don't like the way we are passing the platform abstraction around as a parameter. This is not the only instance, there are more examples of that in the code base. The platform type basically follows a singleton pa...
svsm
github_2023
others
496
coconut-svsm
Freax13
@@ -157,4 +157,12 @@ impl SvsmPlatformCell { SvsmPlatformCell::Tdp(platform) => platform, } } + + pub fn halt(platform_type: SvsmPlatformType) {
What's the reasoning behind making this a function on `SvsmPlatformCell`?
svsm
github_2023
others
460
coconut-svsm
msft-jlange
@@ -197,36 +197,28 @@ impl<T: ?Sized> DerefMut for PageBox<T> { impl<T: ?Sized> borrow::Borrow<T> for PageBox<T> { #[inline] fn borrow(&self) -> &T { - // SAFETY: this is part of the invariants of this type, as it must - // hold a pointer to valid memory for the given `T`. - unsafe { sel...
If this function doesn't require any manipulation of `self` before returning, then why keep the function body at all? I just tried an experiment where I completely removed the four functions you're touching here, and the compiler is perfectly happy, so it doesn't seem like we get any benefit from keeping functions tha...
svsm
github_2023
others
410
coconut-svsm
00xc
@@ -0,0 +1,80 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) 2024 SUSE LLC +// +// Author: Vasant Karasulli <vkarasulli@suse.de> + +use crate::cpu::control_regs::{cr0_sse_enable, cr4_osfxsr_enable, cr4_xsave_enable}; +use crate::cpu::cpuid::CpuidResult; +use core::arch::asm; +const CPUID_EDX_SS...
Perhaps this should be an error? ```suggestion log::error!("Legacy SSE instructions not supported by this hardware"); ```
svsm
github_2023
others
410
coconut-svsm
00xc
@@ -0,0 +1,80 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) 2024 SUSE LLC +// +// Author: Vasant Karasulli <vkarasulli@suse.de> + +use crate::cpu::control_regs::{cr0_sse_enable, cr4_osfxsr_enable, cr4_xsave_enable}; +use crate::cpu::cpuid::CpuidResult; +use core::arch::asm; +const CPUID_EDX_SS...
Rust has builtins for extended control register access, so these should work: ```suggestion use core::arch::x86_64::{_xgetbv, _xsetbv}; fn xcr0_set() { unsafe { // set bits [0-2] in XCR0 to enable extended SSE let xr0 = _xgetbv(0) | 0x7; _xsetbv(0, xr0); } } ```
svsm
github_2023
others
410
coconut-svsm
00xc
@@ -112,10 +113,15 @@ impl TaskSchedState { } } +// Layout of this struct is important. Offset of the members +// have to be kept the same. Add members to the end if necessary. #[repr(C)] pub struct Task { pub rsp: u64, + /// XSave area address for the task + pub xsa_addr: u64,
```suggestion pub xsa_addr: VirtAddr, ```
svsm
github_2023
others
410
coconut-svsm
00xc
@@ -0,0 +1,43 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) 2022-2024 SUSE LLC +// +// Author: Vasant Karasulli <vkarasulli@suse.de> + +use super::VirtualMapping; +use crate::address::PhysAddr; +use crate::error::SvsmError; +use crate::mm::alloc::allocate_file_page_ref; +use crate::mm::pagetab...
Any reason we're not using a regular page, i.e. `allocate_page()`?
svsm
github_2023
others
410
coconut-svsm
00xc
@@ -0,0 +1,80 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) 2024 SUSE LLC +// +// Author: Vasant Karasulli <vkarasulli@suse.de> + +use crate::cpu::control_regs::{cr0_sse_enable, cr4_osfxsr_enable, cr4_xsave_enable}; +use crate::cpu::cpuid::CpuidResult; +use core::arch::asm; +const CPUID_EDX_SS...
Same here, perhaps this should be an error. Also, can we continue operation without XSAVE?
svsm
github_2023
others
410
coconut-svsm
joergroedel
@@ -385,18 +385,33 @@ global_asm!( // Save the current stack pointer testq %rsi, %rsi jz 1f + + //set bits in edx:eax that correspond to SSE/FPU context + movq $0x7, %rax + xorq %rdx, %rdx + //rsi + 8 contains xsave area address + movq 8(%rsi...
Can this happen outside of the main task-switching assembly? The task switching code does not need FPU, so the context can be saved in a preparation state (using a helper method/function) and the new task can restore the content after the actual switch happened.
svsm
github_2023
others
410
coconut-svsm
joergroedel
@@ -0,0 +1,80 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) 2024 SUSE LLC +// +// Author: Vasant Karasulli <vkarasulli@suse.de> + +use crate::cpu::control_regs::{cr0_sse_enable, cr4_osfxsr_enable, cr4_xsave_enable}; +use crate::cpu::cpuid::CpuidResult; +use core::arch::asm; +const CPUID_EDX_SS...
We should cache the current value of XCR register in per-cpu and not read it every time we make a change.
svsm
github_2023
others
410
coconut-svsm
joergroedel
@@ -0,0 +1,80 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) 2024 SUSE LLC +// +// Author: Vasant Karasulli <vkarasulli@suse.de> + +use crate::cpu::control_regs::{cr0_sse_enable, cr4_osfxsr_enable, cr4_xsave_enable}; +use crate::cpu::cpuid::CpuidResult; +use core::arch::asm; +const CPUID_EDX_SS...
Can you please split the 7 up into individual bits we can OR together?
svsm
github_2023
others
410
coconut-svsm
joergroedel
@@ -0,0 +1,115 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) 2024 SUSE LLC +// +// Author: Vasant Karasulli <vkarasulli@suse.de> + +use crate::cpu::control_regs::{cr0_sse_enable, cr4_osfxsr_enable, cr4_xsave_enable}; +use crate::cpu::cpuid::cpuid_table_raw; +use core::arch::asm; +use core::arc...
This code needs to use the `cpuid` instruction directly to be compatible with the native and TD platform targets. I just realized there is no wrapper yet for `cpuid`, so please add one and use it for any FPU-related CPUID queries. This also affects other places in this PR.
svsm
github_2023
others
410
coconut-svsm
joergroedel
@@ -0,0 +1,115 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) 2024 SUSE LLC +// +// Author: Vasant Karasulli <vkarasulli@suse.de> + +use crate::cpu::control_regs::{cr0_sse_enable, cr4_osfxsr_enable, cr4_xsave_enable}; +use crate::cpu::cpuid::cpuid_table_raw; +use core::arch::asm; +use core::arc...
```suggestion if !extended_sse_supported() { panic!("Extended SSE is not supported by this hardware"); } if !xsave_supported() { panic!("XSAVE is not supported by this hardware"); } cr4_xsave_enable(); xcr0_set(); ``` Make the panic messages a bit more...
svsm
github_2023
others
410
coconut-svsm
joergroedel
@@ -298,6 +300,10 @@ unsafe fn task_pointer(taskptr: TaskPointer) -> *const Task { unsafe fn switch_to(prev: *const Task, next: *const Task) { let cr3: u64 = unsafe { (*next).page_table.lock().cr3_value().bits() as u64 }; + if !prev.is_null() { + sse_save_context(u64::from((*prev).xsa.vaddr())); + ...
This can happen in `schedule()`.
svsm
github_2023
others
410
coconut-svsm
joergroedel
@@ -361,8 +367,13 @@ pub fn schedule() { drop(guard); - // We're now in the context of the new task. If the previous task had terminated - // then we can release it's reference here. + // We're now in the context of the new task. + let cur = current_task(); + unsafe { + sse_restore_contex...
This needs to be moved into the `if let Some((current, next)) = work {` branch. Otherwise the code will load an old FPU context when no context switch is happening.
svsm
github_2023
others
410
coconut-svsm
joergroedel
@@ -501,8 +525,11 @@ fn setup_new_task() { } } -extern "C" fn run_kernel_task(entry: extern "C" fn()) { +extern "C" fn run_kernel_task(entry: extern "C" fn(), xsa_addr: u64) { setup_new_task(); + unsafe { + sse_restore_context(xsa_addr); + }
This needs to be in `setup_new_task()`.
svsm
github_2023
others
410
coconut-svsm
joergroedel
@@ -176,7 +184,9 @@ impl Task { let vm_kernel_range = VMR::new(SVSM_PERTASK_BASE, SVSM_PERTASK_END, PTEntryFlags::empty()); vm_kernel_range.initialize()?; - let (stack, raw_bounds, rsp_offset) = Self::allocate_ktask_stack(cpu, entry)?; + let xsa = Self::allocate_xsave_area(); + ...
The same needs to happen for user tasks.
svsm
github_2023
others
410
coconut-svsm
joergroedel
@@ -353,16 +355,20 @@ pub fn schedule() { unsafe { let a = task_pointer(current); let b = task_pointer(next); + sse_save_context(u64::from((*a).xsa.vaddr())); // Switch tasks switch_to(a, b); + + // We're now in the context of the new ...
The context needs to be loaded from `*b` instead of `*a`, no?
svsm
github_2023
others
485
coconut-svsm
Freax13
@@ -404,3 +404,21 @@ global_asm!( "#, options(att_syntax) ); + +#[repr(C)] +#[derive(Debug, Clone, Copy)] +pub enum IdtEventType { + Unknown = 0, + External, + Software,
Are the `External` and `Software` event types instantiated anywhere? I can't find any uses.
svsm
github_2023
others
485
coconut-svsm
Freax13
@@ -404,3 +404,21 @@ global_asm!( "#, options(att_syntax) ); + +#[repr(C)] +#[derive(Debug, Clone, Copy)] +pub enum IdtEventType { + Unknown = 0, + External, + Software, +} + +impl IdtEventType { + pub fn is_external_interrupt(&self, vector: usize) -> bool { + match self { + ...
```suggestion Self::Unknown => SVSM_PLATFORM.as_dyn_ref().is_external_interrupt(vector), ```
svsm
github_2023
others
485
coconut-svsm
Freax13
@@ -224,7 +224,16 @@ extern "C" fn ex_handler_vmm_communication(ctxt: &mut X86ExceptionContext, vecto // System Call SoftIRQ handler #[no_mangle] -extern "C" fn ex_handler_system_call(ctxt: &mut X86ExceptionContext) { +extern "C" fn ex_handler_system_call( + ctxt: &mut X86ExceptionContext, + vector: usize, + ...
```suggestion assert!(event_type.is_external_interrupt(vector), "Syscall handler invoked as external interrupt!"); ```
svsm
github_2023
others
485
coconut-svsm
Freax13
@@ -152,6 +152,19 @@ impl IrqState { pub fn count(&self) -> isize { self.count.load(Ordering::Relaxed) } + + /// Changes whether interrupts will be enabled when the nesting count + /// drops to zero. + /// + /// # Safety + /// + /// The caller must ensure that the current nesting co...
```suggestion assert_ne!(self.count.load(Ordering::Relaxed), 0); ```
svsm
github_2023
others
485
coconut-svsm
Freax13
@@ -114,12 +114,23 @@ impl SvsmPlatform for TdpPlatform { false } + fn use_interrupts(&self) -> bool { + true + } + fn post_irq(&self, _icr: u64) -> Result<(), SvsmError> { Err(SvsmError::Tdx) } fn eoi(&self) {} + fn is_external_interrupt(&self, _vector: usize...
Are you planning on implementing this in this PR or will this be done in a follow-up PR?
svsm
github_2023
others
485
coconut-svsm
Freax13
@@ -377,8 +377,14 @@ impl GHCB { let ghcb_address = VirtAddr::from(self as *const GHCB); let ghcb_pa = u64::from(virt_to_phys(ghcb_address)); + // Disable interrupts between writing the MSR and making the GHCB call + // to prevent reentrant use of the GHCB MSR. + let guard = Irq...
Should we move this guard to the top of the function and not drop it until the end? Guarding the MSR is one thing, we'll probably also want to protect the GHCB contents as well.
svsm
github_2023
others
485
coconut-svsm
p4zuu
@@ -224,7 +224,16 @@ extern "C" fn ex_handler_vmm_communication(ctxt: &mut X86ExceptionContext, vecto // System Call SoftIRQ handler #[no_mangle] -extern "C" fn ex_handler_system_call(ctxt: &mut X86ExceptionContext) { +extern "C" fn ex_handler_system_call( + ctxt: &mut X86ExceptionContext, + vector: usize, + ...
Why exactly handling an injected interrupt as a system call is a security issue? Making the kernel possibly `panic!()` in the system call handler still looks like a security issue to me, why can't we gracefully return?
svsm
github_2023
others
494
coconut-svsm
Freax13
@@ -108,8 +108,15 @@ impl SvsmPlatform for SnpPlatform { cpu.setup_ghcb() } - fn setup_percpu_current(&self, cpu: &PerCpu) -> Result<(), SvsmError> { + fn setup_percpu_current(&self, cpu: &PerCpu, is_bsp: bool) -> Result<(), SvsmError> {
Instead of adding a parameter here, we could also add a method `is_bsp(&self) -> bool` to `PerCpu`.
svsm
github_2023
others
419
coconut-svsm
joergroedel
@@ -83,7 +83,11 @@ pub trait SvsmPlatform { ) -> Result<(), SvsmError>; /// Marks a range of pages as valid for use as private pages. - fn validate_page_range(&self, region: MemoryRegion<VirtAddr>) -> Result<(), SvsmError>; + fn validate_page_range( + &self, + region: MemoryRegion<VirtAd...
This interface change puzzles me a bit. I imposes certain constraints on the method caller (like that the virtual region maps physically contiguous memory). At least the interface needs to be documented after that change. In general I think it is possible to get the physical address from within the method. Stage2 is i...
svsm
github_2023
others
419
coconut-svsm
joergroedel
@@ -440,6 +440,8 @@ pub extern "C" fn stage2_main(launch_info: &Stage2LaunchInfo) { // Shut down the GHCB shutdown_percpu(); + log::info!("Starting SVSM kernel...");
This needs to happen before `shutdown_percpu()`, otherwise it crashes on SNP. The `shutdown_percpu()` function also shuts down the GHCB on SNP which is required for serial port access, and as a consequence also to print any log messages.
svsm
github_2023
others
419
coconut-svsm
msft-jlange
@@ -52,6 +55,33 @@ impl IOPort for SVSMIOPort { } } +#[derive(Clone, Copy, Debug, Default)] +pub struct SvsmTdIOPort {}
Can we not just change `SVSMIOPort` to use IN and OUT instructions natively, and then have the #VC handler issue GHCB calls and the #VE handler issue GHCI calls? This seems like it would be much cleaner because it restricts platform-specific functionality to code paths that are already platform-specific (exception han...
svsm
github_2023
others
419
coconut-svsm
msft-jlange
@@ -215,7 +215,7 @@ impl WriteLockGuard<'static, IDT> { /// Load an IDT. Its lifetime must be static so that its entries are /// always available to the CPU. pub fn load(&self) { - let desc: IdtDesc = IdtDesc { + let desc = IdtDesc {
What's the reason for this change? Is this related to TDP?
svsm
github_2023
others
419
coconut-svsm
msft-jlange
@@ -173,7 +173,7 @@ pub mod svsm_gdbstub { static GDB_INITIALISED: AtomicBool = AtomicBool::new(false); static GDB_STATE: SpinLock<Option<SvsmGdbStub<'_>>> = SpinLock::new(None); - static GDB_IO: SVSMIOPort = SVSMIOPort::new(); + static GDB_IO: SvsmSevIOPort = SvsmSevIOPort::new();
Isn't this going to be problematic when we finally make GDB work on TDP? Wouldn't it be better to define a platform abstraction now since you are already forced to touch this code?
svsm
github_2023
others
419
coconut-svsm
msft-jlange
@@ -611,9 +647,9 @@ impl PageTable { /// - `vaddr': The virtual address to transalte. /// /// # Returns - /// Some(PhysAddr) if the virtual address is valid. + /// Some(PageFrame) if the virtual address is valid. /// None if the virtual address is not valid. - pub fn virt_to_phys(vaddr: Vir...
For consistency, this function should be renamed `virt_to_frame` because it returns a `PageFrame` and not a `PhysAddr`.
svsm
github_2023
others
419
coconut-svsm
msft-jlange
@@ -450,6 +450,42 @@ pub enum Mapping<'a> { Level0(&'a mut PTEntry), } +/// A physical address within a page frame +#[derive(Debug)] +pub enum PageFrame { + Size4K(PhysAddr), + Size2M(PhysAddr), + Size1G(PhysAddr), +} + +impl PageFrame { + pub fn address(&self) -> PhysAddr { + match *self { +...
```suggestion match self { Self::Size4K(_) => PageSize::Regular, Self::Size2M(_) => PageSize::Huge, Self::Size1G(_) => PageSize::Huge1G, }.into() ``` Note that you don't need an explicit dereference of `self` (the compiler will do that for you) and you can us...
svsm
github_2023
others
419
coconut-svsm
msft-jlange
@@ -611,9 +647,9 @@ impl PageTable { /// - `vaddr': The virtual address to transalte.
Since you're fixing some of my other typos, it would be great if you could change `transalte` to `translate` while you're at it.
svsm
github_2023
others
419
coconut-svsm
msft-jlange
@@ -9,20 +9,24 @@ use crate::sev::vmsa::VMPL_MAX; pub const PAGE_SHIFT: usize = 12; pub const PAGE_SHIFT_2M: usize = 21; +pub const PAGE_SHIFT_1G: usize = 30; pub const PAGE_SIZE: usize = 1 << PAGE_SHIFT; -pub const PAGE_SIZE_2M: usize = PAGE_SIZE * 512; +pub const PAGE_SIZE_2M: usize = 1 << PAGE_SHIFT_2M; +pub co...
Is this really necessary? Given that SNP does not support 1 GB pages, I don't believe COCONUT-SVSM will ever attempt to make any use of them, and thus this size will never be meaningful.
svsm
github_2023
others
492
coconut-svsm
Freax13
@@ -173,6 +172,8 @@ pub fn request_loop() { flush_tlb_global_sync(); switch_to_vmpl(GUEST_VMPL as u32); + + drop(guard);
This line isn't needed, but if your goal is to be explicit about this, I'm also fine with leaving this as is.
svsm
github_2023
others
480
coconut-svsm
Freax13
@@ -6,43 +6,64 @@ use bitfield_struct::bitfield; +#[derive(Clone, Copy, Debug, PartialEq)] +#[allow(dead_code, non_camel_case_types)]
```suggestion #[allow(dead_code)] ```
svsm
github_2023
others
480
coconut-svsm
Freax13
@@ -6,43 +6,64 @@ use bitfield_struct::bitfield; +#[derive(Clone, Copy, Debug, PartialEq)] +#[allow(dead_code, non_camel_case_types)] +pub struct GuestVMExit(u64); + +macro_rules! guest_vmexits { + ( + $( + ($exit:ident, $value:expr); + )+ + ) => { + impl GuestVMExit { + ...
I'm not sure if we need to use a macro for this. I get that the macro makes the code a bit less verbose, but it also makes it less obvious that there is nothing else going on. I could understand the need for the macro if we also used it to generate a prettier `Debug` implementation.
svsm
github_2023
others
480
coconut-svsm
Freax13
@@ -6,43 +6,50 @@ use bitfield_struct::bitfield; +#[derive(Clone, Copy, Debug, PartialEq)] +#[allow(dead_code)] +pub struct GuestVMExit(u64);
```suggestion #[repr(transparent)] pub struct GuestVMExit(u64); ```
svsm
github_2023
others
473
coconut-svsm
Freax13
@@ -0,0 +1,20 @@ +// SPDX-License-Identifier: MIT +// +// Copyright (c) 2024 SUSE LLC +// +// Authors: Thomas Leroy <tleroy@suse.de> + +.code64 + +.section .text +.macro asm_clac + .if CFG_SMAP + .byte 0x0f, 0x01, 0xca
Here and elsewhere: ```suggestion clac ``` Is there a reason we need to use directives?
svsm
github_2023
others
473
coconut-svsm
Freax13
@@ -0,0 +1,27 @@ +// SPDX-License-Identifier: MIT +// +// Copyright (c) 2024 SUSE LLC +// +// Authors: Thomas Leroy <tleroy@suse.de> + +use core::arch::asm; + +/// Clears RFLAGS.AC to enable SMAP. +/// This is currently only used when SMAP is supported and enabled. +/// SMAP protection is effective only if CR4.SMAP is ...
```suggestion unsafe { asm!("clac", options(att_syntax, nomem, nostack, preserves_flags)) } ``` [Inline assembly](https://doc.rust-lang.org/reference/inline-assembly.html) may touch the `AC` flag if the `preserves_flags` is set.
svsm
github_2023
others
473
coconut-svsm
cxdong
@@ -45,7 +47,16 @@ pub const HV_VECTOR: usize = 28; pub const VC_VECTOR: usize = 29; pub const SX_VECTOR: usize = 30; -pub const PF_ERROR_WRITE: usize = 2; +bitflags! { + #[repr(transparent)] + #[derive(Copy, Clone, Debug, PartialEq)] + pub struct PFErrors: usize { + const PROT = 1 << 0; + co...
It appears that `PFError` has the similar error flags with the `PageFaultError` within this file. It might be beneficial to consider merging the two for consistency and to reduce redundancy?
svsm
github_2023
others
412
coconut-svsm
msft-jlange
@@ -249,6 +249,8 @@ impl LocalApic { Some(calling_area) } + /// Attempts to deliver the specified IRQ into the specified guest CPU
We should distinguish this from queueing an interrupt. The key here is that this function attempts to deliver the specified interrupt so it will be observed immediately upon the next guest entry, and will fail if the guest state is such that interrupt delivery would need to be deferred (e.g. due to disabled interrupts...
svsm
github_2023
others
472
coconut-svsm
roy-hopkins
@@ -64,6 +64,10 @@ pub struct CmdOptions { #[arg(long, default_value_t = false)] pub native: bool, + /// Includ VSM isolation platform target.
Typo: "Includ"
svsm
github_2023
others
472
coconut-svsm
roy-hopkins
@@ -52,56 +176,105 @@ pub fn construct_vmsa( let mut vmsa_box = SevVmsa::new_box_zeroed(); let vmsa = vmsa_box.as_mut(); - // Copy GPRs. - vmsa.rax = context.rax; - vmsa.rcx = context.rcx; - vmsa.rdx = context.rdx; - vmsa.rbx = context.rbx; - vmsa.rsp = context.rsp; - vmsa.rbp = context...
These two have been mixed up - Idtr sets gdtr and vise versa.
svsm
github_2023
others
472
coconut-svsm
roy-hopkins
@@ -52,56 +176,105 @@ pub fn construct_vmsa( let mut vmsa_box = SevVmsa::new_box_zeroed(); let vmsa = vmsa_box.as_mut(); - // Copy GPRs. - vmsa.rax = context.rax; - vmsa.rcx = context.rcx; - vmsa.rdx = context.rdx; - vmsa.rbx = context.rbx; - vmsa.rsp = context.rsp; - vmsa.rbp = context...
No rdi?
svsm
github_2023
others
472
coconut-svsm
roy-hopkins
@@ -4,46 +4,170 @@ // // Author: Roy Hopkins <roy.hopkins@suse.com> -use igvm::snp_defs::{SevFeatures, SevVmsa}; +use igvm::registers::{SegmentRegister, X86Register}; +use igvm::snp_defs::{SevFeatures, SevSelector, SevVmsa}; use igvm::IgvmDirectiveHeader; use igvm_defs::IgvmNativeVpContextX64; use zerocopy::From...
No rdi?
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) -> PTEntry { + unsafe { *vaddr.as_ptr::<PTEn...
```suggestion /// Read a page table entry from the specified virtual address. pub unsafe fn read_pte(vaddr: VirtAddr) -> Self { unsafe { *vaddr.as_ptr::<Self>() } } ```
svsm
github_2023
others
461
coconut-svsm
Freax13
@@ -457,14 +463,28 @@ impl PageTable { virt_to_phys(pgtable) } + /// Initializes the self-map pointer within the page table. + pub fn set_self_map(&mut self, paddr: PhysAddr) {
```suggestion pub unsafe fn set_self_map(&mut self, paddr: PhysAddr) { ```