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 various ioctls required by SEV-SNP guest #102

Merged
merged 5 commits into from
Jul 6, 2023
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
57 changes: 57 additions & 0 deletions mshv-ioctls/src/ioctls/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,63 @@ impl VmFd {
Err(errno::Error::last())
}
}
/// Modify host visibility for a range of GPA
pub fn modify_gpa_host_access(
&self,
gpa_host_access_args: &mshv_modify_gpa_host_access,
) -> Result<()> {
// SAFETY: IOCTL with correct types
let ret =
unsafe { ioctl_with_ref(self, MSHV_MODIFY_GPA_HOST_ACCESS(), gpa_host_access_args) };
if ret == 0 {
Ok(())
} else {
Err(errno::Error::last())
}
}
/// Import the isolated pages
pub fn import_isolated_pages(
&self,
isolate_page_list: &mshv_import_isolated_pages,
) -> Result<()> {
// SAFETY: IOCTL with correct types
let ret = unsafe { ioctl_with_ref(self, MSHV_IMPORT_ISOLATED_PAGES(), isolate_page_list) };
if ret == 0 {
Ok(())
} else {
Err(errno::Error::last())
}
}
/// Mark completion of importing the isoalted pages
pub fn complete_isolated_import(&self, data: &mshv_complete_isolated_import) -> Result<()> {
// SAFETY: IOCTL with correct types
let ret = unsafe { ioctl_with_ref(self, MSHV_COMPLETE_ISOLATED_IMPORT(), data) };
if ret == 0 {
Ok(())
} else {
Err(errno::Error::last())
}
}
/// Issue PSP request from guest side
pub fn psp_issue_guest_request(&self, data: &mshv_issue_psp_guest_request) -> Result<()> {
// SAFETY: IOCTL with correct types
let ret = unsafe { ioctl_with_ref(self, MSHV_ISSUE_PSP_GUEST_REQUEST(), data) };
if ret == 0 {
Ok(())
} else {
Err(errno::Error::last())
}
}
/// Create AP threads for SEV-SNP guest
pub fn sev_snp_ap_create(&self, data: &mshv_sev_snp_ap_create) -> Result<()> {
// SAFETY: IOCTL with correct types
let ret = unsafe { ioctl_with_ref(self, MSHV_SEV_SNP_AP_CREATE(), data) };
if ret == 0 {
Ok(())
} else {
Err(errno::Error::last())
}
}
/// Creates/modifies a guest physical memory.
pub fn map_user_memory(&self, user_memory_region: mshv_user_mem_region) -> Result<()> {
// SAFETY: IOCTL with correct types
Expand Down
30 changes: 30 additions & 0 deletions mshv-ioctls/src/mshv_ioctls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,35 @@ ioctl_iowr_nr!(
0x1B,
mshv_get_vp_cpuid_values
);
ioctl_iow_nr!(
MSHV_MODIFY_GPA_HOST_ACCESS,
MSHV_IOCTL,
0x28,
mshv_modify_gpa_host_access
);
ioctl_iow_nr!(
MSHV_IMPORT_ISOLATED_PAGES,
MSHV_IOCTL,
0x29,
mshv_import_isolated_pages
);
ioctl_iow_nr!(
MSHV_COMPLETE_ISOLATED_IMPORT,
MSHV_IOCTL,
0x30,
mshv_complete_isolated_import
);
ioctl_iow_nr!(
MSHV_ISSUE_PSP_GUEST_REQUEST,
MSHV_IOCTL,
0x31,
mshv_issue_psp_guest_request
);
ioctl_iowr_nr!(MSHV_READ_GPA, MSHV_IOCTL, 0x32, mshv_read_write_gpa);
ioctl_iow_nr!(MSHV_WRITE_GPA, MSHV_IOCTL, 0x33, mshv_read_write_gpa);
ioctl_iow_nr!(
MSHV_SEV_SNP_AP_CREATE,
MSHV_IOCTL,
0x34,
mshv_sev_snp_ap_create
);
Loading