Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4238988yba; Sun, 12 May 2019 08:09:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqwDqyLF2bZOYcIc8iuuMsQPNFjjlBv6HnoWkkTvqwLLAUuXKre8d9oj2hwv1e9QZKssS8NX X-Received: by 2002:a63:d0e:: with SMTP id c14mr26365201pgl.345.1557673755639; Sun, 12 May 2019 08:09:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557673755; cv=none; d=google.com; s=arc-20160816; b=giI1611302m8f75nJZsd22RxNJF8Z3cVTxjnWfqlW9xWcL5UvqNwn6fLtC2AYbMs6m 0kzj34qUGoYgcCvZi/UHqmpyKF3T1U28uVBM+ZY7qZyXJoEUVjgsPfgnaUyOiKN8XCT6 zAcIqak6eo/IpbHNenXTg/Pa9MDG0zwZCnfzcLb/kgNL8CYgbiEgfPMKWZt21kgVfmGq zz2QUIGJ19KTA+nZh9pYMAIhNAEXIVlCi7/8Sp2iG630pft9NIHcCMPtSBR7jZYayrCH OevqNtNH0MpRiJoeWiXENbIlD/eWN3EEqL3yFKsyE9nxlD6ASiEfLW1jHmj1F/bjVq4i Lo2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=esV7ZquD2TFM89nJy4yZbNRteT7gRam6/wb6pcqQV+o=; b=VYDIRYXK9ROtlRWPVUFV1KnKUMkCmErJpRaU8d6+SH9OCm0iipRhjoRgy9AltyOsXz wIan/bDc5selmCrqjPFtjwq9dI/vMgJpDUUTn1LqV/v4qxy6ROu61UoA0ShnSWrz4tfW 6ecQ0dqDLgYHb6xzRp5DMDbXwRqAP0J/8qjuDxDmlqVeCMsl8+9IexGgXqgER+Yuikgo NR3vaW8sAORQ57wcwtQqkzxDcTEteVglJGCO4dO40vfeNJnjuO01+wO01LjgPmJXU3NP IQL2+gJfhqcu3zHQGkBLbZV7oRI7L3ax7GG4wLMvdjyM1T/JkoAOuN031n3ARC9iSH9W IoXQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 68si13905578pga.147.2019.05.12.08.08.47; Sun, 12 May 2019 08:09:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726660AbfELPH3 (ORCPT + 99 others); Sun, 12 May 2019 11:07:29 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41406 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726478AbfELPH3 (ORCPT ); Sun, 12 May 2019 11:07:29 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 66B913086275; Sun, 12 May 2019 15:07:28 +0000 (UTC) Received: from redhat.com (ovpn-120-196.rdu2.redhat.com [10.10.120.196]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 84A3860C47; Sun, 12 May 2019 15:07:26 +0000 (UTC) Date: Sun, 12 May 2019 11:07:24 -0400 From: Jerome Glisse To: Ralph Campbell Cc: Souptick Joarder , Linux-MM , linux-kernel@vger.kernel.org, John Hubbard , Ira Weiny , Dan Williams , Arnd Bergmann , Balbir Singh , Dan Carpenter , Matthew Wilcox , Andrew Morton Subject: Re: [PATCH 4/5] mm/hmm: hmm_vma_fault() doesn't always call hmm_range_unregister() Message-ID: <20190512150724.GA4238@redhat.com> References: <20190506232942.12623-1-rcampbell@nvidia.com> <20190506232942.12623-5-rcampbell@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.11.4 (2019-03-13) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Sun, 12 May 2019 15:07:28 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 07, 2019 at 11:12:14AM -0700, Ralph Campbell wrote: > > On 5/7/19 6:15 AM, Souptick Joarder wrote: > > On Tue, May 7, 2019 at 5:00 AM wrote: > > > > > > From: Ralph Campbell > > > > > > The helper function hmm_vma_fault() calls hmm_range_register() but is > > > missing a call to hmm_range_unregister() in one of the error paths. > > > This leads to a reference count leak and ultimately a memory leak on > > > struct hmm. > > > > > > Always call hmm_range_unregister() if hmm_range_register() succeeded. > > > > How about * Call hmm_range_unregister() in error path if > > hmm_range_register() succeeded* ? > > Sure, sounds good. > I'll include that in v2. NAK for the patch see below why > > > > > > > Signed-off-by: Ralph Campbell > > > Cc: John Hubbard > > > Cc: Ira Weiny > > > Cc: Dan Williams > > > Cc: Arnd Bergmann > > > Cc: Balbir Singh > > > Cc: Dan Carpenter > > > Cc: Matthew Wilcox > > > Cc: Souptick Joarder > > > Cc: Andrew Morton > > > --- > > > include/linux/hmm.h | 3 ++- > > > 1 file changed, 2 insertions(+), 1 deletion(-) > > > > > > diff --git a/include/linux/hmm.h b/include/linux/hmm.h > > > index 35a429621e1e..fa0671d67269 100644 > > > --- a/include/linux/hmm.h > > > +++ b/include/linux/hmm.h > > > @@ -559,6 +559,7 @@ static inline int hmm_vma_fault(struct hmm_range *range, bool block) > > > return (int)ret; > > > > > > if (!hmm_range_wait_until_valid(range, HMM_RANGE_DEFAULT_TIMEOUT)) { > > > + hmm_range_unregister(range); > > > /* > > > * The mmap_sem was taken by driver we release it here and > > > * returns -EAGAIN which correspond to mmap_sem have been > > > @@ -570,13 +571,13 @@ static inline int hmm_vma_fault(struct hmm_range *range, bool block) > > > > > > ret = hmm_range_fault(range, block); > > > if (ret <= 0) { > > > + hmm_range_unregister(range); > > > > what is the reason to moved it up ? > > I moved it up because the normal calling pattern is: > down_read(&mm->mmap_sem) > hmm_vma_fault() > hmm_range_register() > hmm_range_fault() > hmm_range_unregister() > up_read(&mm->mmap_sem) > > I don't think it is a bug to unlock mmap_sem and then unregister, > it is just more consistent nesting. So this is not the usage pattern with HMM usage pattern is: hmm_range_register() hmm_range_fault() hmm_range_unregister() The hmm_vma_fault() is gonne so this patch here break thing. See https://cgit.freedesktop.org/~glisse/linux/log/?h=hmm-5.2-v3