-
Notifications
You must be signed in to change notification settings - Fork 142
Add ability to debug additional registers via gdb #817
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -16,6 +16,7 @@ limitations under the License. | |||||
|
||||||
use std::collections::HashMap; | ||||||
|
||||||
use gdbstub_arch::msp430::reg; | ||||||
use kvm_bindings::{ | ||||||
KVM_GUESTDBG_ENABLE, KVM_GUESTDBG_SINGLESTEP, KVM_GUESTDBG_USE_HW_BP, KVM_GUESTDBG_USE_SW_BP, | ||||||
kvm_debug_exit_arch, kvm_guest_debug, kvm_regs, | ||||||
|
@@ -193,6 +194,31 @@ impl GuestDebug for KvmDebug { | |||||
regs.rip = vcpu_regs.rip; | ||||||
regs.rflags = vcpu_regs.rflags; | ||||||
|
||||||
// Read XMM registers from FPU state | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
// note kvm get_fpu doesn't actually set or read the mxcsr value | ||||||
// https://elixir.bootlin.com/linux/v6.16/source/arch/x86/kvm/x86.c#L12229 | ||||||
match vcpu_fd.get_fpu() { | ||||||
Ok(fpu) => { | ||||||
// Convert KVM XMM registers ([u8; 16] x 16) to [u128; 16] | ||||||
regs.xmm = fpu.xmm.map(u128::from_le_bytes); | ||||||
}, | ||||||
Err(e) => { | ||||||
log::warn!("Failed to read FPU state for XMM registers: {:?}", e); | ||||||
} | ||||||
} | ||||||
|
||||||
// Read MXCSR from XSAVE (MXCSR is at byte offset 24 -> u32 index 6) | ||||||
// Todo maybe I could use xsave to read the registers too instead of a separate call to get_fpu | ||||||
match vcpu_fd.get_xsave() { | ||||||
Ok(xsave) => { | ||||||
regs.mxcsr = xsave.region[6]; | ||||||
|
||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
Err(e) => { | ||||||
log::warn!("Failed to read XSAVE for MXCSR: {:?}", e); | ||||||
} | ||||||
} | ||||||
|
||||||
Ok(()) | ||||||
} | ||||||
|
||||||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -220,6 +220,18 @@ impl GuestDebug for MshvDebug { | |||
regs.rip = vcpu_regs.rip; | ||||
regs.rflags = vcpu_regs.rflags; | ||||
|
||||
// Try to read XMM from the FPU state | ||||
match vcpu_fd.get_fpu() { | ||||
Ok(fpu) => { | ||||
// MSHV exposes XMM as [[u8; 16]; 16]. Convert to [u128; 16] | ||||
regs.xmm = fpu.xmm.map(u128::from_le_bytes); | ||||
regs.mxcsr = fpu.mxcsr; | ||||
} | ||||
Err(e) => { | ||||
log::warn!("Failed to read FPU state for XMM registers (MSHV): {:?}", e); | ||||
} | ||||
} | ||||
|
||||
Ok(()) | ||||
} | ||||
|
||||
|
@@ -258,6 +270,8 @@ impl GuestDebug for MshvDebug { | |||
|
||||
rip: regs.rip, | ||||
rflags: regs.rflags, | ||||
|
||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
|
||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
}; | ||||
|
||||
vcpu_fd | ||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -591,6 +591,9 @@ impl Hypervisor for KVMDriver { | |
mxcsr: MXCSR_DEFAULT, | ||
..Default::default() // zero out the rest | ||
}; | ||
|
||
// note kvm set_fpu doesn't actually set or read the mxcsr value | ||
// https://elixir.bootlin.com/linux/v6.16/source/arch/x86/kvm/x86.c#L12229 | ||
self.vcpu_fd.set_fpu(&fpu)?; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How could we change the code to set/read the mxcsr value? |
||
|
||
// run | ||
|
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 this is not needed, right?