From patchwork Fri Mar 29 13:54:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiaoyao Li X-Patchwork-Id: 10877101 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 637BF1390 for ; Fri, 29 Mar 2019 13:55:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 51CC228EE3 for ; Fri, 29 Mar 2019 13:55:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 45DE429054; Fri, 29 Mar 2019 13:55:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D4CD328EE3 for ; Fri, 29 Mar 2019 13:55:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729703AbfC2Nyu (ORCPT ); Fri, 29 Mar 2019 09:54:50 -0400 Received: from mga03.intel.com ([134.134.136.65]:44836 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729666AbfC2Nyu (ORCPT ); Fri, 29 Mar 2019 09:54:50 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Mar 2019 06:54:49 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,284,1549958400"; d="scan'208";a="138342085" Received: from lxy-server.sh.intel.com ([10.239.48.11]) by orsmga003.jf.intel.com with ESMTP; 29 Mar 2019 06:54:47 -0700 From: Xiaoyao Li To: Paolo Bonzini , =?utf-8?b?UmFkaW0gS3LEjW3DocWZ?= , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Xiaoyao Li , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , x86@kernel.org, chao.gao@intel.com, Sean Christopherson Subject: [PATCH v4 0/2] Switch MSR_MISC_FEATURES_ENABLES and one optimization Date: Fri, 29 Mar 2019 21:54:20 +0800 Message-Id: <20190329135422.15046-1-xiaoyao.li@linux.intel.com> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Patch 1 switches MSR_MISC_FEATURES_ENABLE between host and guest during vcpu_{load,put} to avoid cpuid faulting and ring3mwait of host leaking to guest. Because cpuid faulting eanbled in host may potentially cause guest boot failure, and kvm doesn't expose ring3mwait to guest yet. Both two features shouldn't be leaked to guest. Patch 2 optimizes the switch of MSR_MISC_FEATURES_ENABLES by avoiding WRMSR whenever possible to save cycles. ==changelog== v3->v4: remove the helper function, and some code refine. per Sean Christopherson's comments. v2->v3: - use msr_misc_features_shadow instead of reading hardware msr, from Sean Christopherson - avoid WRMSR whenever possible, from Sean Christopherson. v1->v2: - move the save/restore of cpuid faulting bit to vmx_prepare_swich_to_guest/vmx_prepare_swich_to_host to avoid every vmentry RDMSR, based on Paolo's comment. Xiaoyao Li (2): kvm/vmx: Switch MSR_MISC_FEATURES_ENABLES between host and guest x86/vmx: optimize MSR_MISC_FEATURES_ENABLES switch arch/x86/include/asm/kvm_host.h | 2 ++ arch/x86/kernel/process.c | 1 + arch/x86/kvm/vmx/vmx.c | 17 +++++++++++++++++ arch/x86/kvm/x86.c | 11 ++++++++--- 4 files changed, 28 insertions(+), 3 deletions(-)