Skip to content

Commit 3940ee2

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 e6800b3 commit 3940ee2

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
@@ -45,6 +45,8 @@ use kvm_bindings::{
4545
kvm_userspace_memory_region2, KVM_API_VERSION, KVM_MEMORY_ATTRIBUTE_PRIVATE,
4646
KVM_MEM_GUEST_MEMFD,
4747
};
48+
#[cfg(feature = "tee")]
49+
use kvm_bindings::{kvm_enable_cap, KVM_CAP_EXIT_HYPERCALL};
4850
use kvm_ioctls::{Cap::*, *};
4951
use utils::eventfd::EventFd;
5052
use utils::signal::{register_signal_handler, sigrtmin, Killable};
@@ -78,6 +80,9 @@ pub enum Error {
7880
GuestMSRs(arch::x86_64::msr::Error),
7981
/// Hyperthreading flag is not initialized.
8082
HTNotInitialized,
83+
/// Unable to enable KVM hypercall exits.
84+
#[cfg(feature = "tee")]
85+
HypercallExitEnable(kvm_ioctls::Error),
8186
/// Cannot configure the IRQ.
8287
Irq(kvm_ioctls::Error),
8388
/// The host kernel reports an invalid KVM API version.
@@ -240,6 +245,8 @@ impl Display for Error {
240245
#[cfg(target_arch = "x86_64")]
241246
GuestMSRs(e) => write!(f, "Retrieving supported guest MSRs fails: {e:?}"),
242247
HTNotInitialized => write!(f, "Hyperthreading flag is not initialized"),
248+
#[cfg(feature = "tee")]
249+
HypercallExitEnable(e) => write!(f, "Unable to enable KVM hypercall exits: {e}"),
243250
KvmApiVersion(v) => {
244251
write!(f, "The host kernel reports an invalid KVM API version: {v}")
245252
}
@@ -482,6 +489,15 @@ impl Vm {
482489
let supported_msrs =
483490
arch::x86_64::msr::supported_guest_msrs(kvm).map_err(Error::GuestMSRs)?;
484491

492+
let cap = kvm_enable_cap {
493+
cap: KVM_CAP_EXIT_HYPERCALL,
494+
flags: 0,
495+
args: [1 << 12 /* KVM_HC_MAP_GPA_RANGE */, 0, 0, 0],
496+
..Default::default()
497+
};
498+
499+
vm_fd.enable_cap(&cap).map_err(Error::HypercallExitEnable)?;
500+
485501
let tee = match tee_config.tee {
486502
Tee::Snp => Some(AmdSnp::new().map_err(Error::SnpSecVirtInit)?),
487503
_ => return Err(Error::InvalidTee),

0 commit comments

Comments
 (0)