Skip to content

Commit eca06b1

Browse files
committed
feat(uhyve): experimental MmioWrite hypercall exiting
Helped-by: Jonathan Klimt <jonathan.klimt@eonerc.rwth-aachen.de>
1 parent cb0d623 commit eca06b1

File tree

4 files changed

+18
-21
lines changed

4 files changed

+18
-21
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ thiserror = { version = "2", default-features = false }
145145
time = { version = "0.3", default-features = false }
146146
volatile = "0.6"
147147
zerocopy = { version = "0.8", default-features = false }
148-
uhyve-interface = "0.1.3"
148+
uhyve-interface = "0.2.0"
149149

150150
[dependencies.smoltcp]
151151
version = "0.12"

src/fd/stdio.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ use core::task::Poll;
44

55
use async_trait::async_trait;
66
use embedded_io::{Read, ReadReady, Write};
7-
use uhyve_interface::parameters::WriteParams;
8-
use uhyve_interface::{GuestVirtAddr, Hypercall};
7+
use uhyve_interface::GuestVirtAddr;
8+
use uhyve_interface::v2::Hypercall;
9+
use uhyve_interface::v2::parameters::WriteParams;
910

1011
use crate::console::{CONSOLE, CONSOLE_WAKER};
1112
use crate::fd::{

src/fs/uhyve.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ use async_lock::Mutex;
88
use async_trait::async_trait;
99
use embedded_io::{ErrorType, Read, Write};
1010
use memory_addresses::VirtAddr;
11-
use uhyve_interface::parameters::{
11+
use uhyve_interface::v2::Hypercall;
12+
use uhyve_interface::v2::parameters::{
1213
CloseParams, LseekParams, OpenParams, ReadParams, UnlinkParams, WriteParams,
1314
};
14-
use uhyve_interface::{GuestPhysAddr, GuestVirtAddr, Hypercall};
15+
use uhyve_interface::{GuestPhysAddr, GuestVirtAddr};
1516

1617
use crate::arch::mm::paging;
1718
use crate::errno::Errno;

src/syscalls/interfaces/uhyve.rs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
use core::ptr;
22

3-
use memory_addresses::VirtAddr;
4-
use uhyve_interface::parameters::{ExitParams, SerialWriteBufferParams};
5-
use uhyve_interface::{Hypercall, HypercallAddress};
3+
use memory_addresses::{PhysAddr, VirtAddr};
4+
use uhyve_interface::v2::parameters::{ExitParams, SerialWriteBufferParams};
5+
use uhyve_interface::v2::{Hypercall, HypercallAddress};
66

77
use crate::arch;
88
use crate::arch::mm::paging::{self, virtual_to_physical};
99
use crate::syscalls::interfaces::SyscallInterface;
1010

11-
/// perform a SerialWriteBuffer hypercall with `buf` as payload.
11+
/// perform a SerialWriteBuffer hypercall with `buf` as payload
1212
#[inline]
1313
#[cfg_attr(target_arch = "riscv64", expect(dead_code))]
1414
pub(crate) fn serial_buf_hypercall(buf: &[u8]) {
@@ -31,9 +31,7 @@ fn data_addr<T>(data: &T) -> u64 {
3131
#[inline]
3232
fn hypercall_data(hypercall: &Hypercall<'_>) -> u64 {
3333
match hypercall {
34-
Hypercall::Cmdsize(data) => data_addr(*data),
35-
Hypercall::Cmdval(data) => data_addr(*data),
36-
Hypercall::Exit(data) => data_addr(*data),
34+
Hypercall::Exit(exit_code) => u64::try_from(*exit_code).unwrap(),
3735
Hypercall::FileClose(data) => data_addr(*data),
3836
Hypercall::FileLseek(data) => data_addr(*data),
3937
Hypercall::FileOpen(data) => data_addr(*data),
@@ -50,24 +48,21 @@ fn hypercall_data(hypercall: &Hypercall<'_>) -> u64 {
5048
#[inline]
5149
#[allow(unused_variables)] // until riscv64 is implemented
5250
pub(crate) fn uhyve_hypercall(hypercall: Hypercall<'_>) {
53-
let ptr = HypercallAddress::from(&hypercall) as u16;
51+
let mut ptr = HypercallAddress::from(&hypercall) as u64;
5452
let data = hypercall_data(&hypercall);
5553

5654
#[cfg(target_arch = "x86_64")]
57-
unsafe {
58-
use x86_64::instructions::port::Port;
59-
60-
let data =
61-
u32::try_from(data).expect("Hypercall data must lie in the first 4GiB of memory");
62-
Port::new(ptr).write(data);
55+
{
56+
let ptr = ptr as *mut u64;
57+
unsafe { ptr.write_volatile(data) };
6358
}
6459

6560
#[cfg(target_arch = "aarch64")]
6661
unsafe {
6762
use core::arch::asm;
6863
asm!(
6964
"str x8, [{ptr}]",
70-
ptr = in(reg) u64::from(ptr),
65+
ptr = in(reg) ptr,
7166
in("x8") data,
7267
options(nostack),
7368
);
@@ -82,7 +77,7 @@ pub struct Uhyve;
8277
impl SyscallInterface for Uhyve {
8378
fn shutdown(&self, error_code: i32) -> ! {
8479
let sysexit = ExitParams { arg: error_code };
85-
uhyve_hypercall(Hypercall::Exit(&sysexit));
80+
uhyve_hypercall(Hypercall::Exit(error_code));
8681

8782
loop {
8883
arch::processor::halt();

0 commit comments

Comments
 (0)