aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/kvm/x86.c
diff options
context:
space:
mode:
authorGleb Natapov <gleb@redhat.com>2010-01-21 08:28:46 -0500
committerMarcelo Tosatti <mtosatti@redhat.com>2010-03-01 10:36:03 -0500
commitab344828ebe729e52949d64046adaa196f6b9dbe (patch)
tree4dcd8ebdd8a2bb3afefb2028abd667970bf4d6ed /arch/x86/kvm/x86.c
parentf0f4b930900ffa8daddb5262522c3e5c67ee1835 (diff)
KVM: x86: fix checking of cr0 validity
Move to/from Control Registers chapter of Intel SDM says. "Reserved bits in CR0 remain clear after any load of those registers; attempts to set them have no impact". Control Register chapter says "Bits 63:32 of CR0 are reserved and must be written with zeros. Writing a nonzero value to any of the upper 32 bits results in a general-protection exception, #GP(0)." This patch tries to implement this twisted logic. Signed-off-by: Gleb Natapov <gleb@redhat.com> Reported-by: Lorenzo Martignoni <martignlo@gmail.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Diffstat (limited to 'arch/x86/kvm/x86.c')
-rw-r--r--arch/x86/kvm/x86.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index fd5101b57fa3..ce267d9f0305 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -430,12 +430,16 @@ void kvm_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0)
430{ 430{
431 cr0 |= X86_CR0_ET; 431 cr0 |= X86_CR0_ET;
432 432
433 if (cr0 & CR0_RESERVED_BITS) { 433#ifdef CONFIG_X86_64
434 if (cr0 & 0xffffffff00000000UL) {
434 printk(KERN_DEBUG "set_cr0: 0x%lx #GP, reserved bits 0x%lx\n", 435 printk(KERN_DEBUG "set_cr0: 0x%lx #GP, reserved bits 0x%lx\n",
435 cr0, kvm_read_cr0(vcpu)); 436 cr0, kvm_read_cr0(vcpu));
436 kvm_inject_gp(vcpu, 0); 437 kvm_inject_gp(vcpu, 0);
437 return; 438 return;
438 } 439 }
440#endif
441
442 cr0 &= ~CR0_RESERVED_BITS;
439 443
440 if ((cr0 & X86_CR0_NW) && !(cr0 & X86_CR0_CD)) { 444 if ((cr0 & X86_CR0_NW) && !(cr0 & X86_CR0_CD)) {
441 printk(KERN_DEBUG "set_cr0: #GP, CD == 0 && NW == 1\n"); 445 printk(KERN_DEBUG "set_cr0: #GP, CD == 0 && NW == 1\n");