For consistency with install_page, make it accept a root page table pointer. Signed-off-by: Paolo Bonzini <pbonzini@xxxxxxxxxx> --- lib/vmalloc.h | 1 + lib/x86/vm.c | 4 ++-- lib/x86/vm.h | 1 - x86/asyncpf.c | 3 ++- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/vmalloc.h b/lib/vmalloc.h index 285a0fc..ec3fe36 100644 --- a/lib/vmalloc.h +++ b/lib/vmalloc.h @@ -7,5 +7,6 @@ extern void init_alloc_vpage(void *top); extern void setup_vm(); extern void *setup_mmu(phys_addr_t top); +extern phys_addr_t virt_to_pte_phys(pgd_t *pgtable, void *virt); #endif diff --git a/lib/x86/vm.c b/lib/x86/vm.c index 0fcc94c..223f14a 100644 --- a/lib/x86/vm.c +++ b/lib/x86/vm.c @@ -192,9 +192,9 @@ void *vmalloc(unsigned long size) return mem; } -uint64_t virt_to_phys_cr3(void *mem) +phys_addr_t virt_to_pte_phys(pgd_t *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 ac0529a..1d8b805 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..ee8baf9 100644 --- a/x86/asyncpf.c +++ b/x86/asyncpf.c @@ -23,6 +23,7 @@ #include "x86/vm.h" #include "libcflat.h" +#include "vmalloc.h" #include <stdint.h> #define KVM_PV_REASON_PAGE_NOT_PRESENT 1 @@ -55,7 +56,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