linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] userfaultfd/hugetlbfs: Fix minor fault page leak
@ 2021-03-22 17:51 Peter Xu
  2021-03-22 20:13 ` Mike Kravetz
  2021-03-22 20:19 ` Axel Rasmussen
  0 siblings, 2 replies; 3+ messages in thread
From: Peter Xu @ 2021-03-22 17:51 UTC (permalink / raw)
  To: linux-mm, linux-kernel
  Cc: Andrew Morton, peterx, Axel Rasmussen, Andrea Arcangeli,
	Mike Kravetz, Mike Rapoport

When uffd-minor enabled, we need to put the page cache before handling the
userfault in hugetlb_no_page(), otherwise the page refcount got leaked.

This can be reproduced by running userfaultfd selftest with hugetlb_shared
mode, then cat /proc/meminfo.

Cc: Axel Rasmussen <axelrasmussen@google.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Mike Rapoport <rppt@linux.vnet.ibm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Fixes: f2bf15fb0969 ("userfaultfd: add minor fault registration mode")
Signed-off-by: Peter Xu <peterx@redhat.com>
---
 mm/hugetlb.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 408dbc08298a..56b78a206913 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -4449,6 +4449,7 @@ static vm_fault_t hugetlb_no_page(struct mm_struct *mm,
 		/* Check for page in userfault range. */
 		if (userfaultfd_minor(vma)) {
 			unlock_page(page);
+			put_page(page);
 			ret = hugetlb_handle_userfault(vma, mapping, idx,
 						       flags, haddr,
 						       VM_UFFD_MINOR);
-- 
2.26.2



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

* Re: [PATCH] userfaultfd/hugetlbfs: Fix minor fault page leak
  2021-03-22 17:51 [PATCH] userfaultfd/hugetlbfs: Fix minor fault page leak Peter Xu
@ 2021-03-22 20:13 ` Mike Kravetz
  2021-03-22 20:19 ` Axel Rasmussen
  1 sibling, 0 replies; 3+ messages in thread
From: Mike Kravetz @ 2021-03-22 20:13 UTC (permalink / raw)
  To: Peter Xu, linux-mm, linux-kernel
  Cc: Andrew Morton, Axel Rasmussen, Andrea Arcangeli, Mike Rapoport

On 3/22/21 10:51 AM, Peter Xu wrote:
> When uffd-minor enabled, we need to put the page cache before handling the
> userfault in hugetlb_no_page(), otherwise the page refcount got leaked.
> 
> This can be reproduced by running userfaultfd selftest with hugetlb_shared
> mode, then cat /proc/meminfo.
> 
> Cc: Axel Rasmussen <axelrasmussen@google.com>
> Cc: Andrea Arcangeli <aarcange@redhat.com>
> Cc: Mike Kravetz <mike.kravetz@oracle.com>
> Cc: Mike Rapoport <rppt@linux.vnet.ibm.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Fixes: f2bf15fb0969 ("userfaultfd: add minor fault registration mode")
> Signed-off-by: Peter Xu <peterx@redhat.com>
> ---
>  mm/hugetlb.c | 1 +
>  1 file changed, 1 insertion(+)

Thanks for finding/fixing.

Reviewed-by: Mike Kravetz <mike.kravetz@oracle.com>

I think this is just in Andrew's tree.  So it will need to be fixed
there.
-- 
Mike Kravetz

> 
> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
> index 408dbc08298a..56b78a206913 100644
> --- a/mm/hugetlb.c
> +++ b/mm/hugetlb.c
> @@ -4449,6 +4449,7 @@ static vm_fault_t hugetlb_no_page(struct mm_struct *mm,
>  		/* Check for page in userfault range. */
>  		if (userfaultfd_minor(vma)) {
>  			unlock_page(page);
> +			put_page(page);
>  			ret = hugetlb_handle_userfault(vma, mapping, idx,
>  						       flags, haddr,
>  						       VM_UFFD_MINOR);
> 


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

* Re: [PATCH] userfaultfd/hugetlbfs: Fix minor fault page leak
  2021-03-22 17:51 [PATCH] userfaultfd/hugetlbfs: Fix minor fault page leak Peter Xu
  2021-03-22 20:13 ` Mike Kravetz
@ 2021-03-22 20:19 ` Axel Rasmussen
  1 sibling, 0 replies; 3+ messages in thread
From: Axel Rasmussen @ 2021-03-22 20:19 UTC (permalink / raw)
  To: Peter Xu
  Cc: Linux MM, LKML, Andrew Morton, Andrea Arcangeli, Mike Kravetz,
	Mike Rapoport

On Mon, Mar 22, 2021 at 10:51 AM Peter Xu <peterx@redhat.com> wrote:
>
> When uffd-minor enabled, we need to put the page cache before handling the
> userfault in hugetlb_no_page(), otherwise the page refcount got leaked.
>
> This can be reproduced by running userfaultfd selftest with hugetlb_shared
> mode, then cat /proc/meminfo.
>
> Cc: Axel Rasmussen <axelrasmussen@google.com>
> Cc: Andrea Arcangeli <aarcange@redhat.com>
> Cc: Mike Kravetz <mike.kravetz@oracle.com>
> Cc: Mike Rapoport <rppt@linux.vnet.ibm.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Fixes: f2bf15fb0969 ("userfaultfd: add minor fault registration mode")
> Signed-off-by: Peter Xu <peterx@redhat.com>
> ---
>  mm/hugetlb.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
> index 408dbc08298a..56b78a206913 100644
> --- a/mm/hugetlb.c
> +++ b/mm/hugetlb.c
> @@ -4449,6 +4449,7 @@ static vm_fault_t hugetlb_no_page(struct mm_struct *mm,
>                 /* Check for page in userfault range. */
>                 if (userfaultfd_minor(vma)) {
>                         unlock_page(page);
> +                       put_page(page);
>                         ret = hugetlb_handle_userfault(vma, mapping, idx,
>                                                        flags, haddr,
>                                                        VM_UFFD_MINOR);
> --
> 2.26.2
>

Thanks for the fix, Peter! I applied the patch and verified it does
indeed fix the issue.

Reviewed-by: Axel Rasmussen <axelrasmussen@google.com>


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

end of thread, other threads:[~2021-03-22 20:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-22 17:51 [PATCH] userfaultfd/hugetlbfs: Fix minor fault page leak Peter Xu
2021-03-22 20:13 ` Mike Kravetz
2021-03-22 20:19 ` Axel Rasmussen

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