Skip to the content.

lab

1 S root     3488032       2  0  80   0 -     0 -      Feb04 ?        00:00:00 [kvm-pit/3487793]

[ ] 虚拟机开机的时候才注入 pit timer 中断

@[
    pit_timer_fn+5
    __hrtimer_run_queues+332
    hrtimer_interrupt+255
    __sysvec_apic_timer_interrupt+82
    sysvec_apic_timer_interrupt+110
    asm_sysvec_apic_timer_interrupt+26
    cpuidle_enter_state+220
    cpuidle_enter+45
    do_idle+459
    cpu_startup_entry+41
    start_secondary+291
    common_startup_64+318
]: 185

通过这个可以观察到:

echo module kvm +p | sudo tee /sys/kernel/debug/dynamic_debug/control

虚拟机启动中之后,

[455960.725218] kvm: load_count val is 0, channel is 0
[455960.725221] kvm: load_count val is 0, channel is 1
[455960.725221] kvm: load_count val is 0, channel is 2
[455960.732540] kvm: load_count val is 65536, channel is 0
[455960.732543] kvm: load_count val is 65536, channel is 1
[455960.732543] kvm: load_count val is 65536, channel is 2
[455960.733238] kvm: load_count val is 65536, channel is 0
[455960.733240] kvm: load_count val is 65536, channel is 1
[455960.733241] kvm: load_count val is 65536, channel is 2
[455960.860902] kvm: load_count val is 11932, channel is 0
[455966.000693] kvm: load_count val is 0, channel is 0
[455966.000697] kvm: load_count val is 0, channel is 1
[455966.000697] kvm: load_count val is 0, channel is 2
[455966.007584] kvm: load_count val is 65536, channel is 0
[455966.007587] kvm: load_count val is 65536, channel is 1
[455966.007588] kvm: load_count val is 65536, channel is 2
[455966.008929] kvm: load_count val is 65536, channel is 0
[455966.008930] kvm: load_count val is 65536, channel is 1
[455966.008931] kvm: load_count val is 65536, channel is 2
[455966.020372] kvm: load_count val is 0, channel is 0
[455966.272783] kvm: load_count val is 0, channel is 0
sudo bpftrace -e "kfunc:pit_load_count { if (args->channel == 0 && args->val == 0) { @[kstack]=count(); } }"

可以捕获到这个:

@[
    pit_load_count+5
    pit_ioport_write+365
    __kvm_io_bus_write+137
    kvm_io_bus_write+90
    emulator_pio_in_out+131
    kvm_fast_pio+236
    vmx_handle_exit+538
    vcpu_enter_guest.constprop.0+1613
    kvm_arch_vcpu_ioctl_run+855
    kvm_vcpu_ioctl+290
    __x64_sys_ioctl+160
    do_syscall_64+193
    entry_SYSCALL_64_after_hwframe+119
]: 2

的确就是启动之后就关闭了:

和 nmi 的关系

看来是在 pit_do_work 的问题:

	/*
	 * Provides NMI watchdog support via Virtual Wire mode.
	 * The route is: PIT -> LVT0 in NMI mode.
	 *
	 * Note: Our Virtual Wire implementation does not follow
	 * the MP specification.  We propagate a PIT interrupt to all
	 * VCPUs and only when LVT0 is in NMI mode.  The interrupt can
	 * also be simultaneously delivered through PIC and IOAPIC.
	 */
	if (atomic_read(&kvm->arch.vapics_in_nmi_mode) > 0)
		kvm_for_each_vcpu(i, vcpu, kvm)
			kvm_apic_nmi_wd_deliver(vcpu);

和 qemu 的联系是什么?

qemu 自动构建的

Tracing 1 functions for "kvm_create_pit"... Hit Ctrl-C to end.
^C
  b'kvm_create_pit'
  b'kvm_arch_vm_ioctl'
  b'kvm_vm_ioctl'
  b'do_vfs_ioctl'
  b'ksys_ioctl'
  b'__x64_sys_ioctl'
  b'do_syscall_64'
  b'entry_SYSCALL_64_after_hwframe'
  b'[unknown]'
  b'[unknown]'
    1

问题虚拟机启动:

