All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm/rmap: Fix potential pte_unmap on an not mapped pte
@ 2021-01-27  9:33 Miaohe Lin
  2021-01-28  0:09 ` Andrew Morton
  0 siblings, 1 reply; 3+ messages in thread
From: Miaohe Lin @ 2021-01-27  9:33 UTC (permalink / raw)
  To: akpm
  Cc: mike.kravetz, shakeelb, hannes, vbabka, walken, linux-mm,
	linux-kernel, linmiaohe

For PMD-mapped page (usually THP), pvmw->pte is NULL. For PTE-mapped THP,
pvmw->pte is mapped. But for HugeTLB pages, pvmw->pte is not mapped and set
to the relevant page table entry. So in page_vma_mapped_walk_done(), we may
do pte_unmap() for HugeTLB pte which is not mapped. Fix this by checking
pvmw->page against PageHuge before trying to do pte_unmap().

Fixes: commit ("ace71a19cec5 mm: introduce page_vma_mapped_walk()")
Signed-off-by: Hongxiang Lou <louhongxiang@huawei.com>
Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
Cc: <stable@vger.kernel.org>
---
 include/linux/rmap.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/linux/rmap.h b/include/linux/rmap.h
index 70085ca1a3fc..def5c62c93b3 100644
--- a/include/linux/rmap.h
+++ b/include/linux/rmap.h
@@ -213,7 +213,8 @@ struct page_vma_mapped_walk {
 
 static inline void page_vma_mapped_walk_done(struct page_vma_mapped_walk *pvmw)
 {
-	if (pvmw->pte)
+	/* HugeTLB pte is set to the relevant page table entry without pte_mapped. */
+	if (pvmw->pte && !PageHuge(pvmw->page))
 		pte_unmap(pvmw->pte);
 	if (pvmw->ptl)
 		spin_unlock(pvmw->ptl);
-- 
2.19.1


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

* Re: [PATCH] mm/rmap: Fix potential pte_unmap on an not mapped pte
  2021-01-27  9:33 [PATCH] mm/rmap: Fix potential pte_unmap on an not mapped pte Miaohe Lin
@ 2021-01-28  0:09 ` Andrew Morton
  2021-01-28  1:54   ` Miaohe Lin
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2021-01-28  0:09 UTC (permalink / raw)
  To: Miaohe Lin
  Cc: mike.kravetz, shakeelb, hannes, vbabka, walken, linux-mm, linux-kernel

On Wed, 27 Jan 2021 04:33:49 -0500 Miaohe Lin <linmiaohe@huawei.com> wrote:

> For PMD-mapped page (usually THP), pvmw->pte is NULL. For PTE-mapped THP,
> pvmw->pte is mapped. But for HugeTLB pages, pvmw->pte is not mapped and set
> to the relevant page table entry. So in page_vma_mapped_walk_done(), we may
> do pte_unmap() for HugeTLB pte which is not mapped. Fix this by checking
> pvmw->page against PageHuge before trying to do pte_unmap().
> 

What are the runtime consequences of this?  Is there a workload which
is known to trigger it?

IOW, how do we justify a -stable backport of this fix?

>
> --- a/include/linux/rmap.h
> +++ b/include/linux/rmap.h
> @@ -213,7 +213,8 @@ struct page_vma_mapped_walk {
>  
>  static inline void page_vma_mapped_walk_done(struct page_vma_mapped_walk *pvmw)
>  {
> -	if (pvmw->pte)
> +	/* HugeTLB pte is set to the relevant page table entry without pte_mapped. */
> +	if (pvmw->pte && !PageHuge(pvmw->page))
>  		pte_unmap(pvmw->pte);
>  	if (pvmw->ptl)
>  		spin_unlock(pvmw->ptl);
> -- 
> 2.19.1

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

* Re: [PATCH] mm/rmap: Fix potential pte_unmap on an not mapped pte
  2021-01-28  0:09 ` Andrew Morton
@ 2021-01-28  1:54   ` Miaohe Lin
  0 siblings, 0 replies; 3+ messages in thread
From: Miaohe Lin @ 2021-01-28  1:54 UTC (permalink / raw)
  To: Andrew Morton
  Cc: mike.kravetz, shakeelb, hannes, vbabka, walken, linux-mm, linux-kernel

Hi:
On 2021/1/28 8:09, Andrew Morton wrote:
> On Wed, 27 Jan 2021 04:33:49 -0500 Miaohe Lin <linmiaohe@huawei.com> wrote:
> 
>> For PMD-mapped page (usually THP), pvmw->pte is NULL. For PTE-mapped THP,
>> pvmw->pte is mapped. But for HugeTLB pages, pvmw->pte is not mapped and set
>> to the relevant page table entry. So in page_vma_mapped_walk_done(), we may
>> do pte_unmap() for HugeTLB pte which is not mapped. Fix this by checking
>> pvmw->page against PageHuge before trying to do pte_unmap().
>>
> 
> What are the runtime consequences of this?  Is there a workload which
> is known to trigger it?
> 

Not yet. This should not be backported. My bad. Sorry about it.

> IOW, how do we justify a -stable backport of this fix?
> >>
>> --- a/include/linux/rmap.h
>> +++ b/include/linux/rmap.h
>> @@ -213,7 +213,8 @@ struct page_vma_mapped_walk {
>>  
>>  static inline void page_vma_mapped_walk_done(struct page_vma_mapped_walk *pvmw)
>>  {
>> -	if (pvmw->pte)
>> +	/* HugeTLB pte is set to the relevant page table entry without pte_mapped. */
>> +	if (pvmw->pte && !PageHuge(pvmw->page))
>>  		pte_unmap(pvmw->pte);
>>  	if (pvmw->ptl)
>>  		spin_unlock(pvmw->ptl);
>> -- 
>> 2.19.1
> .
> 


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

end of thread, other threads:[~2021-01-28  1:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-27  9:33 [PATCH] mm/rmap: Fix potential pte_unmap on an not mapped pte Miaohe Lin
2021-01-28  0:09 ` Andrew Morton
2021-01-28  1:54   ` Miaohe Lin

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.