The buddy page allocator need setting up based on virtual memory mapping (vmemmap), it is based on MMU page table. Meanwhile MMU page table setup for virtual memory mapping needs page allocator as well. Before pKVM setup buddy page allocator, uses a early page allocator based mm_ops for MMU page table. This patch adds such mm_ops based on early page allocator, and it will be used later for MMU page table early setup. Signed-off-by: Shaoqin Huang <shaoqin.huang@xxxxxxxxx> Signed-off-by: Jason Chen CJ <jason.cj.chen@xxxxxxxxx> --- arch/x86/kvm/vmx/pkvm/hyp/early_alloc.c | 26 +++++++++++++++++++++++++ arch/x86/kvm/vmx/pkvm/hyp/early_alloc.h | 3 +++ 2 files changed, 29 insertions(+) diff --git a/arch/x86/kvm/vmx/pkvm/hyp/early_alloc.c b/arch/x86/kvm/vmx/pkvm/hyp/early_alloc.c index aac5cf243874..6c2bf46f23c9 100644 --- a/arch/x86/kvm/vmx/pkvm/hyp/early_alloc.c +++ b/arch/x86/kvm/vmx/pkvm/hyp/early_alloc.c @@ -7,12 +7,21 @@ #include <asm/pkvm_spinlock.h> #include <pkvm.h> +#include "pgtable.h" + static unsigned long base; static unsigned long end; static unsigned long cur; static pkvm_spinlock_t early_lock = __PKVM_SPINLOCK_UNLOCKED; +struct pkvm_mm_ops pkvm_early_alloc_mm_ops; + +unsigned long pkvm_early_alloc_nr_used_pages(void) +{ + return (cur - base) >> PAGE_SHIFT; +} + void *pkvm_early_alloc_contig(unsigned int nr_pages) { unsigned long size = (nr_pages << PAGE_SHIFT); @@ -40,8 +49,25 @@ void *pkvm_early_alloc_page(void) return pkvm_early_alloc_contig(1); } +static void pkvm_early_alloc_get_page(void *addr) { } +static void pkvm_early_alloc_put_page(void *addr) { } +static void pkvm_early_flush_tlb(void) { } + +static int pkvm_early_page_count(void *vaddr) +{ + return 512; +} + void pkvm_early_alloc_init(void *virt, unsigned long size) { base = cur = (unsigned long)virt; end = base + size; + + pkvm_early_alloc_mm_ops.zalloc_page = pkvm_early_alloc_page; + pkvm_early_alloc_mm_ops.get_page = pkvm_early_alloc_get_page; + pkvm_early_alloc_mm_ops.put_page = pkvm_early_alloc_put_page; + pkvm_early_alloc_mm_ops.phys_to_virt = pkvm_phys_to_virt; + pkvm_early_alloc_mm_ops.virt_to_phys = pkvm_virt_to_phys; + pkvm_early_alloc_mm_ops.page_count = pkvm_early_page_count; + pkvm_early_alloc_mm_ops.flush_tlb = pkvm_early_flush_tlb; } diff --git a/arch/x86/kvm/vmx/pkvm/hyp/early_alloc.h b/arch/x86/kvm/vmx/pkvm/hyp/early_alloc.h index 96c041557d92..a1c2127442e0 100644 --- a/arch/x86/kvm/vmx/pkvm/hyp/early_alloc.h +++ b/arch/x86/kvm/vmx/pkvm/hyp/early_alloc.h @@ -5,8 +5,11 @@ #ifndef __PKVM_EARLY_ALLOC_H #define __PKVM_EARLY_ALLOC_H +unsigned long pkvm_early_alloc_nr_used_pages(void); void *pkvm_early_alloc_contig(unsigned int nr_pages); void *pkvm_early_alloc_page(void); void pkvm_early_alloc_init(void *virt, unsigned long size); +extern struct pkvm_mm_ops pkvm_early_alloc_mm_ops; + #endif -- 2.25.1