From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A0435C54FCB for ; Wed, 22 Apr 2020 05:52:33 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6DA9D2075A for ; Wed, 22 Apr 2020 05:52:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6DA9D2075A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 1D09C8E0006; Wed, 22 Apr 2020 01:52:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1A64C8E0003; Wed, 22 Apr 2020 01:52:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0BC2E8E0006; Wed, 22 Apr 2020 01:52:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0072.hostedemail.com [216.40.44.72]) by kanga.kvack.org (Postfix) with ESMTP id E4B778E0003 for ; Wed, 22 Apr 2020 01:52:32 -0400 (EDT) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 952A72479 for ; Wed, 22 Apr 2020 05:52:32 +0000 (UTC) X-FDA: 76734421344.10.dust53_6d782087ceb0f X-HE-Tag: dust53_6d782087ceb0f X-Filterd-Recvd-Size: 4261 Received: from verein.lst.de (verein.lst.de [213.95.11.211]) by imf29.hostedemail.com (Postfix) with ESMTP for ; Wed, 22 Apr 2020 05:52:32 +0000 (UTC) Received: by verein.lst.de (Postfix, from userid 2407) id 8C51968C4E; Wed, 22 Apr 2020 07:52:29 +0200 (CEST) Date: Wed, 22 Apr 2020 07:52:29 +0200 From: Christoph Hellwig To: Jason Gunthorpe Cc: linux-mm@kvack.org, Ralph Campbell , Alex Deucher , amd-gfx@lists.freedesktop.org, Ben Skeggs , Christian =?iso-8859-1?Q?K=F6nig?= , "David (ChunMing) Zhou" , dri-devel@lists.freedesktop.org, "Kuehling, Felix" , Christoph Hellwig , intel-gfx@lists.freedesktop.org, =?iso-8859-1?B?Suly9G1l?= Glisse , John Hubbard , linux-kernel@vger.kernel.org, Niranjana Vishwanathapura , nouveau@lists.freedesktop.org Subject: Re: [PATCH hmm 2/5] mm/hmm: make hmm_range_fault return 0 or -1 Message-ID: <20200422055229.GB22366@lst.de> References: <0-v1-4eb72686de3c+5062-hmm_no_flags_jgg@mellanox.com> <2-v1-4eb72686de3c+5062-hmm_no_flags_jgg@mellanox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2-v1-4eb72686de3c+5062-hmm_no_flags_jgg@mellanox.com> User-Agent: Mutt/1.5.17 (2007-11-01) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue, Apr 21, 2020 at 09:21:43PM -0300, Jason Gunthorpe wrote: > From: Jason Gunthorpe > > hmm_vma_walk->last is supposed to be updated after every write to the > pfns, so that it can be returned by hmm_range_fault(). However, this is > not done consistently. Fortunately nothing checks the return code of > hmm_range_fault() for anything other than error. > > More importantly last must be set before returning -EBUSY as it is used to > prevent reading an output pfn as an input flags when the loop restarts. > > For clarity and simplicity make hmm_range_fault() return 0 or -ERRNO. Only > set last when returning -EBUSY. > > Signed-off-by: Jason Gunthorpe > --- > Documentation/vm/hmm.rst | 2 +- > drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 4 ++-- > drivers/gpu/drm/nouveau/nouveau_svm.c | 6 +++--- > include/linux/hmm.h | 2 +- > mm/hmm.c | 25 +++++++++---------------- > 5 files changed, 16 insertions(+), 23 deletions(-) > > diff --git a/Documentation/vm/hmm.rst b/Documentation/vm/hmm.rst > index 4e3e9362afeb10..9924f2caa0184c 100644 > --- a/Documentation/vm/hmm.rst > +++ b/Documentation/vm/hmm.rst > @@ -161,7 +161,7 @@ device must complete the update before the driver callback returns. > When the device driver wants to populate a range of virtual addresses, it can > use:: > > - long hmm_range_fault(struct hmm_range *range); > + int hmm_range_fault(struct hmm_range *range); > > It will trigger a page fault on missing or read-only entries if write access is > requested (see below). Page faults use the generic mm page fault code path just > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c > index 6309ff72bd7876..efc1329a019127 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c > @@ -852,12 +852,12 @@ int amdgpu_ttm_tt_get_user_pages(struct amdgpu_bo *bo, struct page **pages) > down_read(&mm->mmap_sem); > r = hmm_range_fault(range); > up_read(&mm->mmap_sem); > - if (unlikely(r <= 0)) { > + if (unlikely(r)) { > /* > * FIXME: This timeout should encompass the retry from > * mmu_interval_read_retry() as well. > */ > - if ((r == 0 || r == -EBUSY) && !time_after(jiffies, timeout)) > + if ((r == -EBUSY) && !time_after(jiffies, timeout)) Please also kill the superflous inner braces here. > + * Return: 0 or -ERRNO with one of the following status codes: Maybe say something like: * Returns 0 on success or one of the following error codes: Otherwise this looks good: Reviewed-by: Christoph Hellwig