* [PATCH] hugetlb: fix hugetlb cgroup refcounting during mremap
@ 2021-11-13 15:44 Bui Quang Minh
2021-11-15 21:16 ` Andrew Morton
0 siblings, 1 reply; 4+ messages in thread
From: Bui Quang Minh @ 2021-11-13 15:44 UTC (permalink / raw)
Cc: Bui Quang Minh, Mike Kravetz, Andrew Morton, Miaohe Lin,
Michal Hocko, Muchun Song, Mina Almasry, linux-kernel, linux-mm
When hugetlb_vm_op_open() is called during copy_vma(), we may take the
reference to resv_map->css. Later, when clearing the reservation pointer
of old_vma after transferring it to new_vma, we forget to drop the
reference to resv_map->css. This leads to a reference leak of css.
Fixes this by adding a check to drop reservation css reference in
clear_vma_resv_huge_pages()
Fixes: 550a7d6 (mm, hugepages: add mremap() support for hugepage backed vma)
Signed-off-by: Bui Quang Minh <minhquangbui99@gmail.com>
---
include/linux/hugetlb_cgroup.h | 12 ++++++++++++
mm/hugetlb.c | 4 +++-
2 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/include/linux/hugetlb_cgroup.h b/include/linux/hugetlb_cgroup.h
index c137396129db..ba025ae27882 100644
--- a/include/linux/hugetlb_cgroup.h
+++ b/include/linux/hugetlb_cgroup.h
@@ -128,6 +128,13 @@ static inline void resv_map_dup_hugetlb_cgroup_uncharge_info(
css_get(resv_map->css);
}
+static inline void resv_map_put_hugetlb_cgroup_uncharge_info(
+ struct resv_map *resv_map)
+{
+ if (resv_map->css)
+ css_put(resv_map->css);
+}
+
extern int hugetlb_cgroup_charge_cgroup(int idx, unsigned long nr_pages,
struct hugetlb_cgroup **ptr);
extern int hugetlb_cgroup_charge_cgroup_rsvd(int idx, unsigned long nr_pages,
@@ -211,6 +218,11 @@ static inline void resv_map_dup_hugetlb_cgroup_uncharge_info(
{
}
+static inline void resv_map_put_hugetlb_cgroup_uncharge_info(
+ struct resv_map *resv_map)
+{
+}
+
static inline int hugetlb_cgroup_charge_cgroup(int idx, unsigned long nr_pages,
struct hugetlb_cgroup **ptr)
{
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index e09159c957e3..3a2479003ddf 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -1037,8 +1037,10 @@ void clear_vma_resv_huge_pages(struct vm_area_struct *vma)
*/
struct resv_map *reservations = vma_resv_map(vma);
- if (reservations && is_vma_resv_set(vma, HPAGE_RESV_OWNER))
+ if (reservations && is_vma_resv_set(vma, HPAGE_RESV_OWNER)) {
+ resv_map_put_hugetlb_cgroup_uncharge_info(reservations);
kref_put(&reservations->refs, resv_map_release);
+ }
reset_vma_resv_huge_pages(vma);
}
--
2.25.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] hugetlb: fix hugetlb cgroup refcounting during mremap
2021-11-13 15:44 [PATCH] hugetlb: fix hugetlb cgroup refcounting during mremap Bui Quang Minh
@ 2021-11-15 21:16 ` Andrew Morton
2021-11-15 22:39 ` Mina Almasry
2021-11-15 23:25 ` Mike Kravetz
0 siblings, 2 replies; 4+ messages in thread
From: Andrew Morton @ 2021-11-15 21:16 UTC (permalink / raw)
To: Bui Quang Minh
Cc: Mike Kravetz, Miaohe Lin, Michal Hocko, Muchun Song,
Mina Almasry, linux-kernel, linux-mm
On Sat, 13 Nov 2021 22:44:10 +0700 Bui Quang Minh <minhquangbui99@gmail.com> wrote:
> When hugetlb_vm_op_open() is called during copy_vma(), we may take the
> reference to resv_map->css. Later, when clearing the reservation pointer
> of old_vma after transferring it to new_vma, we forget to drop the
> reference to resv_map->css. This leads to a reference leak of css.
>
> Fixes this by adding a check to drop reservation css reference in
> clear_vma_resv_huge_pages()
Thanks. I added cc:stable to this (550a7d60bd5e35a was merged a year
ago) and I've queued it for 5.16-rc2, pending suitable reviewer feedback.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] hugetlb: fix hugetlb cgroup refcounting during mremap
2021-11-15 21:16 ` Andrew Morton
@ 2021-11-15 22:39 ` Mina Almasry
2021-11-15 23:25 ` Mike Kravetz
1 sibling, 0 replies; 4+ messages in thread
From: Mina Almasry @ 2021-11-15 22:39 UTC (permalink / raw)
To: Andrew Morton
Cc: Bui Quang Minh, Mike Kravetz, Miaohe Lin, Michal Hocko,
Muchun Song, linux-kernel, linux-mm
On Mon, Nov 15, 2021 at 1:16 PM Andrew Morton <akpm@linux-foundation.org> wrote:
>
> On Sat, 13 Nov 2021 22:44:10 +0700 Bui Quang Minh <minhquangbui99@gmail.com> wrote:
>
> > When hugetlb_vm_op_open() is called during copy_vma(), we may take the
> > reference to resv_map->css. Later, when clearing the reservation pointer
> > of old_vma after transferring it to new_vma, we forget to drop the
> > reference to resv_map->css. This leads to a reference leak of css.
> >
> > Fixes this by adding a check to drop reservation css reference in
> > clear_vma_resv_huge_pages()
>
> Thanks. I added cc:stable to this (550a7d60bd5e35a was merged a year
> ago) and I've queued it for 5.16-rc2, pending suitable reviewer feedback.
>
Thanks,
Reviewed-by: Mina Almasry <almasrymina@google.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] hugetlb: fix hugetlb cgroup refcounting during mremap
2021-11-15 21:16 ` Andrew Morton
2021-11-15 22:39 ` Mina Almasry
@ 2021-11-15 23:25 ` Mike Kravetz
1 sibling, 0 replies; 4+ messages in thread
From: Mike Kravetz @ 2021-11-15 23:25 UTC (permalink / raw)
To: Andrew Morton, Bui Quang Minh
Cc: Miaohe Lin, Michal Hocko, Muchun Song, Mina Almasry,
linux-kernel, linux-mm
Subject: Re: [PATCH] hugetlb: fix hugetlb cgroup refcounting during mremap
To: Andrew Morton <akpm@linux-foundation.org>, Bui Quang Minh <minhquangbui99@gmail.com>
Cc: Miaohe Lin <linmiaohe@huawei.com>, Michal Hocko <mhocko@suse.com>, Muchun Song <songmuchun@bytedance.com>, Mina Almasry <almasrymina@google.com>, linux-kernel@vger.kernel.org, linux-mm@kvack.org
Bcc:
-=-=-=-=-=-=-=-=-=# Don't remove this line #=-=-=-=-=-=-=-=-=-
On 11/15/21 1:16 PM, Andrew Morton wrote:
> On Sat, 13 Nov 2021 22:44:10 +0700 Bui Quang Minh <minhquangbui99@gmail.com> wrote:
>
>> When hugetlb_vm_op_open() is called during copy_vma(), we may take the
>> reference to resv_map->css. Later, when clearing the reservation pointer
>> of old_vma after transferring it to new_vma, we forget to drop the
>> reference to resv_map->css. This leads to a reference leak of css.
>>
>> Fixes this by adding a check to drop reservation css reference in
>> clear_vma_resv_huge_pages()
Good catch! Sorry I missed this in my review.
Reviewed-by: Mike Kravetz <mike.kravetz@oracle.com
> Thanks. I added cc:stable to this (550a7d60bd5e35a was merged a year
> ago) and I've queued it for 5.16-rc2, pending suitable reviewer feedback.
I may be confused, but 550a7d60bd5e35a was just merged in 5.16-rc1 so
no need for cc:stable.
--
Mike Kravetz
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-11-16 0:15 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-13 15:44 [PATCH] hugetlb: fix hugetlb cgroup refcounting during mremap Bui Quang Minh
2021-11-15 21:16 ` Andrew Morton
2021-11-15 22:39 ` Mina Almasry
2021-11-15 23:25 ` Mike Kravetz
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).