Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .buildkite/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def run_all_tests(changed_files):
return not changed_files or any(
x.suffix != ".md"
and not (x.parts[0] == ".github" and x.suffix == ".yml")
and x.parts[1] != "hiding_ci"
and (len(x.parts) < 2 or x.parts[1] != "hiding_ci")
for x in changed_files
)

Expand Down
40 changes: 7 additions & 33 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/firecracker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ regex = { version = "1.11.1", default-features = false, features = [

# Dev-Dependencies for uffd examples
serde = { version = "1.0.219", features = ["derive"] }
userfaultfd = "0.8.1"
userfaultfd = { version = "0.9.0", features = ["linux5_13"] }

[lints]
workspace = true
Expand Down
13 changes: 4 additions & 9 deletions src/firecracker/examples/uffd/fault_all_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,11 @@
mod uffd_utils;

use std::fs::File;
use std::os::fd::AsRawFd;
use std::os::unix::net::UnixListener;

use uffd_utils::{Runtime, UffdHandler};
use utils::time::{ClockType, get_time_us};

use crate::uffd_utils::uffd_continue;

fn main() {
let mut args = std::env::args();
let uffd_sock_path = args.nth(1).expect("No socket path given");
Expand Down Expand Up @@ -57,12 +54,10 @@ fn main() {
// TODO: we currently ignore the result as we may attempt to
// populate the page that is already present as we may receive
// multiple minor fault events per page.
let _ = uffd_continue(
uffd_handler.uffd.as_raw_fd(),
addr as _,
uffd_handler.page_size as u64,
)
.inspect_err(|err| println!("Error during uffdio_continue: {:?}", err));
_ = uffd_handler
.uffd
.r#continue(addr, uffd_handler.page_size, true)
.inspect_err(|err| println!("Error during uffdio_continue: {:?}", err));
} else {
fault_all(uffd_handler, addr);
}
Expand Down
17 changes: 6 additions & 11 deletions src/firecracker/examples/uffd/on_demand_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,10 @@
mod uffd_utils;

use std::fs::File;
use std::os::fd::AsRawFd;
use std::os::unix::net::UnixListener;

use uffd_utils::{Runtime, UffdHandler};

use crate::uffd_utils::uffd_continue;

fn main() {
let mut args = std::env::args();
let uffd_sock_path = args.nth(1).expect("No socket path given");
Expand Down Expand Up @@ -112,14 +109,12 @@ fn main() {
// TODO: we currently ignore the result as we may attempt to
// populate the page that is already present as we may receive
// multiple minor fault events per page.
let _ = uffd_continue(
uffd_handler.uffd.as_raw_fd(),
addr as _,
uffd_handler.page_size as u64,
)
.inspect_err(|err| {
println!("uffdio_continue error: {:?}", err)
});
let _ = uffd_handler
.uffd
.r#continue(addr.cast(), uffd_handler.page_size, true)
.inspect_err(|err| {
println!("uffdio_continue error: {:?}", err)
});
}
} else if !uffd_handler.serve_pf(addr.cast(), uffd_handler.page_size) {
deferred_events.push(event);
Expand Down
42 changes: 3 additions & 39 deletions src/firecracker/examples/uffd/uffd_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use std::ffi::c_void;
use std::fs::File;
use std::io::{Read, Write};
use std::num::NonZero;
use std::os::fd::RawFd;
use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd};
use std::os::unix::net::UnixStream;
use std::ptr;
Expand All @@ -28,47 +27,10 @@ use std::time::Duration;
use serde::{Deserialize, Serialize};
use serde_json::{Deserializer, StreamDeserializer};
use userfaultfd::{Error, Event, Uffd};
use vmm_sys_util::ioctl::ioctl_with_mut_ref;
use vmm_sys_util::ioctl_iowr_nr;
use vmm_sys_util::sock_ctrl_msg::ScmSocket;

use crate::uffd_utils::userfault_bitmap::UserfaultBitmap;

// TODO: remove when UFFDIO_CONTINUE for guest_memfd is available in the crate
#[repr(C)]
struct uffdio_continue {
range: uffdio_range,
mode: u64,
mapped: u64,
}

ioctl_iowr_nr!(UFFDIO_CONTINUE, 0xAA, 0x7, uffdio_continue);

#[repr(C)]
struct uffdio_range {
start: u64,
len: u64,
}

pub fn uffd_continue(uffd: RawFd, fault_addr: u64, len: u64) -> std::io::Result<()> {
let mut cont = uffdio_continue {
range: uffdio_range {
start: fault_addr,
len,
},
mode: 0, // Normal continuation mode
mapped: 0,
};

let ret = unsafe { ioctl_with_mut_ref(&uffd, UFFDIO_CONTINUE(), &mut cont) };

if ret == -1 {
return Err(std::io::Error::last_os_error());
}

Ok(())
}

// This is the same with the one used in src/vmm.
/// This describes the mapping between Firecracker base virtual address and offset in the
/// buffer or file backend for a guest memory region. It is used to tell an external
Expand Down Expand Up @@ -440,7 +402,9 @@ impl UffdHandler {
.unwrap()
.reset_addr_range(offset, len);

uffd_continue(self.uffd.as_raw_fd(), dst, len as u64).expect("uffd_continue");
self.uffd
.r#continue(dst as _, len, true)
.expect("uffd_continue");

true
}
Expand Down
2 changes: 1 addition & 1 deletion src/vmm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ serde_json = "1.0.142"
slab = "0.4.11"
thiserror = "2.0.14"
timerfd = "1.5.0"
userfaultfd = "0.8.1"
userfaultfd = { version = "0.9.0", features = ["linux5_13"] }
utils = { path = "../utils" }
uuid = "1.18.0"
vhost = { version = "0.14.0", features = ["vhost-user-frontend"] }
Expand Down
5 changes: 1 addition & 4 deletions src/vmm/src/persist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,9 +504,6 @@ pub enum GuestMemoryFromUffdError {
HugetlbfsSnapshot,
}

// TODO remove these when the UFFD crate supports minor faults for guest_memfd
const UFFDIO_REGISTER_MODE_MINOR: u64 = 1 << 2;

type GuestMemoryResult =
Result<(Vec<GuestRegionMmap>, Option<Uffd>, Option<UnixStream>), GuestMemoryFromUffdError>;

Expand Down Expand Up @@ -542,7 +539,7 @@ pub fn guest_memory_from_uffd(
let mut fds = vec![uffd.as_raw_fd()];

if let Some(gmem) = guest_memfd_fd {
mode = RegisterMode::from_bits_retain(UFFDIO_REGISTER_MODE_MINOR);
mode = RegisterMode::MINOR;
fds.push(gmem);
fds.push(
userfault_bitmap_memfd
Expand Down
Loading