Skip to content

Commit

Permalink
Merge pull request coconut-svsm#545 from msft-jlange/safety
Browse files Browse the repository at this point in the history
hyperv: fix safety comments
  • Loading branch information
joergroedel authored Dec 3, 2024
2 parents e5c23c8 + c258b67 commit 73ca08b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion kernel/src/cpu/percpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ impl PerCpu {
// to ensure that only a single reference can ever be taken at a time.
let page_ref: RefMut<'_, Option<(VirtPhysPair, VirtPhysPair)>> =
self.hypercall_pages.borrow_mut();
// SAFETY - the virtual addresses were allocated when the hypercall
// SAFETY: the virtual addresses were allocated when the hypercall
// pages were configured, and the physical addresses were captured at
// that time.
unsafe { HypercallPagesGuard::new(RefMut::map(page_ref, |o| o.as_mut().unwrap())) }
Expand Down
14 changes: 7 additions & 7 deletions kernel/src/hyperv/hv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl<'a> HypercallPagesGuard<'a> {
fn hypercall_input<H>(&mut self) -> &mut H {
let header = self.input.vaddr.as_mut_ptr::<H>();
assert!(size_of::<H>() <= PAGE_SIZE);
// SAFETY - the virtual address represents an entire page which is
// SAFETY: the virtual address represents an entire page which is
// exclusively owned by the `HypercallPagesGuard` and can safely be
// cast to a header of type `H`.
unsafe { &mut *header }
Expand All @@ -93,7 +93,7 @@ impl<'a> HypercallPagesGuard<'a> {
let rep_count = (PAGE_SIZE - header_size) / size_of::<T>();
let header = self.input.vaddr.as_mut_ptr::<H>();
let rep_slice = self.input.vaddr.const_add(header_size).as_mut_ptr::<T>();
// SAFETY - the virtual address represents an entire page which is
// SAFETY: the virtual address represents an entire page which is
// exclusively owned by the `HypercallPagesGuard` and can safely be
// cast to a header of type `H` followed by an array of `T` up to the
// size of one page.
Expand All @@ -116,7 +116,7 @@ impl<'a> HypercallPagesGuard<'a> {
1
};
assert!(count * size_of::<T>() <= PAGE_SIZE);
// SAFETY - the virtual address represents an entire page which is
// SAFETY: the virtual address represents an entire page which is
// exclusively owned by the `HypercallPagesGuard` and can safely be
// cast to an array of `T` up to the size of one page.
unsafe { slice::from_raw_parts(self.output.vaddr.as_ptr::<T>(), count) }
Expand Down Expand Up @@ -219,7 +219,7 @@ unsafe fn hypercall(
) -> HvHypercallOutput {
let hypercall_va = u64::from(*HYPERV_HYPERCALL_CODE_PAGE);
let mut output: u64;
// SAFETY - inline assembly is required to invoke the hypercall.
// SAFETY: inline assembly is required to invoke the hypercall.
unsafe {
asm!("callq *%rax",
in("rax") hypercall_va,
Expand Down Expand Up @@ -261,7 +261,7 @@ pub fn get_vp_register(name: hyperv::HvRegisterName) -> Result<u64, SvsmError> {
*header = input_header;
slice[0] = name as u32;

// SAFETY - the GetVpRegisters hypercall does not write to any memory other
// SAFETY: the GetVpRegisters hypercall does not write to any memory other
// than the hypercall page, and does not consume memory that is not
// included in the hypercall input.
let call_output = unsafe { hypercall(input_control, &hypercall_pages) };
Expand Down Expand Up @@ -307,7 +307,7 @@ fn enable_vp_vtl_hypercall(
let header = hypercall_pages.hypercall_input::<HvInputEnableVpVtl>();
*header = input_header;

// SAFETY - the EnableVpVtl hypercall does not write to any memory and
// SAFETY: the EnableVpVtl hypercall does not write to any memory and
// does not consume memory that is not included in the hypercall input.
let call_output = unsafe { hypercall(input_control, &hypercall_pages) };
let status = call_output.status();
Expand Down Expand Up @@ -348,7 +348,7 @@ fn start_vp_hypercall(
let header = hypercall_pages.hypercall_input::<HvInputStartVirtualProcessor>();
*header = input_header;

// SAFETY - the StartVp hypercall does not write to any memory and does not
// SAFETY: the StartVp hypercall does not write to any memory and does not
// consume memory that is not included in the hypercall input.
let call_output = unsafe { hypercall(input_control, &hypercall_pages) };
let status = call_output.status();
Expand Down

0 comments on commit 73ca08b

Please sign in to comment.