All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/mm: Make pud_present() check _PAGE_PROTNONE and _PAGE_PSE as well
@ 2020-03-18  5:01 Anshuman Khandual
  2020-03-20  3:23 ` Anshuman Khandual
  0 siblings, 1 reply; 6+ messages in thread
From: Anshuman Khandual @ 2020-03-18  5:01 UTC (permalink / raw)
  To: linux-mm
  Cc: Anshuman Khandual, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	H. Peter Anvin, Dave Hansen, Andrew Morton, x86, linux-kernel

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@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Dave Hansen <dave.hansen@intel.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: x86@kernel.org
Cc: linux-mm@kvack.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
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(-)

diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
index 7e118660bbd9..8adf1d00b506 100644
--- a/arch/x86/include/asm/pgtable.h
+++ b/arch/x86/include/asm/pgtable.h
@@ -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)
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] x86/mm: Make pud_present() check _PAGE_PROTNONE and _PAGE_PSE as well
  2020-03-18  5:01 [PATCH] x86/mm: Make pud_present() check _PAGE_PROTNONE and _PAGE_PSE as well Anshuman Khandual
@ 2020-03-20  3:23 ` Anshuman Khandual
  2020-03-20 11:47   ` Kirill A. Shutemov
  0 siblings, 1 reply; 6+ messages in thread
From: Anshuman Khandual @ 2020-03-20  3:23 UTC (permalink / raw)
  To: linux-mm
  Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, H. Peter Anvin,
	Dave Hansen, Andrew Morton, x86, linux-kernel,
	Kirill A. Shutemov, Dan Williams



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@linutronix.de>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: Borislav Petkov <bp@alien8.de>
> Cc: "H. Peter Anvin" <hpa@zytor.com>
> Cc: Dave Hansen <dave.hansen@intel.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: x86@kernel.org
> Cc: linux-mm@kvack.org
> Cc: linux-kernel@vger.kernel.org
> Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
> ---
> 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@shutemov.name>
+Cc: Dan Williams <dan.j.williams@intel.com>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] x86/mm: Make pud_present() check _PAGE_PROTNONE and _PAGE_PSE as well
  2020-03-20  3:23 ` Anshuman Khandual
@ 2020-03-20 11:47   ` Kirill A. Shutemov
  2020-03-20 13:22     ` Anshuman Khandual
  0 siblings, 1 reply; 6+ messages in thread
From: Kirill A. Shutemov @ 2020-03-20 11:47 UTC (permalink / raw)
  To: Anshuman Khandual
  Cc: linux-mm, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	H. Peter Anvin, Dave Hansen, Andrew Morton, x86, linux-kernel,
	Dan Williams

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@linutronix.de>
> > Cc: Ingo Molnar <mingo@redhat.com>
> > Cc: Borislav Petkov <bp@alien8.de>
> > Cc: "H. Peter Anvin" <hpa@zytor.com>
> > Cc: Dave Hansen <dave.hansen@intel.com>
> > Cc: Andrew Morton <akpm@linux-foundation.org>
> > Cc: x86@kernel.org
> > Cc: linux-mm@kvack.org
> > Cc: linux-kernel@vger.kernel.org
> > Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
> > ---
> > 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@shutemov.name>
> +Cc: Dan Williams <dan.j.williams@intel.com>

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

-- 
 Kirill A. Shutemov

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] x86/mm: Make pud_present() check _PAGE_PROTNONE and _PAGE_PSE as well
  2020-03-20 11:47   ` Kirill A. Shutemov
@ 2020-03-20 13:22     ` Anshuman Khandual
  2020-03-20 19:50       ` John Hubbard
  0 siblings, 1 reply; 6+ messages in thread
From: Anshuman Khandual @ 2020-03-20 13:22 UTC (permalink / raw)
  To: Kirill A. Shutemov
  Cc: linux-mm, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	H. Peter Anvin, Dave Hansen, Andrew Morton, x86, linux-kernel,
	Dan Williams



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@linutronix.de>
>>> Cc: Ingo Molnar <mingo@redhat.com>
>>> Cc: Borislav Petkov <bp@alien8.de>
>>> Cc: "H. Peter Anvin" <hpa@zytor.com>
>>> Cc: Dave Hansen <dave.hansen@intel.com>
>>> Cc: Andrew Morton <akpm@linux-foundation.org>
>>> Cc: x86@kernel.org
>>> Cc: linux-mm@kvack.org
>>> Cc: linux-kernel@vger.kernel.org
>>> Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
>>> ---
>>> 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@shutemov.name>
>> +Cc: Dan Williams <dan.j.williams@intel.com>
> 
> 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.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] x86/mm: Make pud_present() check _PAGE_PROTNONE and _PAGE_PSE as well
  2020-03-20 13:22     ` Anshuman Khandual
@ 2020-03-20 19:50       ` John Hubbard
  2020-03-22  1:00         ` Anshuman Khandual
  0 siblings, 1 reply; 6+ messages in thread
From: John Hubbard @ 2020-03-20 19:50 UTC (permalink / raw)
  To: Anshuman Khandual, Kirill A. Shutemov
  Cc: linux-mm, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	H. Peter Anvin, Dave Hansen, Andrew Morton, x86, linux-kernel,
	Dan Williams

On 3/20/20 6:22 AM, Anshuman Khandual wrote:
...
>>> +Cc: Kirill A. Shutemov <kirill@shutemov.name>
>>> +Cc: Dan Williams <dan.j.williams@intel.com>
>>
>> Or we can just drop the pud_mknotpresent(). There's no users AFAICS and
>> only x86 provides it.

+1

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


> (2) PMD & PUD will be exact same (THP is supported on either level)
> 
> Nonetheless, I am happy to go either way.
> 


thanks,
-- 
John Hubbard
NVIDIA

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] x86/mm: Make pud_present() check _PAGE_PROTNONE and _PAGE_PSE as well
  2020-03-20 19:50       ` John Hubbard
@ 2020-03-22  1:00         ` Anshuman Khandual
  0 siblings, 0 replies; 6+ messages in thread
From: Anshuman Khandual @ 2020-03-22  1:00 UTC (permalink / raw)
  To: John Hubbard, Kirill A. Shutemov
  Cc: linux-mm, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	H. Peter Anvin, Dave Hansen, Andrew Morton, x86, linux-kernel,
	Dan Williams



On 03/21/2020 01:20 AM, John Hubbard wrote:
> On 3/20/20 6:22 AM, Anshuman Khandual wrote:
> ...
>>>> +Cc: Kirill A. Shutemov <kirill@shutemov.name>
>>>> +Cc: Dan Williams <dan.j.williams@intel.com>
>>>
>>> Or we can just drop the pud_mknotpresent(). There's no users AFAICS and
>>> only x86 provides it.
> 
> +1
> 
>>
>> 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.


Sure, will resend with pud_mknotpresent() dropped.

> 
> 
>> (2) PMD & PUD will be exact same (THP is supported on either level)
>>
>> Nonetheless, I am happy to go either way.
>>
> 
> 
> thanks,

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-03-22  1:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-18  5:01 [PATCH] x86/mm: Make pud_present() check _PAGE_PROTNONE and _PAGE_PSE as well Anshuman Khandual
2020-03-20  3:23 ` Anshuman Khandual
2020-03-20 11:47   ` Kirill A. Shutemov
2020-03-20 13:22     ` Anshuman Khandual
2020-03-20 19:50       ` John Hubbard
2020-03-22  1:00         ` Anshuman Khandual

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.