From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marcelo Tosatti Subject: KVM: MMU: update sp->gfns on pte update path Date: Tue, 25 Jan 2011 11:07:33 -0200 Message-ID: <20110125130733.GA5645@amt.cnet> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: Avi Kivity , Nicolas Prochazka To: kvm Return-path: Received: from mx1.redhat.com ([209.132.183.28]:51840 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753568Ab1AYN7K (ORCPT ); Tue, 25 Jan 2011 08:59:10 -0500 Content-Disposition: inline Sender: kvm-owner@vger.kernel.org List-ID: If an emulated pte write modifies the gpa of a present spte, sp->gfns is not updated, retaining a stale value which later leads to: rmap_remove: ffff8807d245fff8 0->BUG ------------[ cut here ]------------ kernel BUG at arch/x86/kvm/mmu.c:695! Fix by updating sp->gfns even if spte was present. Resolves: https://bugzilla.kernel.org/show_bug.cgi?id=27052 Reported-and-tested-by: Nicolas Prochazka KVM-Stable-Tag. diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c index cc1bada..37d0886 100644 --- a/arch/x86/kvm/mmu.c +++ b/arch/x86/kvm/mmu.c @@ -2054,6 +2054,12 @@ static void mmu_set_spte(struct kvm_vcpu *vcpu, u64 *sptep, rmap_count = rmap_add(vcpu, sptep, gfn); if (rmap_count > RMAP_RECYCLE_THRESHOLD) rmap_recycle(vcpu, sptep, gfn); + } else { + struct kvm_mmu_page *sp = page_header(__pa(sptep)); + int index = sptep - sp->spt; + + if (!sp->role.direct && sp->gfns[index] != gfn) + sp->gfns[index] = gfn; } kvm_release_pfn_clean(pfn); if (speculative) {