Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp6623256imu; Wed, 30 Jan 2019 19:11:00 -0800 (PST) X-Google-Smtp-Source: ALg8bN5oC2IvxRJRytmgJbHLiTfw9jU6diObf8QGr2LAfyUrartFjpufIhLuLTeOUJLMI86+biIP X-Received: by 2002:a65:610d:: with SMTP id z13mr30372898pgu.427.1548904260291; Wed, 30 Jan 2019 19:11:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548904260; cv=none; d=google.com; s=arc-20160816; b=wbIDvBb1zkvfrNaBI8QO9T/85Bss7hWE635x7Pd2SgIagyA+hhrkGHTd8St0o1ZRgC 45bz6aP/jNasq4ebGE1Du4PXjRjRZjvCQhuc4ll/7yzN9aBg/zA94lxwYeSrRTv2K0qY RlWX5roftqzS/IM4MLz/z4vN9iYUoLBhMJh2jiQbv2A28dfOKea4pvj1p32Bo3zKuARw nR1Ao61t8EKI7P/i4T0jCszgFa4u3B+fkJTJoBMA1sYsLKpY/VZd5GPBm2D/LPkI5bDQ YJWXttZDmRn2Obf9XtaJhF8VWs5qkEOOWSX1/VxJFiyEuFu+6RcaKJdYjFIeHIfom5Y+ Jvyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature; bh=+gTPMCxXNjJoF0/n+ZWKrD0/ywZQWm6nRUnBrn1+xaM=; b=rhVHW9u3O381KDhtx3wJjeDmrxJn7ZQqyZEZDNzljdeplnWsQ3O/ASe98OFluPvt9r Vndsf7uaVixjooP63jACbeuIMt1jfr7mlZpROrZOQP1Bf2gApl+p2hBvlLM/tHm5z6BV 5VlEOAZVQ1Zhz1pcNPgm0gTz4L3gQ8qihrY3XipBob28XCcRNGJpGrifnjaRUUYEDgsA MpkR3yM1YhS0asRzQhyi8Q+ktNvL/DXiEv57r/XO7MB2DR1cFkh6Vq0tP3NYjozTLCQ1 3jc93/R7YR+wKP+9kjW/+Sb4VZqv9Ug4k++zf/uo0ttOTtNGwdG96omE0BKFsiJ/fClx wkpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=mU6lU6IJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v7si3036445pgs.304.2019.01.30.19.10.45; Wed, 30 Jan 2019 19:11:00 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=mU6lU6IJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727401AbfAaDJy (ORCPT + 99 others); Wed, 30 Jan 2019 22:09:54 -0500 Received: from mail-pf1-f196.google.com ([209.85.210.196]:45820 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725535AbfAaDJx (ORCPT ); Wed, 30 Jan 2019 22:09:53 -0500 Received: by mail-pf1-f196.google.com with SMTP id g62so787878pfd.12 for ; Wed, 30 Jan 2019 19:09:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=+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-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=+gTPMCxXNjJoF0/n+ZWKrD0/ywZQWm6nRUnBrn1+xaM=; b=BDj/Za3MAy8mglEiuDD42e2mYqBK/DSX6mx0JeM/DkOvpiWc3WPll0IY9IdwYUeXXn I91exTM5KvNsRy+143rSozIdKQpY4lHrarOQpOlT1a3KGM9JtkBajmZrIXLSiTlmZZK1 +U7v454mDQTEgHHmb13rzP/7js0NKhW8V7XCCIq0kZ/3YGsbmzoS9I6jlAPW+Y2HUP4t 4b3s3KGb7FAkcDfpiumgObkwvrPz9vxxkJnRkdys7bGn8lOU/W3AqUWw+7SMkLkX3O02 m+qLroJgGdQRtqWxnRgU/5uWMQ5NE8D8Ha/qmGtIIRSn7EHwNWlwWvGXyzzqa7HBlwXA 6EBA== X-Gm-Message-State: AJcUukc5D46DtR1dvaOKLVO7Bvn8bUlhquhzl06Jv+qhkpQJ1skgKrF7 GQIbBdIKMEEPEvNnY5TtxUw= 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-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 /* -- 1.9.1