microsoft/openvmm

Public

mirrored fromhttps://github.com/microsoft/openvmmAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
f98aebb2e0ca8cbef1204344b8537eecdc2869f6

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

openhcl/get_lower_vtl/src/lib.rs

43lines · modecode

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4#![cfg(target_os = "linux")]
5
6//! This is an implementation of [`virt::VtlMemoryProtection`] that uses the
7//! [`hcl::ioctl::MshvHvcall`] type. This is only to be used for the GET, as we
8//! cannot use the normal partition implementation in OpenHCL due to ordering
9//! requirements for struct initialization.
10
11use anyhow::Context;
12use anyhow::Result;
13use hvdef::hypercall::HvInputVtl;
14use inspect::Inspect;
15use memory_range::MemoryRange;
16use std::sync::Arc;
17use virt::VtlMemoryProtection;
18
19#[derive(Inspect)]
20pub struct GetLowerVtl {
21 #[inspect(skip)]
22 mshv_hvcall: hcl::ioctl::MshvHvcall,
23}
24
25impl GetLowerVtl {
26 pub fn new() -> Result<Arc<Self>> {
27 let mshv_hvcall = hcl::ioctl::MshvHvcall::new().context("failed to open mshv_hvcall")?;
28 mshv_hvcall.set_allowed_hypercalls(&[hvdef::HypercallCode::HvCallModifyVtlProtectionMask]);
29 Ok(Arc::new(Self { mshv_hvcall }))
30 }
31}
32
33impl VtlMemoryProtection for GetLowerVtl {
34 fn modify_vtl_page_setting(&self, pfn: u64, flags: hvdef::HvMapGpaFlags) -> Result<()> {
35 self.mshv_hvcall
36 .modify_vtl_protection_mask(
37 MemoryRange::from_4k_gpn_range(pfn..pfn + 1),
38 flags,
39 HvInputVtl::CURRENT_VTL,
40 )
41 .context("failed to modify VTL page permissions")
42 }
43}
44