linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] arm64: mm: use ptep_clear() instead of pte_clear() in clear_flush()
@ 2023-08-10  9:32 Qi Zheng
  2023-08-11  2:38 ` Qi Zheng
  2023-08-11 11:03 ` Will Deacon
  0 siblings, 2 replies; 7+ messages in thread
From: Qi Zheng @ 2023-08-10  9:32 UTC (permalink / raw)
  To: catalin.marinas, will, akpm, wangkefeng.wang, pasha.tatashin,
	muchun.song
  Cc: linux-arm-kernel, linux-kernel, Qi Zheng

From: Qi Zheng <zhengqi.arch@bytedance.com>

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")
Signed-off-by: Qi Zheng <zhengqi.arch@bytedance.com>
---
 arch/arm64/mm/hugetlbpage.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm64/mm/hugetlbpage.c b/arch/arm64/mm/hugetlbpage.c
index 21716c940682..9c52718ea750 100644
--- a/arch/arm64/mm/hugetlbpage.c
+++ b/arch/arm64/mm/hugetlbpage.c
@@ -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);
 }
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] arm64: mm: use ptep_clear() instead of pte_clear() in clear_flush()
  2023-08-10  9:32 [PATCH] arm64: mm: use ptep_clear() instead of pte_clear() in clear_flush() Qi Zheng
@ 2023-08-11  2:38 ` Qi Zheng
  2023-08-11 11:03 ` Will Deacon
  1 sibling, 0 replies; 7+ messages in thread
From: Qi Zheng @ 2023-08-11  2:38 UTC (permalink / raw)
  To: catalin.marinas, will, akpm, pasha.tatashin, muchun.song,
	wangkefeng.wang
  Cc: linux-arm-kernel, linux-kernel


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


On 2023/8/10 17:32, Qi Zheng wrote:
> From: Qi Zheng <zhengqi.arch@bytedance.com>
> 
> 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")
> Signed-off-by: Qi Zheng <zhengqi.arch@bytedance.com>
> ---
>   arch/arm64/mm/hugetlbpage.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/arm64/mm/hugetlbpage.c b/arch/arm64/mm/hugetlbpage.c
> index 21716c940682..9c52718ea750 100644
> --- a/arch/arm64/mm/hugetlbpage.c
> +++ b/arch/arm64/mm/hugetlbpage.c
> @@ -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);
>   }

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] arm64: mm: use ptep_clear() instead of pte_clear() in clear_flush()
  2023-08-10  9:32 [PATCH] arm64: mm: use ptep_clear() instead of pte_clear() in clear_flush() Qi Zheng
  2023-08-11  2:38 ` Qi Zheng
@ 2023-08-11 11:03 ` Will Deacon
       [not found]   ` <CAOgjDMi6kTZUjEianbO670RQxJ8=JhHxkeci9NspSCRT5rPhYw@mail.gmail.com>
  1 sibling, 1 reply; 7+ messages in thread
From: Will Deacon @ 2023-08-11 11:03 UTC (permalink / raw)
  To: Qi Zheng
  Cc: catalin.marinas, akpm, wangkefeng.wang, pasha.tatashin,
	muchun.song, linux-arm-kernel, linux-kernel, Qi Zheng

On Thu, Aug 10, 2023 at 09:32:41AM +0000, Qi Zheng wrote:
> From: Qi Zheng <zhengqi.arch@bytedance.com>
> 
> 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

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] arm64: mm: use ptep_clear() instead of pte_clear() in clear_flush()
       [not found]   ` <CAOgjDMi6kTZUjEianbO670RQxJ8=JhHxkeci9NspSCRT5rPhYw@mail.gmail.com>
@ 2023-08-11 11:21     ` Will Deacon
       [not found]       ` <CAOgjDMgVZXbEeA6O2yPR9N27JWCMNR3D7cgHJbmbfYYUdKF3eQ@mail.gmail.com>
  0 siblings, 1 reply; 7+ messages in thread
From: Will Deacon @ 2023-08-11 11:21 UTC (permalink / raw)
  To: Qi Zheng
  Cc: Qi Zheng, akpm, catalin.marinas, linux-arm-kernel, linux-kernel,
	muchun.song, pasha.tatashin, wangkefeng.wang

On Fri, Aug 11, 2023 at 07:16:20PM +0800, Qi Zheng wrote:
>    Will Deacon <[1]will@kernel.org>于2023年8月11日 周五19:03写道:
> 
>      On Thu, Aug 10, 2023 at 09:32:41AM +0000, Qi Zheng wrote:
>      > From: Qi Zheng <[2]zhengqi.arch@bytedance.com>
>      >
>      > 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?
> 
>    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
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] arm64: mm: use ptep_clear() instead of pte_clear() in clear_flush()
       [not found]       ` <CAOgjDMgVZXbEeA6O2yPR9N27JWCMNR3D7cgHJbmbfYYUdKF3eQ@mail.gmail.com>
@ 2023-08-21 20:21         ` Andrew Morton
  2023-08-22  2:23           ` Qi Zheng
  2023-08-22  9:58           ` Will Deacon
  0 siblings, 2 replies; 7+ messages in thread
