trace.h 24.0 KB
Newer Older
1 2 3 4
#if !defined(_TRACE_KVM_H) || defined(TRACE_HEADER_MULTI_READ)
#define _TRACE_KVM_H

#include <linux/tracepoint.h>
5 6
#include <asm/vmx.h>
#include <asm/svm.h>
7
#include <asm/clocksource.h>
8
#include <asm/pvclock-abi.h>
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59

#undef TRACE_SYSTEM
#define TRACE_SYSTEM kvm

/*
 * Tracepoint for guest mode entry.
 */
TRACE_EVENT(kvm_entry,
	TP_PROTO(unsigned int vcpu_id),
	TP_ARGS(vcpu_id),

	TP_STRUCT__entry(
		__field(	unsigned int,	vcpu_id		)
	),

	TP_fast_assign(
		__entry->vcpu_id	= vcpu_id;
	),

	TP_printk("vcpu %u", __entry->vcpu_id)
);

/*
 * Tracepoint for hypercall.
 */
TRACE_EVENT(kvm_hypercall,
	TP_PROTO(unsigned long nr, unsigned long a0, unsigned long a1,
		 unsigned long a2, unsigned long a3),
	TP_ARGS(nr, a0, a1, a2, a3),

	TP_STRUCT__entry(
		__field(	unsigned long, 	nr		)
		__field(	unsigned long,	a0		)
		__field(	unsigned long,	a1		)
		__field(	unsigned long,	a2		)
		__field(	unsigned long,	a3		)
	),

	TP_fast_assign(
		__entry->nr		= nr;
		__entry->a0		= a0;
		__entry->a1		= a1;
		__entry->a2		= a2;
		__entry->a3		= a3;
	),

	TP_printk("nr 0x%lx a0 0x%lx a1 0x%lx a2 0x%lx a3 0x%lx",
		 __entry->nr, __entry->a0, __entry->a1,  __entry->a2,
		 __entry->a3)
);

60 61 62 63 64 65 66 67 68 69 70 71 72
/*
 * Tracepoint for hypercall.
 */
TRACE_EVENT(kvm_hv_hypercall,
	TP_PROTO(__u16 code, bool fast, __u16 rep_cnt, __u16 rep_idx,
		 __u64 ingpa, __u64 outgpa),
	TP_ARGS(code, fast, rep_cnt, rep_idx, ingpa, outgpa),

	TP_STRUCT__entry(
		__field(	__u16,		rep_cnt		)
		__field(	__u16,		rep_idx		)
		__field(	__u64,		ingpa		)
		__field(	__u64,		outgpa		)
73 74
		__field(	__u16, 		code		)
		__field(	bool,		fast		)
75 76 77 78 79 80 81
	),

	TP_fast_assign(
		__entry->rep_cnt	= rep_cnt;
		__entry->rep_idx	= rep_idx;
		__entry->ingpa		= ingpa;
		__entry->outgpa		= outgpa;
82 83
		__entry->code		= code;
		__entry->fast		= fast;
84 85 86 87 88 89 90 91
	),

	TP_printk("code 0x%x %s cnt 0x%x idx 0x%x in 0x%llx out 0x%llx",
		  __entry->code, __entry->fast ? "fast" : "slow",
		  __entry->rep_cnt, __entry->rep_idx,  __entry->ingpa,
		  __entry->outgpa)
);

92 93 94
/*
 * Tracepoint for PIO.
 */
95 96 97 98

#define KVM_PIO_IN   0
#define KVM_PIO_OUT  1

99 100
TRACE_EVENT(kvm_pio,
	TP_PROTO(unsigned int rw, unsigned int port, unsigned int size,
101 102
		 unsigned int count, void *data),
	TP_ARGS(rw, port, size, count, data),
103 104 105 106 107 108

	TP_STRUCT__entry(
		__field(	unsigned int, 	rw		)
		__field(	unsigned int, 	port		)
		__field(	unsigned int, 	size		)
		__field(	unsigned int,	count		)
109
		__field(	unsigned int,	val		)
110 111 112 113 114 115 116
	),

	TP_fast_assign(
		__entry->rw		= rw;
		__entry->port		= port;
		__entry->size		= size;
		__entry->count		= count;
117 118 119 120 121 122
		if (size == 1)
			__entry->val	= *(unsigned char *)data;
		else if (size == 2)
			__entry->val	= *(unsigned short *)data;
		else
			__entry->val	= *(unsigned int *)data;
123 124
	),

125
	TP_printk("pio_%s at 0x%x size %d count %d val 0x%x %s",
126
		  __entry->rw ? "write" : "read",
127 128
		  __entry->port, __entry->size, __entry->count, __entry->val,
		  __entry->count > 1 ? "(...)" : "")
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
);

