Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp2022842ybh; Sun, 4 Aug 2019 15:53:33 -0700 (PDT) X-Google-Smtp-Source: APXvYqwphiR0HvxAFeUY7YqlAUjPWtRHCx9CCeE6K47oRRv8xa5QRYrG27w1D1hGHJ9tzFO59YsV X-Received: by 2002:a17:902:a612:: with SMTP id u18mr137502747plq.181.1564959213064; Sun, 04 Aug 2019 15:53:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564959213; cv=none; d=google.com; s=arc-20160816; b=brmhmRetH8Qq7fa41eXV7aW2KtlpxkIiXCZpDBN3uitMLXr47vwa5EAP9rQorVDRam 2jZ+qFPN3pBdLBMslkCQ9/tv1JBIYru8p3JwzsCeNScwrWhke40UHUt8Kx73yYEH4wQo pmiztgGOXEi9erPnEzr0V5s80KeLTm2ydl0FdpB4+sbihsZASSNfw9hCvZqFgyy9xcJ6 5KQZBkXj0yWXvSZPLUQrhMzMsQVArle+5qzo27RMq65sbcdOh4NkuGDXdNRErgD9EU+d 0ggRvU5zsVjVNEup6pcrM4E4O7/qu9eekEq7KfJ08WOFGNZfNcqbjUcSTju0dJD4+Wno H1ew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=AuJQGBUMCI3UccHUazXwp/b3Q3tZUYyhW4Da3QIy1yc=; b=W71R1TZsznhHoKyHDlhGcXUpwoJi1uivVU+vaopJOtNLZR5QnJaQqi2aJSNPq+Pd79 UWwPVk7EljnE33C1w7JPrgjzgRUUUq9pLi7DM9BvPuuVmz2dKMjVum8umo4gNH/t88kb XWroKHLKZPHli21KNNzK1NQHmW55a+FSGlh2Htln6v1oyTH80FnUKAjEEDuzsffPhmH3 rbDKCW0dMxNxC+rCyaFauMUtz8PUvg2zmfyn2fXA2Q/GTor1L+Mc7FIguK8piQqbrVx6 UzvDOKPAHtx4QnIN6c7sUPLZ8UJBk3lx1Pik/i0N7w0Nbyg30BPf0tGcUn3GStdyWfeZ lVTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=DGwCGc6X; spf=pass (google.com: best guess record for domain of linux-nfs-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-nfs-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 h38si24571901pgi.327.2019.08.04.15.53.20; Sun, 04 Aug 2019 15:53:33 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-nfs-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=DGwCGc6X; spf=pass (google.com: best guess record for domain of linux-nfs-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-nfs-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 S1727855AbfHDWxI (ORCPT + 99 others); Sun, 4 Aug 2019 18:53:08 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:39554 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727556AbfHDWtw (ORCPT ); Sun, 4 Aug 2019 18:49:52 -0400 Received: by mail-pf1-f195.google.com with SMTP id f17so34607334pfn.6; Sun, 04 Aug 2019 15:49:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AuJQGBUMCI3UccHUazXwp/b3Q3tZUYyhW4Da3QIy1yc=; b=DGwCGc6XDVUwXaE45gbbQy6fhhO+2zHlJorg8NcW6argb8euBbhs0pQfwz4p3wmYGr nE4Tqc1S5TSCGn3z79bluHB8kOP9URQ6GDk8Ag8nOY+Zwx7t9ZzdbkCdvZMxHFv73WPf yFrTejZLylWrlE9UzmSxnSGub+p3uIuGa+QwFG1rIqaL2jFj/TWeF75UBCckNw/JWLPd Hk2vfaOt8Y8GmAEec78Ag4Fdx8td9DJVeEYJYZvv4nQW4t60cvCAgLcPPzOrCX7IP55D 7nJuSqZwA2LhbQQi1IP2+3jA4kCrhPeh22tmmVy2bqH2f2tTU9mzsW8VQ8AU7oTjorNW HTKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=AuJQGBUMCI3UccHUazXwp/b3Q3tZUYyhW4Da3QIy1yc=; b=rsDXgi13CaLiZjmBZHXsrliGgVCY9blPnBsQ4LW3pBW4WxGZAAZZUql3miWMFRC/xU omvUs4E0jIYkGtGQn+QgoGmrmdQE+VWh9+ur2VTcQu/afYTYRsP9gy8QunM84C3KwJ0a kGRu2Rey9XBqlBEcv0tgL/tVeO5b5ey57mfjll+LqB2sIkOuqarafOUM2jXmKph/Popb D55AW5oho4x6h8N7QKNBQuXB3/3scNDomqfFBgBVcroYiZLdGISxK6w2KstsQVoGMpXG zUatKohnXgrMUW12c33InV1FRRMwVQSiaxl0t9hAGzB/khJHCedVrS16VXAim3nGVJGV 7VNA== X-Gm-Message-State: APjAAAWq4zizDowjior0QQG0Lfdbm3DPLcJCQYLPqHEBc7T8rZYUGQIt x9I3Wy4gazSKVXTqdV3VwuA= X-Received: by 2002:a63:c006:: with SMTP id h6mr3370638pgg.290.1564958991047; Sun, 04 Aug 2019 15:49:51 -0700 (PDT) Received: from blueforge.nvidia.com (searspoint.nvidia.com. [216.228.112.21]) by smtp.gmail.com with ESMTPSA id r6sm35946836pjb.22.2019.08.04.15.49.49 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sun, 04 Aug 2019 15:49:50 -0700 (PDT) From: john.hubbard@gmail.com X-Google-Original-From: jhubbard@nvidia.com To: Andrew Morton Cc: Christoph Hellwig , Dan Williams , Dave Chinner , Dave Hansen , Ira Weiny , Jan Kara , Jason Gunthorpe , =?UTF-8?q?J=C3=A9r=C3=B4me=20Glisse?= , LKML , amd-gfx@lists.freedesktop.org, ceph-devel@vger.kernel.org, devel@driverdev.osuosl.org, devel@lists.orangefs.org, dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-block@vger.kernel.org, linux-crypto@vger.kernel.org, linux-fbdev@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-media@vger.kernel.org, linux-mm@kvack.org, linux-nfs@vger.kernel.org, linux-rdma@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, linux-xfs@vger.kernel.org, netdev@vger.kernel.org, rds-devel@oss.oracle.com, sparclinux@vger.kernel.org, x86@kernel.org, xen-devel@lists.xenproject.org, John Hubbard , Juergen Gross , Boris Ostrovsky Subject: [PATCH v2 20/34] xen: convert put_page() to put_user_page*() Date: Sun, 4 Aug 2019 15:49:01 -0700 Message-Id: <20190804224915.28669-21-jhubbard@nvidia.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190804224915.28669-1-jhubbard@nvidia.com> References: <20190804224915.28669-1-jhubbard@nvidia.com> MIME-Version: 1.0 X-NVConfidentiality: public Content-Transfer-Encoding: 8bit Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: John Hubbard For pages that were retained via get_user_pages*(), release those pages via the new put_user_page*() routines, instead of via put_page() or release_pages(). This is part a tree-wide conversion, as described in commit fc1d8e7cca2d ("mm: introduce put_user_page*(), placeholder versions"). This also handles pages[i] == NULL cases, thanks to an approach that is actually written by Juergen Gross. Signed-off-by: Juergen Gross Signed-off-by: John Hubbard Cc: Boris Ostrovsky Cc: xen-devel@lists.xenproject.org --- Hi Juergen, Say, this is *exactly* what you proposed in your gup.patch, so I've speculatively added your Signed-off-by above, but need your approval before that's final. Let me know please... thanks, John Hubbard drivers/xen/privcmd.c | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/drivers/xen/privcmd.c b/drivers/xen/privcmd.c index c6070e70dd73..c7d0763ca8c2 100644 --- a/drivers/xen/privcmd.c +++ b/drivers/xen/privcmd.c @@ -582,10 +582,11 @@ static long privcmd_ioctl_mmap_batch( static int lock_pages( struct privcmd_dm_op_buf kbufs[], unsigned int num, - struct page *pages[], unsigned int nr_pages) + struct page *pages[], unsigned int *nr_pages) { - unsigned int i; + unsigned int i, free = *nr_pages; + *nr_pages = 0; for (i = 0; i < num; i++) { unsigned int requested; int pinned; @@ -593,35 +594,22 @@ static int lock_pages( requested = DIV_ROUND_UP( offset_in_page(kbufs[i].uptr) + kbufs[i].size, PAGE_SIZE); - if (requested > nr_pages) + if (requested > free) return -ENOSPC; pinned = get_user_pages_fast( (unsigned long) kbufs[i].uptr, - requested, FOLL_WRITE, pages); + requested, FOLL_WRITE, pages + *nr_pages); if (pinned < 0) return pinned; - nr_pages -= pinned; - pages += pinned; + free -= pinned; + *nr_pages += pinned; } return 0; } -static void unlock_pages(struct page *pages[], unsigned int nr_pages) -{ - unsigned int i; - - if (!pages) - return; - - for (i = 0; i < nr_pages; i++) { - if (pages[i]) - put_page(pages[i]); - } -} - static long privcmd_ioctl_dm_op(struct file *file, void __user *udata) { struct privcmd_data *data = file->private_data; @@ -681,11 +669,12 @@ static long privcmd_ioctl_dm_op(struct file *file, void __user *udata) xbufs = kcalloc(kdata.num, sizeof(*xbufs), GFP_KERNEL); if (!xbufs) { + nr_pages = 0; rc = -ENOMEM; goto out; } - rc = lock_pages(kbufs, kdata.num, pages, nr_pages); + rc = lock_pages(kbufs, kdata.num, pages, &nr_pages); if (rc) goto out; @@ -699,7 +688,8 @@ static long privcmd_ioctl_dm_op(struct file *file, void __user *udata) xen_preemptible_hcall_end(); out: - unlock_pages(pages, nr_pages); + if (pages) + put_user_pages(pages, nr_pages); kfree(xbufs); kfree(pages); kfree(kbufs); -- 2.22.0