Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp213383imj; Wed, 13 Feb 2019 07:10:18 -0800 (PST) X-Google-Smtp-Source: AHgI3IYj76IJLVDbB4MYweGLOi/6q4D6rD5xB6Rqb/Ik4UopywBtsbvtQS2qnk1wyOdAewb60JY6 X-Received: by 2002:a65:488a:: with SMTP id n10mr875880pgs.261.1550070618222; Wed, 13 Feb 2019 07:10:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550070618; cv=none; d=google.com; s=arc-20160816; b=FGDSkBL3plwGmfa5a91+FEogU6Sfr/tcbSNAQzH1pPynSNbYMf/XzAXig7jKD+IzN/ SsC8pMPLnDkWXCWjlhPJ5/U3ClACN7T5gF7mb4bTtagQepbSQ7pa8JudgxR1zxebfbM/ /QZyzjWnYdWTldnvPKD6qJi+wjmzwnddu8psl/Hbgv2Z3L+4YXv6r6RbD1mXcJr+ppWS g9bcIUa8yjWYL3OPcnrd3m0ZZBh/JAq1hrOcmxIB9En8UsALAftKCIeUbB3J5X0Jg8QR 3rolkgcIkKcz9iCxleDtlA/jOM2BYMCB0hxXNEL/elCUmIUTwqv5auBihXWJ2WG3LyuG luGA== 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=H3f1MfvSqhk7fYk2/rKXnYTMr6+lbY/NU0rOXhC8O5U=; b=dvpUlnmDQJJ8Dqys3dkuFiXvWRNTSzJnitR9GEVq32BRbLXezq4hImq/sxILCHM0Hr OV9JimDj2xBchrm/oRWsVJI/v4Xf48WQuY8Kdrk6tL+0RQIfvoO7UO3aS7UPguUTxxRN b2dDgi2iOa3ukbuqsRTV4hlH2Dc7cQlkX+LurpRHQFIqloUZK0MTt1ZnAf37r2HaK/ko 53ZvBEHPHxhI75Lpl72RDWxvMT8H1lV0reNZ2ancV0kenIfLyYNXowlg9AsTt0W0zSth QmhhzuIfjiRjY1v/3fDyXIQPDe6mfovfgGY4dDEGyviLt2hsZrKe8S/Gh4zKkeFPjIf0 p38A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=VpMiZSwr; 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 j192si15986818pgc.415.2019.02.13.07.10.02; Wed, 13 Feb 2019 07:10:18 -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=VpMiZSwr; 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 S2391516AbfBMODL (ORCPT + 99 others); Wed, 13 Feb 2019 09:03:11 -0500 Received: from mail-pg1-f193.google.com ([209.85.215.193]:39692 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726372AbfBMODL (ORCPT ); Wed, 13 Feb 2019 09:03:11 -0500 Received: by mail-pg1-f193.google.com with SMTP id r11so1175586pgp.6 for ; Wed, 13 Feb 2019 06:03:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=H3f1MfvSqhk7fYk2/rKXnYTMr6+lbY/NU0rOXhC8O5U=; b=VpMiZSwr42h7RxTwV/fk8d9BvpQX7IxZRgpbvLieA3dNWhefjo4gx9DsgkSJxHG5xY wC8gs8rhLMdhakzvA7oL3jNRziwz7HEyOTtO2L3OQIzTamDfB/biwjzged3RE0GG3ATU xuWbBjt2GRG8opSicVG2QUTYyUnn+GGduoR+U6oEElaJScHfTOMoRrcwP5w0vms4QADZ 9VBDPI8ieNLKUwgTj1XSYpg8Ft8L5J7CWA6BmuBq/Ue9jTcjw/QWui/8DSIihzIKTXLv OQeBIirsIL7XlCwp3H6auQQD2MIsgvPcgl9fMY7o0nzmpEMK84/HhiQq7ryFqw3J6BLN P70A== 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=H3f1MfvSqhk7fYk2/rKXnYTMr6+lbY/NU0rOXhC8O5U=; b=VtMti/muM2GhBerQnh5RE3nGssJUWw9EVjnitbaOL5EWOjIDOJrHMLsGkFCrpbAzMq MgwR/10wRAqJ2j+TjkHZ+ec1YLPcsiJw75rEZ+isXnPXsf5YreQ2K7lcI2VQWiOGC3j1 7w0kWxKlVcFvDNxT7h3eTvGLAESst4zqbcxodcj/XR107z8k2siFgppf9yDh0G3Tezt4 TIUIOaOpYjf1u+OnAmNC44+0ptJ6P7oWj4lZuK9QpNjoJ9oFrXm0Tdo991/qdlSiORco Yp/vru/NbQMwZQPDOoWxyhm0Pqe5M3LZVPHOwVtlmjC7LD6lP5qx2HcTi6A6vP2nij5j eFwg== X-Gm-Message-State: AHQUAubLgJHRTVZMNHsSeiGfeS3nAcqemv6y2X/5f3LCpZBj4PMcDFDv unsEWzocjeCWsMJYArn5cWw= X-Received: by 2002:aa7:8497:: with SMTP id u23mr631577pfn.253.1550066590259; Wed, 13 Feb 2019 06:03:10 -0800 (PST) Received: from jordon-HP-15-Notebook-PC ([49.207.48.54]) by smtp.gmail.com with ESMTPSA id o2sm27533402pfa.149.2019.02.13.06.03.08 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 13 Feb 2019 06:03:09 -0800 (PST) Date: Wed, 13 Feb 2019 19:37:28 +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 v3 8/9] xen/gntdev.c: Convert to use vm_map_pages() Message-ID: <20190213140728.GA22080@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_map_pages() to map range of kernel memory to user vma. map->count is passed to vm_map_pages() 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..7f65ba3 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_map_pages(vma, map->pages, map->count); + if (err) + goto out_put_map; } else { #ifdef CONFIG_X86 /* -- 1.9.1