/*
 * Tracepoint for cpuid.
 */
TRACE_EVENT(kvm_cpuid,
	TP_PROTO(unsigned int function, unsigned long rax, unsigned long rbx,
		 unsigned long rcx, unsigned long rdx),
	TP_ARGS(function, rax, rbx, rcx, rdx),

	TP_STRUCT__entry(
		__field(	unsigned int,	function	)
		__field(	unsigned long,	rax		)
		__field(	unsigned long,	rbx		)
		__field(	unsigned long,	rcx		)
		__field(	unsigned long,	rdx		)
	),

	TP_fast_assign(
		__entry->function	= function;
		__entry->rax		= rax;
		__entry->rbx		= rbx;
		__entry->rcx		= rcx;
		__entry->rdx		= rdx;
	),

	TP_printk("func %x rax %lx rbx %lx rcx %lx rdx %lx",
		  __entry->function, __entry->rax,
		  __entry->rbx, __entry->rcx, __entry->rdx)
);

160 161 162 163 164 165 166 167 168
#define AREG(x) { APIC_##x, "APIC_" #x }

#define kvm_trace_symbol_apic						    \
	AREG(ID), AREG(LVR), AREG(TASKPRI), AREG(ARBPRI), AREG(PROCPRI),    \
	AREG(EOI), AREG(RRR), AREG(LDR), AREG(DFR), AREG(SPIV), AREG(ISR),  \
	AREG(TMR), AREG(IRR), AREG(ESR), AREG(ICR), AREG(ICR2), AREG(LVTT), \
	AREG(LVTTHMR), AREG(LVTPC), AREG(LVT0), AREG(LVT1), AREG(LVTERR),   \
	AREG(TMICT), AREG(TMCCT), AREG(TDCR), AREG(SELF_IPI), AREG(EFEAT),  \
	AREG(ECTRL)
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
/*
 * Tracepoint for apic access.
 */
TRACE_EVENT(kvm_apic,
	TP_PROTO(unsigned int rw, unsigned int reg, unsigned int val),
	TP_ARGS(rw, reg, val),

	TP_STRUCT__entry(
		__field(	unsigned int,	rw		)
		__field(	unsigned int,	reg		)
		__field(	unsigned int,	val		)
	),

	TP_fast_assign(
		__entry->rw		= rw;
		__entry->reg		= reg;
		__entry->val		= val;
	),

188
	TP_printk("apic_%s %s = 0x%x",
189
		  __entry->rw ? "write" : "read",
190 191
		  __print_symbolic(__entry->reg, kvm_trace_symbol_apic),
		  __entry->val)
192 193 194 195 196
);

#define trace_kvm_apic_read(reg, val)		trace_kvm_apic(0, reg, val)
#define trace_kvm_apic_write(reg, val)		trace_kvm_apic(1, reg, val)

197 198 199
#define KVM_ISA_VMX   1
#define KVM_ISA_SVM   2

200 201 202 203
/*
 * Tracepoint for kvm guest exit:
 */
TRACE_EVENT(kvm_exit,
204 205
	TP_PROTO(unsigned int exit_reason, struct kvm_vcpu *vcpu, u32 isa),
	TP_ARGS(exit_reason, vcpu, isa),
206 207 208 209

	TP_STRUCT__entry(
		__field(	unsigned int,	exit_reason	)
		__field(	unsigned long,	guest_rip	)
210
		__field(	u32,	        isa             )
211 212
		__field(	u64,	        info1           )
		__field(	u64,	        info2           )
213 214 215 216
	),

	TP_fast_assign(
		__entry->exit_reason	= exit_reason;
217
		__entry->guest_rip	= kvm_rip_read(vcpu);
218
		__entry->isa            = isa;
219 220
		kvm_x86_ops->get_exit_info(vcpu, &__entry->info1,
					   &__entry->info2);
221 222
	),

223
	TP_printk("reason %s rip 0x%lx info %llx %llx",
224 225 226
		 (__entry->isa == KVM_ISA_VMX) ?
		 __print_symbolic(__entry->exit_reason, VMX_EXIT_REASONS) :
		 __print_symbolic(__entry->exit_reason, SVM_EXIT_REASONS),
227
		 __entry->guest_rip, __entry->info1, __entry->info2)
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
);

/*
 * Tracepoint for kvm interrupt injection:
 */
TRACE_EVENT(kvm_inj_virq,
	TP_PROTO(unsigned int irq),
	TP_ARGS(irq),

	TP_STRUCT__entry(
		__field(	unsigned int,	irq		)
	),

	TP_fast_assign(
		__entry->irq		= irq;
	),

	TP_printk("irq %u", __entry->irq)
);

