Skip to contentSkip to conversation

x86/mm: Make pud_present() check _PAGE_PROTNONE and _PAGE_PSE as well

PATCH In review Anshuman Khandual 3 participants 6 messages Mar 18, 2020 – Mar 22, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/mm: Make pud_present() check _PAGE_PROTNONE and _PAGE_PSE as well

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 <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
Cc Dave Hansen <[email protected]>
Cc Andrew Morton <[email protected]>

---
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.

 arch/x86/include/asm/pgtable.h | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
arch/x86/include/asm/pgtable.h +7 -1
index 7e118660bbd9..8adf1d00b506 100644
@@ -857,7 +857,13 @@ static inline int pud_none(pud_t pud)
 
 static inline int pud_present(pud_t pud)
 {
-	return pud_flags(pud) & _PAGE_PRESENT;
+	/*
+	 * Checking for _PAGE_PSE is needed too because
+	 * split_huge_page will temporarily clear the present bit (but
+	 * the _PAGE_PSE flag will remain set at all times while the
+	 * _PAGE_PRESENT bit is clear).
+	 */
+	return pud_flags(pud) & (_PAGE_PRESENT | _PAGE_PROTNONE | _PAGE_PSE);
 }
 
 static inline unsigned long pud_page_vaddr(pud_t pud)
Signature · 1 line
2.17.1
#1 lore raw
Quoted 19 lines · Anshuman Khandual

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 <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
Cc Dave Hansen <[email protected]>
Cc Andrew Morton <[email protected]>

---
Even though pud_mknotpresent() is not used any where currently, there is a discrepancy between PMD and PUD.

Quoted 7 lines

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 <[email protected]>
+Cc: Dan Williams <[email protected]>

#2 lore raw
Quoted 32 lines · Anshuman Khandual
Quoted 19 lines · Anshuman Khandual

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 <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
Cc Dave Hansen <[email protected]>
Cc Andrew Morton <[email protected]>

---
Even though pud_mknotpresent() is not used any where currently, there is a discrepancy between PMD and PUD.

Quoted 7 lines

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.

Review

Quoted 2 lines
(quoted diff) +2 -0
+Cc: Kirill A. Shutemov <[email protected]>
+Cc: Dan Williams <[email protected]>

Or we can just drop the pud_mknotpresent(). There's no users AFAICS and only x86 provides it.

Signature · 1 line
 Kirill A. Shutemov
#3 lore raw
Quoted 31 lines · Kirill A. Shutemov
Quoted 30 lines · Anshuman Khandual
Quoted 26 lines · Anshuman Khandual

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 <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
Cc Dave Hansen <[email protected]>
Cc Andrew Morton <[email protected]>

---
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.

Quoted 7 lines

Review

Quoted 4 lines

Adding Kirill and Dan.

(quoted diff) +2 -0
+Cc: Kirill A. Shutemov <[email protected]>
+Cc: Dan Williams <[email protected]>

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.

#4 lore raw

On 3/20/20 6:22 AM, Anshuman Khandual wrote:
...

Quoted 5 lines
Quoted 5 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+Cc: Kirill A. Shutemov <[email protected]>
+Cc: Dan Williams <[email protected]>

Or we can just drop the pud_mknotpresent(). There's no users AFAICS and only x86 provides it.

+1

Quoted 5 lines

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

It might. Or it might not. Let's wait until it's actually used, and see. Dead code is an avoidable expense (adds size, space on the screen, email traffic and other wasted time), so let's avoid it here.

Quoted 4 lines

(2) PMD & PUD will be exact same (THP is supported on either level)

Nonetheless, I am happy to go either way.

thanks,

Signature · 2 lines
John Hubbard
NVIDIA
#5 lore raw
Quoted 14 lines · John Hubbard

On 3/20/20 6:22 AM, Anshuman Khandual wrote:
...

Quoted 5 lines
Quoted 5 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+Cc: Kirill A. Shutemov <[email protected]>
+Cc: Dan Williams <[email protected]>

Or we can just drop the pud_mknotpresent(). There's no users AFAICS and only x86 provides it.

+1

Quoted 4 lines

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

Quoted 6 lines
Quoted 1 line

(1) pud_mknotpresent() with fixed pud_present() might be required later

It might. Or it might not. Let's wait until it's actually used, and see. Dead code is an avoidable expense (adds size, space on the screen, email traffic and other wasted time), so let's avoid it here.

Sure, will resend with pud_mknotpresent() dropped.

Quoted 9 lines
Quoted 6 lines

(2) PMD & PUD will be exact same (THP is supported on either level)

Nonetheless, I am happy to go either way.

thanks,