From patchwork Mon Jan 24 09:02:25 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 80123 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 61186B7129 for ; Mon, 24 Jan 2011 20:56:13 +1100 (EST) Received: from localhost ([127.0.0.1]:56803 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PhJ9d-00028S-9M for incoming@patchwork.ozlabs.org; Mon, 24 Jan 2011 04:56:09 -0500 Received: from [140.186.70.92] (port=38123 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PhIMZ-0008RR-Lk for qemu-devel@nongnu.org; Mon, 24 Jan 2011 04:05:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PhIMQ-0007GI-7e for qemu-devel@nongnu.org; Mon, 24 Jan 2011 04:05:27 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49661) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PhIMP-0007Ex-S1 for qemu-devel@nongnu.org; Mon, 24 Jan 2011 04:05:18 -0500 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id p0O95GTN029012 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 24 Jan 2011 04:05:16 -0500 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p0O95Fq3014259; Mon, 24 Jan 2011 04:05:16 -0500 Received: from amt.cnet (vpn2-9-29.ams2.redhat.com [10.36.9.29]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id p0O95BSA008799; Mon, 24 Jan 2011 04:05:14 -0500 Received: from amt.cnet (localhost.localdomain [127.0.0.1]) by amt.cnet (Postfix) with ESMTP id 5C656652153; Mon, 24 Jan 2011 07:04:04 -0200 (BRST) Received: (from marcelo@localhost) by amt.cnet (8.14.4/8.14.4/Submit) id p0O9417C028402; Mon, 24 Jan 2011 07:04:01 -0200 From: Marcelo Tosatti To: Anthony Liguori Date: Mon, 24 Jan 2011 07:02:25 -0200 Message-Id: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: Jan Kiszka , Marcelo Tosatti , qemu-devel@nongnu.org, kvm@vger.kernel.org Subject: [Qemu-devel] [PATCH 16/31] kvm: Improve reporting of fatal errors X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Jan Kiszka Report KVM_EXIT_UNKNOWN, KVM_EXIT_FAIL_ENTRY, and KVM_EXIT_EXCEPTION with more details to stderr. The latter two are so far x86-only, so move them into the arch-specific handler. Integrate the Intel real mode warning on KVM_EXIT_FAIL_ENTRY that qemu-kvm carries, but actually restrict it to Intel CPUs. Moreover, always dump the CPU state in case we fail. Signed-off-by: Jan Kiszka Signed-off-by: Marcelo Tosatti --- kvm-all.c | 22 ++++++++-------------- target-i386/cpu.h | 2 ++ target-i386/cpuid.c | 5 ++--- target-i386/kvm.c | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 45 insertions(+), 17 deletions(-) diff --git a/kvm-all.c b/kvm-all.c index eaf9272..10e1194 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -817,22 +817,22 @@ static int kvm_handle_io(uint16_t port, void *data, int direction, int size, #ifdef KVM_CAP_INTERNAL_ERROR_DATA static int kvm_handle_internal_error(CPUState *env, struct kvm_run *run) { - + fprintf(stderr, "KVM internal error."); if (kvm_check_extension(kvm_state, KVM_CAP_INTERNAL_ERROR_DATA)) { int i; - fprintf(stderr, "KVM internal error. Suberror: %d\n", - run->internal.suberror); - + fprintf(stderr, " Suberror: %d\n", run->internal.suberror); for (i = 0; i < run->internal.ndata; ++i) { fprintf(stderr, "extra data[%d]: %"PRIx64"\n", i, (uint64_t)run->internal.data[i]); } + } else { + fprintf(stderr, "\n"); } - cpu_dump_state(env, stderr, fprintf, 0); if (run->internal.suberror == KVM_INTERNAL_ERROR_EMULATION) { fprintf(stderr, "emulation failure\n"); if (!kvm_arch_stop_on_emulation_error(env)) { + cpu_dump_state(env, stderr, fprintf, 0); return 0; } } @@ -966,15 +966,8 @@ int kvm_cpu_exec(CPUState *env) ret = 1; break; case KVM_EXIT_UNKNOWN: - DPRINTF("kvm_exit_unknown\n"); - ret = -1; - break; - case KVM_EXIT_FAIL_ENTRY: - DPRINTF("kvm_exit_fail_entry\n"); - ret = -1; - break; - case KVM_EXIT_EXCEPTION: - DPRINTF("kvm_exit_exception\n"); + fprintf(stderr, "KVM: unknown exit, hardware reason %" PRIx64 "\n", + (uint64_t)run->hw.hardware_exit_reason); ret = -1; break; #ifdef KVM_CAP_INTERNAL_ERROR_DATA @@ -1001,6 +994,7 @@ int kvm_cpu_exec(CPUState *env) } while (ret > 0); if (ret < 0) { + cpu_dump_state(env, stderr, fprintf, 0); vm_stop(0); env->exit_request = 1; } diff --git a/target-i386/cpu.h b/target-i386/cpu.h index dddcd74..a457423 100644 --- a/target-i386/cpu.h +++ b/target-i386/cpu.h @@ -874,6 +874,8 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, uint32_t *ecx, uint32_t *edx); int cpu_x86_register (CPUX86State *env, const char *cpu_model); void cpu_clear_apic_feature(CPUX86State *env); +void host_cpuid(uint32_t function, uint32_t count, + uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx); /* helper.c */ int cpu_x86_handle_mmu_fault(CPUX86State *env, target_ulong addr, diff --git a/target-i386/cpuid.c b/target-i386/cpuid.c index 165045e..5382a28 100644 --- a/target-i386/cpuid.c +++ b/target-i386/cpuid.c @@ -103,9 +103,8 @@ typedef struct model_features_t { int check_cpuid = 0; int enforce_cpuid = 0; -static void host_cpuid(uint32_t function, uint32_t count, - uint32_t *eax, uint32_t *ebx, - uint32_t *ecx, uint32_t *edx) +void host_cpuid(uint32_t function, uint32_t count, + uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx) { #if defined(CONFIG_KVM) uint32_t vec[4]; diff --git a/target-i386/kvm.c b/target-i386/kvm.c index 6b4abaa..0ba13fc 100644 --- a/target-i386/kvm.c +++ b/target-i386/kvm.c @@ -1525,8 +1525,19 @@ static int kvm_handle_halt(CPUState *env) return 1; } +static bool host_supports_vmx(void) +{ + uint32_t ecx, unused; + + host_cpuid(1, 0, &unused, &unused, &ecx, &unused); + return ecx & CPUID_EXT_VMX; +} + +#define VMX_INVALID_GUEST_STATE 0x80000021 + int kvm_arch_handle_exit(CPUState *env, struct kvm_run *run) { + uint64_t code; int ret = 0; switch (run->exit_reason) { @@ -1537,6 +1548,28 @@ int kvm_arch_handle_exit(CPUState *env, struct kvm_run *run) case KVM_EXIT_SET_TPR: ret = 1; break; + case KVM_EXIT_FAIL_ENTRY: + code = run->fail_entry.hardware_entry_failure_reason; + fprintf(stderr, "KVM: entry failed, hardware error 0x%" PRIx64 "\n", + code); + if (host_supports_vmx() && code == VMX_INVALID_GUEST_STATE) { + fprintf(stderr, + "\nIf you're runnning a guest on an Intel machine without " + "unrestricted mode\n" + "support, the failure can be most likely due to the guest " + "entering an invalid\n" + "state for Intel VT. For example, the guest maybe running " + "in big real mode\n" + "which is not supported on less recent Intel processors." + "\n\n"); + } + ret = -1; + break; + case KVM_EXIT_EXCEPTION: + fprintf(stderr, "KVM: exception %d exit (error code 0x%x)\n", + run->ex.exception, run->ex.error_code); + ret = -1; + break; default: fprintf(stderr, "KVM: unknown exit reason %d\n", run->exit_reason); ret = -1;