Skip to content

Commit cd0901c

Browse files
avagingvisor-bot
authored andcommitted
kvm: add more debug info on unexpected exits
PiperOrigin-RevId: 829616436
1 parent 6792b9a commit cd0901c

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

pkg/sentry/platform/kvm/bluepill_amd64_unsafe.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ func (c *vCPU) dieArchSetup(context *arch.SignalContext64, guestRegs *userRegs,
6161
context.Rbp = guestRegs.RBP
6262
context.Eflags = guestRegs.RFLAGS
6363
}
64+
printHex([]byte("FATAL: rip = "), guestRegs.RIP)
65+
printHex([]byte("FATAL: rsp = "), guestRegs.RSP)
66+
printHex([]byte("FATAL: rbp = "), guestRegs.RBP)
67+
printHex([]byte("FATAL: rflags = "), guestRegs.RFLAGS)
6468
if dumpExitReason {
6569
// Store the original instruction pointer in R9 and populates
6670
// registers R10-R14 with the vCPU's exit reason and associated

pkg/sentry/platform/kvm/bluepill_unsafe.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,33 @@ func printHex(title []byte, val uint64) {
9696
hostsyscall.RawSyscallErrno(unix.SYS_WRITE, uintptr(unix.Stderr), uintptr(unsafe.Pointer(&str)), 18)
9797
}
9898

99+
//go:nosplit
100+
func logKVMExitReason(c *vCPU, exitReason int) {
101+
printHex(printHexTitles[exitReason], uint64(c.runData.data[0]))
102+
}
103+
104+
const (
105+
kvmExitExceptionStr = iota
106+
kvmExitIOStr
107+
kvmExitInternalErrorStr
108+
kvmExitHypercallStr
109+
kvmExitDebugStr
110+
kvmExitMMIOStr
111+
kvmExitShutdownStr
112+
kvmExitFailEntryStr
113+
)
114+
115+
var printHexTitles = [8][]byte{
116+
kvmExitExceptionStr: []byte("unexpected exception exit: "),
117+
kvmExitIOStr: []byte("unexpected I/O exit: "),
118+
kvmExitInternalErrorStr: []byte("unexpected internal_error exit: "),
119+
kvmExitHypercallStr: []byte("unexpected hypercall exit: "),
120+
kvmExitDebugStr: []byte("unexpected debug exit: "),
121+
kvmExitMMIOStr: []byte("unexpected MMIO exit: "),
122+
kvmExitShutdownStr: []byte("unexpected shutdown exit: "),
123+
kvmExitFailEntryStr: []byte("unexpected fail_entry exit: "),
124+
}
125+
99126
// bluepillHandler is called from the signal stub.
100127
//
101128
// The world may be stopped while this is executing, and it executes on the
@@ -183,9 +210,11 @@ func bluepillHandler(context unsafe.Pointer) {
183210

184211
switch c.runData.exitReason {
185212
case _KVM_EXIT_EXCEPTION:
213+
logKVMExitReason(c, kvmExitExceptionStr)
186214
c.die(bluepillArchContext(context), "exception")
187215
return
188216
case _KVM_EXIT_IO:
217+
logKVMExitReason(c, kvmExitIOStr)
189218
c.die(bluepillArchContext(context), "I/O")
190219
return
191220
case _KVM_EXIT_INTERNAL_ERROR:
@@ -194,10 +223,13 @@ func bluepillHandler(context unsafe.Pointer) {
194223
// it might fail because we have multiple regions that
195224
// are not mapped). We would actually prefer that no
196225
// emulation occur, and don't mind at all if it fails.
226+
logKVMExitReason(c, kvmExitInternalErrorStr)
197227
case _KVM_EXIT_HYPERCALL:
228+
logKVMExitReason(c, kvmExitHypercallStr)
198229
c.die(bluepillArchContext(context), "hypercall")
199230
return
200231
case _KVM_EXIT_DEBUG:
232+
logKVMExitReason(c, kvmExitDebugStr)
201233
c.die(bluepillArchContext(context), "debug")
202234
return
203235
case _KVM_EXIT_HLT:
@@ -210,14 +242,17 @@ func bluepillHandler(context unsafe.Pointer) {
210242
return
211243
}
212244

245+
logKVMExitReason(c, kvmExitMMIOStr)
213246
c.die(bluepillArchContext(context), "exit_mmio")
214247
return
215248
case _KVM_EXIT_IRQ_WINDOW_OPEN:
216249
bluepillStopGuest(c)
217250
case _KVM_EXIT_SHUTDOWN:
251+
logKVMExitReason(c, kvmExitShutdownStr)
218252
c.die(bluepillArchContext(context), "shutdown")
219253
return
220254
case _KVM_EXIT_FAIL_ENTRY:
255+
logKVMExitReason(c, kvmExitFailEntryStr)
221256
c.dieAndDumpExitReason(bluepillArchContext(context))
222257
return
223258
default:

0 commit comments

Comments
 (0)