[966207.634121] kvm_get_time_scale: base_hz 1000000000 => 1996249000, shift 1, mul 4286912084
[966207.636397] kvm: new tsc generation 1, clock 0
[966207.637449] kvm_get_time_scale: base_hz 1000000000 => 1996249000, shift 1, mul 4286912084
[966207.637490] kvm: matched tsc offset for 0
[966207.638327] kvm_get_time_scale: base_hz 1000000000 => 1996249000, shift 1, mul 4286912084
[966207.638380] kvm: matched tsc offset for 0
[966207.638957] kvm_get_time_scale: base_hz 1000000000 => 1996249000, shift 1, mul 4286912084
[966207.638995] kvm: matched tsc offset for 0
[966207.654663] pit: load_count val is 0, channel is 0
[966207.654667] pit: load_count val is 0, channel is 1
[966207.654668] pit: load_count val is 0, channel is 2
[966207.675534] kvm_get_time_scale: base_hz 1000000000 => 1996249000, shift 1, mul 4286912084
[966207.675568] kvm: matched tsc offset for 0
[966207.676644] kvm_get_time_scale: base_hz 1000000000 => 1996249000, shift 1, mul 4286912084
[966207.676674] kvm: matched tsc offset for 0
[966207.676747] kvm_get_time_scale: base_hz 1000000000 => 1996249000, shift 1, mul 4286912084
[966207.676777] kvm: matched tsc offset for 0
[966207.676838] kvm_get_time_scale: base_hz 1000000000 => 1996249000, shift 1, mul 4286912084
[966207.676885] kvm: matched tsc offset for 0
[966207.693120] pit: load_count val is 65536, channel is 0
[966207.693123] pit: create pit timer, interval is 54925447 nsec
[966207.693125] pit: load_count val is 65536, channel is 1
[966207.693126] pit: load_count val is 65536, channel is 2
[966207.693694] kvm: matched tsc offset for 0
[966207.693759] kvm: matched tsc offset for 0
[966207.693817] kvm: matched tsc offset for 0
[966207.693900] kvm: matched tsc offset for 0
[966209.370141] kvm_get_time_scale: base_hz 1996249000 => 1000000000, shift 0, mul 2151518821
[966209.370254] pit: load_count val is 65536, channel is 0
[966209.370256] pit: create pit timer, interval is 54925447 nsec
[966209.370259] pit: load_count val is 65536, channel is 1
[966209.370260] pit: load_count val is 65536, channel is 2
[966209.370401] kvm_get_time_scale: base_hz 1996249000 => 1000000000, shift 0, mul 2151518821
[966209.406843] kvm_get_time_scale: base_hz 1996249000 => 1000000000, shift 0, mul 2151518821
[966209.406846] kvm_get_time_scale: base_hz 1996249000 => 1000000000, shift 0, mul 2151518821
[966209.406862] kvm_get_time_scale: base_hz 1996249000 => 1000000000, shift 0, mul 2151518821
[966209.420342] pit: write addr is 0x3, len is 1, val is 0x34
[966209.420348] pit: load_count val is 0, channel is 0
[966209.420349] pit: create pit timer, interval is 54925447 nsec
[966220.661200] pit: write addr is 0x3, len is 1, val is 0x34
[966220.661209] pit: write addr is 0x0, len is 1, val is 0x9c
[966220.661216] pit: write addr is 0x0, len is 1, val is 0x2e
[966220.661217] pit: load_count val is 11932, channel is 0
[966220.661218] pit: create pit timer, interval is 10000159 nsec

没问题虚拟机启动:

