Skip to content

Commit

Permalink
cpu/vc Add #VC handler tests
Browse files Browse the repository at this point in the history
Adds tests that make sure a #VC exception is raised while executing
various instructions and that the #VC handler properly handles them via
the ghcb.

Adds tests for cpuid, msrs, port IO, MMIO, wbinvd, rdtsc, dr7, and vmmcall.

Relies on being able to run tests inside the guest VM, e.g. with PR coconut-svsm#120.

The #VC handler is not yet implemented, so these tests are all marked
with #[should_panic]. See PR coconut-svsm#55 for progress on its implementation.

TODO:
Remove added dependencies
Move the tests to vc.rs or a new file
Clean up comments, etc.
Move assembly wrapper helper functions to more sensible places
Implement page state change (PSC) test

Signed-off-by: Adam Dunlap <acdunlap@google.com>
  • Loading branch information
AdamCDunlap committed Oct 27, 2023
1 parent 4798647 commit 80af84a
Show file tree
Hide file tree
Showing 5 changed files with 438 additions and 2 deletions.
37 changes: 37 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ gdbstub_arch = { version = "0.2.4", optional = true }
intrusive-collections = "0.9.6"
log = { version = "0.4.17", features = ["max_level_info", "release_max_level_info"] }
packit = { git = "https://github.com/coconut-svsm/packit", version = "0.1.0" }
x86 = "0.52.0"
raw-cpuid = "11.0"

[target."x86_64-unknown-none".dev-dependencies]
test = { version = "0.1.0", path = "test" }
Expand Down
23 changes: 23 additions & 0 deletions src/cpu/msr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,29 @@ pub fn rdtsc() -> u64 {
(eax as u64) | (edx as u64) << 32
}

pub struct RdtscpOut {
pub timestamp: u64,
pub pid: u32,
}

pub fn rdtscp() -> RdtscpOut {
let eax: u32;
let edx: u32;
let ecx: u32;

unsafe {
asm!("rdtsc",
out("eax") eax,
out("ecx") ecx,
out("edx") edx,
options(att_syntax, nomem, nostack));
}
RdtscpOut {
timestamp: (eax as u64) | (edx as u64) << 32,
pid: ecx,
}
}

pub fn read_flags() -> u64 {
let rax: u64;
unsafe {
Expand Down
Loading

0 comments on commit 80af84a

Please sign in to comment.