From patchwork Mon Dec 17 20:22:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Souptick Joarder X-Patchwork-Id: 10734255 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 73ACF14DE for ; Mon, 17 Dec 2018 20:18:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 625172A2DF for ; Mon, 17 Dec 2018 20:18:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 538012A2E8; Mon, 17 Dec 2018 20:18:21 +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.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3B9882A2DF for ; Mon, 17 Dec 2018 20:18:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 55B9A8E004E; Mon, 17 Dec 2018 15:18:19 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 50ACE8E0033; Mon, 17 Dec 2018 15:18:19 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 424858E004E; Mon, 17 Dec 2018 15:18:19 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) by kanga.kvack.org (Postfix) with ESMTP id 0245D8E0033 for ; Mon, 17 Dec 2018 15:18:19 -0500 (EST) Received: by mail-pl1-f200.google.com with SMTP id v11so10007178ply.4 for ; Mon, 17 Dec 2018 12:18:18 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:date:from:to:cc:subject :message-id:mime-version:content-disposition:user-agent; bh=sUyJE5XZI7PFTFAoMHl2QCf6i1YL7AfLuhA9/P6Ludc=; b=nKHKsMA6sSFluURG9gIqD+xRVHyNRRndGBBbc0hx+klkRUIF2nfEr336OnJp+Wt4uo 784kVn8fB8RD1wlEdzNdskZB8WTMxrZck3p2TD3lRagBsdDxsIckjspvVEfTM9X5gWGt NiJj+2YAgUWXavKwnGR6grlWbYtUkLKPPzTLa9kQKrC8i6/P5sB/c5Nn6tKQdUyEZCel upo0AM26siMeE0Z0OfILv23nOih3hoXulYXw8zHuTA9sudcdS9BZDeViXdAyZ1GtC6UQ fodNpiggiL3vZC4va6TOUO3pmJ5aeTP61FaD18a3v6wR+gWGvLWJha6O4doel4okrKbw zUQw== X-Gm-Message-State: AA+aEWZNewwIsAlbySUGq0WuHYp+0VDK8XG+gy3UQ8+85bxkEroB+Cvj fhA/NrrADnslnTJLS2zl5JRO+ehN4oIfwiVloO2CyvFkxrv3TrfJy4xS3nAN5sMl0YnZ5TU1l9F H773tAmjbdGix+8CsDTYR+Ql97nx3Oq9xKzlLZFxyApL6uPmoGVE0GVpXn/lKXnUlzmTCM5jbdp uYKpQ3sCezPmnaSn7B3Q4aR8CAn7eGOOieKxvXAjQl+rM5tsbZubKx1uBY77iz9u9OQi4dHhwOm jAdzZqf//MgvQcYwK1MM+xpKRu8PFiNuhAdPMSTiyMkdJOg7nfWRTVMXoSBcnpCeBHN/6ZMXd8J NbvHGolc5v+uXE2aIX/yTdcte/fhxVW8N8r1LuCGPWxQpr+CaYQagV+5Yp2f80M+39FoGxaj1Mw r X-Received: by 2002:a63:3602:: with SMTP id d2mr12975737pga.404.1545077898689; Mon, 17 Dec 2018 12:18:18 -0800 (PST) X-Received: by 2002:a63:3602:: with SMTP id d2mr12975700pga.404.1545077898007; Mon, 17 Dec 2018 12:18:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545077897; cv=none; d=google.com; s=arc-20160816; b=j8uWo9a0Vr8Mmr80eT7M4wQl5M9C3eOHoirOpnqWfpB3U9iUoB/mBN5ajH7BG5kafM 0nID76tP0J0QtyiJbz7kBNxhof4Mb1MlNYWxIwutPqdK+Wyre2WezQF0cctUmWPxMLz3 mx8QM7qloEH0CX/3/RL1UIylyI2put+5/j58Sr6LWNP/j/Amlk9QMXj1zVVvJOLMjBZN GyZ3RYoA3acDq5psRb+njtz5vr0maW/TnV+KEk8MWEqZ7QuljNmI7146tVh427kPwNb8 rwIcgAoEgfjgjXLflpbbadbjhXImMPlLbF6ljSzrqUF3oqBGmtmFMFa+QFQMVmqH95eh pwxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:content-disposition:mime-version:message-id:subject:cc :to:from:date:dkim-signature; bh=sUyJE5XZI7PFTFAoMHl2QCf6i1YL7AfLuhA9/P6Ludc=; b=jcj8zUaBfI1ZAWYmnXwsMks6A29iluvf3hhi95w8txcXOtWV77wiAobiUpadedHBxh h4e3ZIJd1fKgSx4Dr46N21siD/NHn0VjWC/wCLQbNbGMMPlo57teiD9AqxCjCbxpMkjO vRs4sQHClP2O6D8OUPaMTnGhNdiGFzFaaYQ0IcXfQ+ZFIgS2cXHLHET/Q8jbhDiMyBgX 5HUNzr9J0bD+Mv+yHZ2sdRcqZAWozzga4XDRDanleTOQNatc73//KewUxmARvKlizG4R LdfjeVvTWNCn8adBmeHrLWIwvYpzZ0KlkcM42C4Kru8lUclyNlCd6PnM2k3t0XP5CImR xkhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=oDI8mY+6; spf=pass (google.com: domain of jrdr.linux@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jrdr.linux@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id 7sor20289582pll.40.2018.12.17.12.18.17 for (Google Transport Security); Mon, 17 Dec 2018 12:18:17 -0800 (PST) Received-SPF: pass (google.com: domain of jrdr.linux@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=oDI8mY+6; spf=pass (google.com: domain of jrdr.linux@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jrdr.linux@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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=sUyJE5XZI7PFTFAoMHl2QCf6i1YL7AfLuhA9/P6Ludc=; b=oDI8mY+6/0wwXEtDv6zcp3R2be1Zb57Xo3+v9BgCECtnF3xZe4e8/tCJOt9WNsnuNx dqVRMZuoCSfpN+GFfo5EpPACd5VV2asAKw/G+JnlkZozp2FqwUiuz2MyMTA/bpiNA8FP /uhScwqU9of7msQcUs0RSLMfAcjhdw226Pxn8s0V8n4CjppbpLxwAuvntwSiFxpLjbA2 pcmRRP643OFxHfwdNeVffdCCBG6XaRBWXxcCjvuidnKsuqLa7j9RmI8ohICniP6TJhDI FERVM7BvY/lViYwRv5CDf8ZBTyVQPoRRuNdXThd00kyj137d+EIDPGbH7zTF1fUS1n7B 6yfw== X-Google-Smtp-Source: AFSGD/XTMTjOndtTsiXcrd9fAIUCns/BphtM6xp91sNWu1YXSRoFffBVluebJhG/DoyPebkudZUydA== X-Received: by 2002:a17:902:a70b:: with SMTP id w11mr13818009plq.84.1545077897631; Mon, 17 Dec 2018 12:18:17 -0800 (PST) Received: from jordon-HP-15-Notebook-PC ([103.227.98.208]) by smtp.gmail.com with ESMTPSA id m19sm35920803pgn.35.2018.12.17.12.18.16 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 17 Dec 2018 12:18:16 -0800 (PST) Date: Tue, 18 Dec 2018 01:52:09 +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 Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v4 2/9] arch/arm/mm/dma-mapping.c: Convert to use vm_insert_range Message-ID: <20181217202209.GA8859@jordon-HP-15-Notebook-PC> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) 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: 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..7cbcde5 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) 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,