CPU reset (INIT#) support for KVM
Paolo Bonzini
maintainercover CPU reset (INIT#) support for KVM
This is a follow up to the series I posted earlier this week to support CPU soft reset. It is a no-op without that series, but it can be applied independently.
The combined series is available at branch x86-soft-reset of my github repository (git://github.com/bonzini/qemu.git). With this series and the corresponding hypervisor patches, the init test of kvm-unit-tests now passes:
$ x86_64-softmmu/qemu-system-x86_64 \
-kernel ../../kvm-unit-tests/x86/init.flat \
-serial mon:stdio -display none \
-device isa-debug-exit,iobase=0xf4 \
--enable-kvm -machine kernel_irqchip=on
enabling apic
testing port 92 init... enabling apic
testing kbd controller reset... enabling apic
testing kbd controller init... enabling apic
testing 0xcf9h init... enabling apic
testing init to BSP... enabling apicPaolo
Paolo Bonzini (2):
kvm: report errors from kvm_arch_process_async_events
kvm: forward INIT signals coming from the chipset
kvm-all.c | 8 +++++++- target-i386/kvm.c | 34 +++++++++++++++++++++++----------- 2 files changed, 30 insertions(+), 12 deletions(-)
Signature · 1 line
1.8.1.4
Paolo Bonzini
maintainerPATCH 1/2 kvm: detect errors from kvm_arch_process_async_events
The next patch will call a ioctl from kvm_arch_process_async_events. Trap errors and abort the program if one comes.
--- kvm-all.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
kvm-all.c +7 -1
@@ -1536,7 +1536,13 @@ int kvm_cpu_exec(CPUArchState *env)DPRINTF ("kvm_cpu_exec()\n" ); -if (kvm_arch_process_async_events (cpu)) { + ret =kvm_arch_process_async_events (cpu); +if (ret) { +if (ret <0 ) { +fprintf (stderr,"error: kvm process events failed %s\n" , +strerror (-ret)); +abort (); + } cpu->exit_request =0 ;return EXCP_HLT ; }
Signature · 1 line
1.8.1.4
Paolo Bonzini
maintainerPATCH 2/2 kvm: forward INIT signals coming from the chipset
In reply to Paolo BonziniCPU_INTERRUPT_INIT can also be generated if you have an internal APIC, since the keyboard controller and the southbridge can also pulse the CPU's INIT# pin.
Exit the VCPU is one is received, and process it by changing the mp_state to KVM_MP_STATE_INIT_RECEIVED.
--- target-i386/kvm.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-)
target-i386/kvm.c +23 -11
@@ -1772,14 +1772,15 @@ void kvm_arch_pre_run(CPUState *cpu, struct kvm_run *run) } } -if (!kvm_irqchip_in_kernel ()) { -/* Force the VCPU out of its inner loop to process any INIT requests -* or pending TPR access reports. */ -if (env->interrupt_request & - (CPU_INTERRUPT_INIT |CPU_INTERRUPT_TPR )) { - cpu->exit_request =1 ; - } +/* Force the VCPU out of its inner loop to process any INIT requests +* or (for userspace APIC, but it is cheap to combine the checks here) +* pending TPR access reports. +*/ +if (env->interrupt_request & (CPU_INTERRUPT_INIT |CPU_INTERRUPT_TPR )) { + cpu->exit_request =1 ; + } +if (!kvm_irqchip_in_kernel ()) {/* Try to inject an interrupt if the guest can accept it */ if (run->ready_for_interrupt_injection && (env->interrupt_request & CPU_INTERRUPT_HARD) &&
@@ -1835,6 +1836,7 @@ int kvm_arch_process_async_events(CPUState *cs) {X86CPU *cpu =X86_CPU (cs);CPUX86State *env = &cpu->env; +int ret;if (env->interrupt_request &CPU_INTERRUPT_MCE ) {/* We must not raise CPU_INTERRUPT_MCE if it's not supported. */
@@ -1859,6 +1861,20 @@ int kvm_arch_process_async_events(CPUState *cs) } } +if (env->interrupt_request &CPU_INTERRUPT_INIT ) { +kvm_cpu_synchronize_state (env); +if (kvm_irqchip_in_kernel ()) { + env->mp_state =KVM_MP_STATE_INIT_RECEIVED ; + env->interrupt_request =0 ; + ret =kvm_put_mp_state (cpu); +if (ret <0 ) { +return ret; + } + }else { +do_cpu_init (cpu); + } + } +if (kvm_irqchip_in_kernel ()) {return 0 ; }
@@ -1872,10 +1888,6 @@ int kvm_arch_process_async_events(CPUState *cs) (env->interrupt_request & CPU_INTERRUPT_NMI)) { env->halted =0 ; } -if (env->interrupt_request &CPU_INTERRUPT_INIT ) { -kvm_cpu_synchronize_state (env); -do_cpu_init (cpu); - }if (env->interrupt_request &CPU_INTERRUPT_SIPI ) {kvm_cpu_synchronize_state (env);do_cpu_sipi (cpu);
Signature · 1 line
1.8.1.4
Re: [PATCH uq/master 2/2] kvm: forward INIT signals coming from the chipset
Quoted 55 lines · Paolo Bonzini
CPU_INTERRUPT_INITcan also be generated if you have an internal APIC, since the keyboard controller and the southbridge can also pulse the CPU's INIT# pin.Exit the VCPU is one is received, and process it by changing the
mp_statetoKVM_MP_STATE_INIT_RECEIVED.Signed-off-by Paolo Bonzini <[email protected]>--- target-i386/kvm.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-)target-i386/kvm.c +13
-7@@ -1772,14 +1772,15 @@ void kvm_arch_pre_run(CPUState *cpu, struct kvm_run *run) } } -if (!kvm_irqchip_in_kernel ()) { -/* Force the VCPU out of its inner loop to process any INIT requests -* or pending TPR access reports. */ -if (env->interrupt_request & - (CPU_INTERRUPT_INIT |CPU_INTERRUPT_TPR )) { - cpu->exit_request =1 ; - } +/* Force the VCPU out of its inner loop to process any INIT requests +* or (for userspace APIC, but it is cheap to combine the checks here) +* pending TPR access reports. +*/ +if (env->interrupt_request & (CPU_INTERRUPT_INIT |CPU_INTERRUPT_TPR )) { + cpu->exit_request =1 ; + } +if (!kvm_irqchip_in_kernel ()) {/* Try to inject an interrupt if the guest can accept it */ if (run->ready_for_interrupt_injection && (env->interrupt_request & CPU_INTERRUPT_HARD) &&@@ -1835,6 +1836,7 @@ int kvm_arch_process_async_events(CPUState *cs) {X86CPU *cpu =X86_CPU (cs);CPUX86State *env = &cpu->env; +int ret;if (env->interrupt_request &CPU_INTERRUPT_MCE ) {/* We must not raise CPU_INTERRUPT_MCE if it's not supported. */ @@ -1859,6 +1861,20 @@ int kvm_arch_process_async_events(CPUState *cs) } } +if (env->interrupt_request &CPU_INTERRUPT_INIT ) { +kvm_cpu_synchronize_state (env); +if (kvm_irqchip_in_kernel ()) { + env->mp_state =KVM_MP_STATE_INIT_RECEIVED ;
target-i386/kvm.c int kvm_arch_process_async_events(CPUState *cs) · line 1877
Quoted 10 lines
target-i386/kvm.c +10
-0+ env->interrupt_request =0 ; + ret =kvm_put_mp_state (cpu); +if (ret <0 ) { +return ret; + } + }else { +do_cpu_init (cpu); + } + } +
Why not move INIT case from below as is? Vcpu is reset to correct sate by QEMU just like during system_reset.
Quoted 16 lines
target-i386/kvm.c +0
-4if (kvm_irqchip_in_kernel ()) {return 0 ; }@@ -1872,10 +1888,6 @@ int kvm_arch_process_async_events(CPUState *cs) (env->interrupt_request & CPU_INTERRUPT_NMI)) { env->halted =0 ; } -if (env->interrupt_request &CPU_INTERRUPT_INIT ) { -kvm_cpu_synchronize_state (env); -do_cpu_init (cpu); - }if (env->interrupt_request &CPU_INTERRUPT_SIPI ) {kvm_cpu_synchronize_state (env);do_cpu_sipi (cpu);Signature · 1 line
1.8.1.4
--
Gleb.
Paolo Bonzini
maintainerRe: [PATCH uq/master 2/2] kvm: forward INIT signals coming from the chipset
Il 10/03/2013 12:54, Gleb Natapov ha scritto:
Quoted 52 lines · Paolo Bonzini
Quoted 51 lines
CPU_INTERRUPT_INITcan also be generated if you have an internal APIC, since the keyboard controller and the southbridge can also pulse the CPU's INIT# pin.Exit the VCPU is one is received, and process it by changing the
mp_statetoKVM_MP_STATE_INIT_RECEIVED.Signed-off-by Paolo Bonzini <[email protected]>--- target-i386/kvm.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-)target-i386/kvm.c +9
-7@@ -1772,14 +1772,15 @@ void kvm_arch_pre_run(CPUState *cpu, struct kvm_run *run) } } -if (!kvm_irqchip_in_kernel ()) { -/* Force the VCPU out of its inner loop to process any INIT requests -* or pending TPR access reports. */ -if (env->interrupt_request & - (CPU_INTERRUPT_INIT |CPU_INTERRUPT_TPR )) { - cpu->exit_request =1 ; - } +/* Force the VCPU out of its inner loop to process any INIT requests +* or (for userspace APIC, but it is cheap to combine the checks here) +* pending TPR access reports. +*/ +if (env->interrupt_request & (CPU_INTERRUPT_INIT |CPU_INTERRUPT_TPR )) { + cpu->exit_request =1 ; + } +if (!kvm_irqchip_in_kernel ()) {/* Try to inject an interrupt if the guest can accept it */ if (run->ready_for_interrupt_injection && (env->interrupt_request & CPU_INTERRUPT_HARD) &&@@ -1835,6 +1836,7 @@ int kvm_arch_process_async_events(CPUState *cs) {X86CPU *cpu =X86_CPU (cs);CPUX86State *env = &cpu->env; +int ret;if (env->interrupt_request &CPU_INTERRUPT_MCE ) {/* We must not raise CPU_INTERRUPT_MCE if it's not supported. */ @@ -1859,6 +1861,20 @@ int kvm_arch_process_async_events(CPUState *cs) } }
Quoted 16 lines
Quoted 4 lines
target-i386/kvm.c +4
-0+if (env->interrupt_request &CPU_INTERRUPT_INIT ) { +kvm_cpu_synchronize_state (env); +if (kvm_irqchip_in_kernel ()) { + env->mp_state =KVM_MP_STATE_INIT_RECEIVED ;target-i386/kvm.c int kvm_arch_process_async_events(CPUState *cs) · line 1877
Quoted 10 lines
target-i386/kvm.c +10
-0+ env->interrupt_request =0 ; + ret =kvm_put_mp_state (cpu); +if (ret <0 ) { +return ret; + } + }else { +do_cpu_init (cpu); + } + } +Why not move INIT case from below as is? Vcpu is reset to correct sate by QEMU just like during
system_reset.
APs would not be able to receive SIPIs after executing do_cpu_init, because they would stay in KVM_MP_STATE_RUNNABLE state.
Paolo
Quoted 25 lines
Quoted 16 lines
target-i386/kvm.c +0
-4if (kvm_irqchip_in_kernel ()) {return 0 ; }@@ -1872,10 +1888,6 @@ int kvm_arch_process_async_events(CPUState *cs) (env->interrupt_request & CPU_INTERRUPT_NMI)) { env->halted =0 ; } -if (env->interrupt_request &CPU_INTERRUPT_INIT ) { -kvm_cpu_synchronize_state (env); -do_cpu_init (cpu); - }if (env->interrupt_request &CPU_INTERRUPT_SIPI ) {kvm_cpu_synchronize_state (env);do_cpu_sipi (cpu);Signature · 1 line
1.8.1.4--
Gleb.
--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH uq/master 2/2] kvm: forward INIT signals coming from the chipset
Quoted 70 lines · Paolo Bonzini
Il 10/03/2013 12:54, Gleb Natapov ha scritto:
Quoted 52 lines · Paolo Bonzini
Quoted 51 lines
CPU_INTERRUPT_INITcan also be generated if you have an internal APIC, since the keyboard controller and the southbridge can also pulse the CPU's INIT# pin.Exit the VCPU is one is received, and process it by changing the
mp_statetoKVM_MP_STATE_INIT_RECEIVED.Signed-off-by Paolo Bonzini <[email protected]>--- target-i386/kvm.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-)target-i386/kvm.c +9
-7@@ -1772,14 +1772,15 @@ void kvm_arch_pre_run(CPUState *cpu, struct kvm_run *run) } } -if (!kvm_irqchip_in_kernel ()) { -/* Force the VCPU out of its inner loop to process any INIT requests -* or pending TPR access reports. */ -if (env->interrupt_request & - (CPU_INTERRUPT_INIT |CPU_INTERRUPT_TPR )) { - cpu->exit_request =1 ; - } +/* Force the VCPU out of its inner loop to process any INIT requests +* or (for userspace APIC, but it is cheap to combine the checks here) +* pending TPR access reports. +*/ +if (env->interrupt_request & (CPU_INTERRUPT_INIT |CPU_INTERRUPT_TPR )) { + cpu->exit_request =1 ; + } +if (!kvm_irqchip_in_kernel ()) {/* Try to inject an interrupt if the guest can accept it */ if (run->ready_for_interrupt_injection && (env->interrupt_request & CPU_INTERRUPT_HARD) &&@@ -1835,6 +1836,7 @@ int kvm_arch_process_async_events(CPUState *cs) {X86CPU *cpu =X86_CPU (cs);CPUX86State *env = &cpu->env; +int ret;if (env->interrupt_request &CPU_INTERRUPT_MCE ) {/* We must not raise CPU_INTERRUPT_MCE if it's not supported. */ @@ -1859,6 +1861,20 @@ int kvm_arch_process_async_events(CPUState *cs) } }Quoted 16 lines
Quoted 4 lines
target-i386/kvm.c +4
-0+if (env->interrupt_request &CPU_INTERRUPT_INIT ) { +kvm_cpu_synchronize_state (env); +if (kvm_irqchip_in_kernel ()) { + env->mp_state =KVM_MP_STATE_INIT_RECEIVED ;target-i386/kvm.c int kvm_arch_process_async_events(CPUState *cs) · line 1877
Quoted 10 lines
target-i386/kvm.c +10
-0+ env->interrupt_request =0 ; + ret =kvm_put_mp_state (cpu); +if (ret <0 ) { +return ret; + } + }else { +do_cpu_init (cpu); + } + } +Why not move INIT case from below as is? Vcpu is reset to correct sate by QEMU just like during
system_reset.
Quoted 3 lines
APs would not be able to receive SIPIs after executing
do_cpu_init, because they would stay inKVM_MP_STATE_RUNNABLEstate.
If APs are in runnable state after reset with in kernel irq chip we have a bug somewhere. Should AP be able to get SIPI without INIT after trigger of INIT# line?
--
Gleb.
Paolo Bonzini
maintainerRe: [PATCH uq/master 2/2] kvm: forward INIT signals coming from the chipset
Il 10/03/2013 15:55, Gleb Natapov ha scritto:
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Why not move INIT case from below as is? Vcpu is reset to correct sate by QEMU just like during
system_reset.APs would not be able to receive SIPIs after executing
do_cpu_init, because they would stay inKVM_MP_STATE_RUNNABLEstate.If APs are in runnable state after reset with in kernel irq chip we have a bug somewhere.
Here is where we are resetting the processor. After clearing CPU_INTERRUPT_INIT, no matter what else we do (such as resetting the APIC and CPU), we need to set the mp_state to KVM_MP_STATE_INIT_RECEIVED.
Or if we go with your simpler hypervisor patch, we need to go to either KVM_MP_STATE_INIT_RECEIVED for APs (wait for SIPI) or KVM_MP_STATE_SIPI_RECEIVED for the BSP (restart running from the reset vector).
Quoted 1 line
Should AP be able to get SIPI without INIT after trigger of INIT# line?
Yes, the effect is the same for an INIT interrupt and the triggering of INIT#.
Paolo
Re: [PATCH uq/master 2/2] kvm: forward INIT signals coming from the chipset
Quoted 10 lines · Paolo Bonzini
Il 10/03/2013 15:55, Gleb Natapov ha scritto:
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Why not move INIT case from below as is? Vcpu is reset to correct sate by QEMU just like during
system_reset.APs would not be able to receive SIPIs after executing
do_cpu_init, because they would stay inKVM_MP_STATE_RUNNABLEstate.If APs are in runnable state after reset with in kernel irq chip we have a bug somewhere.
Quoted 9 lines
Here is where we are resetting the processor. After clearing
CPU_INTERRUPT_INIT, no matter what else we do (such as resetting the APIC and CPU), we need to set themp_statetoKVM_MP_STATE_INIT_RECEIVED.Or if we go with your simpler hypervisor patch, we need to go to either
KVM_MP_STATE_INIT_RECEIVEDfor APs (wait for SIPI) orKVM_MP_STATE_SIPI_RECEIVEDfor the BSP (restart running from the reset vector).
No need for KVM_MP_STATE_SIPI_RECEIVED. Just make it RUNNING. This is similar to system_reset path, not? UNINIT for AP, RUNNING for BSP.
Quoted 5 lines
Quoted 1 line
Should AP be able to get SIPI without INIT after trigger of INIT# line?
Yes, the effect is the same for an INIT interrupt and the triggering of INIT#.
Can you give me SDM pointer?
--
Gleb.
Paolo Bonzini
maintainerRe: [PATCH uq/master 2/2] kvm: forward INIT signals coming from the chipset
Il 10/03/2013 16:24, Gleb Natapov ha scritto:
Quoted 23 lines · Paolo Bonzini
Quoted 10 lines
Il 10/03/2013 15:55, Gleb Natapov ha scritto:
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Why not move INIT case from below as is? Vcpu is reset to correct sate by QEMU just like during
system_reset.APs would not be able to receive SIPIs after executing
do_cpu_init, because they would stay inKVM_MP_STATE_RUNNABLEstate.If APs are in runnable state after reset with in kernel irq chip we have a bug somewhere.
Quoted 9 lines
Here is where we are resetting the processor. After clearing
CPU_INTERRUPT_INIT, no matter what else we do (such as resetting the APIC and CPU), we need to set themp_statetoKVM_MP_STATE_INIT_RECEIVED.Or if we go with your simpler hypervisor patch, we need to go to either
KVM_MP_STATE_INIT_RECEIVEDfor APs (wait for SIPI) orKVM_MP_STATE_SIPI_RECEIVEDfor the BSP (restart running from the reset vector).No need for
KVM_MP_STATE_SIPI_RECEIVED. Just make it RUNNING. This is similar tosystem_resetpath, not? UNINIT for AP, RUNNING for BSP.
Quoted 6 lines
Quoted 5 lines
Quoted 1 line
Should AP be able to get SIPI without INIT after trigger of INIT# line?
Yes, the effect is the same for an INIT interrupt and the triggering of INIT#.
Can you give me SDM pointer?
10.4.7.3 Local APIC State After an INIT Reset (“Wait-for-SIPI” State)
An INIT reset of the processor can be initiated in either of two ways:
• By asserting the processor’s INIT# pin.
• By sending the processor an INIT IPI (an IPI with the delivery mode set to INIT).
Upon receiving an INIT through either of these mechanisms, the processor responds by beginning the initialization process of the processor core and the local APIC. The state of the local APIC following an INIT reset is the same as it is after a power-up or
hardware RESET, except that the APIC ID and arbitration ID registers are not affected. This state is also referred to at the “wait-for-SIPI” state (see also: Section 8.4.2, “MP Initialization Protocol Requirements and Restrictions”).
Paolo