提交 854e42f3 编写于 作者: C Christian Borntraeger 提交者: Alexander Graf

s390: Fix cpu shutdown for KVM

On s390 a shutdown is the state of all CPUs being either stopped
or disabled (for interrupts) waiting. We have to track the overall
number of running CPUs to call the shutdown sequence accordingly.
This patch implements the counting and shutdown handling for the
kvm path in qemu.
Lets also wrap changes to env->halted and env->exception_index.
Signed-off-by: NChristian Borntraeger <borntraeger@de.ibm.com>
Signed-off-by: NAlexander Graf <agraf@suse.de>
上级 13449a6e
...@@ -121,6 +121,34 @@ int s390_virtio_hypercall(CPUState *env, uint64_t mem, uint64_t hypercall) ...@@ -121,6 +121,34 @@ int s390_virtio_hypercall(CPUState *env, uint64_t mem, uint64_t hypercall)
return r; return r;
} }
/*
* The number of running CPUs. On s390 a shutdown is the state of all CPUs
* being either stopped or disabled (for interrupts) waiting. We have to
* track this number to call the shutdown sequence accordingly. This
* number is modified either on startup or while holding the big qemu lock.
*/
static unsigned s390_running_cpus;
void s390_add_running_cpu(CPUState *env)
{
if (env->halted) {
s390_running_cpus++;
env->halted = 0;
env->exception_index = -1;
}
}
unsigned s390_del_running_cpu(CPUState *env)
{
if (env->halted == 0) {
assert(s390_running_cpus >= 1);
s390_running_cpus--;
env->halted = 1;
env->exception_index = EXCP_HLT;
}
return s390_running_cpus;
}
/* PC hardware initialisation */ /* PC hardware initialisation */
static void s390_init(ram_addr_t my_ram_size, static void s390_init(ram_addr_t my_ram_size,
const char *boot_device, const char *boot_device,
...@@ -179,8 +207,8 @@ static void s390_init(ram_addr_t my_ram_size, ...@@ -179,8 +207,8 @@ static void s390_init(ram_addr_t my_ram_size,
tmp_env->storage_keys = storage_keys; tmp_env->storage_keys = storage_keys;
} }
env->halted = 0; /* One CPU has to run */
env->exception_index = 0; s390_add_running_cpu(env);
if (kernel_filename) { if (kernel_filename) {
kernel_size = load_image(kernel_filename, qemu_get_ram_ptr(0)); kernel_size = load_image(kernel_filename, qemu_get_ram_ptr(0));
......
...@@ -309,6 +309,8 @@ static inline void kvm_s390_interrupt_internal(CPUState *env, int type, ...@@ -309,6 +309,8 @@ static inline void kvm_s390_interrupt_internal(CPUState *env, int type,
} }
#endif #endif
CPUState *s390_cpu_addr2state(uint16_t cpu_addr); CPUState *s390_cpu_addr2state(uint16_t cpu_addr);
void s390_add_running_cpu(CPUState *env);
unsigned s390_del_running_cpu(CPUState *env);
/* from s390-virtio-bus */ /* from s390-virtio-bus */
extern const target_phys_addr_t virtio_size; extern const target_phys_addr_t virtio_size;
......
...@@ -185,8 +185,7 @@ void kvm_s390_interrupt_internal(CPUState *env, int type, uint32_t parm, ...@@ -185,8 +185,7 @@ void kvm_s390_interrupt_internal(CPUState *env, int type, uint32_t parm,
return; return;
} }
env->halted = 0; s390_add_running_cpu(env);
env->exception_index = -1;
qemu_cpu_kick(env); qemu_cpu_kick(env);
kvmint.type = type; kvmint.type = type;
...@@ -299,8 +298,7 @@ static int handle_diag(CPUState *env, struct kvm_run *run, int ipb_code) ...@@ -299,8 +298,7 @@ static int handle_diag(CPUState *env, struct kvm_run *run, int ipb_code)
static int s390_cpu_restart(CPUState *env) static int s390_cpu_restart(CPUState *env)
{ {
kvm_s390_interrupt(env, KVM_S390_RESTART, 0); kvm_s390_interrupt(env, KVM_S390_RESTART, 0);
env->halted = 0; s390_add_running_cpu(env);
env->exception_index = -1;
qemu_cpu_kick(env); qemu_cpu_kick(env);
dprintf("DONE: SIGP cpu restart: %p\n", env); dprintf("DONE: SIGP cpu restart: %p\n", env);
return 0; return 0;
...@@ -425,17 +423,16 @@ static int handle_intercept(CPUState *env) ...@@ -425,17 +423,16 @@ static int handle_intercept(CPUState *env)
r = handle_instruction(env, run); r = handle_instruction(env, run);
break; break;
case ICPT_WAITPSW: case ICPT_WAITPSW:
/* XXX What to do on system shutdown? */ case ICPT_CPU_STOP:
env->halted = 1; if (s390_del_running_cpu(env) == 0) {
env->exception_index = EXCP_HLT; qemu_system_shutdown_request();
}
r = EXCP_HALTED;
break; break;
case ICPT_SOFT_INTERCEPT: case ICPT_SOFT_INTERCEPT:
fprintf(stderr, "KVM unimplemented icpt SOFT\n"); fprintf(stderr, "KVM unimplemented icpt SOFT\n");
exit(1); exit(1);
break; break;
case ICPT_CPU_STOP:
qemu_system_shutdown_request();
break;
case ICPT_IO: case ICPT_IO:
fprintf(stderr, "KVM unimplemented icpt IO\n"); fprintf(stderr, "KVM unimplemented icpt IO\n");
exit(1); exit(1);
...@@ -468,8 +465,6 @@ int kvm_arch_handle_exit(CPUState *env, struct kvm_run *run) ...@@ -468,8 +465,6 @@ int kvm_arch_handle_exit(CPUState *env, struct kvm_run *run)
if (ret == 0) { if (ret == 0) {
ret = EXCP_INTERRUPT; ret = EXCP_INTERRUPT;
} else if (ret > 0) {
ret = 0;
} }
return ret; return ret;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册