5.1.0-rc1 regression: reset fails with kvm and -cpu host
Hi all,
this locks up the guest:
- qemu-system-x86_64 -enable-kvm -cpu host
- trigger hard reset
Host kernel: 5.7.7.
Host CPU: i7-8850H
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RDA IOT SES-DE Corporate Competence Center Embedded Linux
Hi Jan,
What was the last version where it worked for you? Does using "-cpu host,-vmx" help?
Quoted 16 lines · Jan Kiszka
Hi all,
this locks up the guest:
- qemu-system-x86_64 -enable-kvm -cpu host
- trigger hard resetHost kernel: 5.7.7.
Host CPU: i7-8850HJan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RDA IOT SES-DE Corporate Competence Center Embedded Linux
Signature · 1 line
Eduardo
Quoted 4 lines · Eduardo Habkost
Hi Jan,
What was the last version where it worked for you? Does using "-cpu host,-vmx" help?
Yeah, -vmx does indeed help.
I didn't have the time to bisect yet. Just check my reflog, picked eb6490f544, and that works.
HTH,
Jan
Quoted 20 lines · Jan Kiszka
Quoted 16 lines
Hi all,
this locks up the guest:
- qemu-system-x86_64 -enable-kvm -cpu host
- trigger hard resetHost kernel: 5.7.7.
Host CPU: i7-8850HJan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RDA IOT SES-DE Corporate Competence Center Embedded Linux
Signature · 2 lines
Siemens AG, Corporate Technology, CT RDA IOT SES-DE Corporate Competence Center Embedded Linux
Quoted 10 lines · Jan Kiszka
Quoted 4 lines · Eduardo Habkost
Hi Jan,
What was the last version where it worked for you? Does using "-cpu host,-vmx" help?
Yeah, -vmx does indeed help.
I didn't have the time to bisect yet. Just check my reflog, picked
eb6490f544, and that works.
Thanks!
I could reproduce it locally[1], I will bisect it.
The good news is that "-cpu host,+vmx" still works, on commit eb6490f544.
[1] Linux 5.6.19-300.fc32.x86_64, Intel Core i7-8665U CPU.
Signature · 1 line
Eduardo
Quoted 12 lines · Eduardo Habkost
Quoted 10 lines · Jan Kiszka
Quoted 4 lines · Eduardo Habkost
Hi Jan,
What was the last version where it worked for you? Does using "-cpu host,-vmx" help?
Yeah, -vmx does indeed help.
I didn't have the time to bisect yet. Just check my reflog, picked
eb6490f544, and that works.
Quoted 8 lines
Thanks!
I could reproduce it locally[1], I will bisect it.
The good news is that "-cpu host,+vmx" still works, on commit
eb6490f544.[1] Linux 5.6.19-300.fc32.x86_64, Intel Core i7-8665U CPU.
Bisected to:
commit b16c0e20c74218f2d69710cedad11da7dd4d2190
Author: Paolo Bonzini <[email protected]> Date: Wed May 20 10:49:22 2020 -0400
KVM: add support for AMD nested live migration
Support for nested guest live migration is part of Linux 5.8, add the corresponding code to QEMU. The migration format consists of a few flags, is an opaque 4k blob.
The blob is in VMCB format (the control area represents the L1 VMCB control fields, the save area represents the pre-vmentry state; KVM does not use the host save area since the AMD manual allows that) but QEMU does not really care about that. However, the flags need to be copied to hflags/hflags2 and back.
In addition, support for retrieving and setting the AMD nested virtualization states allows the L1 guest to be reset while running a nested guest, but a small bug in CPU reset needs to be fixed for that to work.
Signature · 1 line
Eduardo
Quoted 40 lines · * Eduardo Habkost ([email protected]) wrote:
Quoted 12 lines · Eduardo Habkost
Quoted 10 lines · Jan Kiszka
Quoted 4 lines · Eduardo Habkost
Hi Jan,
What was the last version where it worked for you? Does using "-cpu host,-vmx" help?
Yeah, -vmx does indeed help.
I didn't have the time to bisect yet. Just check my reflog, picked
eb6490f544, and that works.Quoted 8 lines
Thanks!
I could reproduce it locally[1], I will bisect it.
The good news is that "-cpu host,+vmx" still works, on commit
eb6490f544.[1] Linux 5.6.19-300.fc32.x86_64, Intel Core i7-8665U CPU.
Bisected to:
commit
b16c0e20c74218f2d69710cedad11da7dd4d2190Author: Paolo Bonzini <[email protected]> Date: Wed May 20 10:49:22 2020 -0400KVM: add support for AMD nested live migration
Support for nested guest live migration is part of Linux 5.8, add the corresponding code to QEMU. The migration format consists of a few flags, is an opaque 4k blob.
The blob is in VMCB format (the control area represents the L1 VMCB control fields, the save area represents the pre-vmentry state; KVM does not use the host save area since the AMD manual allows that) but QEMU does not really care about that. However, the flags need to be copied to hflags/hflags2 and back.
Quoted 5 lines
In addition, support for retrieving and setting the AMD nested virtualization states allows the L1 guest to be reset while running a nested guest, but a small bug in CPU reset needs to be fixed for that to work.
Signed-off-by Paolo Bonzini <[email protected]>
Guesswork led me to try reverting the chunk in kvm_put_nested_state; without it the reset seems to work; I can't explain that code though.
Dave
Quoted 5 lines
Signature · 2 lines
-- Eduardo
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
+Vitaly
Quoted 61 lines · Dr. David Alan Gilbert
Quoted 40 lines · * Eduardo Habkost ([email protected]) wrote:
Quoted 12 lines · Eduardo Habkost
Quoted 10 lines · Jan Kiszka
Quoted 4 lines · Eduardo Habkost
Hi Jan,
What was the last version where it worked for you? Does using "-cpu host,-vmx" help?
Yeah, -vmx does indeed help.
I didn't have the time to bisect yet. Just check my reflog, picked
eb6490f544, and that works.Quoted 8 lines
Thanks!
I could reproduce it locally[1], I will bisect it.
The good news is that "-cpu host,+vmx" still works, on commit
eb6490f544.[1] Linux 5.6.19-300.fc32.x86_64, Intel Core i7-8665U CPU.
Bisected to:
commit
b16c0e20c74218f2d69710cedad11da7dd4d2190Author: Paolo Bonzini <[email protected]> Date: Wed May 20 10:49:22 2020 -0400KVM: add support for AMD nested live migration
Support for nested guest live migration is part of Linux 5.8, add the corresponding code to QEMU. The migration format consists of a few flags, is an opaque 4k blob.
The blob is in VMCB format (the control area represents the L1 VMCB control fields, the save area represents the pre-vmentry state; KVM does not use the host save area since the AMD manual allows that) but QEMU does not really care about that. However, the flags need to be copied to hflags/hflags2 and back.
Quoted 5 lines
In addition, support for retrieving and setting the AMD nested virtualization states allows the L1 guest to be reset while running a nested guest, but a small bug in CPU reset needs to be fixed for that to work.
Signed-off-by Paolo Bonzini <[email protected]>Guesswork led me to try reverting the chunk in
kvm_put_nested_state; without it the reset seems to work; I can't explain that code though.Dave
Quoted 5 lines
Signature · 2 lines
-- Eduardo--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Quoted 53 lines · Philippe Mathieu-Daudé
+Vitaly
Quoted 50 lines · Dr. David Alan Gilbert
Quoted 40 lines · * Eduardo Habkost ([email protected]) wrote:
Quoted 12 lines · Eduardo Habkost
Quoted 10 lines · Jan Kiszka
Quoted 4 lines · Eduardo Habkost
Hi Jan,
What was the last version where it worked for you? Does using "-cpu host,-vmx" help?
Yeah, -vmx does indeed help.
I didn't have the time to bisect yet. Just check my reflog, picked
eb6490f544, and that works.Quoted 8 lines
Thanks!
I could reproduce it locally[1], I will bisect it.
The good news is that "-cpu host,+vmx" still works, on commit
eb6490f544.[1] Linux 5.6.19-300.fc32.x86_64, Intel Core i7-8665U CPU.
Bisected to:
commit
b16c0e20c74218f2d69710cedad11da7dd4d2190Author: Paolo Bonzini <[email protected]> Date: Wed May 20 10:49:22 2020 -0400KVM: add support for AMD nested live migration
Support for nested guest live migration is part of Linux 5.8, add the corresponding code to QEMU. The migration format consists of a few flags, is an opaque 4k blob.
The blob is in VMCB format (the control area represents the L1 VMCB control fields, the save area represents the pre-vmentry state; KVM does not use the host save area since the AMD manual allows that) but QEMU does not really care about that. However, the flags need to be copied to hflags/hflags2 and back.
Quoted 5 lines
In addition, support for retrieving and setting the AMD nested virtualization states allows the L1 guest to be reset while running a nested guest, but a small bug in CPU reset needs to be fixed for that to work.
Signed-off-by Paolo Bonzini <[email protected]>Guesswork led me to try reverting the chunk in
kvm_put_nested_state; without it the reset seems to work; I can't explain that code though.
(sorry, missed the beginning of the discussion)
So one does:
(qemu) system_reset
on Intel wiht '-cpu host' and the result is:
(qemu) KVM: entry failed, hardware error 0x80000021
If you're running a guest on an Intel machine without unrestricted mode support, the failure can be most likely due to the guest entering an invalid state for Intel VT. For example, the guest maybe running in big real mode which is not supported on less recent Intel processors.
EAX=00000064 EBX=91df5efe ECX=00000000 EDX=000003f8
ESI=00000000 EDI=91ee32c0 EBP=90643260 ESP=00013c68
EIP=906428e6 EFL=00000002 [-------] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0000 00000000 0000ffff 00009300
CS =f000 ffff0000 0000ffff 00009b00
SS =0000 00000000 0000ffff 00009300
DS =0000 00000000 0000ffff 00009300
FS =0000 00000000 0000ffff 00009300
GS =0000 00000000 0000ffff 00009300
LDT=0000 00000000 0000ffff 00008200
TR =0000 00000000 0000ffff 00008b00
GDT= 00000000 0000ffff
IDT= 00000000 0000ffff
CR0=60000010 CR2=00000000 CR3=00000000 CR4=00000000
DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000
DR6=00000000ffff0ff0 DR7=0000000000000400
EFER=0000000000000000
Code=?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? <??> ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ??
I can take a look (if no one beats me to it).
Signature · 1 line
Vitaly
Quoted 58 lines · * Vitaly Kuznetsov ([email protected]) wrote:
Quoted 53 lines · Philippe Mathieu-Daudé
+Vitaly
Quoted 50 lines · Dr. David Alan Gilbert
Quoted 40 lines · * Eduardo Habkost ([email protected]) wrote:
Quoted 12 lines · Eduardo Habkost
Quoted 10 lines · Jan Kiszka
Quoted 4 lines · Eduardo Habkost
Hi Jan,
What was the last version where it worked for you? Does using "-cpu host,-vmx" help?
Yeah, -vmx does indeed help.
I didn't have the time to bisect yet. Just check my reflog, picked
eb6490f544, and that works.Quoted 8 lines
Thanks!
I could reproduce it locally[1], I will bisect it.
The good news is that "-cpu host,+vmx" still works, on commit
eb6490f544.[1] Linux 5.6.19-300.fc32.x86_64, Intel Core i7-8665U CPU.
Bisected to:
commit
b16c0e20c74218f2d69710cedad11da7dd4d2190Author: Paolo Bonzini <[email protected]> Date: Wed May 20 10:49:22 2020 -0400KVM: add support for AMD nested live migration
Support for nested guest live migration is part of Linux 5.8, add the corresponding code to QEMU. The migration format consists of a few flags, is an opaque 4k blob.
The blob is in VMCB format (the control area represents the L1 VMCB control fields, the save area represents the pre-vmentry state; KVM does not use the host save area since the AMD manual allows that) but QEMU does not really care about that. However, the flags need to be copied to hflags/hflags2 and back.
Quoted 5 lines
In addition, support for retrieving and setting the AMD nested virtualization states allows the L1 guest to be reset while running a nested guest, but a small bug in CPU reset needs to be fixed for that to work.
Signed-off-by Paolo Bonzini <[email protected]>Guesswork led me to try reverting the chunk in
kvm_put_nested_state; without it the reset seems to work; I can't explain that code though.(sorry, missed the beginning of the discussion)
Quoted 7 lines
So one does:
(qemu)
system_reseton Intel wiht '-cpu host' and the result is:
(qemu) KVM: entry failed, hardware error
0x80000021
Interesting; I hadn't seen that error - I just see a hard hung guest rather than a reset one.
(i7-8650U laptop 5.7.9 fedora 32)
Dave
Quoted 24 lines
If you're running a guest on an Intel machine without unrestricted mode support, the failure can be most likely due to the guest entering an invalid state for Intel VT. For example, the guest maybe running in big real mode which is not supported on less recent Intel processors.
EAX=00000064 EBX=91df5efe ECX=00000000 EDX=000003f8
ESI=00000000 EDI=91ee32c0 EBP=90643260 ESP=00013c68
EIP=906428e6 EFL=00000002 [-------] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0000 000000000000ffff00009300
CS =f000ffff00000000ffff00009b00
SS =0000 000000000000ffff00009300
DS =0000 000000000000ffff00009300
FS =0000 000000000000ffff00009300
GS =0000 000000000000ffff00009300
LDT=0000 000000000000ffff00008200
TR =0000 000000000000ffff00008b00
GDT= 000000000000ffff
IDT= 000000000000ffff
CR0=60000010 CR2=00000000 CR3=00000000 CR4=00000000
DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000
DR6=00000000ffff0ff0 DR7=0000000000000400
EFER=0000000000000000
Code=?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? <??> ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ??
Quoted 5 lines
I can take a look (if no one beats me to it).
Signature · 1 line
Vitaly
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Quoted 61 lines · Dr. David Alan Gilbert
Quoted 60 lines · * Vitaly Kuznetsov ([email protected]) wrote:
Quoted 53 lines · Philippe Mathieu-Daudé
+Vitaly
Quoted 50 lines · Dr. David Alan Gilbert
Quoted 40 lines · * Eduardo Habkost ([email protected]) wrote:
Quoted 12 lines · Eduardo Habkost
Quoted 10 lines · Jan Kiszka
Quoted 4 lines · Eduardo Habkost
Hi Jan,
What was the last version where it worked for you? Does using "-cpu host,-vmx" help?
Yeah, -vmx does indeed help.
I didn't have the time to bisect yet. Just check my reflog, picked
eb6490f544, and that works.Quoted 8 lines
Thanks!
I could reproduce it locally[1], I will bisect it.
The good news is that "-cpu host,+vmx" still works, on commit
eb6490f544.[1] Linux 5.6.19-300.fc32.x86_64, Intel Core i7-8665U CPU.
Bisected to:
commit
b16c0e20c74218f2d69710cedad11da7dd4d2190Author: Paolo Bonzini <[email protected]> Date: Wed May 20 10:49:22 2020 -0400KVM: add support for AMD nested live migration
Support for nested guest live migration is part of Linux 5.8, add the corresponding code to QEMU. The migration format consists of a few flags, is an opaque 4k blob.
The blob is in VMCB format (the control area represents the L1 VMCB control fields, the save area represents the pre-vmentry state; KVM does not use the host save area since the AMD manual allows that) but QEMU does not really care about that. However, the flags need to be copied to hflags/hflags2 and back.
Quoted 5 lines
In addition, support for retrieving and setting the AMD nested virtualization states allows the L1 guest to be reset while running a nested guest, but a small bug in CPU reset needs to be fixed for that to work.
Signed-off-by Paolo Bonzini <[email protected]>Guesswork led me to try reverting the chunk in
kvm_put_nested_state; without it the reset seems to work; I can't explain that code though.(sorry, missed the beginning of the discussion)
So one does:
Quoted 8 lines
Quoted 5 lines
(qemu)
system_reseton Intel wiht '-cpu host' and the result is:
(qemu) KVM: entry failed, hardware error
0x80000021Interesting; I hadn't seen that error - I just see a hard hung guest rather than a reset one.
I've seen it once or twice, maybe that was also with a more complex command line. The point is that an invalid state is very likely loaded on reset. Not all invalid states cause KVM to complain, though. Some just lock up the guest.
Jan
Quoted 37 lines
(i7-8650U laptop 5.7.9 fedora 32)
Dave
Quoted 24 lines
If you're running a guest on an Intel machine without unrestricted mode support, the failure can be most likely due to the guest entering an invalid state for Intel VT. For example, the guest maybe running in big real mode which is not supported on less recent Intel processors.
EAX=00000064 EBX=91df5efe ECX=00000000 EDX=000003f8
ESI=00000000 EDI=91ee32c0 EBP=90643260 ESP=00013c68
EIP=906428e6 EFL=00000002 [-------] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0000 000000000000ffff00009300
CS =f000ffff00000000ffff00009b00
SS =0000 000000000000ffff00009300
DS =0000 000000000000ffff00009300
FS =0000 000000000000ffff00009300
GS =0000 000000000000ffff00009300
LDT=0000 000000000000ffff00008200
TR =0000 000000000000ffff00008b00
GDT= 000000000000ffff
IDT= 000000000000ffff
CR0=60000010 CR2=00000000 CR3=00000000 CR4=00000000
DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000
DR6=00000000ffff0ff0 DR7=0000000000000400
EFER=0000000000000000
Code=?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? <??> ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ??Quoted 5 lines
I can take a look (if no one beats me to it).
Signature · 1 line
Vitaly--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Signature · 2 lines
Siemens AG, Corporate Technology, CT RDA IOT SES-DE Corporate Competence Center Embedded Linux
Quoted 68 lines · Jan Kiszka
Quoted 67 lines · Dr. David Alan Gilbert
Quoted 65 lines · * Vitaly Kuznetsov ([email protected]) wrote:
Quoted 53 lines · Philippe Mathieu-Daudé
+Vitaly
Quoted 50 lines · Dr. David Alan Gilbert
Quoted 40 lines · * Eduardo Habkost ([email protected]) wrote:
Quoted 12 lines · Eduardo Habkost
Quoted 10 lines · Jan Kiszka
Quoted 4 lines · Eduardo Habkost
Hi Jan,
What was the last version where it worked for you? Does using "-cpu host,-vmx" help?
Yeah, -vmx does indeed help.
I didn't have the time to bisect yet. Just check my reflog, picked
eb6490f544, and that works.Quoted 8 lines
Thanks!
I could reproduce it locally[1], I will bisect it.
The good news is that "-cpu host,+vmx" still works, on commit
eb6490f544.[1] Linux 5.6.19-300.fc32.x86_64, Intel Core i7-8665U CPU.
Bisected to:
commit
b16c0e20c74218f2d69710cedad11da7dd4d2190Author: Paolo Bonzini <[email protected]> Date: Wed May 20 10:49:22 2020 -0400KVM: add support for AMD nested live migration
Support for nested guest live migration is part of Linux 5.8, add the corresponding code to QEMU. The migration format consists of a few flags, is an opaque 4k blob.
The blob is in VMCB format (the control area represents the L1 VMCB control fields, the save area represents the pre-vmentry state; KVM does not use the host save area since the AMD manual allows that) but QEMU does not really care about that. However, the flags need to be copied to hflags/hflags2 and back.
Quoted 5 lines
In addition, support for retrieving and setting the AMD nested virtualization states allows the L1 guest to be reset while running a nested guest, but a small bug in CPU reset needs to be fixed for that to work.
Signed-off-by Paolo Bonzini <[email protected]>Guesswork led me to try reverting the chunk in
kvm_put_nested_state; without it the reset seems to work; I can't explain that code though.(sorry, missed the beginning of the discussion)
So one does:
(qemu)
system_reseton Intel wiht '-cpu host' and the result is:
(qemu) KVM: entry failed, hardware error
0x80000021
Quoted 7 lines
Quoted 2 lines
Interesting; I hadn't seen that error - I just see a hard hung guest rather than a reset one.
I've seen it once or twice, maybe that was also with a more complex command line. The point is that an invalid state is very likely loaded on reset. Not all invalid states cause KVM to complain, though. Some just lock up the guest.
This depends on whether the guest has performed VMXON or not I believe.
Anyways, I *think* the fix will be:
target/i386/kvm.c +1 -1
@@ -3883,7 +3883,7 @@ static int kvm_put_nested_state(X86CPU *cpu) }else { env->nested_state->flags &= ~KVM_STATE_NESTED_GUEST_MODE ; } -if (env->hflags2 &HF2_GIF_MASK ) { +if (cpu_has_svm (env) && (env->hflags2 &HF2_GIF_MASK )) { env->nested_state->flags |=KVM_STATE_NESTED_GIF_SET ; }else { env->nested_state->flags &= ~KVM_STATE_NESTED_GIF_SET ;
As "KVM_STATE_NESTED_GIF_SET" is not relevant to nVMX, this works for me but let me explore kernel side of this a bit more.
Signature · 1 line
Vitaly
Yes, that seems correct.
Paolo
Il gio 23 lug 2020, 15:26 Vitaly Kuznetsov <[email protected]> ha scritto:
Quoted 25 lines
This depends on whether the guest has performed VMXON or not I believe.
Anyways, I *think* the fix will be:
target/i386/kvm.c +1
-1@@ -3883,7 +3883,7 @@ static int kvm_put_nested_state(X86CPU *cpu) }else { env->nested_state->flags &= ~KVM_STATE_NESTED_GUEST_MODE ; } -if (env->hflags2 &HF2_GIF_MASK ) { +if (cpu_has_svm (env) && (env->hflags2 &HF2_GIF_MASK )) { env->nested_state->flags |=KVM_STATE_NESTED_GIF_SET ; }else { env->nested_state->flags &= ~KVM_STATE_NESTED_GIF_SET ;As "
KVM_STATE_NESTED_GIF_SET" is not relevant to nVMX, this works for me but let me explore kernel side of this a bit more.--
Vitaly
Quoted 2 lines · Paolo Bonzini
Yes, that seems correct.
Thank you!
It seems we also need to not reset HF2_GIF_MASK in kvm_get_nested_state() when !svm and KVM_STATE_NESTED_GIF_SET is missing (as nVMX doesn't set it). I'll be sending the patch shortly.
Signature · 1 line
Vitaly