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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 136F9C433F5 for ; Thu, 20 Jan 2022 15:50:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 843F56B00A3; Thu, 20 Jan 2022 10:50:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7F41F6B00A5; Thu, 20 Jan 2022 10:50:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 66D326B00A6; Thu, 20 Jan 2022 10:50:12 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0178.hostedemail.com [216.40.44.178]) by kanga.kvack.org (Postfix) with ESMTP id 5899C6B00A3 for ; Thu, 20 Jan 2022 10:50:12 -0500 (EST) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 1AD34181C49D1 for ; Thu, 20 Jan 2022 15:50:12 +0000 (UTC) X-FDA: 79051101864.30.EAFBE85 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf09.hostedemail.com (Postfix) with ESMTP id 71E12140004 for ; Thu, 20 Jan 2022 15:50:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=+OqexFoNCw32h57DcgoxO/vo70BrOjYwfG6rLAmWBFk=; b=hpYJa8iURpESRfETFsBuVnmNao 5TNej4O57CGbRr8rVRkuB1yNHsu02X5/nl/cpjO/VIHtqaNXy/cfO4VXXpw0lHkRlYPW9IGNt+Mwl wi/QPhzbw5zP5kQwPWvBBcthI5gUG0Ub0e7/afSo3swET/a7d94V5/S0Lj18ekylHxfyIvn8UdT/R GIbnv/mxwdb4Kw2MOl//pKSTL4Pfi8eQsBueheUVHLpuYaEYLNX2y/+WPa5498YYhJPhLzkCChv90 pexyEMGXpqJE5vQrDGwtKJ/RW11j56Q6vu/cnJHwNHFTtqbFueGtipqGz5O+UYh0GWcCEj8MEvEHk xHpZBd+A==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1nAZhJ-00EOay-4L; Thu, 20 Jan 2022 15:50:01 +0000 Date: Thu, 20 Jan 2022 15:50:01 +0000 From: Matthew Wilcox To: Vlastimil Babka Cc: Liam Howlett , "maple-tree@lists.infradead.org" , "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" , Andrew Morton , Song Liu , Davidlohr Bueso , "Paul E . McKenney" , Laurent Dufour , David Rientjes , Axel Rasmussen , Suren Baghdasaryan , Rik van Riel , Peter Zijlstra , Michel Lespinasse , Jerome Glisse , Minchan Kim , Joel Fernandes , Rom Lemarchand Subject: Re: [PATCH v4 63/66] i915: Use the VMA iterator Message-ID: References: <20211201142918.921493-1-Liam.Howlett@oracle.com> <20211201142918.921493-64-Liam.Howlett@oracle.com> <807fa53c-6492-52ca-abf3-ce58cc84ca08@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <807fa53c-6492-52ca-abf3-ce58cc84ca08@suse.cz> X-Rspamd-Queue-Id: 71E12140004 X-Stat-Signature: rn8b5g54pzt985sg4c94o7q8eumafhs4 Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=hpYJa8iU; dmarc=none; spf=none (imf09.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org X-Rspamd-Server: rspam08 X-HE-Tag: 1642693811-18011 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 Thu, Jan 20, 2022 at 03:59:11PM +0100, Vlastimil Babka wrote: > On 12/1/21 15:30, Liam Howlett wrote: > > From: "Matthew Wilcox (Oracle)" > > > > Replace the O(n.log(n)) loop with an O(n) loop. > > Not true? Oh, right, that should have been just the linked-list walk. I misread it as calling find_vma() for each iteration instead of just the first one. Liam, do you mind updating the changelog here? I wonder whether we want a "for_each_contiguous_vma()" that will stop on a hole. It seems like a relatively sensible thing to do -- walk across a contiguous range of memory and stop if there's no VMA mapping a page. Like gup(), for example. > > Signed-off-by: Matthew Wilcox (Oracle) > > Signed-off-by: Liam R. Howlett > > Acked-by: Vlastimil Babka > > > --- > > drivers/gpu/drm/i915/gem/i915_gem_userptr.c | 14 +++++--------- > > 1 file changed, 5 insertions(+), 9 deletions(-) > > > > diff --git a/drivers/gpu/drm/i915/gem/i915_gem_userptr.c b/drivers/gpu/drm/i915/gem/i915_gem_userptr.c > > index 3173c9f9a040..39960973c130 100644 > > --- a/drivers/gpu/drm/i915/gem/i915_gem_userptr.c > > +++ b/drivers/gpu/drm/i915/gem/i915_gem_userptr.c > > @@ -425,12 +425,11 @@ static const struct drm_i915_gem_object_ops i915_gem_userptr_ops = { > > static int > > probe_range(struct mm_struct *mm, unsigned long addr, unsigned long len) > > { > > - const unsigned long end = addr + len; > > + VMA_ITERATOR(vmi, mm, addr); > > struct vm_area_struct *vma; > > - int ret = -EFAULT; > > > > mmap_read_lock(mm); > > - for (vma = find_vma(mm, addr); vma; vma = vma->vm_next) { > > + for_each_vma_range(vmi, vma, addr + len) { > > /* Check for holes, note that we also update the addr below */ > > if (vma->vm_start > addr) > > break; > > @@ -438,16 +437,13 @@ probe_range(struct mm_struct *mm, unsigned long addr, unsigned long len) > > if (vma->vm_flags & (VM_PFNMAP | VM_MIXEDMAP)) > > break; > > > > - if (vma->vm_end >= end) { > > - ret = 0; > > - break; > > - } > > - > > addr = vma->vm_end; > > } > > mmap_read_unlock(mm); > > > > - return ret; > > + if (vma) > > + return -EFAULT; > > + return 0; > > } > > > > /* >