qemu-kvm: x86: Fix mismerge in cpu_post_load
PATCH 1/1 qemu-kvm: x86: Fix mismerge in cpu_post_load
Merge 8e2c5ec2f6 forgot to restore some qemu-kvm-specific hooks in cpu_post_load. mp_state was readded later on, but tsc was missing, breaking the guest timing after resume. Also, reset of halt was dropped which is obviously required for in-kernel irqchip.
---
This solves "Problem 1" on my list.
BTW, this patch just made me realize that the TSC MSR belongs to the list states that should not be written back unconditionally. Upstream does this currently, qemu-kvm not (at the price one more kvm-specific hook into generic code). Unlike the other states we discussed, this one is not "fixable" in the kernel. So I tend to think there is a real need for my write-back scope abstraction - which would also be able to handle the other states cleanly, both in upstream and here.
target-i386/machine.c | 10 +++++++++- 1 files changed, 9 insertions(+), 1 deletions(-)
target-i386/machine.c +9 -1
@@ -366,7 +366,15 @@ static int cpu_post_load(void *opaque, int version_id)hw_breakpoint_insert (env, i);tlb_flush (env,1 ); -kvm_load_mpstate (env); + +if (kvm_enabled ()) { +/* when in-kernel irqchip is used, env->halted causes deadlock +because no userspace IRQs will ever clear this flag */ + env->halted =0 ; + +kvm_load_tsc (env); +kvm_load_mpstate (env); + }return 0 ; }
Avi Kivity
AppliedQuoted 5 lines · Jan Kiszka
Merge
8e2c5ec2f6forgot to restore some qemu-kvm-specific hooks incpu_post_load.mp_statewas readded later on, but tsc was missing, breaking the guest timing after resume. Also, reset of halt was dropped which is obviously required for in-kernel irqchip.
Applied, thanks.
Quoted 4 lines
BTW, this patch just made me realize that the TSC MSR belongs to the list states that should not be written back unconditionally. Upstream does this currently, qemu-kvm not (at the price one more kvm-specific hook into generic code).
Yet another reminder why we don't rewrite, only refactor.
Quoted 5 lines
Unlike the other states we discussed, this one
is not "fixable" in the kernel. So I tend to think there is a real need for my write-back scope abstraction - which would also be able to handle the other states cleanly, both in upstream and here.
Yes. Gleb suggested treating mpstate/nmi as part of the APIC state (which makes sense), which would work, as APIC state is not automatically written back. But the tsc msr would need special treatment.
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 26 lines · Jan Kiszka
Merge
8e2c5ec2f6forgot to restore some qemu-kvm-specific hooks incpu_post_load.mp_statewas readded later on, but tsc was missing, breaking the guest timing after resume. Also, reset of halt was dropped which is obviously required for in-kernel irqchip.Signed-off-by Jan Kiszka <[email protected]>---
This solves "Problem 1" on my list.
BTW, this patch just made me realize that the TSC MSR belongs to the list states that should not be written back unconditionally. Upstream does this currently, qemu-kvm not (at the price one more kvm-specific hook into generic code). Unlike the other states we discussed, this one is not "fixable" in the kernel. So I tend to think there is a real need for my write-back scope abstraction - which would also be able to handle the other states cleanly, both in upstream and here.
target-i386/machine.c | 10 +++++++++- 1 files changed, 9 insertions(+), 1 deletions(-)target-i386/machine.c +0
-0
target-i386/machine.c static int cpu_post_load(void *opaque, int version_id) · line 374
Quoted 10 lines
target-i386/machine.c +6
-1@@ -366,7 +366,15 @@ static int cpu_post_load(void *opaque, int version_id)hw_breakpoint_insert (env, i);tlb_flush (env,1 ); -kvm_load_mpstate (env); + +if (kvm_enabled ()) { +/* when in-kernel irqchip is used, env->halted causes deadlock +because no userspace IRQs will ever clear this flag */ + env->halted =0 ; +
That is strange. env->halted should be used only for "info cpus" output in case of in-kernel irqchip. Can you see where it hangs?
target-i386/machine.c static int cpu_post_load(void *opaque, int version_id) · line 380
Quoted 6 lines
target-i386/machine.c +3
-0+kvm_load_tsc (env); +kvm_load_mpstate (env); + }return 0 ; }
--
Gleb.
Quoted 7 lines · Avi Kivity
Quoted 5 lines · Jan Kiszka
Merge
8e2c5ec2f6forgot to restore some qemu-kvm-specific hooks incpu_post_load.mp_statewas readded later on, but tsc was missing, breaking the guest timing after resume. Also, reset of halt was dropped which is obviously required for in-kernel irqchip.
Quoted 8 lines
Applied, thanks.
Quoted 4 lines
BTW, this patch just made me realize that the TSC MSR belongs to the list states that should not be written back unconditionally. Upstream does this currently, qemu-kvm not (at the price one more kvm-specific hook into generic code).
Yet another reminder why we don't rewrite, only refactor.
Which also has it's downsides like slow merging progress with quite a few subtle merge regressions on qemu-kvm side...
Quoted 10 lines
Quoted 6 lines
Unlike the other states we discussed, this one
is not "fixable" in the kernel. So I tend to think there is a real need for my write-back scope abstraction - which would also be able to handle the other states cleanly, both in upstream and here.Yes. Gleb suggested treating mpstate/nmi as part of the APIC state (which makes sense), which would work, as APIC state is not automatically written back. But the tsc msr would need special treatment.
(just realized that I forgot to answer him)
While this would make sense for mpstate, NMIs are not coupled to the APICs. The APIC just happens to be one source for them (though a common one). So if there is no in-kernel APIC state, there would never be a write-back of the NMI state, which is bad.
That said, I think we should hurry to add some mask to the new KVM_SET_VCPU_EVENTS (for 2.6.33) in order to skip nmi_pending and sipi_vector, giving us maximum flexibility how to address the issue. Will send a patch later.
Jan
Quoted 5 lines · Jan Kiszka
That said, I think we should hurry to add some mask to the new
KVM_SET_VCPU_EVENTS(for 2.6.33) in order to skipnmi_pendingandsipi_vector, giving us maximum flexibility how to address the issue. Will send a patch later.
Yes. Thanks.
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 29 lines · Gleb Natapov
Quoted 28 lines · Jan Kiszka
Merge
8e2c5ec2f6forgot to restore some qemu-kvm-specific hooks incpu_post_load.mp_statewas readded later on, but tsc was missing, breaking the guest timing after resume. Also, reset of halt was dropped which is obviously required for in-kernel irqchip.Signed-off-by Jan Kiszka <[email protected]>---
This solves "Problem 1" on my list.
BTW, this patch just made me realize that the TSC MSR belongs to the list states that should not be written back unconditionally. Upstream does this currently, qemu-kvm not (at the price one more kvm-specific hook into generic code). Unlike the other states we discussed, this one is not "fixable" in the kernel. So I tend to think there is a real need for my write-back scope abstraction - which would also be able to handle the other states cleanly, both in upstream and here.
target-i386/machine.c | 10 +++++++++- 1 files changed, 9 insertions(+), 1 deletions(-)target-i386/machine.c +0
-0@@ -366,7 +366,15 @@ static int cpu_post_load(void *opaque, int version_id)hw_breakpoint_insert (env, i);
Quoted 10 lines
target-i386/machine.c static int cpu_post_load(void *opaque, int version_id) · line 374
Quoted 8 lines
target-i386/machine.c +6
-1tlb_flush (env,1 ); -kvm_load_mpstate (env); + +if (kvm_enabled ()) { +/* when in-kernel irqchip is used, env->halted causes deadlock +because no userspace IRQs will ever clear this flag */ + env->halted =0 ; +That is strange.
env->haltedshould be used only for "info cpus" output in case of in-kernel irqchip. Can you see where it hangs?
This line was not directly involved in the regression I saw, it was just the next one (load_tsc). But I simply restored qemu-kvm to the state before the vmstate conversion merge, dropping only obviously unneeded bits (namely the full register write-back).
The above line may no longer be required, but I wanted to play safe. If you can explain which qemu-kvm change made this obsolete, please file a removal patch!
Quoted 10 lines
target-i386/machine.c static int cpu_post_load(void *opaque, int version_id) · line 380
Quoted 7 lines
target-i386/machine.c +3
-0+kvm_load_tsc (env); +kvm_load_mpstate (env); + }return 0 ; }--
Gleb.
Jan
Quoted 41 lines · Jan Kiszka
Quoted 29 lines · Gleb Natapov
Quoted 28 lines · Jan Kiszka
Merge
8e2c5ec2f6forgot to restore some qemu-kvm-specific hooks incpu_post_load.mp_statewas readded later on, but tsc was missing, breaking the guest timing after resume. Also, reset of halt was dropped which is obviously required for in-kernel irqchip.Signed-off-by Jan Kiszka <[email protected]>---
This solves "Problem 1" on my list.
BTW, this patch just made me realize that the TSC MSR belongs to the list states that should not be written back unconditionally. Upstream does this currently, qemu-kvm not (at the price one more kvm-specific hook into generic code). Unlike the other states we discussed, this one is not "fixable" in the kernel. So I tend to think there is a real need for my write-back scope abstraction - which would also be able to handle the other states cleanly, both in upstream and here.
target-i386/machine.c | 10 +++++++++- 1 files changed, 9 insertions(+), 1 deletions(-)target-i386/machine.c +0
-0@@ -366,7 +366,15 @@ static int cpu_post_load(void *opaque, int version_id)hw_breakpoint_insert (env, i);Quoted 10 lines
target-i386/machine.c static int cpu_post_load(void *opaque, int version_id) · line 374
Quoted 8 lines
target-i386/machine.c +6
-1tlb_flush (env,1 ); -kvm_load_mpstate (env); + +if (kvm_enabled ()) { +/* when in-kernel irqchip is used, env->halted causes deadlock +because no userspace IRQs will ever clear this flag */ + env->halted =0 ; +That is strange.
env->haltedshould be used only for "info cpus" output in case of in-kernel irqchip. Can you see where it hangs?
Quoted 9 lines
This line was not directly involved in the regression I saw, it was just the next one (
load_tsc). But I simply restored qemu-kvm to the state before the vmstate conversion merge, dropping only obviously unneeded bits (namely the full register write-back).The above line may no longer be required, but I wanted to play safe. If you can explain which qemu-kvm change made this obsolete, please file a removal patch!
Ah, OK then. There was no particular patch that made in kernel irqchip to not use env->halted. AFAIR it was always this way.
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
target-i386/machine.c +3
-0+kvm_load_tsc (env); +kvm_load_mpstate (env); + }
Quoted 8 lines
Quoted 5 lines
target-i386/machine.c static int cpu_post_load(void *opaque, int version_id) · line 380
Quoted 2 lines
target-i386/machine.c +0
-0return 0 ; }--
Gleb.Jan
--
Gleb.
Quoted 10 lines · Jan Kiszka
Quoted 9 lines
Quoted 5 lines
Unlike the other states we discussed, this one
is not "fixable" in the kernel. So I tend to think there is a real need for my write-back scope abstraction - which would also be able to handle the other states cleanly, both in upstream and here.Yes. Gleb suggested treating mpstate/nmi as part of the APIC state (which makes sense), which would work, as APIC state is not automatically written back. But the tsc msr would need special treatment.
Quoted 7 lines
(just realized that I forgot to answer him)
While this would make sense for mpstate, NMIs are not coupled to the APICs. The APIC just happens to be one source for them (though a common one). So if there is no in-kernel APIC state, there would never be a write-back of the NMI state, which is bad.
I agree about NMI. We never do RMW to NMI anyway. Mpstate/sipi_vector belong to APIC state though.
--
Gleb.