From: Michal Hocko <mhocko@kernel.org> To: Kirill Tkhai <ktkhai@virtuozzo.com> Cc: akpm@linux-foundation.org, aarcange@redhat.com, minchan@kernel.org, zhongjiang@huawei.com, mingo@kernel.org, imbrenda@linux.vnet.ibm.com, kirill.shutemov@linux.intel.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Hugh Dickins <hughd@google.com> Subject: Re: [PATCH] ksm: Fix unlocked iteration over vmas in cmp_and_merge_page() Date: Wed, 13 Sep 2017 13:25:09 +0200 [thread overview] Message-ID: <20170913112509.mus2fuccajoe2l25@dhcp22.suse.cz> (raw) In-Reply-To: <150512788393.10691.8868381099691121308.stgit@localhost.localdomain> [CC Claudio and Hugh] On Mon 11-09-17 14:05:05, Kirill Tkhai wrote: > In this place mm is unlocked, so vmas or list may change. > Down read mmap_sem to protect them from modifications. > > Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com> > (and compile-tested-by) Fixes: e86c59b1b12d ("mm/ksm: improve deduplication of zero pages with colouring") AFAICS. Maybe even CC: stable as unstable vma can cause large variety of issues including memory corruption. The fix lookds good to me Acked-by: Michal Hocko <mhocko@suse.com> > --- > mm/ksm.c | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/mm/ksm.c b/mm/ksm.c > index db20f8436bc3..86f0db3d6cdb 100644 > --- a/mm/ksm.c > +++ b/mm/ksm.c > @@ -1990,6 +1990,7 @@ static void stable_tree_append(struct rmap_item *rmap_item, > */ > static void cmp_and_merge_page(struct page *page, struct rmap_item *rmap_item) > { > + struct mm_struct *mm = rmap_item->mm; > struct rmap_item *tree_rmap_item; > struct page *tree_page = NULL; > struct stable_node *stable_node; > @@ -2062,9 +2063,11 @@ static void cmp_and_merge_page(struct page *page, struct rmap_item *rmap_item) > if (ksm_use_zero_pages && (checksum == zero_checksum)) { > struct vm_area_struct *vma; > > - vma = find_mergeable_vma(rmap_item->mm, rmap_item->address); > + down_read(&mm->mmap_sem); > + vma = find_mergeable_vma(mm, rmap_item->address); > err = try_to_merge_one_page(vma, page, > ZERO_PAGE(rmap_item->address)); > + up_read(&mm->mmap_sem); > /* > * In case of failure, the page was not really empty, so we > * need to continue. Otherwise we're done. > -- Michal Hocko SUSE Labs
WARNING: multiple messages have this Message-ID (diff)
From: Michal Hocko <mhocko@kernel.org> To: Kirill Tkhai <ktkhai@virtuozzo.com> Cc: akpm@linux-foundation.org, aarcange@redhat.com, minchan@kernel.org, zhongjiang@huawei.com, mingo@kernel.org, imbrenda@linux.vnet.ibm.com, kirill.shutemov@linux.intel.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Hugh Dickins <hughd@google.com> Subject: Re: [PATCH] ksm: Fix unlocked iteration over vmas in cmp_and_merge_page() Date: Wed, 13 Sep 2017 13:25:09 +0200 [thread overview] Message-ID: <20170913112509.mus2fuccajoe2l25@dhcp22.suse.cz> (raw) In-Reply-To: <150512788393.10691.8868381099691121308.stgit@localhost.localdomain> [CC Claudio and Hugh] On Mon 11-09-17 14:05:05, Kirill Tkhai wrote: > In this place mm is unlocked, so vmas or list may change. > Down read mmap_sem to protect them from modifications. > > Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com> > (and compile-tested-by) Fixes: e86c59b1b12d ("mm/ksm: improve deduplication of zero pages with colouring") AFAICS. Maybe even CC: stable as unstable vma can cause large variety of issues including memory corruption. The fix lookds good to me Acked-by: Michal Hocko <mhocko@suse.com> > --- > mm/ksm.c | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/mm/ksm.c b/mm/ksm.c > index db20f8436bc3..86f0db3d6cdb 100644 > --- a/mm/ksm.c > +++ b/mm/ksm.c > @@ -1990,6 +1990,7 @@ static void stable_tree_append(struct rmap_item *rmap_item, > */ > static void cmp_and_merge_page(struct page *page, struct rmap_item *rmap_item) > { > + struct mm_struct *mm = rmap_item->mm; > struct rmap_item *tree_rmap_item; > struct page *tree_page = NULL; > struct stable_node *stable_node; > @@ -2062,9 +2063,11 @@ static void cmp_and_merge_page(struct page *page, struct rmap_item *rmap_item) > if (ksm_use_zero_pages && (checksum == zero_checksum)) { > struct vm_area_struct *vma; > > - vma = find_mergeable_vma(rmap_item->mm, rmap_item->address); > + down_read(&mm->mmap_sem); > + vma = find_mergeable_vma(mm, rmap_item->address); > err = try_to_merge_one_page(vma, page, > ZERO_PAGE(rmap_item->address)); > + up_read(&mm->mmap_sem); > /* > * In case of failure, the page was not really empty, so we > * need to continue. Otherwise we're done. > -- Michal Hocko SUSE Labs -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2017-09-13 11:25 UTC|newest] Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top 2017-09-11 11:05 [PATCH] ksm: Fix unlocked iteration over vmas in cmp_and_merge_page() Kirill Tkhai 2017-09-11 11:05 ` Kirill Tkhai 2017-09-13 11:25 ` Michal Hocko [this message] 2017-09-13 11:25 ` Michal Hocko 2017-09-13 13:46 ` Andrea Arcangeli 2017-09-13 13:46 ` Andrea Arcangeli
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20170913112509.mus2fuccajoe2l25@dhcp22.suse.cz \ --to=mhocko@kernel.org \ --cc=aarcange@redhat.com \ --cc=akpm@linux-foundation.org \ --cc=hughd@google.com \ --cc=imbrenda@linux.vnet.ibm.com \ --cc=kirill.shutemov@linux.intel.com \ --cc=ktkhai@virtuozzo.com \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-mm@kvack.org \ --cc=minchan@kernel.org \ --cc=mingo@kernel.org \ --cc=zhongjiang@huawei.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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.