Received: by 2002:a25:5b86:0:0:0:0:0 with SMTP id p128csp860821ybb; Thu, 28 Mar 2019 13:44:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqxO2Lilt8cUYPI6dC/JWjL1U8ZcYOQZD6qXO05bQ/96UugIBDtIIZYtmcj540+vAQcKsyz5 X-Received: by 2002:a63:3188:: with SMTP id x130mr40664626pgx.64.1553805857156; Thu, 28 Mar 2019 13:44:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553805857; cv=none; d=google.com; s=arc-20160816; b=YIdp2i62BxCWm8VPgByUKkTVbntQxHaC6pDuLuvO8fSAcYkSTPxecERhQ9YsyBzA9z y8TwunSkTbuOeq7QCM6J1XQmC3QZrNhTjc37STxOKTQGDUbrE5at3MJtYSpuNrXIg1uA s6cyt9TnOiW1hSb5W0wN3nDlISRssNAncpRnFiRpS0QMiwfBR1Cgas8zu/KRPfTWv3x9 aCmeJ1WUEe2eI7bHKIYskAKjAC7wSNn+72SN+R98Eku4q0WHgUFnlL+Ifgo2UKeXsNmj clz3zU+n0kjxNV66OB6P7MGrMwDx8DeOwZUtd/Q8Y3vux9KBMyNrFcFk2ZEm9jMh+ebA myrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:dkim-signature:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=BWTZDuw9Jf4+5EuJDB2gXJbAkQHyJFX7dIq0NX94hfY=; b=x0kDwIW2K5+rJo1YwDZSBfwXHE+maIlA1h7hikOqUQCZSKmHx/XexeqJX4KomWq6qX vD1JkfKPizq5LVtDUB/l3KurrV/Xdn3BSP96MHf+Yiv+rHOn/uRM/DAq4DufkN2WmeP0 cWwTjeZ9/At9VmyjKlnhvWUiKSZBQVHf50qMRzhszc1GkKZwnbKmnrkX4x4jk1rlVQH7 PufXLCPwEFX62UYW0KU/9FXffXYbSnVCKvoWYGOXXLskJY8KZjRV/mmIpxXvswBp5/hN YLVoVlFY05XIjqT+QGIHqkoHtH2N8YjdA4RloPnwtar5XpVPsK8oMUBLoWClXstmkFzy JMYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b="T/vcYOjj"; 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=NONE dis=NONE) header.from=nvidia.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j1si11105pfa.138.2019.03.28.13.44.00; Thu, 28 Mar 2019 13:44:17 -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=@nvidia.com header.s=n1 header.b="T/vcYOjj"; 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=NONE dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727183AbfC1UnQ (ORCPT + 99 others); Thu, 28 Mar 2019 16:43:16 -0400 Received: from hqemgate15.nvidia.com ([216.228.121.64]:3270 "EHLO hqemgate15.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726100AbfC1UnQ (ORCPT ); Thu, 28 Mar 2019 16:43:16 -0400 Received: from hqpgpgate102.nvidia.com (Not Verified[216.228.121.13]) by hqemgate15.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Thu, 28 Mar 2019 13:43:07 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate102.nvidia.com (PGP Universal service); Thu, 28 Mar 2019 13:43:13 -0700 X-PGP-Universal: processed; by hqpgpgate102.nvidia.com on Thu, 28 Mar 2019 13:43:13 -0700 Received: from [10.110.48.28] (10.124.1.5) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Thu, 28 Mar 2019 20:43:13 +0000 Subject: Re: [PATCH v2 02/11] mm/hmm: use reference counting for HMM struct v2 To: Jerome Glisse , Ira Weiny CC: , , Andrew Morton , Dan Williams References: <20190325144011.10560-1-jglisse@redhat.com> <20190325144011.10560-3-jglisse@redhat.com> <20190328110719.GA31324@iweiny-DESK2.sc.intel.com> <20190328191122.GA5740@redhat.com> From: John Hubbard X-Nvconfidentiality: public Message-ID: Date: Thu, 28 Mar 2019 13:43:13 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.3 MIME-Version: 1.0 In-Reply-To: <20190328191122.GA5740@redhat.com> X-Originating-IP: [10.124.1.5] X-ClientProxiedBy: HQMAIL108.nvidia.com (172.18.146.13) To HQMAIL101.nvidia.com (172.20.187.10) Content-Type: text/plain; charset="utf-8" Content-Language: en-US-large Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1553805787; bh=BWTZDuw9Jf4+5EuJDB2gXJbAkQHyJFX7dIq0NX94hfY=; h=X-PGP-Universal:Subject:To:CC:References:From:X-Nvconfidentiality: Message-ID:Date:User-Agent:MIME-Version:In-Reply-To: X-Originating-IP:X-ClientProxiedBy:Content-Type:Content-Language: Content-Transfer-Encoding; b=T/vcYOjjkqOeh+Fz56ku6rzMa1BCA3/mqrpXbOWH6QkV+b9Hqfr7h16DzJL+azPDg J3OaHYyKzqZHXwRfbMo9R2hSAn/ZAeB848Qy//zRHMQXXg2ut7CKZWcpFZZaaF/xte xGnbgwiGbCruOLTpz2cpP4iQD7MxFFlwlSEKB0ZOpHQirFl1LlP7UCPrx23PJ5bZoX szbDTkVIbjcUReAiZBPgQnxBu0jUpAsIailolyBlmAG9qVe0OxoTX2wNiTy0I85yuU vvC0MNnxePtyy+vOq5l9TVRIUEE7K5wYH1B5L6bhhccRpB6wSKlQLZWkNAx2giKgRJ ohhus6ZW7lFfQ== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 3/28/19 12:11 PM, Jerome Glisse wrote: > 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=C3=A9r=C3=B4me 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=C3=A9r=C3=B4me 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; >>> }; >>> =20 >>> +static inline struct hmm *mm_get_hmm(struct mm_struct *mm) >>> +{ >>> + struct hmm *hmm =3D 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 =3D READ_ONCE(mm->hmm); >>> + struct hmm *hmm =3D mm_get_hmm(mm); >> >> FWIW: having hmm_register =3D=3D "hmm get" is a bit confusing... >=20 > 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. >=20 > Also this is all internal to HMM code and so it should not confuse > anyone. >=20 Well, it has repeatedly come up, and I'd claim that it is quite=20 counter-intuitive. So if there is an easy way to make this internal=20 HMM code clearer or better named, I would really love that to happen. And we shouldn't ever dismiss feedback based on "this is just internal xxx subsystem code, no need for it to be as clear as other parts of the kernel", right? thanks, --=20 John Hubbard NVIDIA