From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753567AbcHPQzF (ORCPT ); Tue, 16 Aug 2016 12:55:05 -0400 Received: from mail-pf0-f180.google.com ([209.85.192.180]:34430 "EHLO mail-pf0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750749AbcHPQzD (ORCPT ); Tue, 16 Aug 2016 12:55:03 -0400 Date: Tue, 16 Aug 2016 09:55:00 -0700 From: Brenden Blanco To: Oleg Nesterov Cc: Johannes Weiner , Michal Hocko , Vladimir Davydov , linux-kernel@vger.kernel.org, Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Alexander Shishkin , Alexei Starovoitov Subject: Re: uprobes: memory leak in enable/disable loop Message-ID: <20160816165459.GA6687@gmail.com> References: <20160815205810.GA22619@gmail.com> <20160816141350.GA17006@redhat.com> <20160816142511.GB17006@redhat.com> <20160816143407.GC17006@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20160816143407.GC17006@redhat.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 16, 2016 at 04:34:08PM +0200, Oleg Nesterov wrote: > On 08/16, Oleg Nesterov wrote: > > > > On 08/16, Oleg Nesterov wrote: > > > > > > On 08/15, Brenden Blanco wrote: > > > > > > > > Hi folks, > > > > > > > > I think I have come across a memory leak in uprobes, which is fairly easy to > > > > reproduce. > > > > > > At first glance this looks as a problem in memcg, add CC's... > > > > > > put_page(old_page) looks properly balanced, and I assume we do not need > > > the additional "uncharge", we can rely on __page_cache_release(). > > > > > > And I do not see any leak if I try to reproduce with CONFIG_MEMCG=n. > > > > Heh. it seems that mem_cgroup_*() logic was always wrong in __replace_page(). > > Yes, it seems this was broken by 00501b53 "mm: memcontrol: rewrite charge API". > > > Could you try the patch below? > > Please see v2 below. We don't need "cancel_charge" under "unlock:" at all. > > Johannes, could you review? > > Oleg. > --- > --- x/kernel/events/uprobes.c > +++ x/kernel/events/uprobes.c > @@ -172,8 +172,10 @@ static int __replace_page(struct vm_area > mmu_notifier_invalidate_range_start(mm, mmun_start, mmun_end); > err = -EAGAIN; > ptep = page_check_address(page, mm, addr, &ptl, 0); > - if (!ptep) > + if (!ptep) { > + mem_cgroup_cancel_charge(kpage, memcg, false); > goto unlock; > + } > > get_page(kpage); > page_add_new_anon_rmap(kpage, vma, addr, false); > @@ -200,7 +202,6 @@ static int __replace_page(struct vm_area > > err = 0; > unlock: > - mem_cgroup_cancel_charge(kpage, memcg, false); > mmu_notifier_invalidate_range_end(mm, mmun_start, mmun_end); > unlock_page(page); > return err; > This passes my tests, thanks! Please note that I applied this to 4.4.15+ubuntu-patches kernel, since that was what I had most handy, therefore I had to adjust the patch to remove the unavailable 'compound' bool parameter in 4.4 kernels.