strace/xlat/kvm_exit_reason.in
Masatake YAMATO b7416438b8 kvm: attach the exit reason of vcpu as auxstr to KVM_RUN output
In KVM, a virtual machine implementation like Qemu can access a vcpu
via ioctl.  KVM_RUN is an ioctl command to enter vcpu.  The command
returns control for various reasons: needs of device emulation or
consuming time slices are the typical ones.  The vmi takes a different
action for the reason.

We, strace users, want to know the reason to understand kvm.  This
change prints the reason as auxstr if "-e kvm=vcpu" option is given,
and if strace runs on Linux 4.16.0 or higher, which includes commit
e46b469278a59781f9b25ff608af84892963821b, "kvm: embed vcpu id to dentry
of vcpu anon inode."

The way to get the reason is a bit complicated because the ioctl does
not return it to the userspace directly.  Instead, the vmi and kvm
communicate via an area of the process virtual memory where the fd of
vcpu is mmap'ed.  strace must peek the area to know the reason.

The change does three things: (1) recording the area for the given vcpu
when the target calls VCPU_CREATE to vcpu_info_list per tcb data field,
(2) verifying the data recorded in vcpu_info_list before doing (3), and
(3) decoding the exit reason field of the area.

The change is complicated because there is a case that strace
does not have a chance to do (1) if -p option is used.
In this case, vcpu_info data created in the step (2).

The area has more fields than "exit reason",
dumping them may be implemented in the future.

* defs.h (struct tcb) [HAVE_LINUX_KVM_H]: Add vcpu_info_list field.
[HAVE_LINUX_KVM_H]: (kvm_run_structure_decoder_init,
kvm_vcpu_info_free): New declarations.
* strace.c (usage): Add "kvm" as a new expression for -e option.
(droptcb): Call kvm_vcpu_info_free.
* filter_qualify.c (qualify_kvm): New function calling
kvm_run_structure_decoder_init to enable for attaching the exit
reason to auxstr.
(qual_options): Add "kvm" as an entry.
* xlat/kvm_exit_reason.in: New file.
* kvm.c: Include xmalloc.h and mmap_cache.h.
(dump_kvm_run_structure): New static variable.
(kvm_run_structure_decoder_init): New function.
(vcpu_info): New struct definition representing the 3-tuple: vcpu file
descriptor, id of the vcpu, and mmap'ed entry.
(vcpu_find, vcpu_alloc, vcpu_register, vcpu_getinfo,
kvm_vcpu_info_free): New functions to access tcb's vcpu_info_list
field and vcpu_info data type.
(is_map_for_file, map_len): New helper functions.
(kvm_ioclt_run_attach_auxstr, kvm_ioctl_decode_run): New functions
decoding vcpu exit reason and attaching the decoded data to auxstr
field of tcb.
(kvm_ioctl_create_vcpu): Call vcpu_register to make an entry mapping
a file descriptor and the vcpu id associated with the fd.
(kvm_ioctl): Call kvm_ioctl_decode_run.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
2018-07-07 10:29:02 +00:00

31 lines
639 B
Plaintext

#value_indexed
KVM_EXIT_UNKNOWN 0
KVM_EXIT_EXCEPTION 1
KVM_EXIT_IO 2
KVM_EXIT_HYPERCALL 3
KVM_EXIT_DEBUG 4
KVM_EXIT_HLT 5
KVM_EXIT_MMIO 6
KVM_EXIT_IRQ_WINDOW_OPEN 7
KVM_EXIT_SHUTDOWN 8
KVM_EXIT_FAIL_ENTRY 9
KVM_EXIT_INTR 10
KVM_EXIT_SET_TPR 11
KVM_EXIT_TPR_ACCESS 12
KVM_EXIT_S390_SIEIC 13
KVM_EXIT_S390_RESET 14
/* deprecated */
KVM_EXIT_DCR 15
KVM_EXIT_NMI 16
KVM_EXIT_INTERNAL_ERROR 17
KVM_EXIT_OSI 18
KVM_EXIT_PAPR_HCALL 19
KVM_EXIT_S390_UCONTROL 20
KVM_EXIT_WATCHDOG 21
KVM_EXIT_S390_TSCH 22
KVM_EXIT_EPR 23
KVM_EXIT_SYSTEM_EVENT 24
KVM_EXIT_S390_STSI 25
KVM_EXIT_IOAPIC_EOI 26
KVM_EXIT_HYPERV 27