From patchwork Mon Dec 14 11:07:57 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haozhong Zhang X-Patchwork-Id: 7843491 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id C2BDCBEEE1 for ; Mon, 14 Dec 2015 11:08:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E4051203DF for ; Mon, 14 Dec 2015 11:08:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 09B0D2022D for ; Mon, 14 Dec 2015 11:08:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932240AbbLNLIa (ORCPT ); Mon, 14 Dec 2015 06:08:30 -0500 Received: from mga14.intel.com ([192.55.52.115]:19188 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932153AbbLNLI3 (ORCPT ); Mon, 14 Dec 2015 06:08:29 -0500 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga103.fm.intel.com with ESMTP; 14 Dec 2015 03:08:20 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,426,1444719600"; d="scan'208";a="873150523" Received: from hz-desktop.sh.intel.com (HELO localhost) ([10.239.13.35]) by fmsmga002.fm.intel.com with ESMTP; 14 Dec 2015 03:08:18 -0800 From: Haozhong Zhang To: kvm@vger.kernel.org Cc: Paolo Bonzini , Marcelo Tosatti , Richard Henderson , Eduardo Habkost , Haozhong Zhang Subject: [PATCH] target-i386: check vcpu features before accessing MSR_TSC_AUX Date: Mon, 14 Dec 2015 19:07:57 +0800 Message-Id: <1450091277-26200-1-git-send-email-haozhong.zhang@intel.com> X-Mailer: git-send-email 2.4.8 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch fix a bug that prevents VM rebooting on recent versions of KVM (from commit 9dbe6cf). kvm_get_msrs() is called to save guest MSR_TSC_AUX and other MSRs across rebooting. It only checks whether KVM exposes MSR_TSC_AUX to userspace. However, if vcpu does not support rdtscp (e.g. kvm64), current KVM will fail the saving and thus all other MSRs following it will fail in kvm_get_msrs(). As a result, from KVM commit 9dbe6cf that exposes MSR_TSC_AUX, VM can not successfully reboot. This patch fixes this bug by adding the missing rdtscp feature checks. Signed-off-by: Haozhong Zhang --- target-i386/kvm.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/target-i386/kvm.c b/target-i386/kvm.c index 6dc9846..cc842c6 100644 --- a/target-i386/kvm.c +++ b/target-i386/kvm.c @@ -1414,7 +1414,8 @@ static int kvm_put_msrs(X86CPU *cpu, int level) if (has_msr_hsave_pa) { kvm_msr_entry_set(&msrs[n++], MSR_VM_HSAVE_PA, env->vm_hsave); } - if (has_msr_tsc_aux) { + if (has_msr_tsc_aux && + (env->features[FEAT_8000_0001_EDX] & CPUID_EXT2_RDTSCP)) { kvm_msr_entry_set(&msrs[n++], MSR_TSC_AUX, env->tsc_aux); } if (has_msr_tsc_adjust) { @@ -1793,7 +1794,8 @@ static int kvm_get_msrs(X86CPU *cpu) if (has_msr_hsave_pa) { msrs[n++].index = MSR_VM_HSAVE_PA; } - if (has_msr_tsc_aux) { + if (has_msr_tsc_aux && + (env->features[FEAT_8000_0001_EDX] & CPUID_EXT2_RDTSCP)) { msrs[n++].index = MSR_TSC_AUX; } if (has_msr_tsc_adjust) {