For consistency with install_page, make it accept a root page table pointer. Signed-off-by: Paolo Bonzini <pbonzini@xxxxxxxxxx> --- lib/x86/asm/page.h | 1 + lib/x86/vm.c | 4 ++-- lib/x86/vm.h | 1 - x86/asyncpf.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/x86/asm/page.h b/lib/x86/asm/page.h index 154d45e..1e6d1a2 100644 --- a/lib/x86/asm/page.h +++ b/lib/x86/asm/page.h @@ -47,6 +47,7 @@ #define PGDIR_OFFSET(va, lvl) (((va) >> PGDIR_BITS(lvl)) & PGDIR_MASK) extern void *setup_mmu(unsigned long top); +phys_addr_t virt_to_pte_phys(void *cr3, void *virt); #endif /* !__ASSEMBLY__ */ #endif diff --git a/lib/x86/vm.c b/lib/x86/vm.c index f6f20e5..9dd7d79 100644 --- a/lib/x86/vm.c +++ b/lib/x86/vm.c @@ -198,9 +198,9 @@ void *vmalloc(unsigned long size) return mem; } -uint64_t virt_to_phys_cr3(void *mem) +phys_addr_t virt_to_pte_phys(void *cr3, void *mem) { - return (*get_pte(phys_to_virt(read_cr3()), mem) & PT_ADDR_MASK) + ((ulong)mem & (PAGE_SIZE - 1)); + return (*get_pte(cr3, mem) & PT_ADDR_MASK) + ((ulong)mem & (PAGE_SIZE - 1)); } void vfree(void *mem) diff --git a/lib/x86/vm.h b/lib/x86/vm.h index c3211eb..9f668c6 100644 --- a/lib/x86/vm.h +++ b/lib/x86/vm.h @@ -10,7 +10,6 @@ void setup_5level_page_table(); void *vmalloc(unsigned long size); void vfree(void *mem); void *vmap(unsigned long long phys, unsigned long size); -uint64_t virt_to_phys_cr3(void *mem); struct pte_search { int level; diff --git a/x86/asyncpf.c b/x86/asyncpf.c index f04d7cb..3b5b4b7 100644 --- a/x86/asyncpf.c +++ b/x86/asyncpf.c @@ -55,7 +55,7 @@ static void pf_isr(struct ex_regs *r) report("unexpected #PF at %#lx", false, read_cr2()); break; case KVM_PV_REASON_PAGE_NOT_PRESENT: - phys = virt_to_phys_cr3(virt); + phys = virt_to_pte_phys(phys_to_virt(read_cr3()), virt); install_pte(phys_to_virt(read_cr3()), 1, virt, phys, 0); write_cr3(read_cr3()); report("Got not present #PF token %lx virt addr %p phys addr %#" PRIx64, -- 2.14.2