A
Avi Kivity 已提交
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
#define EXS(x) { x##_VECTOR, "#" #x }

#define kvm_trace_sym_exc						\
	EXS(DE), EXS(DB), EXS(BP), EXS(OF), EXS(BR), EXS(UD), EXS(NM),	\
	EXS(DF), EXS(TS), EXS(NP), EXS(SS), EXS(GP), EXS(PF),		\
	EXS(MF), EXS(MC)

/*
 * Tracepoint for kvm interrupt injection:
 */
TRACE_EVENT(kvm_inj_exception,
	TP_PROTO(unsigned exception, bool has_error, unsigned error_code),
	TP_ARGS(exception, has_error, error_code),

	TP_STRUCT__entry(
		__field(	u8,	exception	)
		__field(	u8,	has_error	)
		__field(	u32,	error_code	)
	),

	TP_fast_assign(
		__entry->exception	= exception;
		__entry->has_error	= has_error;
		__entry->error_code	= error_code;
	),

	TP_printk("%s (0x%x)",
		  __print_symbolic(__entry->exception, kvm_trace_sym_exc),
		  /* FIXME: don't print error_code if not present */
		  __entry->has_error ? __entry->error_code : 0)
);

280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304
/*
 * Tracepoint for page fault.
 */
TRACE_EVENT(kvm_page_fault,
	TP_PROTO(unsigned long fault_address, unsigned int error_code),
	TP_ARGS(fault_address, error_code),

	TP_STRUCT__entry(
		__field(	unsigned long,	fault_address	)
		__field(	unsigned int,	error_code	)
	),

	TP_fast_assign(
		__entry->fault_address	= fault_address;
		__entry->error_code	= error_code;
	),

	TP_printk("address %lx error_code %x",
		  __entry->fault_address, __entry->error_code)
);

/*
 * Tracepoint for guest MSR access.
 */
TRACE_EVENT(kvm_msr,
305 306
	TP_PROTO(unsigned write, u32 ecx, u64 data, bool exception),
	TP_ARGS(write, ecx, data, exception),
307 308

	TP_STRUCT__entry(
A
Avi Kivity 已提交
309 310 311
		__field(	unsigned,	write		)
		__field(	u32,		ecx		)
		__field(	u64,		data		)
312
		__field(	u8,		exception	)
313 314 315
	),

	TP_fast_assign(
A
Avi Kivity 已提交
316
		__entry->write		= write;
317 318
		__entry->ecx		= ecx;
		__entry->data		= data;
319
		__entry->exception	= exception;
320 321
	),

322
	TP_printk("msr_%s %x = 0x%llx%s",
A
Avi Kivity 已提交
323
		  __entry->write ? "write" : "read",
324 325
		  __entry->ecx, __entry->data,
		  __entry->exception ? " (#GP)" : "")
326 327
);

328 329 330 331
#define trace_kvm_msr_read(ecx, data)      trace_kvm_msr(0, ecx, data, false)
#define trace_kvm_msr_write(ecx, data)     trace_kvm_msr(1, ecx, data, false)
#define trace_kvm_msr_read_ex(ecx)         trace_kvm_msr(0, ecx, 0, true)
#define trace_kvm_msr_write_ex(ecx, data)  trace_kvm_msr(1, ecx, data, true)
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359

/*
 * Tracepoint for guest CR access.
 */
TRACE_EVENT(kvm_cr,
	TP_PROTO(unsigned int rw, unsigned int cr, unsigned long val),
	TP_ARGS(rw, cr, val),

	TP_STRUCT__entry(
		__field(	unsigned int,	rw		)
		__field(	unsigned int,	cr		)
		__field(	unsigned long,	val		)
	),

	TP_fast_assign(
		__entry->rw		= rw;
		__entry->cr		= cr;
		__entry->val		= val;
	),

	TP_printk("cr_%s %x = 0x%lx",
		  __entry->rw ? "write" : "read",
		  __entry->cr, __entry->val)
);

#define trace_kvm_cr_read(cr, val)		trace_kvm_cr(0, cr, val)
#define trace_kvm_cr_write(cr, val)		trace_kvm_cr(1, cr, val)

360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418
TRACE_EVENT(kvm_pic_set_irq,
	    TP_PROTO(__u8 chip, __u8 pin, __u8 elcr, __u8 imr, bool coalesced),
	    TP_ARGS(chip, pin, elcr, imr, coalesced),

	TP_STRUCT__entry(
		__field(	__u8,		chip		)
		__field(	__u8,		pin		)
		__field(	__u8,		elcr		)
		__field(	__u8,		imr		)
		__field(	bool,		coalesced	)
	),

	TP_fast_assign(
		__entry->chip		= chip;
		__entry->pin		= pin;
		__entry->elcr		= elcr;
		__entry->imr		= imr;
		__entry->coalesced	= coalesced;
	),

	TP_printk("chip %u pin %u (%s%s)%s",
		  __entry->chip, __entry->pin,
		  (__entry->elcr & (1 << __entry->pin)) ? "level":"edge",
		  (__entry->imr & (1 << __entry->pin)) ? "|masked":"",
		  __entry->coalesced ? " (coalesced)" : "")
);

