x86/head/64: level2_kernel_pgt's kernel area is built with _PAGE_PRESENT set
PATCH 1/1 x86/head/64: level2_kernel_pgt's kernel area is built with _PAGE_PRESENT set
The code is first introduced in 'commit 1ab60e0f72f7 ("[PATCH] x86-64:
Relocatable Kernel Support")'. Then 'commit c88d71508e36b ("x86/boot/64: Rewrite startup_64() in C")', convert it to c. And 'commit 2aa85f246c181 ("x86/boot/64: Make level2_kernel_pgt pages invalid outside kernel area")' limit the range from _text to _end.
Originally, it does the check because the loop iterate the whole level2_kernel_pgt, while currently it just fixup the kernel area. This area is built with _PAGE_PRESENT set.
--- arch/x86/kernel/head64.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
arch/x86/kernel/head64.c +1 -2
@@ -253,8 +253,7 @@ unsigned long __head __startup_64(unsigned long physaddr,/* fixup pages that are part of the kernel image */ for (; i <=pmd_index ((unsigned long )_end); i++) -if (pmd[i] & _PAGE_PRESENT) - pmd[i] += load_delta; + pmd[i] += load_delta;/* invalidate pages after the kernel image */ for (; i <PTRS_PER_PMD ; i++)
Signature · 1 line
2.34.1
Quoted 9 lines · Wei Yang
The code is first introduced in 'commit
1ab60e0f72f7("[PATCH] x86-64:
Relocatable Kernel Support")'. Then 'commitc88d71508e36b("x86/boot/64: Rewritestartup_64()in C")', convert it to c. And 'commit2aa85f246c181("x86/boot/64: Makelevel2_kernel_pgtpages invalid outside kernel area")' limit the range from_textto_end.Originally, it does the check because the loop iterate the whole
level2_kernel_pgt, while currently it just fixup the kernel area. This area is built with_PAGE_PRESENTset.
Ping
Quoted 27 lines
Signed-off-by Wei Yang <[email protected]>CC Vivek Goyal <[email protected]>CC Kirill A. Shutemov <[email protected]>CC Ingo Molnar <[email protected]>CC Steve Wahl <[email protected]>CC Borislav Petkov <[email protected]>---
arch/x86/kernel/head64.c| 3 +--1 file changed, 1 insertion(+), 2 deletions(-)arch/x86/kernel/head64.c +1
-2@@ -253,8 +253,7 @@ unsigned long __head __startup_64(unsigned long physaddr,/* fixup pages that are part of the kernel image */ for (; i <=pmd_index ((unsigned long )_end); i++) -if (pmd[i] & _PAGE_PRESENT) - pmd[i] += load_delta; + pmd[i] += load_delta;/* invalidate pages after the kernel image */ for (; i <PTRS_PER_PMD ; i++)Signature · 1 line
2.34.1
Signature · 2 lines
Wei Yang Help you, Help me
Quoted 9 lines · Wei Yang
The code is first introduced in 'commit
1ab60e0f72f7("[PATCH] x86-64:
Relocatable Kernel Support")'. Then 'commitc88d71508e36b("x86/boot/64: Rewritestartup_64()in C")', convert it to c. And 'commit2aa85f246c181("x86/boot/64: Makelevel2_kernel_pgtpages invalid outside kernel area")' limit the range from_textto_end.Originally, it does the check because the loop iterate the whole
level2_kernel_pgt, while currently it just fixup the kernel area. This area is built with_PAGE_PRESENTset.
What's the actual problem you are trying to solve?
arch/x86/kernel/head64.c unsigned long __head __startup_64(unsigned long physaddr, · line 256
Quoted 5 lines
arch/x86/kernel/head64.c +1
-2/* fixup pages that are part of the kernel image */ for (; i <=pmd_index ((unsigned long )_end); i++) -if (pmd[i] & _PAGE_PRESENT) - pmd[i] += load_delta; + pmd[i] += load_delta;
Fixing up non-present PMDs is a pointless exercise.
Thanks,
tglx
Quoted 7 lines · Thomas Gleixner
Quoted 6 lines · Wei Yang
The code is first introduced in 'commit
1ab60e0f72f7("[PATCH] x86-64:
Relocatable Kernel Support")'. Then 'commitc88d71508e36b("x86/boot/64: Rewritestartup_64()in C")', convert it to c. And 'commit2aa85f246c181("x86/boot/64: Makelevel2_kernel_pgtpages invalid outside kernel area")' limit the range from_textto_end.
Quoted 5 lines
Quoted 3 lines
Originally, it does the check because the loop iterate the whole
level2_kernel_pgt, while currently it just fixup the kernel area. This area is built with_PAGE_PRESENTset.What's the actual problem you are trying to solve?
Not a problem. It tries to remove some duplicate check.
Quoted 9 lines
arch/x86/kernel/head64.c unsigned long __head __startup_64(unsigned long physaddr, · line 256
Quoted 6 lines
arch/x86/kernel/head64.c +1
-2/* fixup pages that are part of the kernel image */ for (; i <=pmd_index ((unsigned long )_end); i++) -if (pmd[i] & _PAGE_PRESENT) - pmd[i] += load_delta; + pmd[i] += load_delta;Fixing up non-present PMDs is a pointless exercise.
Agree. While we are sure then range here must present.
The whole process looks like this
pmd in [0, _text)
unset _PAGE_PRESENT
pmd in [_text, _end]
fix up delta
pmd in (_end, 256)
unset _PAGE_PRESENT
Since we have compiled in _PAGE_PRESENT in this page table, it is not necessary to check _PAGE_PRESENT again before fixing up delta.
BTW, if one entry between _text and _end is not present, we will failed to fixing the kernel code pmd entry, which will lead to some problem.
Quoted 3 lines
Thanks,
tglx
Signature · 2 lines
Wei Yang Help you, Help me
Quoted 5 lines · Wei Yang
Quoted 2 lines · Thomas Gleixner
What's the actual problem you are trying to solve?
Not a problem. It tries to remove some duplicate check.
I assume you mean redundant check, right?
The changelog should explain that. I really could not figure out what this is about.
Quoted 20 lines
Quoted 8 lines
arch/x86/kernel/head64.c unsigned long __head __startup_64(unsigned long physaddr, · line 256
Quoted 5 lines
arch/x86/kernel/head64.c +1
-2/* fixup pages that are part of the kernel image */ for (; i <=pmd_index ((unsigned long )_end); i++) -if (pmd[i] & _PAGE_PRESENT) - pmd[i] += load_delta; + pmd[i] += load_delta;Fixing up non-present PMDs is a pointless exercise.
Agree. While we are sure then range here must present.
The whole process looks like this
pmd in [0,
_text)
unset_PAGE_PRESENT
pmd in [_text,_end]
fix up delta
pmd in (_end, 256)
unset_PAGE_PRESENT
Quoted 2 lines
Since we have compiled in
_PAGE_PRESENTin this page table, it is not necessary to check_PAGE_PRESENTagain before fixing up delta.
That wants to be in the change log.
Referencing the history of the code is definitely interesting and you did a great job on decoding it, but for the change itself the only relevant information is that all PMDs between _text and _end are marked present because the whole table is marked so.
Quoted 2 lines
BTW, if one entry between
_textand_endis not present, we will failed to fixing the kernel code pmd entry, which will lead to some problem.
It does not because a non-present entry does not care about the load delta obviously.
Thanks,
tglx
Quoted 8 lines · Thomas Gleixner
Quoted 5 lines · Wei Yang
Quoted 2 lines · Thomas Gleixner
What's the actual problem you are trying to solve?
Not a problem. It tries to remove some duplicate check.
I assume you mean redundant check, right?
Yep, you are right.
Quoted 24 lines
The changelog should explain that. I really could not figure out what this is about.
Quoted 20 lines
Quoted 8 lines
arch/x86/kernel/head64.c unsigned long __head __startup_64(unsigned long physaddr, · line 256
Quoted 5 lines
arch/x86/kernel/head64.c +1
-2/* fixup pages that are part of the kernel image */ for (; i <=pmd_index ((unsigned long )_end); i++) -if (pmd[i] & _PAGE_PRESENT) - pmd[i] += load_delta; + pmd[i] += load_delta;Fixing up non-present PMDs is a pointless exercise.
Agree. While we are sure then range here must present.
The whole process looks like this
pmd in [0,
_text)
unset_PAGE_PRESENT
pmd in [_text,_end]
fix up delta
pmd in (_end, 256)
unset_PAGE_PRESENT
Quoted 5 lines
Quoted 2 lines
Since we have compiled in
_PAGE_PRESENTin this page table, it is not necessary to check_PAGE_PRESENTagain before fixing up delta.That wants to be in the change log.
Sure, I would put this in the change log in next version.
Quoted 14 lines
Referencing the history of the code is definitely interesting and you did a great job on decoding it, but for the change itself the only relevant information is that all PMDs between
_textand_endare marked present because the whole table is marked so.Quoted 2 lines
BTW, if one entry between
_textand_endis not present, we will failed to fixing the kernel code pmd entry, which will lead to some problem.It does not because a non-present entry does not care about the load delta obviously.
Thanks,
tglx
Signature · 2 lines
Wei Yang Help you, Help me