mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/chenhuacai/linux-loongson
synced 2025-08-28 09:22:08 +00:00

In nVHE protected mode, the EL2 code uses a temporary allocator during boot while re-creating its stage-1 page-table. Unfortunately, the hyp_vmmemap is not ready to use at this stage, so refcounting pages is not possible. That is not currently a problem because hyp stage-1 mappings are never removed, which implies refcounting of page-table pages is unnecessary. In preparation for allowing hypervisor stage-1 mappings to be removed, provide stub implementations for {get,put}_page() in the early allocator. Acked-by: Will Deacon <will@kernel.org> Signed-off-by: Quentin Perret <qperret@google.com> Signed-off-by: Marc Zyngier <maz@kernel.org> Link: https://lore.kernel.org/r/20211215161232.1480836-2-qperret@google.com
60 lines
1.3 KiB
C
60 lines
1.3 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
* Copyright (C) 2020 Google LLC
|
|
* Author: Quentin Perret <qperret@google.com>
|
|
*/
|
|
|
|
#include <asm/kvm_pgtable.h>
|
|
|
|
#include <nvhe/early_alloc.h>
|
|
#include <nvhe/memory.h>
|
|
|
|
struct kvm_pgtable_mm_ops hyp_early_alloc_mm_ops;
|
|
s64 __ro_after_init hyp_physvirt_offset;
|
|
|
|
static unsigned long base;
|
|
static unsigned long end;
|
|
static unsigned long cur;
|
|
|
|
unsigned long hyp_early_alloc_nr_used_pages(void)
|
|
{
|
|
return (cur - base) >> PAGE_SHIFT;
|
|
}
|
|
|
|
void *hyp_early_alloc_contig(unsigned int nr_pages)
|
|
{
|
|
unsigned long size = (nr_pages << PAGE_SHIFT);
|
|
void *ret = (void *)cur;
|
|
|
|
if (!nr_pages)
|
|
return NULL;
|
|
|
|
if (end - cur < size)
|
|
return NULL;
|
|
|
|
cur += size;
|
|
memset(ret, 0, size);
|
|
|
|
return ret;
|
|
}
|
|
|
|
void *hyp_early_alloc_page(void *arg)
|
|
{
|
|
return hyp_early_alloc_contig(1);
|
|
}
|
|
|
|
static void hyp_early_alloc_get_page(void *addr) { }
|
|
static void hyp_early_alloc_put_page(void *addr) { }
|
|
|
|
void hyp_early_alloc_init(void *virt, unsigned long size)
|
|
{
|
|
base = cur = (unsigned long)virt;
|
|
end = base + size;
|
|
|
|
hyp_early_alloc_mm_ops.zalloc_page = hyp_early_alloc_page;
|
|
hyp_early_alloc_mm_ops.phys_to_virt = hyp_phys_to_virt;
|
|
hyp_early_alloc_mm_ops.virt_to_phys = hyp_virt_to_phys;
|
|
hyp_early_alloc_mm_ops.get_page = hyp_early_alloc_get_page;
|
|
hyp_early_alloc_mm_ops.put_page = hyp_early_alloc_put_page;
|
|
}
|