#define kvm_apic_dst_shorthand		\
	{0x0, "dst"},			\
	{0x1, "self"},			\
	{0x2, "all"},			\
	{0x3, "all-but-self"}

TRACE_EVENT(kvm_apic_ipi,
	    TP_PROTO(__u32 icr_low, __u32 dest_id),
	    TP_ARGS(icr_low, dest_id),

	TP_STRUCT__entry(
		__field(	__u32,		icr_low		)
		__field(	__u32,		dest_id		)
	),

	TP_fast_assign(
		__entry->icr_low	= icr_low;
		__entry->dest_id	= dest_id;
	),

	TP_printk("dst %x vec %u (%s|%s|%s|%s|%s)",
		  __entry->dest_id, (u8)__entry->icr_low,
		  __print_symbolic((__entry->icr_low >> 8 & 0x7),
				   kvm_deliver_mode),
		  (__entry->icr_low & (1<<11)) ? "logical" : "physical",
		  (__entry->icr_low & (1<<14)) ? "assert" : "de-assert",
		  (__entry->icr_low & (1<<15)) ? "level" : "edge",
		  __print_symbolic((__entry->icr_low >> 18 & 0x3),
				   kvm_apic_dst_shorthand))
);

TRACE_EVENT(kvm_apic_accept_irq,
419 420
	    TP_PROTO(__u32 apicid, __u16 dm, __u8 tm, __u8 vec),
	    TP_ARGS(apicid, dm, tm, vec),
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435

	TP_STRUCT__entry(
		__field(	__u32,		apicid		)
		__field(	__u16,		dm		)
		__field(	__u8,		tm		)
		__field(	__u8,		vec		)
	),

	TP_fast_assign(
		__entry->apicid		= apicid;
		__entry->dm		= dm;
		__entry->tm		= tm;
		__entry->vec		= vec;
	),

436
	TP_printk("apicid %x vec %u (%s|%s)",
437 438
		  __entry->apicid, __entry->vec,
		  __print_symbolic((__entry->dm >> 8 & 0x7), kvm_deliver_mode),
439
		  __entry->tm ? "level" : "edge")
440 441
);

442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475
TRACE_EVENT(kvm_eoi,
	    TP_PROTO(struct kvm_lapic *apic, int vector),
	    TP_ARGS(apic, vector),

	TP_STRUCT__entry(
		__field(	__u32,		apicid		)
		__field(	int,		vector		)
	),

	TP_fast_assign(
		__entry->apicid		= apic->vcpu->vcpu_id;
		__entry->vector		= vector;
	),

	TP_printk("apicid %x vector %d", __entry->apicid, __entry->vector)
);

TRACE_EVENT(kvm_pv_eoi,
	    TP_PROTO(struct kvm_lapic *apic, int vector),
	    TP_ARGS(apic, vector),

	TP_STRUCT__entry(
		__field(	__u32,		apicid		)
		__field(	int,		vector		)
	),

	TP_fast_assign(
		__entry->apicid		= apic->vcpu->vcpu_id;
		__entry->vector		= vector;
	),

	TP_printk("apicid %x vector %d", __entry->apicid, __entry->vector)
);

476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502
/*
 * Tracepoint for nested VMRUN
 */
TRACE_EVENT(kvm_nested_vmrun,
	    TP_PROTO(__u64 rip, __u64 vmcb, __u64 nested_rip, __u32 int_ctl,
		     __u32 event_inj, bool npt),
	    TP_ARGS(rip, vmcb, nested_rip, int_ctl, event_inj, npt),

	TP_STRUCT__entry(
		__field(	__u64,		rip		)
		__field(	__u64,		vmcb		)
		__field(	__u64,		nested_rip	)
		__field(	__u32,		int_ctl		)
		__field(	__u32,		event_inj	)
		__field(	bool,		npt		)
	),

	TP_fast_assign(
		__entry->rip		= rip;
		__entry->vmcb		= vmcb;
		__entry->nested_rip	= nested_rip;
		__entry->int_ctl	= int_ctl;
		__entry->event_inj	= event_inj;
		__entry->npt		= npt;
	),

	TP_printk("rip: 0x%016llx vmcb: 0x%016llx nrip: 0x%016llx int_ctl: 0x%08x "
503
		  "event_inj: 0x%08x npt: %s",
504 505 506 507 508
		__entry->rip, __entry->vmcb, __entry->nested_rip,
		__entry->int_ctl, __entry->event_inj,
		__entry->npt ? "on" : "off")
);