[966318.720287] kvm_get_time_scale: base_hz 1000000000 => 1996249000, shift 1, mul 4286912084
[966318.722295] kvm: new tsc generation 1, clock 0
[966318.722835] kvm_get_time_scale: base_hz 1000000000 => 1996249000, shift 1, mul 4286912084
[966318.722874] kvm: matched tsc offset for 0
[966318.723186] kvm_get_time_scale: base_hz 1000000000 => 1996249000, shift 1, mul 4286912084
[966318.723223] kvm: matched tsc offset for 0
[966318.723554] kvm_get_time_scale: base_hz 1000000000 => 1996249000, shift 1, mul 4286912084
[966318.723604] kvm: matched tsc offset for 0
[966318.723925] kvm_get_time_scale: base_hz 1000000000 => 1996249000, shift 1, mul 4286912084
[966318.723961] kvm: matched tsc offset for 0
[966318.724295] kvm_get_time_scale: base_hz 1000000000 => 1996249000, shift 1, mul 4286912084
[966318.724330] kvm: matched tsc offset for 0
[966318.736279] pit: load_count val is 0, channel is 0
[966318.736282] pit: load_count val is 0, channel is 1
[966318.736283] pit: load_count val is 0, channel is 2
[966318.759299] kvm_get_time_scale: base_hz 1000000000 => 1996249000, shift 1, mul 4286912084
[966318.759323] kvm: matched tsc offset for 0
[966318.760547] kvm_get_time_scale: base_hz 1000000000 => 1996249000, shift 1, mul 4286912084
[966318.760593] kvm: matched tsc offset for 0
[966318.760675] kvm_get_time_scale: base_hz 1000000000 => 1996249000, shift 1, mul 4286912084
[966318.760696] kvm: matched tsc offset for 0
[966318.760764] kvm_get_time_scale: base_hz 1000000000 => 1996249000, shift 1, mul 4286912084
[966318.760784] kvm: matched tsc offset for 0
[966318.760849] kvm_get_time_scale: base_hz 1000000000 => 1996249000, shift 1, mul 4286912084
[966318.760868] kvm: matched tsc offset for 0
[966318.760934] kvm_get_time_scale: base_hz 1000000000 => 1996249000, shift 1, mul 4286912084
[966318.760951] kvm: matched tsc offset for 0
[966318.775730] pit: load_count val is 65536, channel is 0
[966318.775733] pit: load_count val is 65536, channel is 1
[966318.775734] pit: load_count val is 65536, channel is 2
[966318.776106] pit: load_count val is 65536, channel is 0
[966318.776108] pit: create pit timer, interval is 54925447 nsec
[966318.776110] pit: load_count val is 65536, channel is 1
[966318.776110] pit: load_count val is 65536, channel is 2
[966318.777545] kvm: matched tsc offset for 0
[966318.777636] kvm: matched tsc offset for 0
[966318.777716] kvm: matched tsc offset for 0
[966318.777786] kvm: matched tsc offset for 0
[966318.777849] kvm: matched tsc offset for 0
[966318.777913] kvm: matched tsc offset for 0
[966320.148759] kvm_get_time_scale: base_hz 1996249000 => 1000000000, shift 0, mul 2151518821
[966320.148974] pit: load_count val is 65536, channel is 0
[966320.148976] pit: create pit timer, interval is 54925447 nsec
[966320.148978] pit: load_count val is 65536, channel is 1
[966320.148979] pit: load_count val is 65536, channel is 2
[966320.149304] kvm_get_time_scale: base_hz 1996249000 => 1000000000, shift 0, mul 2151518821
[966320.328452] kvm_get_time_scale: base_hz 1996249000 => 1000000000, shift 0, mul 2151518821
[966320.328460] kvm_get_time_scale: base_hz 1996249000 => 1000000000, shift 0, mul 2151518821
[966320.328463] kvm_get_time_scale: base_hz 1996249000 => 1000000000, shift 0, mul 2151518821
[966320.328467] kvm_get_time_scale: base_hz 1996249000 => 1000000000, shift 0, mul 2151518821
[966320.328472] kvm_get_time_scale: base_hz 1996249000 => 1000000000, shift 0, mul 2151518821
[966320.993136] pit: write addr is 0x3, len is 1, val is 0x36
[966320.993141] pit: write addr is 0x0, len is 1, val is 0x9c
[966320.993143] pit: write addr is 0x0, len is 1, val is 0x2e
[966320.993145] pit: load_count val is 11932, channel is 0
[966320.993146] pit: create pit timer, interval is 10000159 nsec

[966331.927248] pit: load_count val is 11932, channel is 0
[966331.927252] pit: load_count val is 65536, channel is 1
[966331.927253] pit: load_count val is 65536, channel is 2
[966333.438209] kvm [868739]: vcpu5 unhandled rdmsr: 0x122
[966333.438213] kvm [868739]: vcpu5 unhandled rdmsr: 0x10f
[966333.438216] kvm [868739]: vcpu5 unhandled rdmsr: 0x123
[966333.438219] kvm [868739]: vcpu5 unhandled rdmsr: 0xc0011020
[966342.026264] kvm [868737]: vcpu2 unhandled rdmsr: 0x3a
[966342.026271] kvm [868737]: vcpu2 unhandled rdmsr: 0xd90

[ ] intel 有这个问题吗?

找一个好点的环境 ?

和 hygon 没有关系,都是会触发的

[ ] 使用 crash 对比,以及 qemu 的原因来分析一下

是从哪一步没有的,必然可以找到的

本站所有文章转发 CSDN 将按侵权追究法律责任,其它情况随意。