Skip to content

Commit 5ac1442

Browse files
committed
uffd: unconditionally enable UFFD_FEATURE_EVENT_REMOVE
Only enabling it when a balloon device is present doesn't really gain us anything, because the only time this feature is checked in the kernel is as part of madvise handling - but without balloon devices we wont ever call madvise, so it makes no difference whether we enabled the feature or not (it is unconditionally available since linux 4.10). Signed-off-by: Patrick Roy <[email protected]>
1 parent 85188a9 commit 5ac1442

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

src/vmm/src/persist.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -393,9 +393,6 @@ pub fn restore_from_snapshot(
393393
mem_backend_path,
394394
mem_state,
395395
track_dirty_pages,
396-
// We enable the UFFD_FEATURE_EVENT_REMOVE feature only if a balloon device
397-
// is present in the microVM state.
398-
microvm_state.device_states.balloon_device.is_some(),
399396
vm_resources.machine_config.huge_pages,
400397
)
401398
.map_err(RestoreFromSnapshotGuestMemoryError::Uffd)?,
@@ -479,19 +476,18 @@ fn guest_memory_from_uffd(
479476
mem_uds_path: &Path,
480477
mem_state: &GuestMemoryState,
481478
track_dirty_pages: bool,
482-
enable_balloon: bool,
483479
huge_pages: HugePageConfig,
484480
) -> Result<(Vec<GuestRegionMmap>, Option<Uffd>), GuestMemoryFromUffdError> {
485481
let (guest_memory, backend_mappings) =
486482
create_guest_memory(mem_state, track_dirty_pages, huge_pages)?;
487483

488484
let mut uffd_builder = UffdBuilder::new();
489485

490-
if enable_balloon {
491-
// We enable this so that the page fault handler can add logic
492-
// for treating madvise(MADV_DONTNEED) events triggerd by balloon inflation.
493-
uffd_builder.require_features(FeatureFlags::EVENT_REMOVE);
494-
}
486+
// We only make use of this if balloon devices are present, but we can enable it unconditionally
487+
// because the only place the kernel checks this is in a hook from madvise, e.g. it doesn't
488+
// actively change the behavior of UFFD, only passively. Without balloon devices
489+
// we never call madvise anyway, so no need to put this into a conditional.
490+
uffd_builder.require_features(FeatureFlags::EVENT_REMOVE);
495491

496492
let uffd = uffd_builder
497493
.close_on_exec(true)

0 commit comments

Comments
 (0)