* [PATCH] kvm: kvm_init_vcpu take Error pointer
@ 2020-07-23 16:09 Dr. David Alan Gilbert (git)
2020-07-23 18:59 ` Philippe Mathieu-Daudé
0 siblings, 1 reply; 2+ messages in thread
From: Dr. David Alan Gilbert (git) @ 2020-07-23 16:09 UTC (permalink / raw)
To: qemu-devel, pbonzini
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
Clean up the error handling in kvm_init_vcpu so we can see what went
wrong more easily.
Make it take an Error ** and fill it out with what failed, including
the cpu id, so you can tell if it only fails at a given ID.
Replace the remaining DPRINTF by a trace.
This turns a:
kvm_init_vcpu failed: Invalid argument
into:
kvm_init_vcpu: kvm_get_vcpu failed (256): Invalid argument
and with the trace you then get to see:
19049@1595520414.310107:kvm_init_vcpu index: 169 id: 212
19050@1595520414.310635:kvm_init_vcpu index: 170 id: 256
qemu-system-x86_64: kvm_init_vcpu: kvm_get_vcpu failed (256): Invalid argument
which makes stuff a lot more obvious.
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
---
accel/kvm/kvm-all.c | 19 ++++++++++++++-----
accel/kvm/trace-events | 1 +
accel/stubs/kvm-stub.c | 2 +-
include/sysemu/kvm.h | 2 +-
softmmu/cpus.c | 6 +-----
5 files changed, 18 insertions(+), 12 deletions(-)
diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index 63ef6af9a1c..0fbece977c7 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -430,17 +430,18 @@ static int kvm_get_vcpu(KVMState *s, unsigned long vcpu_id)
return kvm_vm_ioctl(s, KVM_CREATE_VCPU, (void *)vcpu_id);
}
-int kvm_init_vcpu(CPUState *cpu)
+int kvm_init_vcpu(CPUState *cpu, Error **errp)
{
KVMState *s = kvm_state;
long mmap_size;
int ret;
- DPRINTF("kvm_init_vcpu\n");
+ trace_kvm_init_vcpu(cpu->cpu_index, kvm_arch_vcpu_id(cpu));
ret = kvm_get_vcpu(s, kvm_arch_vcpu_id(cpu));
if (ret < 0) {
- DPRINTF("kvm_create_vcpu failed\n");
+ error_setg_errno(errp, -ret, "kvm_init_vcpu: kvm_get_vcpu failed (%lu)",
+ kvm_arch_vcpu_id(cpu));
goto err;
}
@@ -451,7 +452,8 @@ int kvm_init_vcpu(CPUState *cpu)
mmap_size = kvm_ioctl(s, KVM_GET_VCPU_MMAP_SIZE, 0);
if (mmap_size < 0) {
ret = mmap_size;
- DPRINTF("KVM_GET_VCPU_MMAP_SIZE failed\n");
+ error_setg_errno(errp, -mmap_size,
+ "kvm_init_vcpu: KVM_GET_VCPU_MMAP_SIZE failed");
goto err;
}
@@ -459,7 +461,9 @@ int kvm_init_vcpu(CPUState *cpu)
cpu->kvm_fd, 0);
if (cpu->kvm_run == MAP_FAILED) {
ret = -errno;
- DPRINTF("mmap'ing vcpu state failed\n");
+ error_setg_errno(errp, ret,
+ "kvm_init_vcpu: mmap'ing vcpu state failed (%lu)",
+ kvm_arch_vcpu_id(cpu));
goto err;
}
@@ -469,6 +473,11 @@ int kvm_init_vcpu(CPUState *cpu)
}
ret = kvm_arch_init_vcpu(cpu);
+ if (ret < 0) {
+ error_setg_errno(errp, -ret,
+ "kvm_init_vcpu: kvm_arch_init_vcpu failed (%lu)",
+ kvm_arch_vcpu_id(cpu));
+ }
err:
return ret;
}
diff --git a/accel/kvm/trace-events b/accel/kvm/trace-events
index a68eb665343..e15ae8980d3 100644
--- a/accel/kvm/trace-events
+++ b/accel/kvm/trace-events
@@ -8,6 +8,7 @@ kvm_run_exit(int cpu_index, uint32_t reason) "cpu_index %d, reason %d"
kvm_device_ioctl(int fd, int type, void *arg) "dev fd %d, type 0x%x, arg %p"
kvm_failed_reg_get(uint64_t id, const char *msg) "Warning: Unable to retrieve ONEREG %" PRIu64 " from KVM: %s"
kvm_failed_reg_set(uint64_t id, const char *msg) "Warning: Unable to set ONEREG %" PRIu64 " to KVM: %s"
+kvm_init_vcpu(int cpu_index, unsigned long arch_cpu_id) "index: %d id: %lu"
kvm_irqchip_commit_routes(void) ""
kvm_irqchip_add_msi_route(char *name, int vector, int virq) "dev %s vector %d virq %d"
kvm_irqchip_update_msi_route(int virq) "Updating MSI route virq=%d"
diff --git a/accel/stubs/kvm-stub.c b/accel/stubs/kvm-stub.c
index 82f118d2df9..cd573bfe3d9 100644
--- a/accel/stubs/kvm-stub.c
+++ b/accel/stubs/kvm-stub.c
@@ -37,7 +37,7 @@ int kvm_destroy_vcpu(CPUState *cpu)
return -ENOSYS;
}
-int kvm_init_vcpu(CPUState *cpu)
+int kvm_init_vcpu(CPUState *cpu, Error **errp)
{
return -ENOSYS;
}
diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
index b4174d941c2..410848af514 100644
--- a/include/sysemu/kvm.h
+++ b/include/sysemu/kvm.h
@@ -216,7 +216,7 @@ int kvm_has_many_ioeventfds(void);
int kvm_has_gsi_routing(void);
int kvm_has_intx_set_mask(void);
-int kvm_init_vcpu(CPUState *cpu);
+int kvm_init_vcpu(CPUState *cpu, Error **errp);
int kvm_cpu_exec(CPUState *cpu);
int kvm_destroy_vcpu(CPUState *cpu);
diff --git a/softmmu/cpus.c b/softmmu/cpus.c
index a802e899abb..9725fd9951f 100644
--- a/softmmu/cpus.c
+++ b/softmmu/cpus.c
@@ -1170,11 +1170,7 @@ static void *qemu_kvm_cpu_thread_fn(void *arg)
cpu->can_do_io = 1;
current_cpu = cpu;
- r = kvm_init_vcpu(cpu);
- if (r < 0) {
- error_report("kvm_init_vcpu failed: %s", strerror(-r));
- exit(1);
- }
+ kvm_init_vcpu(cpu, &error_fatal);
kvm_init_cpu_signals(cpu);
--
2.26.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] kvm: kvm_init_vcpu take Error pointer
2020-07-23 16:09 [PATCH] kvm: kvm_init_vcpu take Error pointer Dr. David Alan Gilbert (git)
@ 2020-07-23 18:59 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 2+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-07-23 18:59 UTC (permalink / raw)
To: Dr. David Alan Gilbert (git), qemu-devel, pbonzini
On 7/23/20 6:09 PM, Dr. David Alan Gilbert (git) wrote:
> From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
>
> Clean up the error handling in kvm_init_vcpu so we can see what went
> wrong more easily.
>
> Make it take an Error ** and fill it out with what failed, including
> the cpu id, so you can tell if it only fails at a given ID.
>
> Replace the remaining DPRINTF by a trace.
>
> This turns a:
> kvm_init_vcpu failed: Invalid argument
>
> into:
> kvm_init_vcpu: kvm_get_vcpu failed (256): Invalid argument
>
> and with the trace you then get to see:
>
> 19049@1595520414.310107:kvm_init_vcpu index: 169 id: 212
> 19050@1595520414.310635:kvm_init_vcpu index: 170 id: 256
> qemu-system-x86_64: kvm_init_vcpu: kvm_get_vcpu failed (256): Invalid argument
>
> which makes stuff a lot more obvious.
>
> Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
> accel/kvm/kvm-all.c | 19 ++++++++++++++-----
> accel/kvm/trace-events | 1 +
> accel/stubs/kvm-stub.c | 2 +-
> include/sysemu/kvm.h | 2 +-
> softmmu/cpus.c | 6 +-----
> 5 files changed, 18 insertions(+), 12 deletions(-)
>
> diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
> index 63ef6af9a1c..0fbece977c7 100644
> --- a/accel/kvm/kvm-all.c
> +++ b/accel/kvm/kvm-all.c
> @@ -430,17 +430,18 @@ static int kvm_get_vcpu(KVMState *s, unsigned long vcpu_id)
> return kvm_vm_ioctl(s, KVM_CREATE_VCPU, (void *)vcpu_id);
> }
>
> -int kvm_init_vcpu(CPUState *cpu)
> +int kvm_init_vcpu(CPUState *cpu, Error **errp)
> {
> KVMState *s = kvm_state;
> long mmap_size;
> int ret;
>
> - DPRINTF("kvm_init_vcpu\n");
> + trace_kvm_init_vcpu(cpu->cpu_index, kvm_arch_vcpu_id(cpu));
>
> ret = kvm_get_vcpu(s, kvm_arch_vcpu_id(cpu));
> if (ret < 0) {
> - DPRINTF("kvm_create_vcpu failed\n");
> + error_setg_errno(errp, -ret, "kvm_init_vcpu: kvm_get_vcpu failed (%lu)",
> + kvm_arch_vcpu_id(cpu));
> goto err;
> }
>
> @@ -451,7 +452,8 @@ int kvm_init_vcpu(CPUState *cpu)
> mmap_size = kvm_ioctl(s, KVM_GET_VCPU_MMAP_SIZE, 0);
> if (mmap_size < 0) {
> ret = mmap_size;
> - DPRINTF("KVM_GET_VCPU_MMAP_SIZE failed\n");
> + error_setg_errno(errp, -mmap_size,
> + "kvm_init_vcpu: KVM_GET_VCPU_MMAP_SIZE failed");
> goto err;
> }
>
> @@ -459,7 +461,9 @@ int kvm_init_vcpu(CPUState *cpu)
> cpu->kvm_fd, 0);
> if (cpu->kvm_run == MAP_FAILED) {
> ret = -errno;
> - DPRINTF("mmap'ing vcpu state failed\n");
> + error_setg_errno(errp, ret,
> + "kvm_init_vcpu: mmap'ing vcpu state failed (%lu)",
> + kvm_arch_vcpu_id(cpu));
> goto err;
> }
>
> @@ -469,6 +473,11 @@ int kvm_init_vcpu(CPUState *cpu)
> }
>
> ret = kvm_arch_init_vcpu(cpu);
> + if (ret < 0) {
> + error_setg_errno(errp, -ret,
> + "kvm_init_vcpu: kvm_arch_init_vcpu failed (%lu)",
> + kvm_arch_vcpu_id(cpu));
> + }
> err:
> return ret;
> }
> diff --git a/accel/kvm/trace-events b/accel/kvm/trace-events
> index a68eb665343..e15ae8980d3 100644
> --- a/accel/kvm/trace-events
> +++ b/accel/kvm/trace-events
> @@ -8,6 +8,7 @@ kvm_run_exit(int cpu_index, uint32_t reason) "cpu_index %d, reason %d"
> kvm_device_ioctl(int fd, int type, void *arg) "dev fd %d, type 0x%x, arg %p"
> kvm_failed_reg_get(uint64_t id, const char *msg) "Warning: Unable to retrieve ONEREG %" PRIu64 " from KVM: %s"
> kvm_failed_reg_set(uint64_t id, const char *msg) "Warning: Unable to set ONEREG %" PRIu64 " to KVM: %s"
> +kvm_init_vcpu(int cpu_index, unsigned long arch_cpu_id) "index: %d id: %lu"
> kvm_irqchip_commit_routes(void) ""
> kvm_irqchip_add_msi_route(char *name, int vector, int virq) "dev %s vector %d virq %d"
> kvm_irqchip_update_msi_route(int virq) "Updating MSI route virq=%d"
> diff --git a/accel/stubs/kvm-stub.c b/accel/stubs/kvm-stub.c
> index 82f118d2df9..cd573bfe3d9 100644
> --- a/accel/stubs/kvm-stub.c
> +++ b/accel/stubs/kvm-stub.c
> @@ -37,7 +37,7 @@ int kvm_destroy_vcpu(CPUState *cpu)
> return -ENOSYS;
> }
>
> -int kvm_init_vcpu(CPUState *cpu)
> +int kvm_init_vcpu(CPUState *cpu, Error **errp)
> {
> return -ENOSYS;
> }
> diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
> index b4174d941c2..410848af514 100644
> --- a/include/sysemu/kvm.h
> +++ b/include/sysemu/kvm.h
> @@ -216,7 +216,7 @@ int kvm_has_many_ioeventfds(void);
> int kvm_has_gsi_routing(void);
> int kvm_has_intx_set_mask(void);
>
> -int kvm_init_vcpu(CPUState *cpu);
> +int kvm_init_vcpu(CPUState *cpu, Error **errp);
> int kvm_cpu_exec(CPUState *cpu);
> int kvm_destroy_vcpu(CPUState *cpu);
>
> diff --git a/softmmu/cpus.c b/softmmu/cpus.c
> index a802e899abb..9725fd9951f 100644
> --- a/softmmu/cpus.c
> +++ b/softmmu/cpus.c
> @@ -1170,11 +1170,7 @@ static void *qemu_kvm_cpu_thread_fn(void *arg)
> cpu->can_do_io = 1;
> current_cpu = cpu;
>
> - r = kvm_init_vcpu(cpu);
> - if (r < 0) {
> - error_report("kvm_init_vcpu failed: %s", strerror(-r));
> - exit(1);
> - }
> + kvm_init_vcpu(cpu, &error_fatal);
>
> kvm_init_cpu_signals(cpu);
>
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-07-23 19:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-23 16:09 [PATCH] kvm: kvm_init_vcpu take Error pointer Dr. David Alan Gilbert (git)
2020-07-23 18:59 ` Philippe Mathieu-Daudé
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.