From: Andrew Morton @ 2023-08-21 20:21 UTC (permalink / raw)
  To: Qi Zheng
  Cc: Will Deacon, Qi Zheng, catalin.marinas, linux-arm-kernel,
	linux-kernel, muchun.song, pasha.tatashin, wangkefeng.wang

On Fri, 11 Aug 2023 19:28:41 +0800 Qi Zheng <zhengqi.arch@bytedance.com> wrote:

> Will Deacon <will@kernel.org>于2023年8月11日 周五19:21写道:
> 
> > On Fri, Aug 11, 2023 at 07:16:20PM +0800, Qi Zheng wrote:
> > >    Will Deacon <[1]will@kernel.org>于2023年8月11日 周五19:03写道:
> > >
> > >      On Thu, Aug 10, 2023 at 09:32:41AM +0000, Qi Zheng wrote:
> > >      > From: Qi Zheng <[2]zhengqi.arch@bytedance.com>
> > >      >
> > >      > 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?
> > >
> > >    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.
> 
> 
> 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?

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] arm64: mm: use ptep_clear() instead of pte_clear() in clear_flush()
  2023-08-21 20:21         ` Andrew Morton
@ 2023-08-22  2:23           ` Qi Zheng
  2023-08-22  9:58           ` Will Deacon
  1 sibling, 0 replies; 7+ messages in thread
From: Qi Zheng @ 2023-08-22  2:23 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Will Deacon, Qi Zheng, catalin.marinas, linux-arm-kernel,
	linux-kernel, muchun.song, pasha.tatashin, wangkefeng.wang



On 2023/8/22 04:21, Andrew Morton wrote:
> On Fri, 11 Aug 2023 19:28:41 +0800 Qi Zheng <zhengqi.arch@bytedance.com> wrote:
> 
>> Will Deacon <will@kernel.org>于2023年8月11日 周五19:21写道:
>>
>>> On Fri, Aug 11, 2023 at 07:16:20PM +0800, Qi Zheng wrote:
>>>>     Will Deacon <[1]will@kernel.org>于2023年8月11日 周五19:03写道:
>>>>
>>>>       On Thu, Aug 10, 2023 at 09:32:41AM +0000, Qi Zheng wrote:
>>>>       > From: Qi Zheng <[2]zhengqi.arch@bytedance.com>
>>>>       >
>>>>       > 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?
>>>>
>>>>     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.
>>
>>
>> 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

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] arm64: mm: use ptep_clear() instead of pte_clear() in clear_flush()
  2023-08-21 20:21         ` Andrew Morton
  2023-08-22  2:23           ` Qi Zheng
@ 2023-08-22  9:58           ` Will Deacon
  1 sibling, 0 replies; 7+ messages in thread
From: Will Deacon @ 2023-08-22  9:58 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Qi Zheng, Qi Zheng, catalin.marinas, linux-arm-kernel,
	linux-kernel, muchun.song, pasha.tatashin, wangkefeng.wang

On Mon, Aug 21, 2023 at 01:21:19PM -0700, Andrew Morton wrote:
> On Fri, 11 Aug 2023 19:28:41 +0800 Qi Zheng <zhengqi.arch@bytedance.com> wrote:
> 
> > Will Deacon <will@kernel.org>于2023年8月11日 周五19:21写道:
> > 
> > > On Fri, Aug 11, 2023 at 07:16:20PM +0800, Qi Zheng wrote:
> > > >    Will Deacon <[1]will@kernel.org>于2023年8月11日 周五19:03写道:
> > > >
> > > >      On Thu, Aug 10, 2023 at 09:32:41AM +0000, Qi Zheng wrote:
> > > >      > From: Qi Zheng <[2]zhengqi.arch@bytedance.com>
> > > >      >
> > > >      > 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?
> > > >
> > > >    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.
> > 
> > 
> > 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:

Acked-by: Will Deacon <will@kernel.org>

Will

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2023-08-22  9:59 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-10  9:32 [PATCH] arm64: mm: use ptep_clear() instead of pte_clear() in clear_flush() Qi Zheng
2023-08-11  2:38 ` Qi Zheng
2023-08-11 11:03 ` Will Deacon
     [not found]   ` <CAOgjDMi6kTZUjEianbO670RQxJ8=JhHxkeci9NspSCRT5rPhYw@mail.gmail.com>
2023-08-11 11:21     ` Will Deacon
     [not found]       ` <CAOgjDMgVZXbEeA6O2yPR9N27JWCMNR3D7cgHJbmbfYYUdKF3eQ@mail.gmail.com>
2023-08-21 20:21         ` Andrew Morton
2023-08-22  2:23           ` Qi Zheng
2023-08-22  9:58           ` 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).