Skip to contentSkip to conversation

arm64: mm: use ptep_clear() instead of pte_clear() in clear_flush()

PATCH Applied Qi Zheng 4 participants 7 messages Aug 10, 2023 – Aug 22, 2023 2 messages not in the archive arm64

lore
Share & tools
lore

Qi Zheng

author
#0 lore raw

PATCH 1/1 arm64: mm: use ptep_clear() instead of pte_clear() in clear_flush()

From: Qi Zheng <[email protected]>

In clear_flush(), the original pte may be a present entry, so we should use ptep_clear() to let page_table_check track the pte clearing operation, otherwise it may cause false positive in subsequent set_pte_at().

Fixes 42b2547137f5 ("arm64/mm: enable ARCH_SUPPORTS_PAGE_TABLE_CHECK")
---
 arch/arm64/mm/hugetlbpage.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/mm/hugetlbpage.c +1 -1
index 21716c940682..9c52718ea750 100644
@@ -236,7 +236,7 @@ static void clear_flush(struct mm_struct *mm,
 	unsigned long i, saddr = addr;
 
 	for (i = 0; i < ncontig; i++, addr += pgsize, ptep++)
-		pte_clear(mm, addr, ptep);
+		ptep_clear(mm, addr, ptep);
 
 	flush_tlb_range(&vma, saddr, addr);
 }
Signature · 1 line
2.30.2
author
#1 lore raw

I wrote wrong Kefeng's email address before, correct it now.

Quoted 25 lines · Qi Zheng

From: Qi Zheng <[email protected]>

In clear_flush(), the original pte may be a present entry, so we should use ptep_clear() to let page_table_check track the pte clearing operation, otherwise it may cause false positive in subsequent set_pte_at().

Fixes 42b2547137f5 ("arm64/mm: enable ARCH_SUPPORTS_PAGE_TABLE_CHECK")
---
  arch/arm64/mm/hugetlbpage.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/mm/hugetlbpage.c +1 -1
index 21716c940682..9c52718ea750 100644
@@ -236,7 +236,7 @@ static void clear_flush(struct mm_struct *mm,
  	unsigned long i, saddr = addr;
 
  	for (i = 0; i < ncontig; i++, addr += pgsize, ptep++)
-		pte_clear(mm, addr, ptep);
+		ptep_clear(mm, addr, ptep);
 
  	flush_tlb_range(&vma, saddr, addr);
  }
maintainer
#2 lore raw
In reply to Qi Zheng
Quoted 5 lines · Qi Zheng

From: Qi Zheng <[email protected]>

In clear_flush(), the original pte may be a present entry, so we should use ptep_clear() to let page_table_check track the pte clearing operation, otherwise it may cause false positive in subsequent set_pte_at().

Isn't this true for most users of pte_clear()? There are some in the core code, so could they trigger the false positive as well?

Will

A message that is not in the archive (sent off-list or not yet received): CAOgjDMi6kTZUjEianbO670RQxJ8=JhHxkeci9NspSCRT5rPhYw@mail.gmail.com

maintainer
#4 lore raw
Quoted 11 lines · Qi Zheng

Will Deacon <[1][email protected]>于2023年8月11日 周五19:03写道:

On Thu, Aug 10, 2023 at 09:32:41AM +0000, Qi Zheng wrote:
> From: Qi Zheng <[2][email protected]>
>
> In clear_flush(), the original pte may be a present entry, so we should
> use ptep_clear() to let page_table_check track the pte clearing operation,
> otherwise it may cause false positive in subsequent set_pte_at().

Quoted 8 lines

Isn't this true for most users of pte_clear()? There are some in the core
code, so could they trigger the false positive as well?

No, the PTE entry in other places where pte_clear() is used is non-present PTE.
The page_table_check does not does track the pte operation in this case, so it will not cause false positives.

Are you sure? For example, the call from flush_all_zero_pkmaps() in highmem.c really looks like it's clearing a valid entry. Not that arm64 cares about highmem, but still.

Will

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

A message that is not in the archive (sent off-list or not yet received): CAOgjDMgVZXbEeA6O2yPR9N27JWCMNR3D7cgHJbmbfYYUdKF3eQ@mail.gmail.com

#6 lore raw
Quoted 25 lines · On Fri, 11 Aug 2023 19:28:41 +0800 Qi Zheng <[email protected]> wrote:
Quoted 23 lines · Will Deacon <[email protected]>于2023年8月11日 周五19:21写道:
Quoted 11 lines · Qi Zheng

