correctly reset the CPU on INIT interrupts
v3 cover correctly reset the CPU on INIT interrupts
These patches finally implement INIT entirely in userspace. The problem here was that the CPU was being reset after kvm_arch_reset_vcpu is called. This made it harder to hook into the reset process and put APs into KVM_MP_STATE_INIT_RECEIVED state (instead of KVM_MP_STATE_UNINITIALIZED which is the state after a system reset).
In this series, patch 1 removes the kvm_arch_reset_vcpu from the generic code, and moves it into each architecture's CPU reset callback (half of our supported architectures do not need the callback anyway).
With this in place, patch 2 can add a similar x86-specific callback that is used after an INIT reset. Apart from this callback, the code for INITs is shared entirely between the userspace irqchip and in-kernel irqchip cases.
v2->v3: add stub kvm_arch_reset_vcpu for s390
Paolo Bonzini (2):
kvm: reset state from the CPU's reset method
kvm: forward INIT signals coming from the chipset
include/sysemu/kvm.h | 2 -- kvm-all.c | 11 ----------- target-arm/kvm.c | 4 ---- target-i386/cpu.c | 5 +++++ target-i386/helper.c | 4 ++++ target-i386/kvm.c | 37 ++++++++++++++++++++++++++----------- target-i386/kvm_i386.h | 2 ++ target-ppc/kvm.c | 4 ---- target-s390x/cpu.c | 4 ++++ target-s390x/cpu.h | 5 +++++ 10 files changed, 46 insertions(+), 32 deletions(-)
Signature · 1 line
1.8.1.4
PATCH v3 1/2 kvm: reset state from the CPU's reset method
Now that we have a CPU object with a reset method, it is better to keep the KVM reset close to the CPU reset. Using qemu_register_reset as we do now keeps them far apart.
---
v2->v3: add stub kvm_arch_reset_vcpu for s390
include/sysemu/kvm.h | 2 -- kvm-all.c | 11 ----------- target-arm/kvm.c | 4 ---- target-i386/cpu.c | 5 +++++ target-i386/kvm_i386.h | 1 + target-ppc/kvm.c | 4 ---- target-s390x/cpu.c | 4 ++++ target-s390x/cpu.h | 5 +++++ 8 files changed, 15 insertions(+), 21 deletions(-)
include/sysemu/kvm.h +0 -2
@@ -199,8 +199,6 @@ int kvm_arch_init_vcpu(CPUState *cpu);/* Returns VCPU ID to be used on KVM_CREATE_VCPU ioctl() */ unsigned long kvm_arch_vcpu_id (CPUState *cpu); -void kvm_arch_reset_vcpu (CPUState *cpu); -int kvm_arch_on_sigbus_vcpu (CPUState *cpu,int code,void *addr);int kvm_arch_on_sigbus (int code,void *addr);
kvm-all.c +0 -11
@@ -207,13 +207,6 @@ static int kvm_set_user_memory_region(KVMState *s, KVMSlot *slot)return kvm_vm_ioctl (s,KVM_SET_USER_MEMORY_REGION , &mem); } -static void kvm_reset_vcpu (void *opaque) -{ -CPUState *cpu = opaque; - -kvm_arch_reset_vcpu (cpu); -} -int kvm_init_vcpu (CPUState *cpu) {KVMState *s = kvm_state;
@@ -253,10 +246,6 @@ int kvm_init_vcpu(CPUState *cpu) } ret =kvm_arch_init_vcpu (cpu); -if (ret ==0 ) { -qemu_register_reset (kvm_reset_vcpu, cpu); -kvm_arch_reset_vcpu (cpu); - } err:return ret; }
target-arm/kvm.c +0 -4
@@ -430,10 +430,6 @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run)return 0 ; } -void kvm_arch_reset_vcpu (CPUState *cs) -{ -} -bool kvm_arch_stop_on_emulation_error (CPUState *cs) {return true;
target-i386/cpu.c +5 -0
@@ -24,6 +24,7 @@#include "cpu.h" #include "sysemu/kvm.h" #include "sysemu/cpus.h" +#include "kvm_i386.h" #include "topology.h" #include "qemu/option.h"
@@ -2015,6 +2016,10 @@ static void x86_cpu_reset(CPUState *s) } s->halted = !cpu_is_bsp (cpu); + +if (kvm_enabled ()) { +kvm_arch_reset_vcpu (s); + }#endif }
target-i386/kvm_i386.h +1 -0
@@ -14,6 +14,7 @@#include "sysemu/kvm.h" bool kvm_allows_irq0_override (void ); +void kvm_arch_reset_vcpu (CPUState *cs);int kvm_device_pci_assign (KVMState *s,PCIHostDeviceAddress *dev_addr,uint32_t flags,uint32_t *dev_id);
target-ppc/kvm.c +0 -4
@@ -425,10 +425,6 @@ int kvm_arch_init_vcpu(CPUState *cs)return ret; } -void kvm_arch_reset_vcpu (CPUState *cpu) -{ -} -static void kvm_sw_tlb_put (PowerPCCPU *cpu) {CPUPPCState *env = &cpu->env;
target-s390x/cpu.c +4 -0
@@ -84,6 +84,10 @@ static void s390_cpu_reset(CPUState *s)* after incrementing the cpu counter */ #if !defined(CONFIG_USER_ONLY ) s->halted =1 ; + +if (kvm_enabled ()) { +kvm_arch_reset_vcpu (s); + }#endif tlb_flush (env,1 ); }
target-s390x/cpu.h +5 -0
@@ -352,11 +352,16 @@ void s390x_cpu_timer(void *opaque);int s390_virtio_hypercall (CPUS390XState *env);#ifdef CONFIG_KVM +void kvm_arch_reset_vcpu (CPUState *cs);void kvm_s390_interrupt (S390CPU *cpu,int type,uint32_t code);void kvm_s390_virtio_irq (S390CPU *cpu,int config_change,uint64_t token);void kvm_s390_interrupt_internal (S390CPU *cpu,int type,uint32_t parm,uint64_t parm64,int vm);#else +static inline void kvm_arch_reset_vcpu (CPUState *cs) +{ +} +static inline void kvm_s390_interrupt (S390CPU *cpu,int type,uint32_t code) { }
Signature · 1 line
1.8.1.4
Re: [Qemu-devel] [PATCH uq/master v3 1/2] kvm: reset state from the CPU's reset method
Am 15.04.2013 14:05, schrieb Paolo Bonzini:
Quoted 8 lines
Now that we have a CPU object with a reset method, it is better to keep the KVM reset close to the CPU reset. Using
qemu_register_resetas we do now keeps them far apart.Signed-off-by Paolo Bonzini <[email protected]>---
v2->v3: add stub kvm_arch_reset_vcpu for s390
Quoted 9 lines
include/sysemu/kvm.h | 2 -- kvm-all.c | 11 ----------- target-arm/kvm.c | 4 ---- target-i386/cpu.c | 5 +++++ target-i386/kvm_i386.h | 1 + target-ppc/kvm.c | 4 ---- target-s390x/cpu.c | 4 ++++ target-s390x/cpu.h | 5 +++++ 8 files changed, 15 insertions(+), 21 deletions(-)
Fine with me.
Have you tested whether i386 needs a similar stub on non-x86? If so then
For anyone else wondering, arm and ppc are no longer calling the kvm_arch_ function, so it can get removed there, while i386 and s390x call it from X86CPU/S390CPU reset handler now. Would be more clear if the commit message was more verbose ;) and would be nice to clean this up as follow-up by renaming to kvm_x86_... and kvm_s390_... or so respectively.
Andreas
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Re: [Qemu-devel] [PATCH uq/master v3 1/2] kvm: reset state from the CPU's reset method
Il 15/04/2013 14:20, Andreas Färber ha scritto:
Quoted 5 lines
Fine with me.
Have you tested whether i386 needs a similar stub on non-x86? If so then
Reviewed-by Andreas Färber <[email protected]>
It doesn't need it, because the prototype is declared always in kvm_i386.h.
I didn't test non-x86, but I tested an alternative patches that places s390's kvm_arch_reset_vcpu prototype outside "#ifdef CONFIG_KVM". That also compiled fine on non-s390, and it's what will happen when compiling on non-x86.
I figured that the dummy inline definition was closer in style to the existing s390 code, so that's what I chose for submission.
Paolo
Re: [Qemu-devel] [PATCH uq/master v3 1/2] kvm: reset state from the CPU's reset method
In reply to Paolo BonziniQuoted 148 lines · Paolo Bonzini
Now that we have a CPU object with a reset method, it is better to keep the KVM reset close to the CPU reset. Using
qemu_register_resetas we do now keeps them far apart.Signed-off-by Paolo Bonzini <[email protected]>---
v2->v3: add stub kvm_arch_reset_vcpu for s390include/sysemu/kvm.h | 2 -- kvm-all.c | 11 ----------- target-arm/kvm.c | 4 ---- target-i386/cpu.c | 5 +++++ target-i386/kvm_i386.h | 1 + target-ppc/kvm.c | 4 ---- target-s390x/cpu.c | 4 ++++ target-s390x/cpu.h | 5 +++++ 8 files changed, 15 insertions(+), 21 deletions(-)include/sysemu/kvm.h +0
-2@@ -199,8 +199,6 @@ int kvm_arch_init_vcpu(CPUState *cpu);/* Returns VCPU ID to be used on KVM_CREATE_VCPU ioctl() */ unsigned long kvm_arch_vcpu_id (CPUState *cpu); -void kvm_arch_reset_vcpu (CPUState *cpu); -int kvm_arch_on_sigbus_vcpu (CPUState *cpu,int code,void *addr);int kvm_arch_on_sigbus (int code,void *addr);kvm-all.c +0
-11@@ -207,13 +207,6 @@ static int kvm_set_user_memory_region(KVMState *s, KVMSlot *slot)return kvm_vm_ioctl (s,KVM_SET_USER_MEMORY_REGION , &mem); } -static void kvm_reset_vcpu (void *opaque) -{ -CPUState *cpu = opaque; - -kvm_arch_reset_vcpu (cpu); -} -int kvm_init_vcpu (CPUState *cpu) {KVMState *s = kvm_state;@@ -253,10 +246,6 @@ int kvm_init_vcpu(CPUState *cpu) } ret =kvm_arch_init_vcpu (cpu); -if (ret ==0 ) { -qemu_register_reset (kvm_reset_vcpu, cpu); -kvm_arch_reset_vcpu (cpu); - } err:return ret; }target-arm/kvm.c +0
-4@@ -430,10 +430,6 @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run)return 0 ; } -void kvm_arch_reset_vcpu (CPUState *cs) -{ -} -bool kvm_arch_stop_on_emulation_error (CPUState *cs) {return true;target-i386/cpu.c +5
-0@@ -24,6 +24,7 @@#include "cpu.h" #include "sysemu/kvm.h" #include "sysemu/cpus.h" +#include "kvm_i386.h" #include "topology.h" #include "qemu/option.h" @@ -2015,6 +2016,10 @@ static void x86_cpu_reset(CPUState *s) } s->halted = !cpu_is_bsp (cpu); + +if (kvm_enabled ()) { +kvm_arch_reset_vcpu (s); + }#endif }target-i386/kvm_i386.h +1
-0@@ -14,6 +14,7 @@#include "sysemu/kvm.h" bool kvm_allows_irq0_override (void ); +void kvm_arch_reset_vcpu (CPUState *cs);int kvm_device_pci_assign (KVMState *s,PCIHostDeviceAddress *dev_addr,uint32_t flags,uint32_t *dev_id);target-ppc/kvm.c +0
-4@@ -425,10 +425,6 @@ int kvm_arch_init_vcpu(CPUState *cs)return ret; } -void kvm_arch_reset_vcpu (CPUState *cpu) -{ -} -static void kvm_sw_tlb_put (PowerPCCPU *cpu) {CPUPPCState *env = &cpu->env;target-s390x/cpu.c +4
-0@@ -84,6 +84,10 @@ static void s390_cpu_reset(CPUState *s)* after incrementing the cpu counter */ #if !defined(CONFIG_USER_ONLY ) s->halted =1 ; + +if (kvm_enabled ()) { +kvm_arch_reset_vcpu (s); + }#endif tlb_flush (env,1 ); }target-s390x/cpu.h +0
-0@@ -352,11 +352,16 @@ void s390x_cpu_timer(void *opaque);int s390_virtio_hypercall (CPUS390XState *env);#ifdef CONFIG_KVM
target-s390x/cpu.h void s390x_cpu_timer(void *opaque); · line 364
Quoted 10 lines
target-s390x/cpu.h +5
-0+void kvm_arch_reset_vcpu (CPUState *cs);void kvm_s390_interrupt (S390CPU *cpu,int type,uint32_t code);void kvm_s390_virtio_irq (S390CPU *cpu,int config_change,uint64_t token);void kvm_s390_interrupt_internal (S390CPU *cpu,int type,uint32_t parm,uint64_t parm64,int vm);#else +static inline void kvm_arch_reset_vcpu (CPUState *cs) +{ +} +
You added stub to s390, but not to x86. It will compile either way with current enough gcc, but I wonder why the inconsistency?
Quoted 6 lines
target-s390x/cpu.h +0
-0static inline void kvm_s390_interrupt (S390CPU *cpu,int type,uint32_t code) { }Signature · 1 line
1.8.1.4
--
Gleb.
Re: [Qemu-devel] [PATCH uq/master v3 1/2] kvm: reset state from the CPU's reset method
Il 18/04/2013 07:37, Gleb Natapov ha scritto:
Quoted 7 lines
Quoted 4 lines
target-s390x/cpu.h void s390x_cpu_timer(void *opaque); · line 364
Quoted 4 lines
target-s390x/cpu.h +4
-0+static inline void kvm_arch_reset_vcpu (CPUState *cs) +{ +} +You added stub to s390, but not to x86. It will compile either way with current enough gcc, but I wonder why the inconsistency?
Because I kept it consistent within the file. s390 prefers stubs, x86 prefers no stubs.
Paolo
PATCH v3 2/2 kvm: forward INIT signals coming from the chipset
In reply to Paolo Bonzini--- target-i386/helper.c | 4 ++++ target-i386/kvm.c | 37 ++++++++++++++++++++++++++----------- target-i386/kvm_i386.h | 1 + 3 files changed, 31 insertions(+), 11 deletions(-)
target-i386/helper.c +4 -0
@@ -19,6 +19,7 @@#include "cpu.h" #include "sysemu/kvm.h" +#include "kvm_i386.h" #ifndef CONFIG_USER_ONLY #include "sysemu/sysemu.h" #include "monitor/monitor.h"
@@ -1290,6 +1291,9 @@ void do_cpu_init(X86CPU *cpu)cpu_reset (cs); cs->interrupt_request = sipi; env->pat = pat; +if (kvm_enabled ()) { +kvm_arch_do_init_vcpu (cs); + }apic_init_reset (env->apic_state); }
target-i386/kvm.c +26 -11
@@ -30,6 +30,8 @@#include "qemu/config-file.h" #include "hw/i386/pc.h" #include "hw/i386/apic.h" +#include "hw/i386/apic_internal.h" +#include "hw/i386/apic-msidef.h" #include "exec/ioport.h" #include "hyperv.h" #include "hw/pci/pci.h"
@@ -676,6 +678,17 @@ void kvm_arch_reset_vcpu(CPUState *cs) } } +void kvm_arch_do_init_vcpu (CPUState *cs) +{ +X86CPU *cpu =X86_CPU (cs); +CPUX86State *env = &cpu->env; + +/* APs get directly into wait-for-SIPI state. */ +if (env->mp_state ==KVM_MP_STATE_UNINITIALIZED ) { + env->mp_state =KVM_MP_STATE_INIT_RECEIVED ; + } +} +static int kvm_get_supported_msrs (KVMState *s) {static int kvm_supported_msrs;
@@ -1773,14 +1786,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 (cpu->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 (cpu->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 && (cpu->interrupt_request & CPU_INTERRUPT_HARD) &&
@@ -1860,6 +1874,11 @@ int kvm_arch_process_async_events(CPUState *cs) } } +if (cs->interrupt_request &CPU_INTERRUPT_INIT ) { +kvm_cpu_synchronize_state (env); +do_cpu_init (cpu); + } +if (kvm_irqchip_in_kernel ()) {return 0 ; }
@@ -1873,10 +1892,6 @@ int kvm_arch_process_async_events(CPUState *cs) (cs->interrupt_request & CPU_INTERRUPT_NMI)) { cs->halted =0 ; } -if (cs->interrupt_request &CPU_INTERRUPT_INIT ) { -kvm_cpu_synchronize_state (env); -do_cpu_init (cpu); - }if (cs->interrupt_request &CPU_INTERRUPT_SIPI ) {kvm_cpu_synchronize_state (env);do_cpu_sipi (cpu);
target-i386/kvm_i386.h +1 -0
@@ -15,6 +15,7 @@bool kvm_allows_irq0_override (void );void kvm_arch_reset_vcpu (CPUState *cs); +void kvm_arch_do_init_vcpu (CPUState *cs);int kvm_device_pci_assign (KVMState *s,PCIHostDeviceAddress *dev_addr,uint32_t flags,uint32_t *dev_id);
Signature · 1 line
1.8.1.4
Quoted 6 lines · Paolo Bonzini
These patches finally implement INIT entirely in userspace. The problem here was that the CPU was being reset after
kvm_arch_reset_vcpuis called. This made it harder to hook into the reset process and put APs intoKVM_MP_STATE_INIT_RECEIVEDstate (instead ofKVM_MP_STATE_UNINITIALIZEDwhich is the state after a system reset).
Quoted 9 lines
In this series, patch 1 removes the
kvm_arch_reset_vcpufrom the generic code, and moves it into each architecture's CPU reset callback (half of our supported architectures do not need the callback anyway).With this in place, patch 2 can add a similar x86-specific callback that is used after an INIT reset. Apart from this callback, the code for INITs is shared entirely between the userspace irqchip and in-kernel irqchip cases.
Quoted 6 lines
v2->v3: add stubkvm_arch_reset_vcpufor s390Paolo Bonzini (2):
kvm: reset state from the CPU's reset method
kvm: forward INIT signals coming from the chipset
Quoted 14 lines
include/sysemu/kvm.h | 2 -- kvm-all.c | 11 ----------- target-arm/kvm.c | 4 ---- target-i386/cpu.c | 5 +++++ target-i386/helper.c | 4 ++++ target-i386/kvm.c | 37 ++++++++++++++++++++++++++----------- target-i386/kvm_i386.h | 2 ++ target-ppc/kvm.c | 4 ---- target-s390x/cpu.c | 4 ++++ target-s390x/cpu.h | 5 +++++ 10 files changed, 46 insertions(+), 32 deletions(-)Signature · 1 line
1.8.1.4
--
Gleb.