From patchwork Thu Jan 31 03:08:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Souptick Joarder X-Patchwork-Id: 10789575 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 A132D159A for ; Thu, 31 Jan 2019 03:04:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 95DEE290E5 for ; Thu, 31 Jan 2019 03:04:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 84D5C29194; Thu, 31 Jan 2019 03:04:03 +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 AB2AB290E5 for ; Thu, 31 Jan 2019 03:04:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B431D8E0002; Wed, 30 Jan 2019 22:04:01 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id ACBC38E0001; Wed, 30 Jan 2019 22:04:01 -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 970978E0002; Wed, 30 Jan 2019 22:04:01 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f200.google.com (mail-pf1-f200.google.com [209.85.210.200]) by kanga.kvack.org (Postfix) with ESMTP id 55D618E0001 for ; Wed, 30 Jan 2019 22:04:01 -0500 (EST) Received: by mail-pf1-f200.google.com with SMTP id e89so1384680pfb.17 for ; Wed, 30 Jan 2019 19:04:01 -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=r3ZyznqxsnQ3TNNkU3/a+vc/4Jb+njKidr9y0sWTaqQ=; b=D0NHnKUCIUZWKu6zUvwV47NCTRQlk4xPBiS8tLUc3cf8gtMj27i+2A0y7B1ozfTvH5 JbvfQS3kWBLpVlojNagesCDDeX5+blOzI44hqqjrJPWhieVbveEi/Ie7wKKsMJAOEGlT 5bK51KbDaDGdRn+W9xm+kOD+hKZPLV+dbSy35acihfISdEiecFEKMmYAgCHs1igopIv3 KsFiQJ1YUrAIklqvBElDNRenD2rNvAgMtQu70k+bRsSEU3UEHBN6DkPZFURa6es1VF73 FsZkVl/p4MTHA6QA3Rl7YZZJaWLEuZHiRxpyJwpOFcMJUkDnovkWqqHDXZ7Bf9VCJuLE NKkw== X-Gm-Message-State: AJcUukfiYE5Bva2rNQ4QdHOqC9pDJQM1yVhk7PQIBgJOaQ8sWz38dFPk ronETWhpxOEdGl4vgjHzTAQsP9E4fHQNg2ElLUYgQwmB5pTwCz5w0EVAF/9bTDTggbSOrbcGPav pybcTMNrWv+3YOs8wDg6wnTqZBYJoG+rf4sgvtCzMoJ5TRqyJK/hyyTHLcfPPh50VdzkHIC+by2 4cJmlvHdTgWMDkYN2sx9f9ttZ67GVPClN8OXaT0xitN/zRckrz4HQsds34iDAE8bVvdCP84LvI9 StjWV0fFBOSTP2WWr0etRcyqJLt6gkvB27+kFwM3iCueRMoOwyKl/0/q4CR74hgRwIchZofM+Lp TiYQiTL5tWoWns2wYETGO498CkQJDrnE5kLyvz9RxgCpxQ5xV4ZhUns31hvRTi005YiWELhAmJn u X-Received: by 2002:a17:902:a586:: with SMTP id az6mr32958666plb.298.1548903840868; Wed, 30 Jan 2019 19:04:00 -0800 (PST) X-Received: by 2002:a17:902:a586:: with SMTP id az6mr32958597plb.298.1548903839863; Wed, 30 Jan 2019 19:03:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548903839; cv=none; d=google.com; s=arc-20160816; b=D+gpuu9Nta98IKLdSj3k68jC6bjxBQu7yqGfS1HE0tsgIQq5Aiy/W/BLztiVRMksfc HmywtOsIni37QmkgHCkMIQBIhJDS+HXMHo8ZZgUwOMJZ7jx5lxeUvVmLQk0vjiOSK9Su pyH32grM83QVdI2x4GQpqy1u7WK0dG5//MNndHYmpwElvvglfwfERWd5FMlUSGDVmFiy 2WydygWd021sJ5ENJbNGZvxz6uZSI8WyDj+fte9kCBDMVHiNXe/PEwOVyqsYTb7MHZ/s LsZp6h3PXfKpii/wVUlh9wqBM78QykyZloSNFybLAg26oxGJ9EodyqLk5+ZL1GcxQA2R Qiaw== 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=r3ZyznqxsnQ3TNNkU3/a+vc/4Jb+njKidr9y0sWTaqQ=; b=qd4DrFIb+jpHw3VvqsMMvEKssVGPV18zrGwpGfAGe7z5c8WgBLiOhhbP7+vTAKWIAI fq2wqnN15wEV+J+g09eThjeQS94FOZrKgmV9NjhhaiEwJa7jnHy9R76ZxhQMQIdQPnfm KQa+xhhJ4pHR+YJ9Mh6BWlK0qehjZREFroSTLvf6P2qbUHUhVqby7JwBRvtPJFqpu0E1 tvEHZnqacg1F+EMQg2VW9SuhWla3Bpw2d2/968tZABnaYPrzWhU/ldPX/0SsfvCCxvfy gZhV1OrI+AY09Am/cHtfy/TZDYDjHxE/FX6s5Yw61XGfKOxuOGN164aVXnLnxPctxNco sz7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=PiHYjKk4; 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 88sor4850343plb.63.2019.01.30.19.03.59 for (Google Transport Security); Wed, 30 Jan 2019 19:03:59 -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=PiHYjKk4; 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=r3ZyznqxsnQ3TNNkU3/a+vc/4Jb+njKidr9y0sWTaqQ=; b=PiHYjKk4ZcYPCaHbgsFEKUnh3fVN4+u8o9GLS7YZQGeXUDDsXHAER0sbMrp2Nx10cO UbY9aiFmB+MSAtIADsbHRqLXyiSDw3GJK9fy286dp1LrInyNT31Ix6VrFQ9eNvYUnSiq 9WAFwTyV++sklgSo+DnkLuAFdcVJyc+p8fUh8+sunYlUazhewyRWPKv5kYFVMTmG7+oM kj03ngQ9CVzkxbfAeUvXTzpjoYCuSRZAeHl4zSHmtfC+OXoFWoECDc/g/G0jh3uGDDSF 1k1EJLOVh6E93hB2QYmTnqC/2vjgRM8HXm4sbhalGPXQb4ZmR3xkRUNg7kVPZITgPO3c NSCg== X-Google-Smtp-Source: ALg8bN77ulDzMTd0u5w2yF1CIUMFdckIxmL4CuhfCBgk9u/Rrp9Yr7EoBKetWq6gkN0hMfNxE8FzMw== X-Received: by 2002:a17:902:4225:: with SMTP id g34mr33628031pld.152.1548903839516; Wed, 30 Jan 2019 19:03:59 -0800 (PST) Received: from jordon-HP-15-Notebook-PC ([106.51.20.103]) by smtp.gmail.com with ESMTPSA id l184sm5303074pfc.112.2019.01.30.19.03.57 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 30 Jan 2019 19:03:58 -0800 (PST) Date: Thu, 31 Jan 2019 08:38:12 +0530 From: Souptick Joarder To: akpm@linux-foundation.org, willy@infradead.org, mhocko@suse.com, kirill.shutemov@linux.intel.com, vbabka@suse.cz, riel@surriel.com, sfr@canb.auug.org.au, rppt@linux.vnet.ibm.com, peterz@infradead.org, linux@armlinux.org.uk, robin.murphy@arm.com, iamjoonsoo.kim@lge.com, treding@nvidia.com, keescook@chromium.org, m.szyprowski@samsung.com, stefanr@s5r6.in-berlin.de, hjc@rock-chips.com, heiko@sntech.de, airlied@linux.ie, oleksandr_andrushchenko@epam.com, joro@8bytes.org, pawel@osciak.com, kyungmin.park@samsung.com, mchehab@kernel.org, boris.ostrovsky@oracle.com, jgross@suse.com Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linux1394-devel@lists.sourceforge.net, dri-devel@lists.freedesktop.org, linux-rockchip@lists.infradead.org, xen-devel@lists.xen.org, iommu@lists.linux-foundation.org, linux-media@vger.kernel.org Subject: [PATCHv2 1/9] mm: Introduce new vm_insert_range and vm_insert_range_buggy API Message-ID: <20190131030812.GA2174@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 Previouly drivers have their own way of mapping range of kernel pages/memory into user vma and this was done by invoking vm_insert_page() within a loop. As this pattern is common across different drivers, it can be generalized by creating new functions and use it across the drivers. vm_insert_range() is the API which could be used to mapped kernel memory/pages in drivers which has considered vm_pgoff vm_insert_range_buggy() is the API which could be used to map range of kernel memory/pages in drivers which has not considered vm_pgoff. vm_pgoff is passed default as 0 for those drivers. We _could_ then at a later "fix" these drivers which are using vm_insert_range_buggy() to behave according to the normal vm_pgoff offsetting simply by removing the _buggy suffix on the function name and if that causes regressions, it gives us an easy way to revert. Signed-off-by: Souptick Joarder Suggested-by: Russell King Suggested-by: Matthew Wilcox Tested-by: Heiko Stuebner --- include/linux/mm.h | 4 +++ mm/memory.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ mm/nommu.c | 14 ++++++++++ 3 files changed, 99 insertions(+) diff --git a/include/linux/mm.h b/include/linux/mm.h index 80bb640..25752b0 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2565,6 +2565,10 @@ unsigned long change_prot_numa(struct vm_area_struct *vma, int remap_pfn_range(struct vm_area_struct *, unsigned long addr, unsigned long pfn, unsigned long size, pgprot_t); int vm_insert_page(struct vm_area_struct *, unsigned long addr, struct page *); +int vm_insert_range(struct vm_area_struct *vma, struct page **pages, + unsigned long num); +int vm_insert_range_buggy(struct vm_area_struct *vma, struct page **pages, + unsigned long num); vm_fault_t vmf_insert_pfn(struct vm_area_struct *vma, unsigned long addr, unsigned long pfn); vm_fault_t vmf_insert_pfn_prot(struct vm_area_struct *vma, unsigned long addr, diff --git a/mm/memory.c b/mm/memory.c index e11ca9d..0a4bf57 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -1520,6 +1520,87 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr, } EXPORT_SYMBOL(vm_insert_page); +/** + * __vm_insert_range - insert range of kernel pages into user vma + * @vma: user vma to map to + * @pages: pointer to array of source kernel pages + * @num: number of pages in page array + * @offset: user's requested vm_pgoff + * + * This allows drivers to insert range of kernel pages they've allocated + * into a user vma. + * + * If we fail to insert any page into the vma, the function will return + * immediately leaving any previously inserted pages present. Callers + * from the mmap handler may immediately return the error as their caller + * will destroy the vma, removing any successfully inserted pages. Other + * callers should make their own arrangements for calling unmap_region(). + * + * Context: Process context. + * Return: 0 on success and error code otherwise. + */ +static int __vm_insert_range(struct vm_area_struct *vma, struct page **pages, + unsigned long num, unsigned long offset) +{ + unsigned long count = vma_pages(vma); + unsigned long uaddr = vma->vm_start; + int ret, i; + + /* Fail if the user requested offset is beyond the end of the object */ + if (offset > num) + return -ENXIO; + + /* Fail if the user requested size exceeds available object size */ + if (count > num - offset) + return -ENXIO; + + for (i = 0; i < count; i++) { + ret = vm_insert_page(vma, uaddr, pages[offset + i]); + if (ret < 0) + return ret; + uaddr += PAGE_SIZE; + } + + return 0; +} + +/** + * vm_insert_range - insert range of kernel pages starts with non zero offset + * @vma: user vma to map to + * @pages: pointer to array of source kernel pages + * @num: number of pages in page array + * + * Maps an object consisting of `num' `pages', catering for the user's + * requested vm_pgoff + * + * Context: Process context. Called by mmap handlers. + * Return: 0 on success and error code otherwise. + */ +int vm_insert_range(struct vm_area_struct *vma, struct page **pages, + unsigned long num) +{ + return __vm_insert_range(vma, pages, num, vma->vm_pgoff); +} +EXPORT_SYMBOL(vm_insert_range); + +/** + * vm_insert_range_buggy - insert range of kernel pages starts with zero offset + * @vma: user vma to map to + * @pages: pointer to array of source kernel pages + * @num: number of pages in page array + * + * Maps a set of pages, always starting at page[0] + * + * Context: Process context. Called by mmap handlers. + * Return: 0 on success and error code otherwise. + */ +int vm_insert_range_buggy(struct vm_area_struct *vma, struct page **pages, + unsigned long num) +{ + return __vm_insert_range(vma, pages, num, 0); +} +EXPORT_SYMBOL(vm_insert_range_buggy); + static vm_fault_t insert_pfn(struct vm_area_struct *vma, unsigned long addr, pfn_t pfn, pgprot_t prot, bool mkwrite) { diff --git a/mm/nommu.c b/mm/nommu.c index 749276b..21d101e 100644 --- a/mm/nommu.c +++ b/mm/nommu.c @@ -473,6 +473,20 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr, } EXPORT_SYMBOL(vm_insert_page); +int vm_insert_range(struct vm_area_struct *vma, struct page **pages, + unsigned long num) +{ + return -EINVAL; +} +EXPORT_SYMBOL(vm_insert_range); + +int vm_insert_range_buggy(struct vm_area_struct *vma, struct page **pages, + unsigned long num) +{ + return -EINVAL; +} +EXPORT_SYMBOL(vm_insert_range_buggy); + /* * sys_brk() for the most part doesn't need the global kernel * lock, except when an application is doing something nasty From patchwork Thu Jan 31 03:09:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Souptick Joarder X-Patchwork-Id: 10789583 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 19156139A for ; Thu, 31 Jan 2019 03:04:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 128E429902 for ; Thu, 31 Jan 2019 03:04:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 06B5329CEA; Thu, 31 Jan 2019 03:04:52 +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 1975529902 for ; Thu, 31 Jan 2019 03:04:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3F1A78E0003; Wed, 30 Jan 2019 22:04:49 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 39F4D8E0001; Wed, 30 Jan 2019 22:04:49 -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 240398E0003; Wed, 30 Jan 2019 22:04:49 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) by kanga.kvack.org (Postfix) with ESMTP id D454A8E0001 for ; Wed, 30 Jan 2019 22:04:48 -0500 (EST) Received: by mail-pl1-f198.google.com with SMTP id x7so1265717pll.23 for ; Wed, 30 Jan 2019 19:04:48 -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=9UKheLNLSM7085+hYajJxzL+Wpldb3TOma8RXX0hjL4=; b=scj8n5gtmWNJiKYB7C9ZjCcL3SGsBCs8lmuOh8hgOFZU4eo5igPH+lxGZf7u0LvYD7 vwdPg2iq/SQTzVr3xQK4ZCZHHJHv4c9NLezBb2OO6qmavN3oqcgT/7T2pFKPROenFqup XQPQ43OyJ9CsApaJFjCGNIPHtbT48g6zUpxxa4lLUSpZnCW0mD5lq0IkJK/J1yKbTbOR AY9UNe4F3jgJw7mJtHkQVAbywK16z2tzyY4/wSeUoTduumSY/O/hHm9xo9CwkOmQwVqX R0/KIc1EWaGLb7mBJvoEc+U0yH1Nvl7UJcqBLsR7m7s1S5rr38GMvi+xHlCaLG4pwD0z irfw== X-Gm-Message-State: AJcUukdH7vVHBOs/ENE13hkOY9KGExKmq4DXm04hRGj5y26yX3B3wtwo WyocjkJvKDDflJ+R3R7QVfvMeZCdd1CH4HXYV2rhmZzJk6rIRlcUjI6OxWFhlOvE6R63DCdBi/i sgZ52RzY2R3BV+1/KYRLK+h5/qNxngbV8b6L+/R1lotcIQZq/HEGIBcvQ4yeKxt9swJaCAaU0vv COa1C74PTZYp0K+Owfa54Yr9a3GDwYKAAl4tuxSllCIdFQxDphWgqIps1wNxhtiSc+oETz0rxJD YG4N4/EeUCKG3LaMGRWTZERjF3KNrHbSxd7wPcPr755wv/KUyWeFN7EjEDm7YjscSmhOTFoZ5zA 4WIZANWPektaHUQFy/3F9LHVhgcwbjBHIfhLoVK3msaqQGFBAPlBt6NRNiYuyVBZ1ZsrGZZm3YP D X-Received: by 2002:a63:5621:: with SMTP id k33mr30241917pgb.395.1548903888494; Wed, 30 Jan 2019 19:04:48 -0800 (PST) X-Received: by 2002:a63:5621:: with SMTP id k33mr30241885pgb.395.1548903887717; Wed, 30 Jan 2019 19:04:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548903887; cv=none; d=google.com; s=arc-20160816; b=UP9tOiw0K+3L2fM3aS7YRdJYzHG8MFSLictEpxynqMC3gDCuU6pqPddVM48BdJA/V4 hWy+uQlEzSn8PRbjuLLj7MY8bZY8bfR9cHgJ4fCEj29qdLsbXACACBFeAQpG5g6viI9S LydmAXCWB9NA4sqcyph96ER7vfrh/tR8Yg1nBQa0ufwE69et7cP0GE2BUJFv0jG7mGol pbncmXD2bIQgOjYPn4Im6iwepKp9TvO8z8slAI3i/5z4iQpnGXsuw9Coz/N4VMkSQGy7 05YiwjmNsolSIhp7SETGNGSgkOIUzSG1SZ+snYRI5EUjTzMPJJ1E8rrqHe8px2Bq5FnE AF1w== 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=9UKheLNLSM7085+hYajJxzL+Wpldb3TOma8RXX0hjL4=; b=UA4muo+ssqOLAGgzzATTUalc03x3Fq1Il8d7TQ6F/DAeNDTTfAszpI/kZysYRcAvIR WDReJFTqufDKB9Y5XQkkoQgONBQbzBhejn7le2cb7DFctnuElP/nDP40tCY8N5GDuu47 G6Uw/oKv5BqwHIghUJ2hmGgfuWIQKO2dGLikmf5kBbFzEwltvnbG7pW746rEsJrjokrW EISeQB5PEYQM6BAsM3niEP8MpfMC4LYEttZfMOadyx39WOcvn6NXrIsmkfqC2GLs73XR mJ5dFkakFd2vsxvlL8215G6xgJzWgl493U+0oCB5Hm0NxXI7v+b2RfxQqrjU50RFIRJN Xnpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=tSgjerC4; 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 w65sor4944095pgw.5.2019.01.30.19.04.47 for (Google Transport Security); Wed, 30 Jan 2019 19:04:47 -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=tSgjerC4; 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=9UKheLNLSM7085+hYajJxzL+Wpldb3TOma8RXX0hjL4=; b=tSgjerC4dK44S06W0OSTr53cNg28+6cUTE4HzPUKTdkevWVpDJ97JFTp+cPosrPNEV D8rphH0u8PJiDjdQsW2TNjafYIBoOsL1lTpSoOkAZyJOLs4Vo+jTdmYEwU7Jl7hXgk8u bhAoeiu1BDGFLMWPAWbdszIxVsMvwVSrmn9/NbkQyumWfBx94sOwPfkrdncoz+vMpmLN GvJIbeBoL5m3lTrGsdAHY7E5Ffo5FQtSCX5JwL9a+t7uCBTkj1fO/HsLuTpU2zXaDEU3 Ob05VCxwKCGE7QtPagY4Sd1s9LT8xNY41xJLt1okURF5K+hRbPJY9tnqbjP0VDuMbxqy h/+Q== X-Google-Smtp-Source: ALg8bN4FchuqbyYG65Y851K8FAAMbykpYxvta9bA6d520FyHakM49c32bL40WPlrtGU5T7jPX/J4QA== X-Received: by 2002:a63:7c6:: with SMTP id 189mr30429168pgh.129.1548903887364; Wed, 30 Jan 2019 19:04:47 -0800 (PST) Received: from jordon-HP-15-Notebook-PC ([106.51.20.103]) by smtp.gmail.com with ESMTPSA id o13sm4055072pfk.57.2019.01.30.19.04.45 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 30 Jan 2019 19:04:46 -0800 (PST) Date: Thu, 31 Jan 2019 08:39:00 +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: [PATCHv2 2/9] arch/arm/mm/dma-mapping.c: Convert to use vm_insert_range Message-ID: <20190131030900.GA2284@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 | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c index f1e2922..915f701 100644 --- a/arch/arm/mm/dma-mapping.c +++ b/arch/arm/mm/dma-mapping.c @@ -1575,31 +1575,21 @@ 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; 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 (vma->vm_pgoff >= nr_pages) return -ENXIO; - pages += off; - - 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); + err = vm_insert_range(vma, pages, nr_pages); + if (err) + pr_err("Remapping memory failed: %d\n", err); - return 0; + return err; } static int arm_iommu_mmap_attrs(struct device *dev, struct vm_area_struct *vma, void *cpu_addr, From patchwork Thu Jan 31 03:10:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Souptick Joarder X-Patchwork-Id: 10789589 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 EE4CB139A for ; Thu, 31 Jan 2019 03:06:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E546F2EBF7 for ; Thu, 31 Jan 2019 03:06:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D64032F0CD; Thu, 31 Jan 2019 03:06:30 +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 62E552EBF7 for ; Thu, 31 Jan 2019 03:06:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7BFF88E0002; Wed, 30 Jan 2019 22:06:29 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 76E7A8E0001; Wed, 30 Jan 2019 22:06:29 -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 65DB18E0002; Wed, 30 Jan 2019 22:06:29 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) by kanga.kvack.org (Postfix) with ESMTP id 25DB78E0001 for ; Wed, 30 Jan 2019 22:06:29 -0500 (EST) Received: by mail-pl1-f199.google.com with SMTP id 12so1279178plb.18 for ; Wed, 30 Jan 2019 19:06:29 -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=fve/F1/lKXEnfpzre5B+d6239UbIM50sDNUC8vj1UvQ=; b=UiU/vS/k/PsO2pufeDlkgKpUtwn3UKb+Um5dBviQDKD7DybJ3qA6zmXAAe4dEH1X7n psXZH6iMHT4cMnS3OnRr8MTva4StCCEXUV8KN+8OeYrzSjSnWBBJ/nVbusRHbbS+lLJ7 WiQj1nvEYqXbHsZRFittgdfmi4C8AltwhyUHSdUj+AfmGpl6YnW/nG1gNq1cLKB6Jho6 C6usg1eUh6xAA9bC3U8Ia8tui6gzjb8MQam5nr7Jnqx62FgQLvUU5NDgJNrFPq1VqUs4 uMNTciCTWDCOjD8m/0wjmmc+tjYbRpxFnD1Sh80AY6MwYb/rcA/MHMDMJot/R2CqLtMc eE8A== X-Gm-Message-State: AJcUukfpXcKJ/VSQw8Ev64IEmFa4DDgyV3puhwNQCnfu1D259//upVPW ZyIxZNUZ+pztIU4KxXQbodrSKZIJTNXdp+oa+K+E/Sd4ZajrW7tacyRAPw2tzRj1oWJ08zVAsw8 u6U18aKESPcpwTi4wfmDmkyfP5GEY0VjzMfRnDEOxBQxeLTxTUAtZRL0xI0l4UdkkayoEoMYwaB HnS5Xp+8rw67pdBDxJwUq/O2jh35yIkKlXZmpg6j+h0u27dfG8iWzIkaCpFPTEI0m+R0VnR3Zbp QKyBhhNHRPG60wQn3r0lAOCkqSwhCmt7LCptZNG+LaQ0dwEG4QIldHE7fKQXM2R2t+1CLlVFgAU 1DEW/04L7LamJhrGzcLHgZSHxy9kp0IN+/6vnXbrDUWa038pFxQ8UIt2EJy0rsluTTYmPBCbrKf 2 X-Received: by 2002:a17:902:5982:: with SMTP id p2mr32735660pli.39.1548903988826; Wed, 30 Jan 2019 19:06:28 -0800 (PST) X-Received: by 2002:a17:902:5982:: with SMTP id p2mr32735621pli.39.1548903988088; Wed, 30 Jan 2019 19:06:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548903988; cv=none; d=google.com; s=arc-20160816; b=KRHz4rAOak8QNMqhtd0/w/lsr8meODKYvQdBSx3+GQNJQqMXfzdnNJPoA68NrgbbIQ NydtZ38Pc3An3msD1MGgW62uxSude17gNpaNgSY+KsL75x0LDbwG1H5gIrYeIaq/388J iFsJ+tcmZs0KlFkehwPtxhKEidpWLQm8CRnsPWHH59dcr4JXkYI5AIFp4C85IeNCL1jj /vBWto2RN4/AyCTqAxARG+Ux7dk2gH2ZLZpQEc2HrOmlVfDhTbY4iNtdPqqPFKpPEdrx CJj2gvE0xBfPB53/q41PN/hk4Ma91fB4em8AyU+cB7Z4rfMR0miUnsz7k/sSaqRjbhoV eKYA== 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=fve/F1/lKXEnfpzre5B+d6239UbIM50sDNUC8vj1UvQ=; b=y+oU8rv4671uEB+tFHe2VN6OxmjL5Cz6A4jlLceLZmzxZc6hrvyRj/rujHzGtmdHje NHZ9VjnLnTommhHFc7Atp1NPmwmM03kJQqhVu23fssRKMv/3HxWGXVZwrKmbIwx7utgw PTNT9kimZCLirYd9Xy/Krh5CziYJHL+cn3sppqTwKSCXJeabG6we9kvlCmijCpNTYhCt Ksiqc7ol4Sv2h4s7vF6ZSPXzaZPEcEfdNwRyd8Un/8HpWwSW3iXtX4T1ptf0XKVL3X9W Zd5Vh1f425HAYoPDZgef5aqMOonCrWRudYhXVx6jy/cNRJ7TqAmPqUtCKTxOlQE9j8SG g5dQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=VJa1+zh8; 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 y6sor5422501pfi.19.2019.01.30.19.06.27 for (Google Transport Security); Wed, 30 Jan 2019 19:06:28 -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=VJa1+zh8; 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=fve/F1/lKXEnfpzre5B+d6239UbIM50sDNUC8vj1UvQ=; b=VJa1+zh8xHi3tI1io1YyR1jW4Ql0L2HM/0G/TqGLCYIRuEUfaDMSQLwWgfnv/q2VCK iMQgvcHSc2/MMEr41Z3VcXIJpBynXvCLMm+MCb5Ony0kLh1P+43S1EyOZ0c2VVcXfUDi zyUHlPc92S25kuxJL0xxi6q5K7621sWC7v7ZPljG/f/9EmAD7+iDx7aFSG3OZ8ScP0cF VzOGvcgsG44tSmhzqBnqDDYP/OTdVImNeD06R22jMcUhnzLmqtpjiveuyfIVjBd7x9Me M4s/fGqqA5tbzFW8w6RcVcyXN17XcXe3Wf1t1LgEPIqHODKKlYApfWHRPjE12iaJHekM stRg== X-Google-Smtp-Source: ALg8bN6rRzXK6nfBRBSHhIlA85333gGdTjbHnrt6wuJpi13BssALmTS8VMglE5ur30io8jYwjS7LDQ== X-Received: by 2002:a62:1f9d:: with SMTP id l29mr33146546pfj.14.1548903987795; Wed, 30 Jan 2019 19:06:27 -0800 (PST) Received: from jordon-HP-15-Notebook-PC ([106.51.20.103]) by smtp.gmail.com with ESMTPSA id v2sm4236663pgs.0.2019.01.30.19.06.26 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 30 Jan 2019 19:06:27 -0800 (PST) Date: Thu, 31 Jan 2019 08:40:40 +0530 From: Souptick Joarder To: akpm@linux-foundation.org, willy@infradead.org, mhocko@suse.com, hjc@rock-chips.com, heiko@sntech.de, airlied@linux.ie, linux@armlinux.org.uk, robin.murphy@arm.com Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, dri-devel@lists.freedesktop.org, linux-rockchip@lists.infradead.org Subject: [PATCHv2 4/9] drm/rockchip/rockchip_drm_gem.c: Convert to use vm_insert_range Message-ID: <20190131031040.GA2320@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 Tested-by: Heiko Stuebner --- drivers/gpu/drm/rockchip/rockchip_drm_gem.c | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_gem.c b/drivers/gpu/drm/rockchip/rockchip_drm_gem.c index a8db758..c9e207f 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_gem.c +++ b/drivers/gpu/drm/rockchip/rockchip_drm_gem.c @@ -221,26 +221,13 @@ static int rockchip_drm_gem_object_mmap_iommu(struct drm_gem_object *obj, struct vm_area_struct *vma) { struct rockchip_gem_object *rk_obj = to_rockchip_obj(obj); - unsigned int i, count = obj->size >> PAGE_SHIFT; + unsigned int count = obj->size >> PAGE_SHIFT; unsigned long user_count = vma_pages(vma); - unsigned long uaddr = vma->vm_start; - unsigned long offset = vma->vm_pgoff; - unsigned long end = user_count + offset; - int ret; if (user_count == 0) return -ENXIO; - if (end > count) - return -ENXIO; - for (i = offset; i < end; i++) { - ret = vm_insert_page(vma, uaddr, rk_obj->pages[i]); - if (ret) - return ret; - uaddr += PAGE_SIZE; - } - - return 0; + return vm_insert_range(vma, rk_obj->pages, count); } static int rockchip_drm_gem_object_mmap_dma(struct drm_gem_object *obj, From patchwork Thu Jan 31 03:11:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Souptick Joarder X-Patchwork-Id: 10789595 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 B93A6139A for ; Thu, 31 Jan 2019 03:07:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AD5AA2EDDF for ; Thu, 31 Jan 2019 03:07:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9C9C22F61A; Thu, 31 Jan 2019 03:07: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.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 38CE92EDDF for ; Thu, 31 Jan 2019 03:07:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4B09B8E0003; Wed, 30 Jan 2019 22:07:31 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 4600F8E0001; Wed, 30 Jan 2019 22:07:31 -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 37A798E0003; Wed, 30 Jan 2019 22:07:31 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.200]) by kanga.kvack.org (Postfix) with ESMTP id E92EB8E0001 for ; Wed, 30 Jan 2019 22:07:30 -0500 (EST) Received: by mail-pg1-f200.google.com with SMTP id f3so1186259pgq.13 for ; Wed, 30 Jan 2019 19:07:30 -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=2owR9Y+Fu1XiPkZWSyijL0gEQb0pHlWrbxT50sCCie8=; b=X/JnwqYZk43/b20RJQBwScieCi+qtr8TueVLICtOSXwOKGakfJN6pumKfuFk+WpZ7I NV5nOYhyjrcjR+SK1DriedJfY0X+ad4SkbahOcslaqrrArERe3Wn9GUtU2u8hrAAGluP SKbeYOPU9Tt3V6Mu+LRLOYepZcaUR/J9xrJFwTdygfGHADB0C6riLEbchQPI0cvX1UH1 Ijne5339ZcriIxmp4VANLB6+jLknj/GSCjIfzlC+5SHoiDKrmRxBwSocLzbofHsiJuJ6 zDfRs5T+F2TNJ7HUpyKcPS4p+gXD5PPV9aBt2WSGOaxbe/6NJuSyyawTaaxgFsgxgM6n ntfg== X-Gm-Message-State: AJcUukfPtTRsGpSCMUbC/AVV+rzoqt7Db8s3FIYVgJgLJtdnblRoG/nA CQFsYRrduR7qKq8PZQ/OPH519XX8kZF9BkIShckX/0kFYgGED1vCz52Jnj3XYhtF7aiK6Im+hPv +K7VHVRasXFuM7O8LEv57BEqyTcJSpncvWCETE2p7GeeDSLibZ1QapW3qZ8S6t0lOONAEsg3CPc 9pf9l3v99ukVJmeARn4nq7iRB7bChYbjJu1kjghTJIPgPxTDsAapb/hQu5ldb9k9VM263diYv6Q ct6g9y7f5xZl4DeOsWL5iy53jxM+SQx8HbvOo21//iFcsipIke+6qM8eROb7FrxH6dOmWxwrokJ /BmNDL1nCKn5SEzfbCwwl/N+z0irP5WiLcNsenNqzrt2c2MMEb6BV7f24FvoKrfEV3FGuS+ThQq p X-Received: by 2002:a62:31c1:: with SMTP id x184mr34015356pfx.204.1548904050615; Wed, 30 Jan 2019 19:07:30 -0800 (PST) X-Received: by 2002:a62:31c1:: with SMTP id x184mr34015331pfx.204.1548904049886; Wed, 30 Jan 2019 19:07:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548904049; cv=none; d=google.com; s=arc-20160816; b=yKjzqntj9Zh2vJHr9cTJr1YSJEwJ1DuP0/kXmZF4MdixN2ljqr1fbZgzuvw9mV5QSL Lk3NuIXOQc4S0sDJNPl9RzAtKFxha7sg2aS6Pm+Qu9VZDLX74hYVkSwbcvgeC1D2HiQx H8a5eGxmPRSBSYHtVe7hvBXfONY89UDRFimMfnriE8amV0VxkkSebZpDHm0uN7CGUEYX cXXOoMHECU+trgeV4VPvsO9AfpI/09C95qzY3DjQYmId/2K/stLparUAqqULnBrcZAFt VynetViGsWu881FyhEn7opk9UMgGVsnTZe5oNKx92EP6O20sWSKyMXclUfTYAcOV5DSc qKqQ== 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=2owR9Y+Fu1XiPkZWSyijL0gEQb0pHlWrbxT50sCCie8=; b=Df2kL0vrBSZcF5rjBDZO/A7SB8m9baGjI03rmjnazpNJk78/k+AJED7FcbA0fX9vFz Mazww8FTW2wrxIFHVXonl35hjmiWCOngc4vCtumOvT7D16uuAUmAiBTwbg2fCzXRXLHV t1iAQS4YlI6BpkdzhUM/rgLnlLfxC8rsS0UexA2Vdy7Hc9/hCMRYgKu8KGmWcqAF0zs1 0kAQqdNsxNRoe+xXYhMpEon+aPW4nH2rz8brhvWoF7bI9IwxxYK7cGbUkfru46fvLVAq KJ318jtj6vlhpI30JV0oNwQldYBW+Ysm54vWeVu0MqbXhUofPe+zAMZZe0deRhnicKfE X+Bw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=NZQeve9z; 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 z6sor4945360pgl.57.2019.01.30.19.07.29 for (Google Transport Security); Wed, 30 Jan 2019 19:07:29 -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=NZQeve9z; 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=2owR9Y+Fu1XiPkZWSyijL0gEQb0pHlWrbxT50sCCie8=; b=NZQeve9zbX4Ge5xvXA78Atzzs0uz6ecZSf2jwkaGy9naKq9UQ0tGyf9387X8jWOLDY 4ZExfwm2IiQfWLdL33XwJ3bqjuvWu3hYYxHJMPAMFEaVhAeOUc/0AE0trX9/ICzKCOpS i+ewoNERn06fUr3RKBdUL5yInvTYP9sftxNuXJaahmRL+kntme6zlalSzoLx36Tmhh8C VinMhm7g3UqnH8SQWO1LKsOibcKBsobp48bdEEKBNKNSZzue/f6r7SLEkykVE53pLDdT dpMFxOI4SJeXn7LVUGa+EVhuKWGKqicsil2CZOCmz1DHhwtAFNoCWpswU1DfJptM3n6G R9Ag== X-Google-Smtp-Source: ALg8bN6J223zMhkVRUiamGrLjZpFQzF4EOI76I5mSAxon5PpAWsE/WAQPINgw1LsAAmjinCuk+7zEA== X-Received: by 2002:a63:7512:: with SMTP id q18mr27636577pgc.231.1548904049578; Wed, 30 Jan 2019 19:07:29 -0800 (PST) Received: from jordon-HP-15-Notebook-PC ([106.51.20.103]) by smtp.gmail.com with ESMTPSA id v184sm3913763pfb.182.2019.01.30.19.07.28 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 30 Jan 2019 19:07:28 -0800 (PST) Date: Thu, 31 Jan 2019 08:41:42 +0530 From: Souptick Joarder To: akpm@linux-foundation.org, willy@infradead.org, mhocko@suse.com, oleksandr_andrushchenko@epam.com, airlied@linux.ie, linux@armlinux.org.uk, robin.murphy@arm.com Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, dri-devel@lists.freedesktop.org, xen-devel@lists.xen.org Subject: [PATCHv2 5/9] drm/xen/xen_drm_front_gem.c: Convert to use vm_insert_range Message-ID: <20190131031142.GA2339@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 Reviewed-by: Oleksandr Andrushchenko --- drivers/gpu/drm/xen/xen_drm_front_gem.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/drivers/gpu/drm/xen/xen_drm_front_gem.c b/drivers/gpu/drm/xen/xen_drm_front_gem.c index 28bc501..b72cf11 100644 --- a/drivers/gpu/drm/xen/xen_drm_front_gem.c +++ b/drivers/gpu/drm/xen/xen_drm_front_gem.c @@ -224,8 +224,7 @@ struct drm_gem_object * static int gem_mmap_obj(struct xen_gem_object *xen_obj, struct vm_area_struct *vma) { - unsigned long addr = vma->vm_start; - int i; + int ret; /* * clear the VM_PFNMAP flag that was set by drm_gem_mmap(), and set the @@ -246,18 +245,11 @@ static int gem_mmap_obj(struct xen_gem_object *xen_obj, * FIXME: as we insert all the pages now then no .fault handler must * be called, so don't provide one */ - for (i = 0; i < xen_obj->num_pages; i++) { - int ret; - - ret = vm_insert_page(vma, addr, xen_obj->pages[i]); - if (ret < 0) { - DRM_ERROR("Failed to insert pages into vma: %d\n", ret); - return ret; - } + ret = vm_insert_range(vma, xen_obj->pages, xen_obj->num_pages); + if (ret < 0) + DRM_ERROR("Failed to insert pages into vma: %d\n", ret); - addr += PAGE_SIZE; - } - return 0; + return ret; } int xen_drm_front_gem_mmap(struct file *filp, struct vm_area_struct *vma) From patchwork Thu Jan 31 03:12:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Souptick Joarder X-Patchwork-Id: 10789597 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 8EB1C17E9 for ; Thu, 31 Jan 2019 03:08:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 87BBA2EDDF for ; Thu, 31 Jan 2019 03:08:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7B8612F61A; Thu, 31 Jan 2019 03:08:12 +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 0950F2EDDF for ; Thu, 31 Jan 2019 03:08:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 28D348E0002; Wed, 30 Jan 2019 22:08:11 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 23C568E0001; Wed, 30 Jan 2019 22:08:11 -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 154C68E0002; Wed, 30 Jan 2019 22:08:11 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) by kanga.kvack.org (Postfix) with ESMTP id CACDF8E0001 for ; Wed, 30 Jan 2019 22:08:10 -0500 (EST) Received: by mail-pl1-f197.google.com with SMTP id v11so1312228ply.4 for ; Wed, 30 Jan 2019 19:08:10 -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=iec/iwyk+9yIyetIpSnDlz9q4nLWbzvs4Tb+BjkPjDE=; b=pO80iymBfVBu4Fj/Qv2yfwGe+1/wApqNqoaqVn9uTuqKx+J3AT+QDUyFu3hL1U/+lk VEuRbV8pclPihIWcf7qIgikAiFSXBugKGZ8+v1tgKcd3OJhsgXrBXg2F+TtXldu0bFkb stZ9PDkd0zMxQbQj4oqeIiL5+9r3o9IR/qkG6TAduqfUTEZxnDV3xzhf3Cv4830+uCYl HHQS8GqsAflVZQMi0RFEzMMWlz399x0grysIJactZ68ku3ea0cD3HFinW4mO9vhF8bQU C9W2XDco5HjKW/JKNyv5eNuzfHk4UhZDzgViLXrSc/Y0MUO/YD8QcxSY0ODMlG8ek/O+ auhw== X-Gm-Message-State: AJcUukdw17l/DLVrqU7EVo0egVIXFQBNczpBBLF21EL6pAHwSYK/nWde sXHEznXnj63wU2STDfdCp/DYyAk2uPJNJpETw94Rl2OG62iLniDSltQqgyAEFdCFIvDyYW/ODK2 JEqUVNnyRMKzWlz/yReOStQ+oPTvECWYlumqHL6qjvpXC+zYNp9BUgpyRDndnK0LkBYmNt2PVos 0Ctl+Rh5NnQvhMxzvLEeCRiMh4gAN1ie+fyh5rdqePLDmxOsdHnRKA28HJ2RVW57xuamhSAihLB 9QgW/BWGBXIyDK9xo37jbJsDX7iQ7vUIeOGxh0sBWtztWesbrn46ifEeXwp8Hpp8//O5UHcBXqq coXjnRZFiNS+DLPmbhTpt7HP7Gc6tnynEjg9G8F/6Ir90dMR8aj9DrL3duMX4W/MUrAmCs78Jbw 3 X-Received: by 2002:a63:8f45:: with SMTP id r5mr29571948pgn.222.1548904090485; Wed, 30 Jan 2019 19:08:10 -0800 (PST) X-Received: by 2002:a63:8f45:: with SMTP id r5mr29571923pgn.222.1548904089821; Wed, 30 Jan 2019 19:08:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548904089; cv=none; d=google.com; s=arc-20160816; b=uu8yXQGhjCruVwYF7UwK+9gvnsWdh6Is9PdL7RXsMbq7xtUPQraJ0kOQdCgVu6Uol7 gOWl/3eCMnRXO/vARg8RFPnAxf3xMK3qxwc/+vpf30Ce/NIyB+7Y/58tkVLVJJYLmOuc /m79OjqCJ75yWrHw2uqyl0nZqpWcQGWYOe47ZTXBRWUccyFRsW+rv6g79zOcjrPEB+qi yFIcIpgRPuvfIzwRKTiuoUzMSLdx5ULFFPGP/i1S2soqthBTQKIrofL/QGtAKJG3ECzP X6KL05H3j8cJUAIiSZFnjunJux/765rPGE1HGhCWM9Uj02tbMHUOGFMAFMMjSAdkS/Lp M3TQ== 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=iec/iwyk+9yIyetIpSnDlz9q4nLWbzvs4Tb+BjkPjDE=; b=qycb3EtvMv80od1BPgXuQZvwFji+4gelxYn971+Dt1CrAyYyqED1RvSeenj8KdTR1l GEy78FnaY6OH1Igiv8OaxGA8rWlS7pmh2lQwKq+Ksfm5oKtKGoHKQRdpQJRnARnlY3RC hEIV+cdK/qxo2Fg55rpMqPmMLuYOyMk6ki/F6xhCx1ZXgBZCOdtOXsjpmSRPIgtJnzTW Z3O515VsJDRThiUEMakD8fVh4fQPc8deVmylhj8CFEE92khyY52+Oe6GcimrTnsAjEFf 7hHEAev05NdvNypvAYA5oNmvvRz5rq8TQngEDNcB3Exe1hTI6bSMm+SikngVmH5EjKOo VyCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=btJPnHFF; 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 t190sor4925804pgd.31.2019.01.30.19.08.09 for (Google Transport Security); Wed, 30 Jan 2019 19:08:09 -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=btJPnHFF; 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=iec/iwyk+9yIyetIpSnDlz9q4nLWbzvs4Tb+BjkPjDE=; b=btJPnHFFmNfaReq5/e7TkaGbwn15giRl9XlitU46PRtF/0teXo0bWC1peOMGRPqPA8 hxAb0yGT180I0FDMfC86c/tvU+9G6qZ1Rx1ilqWyX4vHBBETh7UPpSVVyUGUHQV1uQQo Nd3mIgmXCAbNkh8lBEMTntnGXxdqSwKzraFTYyTORHy0zOogKhLvdaw47rbsjlLPPuRs aeqhr8e4CwkRDvSeOrC7vIPstO0GVYeSubKCmIlkrToB20gf51xWHeogaA5+SVliS+ZB SoSvM7OtvGHYInHjKr77zMMAlEywrAABgpKu1dA0bjh0cumvwJ/m0hgNXUPCXOF1J3H7 mDkA== X-Google-Smtp-Source: ALg8bN7nn3ngJBjBBd3F3bgclAbBF0cXBwm0q+GBXn5HYfScD2qZEcAMQ9j5PQSYrWPibjpeeIgmmw== X-Received: by 2002:a63:1f4e:: with SMTP id q14mr28672360pgm.88.1548904089076; Wed, 30 Jan 2019 19:08:09 -0800 (PST) Received: from jordon-HP-15-Notebook-PC ([106.51.20.103]) by smtp.gmail.com with ESMTPSA id z13sm3977258pgf.84.2019.01.30.19.08.07 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 30 Jan 2019 19:08:08 -0800 (PST) Date: Thu, 31 Jan 2019 08:42:22 +0530 From: Souptick Joarder To: akpm@linux-foundation.org, willy@infradead.org, mhocko@suse.com, joro@8bytes.org, linux@armlinux.org.uk, robin.murphy@arm.com Cc: iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCHv2 6/9] iommu/dma-iommu.c: Convert to use vm_insert_range Message-ID: <20190131031222.GA2356@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 --- drivers/iommu/dma-iommu.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index d19f3d6..bdf14b87 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -620,17 +620,7 @@ 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; - - 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, pages, PAGE_ALIGN(size) >> PAGE_SHIFT); } static dma_addr_t __iommu_dma_map(struct device *dev, phys_addr_t phys, From patchwork Thu Jan 31 03:14:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Souptick Joarder X-Patchwork-Id: 10789601 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 5DEE3139A for ; Thu, 31 Jan 2019 03:09:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 56AD13002D for ; Thu, 31 Jan 2019 03:09:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 48D1430051; Thu, 31 Jan 2019 03:09:56 +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 D280C3002D for ; Thu, 31 Jan 2019 03:09:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EE9018E0002; Wed, 30 Jan 2019 22:09:54 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id E96C48E0001; Wed, 30 Jan 2019 22:09:54 -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 D86708E0002; Wed, 30 Jan 2019 22:09:54 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) by kanga.kvack.org (Postfix) with ESMTP id 9018F8E0001 for ; Wed, 30 Jan 2019 22:09:54 -0500 (EST) Received: by mail-pl1-f197.google.com with SMTP id t10so1299751plo.13 for ; Wed, 30 Jan 2019 19:09:54 -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=+gTPMCxXNjJoF0/n+ZWKrD0/ywZQWm6nRUnBrn1+xaM=; b=WBfrv5iQtQ2rfnfIWu4ZMkkl3Jg8LjSYzbeZ3p0ey4P7BmfF6hUJY3y4lFePvt1XH3 83Q5WDuRtjwClmWwg68ZJDrKmbCvb2M6QHJWdP/U3T74UlpSsGnOYkoEfhMCxD0Wx1F8 OprzUymIoI7DSZkZz/8dCmI7qMvdvgh5kLpNGn5FEPYvTs6JYJ7137Rb/ZHm6jnbyzm6 IyHItEe70AuK7rGk3iqp1DAClY6mIBBleMkm76lvjrPGurrEWBRhAqYNWyifFIcWr3Rh TkhYKYNqSclFIVNl/UvUSb8/SARjneZeKxDiyXnAxHTpqaXVuNx/VyQ7yVpwhfopwCL8 vzJg== X-Gm-Message-State: AJcUukdQzEU5YMJuXvjG/K1Haki86knCSzgSpx8Z9cevIoHq9mfRiusV ObQ95i3Rz5iLrfGtCQdDxYktNVxOB0JXKjFV/INicsZmYsm38q17ZrkGmDdVeWmJ6b8nSCGnuwX o3qWcdUk8PO9LmaMin3YuSvnZrSYS0HW+kFFJcAJHabdrWbe/tPw5KxvMItge6Y2gp6/dbKCpcV mvsigtnXCY7mgLfUFfZlsZonaoFQMcyF0DCX3oUUcVQcxcTxTv2wUZTZJYb1Qf8mq1mHsCz+FQX dXcVCqiycCBXODioMux/AagtT9G5oysfiYghshEqvmiw6f8yqP6fXDiJjd0X8kQYtGrPILZ0TKd GkeUUoyDJGRp9fzmxohs4jb3SUjj9k2uD5fwx+dzLU73V0egMzlou6zmS/s04IspS8U/BNiFAjO M X-Received: by 2002:a17:902:5a86:: with SMTP id r6mr31912663pli.301.1548904194212; Wed, 30 Jan 2019 19:09:54 -0800 (PST) X-Received: by 2002:a17:902:5a86:: with SMTP id r6mr31912631pli.301.1548904193576; Wed, 30 Jan 2019 19:09:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548904193; cv=none; d=google.com; s=arc-20160816; b=AnUn71jINo3lblxBh5v8KRTxfFCPGt2m1Qi/c1B2FJKQHluPogLqZomG3YN5KkKHSP qNpPJlB5v/qix3ZWrwwVaLjtlt5+IpJy1u/T37Clk4f2WvOFKxI1NsEr99+Y9sHl9vaY pztiaiwfcth/3KXDFV8Hj6Cue56q4B0L2bPQigkuHgcPKGtm79JIqZp0dC/PgvHHeync dKq9bAhPeup1umD+u/g4cW2wP+BOhLizgZ5VJ+LuVGkyQdUVsxP5pOeXKYTh/+uqcSYd guirNlntrjZBw4sZEUPaUmzpznrItdVSvkjMofZVKdVi3ENYEHx6BF+qqG+CZc4Zl9Kd rqfA== 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=+gTPMCxXNjJoF0/n+ZWKrD0/ywZQWm6nRUnBrn1+xaM=; b=vge0cmYycjGGbKG0gurxXlaeHJdEbrc1qNyopisTgDUsH/ODVH0unTQhe2s+AoPsJL WreCQEOp8rCWES5YxPrNsbeA53HDzYZk/BtbTry9DVBRYSTZNDhaTWXsNMKg4iqaGavt NZOaCviJ8s5PgURREIF9Udke73+ulQ4cHSe2jq9aqje1B30w8UsRcISQixrCeU/rsSOs rYc1M/Nn/ZCaExFgSNFrBiu14Gf9ce63dIGmxr7Of/kimaO98oDNTLuWKMDqdw+CUmdY wLy8mbKIFoyc8CfSt+OMGbXhKejzBPrXdLGHntjCZ8NcNHU57ZCKFq2H5fYaIxZ9i7DG SU+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=mU6lU6IJ; 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 u69sor4938463pgd.63.2019.01.30.19.09.53 for (Google Transport Security); Wed, 30 Jan 2019 19:09:53 -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=mU6lU6IJ; 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=+gTPMCxXNjJoF0/n+ZWKrD0/ywZQWm6nRUnBrn1+xaM=; b=mU6lU6IJNCLpuAcuJxrPEZ1u3GAeO+o0KiIBw8WOJ7nHkvQ/IRblpfpIe7nKGE7SRS Jg/T/3v0UNJFS2ktWc5+OgfeOuKABQn/qSDh9+tKHK1j6397KBeQm3i1CVZMMARZoL3u B6B8kBVJCO7f7uHnWzxHim/3AfChVmfnNtnvesAqnmMkFkGOnxIO+M8Df5usoBeDldYE g5trqSbU9wGgzK5DmVX9Twt/Nu/aUuItzZvMs4icY7h8Xm9U4Ns30dICFjWvsRwcLg0j PCwe83KHpSqzmkWOFkQH0lWMijXrL5IVqPElMGZbADLzAoDuWK5KCHbF4SBiqNu0V2H8 0VGQ== X-Google-Smtp-Source: ALg8bN6YIgFd5TO8T3mweJGXLOhL/Ot0Mn0pImW/qnzib4a+Il1p86aJ+miihranjEIIU0R7Kc0BbQ== X-Received: by 2002:a63:6b05:: with SMTP id g5mr29145840pgc.15.1548904192746; Wed, 30 Jan 2019 19:09:52 -0800 (PST) Received: from jordon-HP-15-Notebook-PC ([106.51.20.103]) by smtp.gmail.com with ESMTPSA id 5sm8349874pfz.149.2019.01.30.19.09.51 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 30 Jan 2019 19:09:51 -0800 (PST) Date: Thu, 31 Jan 2019 08:44:05 +0530 From: Souptick Joarder To: akpm@linux-foundation.org, willy@infradead.org, mhocko@suse.com, boris.ostrovsky@oracle.com, jgross@suse.com, linux@armlinux.org.uk, robin.murphy@arm.com Cc: xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCHv2 8/9] xen/gntdev.c: Convert to use vm_insert_range Message-ID: <20190131031405.GA2418@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. map->count is passed to vm_insert_range and internal API verify map->count against count ( count = vma_pages(vma)) for page array boundary overrun. With this count is not needed inside gntdev_mmap() and it could be replaced with vma_pages(vma). Signed-off-by: Souptick Joarder Reviewed-by: Boris Ostrovsky --- drivers/xen/gntdev.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/drivers/xen/gntdev.c b/drivers/xen/gntdev.c index 5efc5ee..a930309 100644 --- a/drivers/xen/gntdev.c +++ b/drivers/xen/gntdev.c @@ -1082,18 +1082,17 @@ static int gntdev_mmap(struct file *flip, struct vm_area_struct *vma) { struct gntdev_priv *priv = flip->private_data; int index = vma->vm_pgoff; - int count = vma_pages(vma); struct gntdev_grant_map *map; - int i, err = -EINVAL; + int err = -EINVAL; if ((vma->vm_flags & VM_WRITE) && !(vma->vm_flags & VM_SHARED)) return -EINVAL; pr_debug("map %d+%d at %lx (pgoff %lx)\n", - index, count, vma->vm_start, vma->vm_pgoff); + index, vma_pages(vma), vma->vm_start, vma->vm_pgoff); mutex_lock(&priv->lock); - map = gntdev_find_map_index(priv, index, count); + map = gntdev_find_map_index(priv, index, vma_pages(vma)); if (!map) goto unlock_out; if (use_ptemod && map->vma) @@ -1145,12 +1144,9 @@ static int gntdev_mmap(struct file *flip, struct vm_area_struct *vma) goto out_put_map; if (!use_ptemod) { - for (i = 0; i < count; i++) { - err = vm_insert_page(vma, vma->vm_start + i*PAGE_SIZE, - map->pages[i]); - if (err) - goto out_put_map; - } + err = vm_insert_range(vma, map->pages, map->count); + if (err) + goto out_put_map; } else { #ifdef CONFIG_X86 /* From patchwork Thu Jan 31 03:14:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Souptick Joarder X-Patchwork-Id: 10789603 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 10352139A for ; Thu, 31 Jan 2019 03:10:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0A625304D7 for ; Thu, 31 Jan 2019 03:10:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F324530570; Thu, 31 Jan 2019 03:10:43 +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 C143030560 for ; Thu, 31 Jan 2019 03:10:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D881F8E0003; Wed, 30 Jan 2019 22:10:41 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D105D8E0001; Wed, 30 Jan 2019 22:10:41 -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 B89DB8E0003; Wed, 30 Jan 2019 22:10:41 -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 6EE728E0001 for ; Wed, 30 Jan 2019 22:10:41 -0500 (EST) Received: by mail-pl1-f200.google.com with SMTP id b24so1300441pls.11 for ; Wed, 30 Jan 2019 19:10:41 -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=iIOMyeYWlqivChsy2LGI2papAkfM6upHHEb8AWJyE+Q=; b=szSGMPtfzS55+aWTccuohxMaErS7wudNDK1kLNPSHC0XNJAfdpc/dONt4i3OPIETZo qxQrRTTVY2juZ4xaAvvXOVdIfPehRwO8wffLX1gRDMLXeG9+Ggxuxf+jrT9RG0UBFh9f 1iSIWNFOp6r6eoVfubmC3SKykRoaPl80R2J0S5t+Fnb/QWfg9zfTyVVs9gTSB7pFf0N2 FPAl21N6e82epGbDajADFEDEJHVE1dnyekQfekSioZIobsvTe9PVUfHd1BEaBk74N4BV roN1RvwxTjlK10xNv2NcyqSN5pS4hbwKyXnCPeqKGgR1chhMYpyQuQLcxtuycTHmfZqf nyTg== X-Gm-Message-State: AJcUukeKMWhI30H+tp0uog23CSScGSsoDfKPkwxBuJLp9E5Ug+k73Xgt uHVLZAdDlzgdU8nhEYEXgs2GeKvaOBud/K+XahIEawTMp+qZl/o5G4uZXYriTXnMlsTlOzODW97 raRSr+JEtCHYEIe/ENXaJyHsy8Af/+gRvscl90dg9So3p2joyyNVEHZmCEqc7mR75ia/SdpEfz0 G5TkP9uQSRtagpPfALGOx6vueAms7jS1kAt5k4qVf4OnXVdA8AfLbICkpgkW/AmROYKTJfMeb+q 7bZZpakF1gASlqPu1DX1z/kZSF5K76tGWbyLFWJ+Wl+Y3jxp6c+Tu9dcqqTXCc/8X3zIavgeYeY uK6y1wkQiP/vN6i+d86Bn6iF9p4pHwhNuWW7lsC0wm0QCIUXk2vJITMgXr2GyrMRNRI/5MRu0QL O X-Received: by 2002:a17:902:2bc5:: with SMTP id l63mr33590199plb.107.1548904241116; Wed, 30 Jan 2019 19:10:41 -0800 (PST) X-Received: by 2002:a17:902:2bc5:: with SMTP id l63mr33590168plb.107.1548904240464; Wed, 30 Jan 2019 19:10:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548904240; cv=none; d=google.com; s=arc-20160816; b=moj2KM/Z5AbXnDRY2Ic5+ccvE3YM+g/Rr+KaGBEWQMnMtEgy1hTyMlb23vtxDetLm1 wcHmwv5VK7Wdsy7inr5cK3FZ6boql5TsimRK3L42xNePe0depAuVhHJ9EcQJK/BmJzaw BwQ7izDXAgPcc5nUh/VUbm9uiOLPHjaE64dBWL/Pk6JDRHy5aUGfLrKH60Iy3+idEik1 X2qw9pbYP9AHM3dMwXJnlVKbom+7HeklBEMc5K5wkU1e32ot0t8RxFYuoZtaQFIyzHeY F19pBYNsznLb+KH7BjZyIdZ/oKbj0p7qNjYfmGNbDwCnKP8kE10+61GjwVKRXnTUCMdp r3hQ== 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=iIOMyeYWlqivChsy2LGI2papAkfM6upHHEb8AWJyE+Q=; b=FcEEzICNiLAqrBnR3nYo4V7Jd2G0J0pFj/cAS1gI1+oxkjLKXtDjli5mYWwNV0rBgE LiIjFqY/qEKCdDD93DHMQV7FSz4dWz8O3w4JUWz/O8ajZE56eH8dyJty8CkfN1p9utAI gaZZGJeCI5ts09kwUD346qF3JkUX9orwBsC3bhLNaLSUeFkInZZYN4RRflZJ9yOhPdLP 4qwAgOsmfrGrc0jLy5Nl32jYqOGYhuNjj4uSr24INcBCv4GhkwrNEh7PQ63A5QWcU//l 9wwlAwRfyV3mTT9mZJNbMvwVT9pygKjYDUVOsaCFyCDfA5jwl4dpDTPuX8Sizses2/Qh z7eQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=NswK+pXy; 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 p3sor4978675plo.56.2019.01.30.19.10.40 for (Google Transport Security); Wed, 30 Jan 2019 19:10:40 -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=NswK+pXy; 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=iIOMyeYWlqivChsy2LGI2papAkfM6upHHEb8AWJyE+Q=; b=NswK+pXyki9uV20jIt/KHa7HuTuS4V54Zl/q2CrjDYOjRi1VObkIq30U6glKytirnt 0uFEr/8IylNweVdpe6nAdkmQlUPc799Ng9XtT9HQWQtcaLU0vx0CH9uUKToZ0dcHIRRz OFVjx5BG4zF32ejxpzEAhCQwoiiyqWhNOBnox42mca/EHqg56YYWJ57EMdY5Dk7uHoNG 1HnE1nbkcSa83Nzgv6xfPIkaG/VWmkT2hfc6BC5eKGqTkwfTAf8pJ4CnIVedn5x6zrD5 31z46YUAOPYiqGZEOMosBhObBe9Bewwh7SZJ7fyrkzS6ImMft7hMC24e0ZOxrrmU+AXX zaXg== X-Google-Smtp-Source: ALg8bN7JWTDtmY7f0SD7kzOXbcjmQSyCFO1iAegZ9zKD6pwUOUT9KVciGd4lF1sfXawzVQ673btnEA== X-Received: by 2002:a17:902:4503:: with SMTP id m3mr33506912pld.23.1548904239727; Wed, 30 Jan 2019 19:10:39 -0800 (PST) Received: from jordon-HP-15-Notebook-PC ([106.51.20.103]) by smtp.gmail.com with ESMTPSA id a65sm3802656pge.65.2019.01.30.19.10.38 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 30 Jan 2019 19:10:38 -0800 (PST) Date: Thu, 31 Jan 2019 08:44:52 +0530 From: Souptick Joarder To: akpm@linux-foundation.org, willy@infradead.org, mhocko@suse.com, boris.ostrovsky@oracle.com, jgross@suse.com, linux@armlinux.org.uk, robin.murphy@arm.com Cc: xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCHv2 9/9] xen/privcmd-buf.c: Convert to use vm_insert_range_buggy Message-ID: <20190131031452.GA2442@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_buggy() to map range of kernel memory to user vma. This driver has ignored vm_pgoff. We could later "fix" these drivers to behave according to the normal vm_pgoff offsetting simply by removing the _buggy suffix on the function name and if that causes regressions, it gives us an easy way to revert. Signed-off-by: Souptick Joarder Reviewed-by: Boris Ostrovsky --- drivers/xen/privcmd-buf.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/xen/privcmd-buf.c b/drivers/xen/privcmd-buf.c index de01a6d..a9d7e97 100644 --- a/drivers/xen/privcmd-buf.c +++ b/drivers/xen/privcmd-buf.c @@ -166,12 +166,8 @@ static int privcmd_buf_mmap(struct file *file, struct vm_area_struct *vma) if (vma_priv->n_pages != count) ret = -ENOMEM; else - for (i = 0; i < vma_priv->n_pages; i++) { - ret = vm_insert_page(vma, vma->vm_start + i * PAGE_SIZE, - vma_priv->pages[i]); - if (ret) - break; - } + ret = vm_insert_range_buggy(vma, vma_priv->pages, + vma_priv->n_pages); if (ret) privcmd_buf_vmapriv_free(vma_priv);