Re: [PATCH] x86/mm: Make pud_present() check _PAGE_PROTNONE and _PAGE_PSE as well

From: Anshuman Khandual
Date: Fri Mar 20 2020 - 09:23:07 EST




On 03/20/2020 05:17 PM, Kirill A. Shutemov wrote:
> On Fri, Mar 20, 2020 at 08:53:16AM +0530, Anshuman Khandual wrote:
>>
>>
>> On 03/18/2020 10:31 AM, Anshuman Khandual wrote:
>>> pud_present() should also check _PAGE_PROTNONE and _PAGE_PSE bits like in
>>> case pmd_present(). This makes a PUD entry test positive for pud_present()
>>> after getting invalidated with pud_mknotpresent(), hence standardizing the
>>> semantics with PMD helpers.
>>>
>>> Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
>>> Cc: Ingo Molnar <mingo@xxxxxxxxxx>
>>> Cc: Borislav Petkov <bp@xxxxxxxxx>
>>> Cc: "H. Peter Anvin" <hpa@xxxxxxxxx>
>>> Cc: Dave Hansen <dave.hansen@xxxxxxxxx>
>>> Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
>>> Cc: x86@xxxxxxxxxx
>>> Cc: linux-mm@xxxxxxxxx
>>> Cc: linux-kernel@xxxxxxxxxxxxxxx
>>> Signed-off-by: Anshuman Khandual <anshuman.khandual@xxxxxxx>
>>> ---
>>> Even though pud_mknotpresent() is not used any where currently, there is
>>> a discrepancy between PMD and PUD.
>>>
>>> WARN_ON(!pud_present(pud_mknotpresent(pud_mkhuge(pud)))) -> Fail
>>> WARN_ON(!pmd_present(pmd_mknotpresent(pmd_mkhuge(pmd)))) -> Pass
>>>
>>> Though pud_mknotpresent() currently clears _PAGE_PROTNONE, pud_present()
>>> does not check it. This change fixes both inconsistencies.
>>>
>>> This has been build and boot tested on x86.
>>
>> Adding Kirill and Dan.
>>
>> +Cc: Kirill A. Shutemov <kirill@xxxxxxxxxxxxx>
>> +Cc: Dan Williams <dan.j.williams@xxxxxxxxx>
>
> Or we can just drop the pud_mknotpresent(). There's no users AFAICS and
> only x86 provides it.

Yes that will be an option but IMHO fixing pud_present() here might be
a better choice because,

(1) pud_mknotpresent() with fixed pud_present() might be required later
(2) PMD & PUD will be exact same (THP is supported on either level)

Nonetheless, I am happy to go either way.