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

[WIP] vmm: pre-create console devices #6403

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

praveen-pk
Copy link
Contributor

Create console devices before vm_create. This will ensure required device paths exist on the host and will allow landlock to add relevant rules to allow cloud-hypervisor to access those devices at runtime.

@@ -428,6 +428,11 @@ pub struct ConsoleConfig {
#[serde(default)]
pub iommu: bool,
pub socket: Option<PathBuf>,
// main_fd is the fd of the pre-created console device
Copy link
Member

Choose a reason for hiding this comment

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

I'm afraid it's not correct to put state like this in a Config struct - it's for user supplied configuration only.

Copy link
Member

@rbradford rbradford left a comment

Choose a reason for hiding this comment

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

I would recommend you create a new struct if you need to carry this state across

@praveen-pk
Copy link
Contributor Author

I would recommend you create a new struct if you need to carry this state across

Gotcha! I will move the FDs to a different struct in my next update.

@praveen-pk praveen-pk changed the title vmm: pre-create console devices [WIP] vmm: pre-create console devices May 8, 2024
@praveen-pk praveen-pk marked this pull request as draft May 8, 2024 23:19
@praveen-pk
Copy link
Contributor Author

I would recommend you create a new struct if you need to carry this state across

@rbradford moving the FDs to different struct resulted in considerable refactoring. I pushed the latest version to get some early feedback on the design. Please let me know using ConsoleInfo as implemented seems reasonable.

I still have to fix some tests and re-check the patches. So, I marked this PR as draft.

@praveen-pk praveen-pk force-pushed the pre_create_console_devs branch 2 times, most recently from ca6685b to 3ad305d Compare May 21, 2024 18:04
vmm/src/console_devices.rs Show resolved Hide resolved
vmm/src/lib.rs Outdated
@@ -1228,6 +1233,12 @@ impl RequestHandler for Vmm {
return Err(VmError::VmMissingConfig);
};

// console_info is set to None in vn_shutdown. re-populate here if empty
Copy link
Member

Choose a reason for hiding this comment

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

Typo vn_shutdown.

vmm/src/lib.rs Outdated Show resolved Hide resolved
vmm/src/console_devices.rs Show resolved Hide resolved
@praveen-pk praveen-pk force-pushed the pre_create_console_devs branch 2 times, most recently from b3151af to 0dcd696 Compare May 22, 2024 22:37
Introduce ConsoleInfo struct. This struct will be used to store FDs of
console devices created in pre_create_console_devices and passed to
vm_boot.

Move set_raw_mode, create_pty methods to console_devices.rs to
consolidate console management methods into a single module.

Lastly, copy the logic to create and configure console devices into
pre_create_console_devices method.

Signed-off-by: Praveen K Paladugu <prapal@linux.microsoft.com>
Move listen_for_sigwinch_on_tty to sigwinch_listener.rs module.

Signed-off-by: Praveen K Paladugu <prapal@linux.microsoft.com>
With this change all the information to manage console devices is now
available within Vmm Object.

Signed-off-by: Praveen K Paladugu <prapal@linux.microsoft.com>
Use pre_create_console_devices method to create and populate console
device FDs into console_info in Vmm Object.

Signed-off-by: Praveen K Paladugu <prapal@linux.microsoft.com>
While adding console devices, DeviceManager will now use the FDs in
console_info instead of creating them.

To reduce the size of this commit, I marked some variables are unused
with '_' prefix. All those variables are cleaned up in next commit.

Signed-off-by: Praveen K Paladugu <prapal@linux.microsoft.com>
Signed-off-by: Praveen K Paladugu <prapal@linux.microsoft.com>
During vm_shutdown or vm_snapshot, all the console devices will be
closed. When this happens stdout (FD #2) will also be closed as the
console device using these FD is closed. If the VM were to be started
later, FD#2 can be assigned to a different file. But
pre_create_console_devices looks for FD#2 while opening tty device,
which could point to any file.

To avoid this problem, the STDOUT FD is duplicated when being
assigned to a console device. Even if the console devices were to be
closed, the duplicated FD will be closed and FD#2 will continue to
point to STDOUT.

Signed-off-by: Praveen K Paladugu <prapal@linux.microsoft.com>
Rename TIOCGTPEER ioctl to it proper name:TIOCGPTPEER.

Signed-off-by: Praveen K Paladugu <prapal@linux.microsoft.com>
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.

None yet

3 participants