509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530
TRACE_EVENT(kvm_nested_intercepts,
	    TP_PROTO(__u16 cr_read, __u16 cr_write, __u32 exceptions, __u64 intercept),
	    TP_ARGS(cr_read, cr_write, exceptions, intercept),

	TP_STRUCT__entry(
		__field(	__u16,		cr_read		)
		__field(	__u16,		cr_write	)
		__field(	__u32,		exceptions	)
		__field(	__u64,		intercept	)
	),

	TP_fast_assign(
		__entry->cr_read	= cr_read;
		__entry->cr_write	= cr_write;
		__entry->exceptions	= exceptions;
		__entry->intercept	= intercept;
	),

	TP_printk("cr_read: %04x cr_write: %04x excp: %08x intercept: %016llx",
		__entry->cr_read, __entry->cr_write, __entry->exceptions,
		__entry->intercept)
);
531 532 533 534 535 536
/*
 * Tracepoint for #VMEXIT while nested
 */
TRACE_EVENT(kvm_nested_vmexit,
	    TP_PROTO(__u64 rip, __u32 exit_code,
		     __u64 exit_info1, __u64 exit_info2,
537
		     __u32 exit_int_info, __u32 exit_int_info_err, __u32 isa),
538
	    TP_ARGS(rip, exit_code, exit_info1, exit_info2,
539
		    exit_int_info, exit_int_info_err, isa),
540 541 542 543 544 545 546 547

	TP_STRUCT__entry(
		__field(	__u64,		rip			)
		__field(	__u32,		exit_code		)
		__field(	__u64,		exit_info1		)
		__field(	__u64,		exit_info2		)
		__field(	__u32,		exit_int_info		)
		__field(	__u32,		exit_int_info_err	)
548
		__field(	__u32,		isa			)
549 550 551 552 553 554 555 556 557
	),

	TP_fast_assign(
		__entry->rip			= rip;
		__entry->exit_code		= exit_code;
		__entry->exit_info1		= exit_info1;
		__entry->exit_info2		= exit_info2;
		__entry->exit_int_info		= exit_int_info;
		__entry->exit_int_info_err	= exit_int_info_err;
558
		__entry->isa			= isa;
559 560
	),
	TP_printk("rip: 0x%016llx reason: %s ext_inf1: 0x%016llx "
561
		  "ext_inf2: 0x%016llx ext_int: 0x%08x ext_int_err: 0x%08x",
562
		  __entry->rip,
563 564 565
		 (__entry->isa == KVM_ISA_VMX) ?
		 __print_symbolic(__entry->exit_code, VMX_EXIT_REASONS) :
		 __print_symbolic(__entry->exit_code, SVM_EXIT_REASONS),
566 567 568 569
		  __entry->exit_info1, __entry->exit_info2,
		  __entry->exit_int_info, __entry->exit_int_info_err)
);

570 571 572 573 574 575
/*
 * Tracepoint for #VMEXIT reinjected to the guest
 */
TRACE_EVENT(kvm_nested_vmexit_inject,
	    TP_PROTO(__u32 exit_code,
		     __u64 exit_info1, __u64 exit_info2,
576
		     __u32 exit_int_info, __u32 exit_int_info_err, __u32 isa),
577
	    TP_ARGS(exit_code, exit_info1, exit_info2,
578
		    exit_int_info, exit_int_info_err, isa),
579 580 581 582 583 584 585

	TP_STRUCT__entry(
		__field(	__u32,		exit_code		)
		__field(	__u64,		exit_info1		)
		__field(	__u64,		exit_info2		)
		__field(	__u32,		exit_int_info		)
		__field(	__u32,		exit_int_info_err	)
586
		__field(	__u32,		isa			)
587 588 589 590 591 592 593 594
	),

	TP_fast_assign(
		__entry->exit_code		= exit_code;
		__entry->exit_info1		= exit_info1;
		__entry->exit_info2		= exit_info2;
		__entry->exit_int_info		= exit_int_info;
		__entry->exit_int_info_err	= exit_int_info_err;
595
		__entry->isa			= isa;
596 597 598
	),

	TP_printk("reason: %s ext_inf1: 0x%016llx "
599
		  "ext_inf2: 0x%016llx ext_int: 0x%08x ext_int_err: 0x%08x",
600 601 602
		 (__entry->isa == KVM_ISA_VMX) ?
		 __print_symbolic(__entry->exit_code, VMX_EXIT_REASONS) :
		 __print_symbolic(__entry->exit_code, SVM_EXIT_REASONS),
603 604 605
		__entry->exit_info1, __entry->exit_info2,
		__entry->exit_int_info, __entry->exit_int_info_err)
);
606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621

