From 681f8a610c1390c238f0bead17c974958833f830 Mon Sep 17 00:00:00 2001 From: Andrea Arcangeli <aarcange@redhat.com> Date: Tue, 9 Mar 2010 14:20:09 -0300 Subject: [PATCH] avoid collision between out of sync ksm and pci passthrough RH-Author: Andrea Arcangeli <aarcange@redhat.com> Message-id: <20100309142009.GA28578@random.random> Patchwork-id: 7612 O-Subject: avoid collision between out of sync ksm and pci passthrough Bugzilla: 566385 RH-Acked-by: Izik Eidus <ieidus@redhat.com> RH-Acked-by: Don Dutile <ddutile@redhat.com> RH-Acked-by: Marcelo Tosatti <mtosatti@redhat.com> RH-Acked-by: Chris Wright <chrisw@redhat.com> From: Andrea Arcangeli <aarcange@redhat.com> This fixes a collision between the patch to allow out of sync on ksm pages (that shall never become writable) and pci passthrough that maps invalid pfn in the sptes. Patch is a noop for everything except pci passthrough. Signed-off-by: Andrea Arcangeli <aarcange@redhat.com> --- Please ACK, this is for 5.5 (hopefully) or 5.6. Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> --- arch/x86/kvm/paging_tmpl.h | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-) diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h index e7226ba..c1f05c2 100644 --- a/arch/x86/kvm/paging_tmpl.h +++ b/arch/x86/kvm/paging_tmpl.h @@ -573,6 +573,7 @@ static int FNAME(sync_page)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp) offset = sp->role.quadrant << PT64_LEVEL_BITS; for (i = 0; i < PT64_ENT_PER_PAGE; i++) { + unsigned long pfn; unsigned pte_access; pt_element_t gpte; gpa_t pte_gpa; @@ -603,7 +604,8 @@ static int FNAME(sync_page)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp) nr_present++; pte_access = sp->role.access & FNAME(gpte_access)(vcpu, gpte); - if (!PageAnon(pfn_to_page(spte_to_pfn(sp->spt[i])))) + pfn = spte_to_pfn(sp->spt[i]); + if (pfn_valid(pfn) && !PageAnon(pfn_to_page(pfn))) pte_access &= ~PT_WRITABLE_MASK; set_spte(vcpu, &sp->spt[i], pte_access, 0, 0, is_dirty_pte(gpte), 0, gpte & PT_GLOBAL_MASK, gfn, -- 1.6.3.rc4.29.g8146