Skip to content
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

Merged
merged 5 commits into from Aug 21, 2022

Conversation

michael2012z
Copy link
Member

@michael2012z michael2012z commented Aug 19, 2022

Fixes #3980

This PR enables the support of GDB to debug guest kernel.

Following GDB commands were tested:

  • info registers command: Checking general purposed registers
  • hb: Setting HW breakpoints
  • ctrl+c: Interrupting
  • bt: Checking backtrack
  • nexti(n): Next line
  • stepi(s): Next line (into function)

Following functionalities are known not ready:

  • info registers: More registers (mainly system registers) are to be added
  • w: HW watchpoints

On 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 to kvm-ioctls for the support. Before that improvement, the hardcoded limit 4 should be practical enough.

@michael2012z michael2012z requested a review from a team as a code owner August 19, 2022 03:40
Copy link
Member

@sboeuf sboeuf left a 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!

@@ -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 }
Copy link
Member

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.

Copy link
Member Author

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"))]
Copy link
Member

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"))]
Copy link
Member

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};

Copy link
Member

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.

@rbradford rbradford added the new-feature New feature to include in release notes label Aug 19, 2022
Copy link
Member

@rbradford rbradford left a 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`,
Copy link
Contributor

Choose a reason for hiding this comment

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

Extract??

Copy link
Member Author

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?

Copy link
Member

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>
@michael2012z
Copy link
Member Author

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.

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),
Copy link
Member

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.

@MrXinWang MrXinWang merged commit c798b95 into cloud-hypervisor:main Aug 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new-feature New feature to include in release notes
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

GDB support on ARM64 KVM
6 participants