/*
 * Tracepoint for nested #vmexit because of interrupt pending
 */
TRACE_EVENT(kvm_nested_intr_vmexit,
	    TP_PROTO(__u64 rip),
	    TP_ARGS(rip),

	TP_STRUCT__entry(
		__field(	__u64,	rip	)
	),

	TP_fast_assign(
		__entry->rip	=	rip
	),

622
	TP_printk("rip: 0x%016llx", __entry->rip)
623
);
624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643

/*
 * Tracepoint for nested #vmexit because of interrupt pending
 */
TRACE_EVENT(kvm_invlpga,
	    TP_PROTO(__u64 rip, int asid, u64 address),
	    TP_ARGS(rip, asid, address),

	TP_STRUCT__entry(
		__field(	__u64,	rip	)
		__field(	int,	asid	)
		__field(	__u64,	address	)
	),

	TP_fast_assign(
		__entry->rip		=	rip;
		__entry->asid		=	asid;
		__entry->address	=	address;
	),

644
	TP_printk("rip: 0x%016llx asid: %d address: 0x%016llx",
645 646
		  __entry->rip, __entry->asid, __entry->address)
);
647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664

/*
 * Tracepoint for nested #vmexit because of interrupt pending
 */
TRACE_EVENT(kvm_skinit,
	    TP_PROTO(__u64 rip, __u32 slb),
	    TP_ARGS(rip, slb),

	TP_STRUCT__entry(
		__field(	__u64,	rip	)
		__field(	__u32,	slb	)
	),

	TP_fast_assign(
		__entry->rip		=	rip;
		__entry->slb		=	slb;
	),

665
	TP_printk("rip: 0x%016llx slb: 0x%08x",
666 667 668
		  __entry->rip, __entry->slb)
);

A
Avi Kivity 已提交
669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722
#define KVM_EMUL_INSN_F_CR0_PE (1 << 0)
#define KVM_EMUL_INSN_F_EFL_VM (1 << 1)
#define KVM_EMUL_INSN_F_CS_D   (1 << 2)
#define KVM_EMUL_INSN_F_CS_L   (1 << 3)

#define kvm_trace_symbol_emul_flags	                  \
	{ 0,   			    "real" },		  \
	{ KVM_EMUL_INSN_F_CR0_PE			  \
	  | KVM_EMUL_INSN_F_EFL_VM, "vm16" },		  \
	{ KVM_EMUL_INSN_F_CR0_PE,   "prot16" },		  \
	{ KVM_EMUL_INSN_F_CR0_PE			  \
	  | KVM_EMUL_INSN_F_CS_D,   "prot32" },		  \
	{ KVM_EMUL_INSN_F_CR0_PE			  \
	  | KVM_EMUL_INSN_F_CS_L,   "prot64" }

#define kei_decode_mode(mode) ({			\
	u8 flags = 0xff;				\
	switch (mode) {					\
	case X86EMUL_MODE_REAL:				\
		flags = 0;				\
		break;					\
	case X86EMUL_MODE_VM86:				\
		flags = KVM_EMUL_INSN_F_EFL_VM;		\
		break;					\
	case X86EMUL_MODE_PROT16:			\
		flags = KVM_EMUL_INSN_F_CR0_PE;		\
		break;					\
	case X86EMUL_MODE_PROT32:			\
		flags = KVM_EMUL_INSN_F_CR0_PE		\
			| KVM_EMUL_INSN_F_CS_D;		\
		break;					\
	case X86EMUL_MODE_PROT64:			\
		flags = KVM_EMUL_INSN_F_CR0_PE		\
			| KVM_EMUL_INSN_F_CS_L;		\
		break;					\
	}						\
	flags;						\
	})

TRACE_EVENT(kvm_emulate_insn,
	TP_PROTO(struct kvm_vcpu *vcpu, __u8 failed),
	TP_ARGS(vcpu, failed),

	TP_STRUCT__entry(
		__field(    __u64, rip                       )
		__field(    __u32, csbase                    )
		__field(    __u8,  len                       )
		__array(    __u8,  insn,    15	             )
		__field(    __u8,  flags       	   	     )
		__field(    __u8,  failed                    )
		),

	TP_fast_assign(
		__entry->csbase = kvm_x86_ops->get_segment_base(vcpu, VCPU_SREG_CS);
723 724 725
		__entry->len = vcpu->arch.emulate_ctxt.fetch.ptr
			       - vcpu->arch.emulate_ctxt.fetch.data;
		__entry->rip = vcpu->arch.emulate_ctxt._eip - __entry->len;
A
Avi Kivity 已提交
726
		memcpy(__entry->insn,
727
		       vcpu->arch.emulate_ctxt.fetch.data,
A
Avi Kivity 已提交
728 729 730 731 732 733 734
		       15);
		__entry->flags = kei_decode_mode(vcpu->arch.emulate_ctxt.mode);
		__entry->failed = failed;
		),

	TP_printk("%x:%llx:%s (%s)%s",
		  __entry->csbase, __entry->rip,
735
		  __print_hex(__entry->insn, __entry->len),
A
Avi Kivity 已提交
736 737 738 739 740 741 742 743 744
		  __print_symbolic(__entry->flags,
				   kvm_trace_symbol_emul_flags),
		  __entry->failed ? " failed" : ""
		)
	);

