Skip to content

Commit e215b5f

Browse files
committed
amd-sev: Enable KVM_EXIT_HYPERCALL for SEV-SNP guests
SEV-SNP guests use KVM_EXIT_HYPERCALL to signal to the hypervisor that they would like some memory shared or private. Enable the KVM capability to allow the guests to use KVM_EXIT_HYPERCALL. Signed-off-by: Tyler Fanelli <[email protected]>
1 parent 006a6f7 commit e215b5f

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/vmm/src/linux/vstate.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ use kvm_bindings::{
4949
kvm_userspace_memory_region2, KVM_API_VERSION, KVM_MEMORY_ATTRIBUTE_PRIVATE,
5050
KVM_MEM_GUEST_MEMFD,
5151
};
52+
#[cfg(feature = "tee")]
53+
use kvm_bindings::{kvm_enable_cap, KVM_CAP_EXIT_HYPERCALL};
5254
use kvm_ioctls::{Cap::*, *};
5355
use utils::eventfd::EventFd;
5456
use utils::signal::{register_signal_handler, sigrtmin, Killable};
@@ -82,6 +84,9 @@ pub enum Error {
8284
GuestMSRs(arch::x86_64::msr::Error),
8385
/// Hyperthreading flag is not initialized.
8486
HTNotInitialized,
87+
/// Unable to enable KVM hypercall exits.
88+
#[cfg(feature = "tee")]
89+
HypercallExitEnable(kvm_ioctls::Error),
8590
/// Cannot configure the IRQ.
8691
Irq(kvm_ioctls::Error),
8792
/// The host kernel reports an invalid KVM API version.
@@ -244,6 +249,8 @@ impl Display for Error {
244249
#[cfg(target_arch = "x86_64")]
245250
GuestMSRs(e) => write!(f, "Retrieving supported guest MSRs fails: {e:?}"),
246251
HTNotInitialized => write!(f, "Hyperthreading flag is not initialized"),
252+
#[cfg(feature = "tee")]
253+
HypercallExitEnable(e) => write!(f, "Unable to enable KVM hypercall exits: {e}"),
247254
KvmApiVersion(v) => {
248255
write!(f, "The host kernel reports an invalid KVM API version: {v}")
249256
}
@@ -486,6 +493,15 @@ impl Vm {
486493
let supported_msrs =
487494
arch::x86_64::msr::supported_guest_msrs(kvm).map_err(Error::GuestMSRs)?;
488495

496+
let cap = kvm_enable_cap {
497+
cap: KVM_CAP_EXIT_HYPERCALL,
498+
flags: 0,
499+
args: [1 << 12 /* KVM_HC_MAP_GPA_RANGE */, 0, 0, 0],
500+
..Default::default()
501+
};
502+
503+
vm_fd.enable_cap(&cap).map_err(Error::HypercallExitEnable)?;
504+
489505
let tee = match tee_config.tee {
490506
Tee::Snp => Some(AmdSnp::new().map_err(Error::SnpSecVirtInit)?),
491507
_ => return Err(Error::InvalidTee),

0 commit comments

Comments
 (0)