Re: external module sched_in event

Avi Kivity
2007-12-22T19:13:44Z

Andrea Arcangeli wrote:

[snip]
> So in short with the below fix applied, after a write_tsc(0,0), the
> UP guest never return any error anymore. Previously it would return
> frequent errors because sched_in wasn't properly invoked by svm.c and
> it would crash at boot every single time after a write_tsc(0,0).
>
> The SMP guest of course still returns TSC errors but that's ok, the
> smp host also return TSC errors, that's ok, it's only the UP guest
> that is forbidden to have a not monotone TSC or the guest would crash
> like it happened to me.
>
> I'm unsure if special_reload_db7 is needed at all, but it certainly
> can't hurt so it's the only hack I left.
>

It's needed, vmx (and IIRC svm) will clear out db7 so we must reload it.

In fairness we need also reload it if the host had it set; it shouldn't
be a hack but part of mainline.

> Finally I can enjoy KVM stability too ;). If you always compiled your
> host kernel with CONFIG_KVM=y on a recent kernels including the
> preempt-notifiers, you could never run into this. If you compile your
> host kernel with CONFIG_KVM=n please try to test this.
>

Unfortunately, this fails badly on Intel i386:

> kvm: emulating preempt notifiers; do not benchmark on this machine
> loaded kvm module (kvm-56-127-g433be51)
> vmwrite error: reg c08 value d8 (err 3080)
> [<f8baf9e2>] vmx_save_host_state+0x4f/0x162 [kvm_intel]
> [<c0425803>] __cond_resched+0x25/0x3c
> [<f91a22a4>] kvm_arch_vcpu_ioctl_run+0x16f/0x3a7 [kvm]
> [<f919f244>] kvm_vcpu_ioctl+0xcb/0x28f [kvm]
> [<c0421987>] enqueue_entity+0x2c0/0x2ea
> [<c05a8340>] skb_dequeue+0x39/0x3f
> [<c0604b6d>] unix_stream_recvmsg+0x3a2/0x4c3
> [<c0425c82>] scheduler_tick+0x1a1/0x274
> [<c0487329>] core_sys_select+0x21f/0x2fa
> [<c043e9e6>] clockevents_program_event+0xb5/0xbc
> [<c04c6853>] avc_has_perm+0x4e/0x58
> [<c04c7174>] inode_has_perm+0x66/0x6e
> [<c0430bed>] recalc_sigpending+0xb/0x1d
> [<c043231d>] dequeue_signal+0xa9/0x12a
> [<c043cb95>] getnstimeofday+0x30/0xbf
> [<c04c7205>] file_has_perm+0x89/0x91
> [<f919f179>] kvm_vcpu_ioctl+0x0/0x28f [kvm]
> [<c04861b9>] do_ioctl+0x21/0xa0
> [<c048646f>] vfs_ioctl+0x237/0x249
> [<c04864cd>] sys_ioctl+0x4c/0x67
> [<c0404f26>] sysenter_past_esp+0x5f/0x85
> =======================

vmwrite error means the vmcs pointer was not loaded, probably because
the sched_in event did not fire after a vcpu migration.

--
Do not meddle in the internals of kernels, for they are subtle and quick to panic.