Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3669514imu; Mon, 24 Dec 2018 06:32:27 -0800 (PST) X-Google-Smtp-Source: ALg8bN5nInPk4FDdpovTojHTzGiA9qH/Z00OxoXhrJ7LTqCdeib5mnJ2diS8SV4OFGRvYfs3Gg6V X-Received: by 2002:a62:1e45:: with SMTP id e66mr13238649pfe.152.1545661946988; Mon, 24 Dec 2018 06:32:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545661946; cv=none; d=google.com; s=arc-20160816; b=ggPrEBy1CKj4bDehZo9yU4Y/G2EdWR3D1P9Wg8KqRLbD6S3zAE/lGXE8YDl5ODw6nq peg/xBOErFdHv1o6L+eft+ndskyA7cX3WCge9CDQQohMtJF9fIb+Eoth1PsqXEiEWiiJ rFRDUQzS+nydKmpFUUINS0RFyLlW04tIYnevsxAAL8uNZq/uhWa/kkTVdgIJkNgh+j0s 5vBxDztS04VZiimA2MFvU/FCA1Jy6ZNFE8jkWoJdTVMHnRWO1XYqIe8ThnQYilCXjLX+ 7PXST0gWDhzaZMQ5+P4ToMUK+AXWlaxbKbumGbqg7Z650BMn8vhwtM8N6Wq0vD0Mf5kq DK8w== 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-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=kvKnfvcb3iLFqvHcRSa+XDrZ1f+GPM4hMRTAJKCzQ9w=; b=R4QzdAlORawogTGz7meXGx1zUYHFuP0jx3wQbaItqn65dnYb0BSZDQaeztNbnomEUB 8Dl+kZ0fVk2xGnRw8ovSdSjtdDMfEmN+OuhkG7K6Q4tKyC2krlkur3Pye5wd7g3WlF44 QV7CS/2f4PDPTfWidR8SaR/tS/oPQnLUuoG5rl+kp4+LOK2DeFBxutvBgSxQbbX/OluN gOMU3B+Aniq1MFfQuazE59vmSd5dz9UkWnpzMKUH700HVts2lYHSAVmizWecFJvhZ/mf WCbK4zJjUcLkatcXh0oGQ0zdmSS2Wrd1ceFQeZq3uzJTo9TvFBNYG3qfKqToDh2iw9b2 lrTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@armlinux.org.uk header.s=pandora-2014 header.b=Cb1dQr9n; 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=armlinux.org.uk Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p3si26948722plr.376.2018.12.24.06.32.11; Mon, 24 Dec 2018 06:32:26 -0800 (PST) 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=fail header.i=@armlinux.org.uk header.s=pandora-2014 header.b=Cb1dQr9n; 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=armlinux.org.uk Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726000AbeLXO34 (ORCPT + 99 others); Mon, 24 Dec 2018 09:29:56 -0500 Received: from pandora.armlinux.org.uk ([78.32.30.218]:52502 "EHLO pandora.armlinux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725766AbeLXO3z (ORCPT ); Mon, 24 Dec 2018 09:29:55 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2014; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=kvKnfvcb3iLFqvHcRSa+XDrZ1f+GPM4hMRTAJKCzQ9w=; b=Cb1dQr9njcsp0qf4pHVdBXH9H rp1LGl7GSrr2Tusok2Fye23JUGYa7J5c2AJBlX5qaStt4v47r3Du0ExYRKFvzCsSW3O9Hrbpk0FR2 EahuDg66ZTj522MzpLTSDjzf3/TpveX4bp/HG4udPiRQdFFwpuvjET3OY5sr3amkbZAFg=; Received: from n2100.armlinux.org.uk ([2002:4e20:1eda:1:214:fdff:fe10:4f86]:59018) by pandora.armlinux.org.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.90_1) (envelope-from ) id 1gbREZ-0007n3-S2; Mon, 24 Dec 2018 14:29:33 +0000 Received: from linux by n2100.armlinux.org.uk with local (Exim 4.90_1) (envelope-from ) id 1gbREX-0006ez-0f; Mon, 24 Dec 2018 14:29:29 +0000 Date: Mon, 24 Dec 2018 14:29:27 +0000 From: Russell King - ARM Linux To: Souptick Joarder Cc: akpm@linux-foundation.org, willy@infradead.org, mhocko@suse.com, joro@8bytes.org, robin.murphy@arm.com, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH v5 6/9] iommu/dma-iommu.c: Convert to use vm_insert_range Message-ID: <20181224142927.GZ26090@n2100.armlinux.org.uk> References: <20181224132531.GA22150@jordon-HP-15-Notebook-PC> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181224132531.GA22150@jordon-HP-15-Notebook-PC> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Dec 24, 2018 at 06:55:31PM +0530, Souptick Joarder wrote: > Convert to use vm_insert_range() to map range of kernel > memory to user vma. > > Signed-off-by: Souptick Joarder > Reviewed-by: Matthew Wilcox > --- > drivers/iommu/dma-iommu.c | 13 +++---------- > 1 file changed, 3 insertions(+), 10 deletions(-) > > diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c > index d1b0475..de7ffd8 100644 > --- a/drivers/iommu/dma-iommu.c > +++ b/drivers/iommu/dma-iommu.c > @@ -622,17 +622,10 @@ struct page **iommu_dma_alloc(struct device *dev, size_t size, gfp_t gfp, > > int iommu_dma_mmap(struct page **pages, size_t size, struct vm_area_struct *vma) > { > - unsigned long uaddr = vma->vm_start; > - unsigned int i, count = PAGE_ALIGN(size) >> PAGE_SHIFT; > - int ret = -ENXIO; > + unsigned long count = PAGE_ALIGN(size) >> PAGE_SHIFT; > > - for (i = vma->vm_pgoff; i < count && uaddr < vma->vm_end; i++) { > - ret = vm_insert_page(vma, uaddr, pages[i]); > - if (ret) > - break; > - uaddr += PAGE_SIZE; > - } > - return ret; > + return vm_insert_range(vma, vma->vm_start, pages + vma->vm_pgoff, > + count - vma->vm_pgoff); This introduces a new bug. I'm not going to continue to point out in minute detail the mistakes you are introducing, as I don't think that is helping you to learn. Look at this closely, and see whether you can spot the mistake. Specifically, compare the boundary conditions for the final page that is to be inserted and the value returned by the original version and by your version for different scenarios. -- RMK's Patch system: http://www.armlinux.org.uk/developer/patches/ FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up According to speedtest.net: 11.9Mbps down 500kbps up