linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3] arm64: mm: fix p?d_leaf()
@ 2022-04-22  6:00 Muchun Song
  2022-04-22 10:55 ` Will Deacon
  0 siblings, 1 reply; 2+ messages in thread
From: Muchun Song @ 2022-04-22  6:00 UTC (permalink / raw)
  To: will, steven.price, catalin.marinas, akpm, anshuman.khandual,
	lengxujun2007, arnd, quic_qiancai, aneesh.kumar
  Cc: smuchun, duanxiongchun, linux-arm-kernel, linux-kernel, Muchun Song

The pmd_leaf() is used to test a leaf mapped PMD, however, it misses
the PROT_NONE mapped PMD on arm64.  Fix it.  A real world issue [1]
caused by this was reported by Qian Cai. Also fix pud_leaf().

Link: https://patchwork.kernel.org/comment/24798260/ [1]
Fixes: 8aa82df3c123 ("arm64: mm: add p?d_leaf() definitions")
Reported-by: Qian Cai <quic_qiancai@quicinc.com>
Signed-off-by: Muchun Song <songmuchun@bytedance.com>
---
v3:
 - Fix pud_leaf() as well.
 - Rework pmd_leaf() as present && !table.

 arch/arm64/include/asm/pgtable.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
index 930077f7b572..9aae3773b6c4 100644
--- a/arch/arm64/include/asm/pgtable.h
+++ b/arch/arm64/include/asm/pgtable.h
@@ -551,7 +551,7 @@ extern pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn,
 				 PMD_TYPE_TABLE)
 #define pmd_sect(pmd)		((pmd_val(pmd) & PMD_TYPE_MASK) == \
 				 PMD_TYPE_SECT)
-#define pmd_leaf(pmd)		pmd_sect(pmd)
+#define pmd_leaf(pmd)		(pmd_present(pmd) && !pmd_table(pmd))
 #define pmd_bad(pmd)		(!pmd_table(pmd))
 
 #define pmd_leaf_size(pmd)	(pmd_cont(pmd) ? CONT_PMD_SIZE : PMD_SIZE)
@@ -641,7 +641,7 @@ static inline unsigned long pmd_page_vaddr(pmd_t pmd)
 #define pud_none(pud)		(!pud_val(pud))
 #define pud_bad(pud)		(!pud_table(pud))
 #define pud_present(pud)	pte_present(pud_pte(pud))
-#define pud_leaf(pud)		pud_sect(pud)
+#define pud_leaf(pud)		(pud_present(pud) && !pud_table(pud))
 #define pud_valid(pud)		pte_valid(pud_pte(pud))
 
 static inline void set_pud(pud_t *pudp, pud_t pud)
-- 
2.11.0


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

* Re: [PATCH v3] arm64: mm: fix p?d_leaf()
  2022-04-22  6:00 [PATCH v3] arm64: mm: fix p?d_leaf() Muchun Song
@ 2022-04-22 10:55 ` Will Deacon
  0 siblings, 0 replies; 2+ messages in thread
From: Will Deacon @ 2022-04-22 10:55 UTC (permalink / raw)
  To: anshuman.khandual, aneesh.kumar, Muchun Song, akpm, quic_qiancai,
	catalin.marinas, arnd, steven.price, lengxujun2007
  Cc: kernel-team, Will Deacon, linux-kernel, linux-arm-kernel,
	smuchun, duanxiongchun

On Fri, 22 Apr 2022 14:00:33 +0800, Muchun Song wrote:
> The pmd_leaf() is used to test a leaf mapped PMD, however, it misses
> the PROT_NONE mapped PMD on arm64.  Fix it.  A real world issue [1]
> caused by this was reported by Qian Cai. Also fix pud_leaf().
> 
> 

Applied to arm64 (for-next/fixes), thanks!

[1/1] arm64: mm: fix p?d_leaf()
      https://git.kernel.org/arm64/c/23bc8f69f0ec

Cheers,
-- 
Will

https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev

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

end of thread, other threads:[~2022-04-22 10:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-22  6:00 [PATCH v3] arm64: mm: fix p?d_leaf() Muchun Song
2022-04-22 10:55 ` Will Deacon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).