Skip to content

Commit 669ee36

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 46da056 commit 669ee36

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/vmm/src/linux/vstate.rs

Lines changed: 18 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};
@@ -76,6 +78,9 @@ pub enum Error {
7678
GuestMSRs(arch::x86_64::msr::Error),
7779
/// Hyperthreading flag is not initialized.
7880
HTNotInitialized,
81+
/// Unable to enable KVM hypercall exits.
82+
#[cfg(feature = "tee")]
83+
HypercallExitEnable(kvm_ioctls::Error),
7984
/// Cannot configure the IRQ.
8085
Irq(kvm_ioctls::Error),
8186
/// 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
}
@@ -470,6 +477,8 @@ impl Vm {
470477

471478
#[cfg(feature = "amd-sev")]
472479
pub fn new(kvm: &Kvm, tee_config: &TeeConfig) -> Result<Self> {
480+
use crate::vstate::Error::*;
481+
473482
//create fd for interacting with kvm-vm specific functions
474483
let vm_fd = kvm
475484
.create_vm_with_type(4 /* KVM_X86_SNP_VM */)
@@ -482,6 +491,15 @@ impl Vm {
482491
let supported_msrs =
483492
arch::x86_64::msr::supported_guest_msrs(kvm).map_err(Error::GuestMSRs)?;
484493

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

0 commit comments

Comments
 (0)