[58/80] KVM: MMU: fix mmu notifier invalidate handler for huge spte

Greg KH
2010-09-24T16:33:16Z

From: Andrea Arcangeli <aarcange@redhat.com>

commit 6e3e243c3b6e0bbd18c6ce0fbc12bc3fe2d77b34 upstream.

The index wasn't calculated correctly (off by one) for huge spte so KVM guest
was unstable with transparent hugepages.

Signed-off-by: Andrea Arcangeli <aarcange@redhat.com>
Reviewed-by: Reviewed-by: Rik van Riel <riel@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
arch/x86/kvm/mmu.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -799,8 +799,12 @@ static int kvm_handle_hva(struct kvm *kv
ret = handler(kvm, &memslot->rmap[gfn_offset], data);

for (j = 0; j < KVM_NR_PAGE_SIZES - 1; ++j) {
- int idx = gfn_offset;
- idx /= KVM_PAGES_PER_HPAGE(PT_DIRECTORY_LEVEL + j);
+ unsigned long idx;
+ int nr;
+
+ nr = KVM_PAGES_PER_HPAGE(PT_DIRECTORY_LEVEL+j);
+ idx = (memslot->base_gfn+gfn_offset) / nr -
+ memslot->base_gfn / nr;
ret |= handler(kvm,
&memslot->lpage_info[j][idx].rmap_pde,
data);