From patchwork Wed Aug 7 01:33:37 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: 11080013 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 1DAB71709 for ; Wed, 7 Aug 2019 01:35:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0EB252858E for ; Wed, 7 Aug 2019 01:35:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 01737286A0; Wed, 7 Aug 2019 01:35:34 +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 7C7FD28893 for ; Wed, 7 Aug 2019 01:35:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730048AbfHGBet (ORCPT ); Tue, 6 Aug 2019 21:34:49 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:38796 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730025AbfHGBeq (ORCPT ); Tue, 6 Aug 2019 21:34:46 -0400 Received: by mail-pg1-f195.google.com with SMTP id z14so5311476pga.5; Tue, 06 Aug 2019 18:34:45 -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=30MQZ7ywyXKAPoZ0MqYExKYsjkeLdKEHUByfnmRZCb0=; b=g67RvuXxl/7UgwJ5Nsn5m7mCWAd1eJK19OdXPfHISavNg0/hlxqTRWRiZsiObbIxd1 z7nTlGaqHPYV4ywgcbsmss6gPc+YHifTLpOQY0K91PQUhyOYukJschqLsfaVLze8bLh+ aV53NaTAotE5e+jR4GjhaqKTLNaydraqrAumktndCtlF4SiNrqRjpIehSehjFa47DX/L ADmdLxhsKJt3PHVHlUoQeH6o3x8T/NrnTA5b/OM8c9NkahQxV1Hajc7XXSthUzvuQiX4 tXYs8SD3Ckew9oHpIJy9DZatkhmnngs/Je/q+s3mKD0DprEGB/SuCd9kYNKpjjLfUk8q m4IA== 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=30MQZ7ywyXKAPoZ0MqYExKYsjkeLdKEHUByfnmRZCb0=; b=f6QyoaEfbxuo9tTZknFSAJWqbXuIhDFPUwVE3hdKY/KhN0tssL28PgEds41wQe8rQ7 Mc2KMTcGIcN1oMTYw7EZDVWkX/ES3FEIFu5dyCFNbtAK2m0mxNL5X3YQMi3n0mMloYCf hrxC1dfEzBW06UGbsrqBcqaaSnrzpJ7sVHF7/fuJjUabtXAChd5EYTU+261qU2AVgHek mZbFsyWomhkVZqlLnAlgDt9jk5QdzHy25qQp3HMFLcHa+wASsDrLt+4o9RN5SQqYnb4f nsBi2Quz0YLewB+ul/h2CVL7j+PDv6MgKZPozLm7HNNj3WHNOpEbJZtwwz/xcJLEUVnc 4OIg== X-Gm-Message-State: APjAAAVn0m9D4Y7TjhBzxMxE5E88b1AlbaoYmKoT6aJKB1EXWAHIYp6q sy2AOcgFeJv4bhOy16WhWM0= X-Google-Smtp-Source: APXvYqw4IyvxT+a447mG7S7T32nq/0vx/OylsLzm55tU7UOjf2NCx+Dmal9oDg9eNuXVr0J1x2ZUyQ== X-Received: by 2002:a63:36cc:: with SMTP id d195mr5452828pga.157.1565141685421; Tue, 06 Aug 2019 18:34:45 -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.43 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 06 Aug 2019 18:34:44 -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 , Benjamin Herrenschmidt , Christoph Hellwig , Michael Ellerman , linuxppc-dev@lists.ozlabs.org Subject: [PATCH v3 38/41] powerpc: convert put_page() to put_user_page*() Date: Tue, 6 Aug 2019 18:33:37 -0700 Message-Id: <20190807013340.9706-39-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"). Note that this effectively changes the code's behavior in mm_iommu_unpin(): it now ultimately calls set_page_dirty_lock(), instead of set_page_dirty(). This is probably more accurate. As Christoph Hellwig put it, "set_page_dirty() is only safe if we are dealing with a file backed page where we have reference on the inode it hangs off." [1] [1] https://lore.kernel.org/r/20190723153640.GB720@lst.de Cc: Benjamin Herrenschmidt Cc: Christoph Hellwig Cc: Michael Ellerman Cc: linuxppc-dev@lists.ozlabs.org Signed-off-by: John Hubbard Acked-by: Michael Ellerman (powerpc) --- arch/powerpc/kvm/book3s_64_mmu_hv.c | 4 ++-- arch/powerpc/kvm/book3s_64_mmu_radix.c | 19 ++++++++++++++----- arch/powerpc/kvm/e500_mmu.c | 3 +-- arch/powerpc/mm/book3s64/iommu_api.c | 11 +++++------ 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/arch/powerpc/kvm/book3s_64_mmu_hv.c b/arch/powerpc/kvm/book3s_64_mmu_hv.c index 9a75f0e1933b..18646b738ce1 100644 --- a/arch/powerpc/kvm/book3s_64_mmu_hv.c +++ b/arch/powerpc/kvm/book3s_64_mmu_hv.c @@ -731,7 +731,7 @@ int kvmppc_book3s_hv_page_fault(struct kvm_run *run, struct kvm_vcpu *vcpu, * we have to drop the reference on the correct tail * page to match the get inside gup() */ - put_page(pages[0]); + put_user_page(pages[0]); } return ret; @@ -1206,7 +1206,7 @@ void kvmppc_unpin_guest_page(struct kvm *kvm, void *va, unsigned long gpa, unsigned long gfn; int srcu_idx; - put_page(page); + put_user_page(page); if (!dirty) return; diff --git a/arch/powerpc/kvm/book3s_64_mmu_radix.c b/arch/powerpc/kvm/book3s_64_mmu_radix.c index 2d415c36a61d..f53273fbfa2d 100644 --- a/arch/powerpc/kvm/book3s_64_mmu_radix.c +++ b/arch/powerpc/kvm/book3s_64_mmu_radix.c @@ -821,8 +821,12 @@ int kvmppc_book3s_instantiate_page(struct kvm_vcpu *vcpu, */ if (!ptep) { local_irq_enable(); - if (page) - put_page(page); + if (page) { + if (upgrade_write) + put_user_page(page); + else + put_page(page); + } return RESUME_GUEST; } pte = *ptep; @@ -870,9 +874,14 @@ int kvmppc_book3s_instantiate_page(struct kvm_vcpu *vcpu, *levelp = level; if (page) { - if (!ret && (pte_val(pte) & _PAGE_WRITE)) - set_page_dirty_lock(page); - put_page(page); + bool dirty = !ret && (pte_val(pte) & _PAGE_WRITE); + if (upgrade_write) + put_user_pages_dirty_lock(&page, 1, dirty); + else { + if (dirty) + set_page_dirty_lock(page); + put_page(page); + } } /* Increment number of large pages if we (successfully) inserted one */ diff --git a/arch/powerpc/kvm/e500_mmu.c b/arch/powerpc/kvm/e500_mmu.c index 2d910b87e441..67bb8d59d4b1 100644 --- a/arch/powerpc/kvm/e500_mmu.c +++ b/arch/powerpc/kvm/e500_mmu.c @@ -850,8 +850,7 @@ int kvm_vcpu_ioctl_config_tlb(struct kvm_vcpu *vcpu, free_privs_first: kfree(privs[0]); put_pages: - for (i = 0; i < num_pages; i++) - put_page(pages[i]); + put_user_pages(pages, num_pages); free_pages: kfree(pages); return ret; diff --git a/arch/powerpc/mm/book3s64/iommu_api.c b/arch/powerpc/mm/book3s64/iommu_api.c index b056cae3388b..e126193ba295 100644 --- a/arch/powerpc/mm/book3s64/iommu_api.c +++ b/arch/powerpc/mm/book3s64/iommu_api.c @@ -170,9 +170,8 @@ static long mm_iommu_do_alloc(struct mm_struct *mm, unsigned long ua, return 0; free_exit: - /* free the reference taken */ - for (i = 0; i < pinned; i++) - put_page(mem->hpages[i]); + /* free the references taken */ + put_user_pages(mem->hpages, pinned); vfree(mem->hpas); kfree(mem); @@ -203,6 +202,7 @@ static void mm_iommu_unpin(struct mm_iommu_table_group_mem_t *mem) { long i; struct page *page = NULL; + bool dirty = false; if (!mem->hpas) return; @@ -215,10 +215,9 @@ static void mm_iommu_unpin(struct mm_iommu_table_group_mem_t *mem) if (!page) continue; - if (mem->hpas[i] & MM_IOMMU_TABLE_GROUP_PAGE_DIRTY) - SetPageDirty(page); + dirty = mem->hpas[i] & MM_IOMMU_TABLE_GROUP_PAGE_DIRTY; - put_page(page); + put_user_pages_dirty_lock(&page, 1, dirty); mem->hpas[i] = 0; } }