2024-05-23 08:38:49

by Wei Yang

[permalink] [raw]
Subject: [Patch v2] x86/head/64: remove redundant check on level2_kernel_pgt's _PAGE_PRESENT bit

This patch tries to remove a redundant check on kernel code's PMD
_PAGE_PRESENT attribute before fix up.

Current process looks like this:

pmd in [0, _text)
unset _PAGE_PRESENT
pmd in [_text, _end]
if (_PAGE_PRESENT)
fix up delta
pmd in (_end, 512)
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

Signed-off-by: Wei Yang <[email protected]>
CC: Thomas Gleixner <[email protected]>
CC: Kirill A. Shutemov <[email protected]>
CC: Ingo Molnar <[email protected]>
CC: Steve Wahl <[email protected]>

---
v2: adjust the change log to emphasize the redundant check
---
arch/x86/kernel/head64.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
index a817ed0724d1..bac33ec19aa2 100644
--- a/arch/x86/kernel/head64.c
+++ b/arch/x86/kernel/head64.c
@@ -260,8 +260,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++)
--
2.34.1



2024-05-23 10:33:40

by Kirill A. Shutemov

[permalink] [raw]
Subject: Re: [Patch v2] x86/head/64: remove redundant check on level2_kernel_pgt's _PAGE_PRESENT bit

On Thu, May 23, 2024 at 08:37:52AM +0000, Wei Yang wrote:
> This patch tries to remove a redundant check on kernel code's PMD
> _PAGE_PRESENT attribute before fix up.

Tries? s/This patch tries to r/R/

> Current process looks like this:
>
> pmd in [0, _text)
> unset _PAGE_PRESENT
> pmd in [_text, _end]
> if (_PAGE_PRESENT)
> fix up delta
> pmd in (_end, 512)
> 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

level2_kernel_pgt compiled with _PAGE_PRESENT set. The check is
redundant.


--
Kiryl Shutsemau / Kirill A. Shutemov

2024-05-23 12:26:44

by Wei Yang

[permalink] [raw]
Subject: Re: [Patch v2] x86/head/64: remove redundant check on level2_kernel_pgt's _PAGE_PRESENT bit

Thanks for comment.

On Thu, May 23, 2024 at 01:33:28PM +0300, Kirill A . Shutemov wrote:
>On Thu, May 23, 2024 at 08:37:52AM +0000, Wei Yang wrote:
>> This patch tries to remove a redundant check on kernel code's PMD
>> _PAGE_PRESENT attribute before fix up.
>
>Tries? s/This patch tries to r/R/

Will use this one.

>
>> Current process looks like this:
>>
>> pmd in [0, _text)
>> unset _PAGE_PRESENT
>> pmd in [_text, _end]
>> if (_PAGE_PRESENT)
>> fix up delta
>> pmd in (_end, 512)
>> 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
>
>level2_kernel_pgt compiled with _PAGE_PRESENT set. The check is
>redundant.
>

Will use this one, thanks

>
>--
> Kiryl Shutsemau / Kirill A. Shutemov

--
Wei Yang
Help you, Help me