-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix(vmm): reject vhost-user hot-add when memory cannot be shared #6204
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
f86d41c
08407e5
f2cb533
19af4ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -647,6 +647,15 @@ impl<'a> GuestMemorySlot<'a> { | |
| } | ||
|
|
||
| impl GuestRegionMmapExt { | ||
| /// The backing file, if another process could map the same pages from it: | ||
| /// file-backed and `MAP_SHARED`. A private mapping copies on write, so a | ||
| /// second mapping of the file diverges from this one. | ||
| pub fn shared_file_offset(&self) -> Option<&FileOffset> { | ||
| self.inner | ||
| .file_offset() | ||
| .filter(|_| self.inner.flags() & libc::MAP_SHARED != 0) | ||
| } | ||
|
Comment on lines
+653
to
+657
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how about just exposing assert!(region.is_shared());
let Some(_file_offset) = region.file_offset() else {
panic!("...")
}
let (mmap_handle, mmap_offset) = (_file_offset.file().as_raw_fd(), _file_offset.start());
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. which is longer and more complicated than the code above? no thanks. Maybe I can add a separate |
||
|
|
||
| /// Adds a DRAM region which only contains a single plugged slot | ||
| pub(crate) fn dram_from_mmap_region(region: GuestRegionMmap, slot: u32) -> Self { | ||
| let slot_size = u64_to_usize(region.len()); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't believe this is a valid error for vhost-user devices. We must not create them if we don't use sharable memfd for memory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now the only way preventing that is that we can't snapshot, but in theory the code could restore it. A modified snapshot could in theory contain it and this makes the check more generic and robust for the future.