KVM: x86: Fix a 4.14 backport regression related to userspace/guest FPU
Subsystems (4)
PATCH 1/1 KVM: x86: Fix a 4.14 backport regression related to userspace/guest FPU
Upstream commit:
f775b13eedee ("x86,kvm: move qemu/guest FPU switching out to vcpu_run")
introduced a bug, which was later fixed by upstream commit:
5663d8f9bbe4 ("kvm: x86: fix WARN due to uninitialized guest FPU state")
For reasons unknown, both commits were initially passed-over for inclusion in the 4.14 stable branch despite being tagged for stable. Eventually, someone noticed that the fixup, commit 5663d8f9bbe4, was missing from stable[1], and so it was queued up for 4.14 and included in release v4.14.79.
Even later, the original buggy patch, commit f775b13eedee, was also applied to the 4.14 stable branch. Through an unlucky coincidence, the incorrect ordering did not generate a conflict between the two patches, and led to v4.14.94 and later releases containing a spurious call to kvm_load_guest_fpu() in kvm_arch_vcpu_ioctl_run(). As a result, KVM may reload stale guest FPU state, e.g. after accepting in INIT event. This can manifest as crashes during boot, segfaults, failed checksums and so on and so forth.
Remove the unwanted kvm_{load,put}_guest_fpu() calls, i.e. make kvm_arch_vcpu_ioctl_run() look like commit 5663d8f9bbe4 was backported after commit f775b13eedee.
[1] https://www.spinics.net/lists/stable/msg263931.html
--- arch/x86/kvm/x86.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
arch/x86/kvm/x86.c +1 -5
@@ -7423,14 +7423,12 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) } } -kvm_load_guest_fpu (vcpu); -if (unlikely (vcpu->arch.complete_userspace_io)) {int (*cui)(struct kvm_vcpu *) = vcpu->arch.complete_userspace_io; vcpu->arch.complete_userspace_io =NULL ; r =cui (vcpu);if (r <=0 ) - goto out_fpu; + goto out; }else WARN_ON (vcpu->arch.pio.count || vcpu->mmio_needed);
@@ -7439,8 +7437,6 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)else r =vcpu_run (vcpu); -out_fpu: -kvm_put_guest_fpu (vcpu); out:kvm_put_guest_fpu (vcpu);post_kvm_run_save (vcpu);
Signature · 1 line
2.20.1
Sasha Levin
maintainerQuoted 29 lines · Sean Christopherson
Upstream commit:
f775b13eedee("x86,kvm: move qemu/guest FPU switching out tovcpu_run")introduced a bug, which was later fixed by upstream commit:
5663d8f9bbe4("kvm: x86: fix WARN due to uninitialized guest FPU state")For reasons unknown, both commits were initially passed-over for inclusion in the 4.14 stable branch despite being tagged for stable. Eventually, someone noticed that the fixup, commit
5663d8f9bbe4, was missing from stable[1], and so it was queued up for 4.14 and included in release v4.14.79.Even later, the original buggy patch, commit
f775b13eedee, was also applied to the 4.14 stable branch. Through an unlucky coincidence, the incorrect ordering did not generate a conflict between the two patches, and led to v4.14.94 and later releases containing a spurious call tokvm_load_guest_fpu()inkvm_arch_vcpu_ioctl_run(). As a result, KVM may reload stale guest FPU state, e.g. after accepting in INIT event. This can manifest as crashes during boot, segfaults, failed checksums and so on and so forth.Remove the unwanted kvm_{load,put}_guest_fpu() calls, i.e. make
kvm_arch_vcpu_ioctl_run()look like commit5663d8f9bbe4was backported after commitf775b13eedee.
Quoted 11 lines
Fixes 4124a4cff344 ("x86,kvm: move qemu/guest FPU switching out to vcpu_run")Cc Sasha Levin <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Cc Peter Xu <[email protected]>Cc Rik van Riel <[email protected]>Cc Paolo Bonzini <[email protected]>Cc Radim Krčmář <[email protected]>Reported-by Roman MamedovReported-by Thomas Lindroth <[email protected]>Signed-off-by Sean Christopherson <[email protected]>
I agree with your analysis and the patch makes sense. Hopefully one of the KVM folks can Ack.
Quoted 45 lines · Sasha Levin
Quoted 33 lines · Sean Christopherson
Upstream commit:
f775b13eedee("x86,kvm: move qemu/guest FPU switching out tovcpu_run")introduced a bug, which was later fixed by upstream commit:
5663d8f9bbe4("kvm: x86: fix WARN due to uninitialized guest FPU state")For reasons unknown, both commits were initially passed-over for inclusion in the 4.14 stable branch despite being tagged for stable. Eventually, someone noticed that the fixup, commit
5663d8f9bbe4, was missing from stable[1], and so it was queued up for 4.14 and included in release v4.14.79.Even later, the original buggy patch, commit
f775b13eedee, was also applied to the 4.14 stable branch. Through an unlucky coincidence, the incorrect ordering did not generate a conflict between the two patches, and led to v4.14.94 and later releases containing a spurious call tokvm_load_guest_fpu()in kvm_arch_vcpu_ioctl_run(). As a result, KVM may reload stale guest FPU state, e.g. after accepting in INIT event. This can manifest as crashes during boot, segfaults, failed checksums and so on and so forth.Remove the unwanted kvm_{load,put}_guest_fpu() calls, i.e. make
kvm_arch_vcpu_ioctl_run()look like commit5663d8f9bbe4was backported after commitf775b13eedee.[1] https://www.spinics.net/lists/stable/msg263931.html
Fixes 4124a4cff344 ("x86,kvm: move qemu/guest FPU switching out to
vcpu_run")Quoted 10 lines
Cc Sasha Levin <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Cc Peter Xu <[email protected]>Cc Rik van Riel <[email protected]>Cc Paolo Bonzini <[email protected]>Cc Radim Krčmář <[email protected]>Reported-by Roman MamedovReported-by Thomas Lindroth <[email protected]>Signed-off-by Sean Christopherson <[email protected]>
Quoted 2 lines
I agree with your analysis and the patch makes sense. Hopefully one of the KVM folks can Ack.
Paolo
Greg Kroah-Hartman
maintainerQuoted 40 lines · Sean Christopherson
Upstream commit:
f775b13eedee("x86,kvm: move qemu/guest FPU switching out tovcpu_run")introduced a bug, which was later fixed by upstream commit:
5663d8f9bbe4("kvm: x86: fix WARN due to uninitialized guest FPU state")For reasons unknown, both commits were initially passed-over for inclusion in the 4.14 stable branch despite being tagged for stable. Eventually, someone noticed that the fixup, commit
5663d8f9bbe4, was missing from stable[1], and so it was queued up for 4.14 and included in release v4.14.79.Even later, the original buggy patch, commit
f775b13eedee, was also applied to the 4.14 stable branch. Through an unlucky coincidence, the incorrect ordering did not generate a conflict between the two patches, and led to v4.14.94 and later releases containing a spurious call tokvm_load_guest_fpu()inkvm_arch_vcpu_ioctl_run(). As a result, KVM may reload stale guest FPU state, e.g. after accepting in INIT event. This can manifest as crashes during boot, segfaults, failed checksums and so on and so forth.Remove the unwanted kvm_{load,put}_guest_fpu() calls, i.e. make
kvm_arch_vcpu_ioctl_run()look like commit5663d8f9bbe4was backported after commitf775b13eedee.[1] https://www.spinics.net/lists/stable/msg263931.html
Fixes 4124a4cff344 ("x86,kvm: move qemu/guest FPU switching out to vcpu_run")Cc Sasha Levin <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Cc Peter Xu <[email protected]>Cc Rik van Riel <[email protected]>Cc Paolo Bonzini <[email protected]>Cc Radim Krčmář <[email protected]>Reported-by Roman MamedovReported-by Thomas Lindroth <[email protected]>Signed-off-by Sean Christopherson <[email protected]>
Quoted 3 lines
--- arch/x86/kvm/x86.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
Thanks so much for this, sorry for the mis-merge, nice catch!
Now queued up.
greg k-h
Quoted 66 lines · Sean Christopherson
Upstream commit:
f775b13eedee("x86,kvm: move qemu/guest FPU switching out tovcpu_run")introduced a bug, which was later fixed by upstream commit:
5663d8f9bbe4("kvm: x86: fix WARN due to uninitialized guest FPU state")For reasons unknown, both commits were initially passed-over for inclusion in the 4.14 stable branch despite being tagged for stable. Eventually, someone noticed that the fixup, commit
5663d8f9bbe4, was missing from stable[1], and so it was queued up for 4.14 and included in release v4.14.79.Even later, the original buggy patch, commit
f775b13eedee, was also applied to the 4.14 stable branch. Through an unlucky coincidence, the incorrect ordering did not generate a conflict between the two patches, and led to v4.14.94 and later releases containing a spurious call tokvm_load_guest_fpu()inkvm_arch_vcpu_ioctl_run(). As a result, KVM may reload stale guest FPU state, e.g. after accepting in INIT event. This can manifest as crashes during boot, segfaults, failed checksums and so on and so forth.Remove the unwanted kvm_{load,put}_guest_fpu() calls, i.e. make
kvm_arch_vcpu_ioctl_run()look like commit5663d8f9bbe4was backported after commitf775b13eedee.[1] https://www.spinics.net/lists/stable/msg263931.html
Fixes 4124a4cff344 ("x86,kvm: move qemu/guest FPU switching out to vcpu_run")Cc Sasha Levin <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Cc Peter Xu <[email protected]>Cc Rik van Riel <[email protected]>Cc Paolo Bonzini <[email protected]>Cc Radim Krčmář <[email protected]>Reported-by Roman MamedovReported-by Thomas Lindroth <[email protected]>Signed-off-by Sean Christopherson <[email protected]>--- arch/x86/kvm/x86.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)arch/x86/kvm/x86.c +1
-3@@ -7423,14 +7423,12 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) } } -kvm_load_guest_fpu (vcpu); -if (unlikely (vcpu->arch.complete_userspace_io)) {int (*cui)(struct kvm_vcpu *) = vcpu->arch.complete_userspace_io; vcpu->arch.complete_userspace_io =NULL ; r =cui (vcpu);if (r <=0 ) - goto out_fpu; + goto out; }else WARN_ON (vcpu->arch.pio.count || vcpu->mmio_needed);
arch/x86/kvm/x86.c int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) · line 7442
Quoted 8 lines
arch/x86/kvm/x86.c +0
-2@@ -7439,8 +7437,6 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)else r =vcpu_run (vcpu); -out_fpu: -kvm_put_guest_fpu (vcpu); out:kvm_put_guest_fpu (vcpu);post_kvm_run_save (vcpu);
I applied this patch on top of a standard 4.14.96 kernel and ran the stress-ng test for a few hours. No errors or other problems to report.