Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 156583
b: refs/heads/master
c: d6289b9
h: refs/heads/master
i:
  156581: 28636df
  156579: e36826c
  156575: 91a47f0
v: v3
  • Loading branch information
Marcelo Tosatti authored and Avi Kivity committed Aug 5, 2009
1 parent 85c4550 commit 6569765
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 0ff77873b1318fc2d77a85e70690d3cd6cafbd41
refs/heads/master: d6289b9365c3f622a8cfe62c4fb054bb70b5061a
39 changes: 38 additions & 1 deletion trunk/arch/x86/kvm/x86.c
Original file line number Diff line number Diff line change
Expand Up @@ -704,11 +704,48 @@ static bool msr_mtrr_valid(unsigned msr)
return false;
}

static bool valid_pat_type(unsigned t)
{
return t < 8 && (1 << t) & 0xf3; /* 0, 1, 4, 5, 6, 7 */
}

static bool valid_mtrr_type(unsigned t)
{
return t < 8 && (1 << t) & 0x73; /* 0, 1, 4, 5, 6 */
}

static bool mtrr_valid(struct kvm_vcpu *vcpu, u32 msr, u64 data)
{
int i;

if (!msr_mtrr_valid(msr))
return false;

if (msr == MSR_IA32_CR_PAT) {
for (i = 0; i < 8; i++)
if (!valid_pat_type((data >> (i * 8)) & 0xff))
return false;
return true;
} else if (msr == MSR_MTRRdefType) {
if (data & ~0xcff)
return false;
return valid_mtrr_type(data & 0xff);
} else if (msr >= MSR_MTRRfix64K_00000 && msr <= MSR_MTRRfix4K_F8000) {
for (i = 0; i < 8 ; i++)
if (!valid_mtrr_type((data >> (i * 8)) & 0xff))
return false;
return true;
}

/* variable MTRRs */
return valid_mtrr_type(data & 0xff);
}

static int set_msr_mtrr(struct kvm_vcpu *vcpu, u32 msr, u64 data)
{
u64 *p = (u64 *)&vcpu->arch.mtrr_state.fixed_ranges;

if (!msr_mtrr_valid(msr))
if (!mtrr_valid(vcpu, msr, data))
return 1;

if (msr == MSR_MTRRdefType) {
Expand Down

0 comments on commit 6569765

Please sign in to comment.