Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp120638ybj; Mon, 4 May 2020 17:23:10 -0700 (PDT) X-Google-Smtp-Source: APiQypIZAlIk5MxaQSLLWYj8RU/10TLsKVl1Unm13gOF/GwKW7gyHv7YNllaVmlB0isumYU59pZA X-Received: by 2002:a17:906:130e:: with SMTP id w14mr313174ejb.155.1588638190319; Mon, 04 May 2020 17:23:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588638190; cv=none; d=google.com; s=arc-20160816; b=cQkqM5npmmGT7vs0NoxRxyJjfIjZYD6cwwgVjB/4Dg/p9avbaX8mBE+ubTC9IaypO5 qmV5JzUHYQcnDfrUTP+TPYG/eIyolucPdYQSE4W0afFKVtBHbeOpN7gJeTcwYcE1RCjW NpmJZ0NTMzVPlE4gmDLk1y02Mn3O9xLcBdJHSi2PpfX82hFxpCdPku+KBcogDXJHw8FS 7iAX8P78RNovp9Xz1aZIFmUpAKOOHvT6VEXkR1ThGGHrGOXsxQEVz8JC6/1FO8PjMT0W jxC7/UF/dfohr8RR16zpGLxZxdeLi3nXR2YA0t+5iPSfRqBjbH/APNviwkLHqgZviICG Tpyg== 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=IxP1FX28IvHHn1UJ333IIWhaZQbrlpthRJPkCq5tlOE=; b=tFRlf7uWeWCk60+5/mkR/a7GvV1zZrm7tIl9Qh6mSPHR8kkPC6jNusgykT29+AGVkG lNe8HRiArxVI8fab9ukbzHae5ZmMzHCIQ463q6FLLsEu/XnVRXRfYr1ZcTyrBHjhNFUF H2zVL0gfyo0op/Ql71bZlCSESmFgGtOg9dhBm9ET4BSMA7sKLYHJlcR6n0VzSLRfVaeQ xDcuJv01s5f2FsKG52ydANQex76/hiHiaOLKP0b0XtoTaXBSOp/gYj6MfQ9GSZlwUdfT jL+foqLHUzx0lyO2s4xjp7FCloYE5FLemad2KiViD2w68R20MrJveotFW3z4jC+ItaOM R35w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=jlUDA7Xe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id dk23si320549edb.282.2020.05.04.17.22.46; Mon, 04 May 2020 17:23:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=jlUDA7Xe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1728487AbgEEAVA (ORCPT + 99 others); Mon, 4 May 2020 20:21:00 -0400 Received: from hqnvemgate25.nvidia.com ([216.228.121.64]:3656 "EHLO hqnvemgate25.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728336AbgEEAVA (ORCPT ); Mon, 4 May 2020 20:21:00 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate25.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Mon, 04 May 2020 17:19:50 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Mon, 04 May 2020 17:20:59 -0700 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Mon, 04 May 2020 17:20:59 -0700 Received: from [10.2.56.198] (172.20.13.39) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 5 May 2020 00:20:59 +0000 Subject: Re: [PATCH hmm v2 2/5] mm/hmm: make hmm_range_fault return 0 or -1 To: Jason Gunthorpe , , Ralph Campbell CC: Alex Deucher , , Ben Skeggs , =?UTF-8?Q?Christian_K=c3=b6nig?= , "David (ChunMing) Zhou" , , Felix Kuehling , Christoph Hellwig , , =?UTF-8?B?SsOpcsO0bWUgR2xpc3Nl?= , , Niranjana Vishwanathapura , , "Yang, Philip" References: <2-v2-b4e84f444c7d+24f57-hmm_no_flags_jgg@mellanox.com> X-Nvconfidentiality: public From: John Hubbard Message-ID: <9cf9f4f0-58b7-1992-6c6e-eed226ba42c0@nvidia.com> Date: Mon, 4 May 2020 17:20:58 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: <2-v2-b4e84f444c7d+24f57-hmm_no_flags_jgg@mellanox.com> X-Originating-IP: [172.20.13.39] X-ClientProxiedBy: HQMAIL107.nvidia.com (172.20.187.13) To HQMAIL107.nvidia.com (172.20.187.13) Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1588637990; bh=IxP1FX28IvHHn1UJ333IIWhaZQbrlpthRJPkCq5tlOE=; h=X-PGP-Universal:Subject:To:CC:References:X-Nvconfidentiality:From: Message-ID:Date:User-Agent:MIME-Version:In-Reply-To: X-Originating-IP:X-ClientProxiedBy:Content-Type:Content-Language: Content-Transfer-Encoding; b=jlUDA7Xe/cEVYvcoOLBLT9WxsiTxB4eaIcRkJbYt7sChT+skJNIVNGkwSxeX311N9 8Icf+Bb+N7FsISzQG4Ci4zeBXx95nSpEwUjZe7BytMfOd9TIqtDhoWdCDk3g2renix JJp4862GZJKQrIMSPPWchAxpo2TL3LdIgZ1nciGXyRvtuaWnU7bnlRQkU6QhCIwddA zZt1IUaeh+IgfHdHcJKHNaZAmd2XKaHg3iGk3SkLeBMTYoH9nYDLidjG4h/hxqZ6a6 Hae57Q5zwNGF0Ax1wOvaZcYkMzvipoDz/QPdM+7uCWP3VezcDvR1L7Kvdm3oMQaoTe S2aJNC1fom1GQ== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020-05-01 11:20, 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. Yes, this is also a nice simplification. > ... > @@ -590,10 +580,13 @@ long hmm_range_fault(struct hmm_range *range) > return -EBUSY; > ret = walk_page_range(mm, hmm_vma_walk.last, range->end, > &hmm_walk_ops, &hmm_vma_walk); > + /* > + * When -EBUSY is returned the loop restarts with > + * hmm_vma_walk.last set to an address that has not been stored > + * in pfns. All entries < last in the pfn array are set to their > + * output, and all >= are still at their input values. > + */ I'm glad you added that comment. This is much easier to figure out with that in place. After poking around this patch and eventually understanding the .last handling, I wondered if you might like this slightly tweaked wording instead: /* * Each of the hmm_walk_ops routines returns -EBUSY if and only * hmm_vma_walk.last has been set to an address that has not yet * been stored in pfns. All entries < last in the pfn array are * set to their output, and all >= are still at their input * values. */ Either way, Reviewed-by: John Hubbard thanks, -- John Hubbard NVIDIA > } while (ret == -EBUSY); > - > - if (ret) > - return ret; > - return (hmm_vma_walk.last - range->start) >> PAGE_SHIFT; > + return ret; > } > EXPORT_SYMBOL(hmm_range_fault); >