Skip to content

Commit 4a3fdde

Browse files
committed
vmm/linux/tee: Handle KVM_EXIT_MEMORY_FAULT exits
Like KVM_EXIT_HYPERCALL, KVM_EXIT_MEMORY_FAULT is used by SEV-SNP guests to set memory regions to private or shared. Allow vCPUs encountering a KVM_EXIT_MEMORY_FAULT to re-use the shared/private memory handler used by KVM_EXIT_HYPERCALL to set regions to private or shared. Co-developed-by: Matias Ezequiel Vara Larsen <mvaralar@redhat.com> Signed-off-by: Tyler Fanelli <tfanelli@redhat.com>
1 parent c941efd commit 4a3fdde

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/vmm/src/linux/vstate.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ use kvm_bindings::{
4545
KVM_MEM_GUEST_MEMFD,
4646
};
4747
#[cfg(feature = "tee")]
48-
use kvm_bindings::{kvm_enable_cap, KVM_CAP_EXIT_HYPERCALL};
48+
use kvm_bindings::{kvm_enable_cap, KVM_CAP_EXIT_HYPERCALL, KVM_MEMORY_EXIT_FLAG_PRIVATE};
4949
use kvm_ioctls::{Cap::*, *};
5050
use utils::eventfd::EventFd;
5151
use utils::signal::{register_signal_handler, sigrtmin, Killable};
@@ -1238,6 +1238,17 @@ impl Vcpu {
12381238
self.io_bus.write(0, u64::from(addr), data);
12391239
Ok(VcpuEmulation::Handled)
12401240
}
1241+
#[cfg(feature = "tee")]
1242+
VcpuExit::MemoryFault { gpa, size, flags } => {
1243+
let private = (flags & (KVM_MEMORY_EXIT_FLAG_PRIVATE as u64)) != 0;
1244+
1245+
let mem_properties = MemoryProperties { gpa, size, private };
1246+
1247+
self.pm_sender.0.send(mem_properties).unwrap();
1248+
let _ = self.pm_sender.1.read().unwrap();
1249+
1250+
Ok(VcpuEmulation::Handled)
1251+
}
12411252
VcpuExit::MmioRead(addr, data) => {
12421253
if let Some(ref mmio_bus) = self.mmio_bus {
12431254
mmio_bus.read(0, addr, data);

0 commit comments

Comments
 (0)