nvmm: Port to DragonFly #18: kernel memory allocation
authorAaron LI <aly@aaronly.me>
Sat, 22 May 2021 04:03:06 +0000 (12:03 +0800)
committerAaron LI <aly@aaronly.me>
Tue, 15 Jun 2021 13:37:04 +0000 (21:37 +0800)
commit48177be4c1554ecd8d1eac257c6a792545874e9a
treef22fc8b182b42dccc81043cd9f88d7d26517f4b3
parent9c47983836784b4ea047b301f186e94fdb30b971
nvmm: Port to DragonFly #18: kernel memory allocation

Use kmem_alloc() and kmem_free() to implement uvm_km_alloc() and
uvm_km_free() as they're used in svm_vcpu_create() and vmx_vcpu_create().
However, our kmem_alloc() may return 0 (i.e., allocation failure), so
need an extra check in the caller functions.

Since we've defined 'kmem_alloc' and 'kmem_free' macros to adapt
NetBSD's functions to use our kmalloc() and kfree().  Therefore, extra
parentheses are added around 'kmem_alloc' and 'kmem_free' to avoid macro
expansion, so the original functions would be called.

In addition, change the 'kmem_free()' to 'uvm_km_free()' in
vmx_vcpu_create(), aligning with the invocation pattern as well as
the use case in svm_vcpu_create().
sys/dev/virtual/nvmm/nvmm_compat.h
sys/dev/virtual/nvmm/x86/nvmm_x86_svm.c
sys/dev/virtual/nvmm/x86/nvmm_x86_vmx.c
sys/vm/vm_map.h