Skip to contentSkip to conversation

CPU reset (INIT#) support for KVM

PATCH In review Paolo Bonzini 2 participants 9 messages Mar 9, 2013 – Mar 11, 2013 KVM

lore
Share & tools
lore

Paolo Bonzini

author maintainer
#0 lore raw

cover 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 apic

Paolo

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
author maintainer
#1 lore raw

PATCH 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
index 4decfdc..bc1534c 100644
@@ -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
author maintainer
#2 lore raw

PATCH 2/2 kvm: forward INIT signals coming from the chipset

In reply to Paolo Bonzini

CPU_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
index 0cf413d..56de77c 100644
@@ -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
#3 lore raw

Re: [PATCH uq/master 2/2] kvm: forward INIT signals coming from the chipset

Quoted 55 lines · Paolo Bonzini

CPU_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 +13 -7
index 0cf413d..56de77c 100644
@@ -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 -4
     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

--
Gleb.

author maintainer
#4 lore raw

Re: [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_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 +9 -7
index 0cf413d..56de77c 100644
@@ -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 -4
     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

--
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

#5 lore raw

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_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 +9 -7
index 0cf413d..56de77c 100644
@@ -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 in KVM_MP_STATE_RUNNABLE state.

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.

author maintainer
#6 lore raw

Re: [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 in KVM_MP_STATE_RUNNABLE state.

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

#7 lore raw

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 in KVM_MP_STATE_RUNNABLE state.

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 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).

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.

author maintainer
#8 lore raw

Re: [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 in KVM_MP_STATE_RUNNABLE state.

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 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).

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 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