Received: by 2002:a25:5b86:0:0:0:0:0 with SMTP id p128csp915097ybb; Thu, 28 Mar 2019 15:01:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqz6AJPFmYeZE2BzV2Q0rTs5Q06LKZ6WjLsTIbVoUq+98Nr4ttNTRilln3hJAXkfSiV0XcrE X-Received: by 2002:a17:902:5a2:: with SMTP id f31mr45034956plf.119.1553810465808; Thu, 28 Mar 2019 15:01:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553810465; cv=none; d=google.com; s=arc-20160816; b=mEYjlpn46r2vq34aC4jrgX1SWf+I9mvcJiNXYpAM8HmVbAFOvsGzEZs9gfSVMvOEPz 1Pb+aFzo5v6oPlTsSo8rBPFBkWjonh2QC2j26SHdVreqq8rwb2ZF+yIepDn38JxYUXHY FR7fdFy9r7pmjD8tVo0ezc8OeSPcff5bI2rnhSXPEYPi+JCJeMC6jTpA2ffQxPZ7pjom 5buoPyOo5R3/YpQpFklUyJuz2xYyrK2SKxUAmw1xD+tS0EYJG6bGJ20vHZBno6x6x8vc tVW5I2GmHch/ZUF3yErB1OXU8jzuOxYsPA8S7I7UUf8LFNXaXr3y+12+3nvZrjymZCZb DPLw== 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=NNa4/s5RLr8tBsJiCFnRZr38vKbxE2ngsDs1pGWjIlg=; b=HxoyyQQ5K1ntUqZfPS694oqUcls6Tpz+3mO3GmJQBAuowkVUvwna0A0q+p1Uij3el8 3bcjb9Rumm6r6R7+xwRwEM4vO54Etob5hWCJxIWMh4h0qoPrhGWgQzyHoynBZUm4ILtg YvwHm3ksqeFzrWnmq+GtW6Cv2TK3SqSICX/eGEo+SKXxwa8nPVSuDrbWMgc+LHW05fqg jlWPVIECUod/54HwyE3+TRL48DIXSeWGo7nzFUGccJw0LkL72mHptOPtXXqEDCSdfExJ UVX2yKcgE/yuK0y6SMTeTJfYtK7/uRWJ56F3cUtpWwkd5wbPdVy7ChwurC80bxJmYLkj nUOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=cI2sZWCF; 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 i67si158543pfb.117.2019.03.28.15.00.50; Thu, 28 Mar 2019 15:01:05 -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=cI2sZWCF; 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 S1728048AbfC1V7x (ORCPT + 99 others); Thu, 28 Mar 2019 17:59:53 -0400 Received: from hqemgate14.nvidia.com ([216.228.121.143]:2887 "EHLO hqemgate14.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728025AbfC1V7w (ORCPT ); Thu, 28 Mar 2019 17:59:52 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqemgate14.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Thu, 28 Mar 2019 14:59:54 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Thu, 28 Mar 2019 14:59:51 -0700 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Thu, 28 Mar 2019 14:59:51 -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 21:59:50 +0000 Subject: Re: [PATCH v2 07/11] mm/hmm: add default fault flags to avoid the need to pre-fill pfns arrays. To: , CC: , Andrew Morton , Dan Williams References: <20190325144011.10560-1-jglisse@redhat.com> <20190325144011.10560-8-jglisse@redhat.com> From: John Hubbard X-Nvconfidentiality: public Message-ID: <2f790427-ea87-b41e-b386-820ccdb7dd38@nvidia.com> Date: Thu, 28 Mar 2019 14:59:50 -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: <20190325144011.10560-8-jglisse@redhat.com> X-Originating-IP: [10.124.1.5] X-ClientProxiedBy: HQMAIL101.nvidia.com (172.20.187.10) 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=1553810394; bh=NNa4/s5RLr8tBsJiCFnRZr38vKbxE2ngsDs1pGWjIlg=; 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=cI2sZWCF4+YGKEOgcJkUT3mkH1Jc5Nyt+uoIoHzVIKMZ4xb84m+F0wvL7eWW4AybC E+Vg/fKOCOUCvOAIJsRZ4ErgncGzMlC4u0jqjZp0taoiagLD5dYx50WQgPKPAnC28b QiGx+5vZR9MOoN+7h/XvFW4FmcXRjCfYsBhGVNBJOmlAH3C7HhXzNoQ+Xg0a9meoQV eugVY37iCwti5sciGjkF61tSPNzB5sPl+jwniGxrDQpPz7NgDvTixOMm5YRor1i2Yj +GmAoB0UZisLt5CmuBDnHKjX0VwzTgL8Mj+b0IiV5zm6jNRlQdR3dC8dggn2POgmT3 Qs3LP9FdDaQDg== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 3/25/19 7:40 AM, jglisse@redhat.com wrote: > From: J=C3=A9r=C3=B4me Glisse >=20 > The HMM mirror API can be use in two fashions. The first one where the HM= M > user coalesce multiple page faults into one request and set flags per pfn= s > for of those faults. The second one where the HMM user want to pre-fault = a > range with specific flags. For the latter one it is a waste to have the u= ser > pre-fill the pfn arrays with a default flags value. >=20 > This patch adds a default flags value allowing user to set them for a ran= ge > without having to pre-fill the pfn array. >=20 > Signed-off-by: J=C3=A9r=C3=B4me Glisse > Reviewed-by: Ralph Campbell > Cc: Andrew Morton > Cc: John Hubbard > Cc: Dan Williams > --- > include/linux/hmm.h | 7 +++++++ > mm/hmm.c | 12 ++++++++++++ > 2 files changed, 19 insertions(+) >=20 > diff --git a/include/linux/hmm.h b/include/linux/hmm.h > index 79671036cb5f..13bc2c72f791 100644 > --- a/include/linux/hmm.h > +++ b/include/linux/hmm.h > @@ -165,6 +165,8 @@ enum hmm_pfn_value_e { > * @pfns: array of pfns (big enough for the range) > * @flags: pfn flags to match device driver page table > * @values: pfn value for some special case (none, special, error, ...) > + * @default_flags: default flags for the range (write, read, ...) > + * @pfn_flags_mask: allows to mask pfn flags so that only default_flags = matter > * @pfn_shifts: pfn shift value (should be <=3D PAGE_SHIFT) > * @valid: pfns array did not change since it has been fill by an HMM fu= nction > */ > @@ -177,6 +179,8 @@ struct hmm_range { > uint64_t *pfns; > const uint64_t *flags; > const uint64_t *values; > + uint64_t default_flags; > + uint64_t pfn_flags_mask; > uint8_t pfn_shift; > bool valid; > }; > @@ -521,6 +525,9 @@ static inline int hmm_vma_fault(struct hmm_range *ran= ge, bool block) > { > long ret; > =20 > + range->default_flags =3D 0; > + range->pfn_flags_mask =3D -1UL; Hi Jerome, This is nice to have. Let's constrain it a little bit more, though: the pfn= _flags_mask definitely does not need to be a run time value. And we want some assurance= that the mask is=20 a) large enough for the flags, and b) small enough to avoid overrunning the pfns field. Those are less certain with a run-time struct field, and more obviously cor= rect with something like, approximately: #define PFN_FLAGS_MASK 0xFFFF or something. In other words, this is more flexibility than we need--just a touch too muc= h, IMHO. > + > ret =3D hmm_range_register(range, range->vma->vm_mm, > range->start, range->end); > if (ret) > diff --git a/mm/hmm.c b/mm/hmm.c > index fa9498eeb9b6..4fe88a196d17 100644 > --- a/mm/hmm.c > +++ b/mm/hmm.c > @@ -415,6 +415,18 @@ static inline void hmm_pte_need_fault(const struct h= mm_vma_walk *hmm_vma_walk, > if (!hmm_vma_walk->fault) > return; > =20 > + /* > + * So we not only consider the individual per page request we also > + * consider the default flags requested for the range. The API can > + * be use in 2 fashions. The first one where the HMM user coalesce > + * multiple page fault into one request and set flags per pfns for > + * of those faults. The second one where the HMM user want to pre- > + * fault a range with specific flags. For the latter one it is a > + * waste to have the user pre-fill the pfn arrays with a default > + * flags value. > + */ > + pfns =3D (pfns & range->pfn_flags_mask) | range->default_flags; Need to verify that the mask isn't too large or too small. > + > /* We aren't ask to do anything ... */ > if (!(pfns & range->flags[HMM_PFN_VALID])) > return; >=20 thanks, --=20 John Hubbard NVIDIA