From patchwork Sun May 14 21:26:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13240572 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9EAA5C77B7D for ; Sun, 14 May 2023 21:26:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F3416900004; Sun, 14 May 2023 17:26:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EE363900002; Sun, 14 May 2023 17:26:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DAADA900004; Sun, 14 May 2023 17:26:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id CE783900002 for ; Sun, 14 May 2023 17:26:52 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 9F434A125A for ; Sun, 14 May 2023 21:26:52 +0000 (UTC) X-FDA: 80790145464.18.D7B0DFD Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) by imf18.hostedemail.com (Postfix) with ESMTP id C838A1C0005 for ; Sun, 14 May 2023 21:26:49 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=sdn5c8Jj; spf=pass (imf18.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.221.51 as permitted sender) smtp.mailfrom=lstoakes@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684099609; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=zDRI/SmuJW1MOkHOGv6LoDkcQTN7wDGl7tj3wYSbUK8=; b=GTkT7h7xHy9GSrFk/auczAXNSoaoWxiPTcnaeVhleGRU78poM1kXCRnhw/yDR2izO0I1c6 AN9irJMif1VhZGOyVosPVGClFoRCIN2mE8x2FsJ7r90LJs8VS7Omvgh2/WTmrtYaOxvX8B SlUUUc7NFjcpZMWK2vzEtKpjkIEyHyU= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=sdn5c8Jj; spf=pass (imf18.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.221.51 as permitted sender) smtp.mailfrom=lstoakes@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684099609; a=rsa-sha256; cv=none; b=NDZz1u158MzAtsjHsvk5znrXo7/0wg2wpM/B2OmKLrCG1JfzJy+CCpob3f0OnChoMP0mJ6 AFn8CqFO4RkL0NvYeB7mqJpDYr1BF1XYEvUvfXJ+tjYvw7BAPylWDyw3YN+KpDsqAzF8X9 yHJzbVFZM4yoMJE7txtMsErTTktS+vs= Received: by mail-wr1-f51.google.com with SMTP id ffacd0b85a97d-30639daee76so7726388f8f.1 for ; Sun, 14 May 2023 14:26:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684099608; x=1686691608; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zDRI/SmuJW1MOkHOGv6LoDkcQTN7wDGl7tj3wYSbUK8=; b=sdn5c8JjWfT/id4kBAa2qLnZNzDuFeXXKXgxcLiuPLppaNWdJBOvyxDpS0VFlVludQ uptDi3JKAyFFeJieI45zFd+JYNbT056xyHCT29j/0yOTbU+LcrSMFcc9pRsij0+QeE6L AG2IhZ2UxfA+1xGP8Ce1JqANQZaqVHtk2a8Q0qhbWzxGMtp32DM/XDvP+qb/pthLkgtH B8cdnnioE9cewziKOptRqqjbwbfq9jPJgEsg1XQi50vJEh1hcTypP3mTST/EhQ9nQv7v u8GXlWjDSXOyPjxevErNsh3kIk0VPGA+zC1ai88lFF+/URQmt3mnoKxdV8Cbu7m958DV SNug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684099608; x=1686691608; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zDRI/SmuJW1MOkHOGv6LoDkcQTN7wDGl7tj3wYSbUK8=; b=kEJ2xCRz35Ain7XuhuwvEa7lZqMspBwiYKQFasRamcuZWuFhPyehM8+F3HfrDxZkng iSMmkWbL9Pv5f0i5TIC7iV9TTqDSjvK8PkneE767wugJAbPTRZjne9DD9wfTg6gcyinW lKRs4f+xiOx3THIPgViX9YOlhUj5XTcSw6qXwDUXQMbG8pLYwUJjTHRoFni7McLNNBvE DW5kEQF50+vs0UKYse9TyQVvahmTXWbk28chWnkBOkWNUyXLaMg6T/L9zX7m2fPWxBUj baIQ66x2NUnGHLofwjFwLQHVean0pUweknC+T0nGpf2kg2Al0nOu+4FiDnV9/h+PvoO5 pvCQ== X-Gm-Message-State: AC+VfDyy/XQrsrp74nBuatcH5D9TkEFktlx7uCImg5thlJe5CqEZoMht BsBP0+oIYkpPUelAxz/o2aO3QKHN0AUn9Q== X-Google-Smtp-Source: ACHHUZ7sG7Qk0+WYMTV6b4v9dHtB0zmY4Zy9Nl7tvG7pDojdVP+7xDTkXtnFXvGR7e5uzEeCeZ2TfA== X-Received: by 2002:adf:f491:0:b0:306:31b7:abe4 with SMTP id l17-20020adff491000000b0030631b7abe4mr26212161wro.14.1684099607746; Sun, 14 May 2023 14:26:47 -0700 (PDT) Received: from lucifer.home ([2a00:23c5:dc8c:8701:1663:9a35:5a7b:1d76]) by smtp.googlemail.com with ESMTPSA id o1-20020a5d6701000000b003063a1cdaf2sm30433846wru.48.2023.05.14.14.26.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 May 2023 14:26:46 -0700 (PDT) From: Lorenzo Stoakes To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton Cc: Matthew Wilcox , David Hildenbrand , x86@kernel.org, linux-sgx@vger.kernel.org, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, kvm@vger.kernel.org, Thomas Gleixner , Ingo Molnar , Borislav Petkov , Jarkko Sakkinen , "H . Peter Anvin" , Xinhui Pan , David Airlie , Daniel Vetter , Dimitri Sivanich , Arnd Bergmann , Greg Kroah-Hartman , Paolo Bonzini , Jens Axboe , Pavel Begunkov , Jason Gunthorpe , John Hubbard , Christian Konig , Lorenzo Stoakes , Jason Gunthorpe Subject: [PATCH v5 1/6] mm/gup: remove unused vmas parameter from get_user_pages() Date: Sun, 14 May 2023 22:26:41 +0100 Message-Id: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: C838A1C0005 X-Stat-Signature: sfitoh9xdre7r9edpqenfjzmt5opwt9o X-HE-Tag: 1684099609-348021 X-HE-Meta: U2FsdGVkX19K6caEojV353OHtdxM4FeizyMIdfGeKsIGxC7sqLd4Wougx9yOm/58BQK3KLdWbIMEB0y/cRUZLad08YmOSA7scFuWXOuqdQp6YZdauvsyVeI7x48dz/MLouQAqHrbfHgZSaJwkGtu9g9CF1nPWLyNZA6SfeNEm5bE3i2VbYFcIQz7Ld6F6pGDW0kt7+g4wY8J3w6uUbMMlnlysCO7F/HQUlFrYoXbfDByL3h3WCok/k7m5P6xLzdcVxMbZNnqoGLfj9/h2PHmtNEmH9p10StNbO8Jn8Hpv1hUJaW20JfdWjZn4WqLNobniqw/3kjwAbuLOV3XsIgCqkSBb3DYIKWvnZqGDJcEqvgoehXMudGi6NuaqJ2O7+ZbRXz96bfcd8ZCWYBVI7Sd8C33WCX0GKEjFxy36wqvm9xE7sblenVahC8XFiHvnAvEUuflqVv3u2Z0w+CzDXcCFAoT8bCVl6w6akFqDczocPFKqwZH0bpniXzZJdrPzDnZkt6fhrRJ20B90QZ1f+lUnmMPjLG5qDIKIjhRNLQxvwajoHwHvB+ZLP4/yjA5BpQIu/AmyXAMQ97DCg+1C1V2ICUZm+oZdSXH/CK0HIBKNTyvl7XmMpZpTKLDesbGfYjYeSr9UGJiVnWfWhNWMdyUcuw9cSHWO9RzSTikxz52eYpr5eH3JY6xdJSmLr9eVrIimEquHFlMbrUk2Kn+KldcAFK8wjlzJkMz/KAVSaKGg45B7Gm2Q+MvqDg/cxQEBnyxgooX5XhnCOwelUnrv2g25xnO3sZRXZsx/s9joo7agO0Ft/0uVgnwJCqb59c4zoXS1MBBRU0ppYVsA4TG+0T/6+00cjZVUoS2mExN4xK3hqooGRJUX7+lO0ZS0w3/CjnCx8ikWlnWJwkVgLVQzrNKRGz3bISquXDe7cwrdI3NBRl6GD4yxfrYlWwKqzU0ykXb+83SU8TaoHLYHGI/X/O PbuP2nx6 fz4NgRELe96I3ykRy2UYTg4MN1Xl3S26iQlsUw1yGAB95whmy0GaSjSwXq3FcQgJB8tMXhy95B72wj+miQM5oB32Dyj25tslrOfl2FVzcV29l78kKUjJPzMWcP7a43qItiUaW6jcvL5FYZ8Q+n48qIRsmN80AXuCtzAWOBk9EbOzQLmLRkdm3yoxgJwlEe50Y3YcbctjmnhEnHLvH65frth5qdRNXfFUP8bDzpVvvzXIU2PLpHINWhBKXZX+G2i+KJ41Fnyz6pErXMZyWtOjZpKBC+SvS6vt6xAYqCNkRQYS3nP4K/b0rr4CO2Myg6gfnPRJKLDxXXIh42kZlb5LVNZBxD19MmhAsGeMINKCVRp301M5E+T/tUvu58ICO+1GRhfrcfeYGIgdvNilOvttJUPhTdaL0o4/nwU6tZ2Yy3+xWSom2av97HrsrV+/7tv9z1F8fm0zReCEiF8Yv7Tv0lN771m5kKSNdZ+d1GkWMfaO57Qi3VTqiWZp3qjDnwJoTnGqxDjSp0LFbJRocSidPq5FPxKsXWlLetqEPL68hzvkne3OZw3OFOUjjvW2RUQWljUgF4K6hFxlJTFo4grnb80dR5QOyVNv0Z1JTIohw+6tSr/FfivrIY787fCzrjp6ZRnKzNAS5nLqEiHBGh+gBdOvJ824teBbYta5wwaCbjknhl33Ir3nHDQDmwjirjaTiBVsE+JTPnxBNlGKm5EZOeTfK8D+471/uVSnAtkfYNI1WcAaoQQofuKOBmQg1/JmXmNaUdl3T2k3gv636mHYtYHaF/iMe6NSNBbwOtFa1QqQ7lq0= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: No invocation of get_user_pages() use the vmas parameter, so remove it. The GUP API is confusing and caveated. Recent changes have done much to improve that, however there is more we can do. Exporting vmas is a prime target as the caller has to be extremely careful to preclude their use after the mmap_lock has expired or otherwise be left with dangling pointers. Removing the vmas parameter focuses the GUP functions upon their primary purpose - pinning (and outputting) pages as well as performing the actions implied by the input flags. This is part of a patch series aiming to remove the vmas parameter altogether. Suggested-by: Matthew Wilcox (Oracle) Acked-by: Greg Kroah-Hartman Acked-by: David Hildenbrand Reviewed-by: Jason Gunthorpe Acked-by: Christian König (for radeon parts) Acked-by: Jarkko Sakkinen Signed-off-by: Lorenzo Stoakes Reviewed-by: Christoph Hellwig Acked-by: Sean Christopherson (KVM) --- arch/x86/kernel/cpu/sgx/ioctl.c | 2 +- drivers/gpu/drm/radeon/radeon_ttm.c | 2 +- drivers/misc/sgi-gru/grufault.c | 2 +- include/linux/mm.h | 3 +-- mm/gup.c | 9 +++------ mm/gup_test.c | 5 ++--- virt/kvm/kvm_main.c | 2 +- 7 files changed, 10 insertions(+), 15 deletions(-) diff --git a/arch/x86/kernel/cpu/sgx/ioctl.c b/arch/x86/kernel/cpu/sgx/ioctl.c index 21ca0a831b70..5d390df21440 100644 --- a/arch/x86/kernel/cpu/sgx/ioctl.c +++ b/arch/x86/kernel/cpu/sgx/ioctl.c @@ -214,7 +214,7 @@ static int __sgx_encl_add_page(struct sgx_encl *encl, if (!(vma->vm_flags & VM_MAYEXEC)) return -EACCES; - ret = get_user_pages(src, 1, 0, &src_page, NULL); + ret = get_user_pages(src, 1, 0, &src_page); if (ret < 1) return -EFAULT; diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c index 2220cdf6a3f6..3a9db030f98f 100644 --- a/drivers/gpu/drm/radeon/radeon_ttm.c +++ b/drivers/gpu/drm/radeon/radeon_ttm.c @@ -359,7 +359,7 @@ static int radeon_ttm_tt_pin_userptr(struct ttm_device *bdev, struct ttm_tt *ttm struct page **pages = ttm->pages + pinned; r = get_user_pages(userptr, num_pages, write ? FOLL_WRITE : 0, - pages, NULL); + pages); if (r < 0) goto release_pages; diff --git a/drivers/misc/sgi-gru/grufault.c b/drivers/misc/sgi-gru/grufault.c index b836936e9747..378cf02a2aa1 100644 --- a/drivers/misc/sgi-gru/grufault.c +++ b/drivers/misc/sgi-gru/grufault.c @@ -185,7 +185,7 @@ static int non_atomic_pte_lookup(struct vm_area_struct *vma, #else *pageshift = PAGE_SHIFT; #endif - if (get_user_pages(vaddr, 1, write ? FOLL_WRITE : 0, &page, NULL) <= 0) + if (get_user_pages(vaddr, 1, write ? FOLL_WRITE : 0, &page) <= 0) return -EFAULT; *paddr = page_to_phys(page); put_page(page); diff --git a/include/linux/mm.h b/include/linux/mm.h index db3f66ed2f32..2c1a92bf5626 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2382,8 +2382,7 @@ long pin_user_pages_remote(struct mm_struct *mm, unsigned int gup_flags, struct page **pages, struct vm_area_struct **vmas, int *locked); long get_user_pages(unsigned long start, unsigned long nr_pages, - unsigned int gup_flags, struct page **pages, - struct vm_area_struct **vmas); + unsigned int gup_flags, struct page **pages); long pin_user_pages(unsigned long start, unsigned long nr_pages, unsigned int gup_flags, struct page **pages, struct vm_area_struct **vmas); diff --git a/mm/gup.c b/mm/gup.c index 90d9b65ff35c..b8189396f435 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -2294,8 +2294,6 @@ long get_user_pages_remote(struct mm_struct *mm, * @pages: array that receives pointers to the pages pinned. * Should be at least nr_pages long. Or NULL, if caller * only intends to ensure the pages are faulted in. - * @vmas: array of pointers to vmas corresponding to each page. - * Or NULL if the caller does not require them. * * This is the same as get_user_pages_remote(), just with a less-flexible * calling convention where we assume that the mm being operated on belongs to @@ -2303,16 +2301,15 @@ long get_user_pages_remote(struct mm_struct *mm, * obviously don't pass FOLL_REMOTE in here. */ long get_user_pages(unsigned long start, unsigned long nr_pages, - unsigned int gup_flags, struct page **pages, - struct vm_area_struct **vmas) + unsigned int gup_flags, struct page **pages) { int locked = 1; - if (!is_valid_gup_args(pages, vmas, NULL, &gup_flags, FOLL_TOUCH)) + if (!is_valid_gup_args(pages, NULL, NULL, &gup_flags, FOLL_TOUCH)) return -EINVAL; return __get_user_pages_locked(current->mm, start, nr_pages, pages, - vmas, &locked, gup_flags); + NULL, &locked, gup_flags); } EXPORT_SYMBOL(get_user_pages); diff --git a/mm/gup_test.c b/mm/gup_test.c index 8ae7307a1bb6..9ba8ea23f84e 100644 --- a/mm/gup_test.c +++ b/mm/gup_test.c @@ -139,8 +139,7 @@ static int __gup_test_ioctl(unsigned int cmd, pages + i); break; case GUP_BASIC_TEST: - nr = get_user_pages(addr, nr, gup->gup_flags, pages + i, - NULL); + nr = get_user_pages(addr, nr, gup->gup_flags, pages + i); break; case PIN_FAST_BENCHMARK: nr = pin_user_pages_fast(addr, nr, gup->gup_flags, @@ -161,7 +160,7 @@ static int __gup_test_ioctl(unsigned int cmd, pages + i, NULL); else nr = get_user_pages(addr, nr, gup->gup_flags, - pages + i, NULL); + pages + i); break; default: ret = -EINVAL; diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index cb5c13eee193..eaa5bb8dbadc 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -2477,7 +2477,7 @@ static inline int check_user_page_hwpoison(unsigned long addr) { int rc, flags = FOLL_HWPOISON | FOLL_WRITE; - rc = get_user_pages(addr, 1, flags, NULL, NULL); + rc = get_user_pages(addr, 1, flags, NULL); return rc == -EHWPOISON; } From patchwork Sun May 14 21:26:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13240573 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7AC34C7EE22 for ; Sun, 14 May 2023 21:26:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 017C5900005; Sun, 14 May 2023 17:26:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F0A3D900002; Sun, 14 May 2023 17:26:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E042C900005; Sun, 14 May 2023 17:26:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id D3D9B900002 for ; Sun, 14 May 2023 17:26:55 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id A28321611D2 for ; Sun, 14 May 2023 21:26:55 +0000 (UTC) X-FDA: 80790145590.07.69AF950 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) by imf27.hostedemail.com (Postfix) with ESMTP id C571040007 for ; Sun, 14 May 2023 21:26:53 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=P9v4mBU3; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf27.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.47 as permitted sender) smtp.mailfrom=lstoakes@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684099613; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ZmBAahwH3yBC6wiSFBmCvOUJZc6pQJuHBQHQjehZN04=; b=iQtYmnOcp5t6sQDpYqBQSiF77p587v++xfXS7XxuCaCm0HBi4KY6eRVO4fswucau65ugKr Bc0qqf2Nu28mdHsjehCpZTVPEnOuiCqbQV4MmIVUMvLv/+IRxuhItbmAsoRUdaKTEm0VUS uhRXfHDi80fD568hi3yvwBmBKUeL8KM= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=P9v4mBU3; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf27.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.47 as permitted sender) smtp.mailfrom=lstoakes@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684099613; a=rsa-sha256; cv=none; b=XCywXnGpIQICWEBUHra7wibnkNZhu0vzCRmVejjEJ9xyFnDKucRSagps7gIofmMnV4hOsE 8+R3NNpyPLlO5u9nUW41ulL6BUeAvYA5LfW36HcTEWO92AxEZWOBl2Qq7BTElbz9oRxvZu 0c/pK144pwleLL6pgATV2cb/UpEm1g0= Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-3f435658d23so57742765e9.3 for ; Sun, 14 May 2023 14:26:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684099612; x=1686691612; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ZmBAahwH3yBC6wiSFBmCvOUJZc6pQJuHBQHQjehZN04=; b=P9v4mBU31DGSqiMeXVGSxNgDot0QvCFZEg81a2ZqSRg8aNjpkh1heg2g0YDLwGP1WW pumh6XzLEJs+M0DyO1sdJOxuO5GXSIg7X98SLUQn5Aq+xU++Ezi5PFtH7qk9tEVHDcVU PtifjH/BqYn+H9IvTbDYymR3gOt7fAs8busLuz8pPLS9adFg/Q17UmH2jxfHUYC7/ffW O3fouSy/AkWD38T9QKesFhyoTZHE7Ndr/7ZPCy9pQbJ2TshQhoPGX6sP53+BdEOT6/6a XApfU798flXg+lhZw7l9ve1Ik8oxAjkwIqV0AzasmwGY7WoC2ffal7clqg7KJx8Mk/xe QpCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684099612; x=1686691612; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZmBAahwH3yBC6wiSFBmCvOUJZc6pQJuHBQHQjehZN04=; b=ROhYdcbj9ToImTw/fIzjAVj80XfhymnC7qCd9y74bb2uki780lbR3Z7mqYa9NmnjY/ +xHpBuN0xJd/OItqqtpkKBS07jmvgOEvcOSbGKMqKAvbX17PM5TtuaaClftN0VisTmd6 Uc0updI2YZ3qPlhtC/FRDKVX5G+33Vy1mzxJGhCRxlAdvK3N3amhVhkHofJuPV1brcuA xG9gibgdXZnkl+oaRAwhQKbB2zMgWjNzF5VYsMvDRthFmG8zzwzYwjxoWubWN1x6Th96 4+HmRj45Fwq1bYD7y3LI9PyA0FULM71uEVy2nmPjFl2RVx83Ks7nybCcrYcFw9eypVT5 avxA== X-Gm-Message-State: AC+VfDwxKmyJT5cOauSdisuAorR6XOVaiDrTtOUd/LyNoR50GMK1wbpB UAxJ+2yO7Wkb1GmHQQOIACFBDiBqsEjJXg== X-Google-Smtp-Source: ACHHUZ7lK5a36mvxmR1Pxfpqxs+w/WjMWXdphswTjkKa0cVHWahzuWK+ycuAS5s3uVehE/QApFMdkQ== X-Received: by 2002:a05:600c:2207:b0:3f5:6e5:1689 with SMTP id z7-20020a05600c220700b003f506e51689mr1792509wml.17.1684099611749; Sun, 14 May 2023 14:26:51 -0700 (PDT) Received: from lucifer.home ([2a00:23c5:dc8c:8701:1663:9a35:5a7b:1d76]) by smtp.googlemail.com with ESMTPSA id l11-20020a05600c1d0b00b003f1978bbcd6sm25750205wms.3.2023.05.14.14.26.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 May 2023 14:26:50 -0700 (PDT) From: Lorenzo Stoakes To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton , iommu@lists.linux.dev Cc: Matthew Wilcox , David Hildenbrand , kvm@vger.kernel.org, Jason Gunthorpe , Kevin Tian , Joerg Roedel , Will Deacon , Robin Murphy , Alex Williamson , Jens Axboe , Pavel Begunkov , John Hubbard , Lorenzo Stoakes , Jason Gunthorpe Subject: [PATCH v5 2/6] mm/gup: remove unused vmas parameter from pin_user_pages_remote() Date: Sun, 14 May 2023 22:26:47 +0100 Message-Id: <61f0d12058825a14feee6a3292e5a257662e719c.1684097002.git.lstoakes@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 X-Stat-Signature: gxk3xek5f6bp3u8bproujrwkzke43nzy X-Rspam-User: X-Rspamd-Queue-Id: C571040007 X-Rspamd-Server: rspam07 X-HE-Tag: 1684099613-818902 X-HE-Meta: U2FsdGVkX1/ozAnyDQilA4b9q9IXJhW8T2ROpBuNGmDcVK3vW3WYF+FJLjq0XJVl2JBlEYtk7s6K5hqYR+v3WTyrqfhOGun1DB6MbtnqdAEJnj8AjjHQxwnPBtZ6pWQ3aWBGiGk8t9lKwHDYeaRwNJD6AlRstu4vYGCyG6N+RRawGcQ36lL0QhOTSWD8CQIIJSk9F+14+fv54xtgEv6EnL9e0GJg2R13jLNo94lTpx9rEaI+oB0Ug96Nzo1ZEqfBLvNUfDIbpd8s8W8W9oc6AJ7mb1hxCxSotcRwMKogFfEsrCbKzWS9uBC0vM+bdm8HOqM+hdJYmZo/epO6lLhknbkPBldbpmqzc1/qHP1Y8b+JMIWa7IxbuR3s+WItrJhKka/gmigpJTG74pogIesO9NQ8eszMJka8MJDAuMeT2WrckwXd7Blw79R/TKnMuFG/HK76XNCvass/ldWoFW5aFVD+UXHAi6kdKFUNLfItNCUp6rZtoF3os0NtqprmEdp/8p2CUWn2jf9QYZwQmio3nqf3mRr1TrQFBbXB8HdpkNs2skA5awGtAaz0c41GkOnj/GmsR9VWosdRZZPAn7YSCO4GkknzWSz+qeKP8VNAkp6OL5s+00/uDwaVToVa5vzrq5soRuvZxseM3ypCBjQDkylWl6C7i5cICMIs9z7GI941cQnRQf5K7DBId8KWNLD3wsStW1QynYl+09Fu1Jo84i8u9Si1wDX8a57wIycHXMB0cVAN5RjMehYqUeprxgHLtzh7x70T55fIk6pJ14H/+r7yLSNYAcZi9DkvNOZ1xR03n/9APlMDPvMR0+eeZTxlD5CiyiuQphdA6cMaEBLl1YUoZ4f5ulzzTFY68IZypgctEUtYSpo+rVd4+ErmsvqRn+/aOIidka4AIH4GpTEcQsEqoRbtrV3ZJ0JtpSHyE6cEEJXpOxnihJqyu5BJ7yg6/1IaEHt3HjO5gSMJavV MbSS6MCR bfjCMVMhvHEK/qrLPicBpN1SUJnhgUQo+myyvoSVZDHzEIcxKwlPp8ebJIp7K2NrAqLMIrCOnQtQFdZwr2SXg4N7HI2a0++I+EH7v3po7WgnhdgTin7T0yWWrEbq+nKqNGZwK56gtYl54OFVWlcAZZcnt1aDMNJkUPLUgU2RS/RJnRVHITAEtI8ci9ewN3FBzMPjZ1RxX8pZoogr4k6En62iko39vFCQ7+bLNOuYXeA32YiJkFcIq37QUrm7wmFkqIjhOvFzeRdZWutPNobfa0gGtkMiKLYXq11hzcGdijiB2k6M1D8Nx27ZB8vaniwNUC4QM6fkK7y52pfFqZXXkzWqle3uGwR1EfQntl629EMt52WIvbjr782+yRd0x3MnMa640S6xu/yD59m2Dfk39lfXOr6vq40bHQpd5Bne4I/H0eJ0RFU2qTsq384w5BkxsyTluv4GVBuRuTiGQrg7Ai36XHGVhzPoJtSwTXnLpHLGjh59AJzRtYE37St9Rn4yrdw1kzNY0enjfO5qUfOzBZN2ulS+5vs37Zac0URTEgMvJobningVIJ7SPtP+1BVhzgCYhF7npHEsCfUgBBfhWGmuyVA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: No invocation of pin_user_pages_remote() uses the vmas parameter, so remove it. This forms part of a larger patch set eliminating the use of the vmas parameters altogether. Acked-by: David Hildenbrand Reviewed-by: Jason Gunthorpe Signed-off-by: Lorenzo Stoakes Reviewed-by: Christoph Hellwig --- drivers/iommu/iommufd/pages.c | 4 ++-- drivers/vfio/vfio_iommu_type1.c | 2 +- include/linux/mm.h | 2 +- mm/gup.c | 8 +++----- mm/process_vm_access.c | 2 +- 5 files changed, 8 insertions(+), 10 deletions(-) diff --git a/drivers/iommu/iommufd/pages.c b/drivers/iommu/iommufd/pages.c index 3c47846cc5ef..412ca96be128 100644 --- a/drivers/iommu/iommufd/pages.c +++ b/drivers/iommu/iommufd/pages.c @@ -786,7 +786,7 @@ static int pfn_reader_user_pin(struct pfn_reader_user *user, user->locked = 1; } rc = pin_user_pages_remote(pages->source_mm, uptr, npages, - user->gup_flags, user->upages, NULL, + user->gup_flags, user->upages, &user->locked); } if (rc <= 0) { @@ -1799,7 +1799,7 @@ static int iopt_pages_rw_page(struct iopt_pages *pages, unsigned long index, rc = pin_user_pages_remote( pages->source_mm, (uintptr_t)(pages->uptr + index * PAGE_SIZE), 1, (flags & IOMMUFD_ACCESS_RW_WRITE) ? FOLL_WRITE : 0, &page, - NULL, NULL); + NULL); mmap_read_unlock(pages->source_mm); if (rc != 1) { if (WARN_ON(rc >= 0)) diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index 3d4dd9420c30..3d2d9a944906 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -562,7 +562,7 @@ static int vaddr_get_pfns(struct mm_struct *mm, unsigned long vaddr, mmap_read_lock(mm); ret = pin_user_pages_remote(mm, vaddr, npages, flags | FOLL_LONGTERM, - pages, NULL, NULL); + pages, NULL); if (ret > 0) { int i; diff --git a/include/linux/mm.h b/include/linux/mm.h index 2c1a92bf5626..8ea82e9e7719 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2380,7 +2380,7 @@ long get_user_pages_remote(struct mm_struct *mm, long pin_user_pages_remote(struct mm_struct *mm, unsigned long start, unsigned long nr_pages, unsigned int gup_flags, struct page **pages, - struct vm_area_struct **vmas, int *locked); + int *locked); long get_user_pages(unsigned long start, unsigned long nr_pages, unsigned int gup_flags, struct page **pages); long pin_user_pages(unsigned long start, unsigned long nr_pages, diff --git a/mm/gup.c b/mm/gup.c index b8189396f435..ce78a5186dbb 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -3243,8 +3243,6 @@ EXPORT_SYMBOL_GPL(pin_user_pages_fast); * @gup_flags: flags modifying lookup behaviour * @pages: array that receives pointers to the pages pinned. * Should be at least nr_pages long. - * @vmas: array of pointers to vmas corresponding to each page. - * Or NULL if the caller does not require them. * @locked: pointer to lock flag indicating whether lock is held and * subsequently whether VM_FAULT_RETRY functionality can be * utilised. Lock must initially be held. @@ -3259,14 +3257,14 @@ EXPORT_SYMBOL_GPL(pin_user_pages_fast); long pin_user_pages_remote(struct mm_struct *mm, unsigned long start, unsigned long nr_pages, unsigned int gup_flags, struct page **pages, - struct vm_area_struct **vmas, int *locked) + int *locked) { int local_locked = 1; - if (!is_valid_gup_args(pages, vmas, locked, &gup_flags, + if (!is_valid_gup_args(pages, NULL, locked, &gup_flags, FOLL_PIN | FOLL_TOUCH | FOLL_REMOTE)) return 0; - return __gup_longterm_locked(mm, start, nr_pages, pages, vmas, + return __gup_longterm_locked(mm, start, nr_pages, pages, NULL, locked ? locked : &local_locked, gup_flags); } diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c index 78dfaf9e8990..0523edab03a6 100644 --- a/mm/process_vm_access.c +++ b/mm/process_vm_access.c @@ -104,7 +104,7 @@ static int process_vm_rw_single_vec(unsigned long addr, mmap_read_lock(mm); pinned_pages = pin_user_pages_remote(mm, pa, pinned_pages, flags, process_pages, - NULL, &locked); + &locked); if (locked) mmap_read_unlock(mm); if (pinned_pages <= 0) From patchwork Sun May 14 21:26:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13240574 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 64DB8C7EE26 for ; Sun, 14 May 2023 21:27:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 017C3900006; Sun, 14 May 2023 17:27:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F0A13900002; Sun, 14 May 2023 17:27:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DAAC5900006; Sun, 14 May 2023 17:27:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id CB498900002 for ; Sun, 14 May 2023 17:27:00 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 7076C4124A for ; Sun, 14 May 2023 21:27:00 +0000 (UTC) X-FDA: 80790145800.22.584B409 Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) by imf23.hostedemail.com (Postfix) with ESMTP id 67353140012 for ; Sun, 14 May 2023 21:26:57 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=SG8hxf81; spf=pass (imf23.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.221.52 as permitted sender) smtp.mailfrom=lstoakes@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684099617; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=4UcwtmbMshSXuvMabtBGpRNNnrw3Ug7R4BdEk+jXhWU=; b=AcTQPlSsFRT5T7qRwibsasf0BGMtNxsWaLFzwmIlEmz3l6Gpc+DM7f6cghxUpyDR4B3/c/ E60L8e5NKPgVMt5iGEhf4Ai2F3HSwWVw7ifZOgf6ffutc7bTWyEC66HASo4fX5P83+HOwD L9KizFlgsvqke8PSEcd7n9B1aA5m7gs= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684099617; a=rsa-sha256; cv=none; b=RaCCw+4k33ueg5DLwV1R3EzQFnciJlW7wR05w3Y9Hfs+atcg/4f+KvCbBy24n72E5BRYnm N3dBjV7Zr+MAPBWh8PZ2bN/KKRPYTRVvTzaWci6Pd5DUrl6eZL3t2vmrIFFp6Cf51y0PD5 N6o64FMnK6Ut9PCgfurxD0npSfO0MY8= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=SG8hxf81; spf=pass (imf23.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.221.52 as permitted sender) smtp.mailfrom=lstoakes@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-307d20548adso2316940f8f.0 for ; Sun, 14 May 2023 14:26:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684099616; x=1686691616; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4UcwtmbMshSXuvMabtBGpRNNnrw3Ug7R4BdEk+jXhWU=; b=SG8hxf81UnHmvvVjeEeKVeA+UZG3mnFP4B4L90u9UyEYnV56GRHXaKsoFAbnamoQIz 2YZhAbxnr00GHA4RxMN62csLPuERPgX0ifRwc3Q+5e5n1MswXKkZS+0GLgr3wOmfiWgn ZPuChWywNQyL6flbeiqXURGxXz850TfIguYclXkSCjhrPENyODdyxWlKb6Y6tNj6/GX0 Sa4aP/Lpdi2Pnd+QzUgxgJcIiKrwqUjg4swH48d9SIJK5uumdrbd0W4L1hoD19HLBWfG W0/IsO+qeRgPFzYOGC7ClZfu4sQo/MYceDdfxRtZQX+6idplJSEqwKzm4yvlQHNdyKCo IgYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684099616; x=1686691616; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4UcwtmbMshSXuvMabtBGpRNNnrw3Ug7R4BdEk+jXhWU=; b=jYNduEX8yFQgbri+esiXF3NLRqfaSSQnLE7NTk3k23s1pJvLhrhBgq0aZ1IAGwYwiA vCyWT5qnR+0EdlInD2drzIs4o/ARfU3pqKWhyXWCBB3GDHMS1A9pdwRFDIN4HBw1bKXG np1vTyo5GY3501CgNGxhbwvgixXW+B63zfX3aiHIx4REuuSEnaOu8bDdi8gz57/xUfi+ YQFMk//dzJnmdqk0L9cCbiKKYdN2dnBsdOphJc9N6t5J0UYWtXyBxZTd9Zk94SpMR2cJ yKI7mck4Xb2u4eBrm3ErCRLpQcGfbfbMvdtl5+JRXYhKj71TrFGowtOHDD96HEjxwj08 fUDw== X-Gm-Message-State: AC+VfDx20Nn4p//kQyvC/THhjRSqoojcdLP6EhJRH0PIgxYaYTeUOpwB 3mBpBRbFhyS1NSSEhKQKX6yy06W1HowWWQ== X-Google-Smtp-Source: ACHHUZ6hrnBUVpEkIbW4de+Qex2SgXu2P8EgEWvpkktR/SPhZZH9saiI6bvSiuP8lMEwTG863yeNzQ== X-Received: by 2002:a5d:55c2:0:b0:306:5149:3aa8 with SMTP id i2-20020a5d55c2000000b0030651493aa8mr21936695wrw.24.1684099615381; Sun, 14 May 2023 14:26:55 -0700 (PDT) Received: from lucifer.home ([2a00:23c5:dc8c:8701:1663:9a35:5a7b:1d76]) by smtp.googlemail.com with ESMTPSA id d19-20020a1c7313000000b003f508777e33sm2105965wmb.3.2023.05.14.14.26.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 May 2023 14:26:54 -0700 (PDT) From: Lorenzo Stoakes To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton Cc: Matthew Wilcox , David Hildenbrand , linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, linux-s390@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-security-module@vger.kernel.org, Catalin Marinas , Will Deacon , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Sven Schnelle , Eric Biederman , Kees Cook , Alexander Viro , Christian Brauner , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kentaro Takeda , Tetsuo Handa , Paul Moore , James Morris , "Serge E . Hallyn" , Paolo Bonzini , Jens Axboe , Pavel Begunkov , Jason Gunthorpe , John Hubbard , Lorenzo Stoakes Subject: [PATCH v5 3/6] mm/gup: remove vmas parameter from get_user_pages_remote() Date: Sun, 14 May 2023 22:26:51 +0100 Message-Id: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 67353140012 X-Stat-Signature: bk3htjokfj49y5151atnrds3parchnaf X-Rspam-User: X-Rspamd-Server: rspam09 X-HE-Tag: 1684099617-229373 X-HE-Meta: U2FsdGVkX1+XH6biVEfw0EjtS7+7neaBZp++hHYSN9pO+wgng5ANakBEBEzUGxRFwtm0HNK2zqRgcKY7/wPNgq/RViUy9Bv0tHAOzlvmgNPIVoWohjRz20UiQFwJi34VQKVBCyR3ipA4n+7yTX0Ta8j7RE4R8y1HnQxtUVj9/L/UpoKVcz6+1+mv9KUaarTQuy2GCw7rD+PYN0lRm72IQDic6ERe2pvdOt9eIUqxDqcSBzCIbD1XSp7EkdE9K6oKsZX8UjNosL593viYYwTmbNUb4GsMZy7HbWn9ayQC+U9UuCd6VMe4qdZ1xouiVV/oQTJ3rzXyUWzOS8vzlHyLrGXSyvOLn+bcKEx8ykcgZKRXoxCVKbG2zyV0VX0blh9TxzWdUdot/zxBAVgcSQ/a7okml7H+b6r+ldjebYS3ezFtLDRsHWy2RSaMqZUNT52aB8zB+jrWZJch4CCxWMtdbcobhTHh936JNim8sYRTKgu6HWVyGxIS2Mdr55T1N5wsyU/CNS0luzHEy5lm4ytbRrPhB5EPK66AQOYNpB4DvvntZ/Zo61pqQ0KolGzvYG0zq6ENcZfxr56Ui5CIW4ceo6RzRoArkrS3J4K5w9ZF4XTsrPT5Y6P11ymJqJFGo+PPL+LyIcsOwE0ZdCtmIHcUDPScW5Slb1ODUb7HdROV15V+DaporuoSphUzApKrOugQNIJ7MfpNEbToXAdY4K10iVM29HUesJZtWZ7WYsRjucsK23O1ryODzcmD4VhIWqecV6D+wu7mBSyNsfHuDzGalCcfUx5woYzj2fq0264fTBwt4xjiRA4u+KqxnydSTgAnbWv5Vk4e8UcLt+QVJEZqZgs/DC7umpu55DytFlEViI/Ar2e08jQ529OVkC71pVVSiihGYQzSqs3hsnQNcXEeSkRN5HTsewYWUFsrqnNEeQxEQGlw9GQZmYJiz9bwOQPeWLhlhEnNezAqz4j2MPt XHJ6RLfW zIegcKWeaKnRgX1mRsChkvyodg/d4/S8buNY0fAs5u3iD/Uz2ZY+vXvxiGMj9q4mbPmo6TuIGtuKh3pjVw9vnXjoVHzeYWEITjAElaAtzO86qB6B3cHGoCCR6XxUsrdCoRE3OqXd+vsH/l76dFgUaMszAK0Ju8iIhBCztW8mmq8dIP5mMI4zpdXTiwEPkKJOZjA7KYvFK4e8NgfYQMOgnrdqzxLIAm4lPCLrWDuTV7iRZq0//6VEeCOB3XClQXZEwyJWEF1rFboyqEc/6kWoCRfttIENs/Sz5lntNr7kMmo1Q1eJ1Tw370EeHzeokNaBoOh2s3vWGKaXHn5DLOEmEjRhgoTgQiQXIlqY3OHMtHC5LlwKcNt6K3yAfJ/6gxbnyAR6b0YuPYVftRPxrhwfcYDvhbk5BxJIiLoblB/oKwWOF3fWl4o7OcNl+geHKfVy1SKNmIQb8SosPtTj7nm0123kyXO2bfYc2CnkPc5yIxEmP3m2TLlwZdgjW0hqH9HfUtp0cR0L4a8HlFOTUJiozn1Gnog1Px5YItTgqRvFVKiKedLD+T8AlwkSTo2fjUjINvMrJY8XXLZeIlEzGcf0GeKDE+XMXWlH+LCkBT0sbpPRys/OvoPhBZn36/FXJcSjxshYwOH4wvQpZ1fT0Njme2cjlxA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The only instances of get_user_pages_remote() invocations which used the vmas parameter were for a single page which can instead simply look up the VMA directly. In particular:- - __update_ref_ctr() looked up the VMA but did nothing with it so we simply remove it. - __access_remote_vm() was already using vma_lookup() when the original lookup failed so by doing the lookup directly this also de-duplicates the code. We are able to perform these VMA operations as we already hold the mmap_lock in order to be able to call get_user_pages_remote(). As part of this work we add get_user_page_vma_remote() which abstracts the VMA lookup, error handling and decrementing the page reference count should the VMA lookup fail. This forms part of a broader set of patches intended to eliminate the vmas parameter altogether. Reviewed-by: Catalin Marinas (for arm64) Acked-by: David Hildenbrand Reviewed-by: Janosch Frank (for s390) Signed-off-by: Lorenzo Stoakes Reviewed-by: Christoph Hellwig Signed-off-by: Lorenzo Stoakes --- arch/arm64/kernel/mte.c | 17 +++++++++-------- arch/s390/kvm/interrupt.c | 2 +- fs/exec.c | 2 +- include/linux/mm.h | 34 +++++++++++++++++++++++++++++++--- kernel/events/uprobes.c | 13 +++++-------- mm/gup.c | 12 ++++-------- mm/memory.c | 14 +++++++------- mm/rmap.c | 2 +- security/tomoyo/domain.c | 2 +- virt/kvm/async_pf.c | 3 +-- 10 files changed, 61 insertions(+), 40 deletions(-) diff --git a/arch/arm64/kernel/mte.c b/arch/arm64/kernel/mte.c index f5bcb0dc6267..cc793c246653 100644 --- a/arch/arm64/kernel/mte.c +++ b/arch/arm64/kernel/mte.c @@ -419,10 +419,9 @@ long get_mte_ctrl(struct task_struct *task) static int __access_remote_tags(struct mm_struct *mm, unsigned long addr, struct iovec *kiov, unsigned int gup_flags) { - struct vm_area_struct *vma; void __user *buf = kiov->iov_base; size_t len = kiov->iov_len; - int ret; + int err = 0; int write = gup_flags & FOLL_WRITE; if (!access_ok(buf, len)) @@ -432,14 +431,16 @@ static int __access_remote_tags(struct mm_struct *mm, unsigned long addr, return -EIO; while (len) { + struct vm_area_struct *vma; unsigned long tags, offset; void *maddr; - struct page *page = NULL; + struct page *page = get_user_page_vma_remote(mm, addr, + gup_flags, &vma); - ret = get_user_pages_remote(mm, addr, 1, gup_flags, &page, - &vma, NULL); - if (ret <= 0) + if (IS_ERR_OR_NULL(page)) { + err = page == NULL ? -EIO : PTR_ERR(page); break; + } /* * Only copy tags if the page has been mapped as PROT_MTE @@ -449,7 +450,7 @@ static int __access_remote_tags(struct mm_struct *mm, unsigned long addr, * was never mapped with PROT_MTE. */ if (!(vma->vm_flags & VM_MTE)) { - ret = -EOPNOTSUPP; + err = -EOPNOTSUPP; put_page(page); break; } @@ -482,7 +483,7 @@ static int __access_remote_tags(struct mm_struct *mm, unsigned long addr, kiov->iov_len = buf - kiov->iov_base; if (!kiov->iov_len) { /* check for error accessing the tracee's address space */ - if (ret <= 0) + if (err) return -EIO; else return -EFAULT; diff --git a/arch/s390/kvm/interrupt.c b/arch/s390/kvm/interrupt.c index da6dac36e959..9bd0a873f3b1 100644 --- a/arch/s390/kvm/interrupt.c +++ b/arch/s390/kvm/interrupt.c @@ -2777,7 +2777,7 @@ static struct page *get_map_page(struct kvm *kvm, u64 uaddr) mmap_read_lock(kvm->mm); get_user_pages_remote(kvm->mm, uaddr, 1, FOLL_WRITE, - &page, NULL, NULL); + &page, NULL); mmap_read_unlock(kvm->mm); return page; } diff --git a/fs/exec.c b/fs/exec.c index a466e797c8e2..25c65b64544b 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -220,7 +220,7 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos, */ mmap_read_lock(bprm->mm); ret = get_user_pages_remote(bprm->mm, pos, 1, gup_flags, - &page, NULL, NULL); + &page, NULL); mmap_read_unlock(bprm->mm); if (ret <= 0) return NULL; diff --git a/include/linux/mm.h b/include/linux/mm.h index 8ea82e9e7719..679b41ef7a6d 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2366,6 +2366,9 @@ static inline void unmap_shared_mapping_range(struct address_space *mapping, unmap_mapping_range(mapping, holebegin, holelen, 0); } +static inline struct vm_area_struct *vma_lookup(struct mm_struct *mm, + unsigned long addr); + extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, unsigned int gup_flags); extern int access_remote_vm(struct mm_struct *mm, unsigned long addr, @@ -2374,13 +2377,38 @@ extern int __access_remote_vm(struct mm_struct *mm, unsigned long addr, void *buf, int len, unsigned int gup_flags); long get_user_pages_remote(struct mm_struct *mm, - unsigned long start, unsigned long nr_pages, - unsigned int gup_flags, struct page **pages, - struct vm_area_struct **vmas, int *locked); + unsigned long start, unsigned long nr_pages, + unsigned int gup_flags, struct page **pages, + int *locked); long pin_user_pages_remote(struct mm_struct *mm, unsigned long start, unsigned long nr_pages, unsigned int gup_flags, struct page **pages, int *locked); + +static inline struct page *get_user_page_vma_remote(struct mm_struct *mm, + unsigned long addr, + int gup_flags, + struct vm_area_struct **vmap) +{ + struct page *page; + struct vm_area_struct *vma; + int got = get_user_pages_remote(mm, addr, 1, gup_flags, &page, NULL); + + if (got < 0) + return ERR_PTR(got); + if (got == 0) + return NULL; + + vma = vma_lookup(mm, addr); + if (WARN_ON_ONCE(!vma)) { + put_page(page); + return ERR_PTR(-EINVAL); + } + + *vmap = vma; + return page; +} + long get_user_pages(unsigned long start, unsigned long nr_pages, unsigned int gup_flags, struct page **pages); long pin_user_pages(unsigned long start, unsigned long nr_pages, diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c index 59887c69d54c..cac3aef7c6f7 100644 --- a/kernel/events/uprobes.c +++ b/kernel/events/uprobes.c @@ -365,7 +365,6 @@ __update_ref_ctr(struct mm_struct *mm, unsigned long vaddr, short d) { void *kaddr; struct page *page; - struct vm_area_struct *vma; int ret; short *ptr; @@ -373,7 +372,7 @@ __update_ref_ctr(struct mm_struct *mm, unsigned long vaddr, short d) return -EINVAL; ret = get_user_pages_remote(mm, vaddr, 1, - FOLL_WRITE, &page, &vma, NULL); + FOLL_WRITE, &page, NULL); if (unlikely(ret <= 0)) { /* * We are asking for 1 page. If get_user_pages_remote() fails, @@ -474,10 +473,9 @@ int uprobe_write_opcode(struct arch_uprobe *auprobe, struct mm_struct *mm, if (is_register) gup_flags |= FOLL_SPLIT_PMD; /* Read the page with vaddr into memory */ - ret = get_user_pages_remote(mm, vaddr, 1, gup_flags, - &old_page, &vma, NULL); - if (ret <= 0) - return ret; + old_page = get_user_page_vma_remote(mm, vaddr, gup_flags, &vma); + if (IS_ERR_OR_NULL(old_page)) + return PTR_ERR(old_page); ret = verify_opcode(old_page, vaddr, &opcode); if (ret <= 0) @@ -2027,8 +2025,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr) * but we treat this as a 'remote' access since it is * essentially a kernel access to the memory. */ - result = get_user_pages_remote(mm, vaddr, 1, FOLL_FORCE, &page, - NULL, NULL); + result = get_user_pages_remote(mm, vaddr, 1, FOLL_FORCE, &page, NULL); if (result < 0) return result; diff --git a/mm/gup.c b/mm/gup.c index ce78a5186dbb..1493cc8dd526 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -2208,8 +2208,6 @@ static bool is_valid_gup_args(struct page **pages, struct vm_area_struct **vmas, * @pages: array that receives pointers to the pages pinned. * Should be at least nr_pages long. Or NULL, if caller * only intends to ensure the pages are faulted in. - * @vmas: array of pointers to vmas corresponding to each page. - * Or NULL if the caller does not require them. * @locked: pointer to lock flag indicating whether lock is held and * subsequently whether VM_FAULT_RETRY functionality can be * utilised. Lock must initially be held. @@ -2224,8 +2222,6 @@ static bool is_valid_gup_args(struct page **pages, struct vm_area_struct **vmas, * * The caller is responsible for releasing returned @pages, via put_page(). * - * @vmas are valid only as long as mmap_lock is held. - * * Must be called with mmap_lock held for read or write. * * get_user_pages_remote walks a process's page tables and takes a reference @@ -2262,15 +2258,15 @@ static bool is_valid_gup_args(struct page **pages, struct vm_area_struct **vmas, long get_user_pages_remote(struct mm_struct *mm, unsigned long start, unsigned long nr_pages, unsigned int gup_flags, struct page **pages, - struct vm_area_struct **vmas, int *locked) + int *locked) { int local_locked = 1; - if (!is_valid_gup_args(pages, vmas, locked, &gup_flags, + if (!is_valid_gup_args(pages, NULL, locked, &gup_flags, FOLL_TOUCH | FOLL_REMOTE)) return -EINVAL; - return __get_user_pages_locked(mm, start, nr_pages, pages, vmas, + return __get_user_pages_locked(mm, start, nr_pages, pages, NULL, locked ? locked : &local_locked, gup_flags); } @@ -2280,7 +2276,7 @@ EXPORT_SYMBOL(get_user_pages_remote); long get_user_pages_remote(struct mm_struct *mm, unsigned long start, unsigned long nr_pages, unsigned int gup_flags, struct page **pages, - struct vm_area_struct **vmas, int *locked) + int *locked) { return 0; } diff --git a/mm/memory.c b/mm/memory.c index 146bb94764f8..63632a5eafc1 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5590,7 +5590,6 @@ EXPORT_SYMBOL_GPL(generic_access_phys); int __access_remote_vm(struct mm_struct *mm, unsigned long addr, void *buf, int len, unsigned int gup_flags) { - struct vm_area_struct *vma; void *old_buf = buf; int write = gup_flags & FOLL_WRITE; @@ -5599,13 +5598,15 @@ int __access_remote_vm(struct mm_struct *mm, unsigned long addr, void *buf, /* ignore errors, just check how much was successfully transferred */ while (len) { - int bytes, ret, offset; + int bytes, offset; void *maddr; - struct page *page = NULL; + struct vm_area_struct *vma; + struct page *page = get_user_page_vma_remote(mm, addr, + gup_flags, &vma); + + if (IS_ERR_OR_NULL(page)) { + int ret = 0; - ret = get_user_pages_remote(mm, addr, 1, - gup_flags, &page, &vma, NULL); - if (ret <= 0) { #ifndef CONFIG_HAVE_IOREMAP_PROT break; #else @@ -5613,7 +5614,6 @@ int __access_remote_vm(struct mm_struct *mm, unsigned long addr, void *buf, * Check if this is a VM_IO | VM_PFNMAP VMA, which * we can access using slightly different code. */ - vma = vma_lookup(mm, addr); if (!vma) break; if (vma->vm_ops && vma->vm_ops->access) diff --git a/mm/rmap.c b/mm/rmap.c index b42fc0389c24..ae127f60a4fb 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -2328,7 +2328,7 @@ int make_device_exclusive_range(struct mm_struct *mm, unsigned long start, npages = get_user_pages_remote(mm, start, npages, FOLL_GET | FOLL_WRITE | FOLL_SPLIT_PMD, - pages, NULL, NULL); + pages, NULL); if (npages < 0) return npages; diff --git a/security/tomoyo/domain.c b/security/tomoyo/domain.c index 31af29f669d2..ac20c0bdff9d 100644 --- a/security/tomoyo/domain.c +++ b/security/tomoyo/domain.c @@ -916,7 +916,7 @@ bool tomoyo_dump_page(struct linux_binprm *bprm, unsigned long pos, */ mmap_read_lock(bprm->mm); ret = get_user_pages_remote(bprm->mm, pos, 1, - FOLL_FORCE, &page, NULL, NULL); + FOLL_FORCE, &page, NULL); mmap_read_unlock(bprm->mm); if (ret <= 0) return false; diff --git a/virt/kvm/async_pf.c b/virt/kvm/async_pf.c index 9bfe1d6f6529..e033c79d528e 100644 --- a/virt/kvm/async_pf.c +++ b/virt/kvm/async_pf.c @@ -61,8 +61,7 @@ static void async_pf_execute(struct work_struct *work) * access remotely. */ mmap_read_lock(mm); - get_user_pages_remote(mm, addr, 1, FOLL_WRITE, NULL, NULL, - &locked); + get_user_pages_remote(mm, addr, 1, FOLL_WRITE, NULL, &locked); if (locked) mmap_read_unlock(mm); From patchwork Sun May 14 21:26:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13240575 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D6937C7EE23 for ; Sun, 14 May 2023 21:27:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 52157900007; Sun, 14 May 2023 17:27:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4D11B900002; Sun, 14 May 2023 17:27:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 34AF6900007; Sun, 14 May 2023 17:27:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 27D07900002 for ; Sun, 14 May 2023 17:27:02 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id EF259A1263 for ; Sun, 14 May 2023 21:27:01 +0000 (UTC) X-FDA: 80790145842.14.00C3B36 Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49]) by imf22.hostedemail.com (Postfix) with ESMTP id 1C811C0009 for ; Sun, 14 May 2023 21:26:59 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b="S/k6Ea9S"; spf=pass (imf22.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.221.49 as permitted sender) smtp.mailfrom=lstoakes@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684099620; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=6lZfZiVFWsAlcMWN5PRi30FiuIH4ExiR/doISXVhpnA=; b=Bk5I9CMm5yK3ZWkOqmOmSfhmlxE1/lSKMpVaWd4sbKghum1g/DHbNTjHsgDtKauJ5EdNFT M++t7ysoP+2r5IdBSsBz6JUXVqIG5cyvWlD+dYUzWkyFILyd56B7o4+5ezTRGcPnGAoLVo DoTV4qidGs6Tibd53FtmzPlj1bEBKkI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684099620; a=rsa-sha256; cv=none; b=dta09DGEMvp8PkyEa25zfQmSqWDLOW3sylEVLicHneooK7xG+gF+5s+GtfhMYn0zOfzwOl mCxE2Xax55Ozbd0CcBVRhZwdATTpyumhjYHjD3NQHdJtuuxAONDLefBRhgZlrb93tZIT17 PDkHxDb6eAas5YK3PBE+LTNY+jpM0F4= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b="S/k6Ea9S"; spf=pass (imf22.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.221.49 as permitted sender) smtp.mailfrom=lstoakes@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-30786c87cdaso9252131f8f.2 for ; Sun, 14 May 2023 14:26:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684099618; x=1686691618; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6lZfZiVFWsAlcMWN5PRi30FiuIH4ExiR/doISXVhpnA=; b=S/k6Ea9S7jTXAkegHdRNsYFunFJtyA0tD50ThbnkZoegODRr5kBExok5WQkHItiThy 9Eqit3HhgZkuqZV4o6mY1FgL3cOhKarBAgLlvy7XoFrsUNHYKuSScvJHno7LbQGZCSJL cBrDEg28rcrgcSohO93qC0JLzI4nT0W5ZizqecvOSJm1aw/HNhkd0n9haUp4X7OXZDhf pIn9jvFlyWIMW7YfXnnzqDAaYDey1Eeyv7BGnybQ19c2uJvcxJKmXwtrK2ijBLkqrwE2 OcSjIqGlL2tu6YE+rNveIHct+bjthi0raPd9ShK3wa4GpPLymWffn7c+Fva20QTttk3D mJgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684099618; x=1686691618; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6lZfZiVFWsAlcMWN5PRi30FiuIH4ExiR/doISXVhpnA=; b=CZiSifLx3cuK5q+SRMmuQbOoJ2tjA+E7PR++tUmqqf0pijXPDlSVyACS5Ez5bviV1+ pOSCN2fwkypcXRkjSE6HY+QjcfJO/AuPr4plJRKaBML4PTDRZ8V9SiVZSognL0PvU6+T wcHh0a1wOiJauANCvEXS4vSbTNPTfJwZ9bFD9fw7vS3OJzwKjGMY1W2lescJSfHEAmtK IseQqGQ49ldYkjQ2V8RBkyBaxgpp+X8dtARRYeBjt8Rov5Ic0MhaHXm6xz0wtLFO+fSv m9T2h0RdVVhJFHC6W5ctFtqbiA+3zEh/9orxxtJb6HKllD3dD5vIjFYET71mGQuwn/Rg FlUQ== X-Gm-Message-State: AC+VfDxGvwMRTgUNbvFKDx4aKD6IL/AUAokuaMwnOlDxonVPR+DKiNnZ q8ZP159CIbsYEXMZ2mXuOK3oaFoZiGwvQQ== X-Google-Smtp-Source: ACHHUZ7xbzYrHEIBsBEOTfbuU9xONp4amC/jy4CMWdSN4lsoxtCis8o8qIA1MVHQab6pCBBaxEceNw== X-Received: by 2002:adf:f142:0:b0:306:36b5:8ada with SMTP id y2-20020adff142000000b0030636b58adamr24687541wro.29.1684099618096; Sun, 14 May 2023 14:26:58 -0700 (PDT) Received: from lucifer.home ([2a00:23c5:dc8c:8701:1663:9a35:5a7b:1d76]) by smtp.googlemail.com with ESMTPSA id z8-20020adfec88000000b003062675d4c9sm30253398wrn.39.2023.05.14.14.26.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 May 2023 14:26:57 -0700 (PDT) From: Lorenzo Stoakes To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton Cc: Matthew Wilcox , David Hildenbrand , Jens Axboe , Pavel Begunkov , io-uring@vger.kernel.org, Jason Gunthorpe , John Hubbard , Lorenzo Stoakes Subject: [PATCH v5 4/6] io_uring: rsrc: delegate VMA file-backed check to GUP Date: Sun, 14 May 2023 22:26:55 +0100 Message-Id: <642128d50f5423b3331e3108f8faf6b8ac0d957e.1684097002.git.lstoakes@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 X-Stat-Signature: 57fcdjthtwqwir8x5mx6iztc6jdi1i3x X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 1C811C0009 X-HE-Tag: 1684099619-642310 X-HE-Meta: U2FsdGVkX19LaaE9QKL+/nk8LaqK7DosC4yaB3J7KvEL/xFOQx7GeypOnKP1Q74JS2RWHZJot8tl3qQWpzE5oTVb9G+9ofypExKUWPRBKNQm+aAfzUWRZs6KYmKMRnSRdWVpbg6NE7Otm8lLHxaCH3DSVvm/fZINTUIU/8Nl6MW0xMUDeFaGPk7CE79hsc08MzcYIAck74GbAVMt4at+7Ax8GRVPMEeiip+BtUDHRDInl5WX53m3/oyPXyaDHfd1HYXflc4XnfyaYG9HsfR1gvK91RnLOcKT+50vZQHOKstm2QQJxZDaZQvcqg5Y6yiAKkrM8YCrNjFgoK3PF9qnNbwfEtDHE5LxGeighoOsyrRlu4RL2mw7DgGbzeCgx7IUTrHHwAtKjp0MlxPQpNdFwTvOQOgmUZVdeT5nakvRamSafCQKbQEHA92+/9BHvwVdBJfeRPaxdda9ewQwma+vXw7qYekRkZfaViZAjidd3gfqA4cOJeQ0EMr/P+arVTujSeuX0uq87ObSNqqsBXKx8m+gl5zIM/xZMD0A6muUGynM+4AizHN2bDvt0pwnKNS5/mMFrsQfE0hKC0wywSCi7QiOERwGIMPNCJhc2h3xTjsP6QMHzFZ3f4/R8dQkw1ZxEEl738DTMC1tsZh0R8wtnfmBCnnMoyw20ukydLLcSBMfyT5bFaflCTVL1BCgi9Z07MylIOK652xL027dhjFALTgGTsCYSEDtCQ4xLhs6iVzDgWBbmm6CokOHTpKIhPgJVzdBHp/nWyhPJFt5O+1LLEDM7GS79TbP0kgDgMTIX/POISB5OkRG7jIzaUZ5V27yGJSWIVDoxibTbn+8VXTok9YF/X1G7RWo70rynF14mQaQvaY3g7Ju6T1zUsMNa1mdJU9bCDnaT8Hh7JeA/5yMNLSri1i4dLvtNWfSYdLI6aO4ktaLmgOyKNUjGmyPyjfS29KSTIvMcTNwuGVuhBI V8LofvDx p5SNn6OzCpRAf3FniKWqPT8AmMUbGTPojefisjfUY4AFzRyBPsZB7D5FTLU25DsRPwtYcPfi5SCXqDSD8rQ9PsWGEoSuT7AdGQV62Cuw+YuNbrhdpLrJAs2NXvnQbsxBGzGCrDwYZKRDWFhsoofSmnhU+wrBz+uFQChkRo1lJGpAjvAj7SKV7c2JHwPwz2ukgmE1lhXZ+UVxxpTJTOP+YPDskzenSbUK1sneibGgxwMN8x2WqvlQyoexQx8dJjzZ22P9Y8IDsM0bmDSaYpABdKicc22IhqItFTPDf6u4bOwg57SLP85LykFLNFchMhnd7XoihwOmgpDEHCMIzvKPUs5wvsQJQr8gdGduIIGRT88aASnDRGFjHjVeegLu/CsQH34Wnrx4MEmev3zbrXX9vYECZpGpyq6zCPIB53e61/txG/lsMS6KFhyyyTNINqmScYLduZWJQKTbZI4WX2s2lBSSsxnF4HHZI0Vb/ag/Fak9Oq1XCT+XEN0p2i+kuE2Tg31uiYdwfvsEVoKaYYb22mQnVhDlW6tZ/yQnS X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Now that the GUP explicitly checks FOLL_LONGTERM pin_user_pages() for broken file-backed mappings in "mm/gup: disallow FOLL_LONGTERM GUP-nonfast writing to file-backed mappings", there is no need to explicitly check VMAs for this condition, so simply remove this logic from io_uring altogether. Signed-off-by: Lorenzo Stoakes Reviewed-by: Christoph Hellwig Reviewed-by: Jens Axboe Reviewed-by: David Hildenbrand --- io_uring/rsrc.c | 34 ++++++---------------------------- 1 file changed, 6 insertions(+), 28 deletions(-) diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c index d46f72a5ef73..b6451f8bc5d5 100644 --- a/io_uring/rsrc.c +++ b/io_uring/rsrc.c @@ -1030,9 +1030,8 @@ static int io_buffer_account_pin(struct io_ring_ctx *ctx, struct page **pages, struct page **io_pin_pages(unsigned long ubuf, unsigned long len, int *npages) { unsigned long start, end, nr_pages; - struct vm_area_struct **vmas = NULL; struct page **pages = NULL; - int i, pret, ret = -ENOMEM; + int pret, ret = -ENOMEM; end = (ubuf + len + PAGE_SIZE - 1) >> PAGE_SHIFT; start = ubuf >> PAGE_SHIFT; @@ -1042,45 +1041,24 @@ struct page **io_pin_pages(unsigned long ubuf, unsigned long len, int *npages) if (!pages) goto done; - vmas = kvmalloc_array(nr_pages, sizeof(struct vm_area_struct *), - GFP_KERNEL); - if (!vmas) - goto done; - ret = 0; mmap_read_lock(current->mm); pret = pin_user_pages(ubuf, nr_pages, FOLL_WRITE | FOLL_LONGTERM, - pages, vmas); - if (pret == nr_pages) { - /* don't support file backed memory */ - for (i = 0; i < nr_pages; i++) { - struct vm_area_struct *vma = vmas[i]; - - if (vma_is_shmem(vma)) - continue; - if (vma->vm_file && - !is_file_hugepages(vma->vm_file)) { - ret = -EOPNOTSUPP; - break; - } - } + pages, NULL); + if (pret == nr_pages) *npages = nr_pages; - } else { + else ret = pret < 0 ? pret : -EFAULT; - } + mmap_read_unlock(current->mm); if (ret) { - /* - * if we did partial map, or found file backed vmas, - * release any pages we did get - */ + /* if we did partial map, release any pages we did get */ if (pret > 0) unpin_user_pages(pages, pret); goto done; } ret = 0; done: - kvfree(vmas); if (ret < 0) { kvfree(pages); pages = ERR_PTR(ret); From patchwork Sun May 14 21:26:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13240576 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 263D3C7EE22 for ; Sun, 14 May 2023 21:27:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B3C91900008; Sun, 14 May 2023 17:27:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AEBEC900002; Sun, 14 May 2023 17:27:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 98BEF900008; Sun, 14 May 2023 17:27:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 89FB1900002 for ; Sun, 14 May 2023 17:27:05 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 5B903121277 for ; Sun, 14 May 2023 21:27:05 +0000 (UTC) X-FDA: 80790146010.25.3762C76 Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) by imf01.hostedemail.com (Postfix) with ESMTP id 6347B40006 for ; Sun, 14 May 2023 21:27:03 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=aoQGznX+; spf=pass (imf01.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.221.48 as permitted sender) smtp.mailfrom=lstoakes@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684099623; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=8xqzyCEy7iofGcOYzYypeQYEUsssg0r/A+Ok0DOjdDs=; b=JGHMo4CXyOfJEtH4gyvwNheRSQtiqfSJpHd3r2sPeKdSgEzShoBxS7+6igvMlRNUQyrBkx V72tb1VnVNo6nbBFQ+nLm0D7P9uBgUS6/aADjfKj7m35gLt3XMHaL7hVJVjQFiFkqEOhKs T9QL6niCYd/LDF8/SRzCxB1PK8OMERw= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=aoQGznX+; spf=pass (imf01.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.221.48 as permitted sender) smtp.mailfrom=lstoakes@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684099623; a=rsa-sha256; cv=none; b=qw+NP6i/Cf/hEK4TWQSPdkuYOIFtpQmRsaXiisxDHMAZH+wGMP5T9moiIxj/WM3A5doYj/ BRZJt0GWx2jcpC1kT/vqT0bKu6o7ve41fSLTkkEByBX2qbxWqPm7UXVJcDixil1EUsmOBl sDjDpCCl5ugYuDN7A5cYjRJUtHitt5M= Received: by mail-wr1-f48.google.com with SMTP id ffacd0b85a97d-306281edf15so11324406f8f.1 for ; Sun, 14 May 2023 14:27:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684099621; x=1686691621; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8xqzyCEy7iofGcOYzYypeQYEUsssg0r/A+Ok0DOjdDs=; b=aoQGznX+L0dqapBQrZ7tkkNVdcbVvdSJlnUDKwjlWhMHJsKAuaUDUnJC42eQD2DeDX 34fO8/v7vg1LUopNvlyFJXzAO8PJUfjM3OQDqGW4BrssZLPdgbji8y3zkxIzTeu5JVw+ FV+CRnz59VmbrLGfyt4pGVm2hqrgAeBWO/vmr91k4swlQ7b3D85FRtZxbGcfBOxjKMkn d6RdWLeX4B78nbG17RhE7r0ymv0s8n0GnnM29Du5pRxfNwNAvV4LSbovqFC2br4iXOY0 F6V6C6RK12INseuaPzDfQvZ3a4AIEsBo87ya77kVsQ2VR2mFMjFu/AjnVpJftddk4v0z Z6og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684099621; x=1686691621; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8xqzyCEy7iofGcOYzYypeQYEUsssg0r/A+Ok0DOjdDs=; b=O9Ez4C6D61oHzXt3uv5zldDVJEqkeF09guhkOzHWNE1jnlyYdkBRMxtClFuSPLWOC3 GUCZpBc4QAIzfLk8uoJHBsbD709lqlbm+8hK7BSJhPhLptwCSbNfgNgdgszUUbNdywI3 Ek+pxqXcIM+o1ODDbt/X2U8ygbSXMKID2wynitLZTplQNgrYVAR/RLaybsu9tPGBwcnr 7EiqAE5yR0Q3ITSXk8aCtyNQ0Ga2cfWqoLehlCHZp27XUaovJs5g7JeCLAoJhuCN3Fme jB58unjJ1ZF+9bFyOiX3l/2mBBRP8QxA37JXMhgEnHye9uDbqk+ZFlP9ivt89sryEHNZ +D5A== X-Gm-Message-State: AC+VfDyM7F/VjSUrPJgbDdpI1e+kxxHBT/va4BiRL4ALW3aMnKQncZIh 03cBewalB5kVVmPcKL7rwK6SfD+zeAqihg== X-Google-Smtp-Source: ACHHUZ6PRLUWV/JXBbb+jR9+33X81exRRn6i14eei9wAVcEb3WES66stfPnuGtQX6n6Zzc9+QFQNkQ== X-Received: by 2002:adf:ec45:0:b0:306:3f97:4847 with SMTP id w5-20020adfec45000000b003063f974847mr21210684wrn.65.1684099621384; Sun, 14 May 2023 14:27:01 -0700 (PDT) Received: from lucifer.home ([2a00:23c5:dc8c:8701:1663:9a35:5a7b:1d76]) by smtp.googlemail.com with ESMTPSA id d18-20020adfe852000000b002fe13ec49fasm30174117wrn.98.2023.05.14.14.26.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 May 2023 14:27:00 -0700 (PDT) From: Lorenzo Stoakes To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton Cc: Matthew Wilcox , David Hildenbrand , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Dennis Dalessandro , Jason Gunthorpe , Leon Romanovsky , Christian Benvenuti , Nelson Escobar , Bernard Metzler , Mauro Carvalho Chehab , "Michael S . Tsirkin" , Jason Wang , Jens Axboe , Pavel Begunkov , Bjorn Topel , Magnus Karlsson , Maciej Fijalkowski , Jonathan Lemon , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , linuxppc-dev@lists.ozlabs.org, linux-rdma@vger.kernel.org, linux-media@vger.kernel.org, virtualization@lists.linux-foundation.org, kvm@vger.kernel.org, netdev@vger.kernel.org, io-uring@vger.kernel.org, bpf@vger.kernel.org, John Hubbard , Lorenzo Stoakes Subject: [PATCH v5 5/6] mm/gup: remove vmas parameter from pin_user_pages() Date: Sun, 14 May 2023 22:26:58 +0100 Message-Id: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 6347B40006 X-Stat-Signature: h8ec8u3bcu8crg1du14f3j1g54xgqjy7 X-HE-Tag: 1684099623-73649 X-HE-Meta: U2FsdGVkX1/ylctd3MkiO2UleA4u/RxTAB5fYiP7iJQSNm71D/WgJV4Dr9kNKbOdnpOvRWUsVqMSKy14LsLfkz1wF5egKmTIS+m3hCmZytnn1tXMu/6uNNiORKOueImizoGJehclOa2U21OVvmEqdOo6hQ1GT/HhwdI/0e+YW46B6ghcqtw8bCBuwqsvaTZbZ+WfesMnWsda2Ja2jyAX04gxop0wBVeuuPZUJIy1/jikhE9QetF9Fe2TGgHE2Wyb5fqyjC+0S1Lws6tb9tHZbrAzsQkEOL2aw9Kvhr0l/91jBMrDFQ8XfIUO1IO3X6VTKwfrbDG9PRjkP2D+H4uqCg4oHcsQkU7Ghe90gzPj1PyvsuZhxICAORwOuunkRa8Z5m7XZFawCijoAPQ/DPj2y+nNbokSreL23RN+8Ne60HD/UVOLR0dr8BOVE00p29cgicNoE5LLUvrS6KOjZNpdb5latFLdUAuJABIGvG2NHiihKQqXl6pg74SVRHkfaIs1mqDDsowHAoj5GHgxF0wDuEHxDmImeR0Gz2u9MstoBuJ4CtoRnWp52d8aiEKcKNDtja0GfFJBCdcXzAbLyIBdqxSMtFlRuPoUgzquyikIfLpLRyU9IL+V/QiEUKtQDG8t7oOFU7eyZZPsQkJ7gwlq+tZRevH7ZMShBNM16qr8K8F5NrszVqF7v9uGFdCyMxXB0eGK9fB8RO9hWL1woKRJ0a0O7Y/KWzAq2uWyWRdHmElJNrfeqeYZKKGWMUjBE1C1u2J8PyWIbL+iRx3+D2oZOM2m3XJZeJkayB72IMXre/FaExydtEDuScYncAtQs0Q5V3IsYKaqpqjqsZ92gZBKSVJzWwR8cCUBoBIrFFTUXsfMA4jDkr0/QnfVlekQWPYLQfmcir06fR+xkYfoKxI1Z/YM6jVTGEgVCfVwX1sTIwVEwDGLrTf1TmJXjWLpJ2HFkbPXNa1kpx9H/TDixAM ArgyYOH1 es7GdnDH5b0AuSV/7R7m2Sx86ghvBT0ORV3DiqcK6daNpboLgLw43ih72i7ZoUk6+PRaR567h7HmIFWl/pzBy3rhZlfaGqxolW3TNbsRq6YzSDfE2yGdKZ/mspaWuFRrcIkgDn/5+goq912caHCJ3QRDrORkdWzY6TQALSXa0pobcy6DWHKPEwN20NlxwOoey/wD6jIMFypDkpNW+OLva//gBWBEKyq2DhlzjFN+jf2jiqH/LhrM0XGHDLQxSpZAqO5dlTiiFtykjVKEqvVsefUmvmmnKwFCYjngtlza3BvE/LKUBEzgfEKSDRFLYBR2SjexkoC4yJZrKFshCrtMlM0apUKWqk/oa//grBkrfoHD85a9E0TWiDKy9+dj5T89UFx9TyT9QUf//A1eqM6g1FQg8hLIZz4j7z2n8+OKTqY3Vmt7lT5VdprhKr4Si7Tmm7k0PGKP+jP6g8MLdt8AqZa1axlHYqZ0hpwUwFXjLkPiB7I3u33rH44bhO3diL3M867QHPVENd3GgIKHhaofX/sHXiv2S/ORud336PBSxSqvA6Z4hrnYP/tTaz/zYt0U9LM6JXXk6n2WHDqmYUwXqKL9JO7WJbYzaS16e28ji/d3tZr7f2iVxjlCzT2N03Igmfwfc X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: We are now in a position where no caller of pin_user_pages() requires the vmas parameter at all, so eliminate this parameter from the function and all callers. This clears the way to removing the vmas parameter from GUP altogether. Acked-by: David Hildenbrand Acked-by: Dennis Dalessandro (for qib) Signed-off-by: Lorenzo Stoakes Reviewed-by: Christoph Hellwig Acked-by: Sakari Ailus # drivers/media --- arch/powerpc/mm/book3s64/iommu_api.c | 2 +- drivers/infiniband/hw/qib/qib_user_pages.c | 2 +- drivers/infiniband/hw/usnic/usnic_uiom.c | 2 +- drivers/infiniband/sw/siw/siw_mem.c | 2 +- drivers/media/v4l2-core/videobuf-dma-sg.c | 2 +- drivers/vdpa/vdpa_user/vduse_dev.c | 2 +- drivers/vhost/vdpa.c | 2 +- include/linux/mm.h | 3 +-- io_uring/rsrc.c | 2 +- mm/gup.c | 9 +++------ mm/gup_test.c | 9 ++++----- net/xdp/xdp_umem.c | 2 +- 12 files changed, 17 insertions(+), 22 deletions(-) diff --git a/arch/powerpc/mm/book3s64/iommu_api.c b/arch/powerpc/mm/book3s64/iommu_api.c index 81d7185e2ae8..d19fb1f3007d 100644 --- a/arch/powerpc/mm/book3s64/iommu_api.c +++ b/arch/powerpc/mm/book3s64/iommu_api.c @@ -105,7 +105,7 @@ static long mm_iommu_do_alloc(struct mm_struct *mm, unsigned long ua, ret = pin_user_pages(ua + (entry << PAGE_SHIFT), n, FOLL_WRITE | FOLL_LONGTERM, - mem->hpages + entry, NULL); + mem->hpages + entry); if (ret == n) { pinned += n; continue; diff --git a/drivers/infiniband/hw/qib/qib_user_pages.c b/drivers/infiniband/hw/qib/qib_user_pages.c index f693bc753b6b..1bb7507325bc 100644 --- a/drivers/infiniband/hw/qib/qib_user_pages.c +++ b/drivers/infiniband/hw/qib/qib_user_pages.c @@ -111,7 +111,7 @@ int qib_get_user_pages(unsigned long start_page, size_t num_pages, ret = pin_user_pages(start_page + got * PAGE_SIZE, num_pages - got, FOLL_LONGTERM | FOLL_WRITE, - p + got, NULL); + p + got); if (ret < 0) { mmap_read_unlock(current->mm); goto bail_release; diff --git a/drivers/infiniband/hw/usnic/usnic_uiom.c b/drivers/infiniband/hw/usnic/usnic_uiom.c index 2a5cac2658ec..84e0f41e7dfa 100644 --- a/drivers/infiniband/hw/usnic/usnic_uiom.c +++ b/drivers/infiniband/hw/usnic/usnic_uiom.c @@ -140,7 +140,7 @@ static int usnic_uiom_get_pages(unsigned long addr, size_t size, int writable, ret = pin_user_pages(cur_base, min_t(unsigned long, npages, PAGE_SIZE / sizeof(struct page *)), - gup_flags, page_list, NULL); + gup_flags, page_list); if (ret < 0) goto out; diff --git a/drivers/infiniband/sw/siw/siw_mem.c b/drivers/infiniband/sw/siw/siw_mem.c index f51ab2ccf151..e6e25f15567d 100644 --- a/drivers/infiniband/sw/siw/siw_mem.c +++ b/drivers/infiniband/sw/siw/siw_mem.c @@ -422,7 +422,7 @@ struct siw_umem *siw_umem_get(u64 start, u64 len, bool writable) umem->page_chunk[i].plist = plist; while (nents) { rv = pin_user_pages(first_page_va, nents, foll_flags, - plist, NULL); + plist); if (rv < 0) goto out_sem_up; diff --git a/drivers/media/v4l2-core/videobuf-dma-sg.c b/drivers/media/v4l2-core/videobuf-dma-sg.c index 53001532e8e3..405b89ea1054 100644 --- a/drivers/media/v4l2-core/videobuf-dma-sg.c +++ b/drivers/media/v4l2-core/videobuf-dma-sg.c @@ -180,7 +180,7 @@ static int videobuf_dma_init_user_locked(struct videobuf_dmabuf *dma, data, size, dma->nr_pages); err = pin_user_pages(data & PAGE_MASK, dma->nr_pages, gup_flags, - dma->pages, NULL); + dma->pages); if (err != dma->nr_pages) { dma->nr_pages = (err >= 0) ? err : 0; diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c index de97e38c3b82..4d4405f058e8 100644 --- a/drivers/vdpa/vdpa_user/vduse_dev.c +++ b/drivers/vdpa/vdpa_user/vduse_dev.c @@ -1052,7 +1052,7 @@ static int vduse_dev_reg_umem(struct vduse_dev *dev, goto out; pinned = pin_user_pages(uaddr, npages, FOLL_LONGTERM | FOLL_WRITE, - page_list, NULL); + page_list); if (pinned != npages) { ret = pinned < 0 ? pinned : -ENOMEM; goto out; diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c index 8c1aefc865f0..61223fcbe82b 100644 --- a/drivers/vhost/vdpa.c +++ b/drivers/vhost/vdpa.c @@ -983,7 +983,7 @@ static int vhost_vdpa_pa_map(struct vhost_vdpa *v, while (npages) { sz2pin = min_t(unsigned long, npages, list_size); pinned = pin_user_pages(cur_base, sz2pin, - gup_flags, page_list, NULL); + gup_flags, page_list); if (sz2pin != pinned) { if (pinned < 0) { ret = pinned; diff --git a/include/linux/mm.h b/include/linux/mm.h index 679b41ef7a6d..db09c7062965 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2412,8 +2412,7 @@ static inline struct page *get_user_page_vma_remote(struct mm_struct *mm, long get_user_pages(unsigned long start, unsigned long nr_pages, unsigned int gup_flags, struct page **pages); long pin_user_pages(unsigned long start, unsigned long nr_pages, - unsigned int gup_flags, struct page **pages, - struct vm_area_struct **vmas); + unsigned int gup_flags, struct page **pages); long get_user_pages_unlocked(unsigned long start, unsigned long nr_pages, struct page **pages, unsigned int gup_flags); long pin_user_pages_unlocked(unsigned long start, unsigned long nr_pages, diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c index b6451f8bc5d5..b56bda46a9eb 100644 --- a/io_uring/rsrc.c +++ b/io_uring/rsrc.c @@ -1044,7 +1044,7 @@ struct page **io_pin_pages(unsigned long ubuf, unsigned long len, int *npages) ret = 0; mmap_read_lock(current->mm); pret = pin_user_pages(ubuf, nr_pages, FOLL_WRITE | FOLL_LONGTERM, - pages, NULL); + pages); if (pret == nr_pages) *npages = nr_pages; else diff --git a/mm/gup.c b/mm/gup.c index 1493cc8dd526..36701b5f0123 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -3274,8 +3274,6 @@ EXPORT_SYMBOL(pin_user_pages_remote); * @gup_flags: flags modifying lookup behaviour * @pages: array that receives pointers to the pages pinned. * Should be at least nr_pages long. - * @vmas: array of pointers to vmas corresponding to each page. - * Or NULL if the caller does not require them. * * Nearly the same as get_user_pages(), except that FOLL_TOUCH is not set, and * FOLL_PIN is set. @@ -3284,15 +3282,14 @@ EXPORT_SYMBOL(pin_user_pages_remote); * see Documentation/core-api/pin_user_pages.rst for details. */ long pin_user_pages(unsigned long start, unsigned long nr_pages, - unsigned int gup_flags, struct page **pages, - struct vm_area_struct **vmas) + unsigned int gup_flags, struct page **pages) { int locked = 1; - if (!is_valid_gup_args(pages, vmas, NULL, &gup_flags, FOLL_PIN)) + if (!is_valid_gup_args(pages, NULL, NULL, &gup_flags, FOLL_PIN)) return 0; return __gup_longterm_locked(current->mm, start, nr_pages, - pages, vmas, &locked, gup_flags); + pages, NULL, &locked, gup_flags); } EXPORT_SYMBOL(pin_user_pages); diff --git a/mm/gup_test.c b/mm/gup_test.c index 9ba8ea23f84e..1668ce0e0783 100644 --- a/mm/gup_test.c +++ b/mm/gup_test.c @@ -146,18 +146,17 @@ static int __gup_test_ioctl(unsigned int cmd, pages + i); break; case PIN_BASIC_TEST: - nr = pin_user_pages(addr, nr, gup->gup_flags, pages + i, - NULL); + nr = pin_user_pages(addr, nr, gup->gup_flags, pages + i); break; case PIN_LONGTERM_BENCHMARK: nr = pin_user_pages(addr, nr, gup->gup_flags | FOLL_LONGTERM, - pages + i, NULL); + pages + i); break; case DUMP_USER_PAGES_TEST: if (gup->test_flags & GUP_TEST_FLAG_DUMP_PAGES_USE_PIN) nr = pin_user_pages(addr, nr, gup->gup_flags, - pages + i, NULL); + pages + i); else nr = get_user_pages(addr, nr, gup->gup_flags, pages + i); @@ -270,7 +269,7 @@ static inline int pin_longterm_test_start(unsigned long arg) gup_flags, pages); else cur_pages = pin_user_pages(addr, remaining_pages, - gup_flags, pages, NULL); + gup_flags, pages); if (cur_pages < 0) { pin_longterm_test_stop(); ret = cur_pages; diff --git a/net/xdp/xdp_umem.c b/net/xdp/xdp_umem.c index 02207e852d79..06cead2b8e34 100644 --- a/net/xdp/xdp_umem.c +++ b/net/xdp/xdp_umem.c @@ -103,7 +103,7 @@ static int xdp_umem_pin_pages(struct xdp_umem *umem, unsigned long address) mmap_read_lock(current->mm); npgs = pin_user_pages(address, umem->npgs, - gup_flags | FOLL_LONGTERM, &umem->pgs[0], NULL); + gup_flags | FOLL_LONGTERM, &umem->pgs[0]); mmap_read_unlock(current->mm); if (npgs != umem->npgs) { From patchwork Sun May 14 21:27:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13240577 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D2EE5C7EE22 for ; Sun, 14 May 2023 21:27:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7436E900009; Sun, 14 May 2023 17:27:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6F363900002; Sun, 14 May 2023 17:27:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5BB33900009; Sun, 14 May 2023 17:27:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 47C6D900002 for ; Sun, 14 May 2023 17:27:09 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 606D3AEECE for ; Sun, 14 May 2023 21:27:08 +0000 (UTC) X-FDA: 80790146136.14.396F4CE Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) by imf05.hostedemail.com (Postfix) with ESMTP id 76DFF100003 for ; Sun, 14 May 2023 21:27:06 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b="CRy4cO/s"; spf=pass (imf05.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.50 as permitted sender) smtp.mailfrom=lstoakes@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684099626; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=vLnqeCecPvm2o2r06fXW6fOfANT1A9Y9lufxO7eNzEs=; b=pwR2Sms7/PyXu0U8Swghx3YIiyU7AkBIylTUcEx7xzK9kFYvPyOCapIZuASJLCU3GRQ5Rc l/waOskTGYuHrm41rnd26ZNm50Iq6APATlftIjW3lebkRjJ1G2ICosM00KISDP+P/CJPBU MmqNpbcdmOI5qRF2jRv//FuarHzdYzs= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b="CRy4cO/s"; spf=pass (imf05.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.50 as permitted sender) smtp.mailfrom=lstoakes@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684099626; a=rsa-sha256; cv=none; b=xjpS3IaZXzq7J9G4eqH3oAmWGhJnHNY/ZMHI6AYR3WGOHwH495g7izNCe9pfI1sIIVAqhw cZYWy5Se0inoKvCu8w4WVVOCnM+MnidEI270JXhKAhiSeDrl/9uicNWePMr5nPk0ATNkje p2rkaie4wiW/qG7amwv5wvN+Za3N1kw= Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-3f41dceb9d4so89036555e9.1 for ; Sun, 14 May 2023 14:27:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684099625; x=1686691625; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vLnqeCecPvm2o2r06fXW6fOfANT1A9Y9lufxO7eNzEs=; b=CRy4cO/sSRxPtZnhpC6n7aMWC40DbBZaF7oCtyw5QUGoYmvGLs1AIIQUbEB5lVTz3P eoOa9IqmWddEcROPUEhAe4suQaeoSeNiQNNgfXpYQbjtfRGDS5F+s/zAJUmFyyMeQjfV 5L4HXZgMGSI2XJCR3/Sg+Nz7PPh+u8/1jxwRnizjyTViymIhFp9cRtnfO3hBFRu/t9il SSzFZGUbVZUEEIpb2luTP/khveBoJrVIy30xt7WSW/Mfa/0P6KSfKlHJ4Z4bF8xam+HG tckaTaqE9nxOeifqd+h5rbF2PSnqWuFJBJL/dUYZsdn8x5/uIiHwZgG1JtLxJFf9GYHa B0Dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684099625; x=1686691625; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vLnqeCecPvm2o2r06fXW6fOfANT1A9Y9lufxO7eNzEs=; b=Tk+e+lTedS7LnZHNsP7EC7y2B5jt+uki/SdPoL9ZvrmzZz1UtGMpi0PE8gcM59MN3H pVQTjlxqJH5Wzwfzv7cuT4cswh2C8eH9Ln5HG7Lf4sbrxwTuxf0RAVqTh6ipcnS1nSyp fo/Xe+bundstLQp7M/ws/tWclmtFve+ykUeNe4oeXRJLdXVAJ2zlzSiDuA1KHEXf/p0V 5t+Qc5bn5qBUZGXffZrro/PLLbsN+T48zo0ZQZ9Q2e/7dSlY7M0t87uHF6+uSjx22jhf yLhl3VK998RuwQoN1B9Q3JaHcw8zZtsLzd7n56qyiveYcqbMtUhUDnac0COgpFMSSS4t xI9A== X-Gm-Message-State: AC+VfDwfjWVY4u/4rVjQcHKj3kOQUcq/JAbseUtdUXXUxDms+BA2iKHZ +LbZ6t6MQoYtSAx0QBP6ktS7UFhKZsiqHw== X-Google-Smtp-Source: ACHHUZ6CJRa4KFleLPcXoSZJm30ThFsypL7WHS+RlS+aaSK78lJSuLiZBVRM4eqcbciL4gH3qo6vcg== X-Received: by 2002:a05:600c:cf:b0:3f4:2a06:dc59 with SMTP id u15-20020a05600c00cf00b003f42a06dc59mr17236558wmm.12.1684099624183; Sun, 14 May 2023 14:27:04 -0700 (PDT) Received: from lucifer.home ([2a00:23c5:dc8c:8701:1663:9a35:5a7b:1d76]) by smtp.googlemail.com with ESMTPSA id r13-20020adfe68d000000b003012030a0c6sm30126843wrm.18.2023.05.14.14.27.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 May 2023 14:27:03 -0700 (PDT) From: Lorenzo Stoakes To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton Cc: Matthew Wilcox , David Hildenbrand , Mike Kravetz , Muchun Song , Jens Axboe , Pavel Begunkov , Jason Gunthorpe , John Hubbard , Lorenzo Stoakes Subject: [PATCH v5 6/6] mm/gup: remove vmas array from internal GUP functions Date: Sun, 14 May 2023 22:27:01 +0100 Message-Id: <23f5b6e75ccf31565355cd37bf1253d20f2e6388.1684097002.git.lstoakes@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 X-Stat-Signature: cwzhscsumizk3z5m5pem34fay7jgcr99 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 76DFF100003 X-Rspam-User: X-HE-Tag: 1684099626-446385 X-HE-Meta: U2FsdGVkX1+az8x7K1hDFnvo7fnJkCx2iWMkJEHmwqRFasP9oSbhlqk4dMm8vyIFcxPhbdYdJf/ccDeWnBccRCEy8wkyW8UA5W640vfLfJDc0oIIMEzB0MTYenL9FWo4fJgr28nbFOst6nA5QK8NzaXO5+2BDGqWFUSMzHh+lxeZo44rXdF8cCBKbHAguvVs7y0mCBPjJEtVVhp96QdkeDP1KgUb7Mk9iB/JnBE+f7jFOMPI0T5mY7/CtvofTXZTIhOBTbQ7uldEVf9vLSwd2TXYizIHcnGH0V9ZYDkVulYHbibndIzzzCg3CPC/uRYcGbxm6xgIiVIQtFbvXF6Sz639PLmmyPabgP46FRAxDo+ofjZ+J7OeyOiKJRfREmtGIZ2pWXLCkf0ACk5PwPHId3B2ReC1Dcs80WTbMSiFYrQkzKNLXcK9P99/tmXkn5uY6kzV9Tvbmd6JpxyjSRlBZ+hA4tRLzX7GtQIUrzvMOrr43E6LKlKr/ps9v0h++YJHbzevoyfnw9Se5UZ78ffc0td4qlmX+K7wZ4zkKPo0DdiZCFHnTKgNrX/jjkxjhKqKJ46t4DDqYDJzi2CptF7R6Lj+1GO5tPwk1f2kyBAkYMVWTtAd2nIKhA2k25MdWw7pjhEzh4qABl9E1LPilDTcNIscV3bXg8Aqpp2m65wMeOqA7RLGI/PqfjAcD2srD58i/LhQg6UZla9y2zrgW5lr2Koo4RKghTaZJbOBYTYZ4K6eGySNDFDlngczxWVF5fLEHvzuimJsK/rPlrp2wVICTx59Wt7weGXH0MQihjLPzLv/xnLQBeWMwAKccUZa+PziGSdd+M4WBPRUPj+DpmPoABABJzmmy+8DvHOCmLQxPd6yTcSFoQ5DfZSiovXd1aIfK4XCSz1TxRvLvWH0dO/4mtvGT1BtS/Znhs3YsAKfXnodNHYo/gM9MA04uNK1lTFSl7axrlyv4cXkamDU8/C G72SpQhK HPLho+DcAv2swBmwqgpb5uhz7yMs7no42I80KATJT5DC8M+wr9mcOvogSbqZ46lkXmyTJ/sa8cjhuh7pSIjl3Ff9hPfC13lCoFJWjgc+/YGkA/Yi7HlNzLfIMNQmYNhiGAA7wCfFGaiKVNZMhKgxodlaHaVz/Rj9Nutr5ohSphWdnG12VVL+0PxO4l1uzFrhRm1i3E9IYqI2D1iHEf6F5zJbQ2jMR3TYjN2CT0fNiy+FT1tWd8Ge97hk9AxbPsTveAC4AQM4jEGgxaXtToCYhStBC+2ikgRFBQue0j85yqMhuYWe4XUZgeVK+vxdAjam27yH4jPyhl/2oKbK2Hu0vdT2lZD06BrdgP00Gb6G+Qx8nlhF1UhSYFp/iroA23g6gmhPb6B6mn11+SIYbnloljsQgnXD4NmXVunDF4HKlNhECOViFZEg+Yca1Eb2v0ywKLz4Mkja0HYweRQOyvtMdp7g38DhVfa8D9FXJkF52z2F63ke+HQYnf+md/t2d1SOSzjSAkUPYjtOZeuI= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Now we have eliminated all callers to GUP APIs which use the vmas parameter, eliminate it altogether. This eliminates a class of bugs where vmas might have been kept around longer than the mmap_lock and thus we need not be concerned about locks being dropped during this operation leaving behind dangling pointers. This simplifies the GUP API and makes it considerably clearer as to its purpose - follow flags are applied and if pinning, an array of pages is returned. Acked-by: David Hildenbrand Signed-off-by: Lorenzo Stoakes Reviewed-by: Christoph Hellwig --- include/linux/hugetlb.h | 10 ++--- mm/gup.c | 83 +++++++++++++++-------------------------- mm/hugetlb.c | 24 +++++------- 3 files changed, 45 insertions(+), 72 deletions(-) diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index 6d041aa9f0fe..b2b698f9a2ec 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -133,9 +133,8 @@ int copy_hugetlb_page_range(struct mm_struct *, struct mm_struct *, struct page *hugetlb_follow_page_mask(struct vm_area_struct *vma, unsigned long address, unsigned int flags); long follow_hugetlb_page(struct mm_struct *, struct vm_area_struct *, - struct page **, struct vm_area_struct **, - unsigned long *, unsigned long *, long, unsigned int, - int *); + struct page **, unsigned long *, unsigned long *, + long, unsigned int, int *); void unmap_hugepage_range(struct vm_area_struct *, unsigned long, unsigned long, struct page *, zap_flags_t); @@ -306,9 +305,8 @@ static inline struct page *hugetlb_follow_page_mask(struct vm_area_struct *vma, static inline long follow_hugetlb_page(struct mm_struct *mm, struct vm_area_struct *vma, struct page **pages, - struct vm_area_struct **vmas, unsigned long *position, - unsigned long *nr_pages, long i, unsigned int flags, - int *nonblocking) + unsigned long *position, unsigned long *nr_pages, + long i, unsigned int flags, int *nonblocking) { BUG(); return 0; diff --git a/mm/gup.c b/mm/gup.c index 36701b5f0123..dbe96d266670 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -1067,8 +1067,6 @@ static int check_vma_flags(struct vm_area_struct *vma, unsigned long gup_flags) * @pages: array that receives pointers to the pages pinned. * Should be at least nr_pages long. Or NULL, if caller * only intends to ensure the pages are faulted in. - * @vmas: array of pointers to vmas corresponding to each page. - * Or NULL if the caller does not require them. * @locked: whether we're still with the mmap_lock held * * Returns either number of pages pinned (which may be less than the @@ -1082,8 +1080,6 @@ static int check_vma_flags(struct vm_area_struct *vma, unsigned long gup_flags) * * The caller is responsible for releasing returned @pages, via put_page(). * - * @vmas are valid only as long as mmap_lock is held. - * * Must be called with mmap_lock held. It may be released. See below. * * __get_user_pages walks a process's page tables and takes a reference to @@ -1119,7 +1115,7 @@ static int check_vma_flags(struct vm_area_struct *vma, unsigned long gup_flags) static long __get_user_pages(struct mm_struct *mm, unsigned long start, unsigned long nr_pages, unsigned int gup_flags, struct page **pages, - struct vm_area_struct **vmas, int *locked) + int *locked) { long ret = 0, i = 0; struct vm_area_struct *vma = NULL; @@ -1159,9 +1155,9 @@ static long __get_user_pages(struct mm_struct *mm, goto out; if (is_vm_hugetlb_page(vma)) { - i = follow_hugetlb_page(mm, vma, pages, vmas, - &start, &nr_pages, i, - gup_flags, locked); + i = follow_hugetlb_page(mm, vma, pages, + &start, &nr_pages, i, + gup_flags, locked); if (!*locked) { /* * We've got a VM_FAULT_RETRY @@ -1226,10 +1222,6 @@ static long __get_user_pages(struct mm_struct *mm, ctx.page_mask = 0; } next_page: - if (vmas) { - vmas[i] = vma; - ctx.page_mask = 0; - } page_increm = 1 + (~(start >> PAGE_SHIFT) & ctx.page_mask); if (page_increm > nr_pages) page_increm = nr_pages; @@ -1384,7 +1376,6 @@ static __always_inline long __get_user_pages_locked(struct mm_struct *mm, unsigned long start, unsigned long nr_pages, struct page **pages, - struct vm_area_struct **vmas, int *locked, unsigned int flags) { @@ -1422,7 +1413,7 @@ static __always_inline long __get_user_pages_locked(struct mm_struct *mm, pages_done = 0; for (;;) { ret = __get_user_pages(mm, start, nr_pages, flags, pages, - vmas, locked); + locked); if (!(flags & FOLL_UNLOCKABLE)) { /* VM_FAULT_RETRY couldn't trigger, bypass */ pages_done = ret; @@ -1486,7 +1477,7 @@ static __always_inline long __get_user_pages_locked(struct mm_struct *mm, *locked = 1; ret = __get_user_pages(mm, start, 1, flags | FOLL_TRIED, - pages, NULL, locked); + pages, locked); if (!*locked) { /* Continue to retry until we succeeded */ BUG_ON(ret != 0); @@ -1584,7 +1575,7 @@ long populate_vma_page_range(struct vm_area_struct *vma, * not result in a stack expansion that recurses back here. */ ret = __get_user_pages(mm, start, nr_pages, gup_flags, - NULL, NULL, locked ? locked : &local_locked); + NULL, locked ? locked : &local_locked); lru_add_drain(); return ret; } @@ -1642,7 +1633,7 @@ long faultin_vma_page_range(struct vm_area_struct *vma, unsigned long start, return -EINVAL; ret = __get_user_pages(mm, start, nr_pages, gup_flags, - NULL, NULL, locked); + NULL, locked); lru_add_drain(); return ret; } @@ -1710,8 +1701,7 @@ int __mm_populate(unsigned long start, unsigned long len, int ignore_errors) #else /* CONFIG_MMU */ static long __get_user_pages_locked(struct mm_struct *mm, unsigned long start, unsigned long nr_pages, struct page **pages, - struct vm_area_struct **vmas, int *locked, - unsigned int foll_flags) + int *locked, unsigned int foll_flags) { struct vm_area_struct *vma; bool must_unlock = false; @@ -1755,8 +1745,7 @@ static long __get_user_pages_locked(struct mm_struct *mm, unsigned long start, if (pages[i]) get_page(pages[i]); } - if (vmas) - vmas[i] = vma; + start = (start + PAGE_SIZE) & PAGE_MASK; } @@ -1937,8 +1926,7 @@ struct page *get_dump_page(unsigned long addr) int locked = 0; int ret; - ret = __get_user_pages_locked(current->mm, addr, 1, &page, NULL, - &locked, + ret = __get_user_pages_locked(current->mm, addr, 1, &page, &locked, FOLL_FORCE | FOLL_DUMP | FOLL_GET); return (ret == 1) ? page : NULL; } @@ -2111,7 +2099,6 @@ static long __gup_longterm_locked(struct mm_struct *mm, unsigned long start, unsigned long nr_pages, struct page **pages, - struct vm_area_struct **vmas, int *locked, unsigned int gup_flags) { @@ -2119,13 +2106,13 @@ static long __gup_longterm_locked(struct mm_struct *mm, long rc, nr_pinned_pages; if (!(gup_flags & FOLL_LONGTERM)) - return __get_user_pages_locked(mm, start, nr_pages, pages, vmas, + return __get_user_pages_locked(mm, start, nr_pages, pages, locked, gup_flags); flags = memalloc_pin_save(); do { nr_pinned_pages = __get_user_pages_locked(mm, start, nr_pages, - pages, vmas, locked, + pages, locked, gup_flags); if (nr_pinned_pages <= 0) { rc = nr_pinned_pages; @@ -2143,9 +2130,8 @@ static long __gup_longterm_locked(struct mm_struct *mm, * Check that the given flags are valid for the exported gup/pup interface, and * update them with the required flags that the caller must have set. */ -static bool is_valid_gup_args(struct page **pages, struct vm_area_struct **vmas, - int *locked, unsigned int *gup_flags_p, - unsigned int to_set) +static bool is_valid_gup_args(struct page **pages, int *locked, + unsigned int *gup_flags_p, unsigned int to_set) { unsigned int gup_flags = *gup_flags_p; @@ -2187,13 +2173,6 @@ static bool is_valid_gup_args(struct page **pages, struct vm_area_struct **vmas, (gup_flags & FOLL_PCI_P2PDMA))) return false; - /* - * Can't use VMAs with locked, as locked allows GUP to unlock - * which invalidates the vmas array - */ - if (WARN_ON_ONCE(vmas && (gup_flags & FOLL_UNLOCKABLE))) - return false; - *gup_flags_p = gup_flags; return true; } @@ -2262,11 +2241,11 @@ long get_user_pages_remote(struct mm_struct *mm, { int local_locked = 1; - if (!is_valid_gup_args(pages, NULL, locked, &gup_flags, + if (!is_valid_gup_args(pages, locked, &gup_flags, FOLL_TOUCH | FOLL_REMOTE)) return -EINVAL; - return __get_user_pages_locked(mm, start, nr_pages, pages, NULL, + return __get_user_pages_locked(mm, start, nr_pages, pages, locked ? locked : &local_locked, gup_flags); } @@ -2301,11 +2280,11 @@ long get_user_pages(unsigned long start, unsigned long nr_pages, { int locked = 1; - if (!is_valid_gup_args(pages, NULL, NULL, &gup_flags, FOLL_TOUCH)) + if (!is_valid_gup_args(pages, NULL, &gup_flags, FOLL_TOUCH)) return -EINVAL; return __get_user_pages_locked(current->mm, start, nr_pages, pages, - NULL, &locked, gup_flags); + &locked, gup_flags); } EXPORT_SYMBOL(get_user_pages); @@ -2329,12 +2308,12 @@ long get_user_pages_unlocked(unsigned long start, unsigned long nr_pages, { int locked = 0; - if (!is_valid_gup_args(pages, NULL, NULL, &gup_flags, + if (!is_valid_gup_args(pages, NULL, &gup_flags, FOLL_TOUCH | FOLL_UNLOCKABLE)) return -EINVAL; return __get_user_pages_locked(current->mm, start, nr_pages, pages, - NULL, &locked, gup_flags); + &locked, gup_flags); } EXPORT_SYMBOL(get_user_pages_unlocked); @@ -3124,7 +3103,7 @@ static int internal_get_user_pages_fast(unsigned long start, start += nr_pinned << PAGE_SHIFT; pages += nr_pinned; ret = __gup_longterm_locked(current->mm, start, nr_pages - nr_pinned, - pages, NULL, &locked, + pages, &locked, gup_flags | FOLL_TOUCH | FOLL_UNLOCKABLE); if (ret < 0) { /* @@ -3166,7 +3145,7 @@ int get_user_pages_fast_only(unsigned long start, int nr_pages, * FOLL_FAST_ONLY is required in order to match the API description of * this routine: no fall back to regular ("slow") GUP. */ - if (!is_valid_gup_args(pages, NULL, NULL, &gup_flags, + if (!is_valid_gup_args(pages, NULL, &gup_flags, FOLL_GET | FOLL_FAST_ONLY)) return -EINVAL; @@ -3199,7 +3178,7 @@ int get_user_pages_fast(unsigned long start, int nr_pages, * FOLL_GET, because gup fast is always a "pin with a +1 page refcount" * request. */ - if (!is_valid_gup_args(pages, NULL, NULL, &gup_flags, FOLL_GET)) + if (!is_valid_gup_args(pages, NULL, &gup_flags, FOLL_GET)) return -EINVAL; return internal_get_user_pages_fast(start, nr_pages, gup_flags, pages); } @@ -3224,7 +3203,7 @@ EXPORT_SYMBOL_GPL(get_user_pages_fast); int pin_user_pages_fast(unsigned long start, int nr_pages, unsigned int gup_flags, struct page **pages) { - if (!is_valid_gup_args(pages, NULL, NULL, &gup_flags, FOLL_PIN)) + if (!is_valid_gup_args(pages, NULL, &gup_flags, FOLL_PIN)) return -EINVAL; return internal_get_user_pages_fast(start, nr_pages, gup_flags, pages); } @@ -3257,10 +3236,10 @@ long pin_user_pages_remote(struct mm_struct *mm, { int local_locked = 1; - if (!is_valid_gup_args(pages, NULL, locked, &gup_flags, + if (!is_valid_gup_args(pages, locked, &gup_flags, FOLL_PIN | FOLL_TOUCH | FOLL_REMOTE)) return 0; - return __gup_longterm_locked(mm, start, nr_pages, pages, NULL, + return __gup_longterm_locked(mm, start, nr_pages, pages, locked ? locked : &local_locked, gup_flags); } @@ -3286,10 +3265,10 @@ long pin_user_pages(unsigned long start, unsigned long nr_pages, { int locked = 1; - if (!is_valid_gup_args(pages, NULL, NULL, &gup_flags, FOLL_PIN)) + if (!is_valid_gup_args(pages, NULL, &gup_flags, FOLL_PIN)) return 0; return __gup_longterm_locked(current->mm, start, nr_pages, - pages, NULL, &locked, gup_flags); + pages, &locked, gup_flags); } EXPORT_SYMBOL(pin_user_pages); @@ -3303,11 +3282,11 @@ long pin_user_pages_unlocked(unsigned long start, unsigned long nr_pages, { int locked = 0; - if (!is_valid_gup_args(pages, NULL, NULL, &gup_flags, + if (!is_valid_gup_args(pages, NULL, &gup_flags, FOLL_PIN | FOLL_TOUCH | FOLL_UNLOCKABLE)) return 0; - return __gup_longterm_locked(current->mm, start, nr_pages, pages, NULL, + return __gup_longterm_locked(current->mm, start, nr_pages, pages, &locked, gup_flags); } EXPORT_SYMBOL(pin_user_pages_unlocked); diff --git a/mm/hugetlb.c b/mm/hugetlb.c index f154019e6b84..ea24718db4af 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -6425,17 +6425,14 @@ int hugetlb_mfill_atomic_pte(pte_t *dst_pte, } #endif /* CONFIG_USERFAULTFD */ -static void record_subpages_vmas(struct page *page, struct vm_area_struct *vma, - int refs, struct page **pages, - struct vm_area_struct **vmas) +static void record_subpages(struct page *page, struct vm_area_struct *vma, + int refs, struct page **pages) { int nr; for (nr = 0; nr < refs; nr++) { if (likely(pages)) pages[nr] = nth_page(page, nr); - if (vmas) - vmas[nr] = vma; } } @@ -6508,9 +6505,9 @@ struct page *hugetlb_follow_page_mask(struct vm_area_struct *vma, } long follow_hugetlb_page(struct mm_struct *mm, struct vm_area_struct *vma, - struct page **pages, struct vm_area_struct **vmas, - unsigned long *position, unsigned long *nr_pages, - long i, unsigned int flags, int *locked) + struct page **pages, unsigned long *position, + unsigned long *nr_pages, long i, unsigned int flags, + int *locked) { unsigned long pfn_offset; unsigned long vaddr = *position; @@ -6638,7 +6635,7 @@ long follow_hugetlb_page(struct mm_struct *mm, struct vm_area_struct *vma, * If subpage information not requested, update counters * and skip the same_page loop below. */ - if (!pages && !vmas && !pfn_offset && + if (!pages && !pfn_offset && (vaddr + huge_page_size(h) < vma->vm_end) && (remainder >= pages_per_huge_page(h))) { vaddr += huge_page_size(h); @@ -6653,11 +6650,10 @@ long follow_hugetlb_page(struct mm_struct *mm, struct vm_area_struct *vma, refs = min3(pages_per_huge_page(h) - pfn_offset, remainder, (vma->vm_end - ALIGN_DOWN(vaddr, PAGE_SIZE)) >> PAGE_SHIFT); - if (pages || vmas) - record_subpages_vmas(nth_page(page, pfn_offset), - vma, refs, - likely(pages) ? pages + i : NULL, - vmas ? vmas + i : NULL); + if (pages) + record_subpages(nth_page(page, pfn_offset), + vma, refs, + likely(pages) ? pages + i : NULL); if (pages) { /*