Skip to content
Closed
Changes from 1 commit
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
24 changes: 24 additions & 0 deletions kvm-ioctls/src/ioctls/vcpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ pub enum VcpuExit<'a> {
/// size
size: u64,
},
/// Corresponds to SBI_EXT_0_1_CONSOLE_PUTCHAR.
SbiExt0_1ConsolePutchar(u64),
/// Corresponds to SBI_EXT_0_1_CONSOLE_GETCHAR.
SbiExt0_1ConsoleGetchar(&'a mut [u64]),
/// Corresponds to an exit reason that is unknown from the current version
/// of the kvm-ioctls crate. Let the consumer decide about what to do with
/// it.
Expand Down Expand Up @@ -1688,6 +1692,26 @@ impl VcpuFd {
Ok(VcpuExit::IoapicEoi(eoi.vector))
}
KVM_EXIT_HYPERV => Ok(VcpuExit::Hyperv),
#[cfg(target_arch = "riscv64")]
KVM_EXIT_RISCV_SBI => {
// SAFETY: Safe because the exit_reason (which comes from the kernel) told us
// which union field to use and the type of extension_id is 'enum sbi_ext_id'.
match unsafe { run.__bindgen_anon_1.riscv_sbi.extension_id } as u32 {
SBI_EXT_0_1_CONSOLE_PUTCHAR => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think these should be handled at the KVM crate level - they should be done by the VMM.

// SAFETY: Safe because the exit_reason (which comes from the kernel) told us
// which union field to use
let ch = unsafe { run.__bindgen_anon_1.riscv_sbi.args[0] };
Ok(VcpuExit::SbiExt0_1ConsolePutchar(ch))
}
SBI_EXT_0_1_CONSOLE_GETCHAR => {
// SAFETY: Safe because the exit_reason (which comes from the kernel) told us
// which union field to use
let ch = unsafe { &mut run.__bindgen_anon_1.riscv_sbi.ret[..1] };
Ok(VcpuExit::SbiExt0_1ConsoleGetchar(ch))
}
r => Ok(VcpuExit::Unsupported(r)),
Copy link
Member

Choose a reason for hiding this comment

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

Is this match arm correct, maybe _?

}
}
r => Ok(VcpuExit::Unsupported(r)),
}
} else {
Expand Down