Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[WIP] vmm: preserved FD: improve code + Error on misconfiguration - #7401

Closed
phip1611 wants to merge 3 commits into
cloud-hypervisor:mainfrom
phip1611:productize-add-preserved-fs-assert
Closed

phip1611 wants to merge 3 commits into
cloud-hypervisor:mainfrom
phip1611:productize-add-preserved-fs-assert

Conversation

@phip1611

@phip1611 phip1611 commented Oct 7, 2025

Copy link
Copy Markdown
Member

Please see the commit messages for details.

Steps to Undraft

  • make CI work
  • run our internal live-migration test suite

@phip1611 phip1611 changed the title [WIP] vmm: simplify and streamline preserved FD handling [WIP for CI RUN] vmm: simplify and streamline preserved FD handling Oct 7, 2025
@phip1611
phip1611 force-pushed the productize-add-preserved-fs-assert branch from 1d119bd to 6e52a4e Compare October 7, 2025 14:31
@phip1611
phip1611 force-pushed the productize-add-preserved-fs-assert branch from 6e52a4e to 3cd4685 Compare October 21, 2025 10:48
@phip1611 phip1611 changed the title [WIP for CI RUN] vmm: simplify and streamline preserved FD handling vmm: simplify and streamline preserved FD handling Oct 21, 2025
@phip1611
phip1611 marked this pull request as ready for review October 21, 2025 10:48
@phip1611
phip1611 requested a review from a team as a code owner October 21, 2025 10:48
@phip1611
phip1611 force-pushed the productize-add-preserved-fs-assert branch 2 times, most recently from e1901bb to fdf6d8a Compare October 21, 2025 10:51
@phip1611

This comment was marked as outdated.

@phip1611
phip1611 force-pushed the productize-add-preserved-fs-assert branch 5 times, most recently from 5fdcc54 to a540d37 Compare October 22, 2025 11:08

@rbradford rbradford left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use of the HashSet prohibits duplicates - and your warning logic flags them up. I wonder if there is a legitimate use case for the same FD being passed in twice.

Comment thread vmm/src/config.rs Outdated
for fd in fds.into_iter() {
if self.preserved_fds.contains(&fd) {
log::warn!(
"FD {fd} is already preserved. Using the same FD multiple times causes most likely unexpected behavior"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The word order in this warning is not quite right - are there legitimate cases where the same FD would be reused?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is illegal to use the same FD multiple times, otherwise we open the gate to complexity hell. For example, assume we add two network devices during runtime with the same FD and the first one is unplugged and closes the file descriptor #7371.

I will remove the warning and return an error instead

Comment thread vmm/src/config.rs Outdated
/// FDs are all valid.
pub unsafe fn add_preserved_fds(&mut self, fds: impl IntoIterator<Item = RawFd>) {
for fd in fds.into_iter() {
if self.preserved_fds.contains(&fd) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be simplified as .insert() returns a bool about where it was added or not - if it wasn't added, because it's a duplicate then we could trigger the warning. Removing the need for the explicit contains check.

@phip1611
phip1611 force-pushed the productize-add-preserved-fs-assert branch 3 times, most recently from 119912e to 0bc2877 Compare October 23, 2025 12:41
@phip1611 phip1611 changed the title vmm: simplify and streamline preserved FD handling vmm: preserved FD: improve code + Error on misconfiguration Oct 23, 2025
- no need for an Option, an empty collection is also as good
- We use a HashSet as all FDs are unique anyway

The next commit will replace the warn! with an Err, when the same FD is
used multiple times.

Signed-off-by: Philipp Schuster <[email protected]>
On-behalf-of: SAP [email protected]
Allowing the same file descriptor (FD) to be preserved more than once
can lead to severe issues. Consider the case where management software
adds two virtio-net devices at runtime, both backed by the same
externally provided FD.

When the first device is removed during runtime, the FD for the second
device becomes invalid [0].

To avoid misconfigurations, we now prevent multiple preservation
attempts of the same FD.

[0] cloud-hypervisor#7371

Signed-off-by: Philipp Schuster <[email protected]>
On-behalf-of: SAP [email protected]
@phip1611
phip1611 force-pushed the productize-add-preserved-fs-assert branch from 0bc2877 to 62468e3 Compare October 23, 2025 12:52
We don't need the order in that we preserve FDs, but it is beneficial
for debugging to see FDs in an ordered way

Signed-off-by: Philipp Schuster <[email protected]>
On-behalf-of: SAP [email protected]
@phip1611
phip1611 force-pushed the productize-add-preserved-fs-assert branch from 62468e3 to 0975ba6 Compare October 23, 2025 12:55
@phip1611 phip1611 changed the title vmm: preserved FD: improve code + Error on misconfiguration [WIP] vmm: preserved FD: improve code + Error on misconfiguration Oct 23, 2025
@phip1611
phip1611 marked this pull request as draft October 23, 2025 13:30
@phip1611

phip1611 commented Oct 23, 2025

Copy link
Copy Markdown
Member Author

I noticed although this is important, it has more caveats than anticipated. I'll do more development in our fork including some testing and upstream this once it is more mature.

FYI, the PoC in our fork.

@phip1611 phip1611 closed this Oct 23, 2025
@phip1611
phip1611 deleted the productize-add-preserved-fs-assert branch October 23, 2025 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants