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
Enable GDB support on AArch64 #4519
Conversation
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.
Just a few comments but it looks great to me!
hypervisor/Cargo.toml
Outdated
@@ -16,7 +16,7 @@ byteorder = "1.4.3" | |||
thiserror = "1.0.32" | |||
libc = "0.2.132" | |||
log = "0.4.17" | |||
kvm-ioctls = { version = "0.11.0", optional = true } | |||
kvm-ioctls = { git = "https://github.com/rust-vmm/kvm-ioctls", branch = "main", optional = true } |
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.
You shouldn't need this since there's already a dependency patch for kvm-ioctls
in the main Cargo.toml
file.
I think all you need is to run cargo update -p kvm-ioctls
in order to update Cargo.lock
.
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.
Cool! Thanks.
vmm/src/cpu.rs
Outdated
@@ -141,10 +155,14 @@ pub enum Error { | |||
#[error("Error during CPU debug: {0}")] | |||
CpuDebug(#[source] hypervisor::HypervisorCpuError), | |||
|
|||
#[cfg(all(target_arch = "x86_64", feature = "gdb"))] | |||
#[cfg(all(feature = "gdb", target_arch = "x86_64"))] |
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: feature
and feature_arch
are reversed compared to other places in the code.
vmm/src/cpu.rs
Outdated
#[error("Error translating virtual address: {0}")] | ||
TranslateVirtualAddress(#[source] hypervisor::HypervisorCpuError), | ||
|
||
#[cfg(all(feature = "gdb", target_arch = "aarch64"))] |
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.
Same here.
@@ -31,7 +31,11 @@ use gdbstub_arch::x86::X86_64_SSE as GdbArch; | |||
use std::{os::unix::net::UnixListener, sync::mpsc}; | |||
use vm_memory::{GuestAddress, GuestMemoryError}; | |||
|
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: This whitespace prevents the use
blocks from being merged together.
01a07da
to
c5eb240
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.
Sorry for the late change! You need to include checks in the .github/workflows for aarch64 with the gdb feature so that we don't get compile/clippy issues.
@@ -74,6 +80,18 @@ use vm_migration::{ | |||
use vmm_sys_util::eventfd::EventFd; | |||
use vmm_sys_util::signal::{register_signal_handler, SIGRTMIN}; | |||
|
|||
#[cfg(all(target_arch = "aarch64", feature = "gdb"))] | |||
/// Extract the specified bits of a 64-bit integer. | |||
/// For example, to extrace 2 bits from offset 1 (zero based) of `6u64`, |
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.
Extract??
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.
The wording or the macro's name is not proper, right? Any suggestion?
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 think using extract should be fine.
Signed-off-by: Michael Zhao <michael.zhao@arm.com>
The `gva_translate` function is still missing, it will be added with a separate commit. Signed-off-by: Michael Zhao <michael.zhao@arm.com>
On AArch64, `translate_gva` API is not provided by KVM. We implemented it in VMM by walking through translation tables. Address translation is big topic, here we only focus the scenario that happens in VMM while debugging kernel. This `translate_gva` implementation is restricted to: - Exception Level 1 - Translate high address range only (kernel space) This implementation supports following Arm-v8a features related to address translation: - FEAT_LPA - FEAT_LVA - FEAT_LPA2 The implementation supports page sizes of 4KiB, 16KiB and 64KiB. Signed-off-by: Michael Zhao <michael.zhao@arm.com>
Signed-off-by: Michael Zhao <michael.zhao@arm.com>
Add 'KVM_SET_GUEST_DEBUG' ioctl to seccomp filter rules. Signed-off-by: Michael Zhao <michael.zhao@arm.com>
36cbe0e
to
6326db6
Compare
Thanks for adding the check. The warnings were fixed. |
#[error("Error during CPU debug: {0}")] | ||
CpuDebug(#[source] hypervisor::HypervisorCpuError), | ||
|
||
#[cfg(all(target_arch = "x86_64", feature = "gdb"))] | ||
#[error("Error translating virtual address: {0}")] | ||
TranslateVirtualAddress(#[source] hypervisor::HypervisorCpuError), | ||
|
||
#[cfg(all(target_arch = "aarch64", feature = "gdb"))] | ||
#[error("Error translating virtual address: {0}")] | ||
TranslateVirtualAddress(#[source] anyhow::Error), |
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.
This can be improved in a later PR.
Now x86 and aarch64 both return this error but their implementation is different.
Fixes #3980
This PR enables the support of GDB to debug guest kernel.
Following GDB commands were tested:
info registers
command: Checking general purposed registershb
: Setting HW breakpointsctrl+c
: Interruptingbt
: Checking backtracknexti(n)
: Next linestepi(s)
: Next line (into function)Following functionalities are known not ready:
info registers
: More registers (mainly system registers) are to be addedw
: HW watchpointsOn AArch64, API
KVM_CAP_GUEST_DEBUG_HW_BPS
should be checked for the max number of HW breakpoints. A PR rust-vmm/kvm-ioctls#202 was created tokvm-ioctls
for the support. Before that improvement, the hardcoded limit4
should be practical enough.