From patchwork Fri Jan 11 15:07: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: 10758187 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 D2BC8746 for ; Fri, 11 Jan 2019 15:03:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B81612A02D for ; Fri, 11 Jan 2019 15:03:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A906D2A07E; Fri, 11 Jan 2019 15:03:16 +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 007A42A02D for ; Fri, 11 Jan 2019 15:03:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0005F8E0002; Fri, 11 Jan 2019 10:03:15 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id ECB9B8E0001; Fri, 11 Jan 2019 10:03:14 -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 D94F08E0002; Fri, 11 Jan 2019 10:03:14 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f198.google.com (mail-pf1-f198.google.com [209.85.210.198]) by kanga.kvack.org (Postfix) with ESMTP id 96B6D8E0001 for ; Fri, 11 Jan 2019 10:03:14 -0500 (EST) Received: by mail-pf1-f198.google.com with SMTP id b17so10480332pfc.11 for ; Fri, 11 Jan 2019 07:03:14 -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=OKnr+eVdmA4Yca5asvAl3VJvv/8NsBSwy+KQiY0Jcow=; b=ATLAtxW3GrSAHf6xxoei8j/8PbtPIBd9+HU7FZU0Zh9YedGmGP5TIktxBHmS01CsbG HyW5RjRLRcYJIqHK3i+tkRRmVR92m1ktkDx6gfno2u9GDp48YxwyJwTpryQfCVy7DfnB HwgQVq2OBFDCxVH4BAR8L9Y5y08UZcIgp/YqfLTQH7/z+n6ed9T/3+Frx0tYM71Mmomn ApOi8U/Q8bh1Xy0bigGgJnbdMXkWOJY0yzahnkwYVWtGYyx3Jrgaemo1uUyNJB/irJ1w uBuw+hL7aJfTQB3K+uXwvE0qzsHQxANh3rVY0+CRxy2vZJjCy/wB05+LmDGsR6PJ0FWj hYLA== X-Gm-Message-State: AJcUukcPKKSPUhrX/FEcXv/xES4GKQ064rvdklBQ96yWDN1V5UHeG0C0 9MX1kItbQHlIgm4ux5PibxGPUB+FW16AdUx56r+X1DWIjJNQQIwGb60zXs0Hhiq//xjNj79KImI 2W/b5L2p3PrFr4KljhG3Kw1fR0BypOWD5Ofz0tFUnQQ8RZ/O4OrwrhQ/aazuJgOaSOj36bXtkEY 6jZCm7E3FCjLLkEABn6LlF9BmAfxRwvChNBh86uAdVqrzfG5NUWxJ1zD8MYuRRxrL0TncLI6YJW I8305d+O/lc9VUlsOZYdi/VymmqyOZPqjb6gOrcRyVDjtfm3vXZ6obmGhksWhrLgiIYOBGwooaV 3vQac+Adzdba0BDkjgwBNGU7EGtZxsLAkiHlW1w9xEcqmULtbzpgc/9DZvJ8f93X9vg1cdeoTIT T X-Received: by 2002:a65:6392:: with SMTP id h18mr13829471pgv.107.1547218994243; Fri, 11 Jan 2019 07:03:14 -0800 (PST) X-Received: by 2002:a65:6392:: with SMTP id h18mr13829399pgv.107.1547218993284; Fri, 11 Jan 2019 07:03:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547218993; cv=none; d=google.com; s=arc-20160816; b=tcYYw2Urh+q4+Cum0IMMKpSu8mitj3sMFMM8Vv0YBCR/OP9CvY/Gbbcpd5BAMsFQCb MkRXh6Zr8z7o48Xba7j95twT699izUz9ualPVxdtJs3Plufi5+oEWZb5CdGkHO/KuzSd cxfdePiD3oqb5qatX3WhbezMWHdtoNvswWDzYd0kprt0qM1pVJjs/KaaP/79cjQzhY9T jCr7t7Vr89/u8N87oplrhz0NazhNIcIYA+zdyeJNEJbHsQKqLDZVUJsRR31fnxCiErKC 6nla7HJkUS5Mpe8idQ7DSeL0QGQNQ6zP9lTJ8t9SGgYFBO0DhWCSEcMDicXXCiq5X8TC Og0g== 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=OKnr+eVdmA4Yca5asvAl3VJvv/8NsBSwy+KQiY0Jcow=; b=vuEH/N+1MqYdqySHbLoxlutcZYzIII9645jodhnys0PqdAe5VcCUeBijrV4nakWzUp q5K5/O+M/UPab2CXqU+uWoctpU7cJL3Fm2IzB2edqFmiDvYP3GTsqm4CFj6+YR3sHkwa 7OBbz+GPKfUvxaIAZyIbjT0FXwjXJWUyqEe8N8VEMcYmSHqkeu3KXrZBRy2LmYGwPsAU vIjrI02YxLDDJYMBWHZx1HHcHTqdFtd7mptnMjgT3fZU+RrhpaobeV6/s5vM8DjVf1cG ck49p75Hm8zVmf0vZZBJTTb6u0x5mDEhL0mmHUhyWgrb+PekcV0OtbVMAXrx62wvpI4e jsyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ecFP8Fvc; 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 n87sor3794675pfh.64.2019.01.11.07.03.13 for (Google Transport Security); Fri, 11 Jan 2019 07:03:13 -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=ecFP8Fvc; 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=OKnr+eVdmA4Yca5asvAl3VJvv/8NsBSwy+KQiY0Jcow=; b=ecFP8FvcstIqu0NB/u52GoYNOTcWG2DvcB07IgY8lEs9qJPP4QRrMpFsf79PdPyxVo +95bi0qc4yFsVreg3UGS61GpTOuoYCQnYZyc+5rX9mPEq6iWXgJAAzC0Dic6/1Ac4kdd ToSp1I9tu34JSInsxojwgpUz/v6muGU8hTz3xenp7NxE8zdhMiFKGpknt4LFIcIdPB8A yk0tCLiaSAkmPdaK/WpQa8EEuvjBTrzwO+wwZHg4X6ykM3D78CNfnJIFfuAC4GhqGeJE 2By7VfXiT62OJFnrYXEMYkgKZWvN35vVUGiGIWMLm2+uUIMEr0RRqcicvSTWrx7DGnxD TQHw== X-Google-Smtp-Source: ALg8bN4N+0OC/ohlRldBlS6pqDxN4tNRJaVupZC6A5wD5JEK2YvVMDK1VGgLB+11HRGTGie4+RIV4Q== X-Received: by 2002:aa7:80d7:: with SMTP id a23mr14629976pfn.86.1547218992868; Fri, 11 Jan 2019 07:03:12 -0800 (PST) Received: from jordon-HP-15-Notebook-PC ([49.207.52.190]) by smtp.gmail.com with ESMTPSA id d129sm119031814pfc.31.2019.01.11.07.03.10 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 11 Jan 2019 07:03:11 -0800 (PST) Date: Fri, 11 Jan 2019 20:37: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: [PATCH 1/9] mm: Introduce new vm_insert_range and vm_insert_range_buggy API Message-ID: <20190111150712.GA2696@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 --- 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 5411de9..9d1dff6 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2514,6 +2514,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 4ad2d29..00e66df 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 Fri Jan 11 15:08:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Souptick Joarder X-Patchwork-Id: 10758195 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 42674746 for ; Fri, 11 Jan 2019 15:04:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E2571281D2 for ; Fri, 11 Jan 2019 15:04:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D5E162837D; Fri, 11 Jan 2019 15: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 77A1F281D2 for ; Fri, 11 Jan 2019 15:04:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 818058E0003; Fri, 11 Jan 2019 10:04:02 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 7ED778E0001; Fri, 11 Jan 2019 10:04:02 -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 6DC688E0003; Fri, 11 Jan 2019 10:04:02 -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 294038E0001 for ; Fri, 11 Jan 2019 10:04:02 -0500 (EST) Received: by mail-pf1-f200.google.com with SMTP id e89so10473611pfb.17 for ; Fri, 11 Jan 2019 07:04:02 -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=WzAQwD4CMcNjfYojTjRfy8sqfmAAp9apVnphS+7qE5M=; b=nYMbvfHjYLJrnZGWiQfIxptkoOthzVAmIIgYkS7ScaSHYISTpjleHO1uHVkRt2Z8eY XqEp608BULQSethR6U+WsejGzxKrIyw/ArtW+HzMGDtcq3QOBepSx+zqVOtKNRbUFAv6 PID4stU+tkhTqYc/reeYTn2XgsKBJT1Y/08FCeKCsa+F03gi4al0vH1athe9OAEBtc22 KDeu4OMv7m0pbuojATsLpiClUGyuYNJk6Hus2fMfppTwSBMX0I4IR3G2MqrtEQlk8H5l S4uwvj9JwCRKVyBsyOaBYaD7YxOkCgminxo88Rr0PLRcpr9m5BNjw8azaUrxQtEVK8lx oNvQ== X-Gm-Message-State: AJcUukfmBFCh3Bbw/r+ANlZqgOFb/vy0+KPf6Df4hSmGCGChnlCSENzR FKC09XHe9UbYlP9RfQKw17xOTBoGdqxEmG/rt+hS4Ls8YkkPeCx4CbJZM9kEtEE0b6xIHUV3vM9 9j59fsjhSWbr47pLsFgpuI4QC58ZiAcAWmBXqgT4J1aQxjLo5jpf7+7ZcoU3kZ3ukzMIA6V4qTl +xevpf7zmHUWYOviBq7JzdOxZQMa/tH9b32+gCdzouVzf+IuTKaUJB3W/qa5oZIJ4BkMsKvyuYl 6zw34/Q04g3tSwiJOQE8zlyB23z+n9no/m1eIyog23JxQoH6EB4d9RgJOuMwIsfBA1GL5s1QFQK wVJUNd1wkmy8LtywI5oM8VpvS4blKUIE30e6uYkYWDpBmnZfqpWBoLXA0RnswmhjAfHDvdhKQ+E y X-Received: by 2002:a17:902:24a2:: with SMTP id w31mr14723539pla.216.1547219041848; Fri, 11 Jan 2019 07:04:01 -0800 (PST) X-Received: by 2002:a17:902:24a2:: with SMTP id w31mr14723493pla.216.1547219041147; Fri, 11 Jan 2019 07:04:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547219041; cv=none; d=google.com; s=arc-20160816; b=Kb0CI4ElM3xqcYRuQoJTXtoIScizcXw4y6HBW4LGO6y0dOMlnAl+O7cbZfBmuLwvdN lwUl4v4eyj4qCEK15KSwcU4nvW7UrIRzp9jljzD3zo1Ic1k9XcTKBXpbjTpQAW/KLE20 J4YxaxCBXTvhMMmMXLkhh38AG+UjkdV1l6OyyBaUZU+D2pnEkwAQRbz8keeoDLIHIL3D xecHWJxKGrP7K4E4UcuUW8etcBC7uSHO9HWiJF7rBYaA61HU2vTd36VmOFvQQj6fXLuR Yjrqs8K4Z/L8SzJR1GabkKFqgdGl8KHFRwbE+IIpeFFIZ3ucQ+JNxdWmCv0aTcYfqEou 5C0g== 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=WzAQwD4CMcNjfYojTjRfy8sqfmAAp9apVnphS+7qE5M=; b=L3z/P1NrT1FzUsKDIjz6V/Eq2Qugl4Ee+ToMCachGsT9ru8ey3dghDUfh1Y+igjkfB 8L6ZWNCoCsbHq7rWZ70gwvUohHUFZWGZaWqFsuViDRxgfIjI94LsrFi8UnJMM4XGPwSo kmLRo/4Ql0X65G6e7VF9zMERXV+/DXD+1K/9wlVEqN934sHrjGkxGy1VdpRnC4L9LMqe B/+Qr+nIa63M3KTE4oxA4bBW645MpY8jsTUXZ3wLXk/FwSB6QQuKL51qeaJdLJ84X1v6 YwEDc2nioqAeew2nagL3GHo+ZMlcwAr2gSJJDuJE6cOcyqIwbHV3/1O+FBqKKWrsVvvc YK7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=HQ9gfhsp; 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 k20sor3786788pfb.26.2019.01.11.07.04.01 for (Google Transport Security); Fri, 11 Jan 2019 07:04:01 -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=HQ9gfhsp; 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=WzAQwD4CMcNjfYojTjRfy8sqfmAAp9apVnphS+7qE5M=; b=HQ9gfhspvagPH29Me3BRhdtcdpJ1ppAkZvxlrEmPYgRip1IdthcKcOCiWAVY5Z895Z PTA3IoN+JoobjwcMS/8b83st4Y+6eHz3yTWfKmWq6hBWZF2NZmmXzgF2mJsADBChdpWa BlzbeMjQsitVUoC0lUosclfzkAMgMA1uWDH4Q+jXZ0a8BMEvbSD4/3aYiYIx2RYsqrV/ uREttfKnl7dDB92r8GsoONQTcYXgxNyBsHnbW/433SZk5GGTnHZxA7gQrkXu0wYSvHer Vv27TCONFgJ3EJ2dLRQBnpmyzs3Y3diG7h3yFHd0GF6Ho2Vfd1jpkcOJiHFErnXjtg9V WdNw== X-Google-Smtp-Source: ALg8bN4zxdDRP2GvwoCa51Ol8AZWOsPmTHbzznH1GTkRyiMejwb4Tfr2KDpSzH8Z6TaZw/NFHZFS/w== X-Received: by 2002:a62:1c86:: with SMTP id c128mr15538564pfc.54.1547219040807; Fri, 11 Jan 2019 07:04:00 -0800 (PST) Received: from jordon-HP-15-Notebook-PC ([49.207.52.190]) by smtp.gmail.com with ESMTPSA id i62sm92403752pge.44.2019.01.11.07.03.58 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 11 Jan 2019 07:03:59 -0800 (PST) Date: Fri, 11 Jan 2019 20:38:01 +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 2/9] arch/arm/mm/dma-mapping.c: Convert to use vm_insert_range Message-ID: <20190111150801.GA2714@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 78de138..5334391 100644 --- a/arch/arm/mm/dma-mapping.c +++ b/arch/arm/mm/dma-mapping.c @@ -1582,31 +1582,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 Fri Jan 11 15:08:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Souptick Joarder X-Patchwork-Id: 10758199 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 C214C91E for ; Fri, 11 Jan 2019 15:04:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AC6A6286BD for ; Fri, 11 Jan 2019 15:04:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A07DD29C77; Fri, 11 Jan 2019 15:04:37 +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 88CAF286BD for ; Fri, 11 Jan 2019 15:04:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 901A08E0004; Fri, 11 Jan 2019 10:04:35 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 8D7378E0001; Fri, 11 Jan 2019 10:04:35 -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 7C7678E0004; Fri, 11 Jan 2019 10:04:35 -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 3B86B8E0001 for ; Fri, 11 Jan 2019 10:04:35 -0500 (EST) Received: by mail-pl1-f197.google.com with SMTP id 89so8391480ple.19 for ; Fri, 11 Jan 2019 07:04:35 -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=3XbEqy88Jb4MHLdqNBAQMVZdhzSqLBYAliAQZ38QAz0=; b=k3SoHAGzJPLVPM6h07L+GgiDJby/6+ba/WTVh2jq3azPbrPPc5HWPAN1Uk4Nyn+pin mIFieETiMJi+6Zqf80BhEfZFRy65LglPfD5psrFpfBjdsvA+Mx/VoWM8otVx6iLHtVqw Hq7xDuWjESNFhZgkp4AY9nNpKa4PGpGEEprAV9Gt6lg1a1aenE/55FFweIkOPnivErP4 vJtsXX+BTFSRGCS6TwOqbC/zxj4BeiYjw/OgJ6pzyDmnx0JsqYC2CegaiOuDftW7M8ei 5Bnxoy9wffHiBqtWlgGZOOFjrUXiatR1t4/AhA7XbhoWD3se1Q61WftvQaviU9GX03Ws j01Q== X-Gm-Message-State: AJcUukfze5om4gXZ4FDFQGYm3hEuzLTZ1lsC5vsLUc8WFxFnRN1oGN0T G49hMO2sgYxfZ48ks1yxiedDyuX31d90N6h7CD+t9R/vA/+LUWZwbAeVLYIheVppT56Skqx8wYn GUp7LZXj/bse94cM5wjrvcYsI6K9OMUQ70KE070rG6TeaT2VQ/wytu5cLFxiVEhQ7HBgX4ilmyt B7t4Yyf+upB41wupmo/jhLJiNKbPp4Y4KEcrQ9O8j/0ss+liV+VRYiRVJOHg+5NLlrK0VmxfUQz hx2lQ6s6LY2fHxaKUPui3IjGyd/MoklWJ4aZeBYNLqqeiuovKNiHJ4Hj5pGCjS5vstndKJMgkYf h1aXXZxWHYr5Enek5yhsWuGGrGBnOpscTmxATPmsJ+4R601MS8WMSuWBK8QY9oC5Z9NWAcJ+qAF v X-Received: by 2002:a63:8149:: with SMTP id t70mr13938858pgd.172.1547219074853; Fri, 11 Jan 2019 07:04:34 -0800 (PST) X-Received: by 2002:a63:8149:: with SMTP id t70mr13938809pgd.172.1547219074222; Fri, 11 Jan 2019 07:04:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547219074; cv=none; d=google.com; s=arc-20160816; b=LYLSB8wmObC3Qi2aosacMNC0QDpT3+mSyOOpC09Lqu6+E1UkRvWGAcamPmR4LmLStp ksAFnjrUb7wlrinexR0R+mwrOaqbLBfipX3tYZPrmEVyWytBuLBdfu+iGPo4UcEZiPYt mm1Fzdl0ogl/FUOGzz0BOdZi5O0K1DZd9xsI1BL6brPgFnEkd7clxREBzlCQlvEu8dnr JAq2bvG8xxDTr/sMeqjf5jc5jQh7QnhMxZBd5Ej17cee6N/h8lOztb3UqDovPhDsSJyZ KkHi8MuNiO2LxVOi8f0yj2ES6QdWvMASyrWDFvgdLP04lcNTtuo6CFWqaJyvEMnr+wty D2BQ== 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=3XbEqy88Jb4MHLdqNBAQMVZdhzSqLBYAliAQZ38QAz0=; b=WFF8L2bsEnQlje8rJEpA1Ref4DJsjz0mZknQ8fuGbb/qvk8k8Q1CdAfI4OMsZhqwtU LQclnMxZGTzqLw2FNJ+/9grIQQN7mk4K9mBb+sfZdU3ivTua85kysRpJsgVpepcqAAXp A3ionQW9yAK5wQNWe2edwauPtuAerkjCrrFw8B9o/xkEZRnXq2VHY7GgkYvhZN+GIFY8 PrEog7/YO3xy8d+8ZNaAf2YFkPoZkrUJ3ln4djL8XzuEPYy9SbPAS13KedQbcFcYF0D8 +PGgWu06HTRyFOgfnNSYIW6vsykTLwx6wwpgDbiAPVE7YcbrJOFI9B4ZEevr8MF3LOJr niMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=SMaXhdA8; 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 b21sor3794773pfm.6.2019.01.11.07.04.34 for (Google Transport Security); Fri, 11 Jan 2019 07:04:34 -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=SMaXhdA8; 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=3XbEqy88Jb4MHLdqNBAQMVZdhzSqLBYAliAQZ38QAz0=; b=SMaXhdA8Q7nrM9qGUNh1kXzTtWH3gVpEoGrrBwY0qxY14/6qIrIZLV5RIbHD4KieFg uMMs3JSQnImublU4VhMlU8lpOUNf2T+DQ1ruR+6UTCQVwyJEqccZa5+mnpsFhDKrFHy5 02c65ESvjA43b3Q3wXtts81HrN/V4kc0SPTdigGT9Sgqw4BqeszJJTCwc+gBM1vxQzTN DHTmwg24rP7PK2YUNwW+2JaRT5FNu8YihWMNxmwMPbZTqtN5VeHCCTywejrfNHHFyh5z OaZ/UtkiIR/jd52gMYtkRUHgi4X2dctsgtWFTEfHBzP1UaGCggVU6qAB+PrqACCOkVwX Bv+w== X-Google-Smtp-Source: ALg8bN5euVDCQBAFkwT8uFKwwThbROCLZs0KfIkBUValIFAmJazBRAFlZV0vDYopnVamFPnq3w74KQ== X-Received: by 2002:a62:b24a:: with SMTP id x71mr15274522pfe.148.1547219073889; Fri, 11 Jan 2019 07:04:33 -0800 (PST) Received: from jordon-HP-15-Notebook-PC ([49.207.52.190]) by smtp.gmail.com with ESMTPSA id 125sm131459879pfd.124.2019.01.11.07.04.32 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 11 Jan 2019 07:04:33 -0800 (PST) Date: Fri, 11 Jan 2019 20:38:34 +0530 From: Souptick Joarder To: akpm@linux-foundation.org, willy@infradead.org, mhocko@suse.com, stefanr@s5r6.in-berlin.de, linux@armlinux.org.uk, robin.murphy@arm.com Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linux1394-devel@lists.sourceforge.net Subject: [PATCH 3/9] drivers/firewire/core-iso.c: Convert to use vm_insert_range_buggy Message-ID: <20190111150834.GA2744@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 and mapped the entire pages. 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 --- drivers/firewire/core-iso.c | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/drivers/firewire/core-iso.c b/drivers/firewire/core-iso.c index 35e784c..99a6582 100644 --- a/drivers/firewire/core-iso.c +++ b/drivers/firewire/core-iso.c @@ -107,19 +107,8 @@ int fw_iso_buffer_init(struct fw_iso_buffer *buffer, struct fw_card *card, int fw_iso_buffer_map_vma(struct fw_iso_buffer *buffer, struct vm_area_struct *vma) { - unsigned long uaddr; - int i, err; - - uaddr = vma->vm_start; - for (i = 0; i < buffer->page_count; i++) { - err = vm_insert_page(vma, uaddr, buffer->pages[i]); - if (err) - return err; - - uaddr += PAGE_SIZE; - } - - return 0; + return vm_insert_range_buggy(vma, buffer->pages, + buffer->page_count); } void fw_iso_buffer_destroy(struct fw_iso_buffer *buffer, From patchwork Fri Jan 11 15:09:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Souptick Joarder X-Patchwork-Id: 10758205 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 AA5CB91E for ; Fri, 11 Jan 2019 15:05:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 94DE029C79 for ; Fri, 11 Jan 2019 15:05:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8695F2A02D; Fri, 11 Jan 2019 15:05:40 +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 2951429C79 for ; Fri, 11 Jan 2019 15:05:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 248DA8E0005; Fri, 11 Jan 2019 10:05:39 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 1F8618E0001; Fri, 11 Jan 2019 10:05:39 -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 0EBF48E0005; Fri, 11 Jan 2019 10:05:39 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) by kanga.kvack.org (Postfix) with ESMTP id BDC468E0001 for ; Fri, 11 Jan 2019 10:05:38 -0500 (EST) Received: by mail-pf1-f197.google.com with SMTP id y88so10520093pfi.9 for ; Fri, 11 Jan 2019 07:05:38 -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=PEly6dDoUqiv25HuxQdMpLmovH7EDbKdzHgNHFdTjnV7OrY/o4hKeayg1kXfYhNaKI d/+YN1x8yvFvWt8fx3rbL5z+lbzYP+wefjUIhENxQ6HZIV4iP+qscpF7e+fYV9Kr3meI ik1LpYKuLZFtRKN65f+m3iSlzoQ4bcf0LFg8L5kdYdulB8edjTf6PsVilWFaFvFyUNGB XFcKVdw9W2USuX4WDLIoMq9iAa0VTkvCUm7wnvYOP0XQG8CFZyGWU0SlIuVln7FRdHNs icCNt3Em1UCkGSw3sx3WlMcYWfLPeZN0Zt0X69omJpdsRU34ehIg1k/nMUeA+VMvO7OD hpbw== X-Gm-Message-State: AJcUukfQ/MwKmzHa/8h9bfsII/xS0/Bqv+K6ES6+WQ3oa/wssb5zDNiu HsS0JQpzmJYfJ1osy6eL2yDIBJkua7DBvx/UzGRdtZN8Y9N6YcDEEmJIqdPmTRaDNucT+mDdm4U q9yiofvkvcc4Yna8zfmj6JEXxBwynroRJtEPfbEBe90L/Be3tODnQGpI1/hQNl6/60NCGLIQYVD 4R7GJc2v2e+xTE7GnOAt+ZUCV1Li2EQ6UvovBh7QGgWcgM9NoNV9+Ut1p3KOxReDrIPRR7A9YCK nskzQflreBn/g/NuPw9fDMKaSuSt8BW56l4Uv7oGquPbWPeZXjVettv9b6I/J5Rd/xvvGNQJxn+ hM0FFA+jCn5MQ+RojC4G5dHE/dGUwqowlV6kf8F2womtyS8sqzhafnk3ZFEFBA2i3411xXYoSOR D X-Received: by 2002:a63:c0f:: with SMTP id b15mr13805020pgl.314.1547219138461; Fri, 11 Jan 2019 07:05:38 -0800 (PST) X-Received: by 2002:a63:c0f:: with SMTP id b15mr13804978pgl.314.1547219137774; Fri, 11 Jan 2019 07:05:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547219137; cv=none; d=google.com; s=arc-20160816; b=rqbDSgljwlcVym8Bm0sCqE9Dgbn423d+xdOTB8ZpBUtlcseshogZP2jc/FTACTCkF8 SuhXAYLFnQj7Hx43rnwwKHD9QAeejvfIJAiPoseyJSkZFg6TIlOdpeih8y69xEioGFWs 9oFRMMHwPUjCjAXiIvzzOzSxK2nWxKcA2/CTizN2GquPcLSyd8ncyuEjIg+J4ubkasnr e0mOEKaxjVgsGeg+09BLrzr4AmOJRIJKZaJfVvYTdE4FQfuUOl2iZ8DEn9b0hhpB0ekB m9iOCt8N80hYgspyoSpGXKdbKCCsC0iqWQ41J34xyul8deXpTDeviHRAEwZpkcE4zQdb TWJw== 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=QFUxjP51Wt0LmrFCqhcb4CqVt5jH110ui/WAzamLDDJaM3pTjy1oPCgxBr0q1vSwxK 3WzJMbFbzlQxal7LQhVsErA9XfxXvCKzM2MSKPoF9JJ54eOnByXRQJcWRNppkYBquW2c nmSTZoKYa7vefwEY97tws3SpFldmKTTJ/FtA+2cqLH0BV9fRtYAc2vaIJCRr2Au3q+R2 WINnAHQbMVZQMByZkfg4CAVril+CIfYv70NTGERFtIrFNXenZFXNghaHkr6RqK/aauwS rpDDtc1v+3YedRDAku7VJo551P815tPAPXHaeZx4f/0DzjGfsAZwP8mmfwkGK5d6QcfB qM3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=sh2LY1Wi; 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 b35sor3496331plb.6.2019.01.11.07.05.37 for (Google Transport Security); Fri, 11 Jan 2019 07:05:37 -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=sh2LY1Wi; 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=sh2LY1WiZPIeUaF3MW5DJg/QEYmtg7MuKqRcV+ohKVqeLOX2kAj87/ncMa6egebbYo k294jPvUpvY8tWh/TVJyCnvyC/T/VHszUoQByu4+B0bLPUEBcCPJg3A6iuRrk0nL/SCc lpg3ZBT6tI1It72Jxe2UE98iYfsC88cR1xfpH7vrMx9OJMw9tL2Vr1vv2W8XZ4Xktn9H NZtgrvTlD3Ik9YbSkPstnCWGQNPhb3+vQLQJ5oV3oYtnxdhNYQ0n2lHyDmzWabMOBagm +fOV5sL4jmozsC4arWO7kSdaVEIRpgV9bHvSvYqaiApnZh3+zyi/XPtspSlyoMBygeU3 sZeA== X-Google-Smtp-Source: ALg8bN5Rc2l8bWM7uxkHK8LK4e398s3Iy/tXK9itkSm2yPC22Yk8baS7VKxthK4Bra16e8DuO0AC9w== X-Received: by 2002:a17:902:1105:: with SMTP id d5mr14463670pla.47.1547219137463; Fri, 11 Jan 2019 07:05:37 -0800 (PST) Received: from jordon-HP-15-Notebook-PC ([49.207.52.190]) by smtp.gmail.com with ESMTPSA id h15sm98053997pgl.43.2019.01.11.07.05.35 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 11 Jan 2019 07:05:36 -0800 (PST) Date: Fri, 11 Jan 2019 20:39:33 +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: [PATCH 4/9] drm/rockchip/rockchip_drm_gem.c: Convert to use vm_insert_range Message-ID: <20190111150933.GA2760@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/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 Fri Jan 11 15:10:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Souptick Joarder X-Patchwork-Id: 10758213 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 CFE7E91E for ; Fri, 11 Jan 2019 15:06:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B85C329C71 for ; Fri, 11 Jan 2019 15:06:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ABC3229F93; Fri, 11 Jan 2019 15:06:40 +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 4CB7E29C71 for ; Fri, 11 Jan 2019 15:06:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 493A38E0006; Fri, 11 Jan 2019 10:06:39 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 440D38E0001; Fri, 11 Jan 2019 10:06:39 -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 358778E0006; Fri, 11 Jan 2019 10:06:39 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com [209.85.210.199]) by kanga.kvack.org (Postfix) with ESMTP id E7AED8E0001 for ; Fri, 11 Jan 2019 10:06:38 -0500 (EST) Received: by mail-pf1-f199.google.com with SMTP id 75so10507440pfq.8 for ; Fri, 11 Jan 2019 07:06:38 -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=jJyfr251abKPUjfrLnfnZBYdiVZ7BdP/pFKC0YWuEDs=; b=QrxlR2R3u4suqD8w6fBwOj8ZYC2GRh55QkZi0Omf98ziJ5NxNgPGi8WNI3vs4rvoHG rACQOgP0YxOohlHb4Iw+2Ut8fGY3T+rkWN12wKAK53TpxIylbRizpCDfVt5Eolip8jBa p9rupcsFxx356rqnaJhOO7G65tRHVp4lkkCv1CwWWucQbBuK/cet7Eo9QoIsfPux09gJ zC+apeA4QVKLi8csmF8r4Eamzvk7FreX1+nxWMOTtlQS43pQacTodAy0MtOQqc7MMdRx FxJpdQZbnH/U5Fac+ZSSPnBjk+HpeV2fg3utjlJB/WlPK7Fp4B8Di1QajDz3tui/S5Yh ozdA== X-Gm-Message-State: AJcUukePwLK9q6ErTo0q0rGSick1sISniDr0e4AbHSlea7V8bx0ld5La RCTz2a/T+36RWssUdKlR5ZrPr/sW/TKd9X3Z8q1u5crNFcjuzYFZHWLDBKKN5dW6pj/UGXz1K7B MTzz3Uly6UHk/ALyMMCewO4kdBzggq+j+r+QUWvHreNIdYvuDJ8r+Tc7uzSCE4XoBUtGL3XZj4F fYkn2JisQ5YS0s9upOGsADxBZM7MEOJTt+aT43Hde4ARkJDidI2nl9Hw5KdrU+XKJUFPE3hvAUb PDu/JiA/XK6gYhYxuvQdPx4Tb2sxkV9fRaddbA+xg17fH3FKP9kLlN6+wmVbZ7uD6k3qwI7V3ft tQiVfkLM5vZfvuj5/GpDaZB+4spmOBYCe0tUjClTiO3IBQK9jwI8Eto9bBe9nJu5gr9FI8tm7hx i X-Received: by 2002:a63:5c22:: with SMTP id q34mr3560409pgb.417.1547219198598; Fri, 11 Jan 2019 07:06:38 -0800 (PST) X-Received: by 2002:a63:5c22:: with SMTP id q34mr3560356pgb.417.1547219197909; Fri, 11 Jan 2019 07:06:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547219197; cv=none; d=google.com; s=arc-20160816; b=Pu2l1FSVuc3h87Ng6aZP47m3cOjH1Lw4EV2R/g84rGb4KylewEV+N/6R6XKIHUz7hx PhZwuy5gZh5t+IfFgFuBo1vGaKKGFFjBkdB2/yADjxrPlGldwoOUTyScw0HPn1Hucpww bSXFrGtrXK50a5wCNgL/+KSl2Va+MNqByVeyQjgbVHqnzT5A8OQX3spFLKQh5MThTqkh rsI0oZXPN7jJFrqZGWTldr8wc4FQ+nF5bAQ4GSsljH1z9hBcOxx4Q8lX4kAQBPGAmfTk sGWHIlfWNz5+Tjs9gPN2UWQA+jfPHrXhdtQcA4mOcW/w7e5HeR7ze7GyuSZLUod4WDzI Udfg== 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=jJyfr251abKPUjfrLnfnZBYdiVZ7BdP/pFKC0YWuEDs=; b=ykLxaAPix6b4T0Zw5epqpR0Y1IM1LOJw4dGJ1/MZNufB/MxLDVl+8Fb3Xln7ZZaeV9 9FiqmuqpjJA6BYZQFYJz+F4Xj5a38NfmJVu8Rlj7pqvrZXbzHF3cbXZwzc/E5Qfb2UPV juhL5CPuVXFbQ/1PyZYZQnifE4RmeDT4Br3X/e1W3/lVKRxllwqkQ+odmXshgY38MNvK J3pgk+SNqkd65tTBkyHF8Z2ffuGbxtaz2T2e+eZ5ZB5nLXrsstE+wapHOljLpi2DcDAW YE2bf40e1PJ0tKx3aQ+Gq+TsyPQMRnZjySLQt+ColjovOVE65uEqYu4A4Nxf+OqXo1xQ zOwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Jn8yGcSe; 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 i11sor3787964pfj.7.2019.01.11.07.06.37 for (Google Transport Security); Fri, 11 Jan 2019 07:06:37 -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=Jn8yGcSe; 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=jJyfr251abKPUjfrLnfnZBYdiVZ7BdP/pFKC0YWuEDs=; b=Jn8yGcSec9ppfdCMuebFOrYumbJez4VJp9ziQIzdHm4MyE7zHGBNv9jGGByDvcgQpn a4Mb1kNvbp+zXJnQq1QgIOOI7k4m7EBEOI8R9NBuJ+gOUIP+fz5rqpguuFagKdcElYjD +1EqR/6zuGgPokgzBSRbAqHNI2HGCTOaMZ7jveItEs2ypgi/m2luTW5lGJazXMnGy64q MXCUeX8B4/c4+WJv1umzbb5ZhKe3bWYqfF0fK3MwigxOq0vl1h7hkKTts1HzhjTGM/nY qASR6ayanD3G4foV2vBVIcJhbX1WEF9mjWene/Rj0RM1C+DPFca6892JPfFLhNGY97Kh 7gXQ== X-Google-Smtp-Source: ALg8bN76xSFly+CWNyQpefhrTarhDoTZdH79A8t9NSuLjWP1kW/Wkt1ixSodqPFgFeaytLToyuoA9A== X-Received: by 2002:aa7:83c6:: with SMTP id j6mr14876943pfn.91.1547219197536; Fri, 11 Jan 2019 07:06:37 -0800 (PST) Received: from jordon-HP-15-Notebook-PC ([49.207.52.190]) by smtp.gmail.com with ESMTPSA id 6sm165163391pfv.30.2019.01.11.07.06.35 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 11 Jan 2019 07:06:36 -0800 (PST) Date: Fri, 11 Jan 2019 20:40:37 +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: [PATCH 5/9] drm/xen/xen_drm_front_gem.c: Convert to use vm_insert_range Message-ID: <20190111151037.GA2781@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 47ff019..9990c2f 100644 --- a/drivers/gpu/drm/xen/xen_drm_front_gem.c +++ b/drivers/gpu/drm/xen/xen_drm_front_gem.c @@ -225,8 +225,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 @@ -247,18 +246,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 Fri Jan 11 15:11:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Souptick Joarder X-Patchwork-Id: 10758217 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 7B35A1515 for ; Fri, 11 Jan 2019 15:07:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 65A0D29C71 for ; Fri, 11 Jan 2019 15:07:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5964229F93; Fri, 11 Jan 2019 15:07:14 +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 002F829C71 for ; Fri, 11 Jan 2019 15:07:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8623B8E0008; Fri, 11 Jan 2019 10:07:12 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 8110A8E0001; Fri, 11 Jan 2019 10:07:12 -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 7011E8E0008; Fri, 11 Jan 2019 10:07:12 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com [209.85.210.199]) by kanga.kvack.org (Postfix) with ESMTP id 325338E0001 for ; Fri, 11 Jan 2019 10:07:12 -0500 (EST) Received: by mail-pf1-f199.google.com with SMTP id b17so10490592pfc.11 for ; Fri, 11 Jan 2019 07:07:12 -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=5lu9A1QSpPTMUXYRUbEIMz+FrtlaKDaua7/G7w3FZL8=; b=H+XEWk1I6YvnG7zAQB/PAaG77CKJ8GMXs53H7O+PAoewgsLxxxZJurHS1FMRl7GWGU UTXAA/nLg8Uo6QWd648DgHuYerAfT/u5Q7PYxewi+CJClLw0rz08BEmtCpTBaccT2QFi u/19A6WGnHl/o/1FCT/hywsmwb1qlntojusgpaeNVjCeGdApkZHL5f4A6G5LPLHdcft9 iDU1Cz/2oDdzVe0awxBcQXdfc8uaaKgJxG8SsNS2vPf+qUgR6qx2z0+tgbvQKE9vGy0v LOXlubQGNAi1hvTIRu7J7U3Ha25MTUPmmej/yv7j/p7+baP0hOoJH9n4JoeyDq+5ZsjW tNRg== X-Gm-Message-State: AJcUukdpGuk8sfuY5uunQdpXhMSwszWYq56wOSJ/W1KH9yAHDvFclbTB v+lvyWL1Z9kZrzIRcpf2hOEWU6mqsp+PZQQZBcsr+cOnE3TokjqCrNkGi0tvg0deKELULSa/e9J 3M7lFhg2obd80pNe5w+Ax+PCVQq5J5O0fcrUJvgZ91GUCmK1rCBhdxLK8FOHikFApzRdWrHJytM /RTumJiem0ShbinryOuC5CbN3HRZ6iYy5UqaNtkPeYb6fPXJS97v91FGA76K8KVPjx38DUL+NV1 HvNtfYuDEy1NxK7MhQLfBOysJDdfNfvPLwmN54rqE8jkpThZiJk7q6iun9rd9cZAjB0jpSXrfEP L8XxGk89MbRrbLbthymUq+s1EV9kv3JlyDPOuZpsAjeCHFwVDJ8iZGXcEdDUW7vI42J1yU3tIZS W X-Received: by 2002:a17:902:e28e:: with SMTP id cf14mr15234605plb.311.1547219231895; Fri, 11 Jan 2019 07:07:11 -0800 (PST) X-Received: by 2002:a17:902:e28e:: with SMTP id cf14mr15234555plb.311.1547219231222; Fri, 11 Jan 2019 07:07:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547219231; cv=none; d=google.com; s=arc-20160816; b=UVK9tl3W7XqDGpXEU2YtWZPfEHWXZCarEepODTbbYqcxxSpVwRvY0iQU0lIGqc4YcZ fkue5kIV9qlPCl1ozuZ5E7ju6+4rYeCD2Q+H70ABHgmB9AE7NXZB01JXeq02nXVl1+9c m9+2EAa2TPAHjWFlb0yJvQLlq48XloGNBQr0VizM1ZnN9HmZDxdMwP8DK7lg2g3PpqrK kei7hYW3eGrBw1Fshju42CGYd3Kv/MihKfsF7C8H56TxrN35244exLbmWWDpjhXVR0/2 BvzqXxrce6yQ5IEgLIkMfMyA1Z4CLZLdUYD0ZCSPfxuBpAV9b4SZcxByAkI2BAcQYfB2 LTtQ== 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=5lu9A1QSpPTMUXYRUbEIMz+FrtlaKDaua7/G7w3FZL8=; b=JecqqrHHjd7ezHeRE0z0oaP8aUi3ImLP7gYLZzrBOI8yfvz6uUaMP94NhuAM7f9gGf 04YKh5ZZQhSzRMGsWzgOBHQgSyi9twPLLiiKtDMPws+172c1+xnNHkOFGUmexuXh8/WL 8w2CdarjkPg2FxdFJ7oj+t1e6/EzJ7GfEdTU2MUty6odWBboRHgaqEqYb/WkwZ5mjHYc tFwfq5tZNys3ii33Hzl4pFwHIXQVLcXHVSm8jFHJOA9KQjxwXbz7+hz4vTZ1HsKZMlPI 8GS1Xpr/jWd/sIJx1jim8TyxNtba9ZKo29sKIncBjR5AFil3Rgfhla/2sqJKc31R+C+T JQnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=QsvM0uu4; 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 l12sor3909024pfb.43.2019.01.11.07.07.11 for (Google Transport Security); Fri, 11 Jan 2019 07:07:11 -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=QsvM0uu4; 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=5lu9A1QSpPTMUXYRUbEIMz+FrtlaKDaua7/G7w3FZL8=; b=QsvM0uu4icAZvextylbdiwQF+jVmwkwcRTFbwvekeKAkggRQtNuG1yoUKv9QGnngR+ DK2boV+OXN4GEhRdq8EaSr0OONaDWE88K/OJ5VAxGivZoh+YGndf9KfrXkwvF6gnVkQX nTyB6idbYpK55CJm0E7qRJQSDcfPgFFxJTFLEELimduks6bbI/fiwhEUg+VQq+4UbKEO /5m8X2KXTUvmdgd9pkhtAPR9EFxD7sLEnYFjQO13ov5Khi9lOk2hF31OiH2YFVU1fvkc ti6rmIsEVP1wp/8gEx/yh8Oebts9hgzlTUAdFMrdOT/2E8srkxPSJ70jx7N4ou8HhnWV uW+w== X-Google-Smtp-Source: ALg8bN6KjwykscB3sBkV9lO0D9hkHDIbI6Lk2JEn0IITS33oEFeAQ1Opc96e0VUEvQ74PX81me3O3Q== X-Received: by 2002:a62:1043:: with SMTP id y64mr15144503pfi.78.1547219230435; Fri, 11 Jan 2019 07:07:10 -0800 (PST) Received: from jordon-HP-15-Notebook-PC ([49.207.52.190]) by smtp.gmail.com with ESMTPSA id b202sm150546595pfb.88.2019.01.11.07.07.08 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 11 Jan 2019 07:07:09 -0800 (PST) Date: Fri, 11 Jan 2019 20:41:11 +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: [PATCH 6/9] iommu/dma-iommu.c: Convert to use vm_insert_range Message-ID: <20190111151110.GA2798@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 d1b0475..802de67 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -622,17 +622,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 Fri Jan 11 15:11:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Souptick Joarder X-Patchwork-Id: 10758221 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 3B35691E for ; Fri, 11 Jan 2019 15:07:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 269B429C71 for ; Fri, 11 Jan 2019 15:07:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1A9BF29F93; Fri, 11 Jan 2019 15:07:57 +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 A9ED729C71 for ; Fri, 11 Jan 2019 15:07:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A0E2F8E0009; Fri, 11 Jan 2019 10:07:55 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 9BECE8E0001; Fri, 11 Jan 2019 10:07:55 -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 8AD5D8E0009; Fri, 11 Jan 2019 10:07:55 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) by kanga.kvack.org (Postfix) with ESMTP id 4C7708E0001 for ; Fri, 11 Jan 2019 10:07:55 -0500 (EST) Received: by mail-pf1-f197.google.com with SMTP id t2so10529069pfj.15 for ; Fri, 11 Jan 2019 07:07:55 -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=xmLU2VoxBI1AblI7e4+GVmT5PEuDGrr9Ez3gDZemTlo=; b=LkC55u8dQ3A0+ZLeQRdBYWJeEk/hKWoCwkYa5p9lIbiWt29hgl4WWJleiajixPDHUO fd9CgDJQi73Tcm50CeK91mmaSTbUMznx0qyn3RrsexU8asz6+2KEdBZdCblf+RnQXRBV hjKfbxRjNadt6NL7evmh1StjgF7nLKJNkMmcJwR/zl9Zur2Id7gd+U4/5NHtnMQH2VWp 5HMnPklQqJMdfAUlu62Yi4YdBabvw7X+24DkoMkSmC562Ynl+N30kdDZ+0BLjCI2hPwT 2s1jI9rrX9zzWdzpENI6VCjRh73cSHJY15UttLJWZ1aMThw0rm14biVbAhCHvfUWc6GN dQEg== X-Gm-Message-State: AJcUukfC0Bcyzm9Rn6NG7OH9gCwGtLgZ/bAqj8N79r2494UtP+FlhFJw HMpxWujIIm9CUI1gandtXScHNrlTpbVhU/C+/vN+l7Zm4bzDglwx4DkR8op8XZPgkAroJAASWgt fzpMZe4sF5tgXBrc4ogwVOSFci+HaxqcWeKUd1r7IfFsuiO9AyxIT5EeZYP9vGeIsUbvTOSl/I+ QhlLHBezxaUODo8k9LsRRR03ShDbSwh4pO/PFDdA593JX10LscRf7eccDsX0uhLs3wAkMoIKO/J bUR8mLgd6i/BQRSAdxIQocZO26YQC6bPzP3z5ir76IobuwFsV4XO36rvuplSpDHZ1wQkeDhN5Bk 8w9oyTObE1DVLM3teIRAZYc0lc2LlRfISFWD6TRc6oCoiPVg8dOYJZhsK6fh+KITnMdZE66pIMI V X-Received: by 2002:a62:4b4d:: with SMTP id y74mr14766681pfa.186.1547219274973; Fri, 11 Jan 2019 07:07:54 -0800 (PST) X-Received: by 2002:a62:4b4d:: with SMTP id y74mr14766632pfa.186.1547219274273; Fri, 11 Jan 2019 07:07:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547219274; cv=none; d=google.com; s=arc-20160816; b=LsPgn6cwDXP6lXDInqb6cYBFrlM0Xtg1cnKQOatpUTk3uEmJcD/HmFXNVPj5vztYgx mO5OPEeIS6CIQF9HK0W0szCNXQh60nxxTMtXmc8mFHKNoCKuQfu6PqXo+8ku7fCk98Zn HN6zDXFDspbr0uYzv8hxIaiTLnzgncCFUNla3ND5MTW48ka4YRtVl1/g2GazxJHwXBn3 0cjiQnUPJHSTlCXwKUDRtIreEZegp4pkbVd8+KnsSEiat4uBAMK2tqLoXeKaMVpPYzgW kmDxHH3qosGrUg1iujsuTZKbbnUnd4QsUVQUVnu8VOpLmaRX3rcTCP6Iz6m+Y2xbjbHd 13fA== 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=xmLU2VoxBI1AblI7e4+GVmT5PEuDGrr9Ez3gDZemTlo=; b=WrJ4zKNVy8lC+lUqn0mjg2FFKYwvlI7ug/ziB+3Vpuh/332jIPuVoEx48Matm/7E5D pjSw8mz+220RDmLTZ9PGnJlbwG3Ee9gLUB1fWagM5/0Gj9Zh6F+LI2II83nB2Mbp5B6O 9K6qf8HezwF8rNmPzGaAFHCzvOjL4xnnx6f2i4CWw9aK0SzYBwr+oOgJHOyLcwA23bdA Un1PyeBgyyWgjSDt+5jJYWzx20ZO7VZyuOdKax2QUD5kOCH0zWAXRg0czezkltNKbN7t 0crRCR6QmOSWgRbwinTYQPdIfuBZJrWlh7p3SStsCWSwGG6GQrTzt3YP4XY1yXAxaeiS QzWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ukuye4IL; 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 b22sor3942539pfe.48.2019.01.11.07.07.54 for (Google Transport Security); Fri, 11 Jan 2019 07:07:54 -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=ukuye4IL; 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=xmLU2VoxBI1AblI7e4+GVmT5PEuDGrr9Ez3gDZemTlo=; b=ukuye4ILBghvl/ea98/Ja45KGMhw2LJ9JaPBDDpqgt2y9VBAhCkwXx/XCC1BJBLszm j/RFMHQI1vnQZm2S/durahGZ3fABpMUNvQNZKd2mWCd1b0seaQ1HdjW0BjizObBP/e+S 7mMLpf4vsXaJ9HXyxFoviwshTVxHZpfMU6FgoF1sktEarBm8ClO7PCkxUkcJ/BwNxnZL yBl4z8N8OTasKmGS9Usrz+JXD5rBahLAWvbEMuQYtCd2+Q9qOk9vKmSlfa499/WHZ/oa C9rO4vYI+xLVeQMZgqOYNUmpDt6leBfFn8bwAdgRC1xdcK18dvi1UirqW/G0uJ8Y+Kpe 4A1w== X-Google-Smtp-Source: ALg8bN78QYDL7o7tAWys1x+bFJlndFbFXr9PHUkCoW3OrmZHFdsg9IHHrJ+vfOFuzdNqNQM2dbbwhg== X-Received: by 2002:a62:5486:: with SMTP id i128mr14545894pfb.215.1547219273447; Fri, 11 Jan 2019 07:07:53 -0800 (PST) Received: from jordon-HP-15-Notebook-PC ([49.207.52.190]) by smtp.gmail.com with ESMTPSA id m3sm137912153pff.173.2019.01.11.07.07.51 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 11 Jan 2019 07:07:52 -0800 (PST) Date: Fri, 11 Jan 2019 20:41:54 +0530 From: Souptick Joarder To: akpm@linux-foundation.org, willy@infradead.org, mhocko@suse.com, pawel@osciak.com, m.szyprowski@samsung.com, kyungmin.park@samsung.com, mchehab@kernel.org, linux@armlinux.org.uk, robin.murphy@arm.com Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 7/9] videobuf2/videobuf2-dma-sg.c: Convert to use vm_insert_range_buggy Message-ID: <20190111151154.GA2819@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. There is an existing bug inside gem_mmap_obj(), where user passed length is not checked against buf->num_pages. For any value of length > buf->num_pages it will end up overrun buf->pages[i], which could lead to a potential bug. This has been addressed by passing buf->num_pages as input to vm_insert_range_buggy() and inside this API error condition is checked which will avoid overrun the page boundary. Signed-off-by: Souptick Joarder --- drivers/media/common/videobuf2/videobuf2-dma-sg.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/drivers/media/common/videobuf2/videobuf2-dma-sg.c b/drivers/media/common/videobuf2/videobuf2-dma-sg.c index 015e737..ef046b4 100644 --- a/drivers/media/common/videobuf2/videobuf2-dma-sg.c +++ b/drivers/media/common/videobuf2/videobuf2-dma-sg.c @@ -328,28 +328,18 @@ static unsigned int vb2_dma_sg_num_users(void *buf_priv) static int vb2_dma_sg_mmap(void *buf_priv, struct vm_area_struct *vma) { struct vb2_dma_sg_buf *buf = buf_priv; - unsigned long uaddr = vma->vm_start; - unsigned long usize = vma->vm_end - vma->vm_start; - int i = 0; + int err; if (!buf) { printk(KERN_ERR "No memory to map\n"); return -EINVAL; } - do { - int ret; - - ret = vm_insert_page(vma, uaddr, buf->pages[i++]); - if (ret) { - printk(KERN_ERR "Remapping memory, error: %d\n", ret); - return ret; - } - - uaddr += PAGE_SIZE; - usize -= PAGE_SIZE; - } while (usize > 0); - + err = vm_insert_range_buggy(vma, buf->pages, buf->num_pages); + if (err) { + printk(KERN_ERR "Remapping memory, error: %d\n", err); + return err; + } /* * Use common vm_area operations to track buffer refcount. From patchwork Fri Jan 11 15:12:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Souptick Joarder X-Patchwork-Id: 10758225 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 BCC2791E for ; Fri, 11 Jan 2019 15:08:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A41F829C71 for ; Fri, 11 Jan 2019 15:08:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9892829F93; Fri, 11 Jan 2019 15:08:38 +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 30C2D29C71 for ; Fri, 11 Jan 2019 15:08:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3F5AB8E000A; Fri, 11 Jan 2019 10:08:37 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 3A3888E0001; Fri, 11 Jan 2019 10:08:37 -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 2BAB48E000A; Fri, 11 Jan 2019 10:08:37 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f199.google.com (mail-pg1-f199.google.com [209.85.215.199]) by kanga.kvack.org (Postfix) with ESMTP id DC6378E0001 for ; Fri, 11 Jan 2019 10:08:36 -0500 (EST) Received: by mail-pg1-f199.google.com with SMTP id o9so8585515pgv.19 for ; Fri, 11 Jan 2019 07:08:36 -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=vHKS//TZxZR6+MbFM/21TvVXK2jPLls5Bm50Y+Ae0UU=; b=O9dvjXcvY07shWRZ5A9BPf4Xz6KuETYML8n0p4A7+TkVOUwdSt09m9KJVK20+Yw7ZY 2pjEuFj5XSOYa6QighKGTNxjpVl2GJ0JocHVJiWuAyR334CG0v46N14neAqTCCr+URq2 2HXWU+RyPyWRFkNLlMBKPFO8eA/BV8Xj0AyerhF0LlL4xBf7+dTtcKV2BfPYLqAA/urK iRqD2D2uOqiT/WR1E+wQIxuNl+edUiBjVgL81fReGtclqFaxs91vZ2gWyju5LGZQJy/i 1PjgifUtA/vBVBsOFAaX6IltCupuxbmyVKFAWxqrzvJzx1dAj6F86kcDB0UB+/iru93X Q3eg== X-Gm-Message-State: AJcUukdvwQUkpduuOftPNYjVuUkRQVlDHUpsEohvoiDZgcaENuCf4fiN PVnFPLo/+nH2ZuNWSUvg17Dv/Dxk0iJENfhIzWlG/de+k2aZW6dQtaHx5Y/RHlCmN4RTFO99/jI Su3/6Lu2jyjJNhHsnlRGwJg7FNWSQawJLhLuJ7hUB08a4kdQ8t27bmJvU9t9hmt2UBqhPtQG73v g+TIDJX2gdLnNORza71A+Bz48YIN1GNznyBHpp0c/zvNzN7B9Wt+jWmTTSydKCnSuUg5TFtbsMv wqy3iN8xNXELFDPAeGNwz3PAtzdGivp1aqlLsf6zPOxd413Ab76mgdqsOQcTXtHwYfvdBgLSAH+ rmPCCn1btYg1nNf8aRDtuem2FsR2JJ6jzSRcJaPVK2726exYSqiPVDDJnuvkl20aD6sqZ69Rv26 6 X-Received: by 2002:a62:5d0c:: with SMTP id r12mr15481436pfb.0.1547219316534; Fri, 11 Jan 2019 07:08:36 -0800 (PST) X-Received: by 2002:a62:5d0c:: with SMTP id r12mr15481384pfb.0.1547219315628; Fri, 11 Jan 2019 07:08:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547219315; cv=none; d=google.com; s=arc-20160816; b=G2rze7XT+BOfRxCwO7quWFLT3pJOll6SjM/DLxudZSzBdw2XPD9v7bQfiwwb+Jsy7Y 44O9ZDiae5IZG3qkUOZbXRGj5u4Hzn7fptzgx28OJf2hjvopfHtsWidsCsG8rEXST/3h UiFC3v6psqL20BChMAq9DtI2wS7RXK+nE24kO9tzpL47DEA5CPTSxdrG1bl8ehO6lRJO AtLOZrFlFnCzeGPl0a92EbSS0vb1Jk9GPZxZ4BEM77MBLEE5BS0T1dujhsGNLI7xWE28 QzdKrE974IG9AZqDK0O3dNmk7TAMZpP1Wh5eTNlf+1QiGZcI/mCByKKDamvPJ3m0/Wae v/iw== 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=vHKS//TZxZR6+MbFM/21TvVXK2jPLls5Bm50Y+Ae0UU=; b=zMQVuOIb6YqfR/VFiAa3VmWNNjKmFLxDaDhLlVX51uONwGGkp6THTYDL1q4cwKYbyz tlZKIQ7CzwijiNdbBlRD85SdjxopRIKPGIDhMXJ7A3+Qj/2L7x+cnwukka++VjxtyCAR J+QAc9blWXPbV0qSTGVX6e11Ln6Orhv82yj495hALuSDH19Cab49oUOqjJ18DzUiAfoa 7BNXjVElzR71DeLVkGpro9DjgmCMpxjbmvSR7SYtFjlXU+gD/HABGjIOjct6z7NKuOnh Xcexd1G3N7h1dV7F1EyVK3t+DQpiSsieN7LTarqne/VzQNn0+xrMrloGpFnTABx+In37 X5eg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=X2l48CPq; 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 s20sor3526226plr.50.2019.01.11.07.08.35 for (Google Transport Security); Fri, 11 Jan 2019 07:08:35 -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=X2l48CPq; 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=vHKS//TZxZR6+MbFM/21TvVXK2jPLls5Bm50Y+Ae0UU=; b=X2l48CPqdu0frS3K3KzOnOT/wmG6wGo1EqRuCPkedTt5YZOuAUEF2j2JuISSDFg3BB +gMBjsDEfs74tgp6sGQktkRbEEwE+4OyUL6m09SMLZ2Zf9fRo4W30YKLfxtg9i3gJ/4n 0z3gaZBnL/DSYiChTec94Kid/dscMX348zoSRjHa9Nb8IzbXGOI5xAu7AgeVwQtDmuFu +AzXD0pz0dIQ5HI5CvA6LVWiieatC5fGrZpEVRmxPXGuzKWRstkm8100YxCMdK8oLi/8 ZtCpQyDhPmYLbeg2MtfFrhJdINQfZmpKjB1GpWLFd3riQDyB7RKNxa3mBG8iqylyBI9v ciEg== X-Google-Smtp-Source: ALg8bN5aDkgg5ldDKHA6yfV1TZQA+qcq0ZDkBcWhCzbgmdJ8IDlZXXhK+dZ6M/q0tbISuC4LhMUrgg== X-Received: by 2002:a17:902:2c83:: with SMTP id n3mr15194441plb.104.1547219314683; Fri, 11 Jan 2019 07:08:34 -0800 (PST) Received: from jordon-HP-15-Notebook-PC ([49.207.52.190]) by smtp.gmail.com with ESMTPSA id l22sm132710551pfj.179.2019.01.11.07.08.32 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 11 Jan 2019 07:08:33 -0800 (PST) Date: Fri, 11 Jan 2019 20:42:35 +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: [PATCH 8/9] xen/gntdev.c: Convert to use vm_insert_range Message-ID: <20190111151235.GA2836@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: 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 b0b02a5..ca4acee 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 Fri Jan 11 15:13:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Souptick Joarder X-Patchwork-Id: 10758227 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 B20A391E for ; Fri, 11 Jan 2019 15:09:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9D7CA2A0A0 for ; Fri, 11 Jan 2019 15:09:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 919E92A0A4; Fri, 11 Jan 2019 15:09:29 +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 355612A0A0 for ; Fri, 11 Jan 2019 15:09:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2BB348E0002; Fri, 11 Jan 2019 10:09:28 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 2917F8E0001; Fri, 11 Jan 2019 10:09:28 -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 1A8B28E0002; Fri, 11 Jan 2019 10:09:28 -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 CF0098E0001 for ; Fri, 11 Jan 2019 10:09:27 -0500 (EST) Received: by mail-pl1-f200.google.com with SMTP id a9so8423540pla.2 for ; Fri, 11 Jan 2019 07:09:27 -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=HRKqpRHmU+L58qncR6PcEXsm4g4xjV60VkG5Win5xw4=; b=TtQLQvBrKbroOHYAHaJ8FFc/kibvn4PDPAjxqFSXKKSJvJ7CKu1tq3SoNyZR2NRFD0 /xUGGpKp5U1P9fOseZmqZR5Ebbh7T1ndWELv8OL+jaehi9SYfd3SiSqmazOQUANjjclU 8b4qDRs7Ik0J39NG7dW9hAvUcPCJvoew+K3tfWCckY/h7Gu/sMWUA07VDxi3a8jaAZze /oT1I9xBIkK5fPNNpXun+q5RrUlu4hXIeof7cemsEQW9BuyfAJ9qdPswkNcB3dLC1qo/ Fp39nsGLFHBtWIdpm+tLaDM6U6p6KUVcHytdJCZCFeQmerszALjP3tIaJXjfU94rCGda EFlA== X-Gm-Message-State: AJcUukdntId5s2zd1jtLqOElAInDHeRySJiwTycWPNlWlpqghRqvuJvh BOYiawv8NZTUDUjOvvZVE3Ng9jB/nzKtk0KgG1TcW7EoJOs5Fve5+0pf6As1odhrJw+5OQpfrlH NbrYwoApSkf5wmWvO5QDqlfX2kuVEb+EKFHuK5sTT4srmMhWIyE6SkgRQi/TXl71o4K4usJ5TCq 9/R/uoWZNJPeWoyph25B+WJunate/F9k1/0cvTNHWZZVSIvsRBduWqvqT4gInIPm9PL3PqtPvyK o/UFy7q/M9sPjxs6sDFroHQyaEixcwZR81hreNIa3lEA2yHdA8IfxzKEUEAOhWKsY3Yk7c39Nct LeNePSkXMcOjM/DW4gQNLsqUUZLu+O+JfUHZBHVhExDz8wxPP/ZXRWdLMB2IWGomcUL605ChHpy i X-Received: by 2002:a62:7792:: with SMTP id s140mr14860171pfc.26.1547219367514; Fri, 11 Jan 2019 07:09:27 -0800 (PST) X-Received: by 2002:a62:7792:: with SMTP id s140mr14860118pfc.26.1547219366882; Fri, 11 Jan 2019 07:09:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547219366; cv=none; d=google.com; s=arc-20160816; b=LzJfOUozIo7orku96sSwOntp7a6uLu/XfFi8cCXCulihFdxVO30vboZoZn8p3ik+9M aaUokCg0ClP5zg724yvxki+NIezZP0J052DRTZPdX9dXThOjULHcKzyvo7HTS/SQRdu7 BUf2J/AET5bmSRtUHBWWSyKc4BHqpMwmGGN4jOjmpB8wACaQv0CnvZViNFv8rFzZnXNi 5ftXq/nNFhceYF9rjQhlD2BRnI/l0QPeU13M/Gv1JbASq8p35+q9Ft/SV2Kn6D81xanS xjgA60yDvsP/FoRK65jorqpX9cB1WrHK5Il+bu1BDneNXNzFo9WU4bBm2OYuHZ4Cwa1p GJuQ== 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=HRKqpRHmU+L58qncR6PcEXsm4g4xjV60VkG5Win5xw4=; b=F02oT0GgzMevaIdhPWlzBnkDu9HpmICYwk63gLqHSoHXsG3xXnOXk338/51rPO7OkR JZu6fntEUmm26TX06QsD9IHshQ3X1/0yoNJclpuK98Wef1U6T3V3cd336X7w+cyplSJm OCQFdDm37niB2GhYxKolt0EBzzUEYGAKdwzJDRYn2o2mYbjIhTNuIVtolOA7rrtNMC7g 3xlQIGDg70x3Nclqt31ssVIagrKmj0s53b0p3VawdKrMtnhx8yMMG/V+EJqXK3GS2j5B XiqadHcc0rUVzshUZQrpm9JnNRPhxCiDCPcxXSxMqnoHdWPHT7q8sgtncUgOkd0VsNZx RfNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=JuNrLoG8; 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 v15sor3927947pfa.0.2019.01.11.07.09.26 for (Google Transport Security); Fri, 11 Jan 2019 07:09:26 -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=JuNrLoG8; 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=HRKqpRHmU+L58qncR6PcEXsm4g4xjV60VkG5Win5xw4=; b=JuNrLoG8W9qZ3wovEJ6sEuIJ29dYs5vMzRIRLtQz9SUWeNl4UjyyhYVOScTr6JHLn2 Eakll8RWLEKrzrgsL7JiV9od8DeDB/HnCTihU+VsG+6pQMp1IYeFSVAW8ic4nAjGgwPu ZquG80FbhCmfchutBXtjW0YNVRdpaTlpJVOe6VTaq+Nm7rNFETfSlrUrbqVTIG45AjOX YcGlCzK1UZdaie9TaJRXte+oGsy8++6U7VC24my1faXZkU2RJU+HKD6DEDvFlr7rPo5p 9hqCN38u1u8+c4OS7vN1ygZtyNLYx3RnDsPhAlpbGIdc6CloSEBGOHLU1mxZiDsPzv38 ZPgg== X-Google-Smtp-Source: ALg8bN40ZHV+TGI6LLpALtlmSgNcU7DuNE7kQ77YVrf7dr/Bp0HI7ekI92a2R/MlUhJCUqv1tRv+Kw== X-Received: by 2002:a62:8c11:: with SMTP id m17mr14936629pfd.224.1547219366063; Fri, 11 Jan 2019 07:09:26 -0800 (PST) Received: from jordon-HP-15-Notebook-PC ([49.207.52.190]) by smtp.gmail.com with ESMTPSA id j21sm109918120pfn.175.2019.01.11.07.09.23 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 11 Jan 2019 07:09:24 -0800 (PST) Date: Fri, 11 Jan 2019 20:43:26 +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: [PATCH 9/9] xen/privcmd-buf.c: Convert to use vm_insert_range_buggy Message-ID: <20190111151326.GA2853@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);