Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for hugepages without using UFFD #1

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
3 changes: 1 addition & 2 deletions github-tf/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@ resource "google_iam_workload_identity_pool_provider" "gha_identity_pool_provide
attribute_mapping = {
"google.subject" = "assertion.sub"
"attribute.repository" = "assertion.repository"
"attribute.ref" = "assertion.ref"
}
attribute_condition = "assertion.repository == \"${var.github_organization}/${var.github_repository}\" && assertion.ref == \"refs/heads/main\""
attribute_condition = "assertion.repository == \"${var.github_organization}/${var.github_repository}\""

oidc {
issuer_uri = "https://token.actions.githubusercontent.com"
Expand Down
22 changes: 11 additions & 11 deletions src/vmm/src/vstate/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ where
regions: Vec<(FileOffset, GuestAddress, usize)>,
track_dirty_pages: bool,
shared: bool,
huge_pages: HugePageConfig,
) -> Result<Self, MemoryError>;

/// Creates a GuestMemoryMmap given a `file` containing the data
Expand Down Expand Up @@ -152,7 +153,7 @@ impl GuestMemoryExtension for GuestMemoryMmap {
})
.collect::<Result<Vec<_>, MemoryError>>()?;

Self::from_raw_regions_file(regions, track_dirty_pages, true)
Self::from_raw_regions_file(regions, track_dirty_pages, true, huge_pages)
}

/// Creates a GuestMemoryMmap from raw regions backed by anonymous memory.
Expand Down Expand Up @@ -195,12 +196,13 @@ impl GuestMemoryExtension for GuestMemoryMmap {
regions: Vec<(FileOffset, GuestAddress, usize)>,
track_dirty_pages: bool,
shared: bool,
huge_pages: HugePageConfig,
) -> Result<Self, MemoryError> {
let prot = libc::PROT_READ | libc::PROT_WRITE;
let flags = if shared {
libc::MAP_NORESERVE | libc::MAP_SHARED
libc::MAP_NORESERVE | libc::MAP_SHARED | huge_pages.mmap_flags()
} else {
libc::MAP_NORESERVE | libc::MAP_PRIVATE
libc::MAP_NORESERVE | libc::MAP_PRIVATE | huge_pages.mmap_flags()
};
let regions = regions
.into_iter()
Expand Down Expand Up @@ -233,10 +235,6 @@ impl GuestMemoryExtension for GuestMemoryMmap {
) -> Result<Self, MemoryError> {
match file {
Some(f) => {
if huge_pages.is_hugetlbfs() {
return Err(MemoryError::HugetlbfsSnapshot);
}

let regions = state
.regions
.iter()
Expand All @@ -249,7 +247,7 @@ impl GuestMemoryExtension for GuestMemoryMmap {
.collect::<Result<Vec<_>, std::io::Error>>()
.map_err(MemoryError::FileError)?;

Self::from_raw_regions_file(regions, track_dirty_pages, false)
Self::from_raw_regions_file(regions, track_dirty_pages, false, huge_pages)
}
None => {
let regions = state
Expand Down Expand Up @@ -472,6 +470,8 @@ mod tests {
fn test_from_raw_regions_file() {
let region_size = 0x10000;

let huge_pages = HugePageConfig::None;

let file = TempFile::new().unwrap().into_file();
let file_size = 4 * region_size;
file.set_len(file_size as u64).unwrap();
Expand Down Expand Up @@ -502,7 +502,7 @@ mod tests {
// Test that all regions are guarded.
{
let guest_memory =
GuestMemoryMmap::from_raw_regions_file(regions.clone(), false, false).unwrap();
GuestMemoryMmap::from_raw_regions_file(regions.clone(), false, false, huge_pages).unwrap();
guest_memory.iter().for_each(|region| {
assert_eq!(region.size(), region_size);
assert!(region.file_offset().is_some());
Expand All @@ -513,7 +513,7 @@ mod tests {
// Check dirty page tracking is off.
{
let guest_memory =
GuestMemoryMmap::from_raw_regions_file(regions.clone(), false, false).unwrap();
GuestMemoryMmap::from_raw_regions_file(regions.clone(), false, false, huge_pages).unwrap();
guest_memory.iter().for_each(|region| {
assert!(region.bitmap().is_none());
});
Expand All @@ -522,7 +522,7 @@ mod tests {
// Check dirty page tracking is on.
{
let guest_memory =
GuestMemoryMmap::from_raw_regions_file(regions, true, false).unwrap();
GuestMemoryMmap::from_raw_regions_file(regions, true, false, huge_pages).unwrap();
guest_memory.iter().for_each(|region| {
assert!(region.bitmap().is_some());
});
Expand Down
Loading