Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3733420yba; Tue, 7 May 2019 06:18:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqx1TpM1/fVxk7jvYt8TmRVEuKF3ZYw2qC05ie28Q+4WU68goQ1s6r05wQRn8WVSxo05sNJ4 X-Received: by 2002:a17:902:b407:: with SMTP id x7mr11661958plr.28.1557235116801; Tue, 07 May 2019 06:18:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557235116; cv=none; d=google.com; s=arc-20160816; b=qVe0oM1ZB+C3dETQ3ParNFwA1IU8PBajIYNqwCpbzTZ4FqtrP++LXxf5gAqD6cIPik 8wZWSq8vkjk1qZCdPACzXgDaFMMjUfK1ixUX+Ly6PgdDRD5byqv7MAlMP4ImMFCczGIm 2fIrCNeCi866dCoxVRWQB4IZm3Trs5kOkqzxAaLD1uDg5jA0HC81hwclaDv1t+t5/WNB XwZKwWom5yUkWx7bPKThM71T9oVjxm6gcL2M9L37nIyRrstEy/+K5/Lhuc26BMAPGYbn 2Y/uGlRHFQr2TXMS3lPSp2tYXf5IYZl4VoO++5beN+w/X4IJIJ44bN+4WXVJOip0uPi9 PEVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=MHPIqM7JCox7474Ql+xv/9Bn+cArjwrigJpmZBOlFYc=; b=PPFS6vJEWIfaahl/DPGIIBwNQAM/fKZF9en65ji92xbH69VM+++i6VNCaJqOO8ko/L bp+XioNH9bqysBpmRnQsdLS1tMlaKG9PHe+0GYyJOC/lrUnXFIvMOCLoe/iBpQQbcLUR O9xUkr6cvjEUhmfbaWJkuso4PDLZVOIBb979/2oDKmakFpwVBbXwHHdXkMP2naknMlZN 413roRC4uJfx20HtEBEfSXkE1OO5ftXzs1wFre2fkkoJzCfbwujc7rIrpW4T03p1/ghs QfKBLtJoSk4z7Cc7/+RrtICmji5GPamYMIbZAtH6zgoprVAQrDd4HwKF745fEems0cQS 1TRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Cm6wvAFw; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t5si18333130plq.83.2019.05.07.06.18.20; Tue, 07 May 2019 06:18:36 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Cm6wvAFw; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726591AbfEGNQK (ORCPT + 99 others); Tue, 7 May 2019 09:16:10 -0400 Received: from mail-lf1-f67.google.com ([209.85.167.67]:45699 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726321AbfEGNQI (ORCPT ); Tue, 7 May 2019 09:16:08 -0400 Received: by mail-lf1-f67.google.com with SMTP id n22so4279362lfe.12 for ; Tue, 07 May 2019 06:16:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=MHPIqM7JCox7474Ql+xv/9Bn+cArjwrigJpmZBOlFYc=; b=Cm6wvAFwgAxp/8D3CkSsBcbPu7kiNDKTuOPOjj7VgZexU4R3MuQVhAtBWxto2J3mkD R5ilpzaX5NiHw5RM65X5ZS2DkJuQA7x+/Hp5Bj/Y3EJ5iS12D5vswADthPKpU8JlQtX/ +evJAeTS11J4tIUcoXBhWnOD404ANf2KNSE50/ynuFzUReJkCdsj0p72urrf5GyApTod 1p2j+DBuZtLzo0G3wpB9Dkn+us74hciQr/9q9l5MhPPR2rrRwHq9GwCHiN/OIhTB42lF ekO9nOGnT2bD3xS7Fw5XfrJwzz1km3w0uXrPLjHG4I5LqG9YqonzZlEzFrqkL70EWiIs Jacw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=MHPIqM7JCox7474Ql+xv/9Bn+cArjwrigJpmZBOlFYc=; b=HVPeJRg37klOqtxVXkacZipoPzft82rKy23i8lXTXC13aU/C7my8av+j3MvxI7B53H i0xxshV59IiB6/0FNF4fB3ayrivHa2161Rcua5vf4S+tqUHT26fQpeWuH+x6+zxy304d hM6YEr/6Q8rQ7WNoEZYSLv7bggj55N4LupBA0TwFIdxLb9a2/DjRRCoD2nk17QwqcIVt ZqVmzThs3rJEe4+XqH1H+Y2p328exNaR0XS1oLfK+Z6p3KTY6yjRY454MBO8YVHOIyv6 C8HQYaYSa/Y8KagEZgoX6+AUNY7Upg/kz9rChcU9sAmOeUtiTt3zOxOl+UihujiBAjxT bLPA== X-Gm-Message-State: APjAAAXbPzoCd54TginzYzlj6ekY52MUxYP68yJ/VOGAhpPqM/Zb98F/ Exr7X1MqCQ6qeWXTQotQOidS1PfdqMZSM4iBPvI= X-Received: by 2002:ac2:5495:: with SMTP id t21mr16592698lfk.3.1557234966713; Tue, 07 May 2019 06:16:06 -0700 (PDT) MIME-Version: 1.0 References: <20190506232942.12623-1-rcampbell@nvidia.com> <20190506232942.12623-5-rcampbell@nvidia.com> In-Reply-To: <20190506232942.12623-5-rcampbell@nvidia.com> From: Souptick Joarder Date: Tue, 7 May 2019 18:45:54 +0530 Message-ID: Subject: Re: [PATCH 4/5] mm/hmm: hmm_vma_fault() doesn't always call hmm_range_unregister() To: Ralph Campbell Cc: Linux-MM , linux-kernel@vger.kernel.org, John Hubbard , Ira Weiny , Dan Williams , Arnd Bergmann , Balbir Singh , Dan Carpenter , Matthew Wilcox , Andrew Morton Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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* ? > > 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 ? > if (ret == -EBUSY || !ret) { > /* Same as above, drop mmap_sem to match old API. */ > up_read(&range->vma->vm_mm->mmap_sem); > ret = -EBUSY; > } else if (ret == -EAGAIN) > ret = -EBUSY; > - hmm_range_unregister(range); > return ret; > } > return 0; > -- > 2.20.1 >