#define trace_kvm_emulate_insn_start(vcpu) trace_kvm_emulate_insn(vcpu, 0)
#define trace_kvm_emulate_insn_failed(vcpu) trace_kvm_emulate_insn(vcpu, 1)

X
Xiao Guangrong 已提交
745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767
TRACE_EVENT(
	vcpu_match_mmio,
	TP_PROTO(gva_t gva, gpa_t gpa, bool write, bool gpa_match),
	TP_ARGS(gva, gpa, write, gpa_match),

	TP_STRUCT__entry(
		__field(gva_t, gva)
		__field(gpa_t, gpa)
		__field(bool, write)
		__field(bool, gpa_match)
		),

	TP_fast_assign(
		__entry->gva = gva;
		__entry->gpa = gpa;
		__entry->write = write;
		__entry->gpa_match = gpa_match
		),

	TP_printk("gva %#lx gpa %#llx %s %s", __entry->gva, __entry->gpa,
		  __entry->write ? "Write" : "Read",
		  __entry->gpa_match ? "GPA" : "GVA")
);
768

769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789
TRACE_EVENT(kvm_write_tsc_offset,
	TP_PROTO(unsigned int vcpu_id, __u64 previous_tsc_offset,
		 __u64 next_tsc_offset),
	TP_ARGS(vcpu_id, previous_tsc_offset, next_tsc_offset),

	TP_STRUCT__entry(
		__field( unsigned int,	vcpu_id				)
		__field(	__u64,	previous_tsc_offset		)
		__field(	__u64,	next_tsc_offset			)
	),

	TP_fast_assign(
		__entry->vcpu_id		= vcpu_id;
		__entry->previous_tsc_offset	= previous_tsc_offset;
		__entry->next_tsc_offset	= next_tsc_offset;
	),

	TP_printk("vcpu=%u prev=%llu next=%llu", __entry->vcpu_id,
		  __entry->previous_tsc_offset, __entry->next_tsc_offset)
);

790 791 792 793 794 795 796 797
#ifdef CONFIG_X86_64

#define host_clocks					\
	{VCLOCK_NONE, "none"},				\
	{VCLOCK_TSC,  "tsc"},				\
	{VCLOCK_HPET, "hpet"}				\

TRACE_EVENT(kvm_update_master_clock,
798 799
	TP_PROTO(bool use_master_clock, unsigned int host_clock, bool offset_matched),
	TP_ARGS(use_master_clock, host_clock, offset_matched),
800 801 802 803

	TP_STRUCT__entry(
		__field(		bool,	use_master_clock	)
		__field(	unsigned int,	host_clock		)
804
		__field(		bool,	offset_matched		)
805 806 807 808 809
	),

	TP_fast_assign(
		__entry->use_master_clock	= use_master_clock;
		__entry->host_clock		= host_clock;
810
		__entry->offset_matched		= offset_matched;
811 812
	),

813
	TP_printk("masterclock %d hostclock %s offsetmatched %u",
814
		  __entry->use_master_clock,
815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845
		  __print_symbolic(__entry->host_clock, host_clocks),
		  __entry->offset_matched)
);

TRACE_EVENT(kvm_track_tsc,
	TP_PROTO(unsigned int vcpu_id, unsigned int nr_matched,
		 unsigned int online_vcpus, bool use_master_clock,
		 unsigned int host_clock),
	TP_ARGS(vcpu_id, nr_matched, online_vcpus, use_master_clock,
		host_clock),

	TP_STRUCT__entry(
		__field(	unsigned int,	vcpu_id			)
		__field(	unsigned int,	nr_vcpus_matched_tsc	)
		__field(	unsigned int,	online_vcpus		)
		__field(	bool,		use_master_clock	)
		__field(	unsigned int,	host_clock		)
	),

	TP_fast_assign(
		__entry->vcpu_id		= vcpu_id;
		__entry->nr_vcpus_matched_tsc	= nr_matched;
		__entry->online_vcpus		= online_vcpus;
		__entry->use_master_clock	= use_master_clock;
		__entry->host_clock		= host_clock;
	),

	TP_printk("vcpu_id %u masterclock %u offsetmatched %u nr_online %u"
		  " hostclock %s",
		  __entry->vcpu_id, __entry->use_master_clock,
		  __entry->nr_vcpus_matched_tsc, __entry->online_vcpus,
846 847 848
		  __print_symbolic(__entry->host_clock, host_clocks))
);

