Skip to content

Commit

Permalink
kvmexit: Don't use raw tracepoint
Browse files Browse the repository at this point in the history
The kvm_exit tracepoint has the following proto ([0]):

  TP_PROTO(struct kvm_vcpu *vcpu, u32 isa)

So for raw tracepoint, the first arg is a pointer to kvm_vcpu,
not exit_reason. The exit_reason is hidden inside struct vcpu_vmx
for Intel CPU (or struct vcpu_svm for AMD CPU). Both structs are
not part of the UAPI, so it's hard to extract exit_reason.
Let's always use the kvm_exit tracepoint instead.

  [0]: https://github.com/torvalds/linux/blob/1ef6663a587b/arch/x86/kvm/trace.h#L296

Signed-off-by: Hengqi Chen <[email protected]>
  • Loading branch information
chenhengqi authored and yonghong-song committed Jun 28, 2023
1 parent 02daf8d commit 8f3b2db
Showing 1 changed file with 2 additions and 19 deletions.
21 changes: 2 additions & 19 deletions tools/kvmexit.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ def valid_args_list(args):
};
BPF_PERCPU_ARRAY(pcpu_cache, struct cache_info, 1);
FUNC_ENTRY {
TRACEPOINT_PROBE(kvm, kvm_exit) {
int cache_miss = 0;
int zero = 0;
u32 er = GET_ER;
u32 er = args->exit_reason;
if (er >= REASON_NUM) {
return 0;
}
Expand Down Expand Up @@ -256,19 +256,6 @@ def valid_args_list(args):
except Exception as e:
raise Exception("Failed to do precondition check, due to: %s." % e)

try:
if BPF.support_raw_tracepoint_in_module():
# Let's firstly try raw_tracepoint_in_module
func_entry = "RAW_TRACEPOINT_PROBE(kvm_exit)"
get_er = "ctx->args[0]"
else:
# If raw_tp_in_module is not supported, fall back to regular tp
func_entry = "TRACEPOINT_PROBE(kvm, kvm_exit)"
get_er = "args->exit_reason"
except Exception as e:
raise Exception("Failed to catch kvm exit reasons due to: %s" % e)


def find_tid(tgt_dir, tgt_vcpu):
for tid in os.listdir(tgt_dir):
path = tgt_dir + "/" + tid + "/comm"
Expand Down Expand Up @@ -309,10 +296,6 @@ def find_tid(tgt_dir, tgt_vcpu):
thread_filter = '0'
header_format = "PID TID "
bpf_text = bpf_text.replace('THREAD_FILTER', thread_filter)

# For kernel >= 5.0, use RAW_TRACEPOINT_MODULE for performance consideration
bpf_text = bpf_text.replace('FUNC_ENTRY', func_entry)
bpf_text = bpf_text.replace('GET_ER', get_er)
b = BPF(text=bpf_text)


Expand Down

0 comments on commit 8f3b2db

Please sign in to comment.