Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp2534647ybi; Sun, 28 Jul 2019 11:08:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqy5b4G4kkQw8+ejpWlRmnOa7dit4BpOZPZN75K4OUYX1rFUvbUzlw3pkiRxjWqJ4tHu8EYc X-Received: by 2002:a17:90a:37ac:: with SMTP id v41mr103559500pjb.6.1564337316965; Sun, 28 Jul 2019 11:08:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564337316; cv=none; d=google.com; s=arc-20160816; b=aWxARa/CFLw2icpHriOcZvnAwWuNsGNyVVET+BtSX7PxrsqwxeLzHvhGwkpvxchEqy TBd/u/PO2Kgllx9nog/Q0hLZ2F5Yizs8jmrCwyTbmhhN8+z6jN34Iis0MTK3xeaiEFRr kgMhcUc0XHbOgYxbiHWbhFBEql8j0mboy1KXn2X1W9YG7fcvkmmbEX/OX4WGSCy6dA1q MkB9HeYMcKS/cubZEP5Mopm+rdlqOklBlhZrSU94Db2emX1R9Oe7vVdXSGbbyT2vKIam MRX93lkYxySBE77+x+pzV3G7wM5dbljssg9erjHJQQbBGOm6TcaaE2kb+d8rV0+zf1Wx 7C7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=Wuh+r/apknyXeChjuNouckyB6vMRP+244QZYYcOsnlc=; b=HvDmLoCuL5Pwt5AwO8y8hZDtmB/aF9015bj5iz4sS9aD5cM8nxw06CEy6yh17ujdOX 2XdDLRQmZdiuUt2r4mcvSM9rYAYIHnJyndUwcIWz++KDoOlu0dh8e56LXksDtBe53An9 HcZWNNRV8Uvri3X4PBPtPkG0hgPBC7GwplVk9H8FzJgdvljB7GdmY+95lJ6gCroygQEf 7HT5PzJBF7JghWATYjgxiurJS/8RejBkc5tsno5GS9IkbASF9+woEzdiUJhID6lNI6JG qU9p/cYoQzePJTx/jNefU08I/SwbTkNpDCfTBr8+awTnAW1wKwkWS57mQ/VXWQT+DQLu BiOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=wm99k6CR; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d19si25859240pgm.310.2019.07.28.11.08.21; Sun, 28 Jul 2019 11:08:36 -0700 (PDT) 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=@messagingengine.com header.s=fm3 header.b=wm99k6CR; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726178AbfG1SGT (ORCPT + 99 others); Sun, 28 Jul 2019 14:06:19 -0400 Received: from new4-smtp.messagingengine.com ([66.111.4.230]:60311 "EHLO new4-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726046AbfG1SGS (ORCPT ); Sun, 28 Jul 2019 14:06:18 -0400 Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailnew.nyi.internal (Postfix) with ESMTP id 4C10C1DBD; Sun, 28 Jul 2019 14:06:17 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute7.internal (MEProxy); Sun, 28 Jul 2019 14:06:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=Wuh+r/ apknyXeChjuNouckyB6vMRP+244QZYYcOsnlc=; b=wm99k6CR/Q7pt9kdCvdLey W/Zd5DFzUtxNhd3HX++suyBzz7TK2G0RL0mJVxzqWORxcoNWAl+nkwRp2ZPrggdC efeLioNTIdDu0vkrqnJTdRczhzg2bZRl7b/ZElpgAEGSwzK98cYlgyoXOXDyCzpq Op2JcVA1skR2DjpkAsEaXT3UXHsHNTriy7bXq0i5+HPhBD2mnynXOZuFM3JqktPy Uxl+pCEZ+f96B307DWmYV7hireznWPHSPS0tchWNI2UB5dnpgwLxaWr0++dWv14c DFXD7Ov6bd7XJphdbktpQc3ieyZm8MjGQjgSq3tcvZ1O1qHkip/AXSXrxmxj1PBQ == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduvddrkeelgdduvddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggujggfsehgtd erredtreejnecuhfhrohhmpeforghrvghkucforghrtgiihihkohifshhkihdqifpkrhgv tghkihcuoehmrghrmhgrrhgvkhesihhnvhhishhisghlvghthhhinhhgshhlrggsrdgtoh hmqeenucfkphepledurdeihedrfeegrdeffeenucfrrghrrghmpehmrghilhhfrhhomhep mhgrrhhmrghrvghksehinhhvihhsihgslhgvthhhihhnghhslhgrsgdrtghomhenucevlh hushhtvghrufhiiigvpedt X-ME-Proxy: Received: from mail-itl (ip5b412221.dynamic.kabel-deutschland.de [91.65.34.33]) by mail.messagingengine.com (Postfix) with ESMTPA id D197D80059; Sun, 28 Jul 2019 14:06:14 -0400 (EDT) Date: Sun, 28 Jul 2019 20:06:11 +0200 From: Marek =?utf-8?Q?Marczykowski-G=C3=B3recki?= To: Souptick Joarder Cc: 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, xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [Xen-devel] [PATCH v4 8/9] xen/gntdev.c: Convert to use vm_map_pages() Message-ID: <20190728180611.GA20589@mail-itl> References: <20190215024830.GA26477@jordon-HP-15-Notebook-PC> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="MGYHOYXEY6WxJCY8" Content-Disposition: inline In-Reply-To: <20190215024830.GA26477@jordon-HP-15-Notebook-PC> User-Agent: Mutt/1.12+29 (a621eaed) (2019-06-14) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --MGYHOYXEY6WxJCY8 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Feb 15, 2019 at 08:18:31AM +0530, Souptick Joarder wrote: > Convert to use vm_map_pages() to map range of kernel > memory to user vma. >=20 > map->count is passed to vm_map_pages() and internal API > verify map->count against count ( count =3D vma_pages(vma)) > for page array boundary overrun condition. This commit breaks gntdev driver. If vma->vm_pgoff > 0, vm_map_pages will: - use map->pages starting at vma->vm_pgoff instead of 0 - verify map->count against vma_pages()+vma->vm_pgoff instead of just vma_pages(). In practice, this breaks using a single gntdev FD for mapping multiple grants. It looks like vm_map_pages() is not a good fit for this code and IMO it should be reverted. > Signed-off-by: Souptick Joarder > Reviewed-by: Boris Ostrovsky > --- > drivers/xen/gntdev.c | 11 ++++------- > 1 file changed, 4 insertions(+), 7 deletions(-) >=20 > diff --git a/drivers/xen/gntdev.c b/drivers/xen/gntdev.c > index 5efc5ee..5d64262 100644 > --- a/drivers/xen/gntdev.c > +++ b/drivers/xen/gntdev.c > @@ -1084,7 +1084,7 @@ static int gntdev_mmap(struct file *flip, struct vm= _area_struct *vma) > int index =3D vma->vm_pgoff; > int count =3D vma_pages(vma); > struct gntdev_grant_map *map; > - int i, err =3D -EINVAL; > + int err =3D -EINVAL; > =20 > if ((vma->vm_flags & VM_WRITE) && !(vma->vm_flags & VM_SHARED)) > return -EINVAL; > @@ -1145,12 +1145,9 @@ static int gntdev_mmap(struct file *flip, struct v= m_area_struct *vma) > goto out_put_map; > =20 > if (!use_ptemod) { > - for (i =3D 0; i < count; i++) { > - err =3D vm_insert_page(vma, vma->vm_start + i*PAGE_SIZE, > - map->pages[i]); > - if (err) > - goto out_put_map; > - } > + err =3D vm_map_pages(vma, map->pages, map->count); > + if (err) > + goto out_put_map; > } else { > #ifdef CONFIG_X86 > /* --=20 Best Regards, Marek Marczykowski-G=C3=B3recki Invisible Things Lab A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing? --MGYHOYXEY6WxJCY8 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEEhrpukzGPukRmQqkK24/THMrX1ywFAl095BIACgkQ24/THMrX 1yziIAf/exzcYKVSO+KS0CX9O2QdFSocXv52LbbEaeXP7AvIDXtfXcdbvxrkBwyA dM4LYJgnMPbjYusQKNqWNDwi16zSJJgNfM0F4g+B4Ch2wkPXqCsobfHILsV8/x96 uYVr05q30FJ5goCzeMvQMNdPwDHv6+xGalM5Zhl56Xj+BGUQNmKo5sw2dAvarOM2 vdJUiQvbaZSBYSLZnufgbaEoZsXKQpDJftX7uM2gt6qmW3OwcEyhhGVI9loMCyJ5 jCWaVsXNj3EW/pZpwSX2nJgygQEp0C0x6xIZrG9rPNt/mZClap556QsmZzUkZDN7 92r6MMVJJLYyM0f880I5KEOKsIGNaQ== =PmYG -----END PGP SIGNATURE----- --MGYHOYXEY6WxJCY8--