P
Paolo Bonzini 已提交
849 850
#endif /* CONFIG_X86_64 */

K
Kai Huang 已提交
851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868
/*
 * Tracepoint for PML full VMEXIT.
 */
TRACE_EVENT(kvm_pml_full,
	TP_PROTO(unsigned int vcpu_id),
	TP_ARGS(vcpu_id),

	TP_STRUCT__entry(
		__field(	unsigned int,	vcpu_id			)
	),

	TP_fast_assign(
		__entry->vcpu_id		= vcpu_id;
	),

	TP_printk("vcpu %d: PML full", __entry->vcpu_id)
);

869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898
TRACE_EVENT(kvm_ple_window,
	TP_PROTO(bool grow, unsigned int vcpu_id, int new, int old),
	TP_ARGS(grow, vcpu_id, new, old),

	TP_STRUCT__entry(
		__field(                bool,      grow         )
		__field(        unsigned int,   vcpu_id         )
		__field(                 int,       new         )
		__field(                 int,       old         )
	),

	TP_fast_assign(
		__entry->grow           = grow;
		__entry->vcpu_id        = vcpu_id;
		__entry->new            = new;
		__entry->old            = old;
	),

	TP_printk("vcpu %u: ple_window %d (%s %d)",
	          __entry->vcpu_id,
	          __entry->new,
	          __entry->grow ? "grow" : "shrink",
	          __entry->old)
);

#define trace_kvm_ple_window_grow(vcpu_id, new, old) \
	trace_kvm_ple_window(true, vcpu_id, new, old)
#define trace_kvm_ple_window_shrink(vcpu_id, new, old) \
	trace_kvm_ple_window(false, vcpu_id, new, old)

899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934
TRACE_EVENT(kvm_pvclock_update,
	TP_PROTO(unsigned int vcpu_id, struct pvclock_vcpu_time_info *pvclock),
	TP_ARGS(vcpu_id, pvclock),

	TP_STRUCT__entry(
		__field(	unsigned int,	vcpu_id			)
		__field(	__u32,		version			)
		__field(	__u64,		tsc_timestamp		)
		__field(	__u64,		system_time		)
		__field(	__u32,		tsc_to_system_mul	)
		__field(	__s8,		tsc_shift		)
		__field(	__u8,		flags			)
	),

	TP_fast_assign(
		__entry->vcpu_id	   = vcpu_id;
		__entry->version	   = pvclock->version;
		__entry->tsc_timestamp	   = pvclock->tsc_timestamp;
		__entry->system_time	   = pvclock->system_time;
		__entry->tsc_to_system_mul = pvclock->tsc_to_system_mul;
		__entry->tsc_shift	   = pvclock->tsc_shift;
		__entry->flags		   = pvclock->flags;
	),

	TP_printk("vcpu_id %u, pvclock { version %u, tsc_timestamp 0x%llx, "
		  "system_time 0x%llx, tsc_to_system_mul 0x%x, tsc_shift %d, "
		  "flags 0x%x }",
		  __entry->vcpu_id,
		  __entry->version,
		  __entry->tsc_timestamp,
		  __entry->system_time,
		  __entry->tsc_to_system_mul,
		  __entry->tsc_shift,
		  __entry->flags)
);

935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954
TRACE_EVENT(kvm_wait_lapic_expire,
	TP_PROTO(unsigned int vcpu_id, s64 delta),
	TP_ARGS(vcpu_id, delta),

	TP_STRUCT__entry(
		__field(	unsigned int,	vcpu_id		)
		__field(	s64,		delta		)
	),

	TP_fast_assign(
		__entry->vcpu_id	   = vcpu_id;
		__entry->delta             = delta;
	),

	TP_printk("vcpu %u: delta %lld (%s)",
		  __entry->vcpu_id,
		  __entry->delta,
		  __entry->delta < 0 ? "early" : "late")
);

955 956
#endif /* _TRACE_KVM_H */

X
Xiao Guangrong 已提交
957 958 959 960 961
#undef TRACE_INCLUDE_PATH
#define TRACE_INCLUDE_PATH arch/x86/kvm
#undef TRACE_INCLUDE_FILE
#define TRACE_INCLUDE_FILE trace

962 963
/* This part must be outside protection */
#include <trace/define_trace.h>