target-arm: Check error conditions on kvm_arm_reset_vcpu
PATCH 1/1 target-arm: Check error conditions on kvm_arm_reset_vcpu
When resetting a VCPU we currently call both kvm_arm_vcpu_init() and write_kvmstate_to_list(), both of which can fail, but we never check the return value.
The only choice here is to print an error an exit if the calls fail.
--- target-arm/kvm32.c | 13 +++++++++++-- target-arm/kvm64.c | 8 +++++++- 2 files changed, 18 insertions(+), 3 deletions(-)
target-arm/kvm32.c +11 -2
@@ -511,9 +511,18 @@ int kvm_arch_get_registers(CPUState *cs)void kvm_arm_reset_vcpu (ARMCPU *cpu) { +int ret; +/* Re-init VCPU so that all registers are set to * their respective reset values. */ -kvm_arm_vcpu_init (CPU (cpu)); -write_kvmstate_to_list (cpu); + ret =kvm_arm_vcpu_init (CPU (cpu)); +if (ret <0 ) { +fprintf (stderr,"kvm_arm_vcpu_init failed: %s\n" ,strerror (ret)); +abort (); + } +if (!write_kvmstate_to_list (cpu)) { +fprintf (stderr,"write_kvmstate_to_list failed\n" ); +abort (); + } }
target-arm/kvm64.c +7 -1
@@ -263,8 +263,14 @@ int kvm_arch_get_registers(CPUState *cs)void kvm_arm_reset_vcpu (ARMCPU *cpu) { +int ret; +/* Re-init VCPU so that all registers are set to * their respective reset values. */ -kvm_arm_vcpu_init (CPU (cpu)); + ret =kvm_arm_vcpu_init (CPU (cpu)); +if (ret <0 ) { +fprintf (stderr,"kvm_arm_vcpu_init failed: %s\n" ,strerror (ret)); +abort (); + } }
Signature · 1 line
2.1.2.330.g565301e.dirty
Quoted 5 lines · Christoffer Dall
When resetting a VCPU we currently call both
kvm_arm_vcpu_init()andwrite_kvmstate_to_list(), both of which can fail, but we never check the return value.The only choice here is to print an error an exit if the calls fail.
I like this patch, but it is going to conflict with a patch I'm nearly done testing and plan to send tomorrow that unifies the sysreg handling for 32 and 64 bit KVM/ARM. Part of what that involves is using a single kvm_arm_reset_vcpu() in kvm.c rather than different 32 and 64 bit versions. So you should probably respin this patch on top of that one.
Quoted 14 lines
Signed-off-by Christoffer Dall <[email protected]>--- target-arm/kvm32.c | 13 +++++++++++-- target-arm/kvm64.c | 8 +++++++- 2 files changed, 18 insertions(+), 3 deletions(-)target-arm/kvm32.c +0
-0@@ -511,9 +511,18 @@ int kvm_arch_get_registers(CPUState *cs)void kvm_arm_reset_vcpu (ARMCPU *cpu) {
target-arm/kvm32.c int kvm_arch_get_registers(CPUState *cs) · line 521
Quoted 10 lines
target-arm/kvm32.c +5
-2+int ret; +/* Re-init VCPU so that all registers are set to * their respective reset values. */ -kvm_arm_vcpu_init (CPU (cpu)); -write_kvmstate_to_list (cpu); + ret =kvm_arm_vcpu_init (CPU (cpu)); +if (ret <0 ) { +fprintf (stderr,"kvm_arm_vcpu_init failed: %s\n" ,strerror (ret));
Shouldn't this be strerror(-ret) ?
thanks
-- PMM
Quoted 6 lines · Peter Maydell
Quoted 4 lines · Christoffer Dall
When resetting a VCPU we currently call both
kvm_arm_vcpu_init()andwrite_kvmstate_to_list(), both of which can fail, but we never check the return value.
Quoted 9 lines
Quoted 1 line
The only choice here is to print an error an exit if the calls fail.
I like this patch, but it is going to conflict with a patch I'm nearly done testing and plan to send tomorrow that unifies the sysreg handling for 32 and 64 bit KVM/ARM. Part of what that involves is using a single
kvm_arm_reset_vcpu()inkvm.crather than different 32 and 64 bit versions. So you should probably respin this patch on top of that one.
ok, will do, or you can squash this into yours, as you like.
Quoted 12 lines
Quoted 12 lines
Signed-off-by Christoffer Dall <[email protected]>--- target-arm/kvm32.c | 13 +++++++++++-- target-arm/kvm64.c | 8 +++++++- 2 files changed, 18 insertions(+), 3 deletions(-)target-arm/kvm32.c +0
-0@@ -511,9 +511,18 @@ int kvm_arch_get_registers(CPUState *cs)
Quoted 15 lines
target-arm/kvm32.c int kvm_arch_get_registers(CPUState *cs) · line 521
Quoted 12 lines
target-arm/kvm32.c +5
-2void kvm_arm_reset_vcpu (ARMCPU *cpu) { +int ret; +/* Re-init VCPU so that all registers are set to * their respective reset values. */ -kvm_arm_vcpu_init (CPU (cpu)); -write_kvmstate_to_list (cpu); + ret =kvm_arm_vcpu_init (CPU (cpu)); +if (ret <0 ) { +fprintf (stderr,"kvm_arm_vcpu_init failed: %s\n" ,strerror (ret));Shouldn't this be strerror(-ret) ?
ah right, the init call returns a negative errno, but strerror expects the positive one.
-Christoffer