-
Notifications
You must be signed in to change notification settings - Fork 127
Add riscv64 sbi bindings #345
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
base: main
Are you sure you want to change the base?
Conversation
@RuoqingHe could you have a look at this one? :o |
70ea5dc
to
6e53a2a
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.
6e53a2a should be squashed into other commits
kvm-bindings/src/riscv64/mod.rs
Outdated
@@ -5,12 +5,14 @@ | |||
#[allow(clippy::all)] | |||
#[allow(clippy::undocumented_unsafe_blocks)] | |||
pub mod bindings; | |||
pub mod sbi_bindings; |
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.
Please align the bindgen version with the version we used to generate kvm-bindings
let ch = unsafe { &mut run.__bindgen_anon_1.riscv_sbi.ret[..1] }; | ||
Ok(VcpuExit::SbiExt0_1ConsoleGetchar(ch)) | ||
} | ||
r => Ok(VcpuExit::Unsupported(r)), |
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.
Is this match arm correct, maybe _
?
kvm-ioctls/src/ioctls/vcpu.rs
Outdated
#[cfg(target_arch = "riscv64")] | ||
KVM_EXIT_RISCV_SBI => { | ||
match unsafe {run.__bindgen_anon_1.riscv_sbi.extension_id} as u32 { | ||
SBI_EXT_0_1_CONSOLE_PUTCHAR => { | ||
let ch = unsafe { run.__bindgen_anon_1.riscv_sbi.args[0] }; | ||
Ok(VcpuExit::SbiExt0_1ConsolePutchar(ch)) | ||
} | ||
SBI_EXT_0_1_CONSOLE_GETCHAR => { | ||
let ch = unsafe { &mut run.__bindgen_anon_1.riscv_sbi.ret[..1] }; | ||
Ok(VcpuExit::SbiExt0_1ConsoleGetchar(ch)) | ||
} | ||
r => Ok(VcpuExit::Unsupported(r)), | ||
} | ||
} |
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.
IMHO we should just return __bindgen_anon_1.riscv_sbi
here, leave the vmm to decide what to do next
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.
IMO we should only introduce KVM_EXIT_RISCV_SBI
here and return __bindgen_anon_1.riscv_sbi
for vmm to further decide
And those sbi bindings are not from kernel, this would not be the right place for them to live in, perhaps add them to the VMM you are working on 🙂
Generate bindings from qemu-10.1.0 target\riscv\sbi_ecall_interface.h using bindgen-cli 0.72.1 Signed-off-by: BillXiang <[email protected]>
Handle console sbi call, which implement early console io while apply 'earlycon=sbi' into kernel parameters. Signed-off-by: BillXiang <[email protected]>
running 1 test test ioctls::vcpu::tests::test_run_code ... ok Signed-off-by: BillXiang <[email protected]>
Signed-off-by: BillXiang <[email protected]>
6e53a2a
to
cfc3c1c
Compare
Maybe it's better to add those sbi bindings to the VMM. |
// 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 => { |
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.
I don't think these should be handled at the KVM crate level - they should be done by the VMM.
Summary of the PR
using bindgen-cli 0.72.1.
Requirements
Before submitting your PR, please make sure you addressed the following
requirements:
git commit -s
), and the commit message has max 60 characters for thesummary and max 75 characters for each description line.
test.
Release" section of CHANGELOG.md (if no such section exists, please create one).
unsafe
code is properly documented.