Received: by 2002:a25:5b86:0:0:0:0:0 with SMTP id p128csp925814ybb; Thu, 28 Mar 2019 15:14:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqzEIkA13Xkk4dgn1A3xbaTLjYMfGMyPbFftMsIoz1iGbwMxSSldYdKSqRCX5u5vt0XKDKUd X-Received: by 2002:a17:902:248:: with SMTP id 66mr46272977plc.286.1553811265691; Thu, 28 Mar 2019 15:14:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553811265; cv=none; d=google.com; s=arc-20160816; b=mnEKFXiCnubsYayvpVZ1LMuR9ceDz/3tRCUsiYSJ7803LiwlJ+Wrwe5rbn+Y4n4cfl VreN5skH7AaHMBmOIxBH5uZMxuVv+2Y/qnmHL7b1whl6bpL4PR9862fot7S2Szu3Xg14 T7npadrA0PYlYo/Gixn2mF+x3NLC88VutpIvtCQbxlC/gOviIxKcuH6PS5qHdvhv2qKV 6vw81Bt415EArMuB4lKgti4l592LQQRp2GKonAluEPydE7YLXa5G8qFyqm6nJuaX0izw ha2GxO7uALexkNpBre2iXYtjhH8Qd20oZdVlrUh6F3WohzXExCy6Z+2RdMmbofDx+ksE BuJg== 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=CEwSl34k6l4FLjjlbRxCU1JxeusG83TWF1XySun55Ik=; b=qlkQKkxmt44a8LI+lPhaKljVXRHJ4V9GFojM/rUYh/fwYW+vIc+fAM9ktDspGPdmSV QBgH1VetDnePl+e5OtDYga7yzMpg2Z3kQFsmryI/XNE9ANT/8yp4v+7YmvlaCJpmd58b F/Jm3A5H31hTJ9pu9TcO2NZofPGx/2ZnZiKfAvk3ZXORQeIbztCSOsOkuq5jIVywvDSR yg6l+prrmk5PuiHa54kmcxQwjzVywivIvQGov/5oBKOEmeCxAY9i6hNRB8tDgvIvLxNB vwSey+hKl2/pKaysXlY7847a0GCewU1NlWHl2MXO0agjynYJKZE8GTKt7ZtXVT9z4VIV 1Cxw== 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 65si242303plf.288.2019.03.28.15.14.09; Thu, 28 Mar 2019 15:14:25 -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 S1728011AbfC1WMH (ORCPT + 99 others); Thu, 28 Mar 2019 18:12:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54960 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727476AbfC1WMH (ORCPT ); Thu, 28 Mar 2019 18:12:07 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C942388306; Thu, 28 Mar 2019 22:12:06 +0000 (UTC) Received: from redhat.com (ovpn-121-118.rdu2.redhat.com [10.10.121.118]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0ECCC1001DDA; Thu, 28 Mar 2019 22:12:05 +0000 (UTC) Date: Thu, 28 Mar 2019 18:12:04 -0400 From: Jerome Glisse To: John Hubbard Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton , Dan Williams Subject: Re: [PATCH v2 07/11] mm/hmm: add default fault flags to avoid the need to pre-fill pfns arrays. Message-ID: <20190328221203.GF13560@redhat.com> References: <20190325144011.10560-1-jglisse@redhat.com> <20190325144011.10560-8-jglisse@redhat.com> <2f790427-ea87-b41e-b386-820ccdb7dd38@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <2f790427-ea87-b41e-b386-820ccdb7dd38@nvidia.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 28 Mar 2019 22:12:06 +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 02:59:50PM -0700, John Hubbard wrote: > On 3/25/19 7:40 AM, jglisse@redhat.com wrote: > > From: J?r?me Glisse > > > > The HMM mirror API can be use in two fashions. The first one where the HMM > > user coalesce multiple page faults 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. > > > > This patch adds a default flags value allowing user to set them for a range > > without having to pre-fill the pfn array. > > > > Signed-off-by: J?r?me 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(+) > > > > 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 <= PAGE_SHIFT) > > * @valid: pfns array did not change since it has been fill by an HMM function > > */ > > @@ -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 *range, bool block) > > { > > long ret; > > > > + range->default_flags = 0; > > + range->pfn_flags_mask = -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 > 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 correct 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 much, > IMHO. This mirror the fact that flags are provided as an array and some devices use the top bits for flags (read, write, ...). So here it is the safe default to set it to -1. If the caller want to leverage this optimization it can override the default_flags value. > > > + > > ret = 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 hmm_vma_walk *hmm_vma_walk, > > if (!hmm_vma_walk->fault) > > return; > > > > + /* > > + * 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 = (pfns & range->pfn_flags_mask) | range->default_flags; > > Need to verify that the mask isn't too large or too small. I need to check agin but default flag is anded somewhere to limit the bit to the one we expect. Cheers, J?r?me