Will Deacon <[1][email protected]>于2023年8月11日 周五19:03写道:

On Thu, Aug 10, 2023 at 09:32:41AM +0000, Qi Zheng wrote:
> From: Qi Zheng <[2][email protected]>
>
> In clear_flush(), the original pte may be a present entry, so we should
> use ptep_clear() to let page_table_check track the pte clearing operation,
> otherwise it may cause false positive in subsequent set_pte_at().

Quoted 5 lines

Isn't this true for most users of pte_clear()? There are some in the core
code, so could they trigger the false positive as well?

No, the PTE entry in other places where pte_clear() is used is

non-present

Quoted 2 lines

PTE.
The page_table_check does not does track the pte operation in this

case,

Quoted 1 line

so it will not cause false positives.

Quoted 7 lines
Quoted 3 lines

Are you sure? For example, the call from flush_all_zero_pkmaps() in highmem.c really looks like it's clearing a valid entry. Not that arm64 cares about highmem, but still.

Ah, this is init_mm, not user mm, page_table_check does not care about this case.

It's unclear where we stand with this patch. An ack or a nack, please?

#7 lore raw
Quoted 32 lines · Andrew Morton
Quoted 30 lines · On Fri, 11 Aug 2023 19:28:41 +0800 Qi Zheng <[email protected]> wrote:
Quoted 26 lines · Will Deacon <[email protected]>于2023年8月11日 周五19:21写道:
Quoted 11 lines · Qi Zheng

Will Deacon <[1][email protected]>于2023年8月11日 周五19:03写道:

On Thu, Aug 10, 2023 at 09:32:41AM +0000, Qi Zheng wrote:
> From: Qi Zheng <[2][email protected]>
>
> In clear_flush(), the original pte may be a present entry, so we should
> use ptep_clear() to let page_table_check track the pte clearing operation,
> otherwise it may cause false positive in subsequent set_pte_at().

Quoted 5 lines

Isn't this true for most users of pte_clear()? There are some in the core
code, so could they trigger the false positive as well?

No, the PTE entry in other places where pte_clear() is used is

non-present

Quoted 2 lines

PTE.
The page_table_check does not does track the pte operation in this

case,

Quoted 1 line

so it will not cause false positives.

Are you sure? For example, the call from flush_all_zero_pkmaps() in highmem.c really looks like it's clearing a valid entry. Not that arm64 cares about highmem, but still.

Quoted 4 lines
Quoted 2 lines

Ah, this is init_mm, not user mm, page_table_check does not care about this case.

It's unclear where we stand with this patch. An ack or a nack, please?

Hi all,

Any comments or suggestions here?

Thanks,
Qi

maintainer Acked-by
#8 lore raw
In reply to Andrew Morton
Quoted 32 lines · Andrew Morton
Quoted 30 lines · On Fri, 11 Aug 2023 19:28:41 +0800 Qi Zheng <[email protected]> wrote:
Quoted 26 lines · Will Deacon <[email protected]>于2023年8月11日 周五19:21写道:
Quoted 11 lines · Qi Zheng

Will Deacon <[1][email protected]>于2023年8月11日 周五19:03写道:

On Thu, Aug 10, 2023 at 09:32:41AM +0000, Qi Zheng wrote:
> From: Qi Zheng <[2][email protected]>
>
> In clear_flush(), the original pte may be a present entry, so we should
> use ptep_clear() to let page_table_check track the pte clearing operation,
> otherwise it may cause false positive in subsequent set_pte_at().

Quoted 5 lines

Isn't this true for most users of pte_clear()? There are some in the core
code, so could they trigger the false positive as well?

No, the PTE entry in other places where pte_clear() is used is

non-present

Quoted 2 lines

PTE.
The page_table_check does not does track the pte operation in this

case,

Quoted 1 line

so it will not cause false positives.

Are you sure? For example, the call from flush_all_zero_pkmaps() in highmem.c really looks like it's clearing a valid entry. Not that arm64 cares about highmem, but still.

Quoted 4 lines
Quoted 2 lines

Ah, this is init_mm, not user mm, page_table_check does not care about this case.

It's unclear where we stand with this patch. An ack or a nack, please?

Sorry Andrew, I saw you'd queued it so I marked it as "done" on my list. I think it's fine:

Will