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

Add support for Hyperlight KVM guest debugging using gdb #111

Open
wants to merge 18 commits into
base: main
Choose a base branch
from

Conversation

dblnz
Copy link
Contributor

@dblnz dblnz commented Dec 13, 2024

The current implementation supports:

  • add/remove HW breakpoints (max 4)
  • add/remove SW breakpoints
  • read/write registers
  • read/write addresses
  • step/continue
  • get code offset from target

The overall architecture is designed to work like a Request - Response protocol from the gdb thread to the hypervisor handler over a DebugCommChannel.

  • All the functionality is implemented on the hypervisor side so it has access to the shared memory and VcpuFd
  • The gdb thread uses gdbstub to handle the communication with the gdb client
  • when the gdb client requests the supported features mentioned above, a request is sent forward to the hypervisor handler for the running sandbox to run

@dblnz dblnz added the kind/enhancement New feature or request label Dec 13, 2024
@dblnz dblnz self-assigned this Dec 13, 2024
@dblnz dblnz marked this pull request as draft December 13, 2024 17:54
@dblnz dblnz force-pushed the gdb-support-latest branch 2 times, most recently from be21b85 to ca61def Compare December 19, 2024 11:41
Copy link
Contributor

@devigned devigned left a comment

Choose a reason for hiding this comment

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

Super excited to see this landing. Nice work! My feedback mostly consists of nits and questions.

docs/how-to-debug-a-hyperlight-guest.md Outdated Show resolved Hide resolved
docs/how-to-debug-a-hyperlight-guest.md Outdated Show resolved Hide resolved
docs/how-to-debug-a-hyperlight-guest.md Outdated Show resolved Hide resolved
src/hyperlight_host/src/hypervisor/gdb/mod.rs Outdated Show resolved Hide resolved
src/hyperlight_host/src/hypervisor/gdb/mod.rs Outdated Show resolved Hide resolved
src/hyperlight_host/src/hypervisor/gdb/target.rs Outdated Show resolved Hide resolved
src/hyperlight_host/src/hypervisor/hypervisor_handler.rs Outdated Show resolved Hide resolved
src/hyperlight_host/src/hypervisor/kvm.rs Outdated Show resolved Hide resolved
@dblnz dblnz force-pushed the gdb-support-latest branch from 4a44b2e to 16492de Compare January 22, 2025 15:40
@dblnz dblnz marked this pull request as ready for review January 22, 2025 16:07
@dblnz dblnz changed the title Initial support for gdb debugging in Hyperlight KVM guest Add support for Hyperlight KVM guest debugging using gdb Jan 22, 2025
@dblnz dblnz force-pushed the gdb-support-latest branch from 2a36f06 to d0db26e Compare February 4, 2025 21:07
ludfjig
ludfjig previously approved these changes Feb 5, 2025
Copy link
Contributor

@ludfjig ludfjig left a comment

Choose a reason for hiding this comment

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

This is awesome!! Looked briefly though everything and I will give a more in-depth review tomorrow

src/hyperlight_host/Cargo.toml Outdated Show resolved Hide resolved
src/hyperlight_host/src/hypervisor/gdb/mod.rs Show resolved Hide resolved
src/hyperlight_host/src/sandbox/config.rs Outdated Show resolved Hide resolved
src/hyperlight_host/src/hypervisor/gdb/x86_64_target.rs Outdated Show resolved Hide resolved
ludfjig
ludfjig previously approved these changes Feb 7, 2025
Copy link
Contributor

@ludfjig ludfjig left a comment

Choose a reason for hiding this comment

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

This is awesome. I tried it out and it works great. Left some more comments, feel free to dismiss if you disagree with any of them. I realize some of them might be hard to implement as well. GREAT WORK!!

