From patchwork Sat May 30 10:59:16 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Guangrong X-Patchwork-Id: 6512661 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 B94D9C0020 for ; Sat, 30 May 2015 11:00:06 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D768320851 for ; Sat, 30 May 2015 11:00:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7CBF920850 for ; Sat, 30 May 2015 11:00:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757789AbbE3K7r (ORCPT ); Sat, 30 May 2015 06:59:47 -0400 Received: from mga11.intel.com ([192.55.52.93]:44040 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757768AbbE3K7o (ORCPT ); Sat, 30 May 2015 06:59:44 -0400 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga102.fm.intel.com with ESMTP; 30 May 2015 03:59:40 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.13,522,1427785200"; d="scan'208";a="717943232" Received: from slu40-mobl2.ccr.corp.intel.com (HELO homedesktop.ccr.corp.intel.com) ([10.254.212.183]) by fmsmga001.fm.intel.com with ESMTP; 30 May 2015 03:59:38 -0700 From: Xiao Guangrong To: pbonzini@redhat.com Cc: gleb@kernel.org, mtosatti@redhat.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Xiao Guangrong Subject: [PATCH 05/15] KVM: MTRR: clean up mtrr default type Date: Sat, 30 May 2015 18:59:16 +0800 Message-Id: <1432983566-15773-6-git-send-email-guangrong.xiao@linux.intel.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1432983566-15773-1-git-send-email-guangrong.xiao@linux.intel.com> References: <1432983566-15773-1-git-send-email-guangrong.xiao@linux.intel.com> 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 Use union definition to avoid the decode/code workload and drop all the hard code Signed-off-by: Xiao Guangrong --- arch/x86/include/asm/kvm_host.h | 12 ++++++++++-- arch/x86/kvm/mtrr.c | 19 ++++++++----------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 2c3c52d..95ce2ff 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -347,8 +347,16 @@ enum { struct kvm_mtrr { struct mtrr_var_range var_ranges[KVM_NR_VAR_MTRR]; mtrr_type fixed_ranges[KVM_NR_FIXED_MTRR_REGION]; - unsigned char enabled; - mtrr_type def_type; + + union { + u64 deftype; + struct { + unsigned def_type:8; + unsigned reserved:2; + unsigned fixed_mtrr_enabled:1; + unsigned mtrr_enabled:1; + }; + }; }; struct kvm_vcpu_arch { diff --git a/arch/x86/kvm/mtrr.c b/arch/x86/kvm/mtrr.c index 562341b..6de49dd 100644 --- a/arch/x86/kvm/mtrr.c +++ b/arch/x86/kvm/mtrr.c @@ -105,7 +105,6 @@ EXPORT_SYMBOL_GPL(kvm_mtrr_valid); static void update_mtrr(struct kvm_vcpu *vcpu, u32 msr) { struct kvm_mtrr *mtrr_state = &vcpu->arch.mtrr_state; - unsigned char mtrr_enabled = mtrr_state->enabled; gfn_t start, end, mask; int index; bool is_fixed = true; @@ -114,7 +113,7 @@ static void update_mtrr(struct kvm_vcpu *vcpu, u32 msr) !kvm_arch_has_noncoherent_dma(vcpu->kvm)) return; - if (!(mtrr_enabled & 0x2) && msr != MSR_MTRRdefType) + if (!mtrr_state->mtrr_enabled && msr != MSR_MTRRdefType) return; switch (msr) { @@ -153,7 +152,7 @@ static void update_mtrr(struct kvm_vcpu *vcpu, u32 msr) end = ((start & mask) | ~mask) + 1; } - if (is_fixed && !(mtrr_enabled & 0x1)) + if (is_fixed && !mtrr_state->fixed_mtrr_enabled) return; kvm_zap_gfn_range(vcpu->kvm, gpa_to_gfn(start), gpa_to_gfn(end)); @@ -166,10 +165,9 @@ int kvm_mtrr_set_msr(struct kvm_vcpu *vcpu, u32 msr, u64 data) if (!kvm_mtrr_valid(vcpu, msr, data)) return 1; - if (msr == MSR_MTRRdefType) { - vcpu->arch.mtrr_state.def_type = data; - vcpu->arch.mtrr_state.enabled = (data & 0xc00) >> 10; - } else if (msr == MSR_MTRRfix64K_00000) + if (msr == MSR_MTRRdefType) + vcpu->arch.mtrr_state.deftype = data; + else if (msr == MSR_MTRRfix64K_00000) p[0] = data; else if (msr == MSR_MTRRfix16K_80000 || msr == MSR_MTRRfix16K_A0000) p[1 + msr - MSR_MTRRfix16K_80000] = data; @@ -216,8 +214,7 @@ int kvm_mtrr_get_msr(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata) return 1; if (msr == MSR_MTRRdefType) - *pdata = vcpu->arch.mtrr_state.def_type + - (vcpu->arch.mtrr_state.enabled << 10); + *pdata = vcpu->arch.mtrr_state.deftype; else if (msr == MSR_MTRRfix64K_00000) *pdata = p[0]; else if (msr == MSR_MTRRfix16K_80000 || msr == MSR_MTRRfix16K_A0000) @@ -256,14 +253,14 @@ static int get_mtrr_type(struct kvm_mtrr *mtrr_state, int i, num_var_ranges = KVM_NR_VAR_MTRR; /* MTRR is completely disabled, use UC for all of physical memory. */ - if (!(mtrr_state->enabled & 0x2)) + if (!mtrr_state->mtrr_enabled) return MTRR_TYPE_UNCACHABLE; /* Make end inclusive end, instead of exclusive */ end--; /* Look in fixed ranges. Just return the type as per start */ - if ((mtrr_state->enabled & 0x1) && (start < 0x100000)) { + if (mtrr_state->fixed_mtrr_enabled && (start < 0x100000)) { int idx; if (start < 0x80000) {