From patchwork Thu Nov 15 15:46:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Souptick Joarder X-Patchwork-Id: 10684651 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5E92C14DB for ; Thu, 15 Nov 2018 15:43:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4C6BF2C8A4 for ; Thu, 15 Nov 2018 15:43:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 40FAC2CB88; Thu, 15 Nov 2018 15:43:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.6 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D6C9C2C8A4 for ; Thu, 15 Nov 2018 15:43:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Subject:To:From :Date:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=yDs4Xms5Ue56josWB+LHsRMfigi+c1rAhzGbOMhld0k=; b=ZmPremPmRm8reA 2861KcoVujpcLBWw3hypE1j8vOAbEXMvi408B+4OTwlWBXfNZylBtXRAw/+23YUDV9Vbp18iFFZ0F wjPTJWjq9fPgADiP3hiOCVrPsMU/VNXDdl+XAvcpZQ8fttJnuJP5mBlkSZR6hehQumTEE3amuPk4C znve2nGl9AMIrGomqPhhXKKuF6Nb1Yk9bi82L7cDf85JdvyRNX8Vyi8zHCS7G++LJvah9DfNn4o3S IRUpYes/NDeRqwkeO4gGIfsgfTCNMqjT8V87b+mIxl04I9bpdhuDcsnenBf7qj//didz219woyjli +ViSb7zNzIxCxoCN/Jyw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gNJng-0005kQ-4q; Thu, 15 Nov 2018 15:43:24 +0000 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gNJnc-0005j9-U8 for linux-arm-kernel@lists.infradead.org; Thu, 15 Nov 2018 15:43:22 +0000 Received: by mail-pl1-x642.google.com with SMTP id b5so3247781plr.4 for ; Thu, 15 Nov 2018 07:43:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=8CQaNbWYfH4rrtr7y1L1OPdwNgqhGo43ZWeJVCZSPio=; b=pCfJfGGRC2UtHAm9HA9aL0m7FenKYdHmKJW2cNiCT4fbUX8KyYAZol4NGubhwf4ix2 JcfsHY3HzR+LD2Gb35qfzVgY1IXhMHnzM33c4dii6hjPbeplvdrBBjf/idYXgOa4HeF4 YqSlCdyPQleDOp9Ofz01vlgd2gfpDL0AyrbT2kWZkpPS2R8a+EQgE0qAz3f8ONGz2wIA cW5Mm2FkhkWKiXO2vC9eyC8WDTsRmUeEmiaMGbYoGFmo2djVIibp1dvUH2JzxD51uN50 IxGo0q4UVc0QPq9Uc2pBekL4kOycmBRKdiAhHeUHyXMzaxqZqXdWAFSq0E2f664geFlm qyEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=8CQaNbWYfH4rrtr7y1L1OPdwNgqhGo43ZWeJVCZSPio=; b=AkP/EFE7Sabp+I+MfVDLQ3HL+7ppUkH0lU7pQWS6w5E+6Q/rcBkZwBTRhPkMh1UnF3 M6P04gLRHysMrwjTHlT3xtRMXC4/O3teNcZzPPzzUY9a4PKTqkr0Zc52us0I+BUb6zQm rJuDs+u0JOgovNrVpw0XklCKKSXiQd8jp/X9whQAJvfrlsjD7NluAijB9xidFw1f5e/5 7pEPtoc8KskSS6hSP4CRJC8plvKF7sd5jdUqHY9rNQzUhCA10Dxu2VB2UlQtxZO0r2q0 yzdcEK8JyHZtbsL4lrkN5oZ3lujXEs4dv34nJTQ3+hki8jjXreXFzLfSR8fRaGqkQc4h +nCw== X-Gm-Message-State: AGRZ1gL2sZj5CzO0ftEmvSh+/K8nYiDrOE+xRB7ZzOrp+wJNstBkVK/m lnpqycirwuBxMadZ6UBPT8rB2oAW X-Google-Smtp-Source: AJdET5f1R8LoBMhkPMKCZQSqkbiD6+/xv1S3DM7BTCxxtIUioUmrA+uSzrT7vwaK3JvVIPNypMhWlQ== X-Received: by 2002:a17:902:ab83:: with SMTP id f3-v6mr6507758plr.122.1542296589903; Thu, 15 Nov 2018 07:43:09 -0800 (PST) Received: from jordon-HP-15-Notebook-PC ([103.227.97.233]) by smtp.gmail.com with ESMTPSA id 4sm25997357pfq.10.2018.11.15.07.43.08 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 15 Nov 2018 07:43:08 -0800 (PST) Date: Thu, 15 Nov 2018 21:16:46 +0530 From: Souptick Joarder To: akpm@linux-foundation.org, willy@infradead.org, mhocko@suse.com, linux@armlinux.org.uk, robin.murphy@arm.com, iamjoonsoo.kim@lge.com, treding@nvidia.com, keescook@chromium.org, m.szyprowski@samsung.com Subject: [PATCH 2/9] arch/arm/mm/dma-mapping.c: Convert to use vm_insert_range Message-ID: <20181115154645.GA27912@jordon-HP-15-Notebook-PC> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181115_074320_966729_1EFEEA92 X-CRM114-Status: GOOD ( 15.64 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Convert to use vm_insert_range() to map range of kernel memory to user vma. Signed-off-by: Souptick Joarder --- arch/arm/mm/dma-mapping.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c index 661fe48..4eec323 100644 --- a/arch/arm/mm/dma-mapping.c +++ b/arch/arm/mm/dma-mapping.c @@ -1582,31 +1582,24 @@ static int __arm_iommu_mmap_attrs(struct device *dev, struct vm_area_struct *vma void *cpu_addr, dma_addr_t dma_addr, size_t size, unsigned long attrs) { - unsigned long uaddr = vma->vm_start; - unsigned long usize = vma->vm_end - vma->vm_start; + unsigned long page_count = vma_pages(vma); struct page **pages = __iommu_get_pages(cpu_addr, attrs); unsigned long nr_pages = PAGE_ALIGN(size) >> PAGE_SHIFT; unsigned long off = vma->vm_pgoff; + int err; if (!pages) return -ENXIO; - if (off >= nr_pages || (usize >> PAGE_SHIFT) > nr_pages - off) + if (off >= nr_pages || page_count > nr_pages - off) return -ENXIO; pages += off; + err = vm_insert_range(vma, vma->vm_start, pages, page_count); + if (err) + pr_err("Remapping memory failed: %d\n", err); - do { - int ret = vm_insert_page(vma, uaddr, *pages++); - if (ret) { - pr_err("Remapping memory failed: %d\n", ret); - return ret; - } - uaddr += PAGE_SIZE; - usize -= PAGE_SIZE; - } while (usize > 0); - - return 0; + return err; } static int arm_iommu_mmap_attrs(struct device *dev, struct vm_area_struct *vma, void *cpu_addr,