src/hyperlight_host/src/sandbox/config.rs Outdated Show resolved Hide resolved
docs/how-to-debug-a-hyperlight-guest.md Outdated Show resolved Hide resolved
docs/how-to-debug-a-hyperlight-guest.md Outdated Show resolved Hide resolved
src/hyperlight_host/Cargo.toml Outdated Show resolved Hide resolved
src/hyperlight_host/src/hypervisor/kvm.rs Show resolved Hide resolved
src/hyperlight_host/src/hypervisor/kvm.rs Outdated Show resolved Hide resolved
src/hyperlight_host/src/hypervisor/kvm.rs Outdated Show resolved Hide resolved
src/hyperlight_host/src/hypervisor/gdb/mod.rs Show resolved Hide resolved
docs/how-to-debug-a-hyperlight-guest.md Show resolved Hide resolved
Copy link
Contributor

@simongdavies simongdavies left a comment

Choose a reason for hiding this comment

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

a few minor issues, but overall this is great. I don't know why the spelling issues are not getting picked up by the spell check in GH actions

docs/how-to-debug-a-hyperlight-guest.md Outdated Show resolved Hide resolved
docs/how-to-debug-a-hyperlight-guest.md Outdated Show resolved Hide resolved
docs/how-to-debug-a-hyperlight-guest.md Show resolved Hide resolved
src/hyperlight_host/build.rs Outdated Show resolved Hide resolved
src/hyperlight_host/src/hypervisor/gdb/mod.rs Outdated Show resolved Hide resolved
src/hyperlight_host/src/hypervisor/kvm.rs Outdated Show resolved Hide resolved
src/hyperlight_host/src/sandbox/mem_access.rs Show resolved Hide resolved
Copy link
Contributor

@syntactically syntactically left a comment

Choose a reason for hiding this comment

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

I really like how this looks overall! I've left a few small things in the code comments. I also have a couple of nits about the commit organization:

Commit message for 579b324: s/tread/thread/

Commits b175f41, af0a52a, 6cc6184, and 98ac60e: please convert
each one to a series of fixup! commits to the original commits
introducing code, so that we can autosquash before merging, or just
rebase the changes into the original commits now if nobody else
objects to that.

src/hyperlight_host/src/sandbox/config.rs Outdated Show resolved Hide resolved
src/hyperlight_host/src/sandbox/uninitialized.rs Outdated Show resolved Hide resolved
src/hyperlight_host/src/hypervisor/gdb/x86_64_target.rs Outdated Show resolved Hide resolved
src/hyperlight_host/src/sandbox/mem_access.rs Outdated Show resolved Hide resolved
src/hyperlight_host/src/hypervisor/gdb/mod.rs Show resolved Hide resolved
src/hyperlight_host/src/hypervisor/gdb/x86_64_target.rs Outdated Show resolved Hide resolved
src/hyperlight_host/src/hypervisor/kvm.rs Show resolved Hide resolved
dblnz added 13 commits February 13, 2025 19:07
Signed-off-by: Doru Blânzeanu <[email protected]>
- this type will be used by the gdb and the hypervisor handler
to send requests and receive responses

Signed-off-by: Doru Blânzeanu <[email protected]>
- the target implements the  traits to provide callbacks
for the gdb commands

Signed-off-by: Doru Blânzeanu <[email protected]>
- adds a specific handler for the vcpu exit debug that waits for
debug messages and processes them

Signed-off-by: Doru Blânzeanu <[email protected]>
Signed-off-by: Doru Blânzeanu <[email protected]>
- also adds handling of gdb client disconnect by resuming execution

Signed-off-by: Doru Blânzeanu <[email protected]>
Signed-off-by: Doru Blânzeanu <[email protected]>
Signed-off-by: Doru Blânzeanu <[email protected]>
- sometimes gdb tries to read from an address where the vcpu translate
  method fails, so we need to handle that in such a way that the
  hypervisor handler doesn't crash

Signed-off-by: Doru Blânzeanu <[email protected]>
Signed-off-by: Doru Blânzeanu <[email protected]>
@dblnz dblnz requested a review from devigned February 13, 2025 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants