hypervisor: kvm: Punch holes in guest_memfd on shared transition

When an SEV-SNP guest transitions pages from private to shared via
KVM_HC_MAP_GPA_RANGE, punch holes in the corresponding guest_memfd
backing it. Without this the balloon driver's `set_memory_decrypted()`
path transitions the page attributes but the physical memory stays
pinned in guest_memfd, making virtio-balloon ineffective for memory
overcommit with confidential VMs. Even without ballooning these pages
are unused by the guest so consume resources. This mirrors the hole
punching that the balloon device does for releasing pages.

The memory_slots Arc is cloned into each KvmVcpu at creation so the
punch can happen in the vcpu thread.

Assisted-by: Claude:claude-opus-4-6
Signed-off-by: Rob Bradford <rbradford@meta.com>
This commit is contained in:
Rob Bradford
2026-05-07 17:01:27 +01:00
parent ebeef03192
commit 49259bb84f
2 changed files with 73 additions and 6 deletions

View File

@@ -881,6 +881,15 @@ fn vcpu_thread_rules(
(libc::SYS_dup, vec![]),
(libc::SYS_exit, vec![]),
(libc::SYS_epoll_ctl, vec![]),
(
libc::SYS_fallocate,
or![and![Cond::new(
1,
ArgLen::Dword,
Eq,
(libc::FALLOC_FL_PUNCH_HOLE | libc::FALLOC_FL_KEEP_SIZE) as u64,
)?]],
),
(libc::SYS_fcntl, vec![]),
(libc::SYS_fstat, vec![]),
(libc::SYS_futex, vec![]),