summaryrefslogtreecommitdiff
path: root/arch/x86
diff options
context:
space:
mode:
authorXiao Guangrong <guangrong.xiao@linux.intel.com>2015-06-15 11:55:30 +0300
committerPaolo Bonzini <pbonzini@redhat.com>2015-06-19 18:16:28 +0300
commita13842dc668b40daef4327294a6d3bdc8bd30276 (patch)
tree764539b97eaaab429055a8719acc4d5c34302333 /arch/x86
parentde9aef5e1ad6e504d6992df17dfa193e8ba5cc34 (diff)
downloadlinux-a13842dc668b40daef4327294a6d3bdc8bd30276.tar.xz
KVM: MTRR: introduce var_mtrr_range
It gets the range for the specified variable MTRR Signed-off-by: Xiao Guangrong <guangrong.xiao@linux.intel.com> [Simplify boolean operations. - Paolo] Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'arch/x86')
-rw-r--r--arch/x86/kvm/mtrr.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/arch/x86/kvm/mtrr.c b/arch/x86/kvm/mtrr.c
index cfeeaef9e419..b081e3ba186f 100644
--- a/arch/x86/kvm/mtrr.c
+++ b/arch/x86/kvm/mtrr.c
@@ -241,10 +241,25 @@ static int fixed_msr_to_range_index(u32 msr)
return fixed_mtrr_seg_unit_range_index(seg, unit);
}
+static void var_mtrr_range(struct kvm_mtrr_range *range, u64 *start, u64 *end)
+{
+ u64 mask;
+
+ *start = range->base & PAGE_MASK;
+
+ mask = range->mask & PAGE_MASK;
+ mask |= ~0ULL << boot_cpu_data.x86_phys_bits;
+
+ /* This cannot overflow because writing to the reserved bits of
+ * variable MTRRs causes a #GP.
+ */
+ *end = (*start | ~mask) + 1;
+}
+
static void update_mtrr(struct kvm_vcpu *vcpu, u32 msr)
{
struct kvm_mtrr *mtrr_state = &vcpu->arch.mtrr_state;
- gfn_t start, end, mask;
+ gfn_t start, end;
int index;
if (msr == MSR_IA32_CR_PAT || !tdp_enabled ||
@@ -264,11 +279,7 @@ static void update_mtrr(struct kvm_vcpu *vcpu, u32 msr)
} else {
/* variable range MTRRs. */
index = (msr - 0x200) / 2;
- start = mtrr_state->var_ranges[index].base & PAGE_MASK;
- mask = mtrr_state->var_ranges[index].mask & PAGE_MASK;
- mask |= ~0ULL << cpuid_maxphyaddr(vcpu);
-
- end = ((start & mask) | ~mask) + 1;
+ var_mtrr_range(&mtrr_state->var_ranges[index], &start, &end);
}
kvm_zap_gfn_range(vcpu->kvm, gpa_to_gfn(start), gpa_to_gfn(end));