From 25b6def2273aec5b33a94587f5d1c9dca4cf23d1 Mon Sep 17 00:00:00 2001 From: Nikita Kalyazin Date: Wed, 26 Mar 2025 17:15:05 +0000 Subject: [PATCH] fix(vmm/persist): do not close uffd socket We prevent Rust from closing the socket file descriptor to avoid a potential race condition between the mappings message and the connection shutdown. If the latter arrives at the UFFD handler first, the handler never sees the mappings. Signed-off-by: Nikita Kalyazin --- CHANGELOG.md | 4 ++++ src/vmm/src/persist.rs | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ed5a75ef72..0fc97cac00f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,6 +44,10 @@ and this project adheres to the `SendCtrlAltDel` command not working for ACPI-enabled guest kernels, by dropping the i8042.nopnp argument from the default kernel command line Firecracker constructs. +- [#5122](https://github.com/firecracker-microvm/firecracker/pull/5122): Keep + the UFFD Unix domain socket open to prevent the race condition between the + guest memory mappings message and the shutdown event that was sometimes + causing arrival of an empty message on the UFFD handler side. ## [1.11.0] diff --git a/src/vmm/src/persist.rs b/src/vmm/src/persist.rs index 3ffc4355f0b..067cb51896b 100644 --- a/src/vmm/src/persist.rs +++ b/src/vmm/src/persist.rs @@ -6,6 +6,7 @@ use std::fmt::Debug; use std::fs::{File, OpenOptions}; use std::io::{self, Write}; +use std::mem::forget; use std::os::unix::io::AsRawFd; use std::os::unix::net::UnixStream; use std::path::Path; @@ -657,6 +658,11 @@ fn send_uffd_handshake( uffd.as_raw_fd(), )?; + // We prevent Rust from closing the socket file descriptor to avoid a potential race condition + // between the mappings message and the connection shutdown. If the latter arrives at the UFFD + // handler first, the handler never sees the mappings. + forget(socket); + Ok(()) }