Skip to content

Commit 154fb14

Browse files
trueptolemyliuw
authored andcommitted
x86/hyperv: Replace kmap() with kmap_local_page()
kmap() is being deprecated in favor of kmap_local_page()[1]. There are two main problems with kmap(): (1) It comes with an overhead as mapping space is restricted and protected by a global lock for synchronization and (2) it also requires global TLB invalidation when the kmap's pool wraps and it might block when the mapping space is fully utilized until a slot becomes available. With kmap_local_page() the mappings are per thread, CPU local, can take page faults, and can be called from any context (including interrupts). It is faster than kmap() in kernels with HIGHMEM enabled. Furthermore, the tasks can be preempted and, when they are scheduled to run again, the kernel virtual addresses are restored and are still valid. In the fuction hyperv_init() of hyperv/hv_init.c, the mapping is used in a single thread and is short live. So, in this case, it's safe to simply use kmap_local_page() to create mapping, and this avoids the wasted cost of kmap() for global synchronization. In addtion, the fuction hyperv_init() checks if kmap() fails by BUG_ON(). From the original discussion[2], the BUG_ON() here is just used to explicitly panic NULL pointer. So still keep the BUG_ON() in place to check if kmap_local_page() fails. Based on this consideration, memcpy_to_page() is not selected here but only kmap_local_page() is used. Therefore, replace kmap() with kmap_local_page() in hyperv/hv_init.c. [1]: https://lore.kernel.org/all/[email protected] [2]: https://lore.kernel.org/lkml/20200915103710.cqmdvzh5lys4wsqo@liuwe-devbox-debian-v2/ Suggested-by: Dave Hansen <[email protected]> Suggested-by: Ira Weiny <[email protected]> Suggested-by: Fabio M. De Francesco <[email protected]> Signed-off-by: Zhao Liu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Wei Liu <[email protected]>
1 parent 4c3386f commit 154fb14

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

arch/x86/hyperv/hv_init.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,13 +459,13 @@ void __init hyperv_init(void)
459459
wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
460460

461461
pg = vmalloc_to_page(hv_hypercall_pg);
462-
dst = kmap(pg);
462+
dst = kmap_local_page(pg);
463463
src = memremap(hypercall_msr.guest_physical_address << PAGE_SHIFT, PAGE_SIZE,
464464
MEMREMAP_WB);
465465
BUG_ON(!(src && dst));
466466
memcpy(dst, src, HV_HYP_PAGE_SIZE);
467467
memunmap(src);
468-
kunmap(pg);
468+
kunmap_local(dst);
469469
} else {
470470
hypercall_msr.guest_physical_address = vmalloc_to_pfn(hv_hypercall_pg);
471471
wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);

0 commit comments

Comments
 (0)