/*
* The head.S code sets up the kernel high mapping:
*
* from __START_KERNEL_map to __START_KERNEL_map + size (== _end-_text)
*
* phys_base holds the negative offset to the kernel, which is added
* to the compile time generated pmds. This results in invalid pmds up
* to the point where we hit the physaddr 0 mapping.
*
* We limit the mappings to the region from _text to _brk_end. _brk_end
* is rounded up to the 2MB boundary. This catches the invalid pmds as
* well, as they are located before _text:
*/
说的有点多,最后的结果比较简单,就是只留下了_text到_brk_end之间的页表映射。
那咱们来打印一下,看看效果呗。
调试补丁
diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
index 14b9dd7..2ffb7f2 100644
--- a/arch/x86/mm/init_64.c
+++ b/arch/x86/mm/init_64.c
@@ -310,6 +310,25 @@ void __init cleanup_highmap(void)
unsigned long vaddr_end = __START_KERNEL_map + KERNEL_IMAGE_SIZE;
unsigned long end = roundup((unsigned long)_brk_end, PMD_SIZE) - 1;
pmd_t *pmd = level2_kernel_pgt;
+ int i = 0;
+
+ pr_err(": phys_base %lx\n", phys_base );
+ pr_err(": #level2_kernel_pgt %lu\n", KERNEL_IMAGE_SIZE/PMD_SIZE);
+ pr_err(": __START_KERNEL_map %lx\n", __START_KERNEL_map);
+ pr_err(": __START_KERNEL %lx\n", __START_KERNEL);
+ pr_err(": _text %lx\n", (unsigned long)_text);
+ pr_err(": _brk_end %lx\n", (unsigned long)_brk_end);
+ pr_err(": _end %lx\n", (unsigned long)_end);
+ pr_err(": __START_KERNEL_map + KI %lx\n",
+ __START_KERNEL_map + KERNEL_IMAGE_SIZE);
+
+ for (i = 0; i < 512; i++) {
+ if (pmd_none(*(pmd + i)))
+ continue;
+
+ pr_err(": level2_kernel_pgt[%d] = %lx\n",
+ i, pmd_val(*(pmd+i)));
+ }
/*
* Native path, max_pfn_mapped is not set yet.
@@ -325,6 +344,17 @@ void __init cleanup_highmap(void)
if (vaddr < (unsigned long) _text || vaddr > end)
set_pmd(pmd, __pmd(0));
}
+
+ pr_err(": 2nd round\n");
+ pmd = level2_kernel_pgt;
+ for (i = 0; i < 512; i++) {
+ if (pmd_none(*(pmd + i)))
+ continue;
+
+ pr_err(": level2_kernel_pgt[%d] = %lx\n",
+ i, pmd_val(*(pmd+i)));
+ }
+
}
/*