Received: by 2002:ac0:a679:0:0:0:0:0 with SMTP id p54csp159181imp; Wed, 20 Feb 2019 16:38:17 -0800 (PST) X-Google-Smtp-Source: AHgI3IYtgHS0QfH4JtAkv2O768qH8HYXNYXCOvdRSnbGZs1uPwGB9cGSBBHp8wpH2YNlm/ylafHN X-Received: by 2002:a62:62c5:: with SMTP id w188mr37824189pfb.160.1550709497334; Wed, 20 Feb 2019 16:38:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550709497; cv=none; d=google.com; s=arc-20160816; b=FtwVg9DhHri9nMcqXPGfGgs597n6wXVkL7yaccx4I+NF/t4p9/frKrNWLTIFzf79d7 g72g9GRZ+z2VU2Y/P5CVD+DIBXZiv/aAfGrmeQXM4QVcGSiabovtkzHwliw1zOKwf0g5 yhvJgmRwdueH1S0l9Qi4VQ6J89bd6If+DB+zo2daTsHOGzxVFVUMnGgvkROXoO6Bui1i KvxgFzqfX6aPpLkDl+y/RMXUCUIFaL2jhGF0TFZpxJiwh93GRbpSeGWbG1+GpzVDWwcd SpYO2ElBP+H4aqjeMZZcJnxD/8Qem8VTDcWOGmqTrCXB8GEm71xoCF5N6thDNVJU2AHE jYDg== 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-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=2nBa+AB4OA1YDWlxbAuOxWE0aW8AnM+NeozjOtk/gzM=; b=yIPot26qW3UdpMJxfFOEaEEHEvr0/bq8mxId2yS7meBnMJXZ8ARqCM37plPYugEDOg eueagV5H2V3+ona+QcDzq0QszfYBTG84d+xdIDzAz7wGcIB8cZ3kiSmLpU+H/zIRWbIU Y2spVtwN2VEnUZy8LpxZZeEOaQn4boeGinZuc/3V6WxPm8e279Ii8nPMXcXP7DL4FMzv QJCB7Q2zg/SrzA9zCSlpeWqA5aSTsThAYFhJGOibKSWAHGnHnNCErCKQeifFync6xJlT +RU+DtNq+12EThx+QmIRbTOTC3t/bKhMaPCcgMYUeQFVyTCuQFLzvRcI/duji7Vcq3Kz 8S9A== 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 h189si3753530pge.152.2019.02.20.16.38.01; Wed, 20 Feb 2019 16:38:17 -0800 (PST) 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 S1726882AbfBUAhT (ORCPT + 99 others); Wed, 20 Feb 2019 19:37:19 -0500 Received: from mx1.redhat.com ([209.132.183.28]:60478 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726776AbfBUAhT (ORCPT ); Wed, 20 Feb 2019 19:37:19 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 47795307D90D; Thu, 21 Feb 2019 00:37:19 +0000 (UTC) Received: from redhat.com (ovpn-120-249.rdu2.redhat.com [10.10.120.249]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6B08C19C58; Thu, 21 Feb 2019 00:37:18 +0000 (UTC) Date: Wed, 20 Feb 2019 19:37:16 -0500 From: Jerome Glisse To: John Hubbard Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Ralph Campbell , Andrew Morton Subject: Re: [PATCH 01/10] mm/hmm: use reference counting for HMM struct Message-ID: <20190221003716.GD24489@redhat.com> References: <20190129165428.3931-1-jglisse@redhat.com> <20190129165428.3931-2-jglisse@redhat.com> <1373673d-721e-a7a2-166f-244c16f236a3@nvidia.com> <20190220235933.GD11325@redhat.com> <20190221001557.GA24489@redhat.com> <58ab7c36-36dd-700a-6a66-8c9abbf4076a@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <58ab7c36-36dd-700a-6a66-8c9abbf4076a@nvidia.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Thu, 21 Feb 2019 00:37:19 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 20, 2019 at 04:32:09PM -0800, John Hubbard wrote: > On 2/20/19 4:15 PM, Jerome Glisse wrote: > > On Wed, Feb 20, 2019 at 04:06:50PM -0800, John Hubbard wrote: > > > On 2/20/19 3:59 PM, Jerome Glisse wrote: > > > > On Wed, Feb 20, 2019 at 03:47:50PM -0800, John Hubbard wrote: > > > > > On 1/29/19 8:54 AM, jglisse@redhat.com wrote: > > > > > > From: J?r?me Glisse > > > > > > > > > > > > Every time i read the code to check that the HMM structure does not > > > > > > vanish before it should thanks to the many lock protecting its removal > > > > > > i get a headache. Switch to reference counting instead it is much > > > > > > easier to follow and harder to break. This also remove some code that > > > > > > is no longer needed with refcounting. > > > > > > > > > > Hi Jerome, > > > > > > > > > > That is an excellent idea. Some review comments below: > > > > > > > > > > [snip] > > > > > > > > > > > static int hmm_invalidate_range_start(struct mmu_notifier *mn, > > > > > > const struct mmu_notifier_range *range) > > > > > > { > > > > > > struct hmm_update update; > > > > > > - struct hmm *hmm = range->mm->hmm; > > > > > > + struct hmm *hmm = hmm_get(range->mm); > > > > > > + int ret; > > > > > > VM_BUG_ON(!hmm); > > > > > > + /* Check if hmm_mm_destroy() was call. */ > > > > > > + if (hmm->mm == NULL) > > > > > > + return 0; > > > > > > > > > > Let's delete that NULL check. It can't provide true protection. If there > > > > > is a way for that to race, we need to take another look at refcounting. > > > > > > > > I will do a patch to delete the NULL check so that it is easier for > > > > Andrew. No need to respin. > > > > > > (Did you miss my request to make hmm_get/hmm_put symmetric, though?) > > > > Went over my mail i do not see anything about symmetric, what do you > > mean ? > > > > Cheers, > > J?r?me > > I meant the comment that I accidentally deleted, before sending the email! > doh. Sorry about that. :) Here is the recreated comment: > > diff --git a/mm/hmm.c b/mm/hmm.c > index a04e4b810610..b9f384ea15e9 100644 > > --- a/mm/hmm.c > > +++ b/mm/hmm.c > > @@ -50,6 +50,7 @@ > > static const struct mmu_notifier_ops hmm_mmu_notifier_ops; > > */ > struct hmm { > struct mm_struct *mm; > + struct kref kref; > spinlock_t lock; > struct list_head ranges; > struct list_head mirrors; > > @@ -57,6 +58,16 @@ > > struct hmm { > > struct rw_semaphore mirrors_sem; > }; > > +static inline struct hmm *hmm_get(struct mm_struct *mm) > +{ > + struct hmm *hmm = READ_ONCE(mm->hmm); > + > + if (hmm && kref_get_unless_zero(&hmm->kref)) > + return hmm; > + > + return NULL; > +} > + > > So for this, hmm_get() really ought to be symmetric with > hmm_put(), by taking a struct hmm*. And the null check is > not helping here, so let's just go with this smaller version: > > static inline struct hmm *hmm_get(struct hmm *hmm) > { > if (kref_get_unless_zero(&hmm->kref)) > return hmm; > > return NULL; > } > > ...and change the few callers accordingly. > What about renaning hmm_get() to mm_get_hmm() instead ? Cheers, J?r?me