From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38601) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a1yqW-0005Ss-OP for qemu-devel@nongnu.org; Thu, 26 Nov 2015 10:52:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a1yqV-0001kR-Cx for qemu-devel@nongnu.org; Thu, 26 Nov 2015 10:52:32 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54266) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a1yqV-0001kN-2Q for qemu-devel@nongnu.org; Thu, 26 Nov 2015 10:52:31 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id B9BDD68E0C for ; Thu, 26 Nov 2015 15:52:30 +0000 (UTC) From: Paolo Bonzini Date: Thu, 26 Nov 2015 16:52:15 +0100 Message-Id: <1448553137-22191-8-git-send-email-pbonzini@redhat.com> In-Reply-To: <1448553137-22191-1-git-send-email-pbonzini@redhat.com> References: <1448553137-22191-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PULL 7/9] target-i386: kvm: Abort if MCE bank count is not supported by host List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Eduardo Habkost From: Eduardo Habkost Instead of silently changing the number of banks in mcg_cap based on kvm_get_mce_cap_supported(), abort initialization if the host doesn't support MCE_BANKS_DEF banks. Note that MCE_BANKS_DEF was always 10 since it was introduced in QEMU, and Linux always returned 32 at KVM_CAP_MCE since KVM_CAP_MCE was introduced, so no behavior is being changed and the error can't be triggered by any Linux version. The point of the new check is to ensure we won't silently change the bank count if we change MCE_BANKS_DEF or make the bank count configurable in the future. Signed-off-by: Eduardo Habkost [Avoid Yoda condition and \n at end of error_report. - Paolo] Signed-off-by: Paolo Bonzini Message-Id: <1448471956-66873-8-git-send-email-pbonzini@redhat.com> --- target-i386/kvm.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/target-i386/kvm.c b/target-i386/kvm.c index 2a9953b..93d1f5e 100644 --- a/target-i386/kvm.c +++ b/target-i386/kvm.c @@ -784,11 +784,14 @@ int kvm_arch_init_vcpu(CPUState *cs) return ret; } - if (banks > MCE_BANKS_DEF) { - banks = MCE_BANKS_DEF; + if (banks < MCE_BANKS_DEF) { + error_report("kvm: Unsupported MCE bank count (QEMU = %d, KVM = %d)", + MCE_BANKS_DEF, banks); + return -ENOTSUP; } + mcg_cap &= MCE_CAP_DEF; - mcg_cap |= banks; + mcg_cap |= MCE_BANKS_DEF; ret = kvm_vcpu_ioctl(cs, KVM_X86_SETUP_MCE, &mcg_cap); if (ret < 0) { fprintf(stderr, "KVM_X86_SETUP_MCE: %s", strerror(-ret)); -- 2.5.0