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

Use hypercall definitions from uhyve-interface #1393

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jounathaen
Copy link
Member

This depends on hermit-os/uhyve#757 (and a publication of uhyve interface V0.1.2)

This is the final step of putting the hypercall definitions in a central crate.
This PR should just deduplicate code without changing functionality.

@jounathaen
Copy link
Member Author

Depends on #1442

Copy link
Member

@mkroening mkroening left a comment

Choose a reason for hiding this comment

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

Overall, this looks good to me, but I have a few remarks. :)

Comment on lines 38 to 79
#[inline]
fn uhyve_send<T>(port: u16, data: &mut T) {
let ptr = VirtAddr::from_ptr(data);
let physical_address = paging::virtual_to_physical(ptr).unwrap();
#[cfg(target_arch = "x86_64")]
/// Perform a hypercall to the uhyve hypervisor
pub(crate) fn uhyve_hypercall(hypercall: Hypercall<'_>) {
let port = HypercallAddress::from(&hypercall) as u16;
let data = hypercall_data(&hypercall);

#[cfg(target_arch = "x86_64")]
unsafe {
x86::io::outl(port, physical_address.as_u64() as u32);
outl(
port,
data.try_into()
.expect("Hypercall data must lie in the first 4GiB of memory"),
);
}
}

#[inline]
#[cfg(target_arch = "aarch64")]
/// Perform a hypercall to the uhyve hypervisor
pub(crate) fn uhyve_hypercall(hypercall: Hypercall<'_>) {
let ptr = HypercallAddress::from(&hypercall) as u16;
let data = hypercall_data(&hypercall);
use core::arch::asm;

#[cfg(target_arch = "aarch64")]
unsafe {
core::arch::asm!(
"str x8, [{port}]",
port = in(reg) u64::from(port),
in("x8") physical_address.as_u64(),
asm!(
"str x8, [{ptr}]",
ptr = in(reg) u64::from(ptr),
in("x8") data,
options(nostack),
);
}

#[cfg(target_arch = "riscv64")]
todo!("uhyve_send(port = {port}, physical_address = {physical_address:p})");
}

#[repr(C, packed)]
struct SysExit {
arg: i32,
}

impl SysExit {
fn new(arg: i32) -> SysExit {
SysExit { arg }
}
#[inline]
#[cfg(target_arch = "riscv64")]
/// Perform a hypercall to the uhyve hypervisor
pub(crate) fn uhyve_hypercall(hypercall: Hypercall<'_>) {
let _ptr = HypercallAddress::from(&hypercall) as u16;
let _data = hypercall_data(&hypercall);
todo!()
}
Copy link
Member

Choose a reason for hiding this comment

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

Why not share a common function definition across architectures like before?

Comment on lines +11 to +13
#[inline]
/// calculates the physical address of the struct passed as reference.
fn data_addr<T>(data: &T) -> u64 {
Copy link
Member

Choose a reason for hiding this comment

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

Nit regarding all doc comments: the doc comments should come before attributes. Also, the beginning of doc comments should be capitalized.

Comment on lines +76 to +78
let mut close_params = CloseParams { fd: self.0, ret: 0 };
// TODO: Panic on ret != 0?
uhyve_hypercall(Hypercall::FileClose(&mut close_params));
Copy link
Member

Choose a reason for hiding this comment

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

Should we resolve this TODO before merging the PR?

Copy link
Member

Choose a reason for hiding this comment

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

Cargo.lock should be updated separately. I have opened #1474.

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.

3 participants