The same problem I asked before. I want to modify kernel image's page table from 2M to 4K.
<div><br></div><div>In arch/x86/kernel/head_64.S, I add another level page table, make pmd point to the new page table. However, after compile and boot it, the kernel cannot work and always reboot.</div><div><br></div><div>
I try many kind of port, it still cannot work normally.</div><div><br></div><div><br></div><div>Here is the context of my modified code :</div><div>-----------------------------------------------------</div><div><div><div>
<div>/* Automate the creation of 1 to 1 mapping pmd entries */</div><div><font class="Apple-style-span" color="#FF0000">#define PMDS(START, PERM, COUNT) \</font></div><div><font class="Apple-style-span" color="#FF0000"> i = 0 ; \</font></div>
<div><font class="Apple-style-span" color="#FF0000"> .rept (COUNT) ; \</font></div><div><font class="Apple-style-span" color="#FF0000"> .quad (START) + (i << PMD_SHIFT) + (PERM) ; \</font></div>
<div><font class="Apple-style-span" color="#FF0000"> i = i + 1 ; \</font></div><div><font class="Apple-style-span" color="#FF0000"> .endr</font></div><div><font class="Apple-style-span" color="#FF0000"><br>
</font></div><div><font class="Apple-style-span" color="#FF0000">#define PTDS(START, PERM, COUNT) \</font></div><div><font class="Apple-style-span" color="#FF0000"> i = 0 ; \</font></div>
<div><font class="Apple-style-span" color="#FF0000"> .rept (COUNT) ; \</font></div><div><font class="Apple-style-span" color="#FF0000"> .quad (START) + (i << PAGE_SHIFT) + (PERM) ; \</font></div>
<div><font class="Apple-style-span" color="#FF0000"> i = i + 1 ; \</font></div><div><font class="Apple-style-span" color="#FF0000"> .endr</font></div></div><div><br></div><div> .data</div><div> /* </div>
<div> * This default setting generates an ident mapping at address 0x100000</div><div> * and a mapping for the kernel that precisely maps virtual address</div><div> * 0xffffffff80000000 to physical address 0x000000. (always using</div>
<div> * 2Mbyte large pages provided by PAE mode)</div><div> */</div><div>NEXT_PAGE(init_level4_pgt)</div><div> .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE</div><div> .org init_level4_pgt + L4_PAGE_OFFSET*8, 0</div>
<div> .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE</div><div> .org init_level4_pgt + L4_START_KERNEL*8, 0</div><div> /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */</div><div> .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE</div>
<div><br></div><div>NEXT_PAGE(level3_ident_pgt)</div><div> .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE</div><div> .fill 511,8,0</div><div><br></div><div>NEXT_PAGE(level3_kernel_pgt)</div><div> .fill L3_START_KERNEL,8,0</div>
<div> /* (2^48-(2*1024*1024*1024)-((2^39)*511))/(2^30) = 510 */</div><div> .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE</div><div> .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE</div>
<div><br></div><div>NEXT_PAGE(level2_fixmap_pgt)</div><div> .fill 506,8,0</div><div> .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE</div><div> /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */</div>
<div> .fill 5,8,0</div><div><br></div><div>NEXT_PAGE(level1_fixmap_pgt)</div><div> .fill 512,8,0</div><div><br></div><div>NEXT_PAGE(level2_ident_pgt)</div><div> /* Since I easily can, map the first 1G.</div><div>
* Don't set NX because code runs from these pages.</div><div> */</div><div> PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)</div><div><br></div><div>NEXT_PAGE(level2_kernel_pgt)</div><div> /* </div>
<div> * 512 MB kernel mapping. We spend a full page on this pagetable</div><div> * anyway.</div></div></div><div><div> *</div><div> * The kernel code+data+bss must not be bigger than that.</div><div> *</div>
<div> * (NOTE: at +512MB starts the module area, see MODULES_VADDR.</div><div> * If you want to increase this then increase MODULES_VADDR</div><div> * too.)</div><div> */</div><div><font class="Apple-style-span" color="#FF0000">/* PMDS(0, __PAGE_KERNEL_LARGE_EXEC,</font></div>
<div><font class="Apple-style-span" color="#FF0000"> KERNEL_IMAGE_SIZE/PMD_SIZE)*/</font></div><div><font class="Apple-style-span" color="#FF0000">#define NEW_PMD_PORT (0x0 | _PAGE_PRESENT | _PAGE_RW | _PAGE_ACCESSED)</font></div>
<div><font class="Apple-style-span" color="#FF0000"> PMDS(level1_kernel_pgt - __START_KERNEL_map, NEW_PMD_PORT, PTRS_PER_PMD)</font></div><div><font class="Apple-style-span" color="#FF0000"><br></font></div><div><font class="Apple-style-span" color="#FF0000">NEXT_PAGE(level1_kernel_pgt)</font></div>
<div><font class="Apple-style-span" color="#FF0000">#define NEW_PTD_PORT (0x0 | _PAGE_PRESENT | _PAGE_RW | |_PAGE_USER | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)</font></div><div><font class="Apple-style-span" color="#FF0000"> PTDS(0, NEW_PTD_PORT, KERNEL_IMAGE_SIZE/PAGE_SIZE)</font></div>
<div><br></div><div>NEXT_PAGE(level2_spare_pgt)</div><div> .fill 512, 8, 0</div></div><div>----------------------------------------------------------------------------------------------</div>