-
Notifications
You must be signed in to change notification settings - Fork 86
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
base: main
Are you sure you want to change the base?
Conversation
Depends on #1442 |
c08658a
to
9720732
Compare
9720732
to
9a16274
Compare
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.
Overall, this looks good to me, but I have a few remarks. :)
#[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!() | ||
} |
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.
Why not share a common function definition across architectures like before?
#[inline] | ||
/// calculates the physical address of the struct passed as reference. | ||
fn data_addr<T>(data: &T) -> u64 { |
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.
Nit regarding all doc comments: the doc comments should come before attributes. Also, the beginning of doc comments should be capitalized.
let mut close_params = CloseParams { fd: self.0, ret: 0 }; | ||
// TODO: Panic on ret != 0? | ||
uhyve_hypercall(Hypercall::FileClose(&mut close_params)); |
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.
Should we resolve this TODO before merging the PR?
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.
Cargo.lock
should be updated separately. I have opened #1474.
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.