From patchwork Wed Aug 7 01:33:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: john.hubbard@gmail.com X-Patchwork-Id: 11080397 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 5594B1399 for ; Wed, 7 Aug 2019 01:38:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4690A28068 for ; Wed, 7 Aug 2019 01:38:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 39DF92887D; Wed, 7 Aug 2019 01:38:46 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C741C2888B for ; Wed, 7 Aug 2019 01:38:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729526AbfHGBeW (ORCPT ); Tue, 6 Aug 2019 21:34:22 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:39655 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729486AbfHGBeV (ORCPT ); Tue, 6 Aug 2019 21:34:21 -0400 Received: by mail-pg1-f196.google.com with SMTP id u17so42543853pgi.6; Tue, 06 Aug 2019 18:34:20 -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=PTeNIVNtmjQFCjQxL5R5M/OrbQjiP2mk2OJMaygoDr4=; b=BG5A7XtqqH4f15Klc4uU0q4X0R2Yv3wfhImw8oiXt1v6JO5KY1LfJ/FOOlCOXGnxrU VariQ4IygIhND6FU5kQCuk9//LCB/lYGlYLJ8TWLMj0IGcKtGZaK7cHMiGMOL9oUoiZc YswM2ntpv1sQkIcN3tEUtcv2aNlSoNXxcBOnTcDMk5HYtBIeSLrq5eWXN9nroLrC19Z/ C0ZG1Pu1hecBjOrW3c3xob4Zs7H7sVar9fXDnKdmBW1H5ACiR9/XADMiFFYI0P1SdPij tJqcrXGje17KBWR1RldTVMzhM/TqzNCkMDLzOIHQRTxPFXZrOO5rIe3URKbbtNFMFJkR bC8w== 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=PTeNIVNtmjQFCjQxL5R5M/OrbQjiP2mk2OJMaygoDr4=; b=kRVJieXvImOixcfFLveXbK99FGO7xgUMCGKlHLH4esjlLpSulhjS86h0P2hM7mbmVe o334t0YiA3MDisTQfOOcxiIIS9EGZ3Opq4zxG7L+IBERPFet9BN/gcVva9O28UPCpOmk qO+fYW2twZcxq3AP3+Id+ydCivM0okMJOg/qpnHVAXA84++7gZYbQrvrzMzFoQaT+e7/ +uo9x2S7Iqc6OtX2lORuMHVQYVcxY5f/58Tq5O5cNClhEEGUZZsEv+NoSzBak2GfXmWx JrweIG62ZfsIN7sO5/ufn6Wcw+on7TtjFVUbgDI+j8QkpZ+T1J+IMcBZrfh3tm8Bwl41 XRHw== X-Gm-Message-State: APjAAAUfP7Jr2mRlKMkonW4uVx5Srq6vayFqOxdbOZx7hdM5RE5YSjR/ s7HnxSlzjb11cb/fLdWEiDM= X-Google-Smtp-Source: APXvYqwNS1xrXhm+UjCuzC7PKxoGrXRgWDwKbPmsbF2Yg7VGgKZOnBNXO8oPa1127+JgtcA8HVibPw== X-Received: by 2002:a63:c055:: with SMTP id z21mr5455551pgi.380.1565141660136; Tue, 06 Aug 2019 18:34:20 -0700 (PDT) Received: from blueforge.nvidia.com (searspoint.nvidia.com. [216.228.112.21]) by smtp.gmail.com with ESMTPSA id u69sm111740800pgu.77.2019.08.06.18.34.18 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 06 Aug 2019 18:34:19 -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?b?SsOpcsO0?= =?utf-8?b?bWUgR2xpc3Nl?= , 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 v3 22/41] xen: convert put_page() to put_user_page*() Date: Tue, 6 Aug 2019 18:33:21 -0700 Message-Id: <20190807013340.9706-23-jhubbard@nvidia.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190807013340.9706-1-jhubbard@nvidia.com> References: <20190807013340.9706-1-jhubbard@nvidia.com> MIME-Version: 1.0 X-NVConfidentiality: public Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Cc: Boris Ostrovsky Cc: xen-devel@lists.xenproject.org Signed-off-by: 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);