Received: by 2002:a25:5b86:0:0:0:0:0 with SMTP id p128csp788869ybb; Thu, 28 Mar 2019 12:12:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqzbIq4+WaLolIeUYGrzP4gzNlGELAZf6kDcHep7GA9LI5AeqRN1oym4KpUZPtxVMqGUY0O1 X-Received: by 2002:a63:c23:: with SMTP id b35mr1645622pgl.298.1553800360681; Thu, 28 Mar 2019 12:12:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553800360; cv=none; d=google.com; s=arc-20160816; b=WmA9F87906unGOoPT7Kna55BX86vTtpFZ8slUYcLHvrMWxZ+2tOB9d5cEUYdTEBtaa ifOdiYhKVvXCnTP/UpvNnz5zAelxvecNRVAM/jVpSjfTrYTYqoUVOr5Lm29rI/ZIzePN UxUEdpaYTVB4r8oHF8AuFV7J7bBRk1IBEw0GaPhO24x6MrdrTIvH7TrLSYWFl4ovchKE WqoBz3BO1wGUJHwAXHiKWVmSvvzUlY56cF3H9aIQidcKU377fOBi/bW5gypivsVnh2j7 0eW2FjBekfTTYNhIFTxV+xpvA3dMEF0BBTLpCzpmxIPFCaDuL3UTqLG/sIg23ItsEcm9 aeWA== 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=hM0v6Z9vU97QJB0zhiOeTElSQxAdDvJbsTGJn9ulqzI=; b=X82FkyToHXv71e+gTbtj445f2pfoUstddmptgtlvshk8rn8UoP8Q+KyCBD5Z9VcJhT xxfsaObBgbr9dhx5Ice0fMg5kxMd80dvRg6G1Vy64bBj9qaCCdiVFYeHJ3jfcdjH42HY wVWolZ6oB1zITBQdAebxvC9t/+LsDhB3skXRmdlaz20Tfe5xVkyxey6vneCdOEO+0GjF 7C8+isT5Aamw3GPhjTqOJ9Lcg7HVLcp51MSggB4bK4p62oA5aJFObZcymRsXOuej+j7K /oNfRESBtJ9amOppJ6Y72zkLdOEGu2PzEKRXgsKhxXjG/w21oqCWjc2xZqc++jVnM1HX A+SQ== 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 l65si21593664pgl.368.2019.03.28.12.12.25; Thu, 28 Mar 2019 12:12:40 -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 S1726650AbfC1TL1 (ORCPT + 99 others); Thu, 28 Mar 2019 15:11:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43132 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726095AbfC1TLZ (ORCPT ); Thu, 28 Mar 2019 15:11:25 -0400 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 16B1C59445; Thu, 28 Mar 2019 19:11:25 +0000 (UTC) Received: from redhat.com (unknown [10.20.6.236]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 62AAE1DB; Thu, 28 Mar 2019 19:11:24 +0000 (UTC) Date: Thu, 28 Mar 2019 15:11:22 -0400 From: Jerome Glisse To: Ira Weiny Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, John Hubbard , Andrew Morton , Dan Williams Subject: Re: [PATCH v2 02/11] mm/hmm: use reference counting for HMM struct v2 Message-ID: <20190328191122.GA5740@redhat.com> References: <20190325144011.10560-1-jglisse@redhat.com> <20190325144011.10560-3-jglisse@redhat.com> <20190328110719.GA31324@iweiny-DESK2.sc.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20190328110719.GA31324@iweiny-DESK2.sc.intel.com> User-Agent: Mutt/1.11.3 (2019-02-01) 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.39]); Thu, 28 Mar 2019 19:11:25 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 28, 2019 at 04:07:20AM -0700, Ira Weiny wrote: > On Mon, Mar 25, 2019 at 10:40:02AM -0400, Jerome Glisse 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. > > > > Changes since v1: > > - removed bunch of useless check (if API is use with bogus argument > > better to fail loudly so user fix their code) > > - s/hmm_get/mm_get_hmm/ > > > > Signed-off-by: J?r?me Glisse > > Reviewed-by: Ralph Campbell > > Cc: John Hubbard > > Cc: Andrew Morton > > Cc: Dan Williams > > --- > > include/linux/hmm.h | 2 + > > mm/hmm.c | 170 ++++++++++++++++++++++++++++---------------- > > 2 files changed, 112 insertions(+), 60 deletions(-) > > > > diff --git a/include/linux/hmm.h b/include/linux/hmm.h > > index ad50b7b4f141..716fc61fa6d4 100644 > > --- a/include/linux/hmm.h > > +++ b/include/linux/hmm.h > > @@ -131,6 +131,7 @@ enum hmm_pfn_value_e { > > /* > > * struct hmm_range - track invalidation lock on virtual address range > > * > > + * @hmm: the core HMM structure this range is active against > > * @vma: the vm area struct for the range > > * @list: all range lock are on a list > > * @start: range virtual start address (inclusive) > > @@ -142,6 +143,7 @@ enum hmm_pfn_value_e { > > * @valid: pfns array did not change since it has been fill by an HMM function > > */ > > struct hmm_range { > > + struct hmm *hmm; > > struct vm_area_struct *vma; > > struct list_head list; > > unsigned long start; > > diff --git a/mm/hmm.c b/mm/hmm.c > > index fe1cd87e49ac..306e57f7cded 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 *mm_get_hmm(struct mm_struct *mm) > > +{ > > + struct hmm *hmm = READ_ONCE(mm->hmm); > > + > > + if (hmm && kref_get_unless_zero(&hmm->kref)) > > + return hmm; > > + > > + return NULL; > > +} > > + > > /* > > * hmm_register - register HMM against an mm (HMM internal) > > * > > @@ -67,14 +78,9 @@ struct hmm { > > */ > > static struct hmm *hmm_register(struct mm_struct *mm) > > { > > - struct hmm *hmm = READ_ONCE(mm->hmm); > > + struct hmm *hmm = mm_get_hmm(mm); > > FWIW: having hmm_register == "hmm get" is a bit confusing... The thing is that you want only one hmm struct per process and thus if there is already one and it is not being destroy then you want to reuse it. Also this is all internal to HMM code and so it should not confuse anyone. Cheers, J?r?me