[09/15] KVM: MTRR: introduce var_mtrr_range
diff mbox

Message ID 1432983566-15773-10-git-send-email-guangrong.xiao@linux.intel.com
State New
Headers show

Commit Message

Xiao Guangrong May 30, 2015, 10:59 a.m. UTC
It gets the range for the specified variable MTRR

Signed-off-by: Xiao Guangrong <guangrong.xiao@linux.intel.com>
---
 arch/x86/kvm/mtrr.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

Comments

David Matlack June 9, 2015, 12:36 a.m. UTC | #1
On Sat, May 30, 2015 at 3:59 AM, Xiao Guangrong
<guangrong.xiao@linux.intel.com> wrote:
> It gets the range for the specified variable MTRR
>
> Signed-off-by: Xiao Guangrong <guangrong.xiao@linux.intel.com>
> ---
>  arch/x86/kvm/mtrr.c | 19 +++++++++++++------
>  1 file changed, 13 insertions(+), 6 deletions(-)
>
> diff --git a/arch/x86/kvm/mtrr.c b/arch/x86/kvm/mtrr.c
> index 888441e..aeb9767 100644
> --- a/arch/x86/kvm/mtrr.c
> +++ b/arch/x86/kvm/mtrr.c
> @@ -217,10 +217,21 @@ static int fixed_msr_to_range_index(u32 msr)
>         return 0;
>  }
>
> +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;
> +       *end = ((*start & mask) | ~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 ||
> @@ -244,11 +255,7 @@ static void update_mtrr(struct kvm_vcpu *vcpu, u32 msr)
>         default:
>                 /* 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);

Why did you drop this in favor of boot_cpu_data.x86_phys_bits?

> -
> -               end = ((start & mask) | ~mask) + 1;
> +               var_mtrr_range(&mtrr_state->var_ranges[index], &start, &end);
>         }
>
>  do_zap:
> --
> 2.1.0
>
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Xiao Guangrong June 9, 2015, 2:38 a.m. UTC | #2
Thanks for your review, David!


On 06/09/2015 08:36 AM, David Matlack wrote:

>>   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 ||
>> @@ -244,11 +255,7 @@ static void update_mtrr(struct kvm_vcpu *vcpu, u32 msr)
>>          default:
>>                  /* 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);
>
> Why did you drop this in favor of boot_cpu_data.x86_phys_bits?
>

It can make the code more generic, @vcpu is not needed anymore.
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch
diff mbox

diff --git a/arch/x86/kvm/mtrr.c b/arch/x86/kvm/mtrr.c
index 888441e..aeb9767 100644
--- a/arch/x86/kvm/mtrr.c
+++ b/arch/x86/kvm/mtrr.c
@@ -217,10 +217,21 @@  static int fixed_msr_to_range_index(u32 msr)
 	return 0;
 }
 
+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;
+	*end = ((*start & mask) | ~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 ||
@@ -244,11 +255,7 @@  static void update_mtrr(struct kvm_vcpu *vcpu, u32 msr)
 	default:
 		/* 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);
 	}
 
 do_zap: