kernel_optimize_test/drivers/kvm
Avi Kivity df513e2cdd KVM: x86 emulator: fix bit string operations operand size
On x86, bit operations operate on a string of bits that can reside in
multiple words.  For example, 'btsl %eax, (blah)' will touch the word
at blah+4 if %eax is between 32 and 63.

The x86 emulator compensates for that by advancing the operand address
by (bit offset / BITS_PER_LONG) and truncating the bit offset to the
range (0..BITS_PER_LONG-1).  This has a side effect of forcing the operand
size to 8 bytes on 64-bit hosts.

Now, a 32-bit guest goes and fork()s a process.  It write protects a stack
page at 0xbffff000 using the 'btr' instruction, at offset 0xffc in the page
table, with bit offset 1 (for the write permission bit).

The emulator now forces the operand size to 8 bytes as previously described,
and an innocent page table update turns into a cross-page-boundary write,
which is assumed by the mmu code not to be a page table, so it doesn't
actually clear the corresponding shadow page table entry.  The guest and
host permissions are out of sync and guest memory is corrupted soon
afterwards, leading to guest failure.

Fix by not using BITS_PER_LONG as the word size; instead use the actual
operand size, so we get a 32-bit write in that case.

Note we still have to teach the mmu to handle cross-page-boundary writes
to guest page table; but for now this allows Damn Small Linux 0.4 (2.4.20)
to boot.

Signed-off-by: Avi Kivity <avi@qumranet.com>
2007-05-03 10:52:28 +03:00
..
Kconfig [PATCH] KVM: Put KVM in a new Virtualization menu 2006-12-13 09:05:46 -08:00
kvm_main.c KVM: Handle writes to MCG_STATUS msr 2007-05-03 10:52:26 +03:00
kvm_svm.h KVM: Remove unused and write-only variables 2007-05-03 10:52:26 +03:00
kvm_vmx.h [PATCH] KVM: Replace __x86_64__ with CONFIG_X86_64 2006-12-13 09:05:46 -08:00
kvm.h KVM: SVM: Ensure timestamp counter monotonicity 2007-05-03 10:52:27 +03:00
Makefile [PATCH] kvm: userspace interface 2006-12-10 09:57:22 -08:00
mmu.c KVM: Use list_move() 2007-05-03 10:52:27 +03:00
paging_tmpl.h KVM: MMU: Fix hugepage pdes mapping same physical address with different access 2007-05-03 10:52:27 +03:00
segment_descriptor.h [PATCH] kvm: userspace interface 2006-12-10 09:57:22 -08:00
svm.c KVM: Remove unused function 2007-05-03 10:52:27 +03:00
svm.h KVM: SVM: forbid guest to execute monitor/mwait 2007-05-03 10:52:26 +03:00
vmx.c KVM: Remove debug message 2007-05-03 10:52:27 +03:00
vmx.h [PATCH] kvm: vmx: handle triple faults by returning EXIT_REASON_SHUTDOWN to userspace 2007-02-12 09:48:40 -08:00
x86_emulate.c KVM: x86 emulator: fix bit string operations operand size 2007-05-03 10:52:28 +03:00
x86_emulate.h [PATCH] KVM: Replace __x86_64__ with CONFIG_X86_64 2006-12-13 09:05:46 -08:00