From f9fa4782687346939b3ab65f7c6cbba9e6da5d56 Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Fri, 25 Jun 2021 18:30:26 +0800 Subject: [PATCH] pmap: Add some API routines to help NVMM manage guest memory Add the following three routines for NVMM to use. NVMM can use these routines to manipulate the cpumask for the pmap backing guest physical memory. * pmap_add_cpu() * pmap_del_cpu() * pmap_del_all_cpus() NOTE: The scheduler might somtimes overload multiple vCPUs on the same physical cpu, so operating is not quite as simple as calling add_cpu/del_cpu in the core vmrun routines. Credit to Matt Dillon --- sys/platform/pc64/x86_64/pmap.c | 30 ++++++++++++++++++++++++++++++ sys/vm/pmap.h | 4 ++++ 2 files changed, 34 insertions(+) diff --git a/sys/platform/pc64/x86_64/pmap.c b/sys/platform/pc64/x86_64/pmap.c index f5abc98dc1..0f42ef4e1a 100644 --- a/sys/platform/pc64/x86_64/pmap.c +++ b/sys/platform/pc64/x86_64/pmap.c @@ -6338,6 +6338,36 @@ pmap_setlwpvm(struct lwp *lp, struct vmspace *newvm) } } +/* + * Used to control the backing vmspace on the host for a guest VM. + * The cpumask is needed by the host pager to properly invalidate the + * host TLB when paging out the backing memory of a guest VM. + * + * NOTE: The scheduler might somtimes overload multiple vCPUs on the + * same physical cpu, so operating is not quite as simple as + * calling add_cpu/del_cpu in the core vmrun routines. + */ +void +pmap_add_cpu(struct vmspace *vm, int cpuid) +{ + ATOMIC_CPUMASK_ORBIT(vm->vm_pmap.pm_active, mycpu->gd_cpuid); + crit_enter(); + pmap_interlock_wait(vm); + crit_exit(); +} + +void +pmap_del_cpu(struct vmspace *vm, int cpuid) +{ + ATOMIC_CPUMASK_NANDBIT(vm->vm_pmap.pm_active, mycpu->gd_cpuid); +} + +void +pmap_del_all_cpus(struct vmspace *vm) +{ + CPUMASK_ASSZERO(vm->vm_pmap.pm_active); +} + /* * Called when switching to a locked pmap, used to interlock against pmaps * undergoing modifications to prevent us from activating the MMU for the diff --git a/sys/vm/pmap.h b/sys/vm/pmap.h index 888445e38d..ea9c2ab3c5 100644 --- a/sys/vm/pmap.h +++ b/sys/vm/pmap.h @@ -233,6 +233,10 @@ void pmap_setlwpvm (struct lwp *, struct vmspace *); vm_paddr_t pmap_kextract(vm_offset_t); void pmap_invalidate_range(pmap_t, vm_offset_t, vm_offset_t); +void pmap_add_cpu(struct vmspace *vm, int cpuid); +void pmap_del_cpu(struct vmspace *vm, int cpuid); +void pmap_del_all_cpus(struct vmspace *vm); + vm_offset_t pmap_addr_hint (vm_object_t obj, vm_offset_t addr, vm_size_t size); void *pmap_kenter_temporary (vm_paddr_t pa, long i); void pmap_init2 (void); -- 2.41.0