From nobody Thu Dec 18 07:50:40 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1D21BC7619A for ; Sat, 15 Apr 2023 12:09:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229984AbjDOMJ2 (ORCPT ); Sat, 15 Apr 2023 08:09:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229557AbjDOMJY (ORCPT ); Sat, 15 Apr 2023 08:09:24 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A5385243; Sat, 15 Apr 2023 05:09:23 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id v10so4945252wmn.5; Sat, 15 Apr 2023 05:09:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681560561; x=1684152561; 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=7bl5SFQ2vJygxB6ULQ7owEqW0w5QgVbsAK3PYNhUFh4=; b=X3wx/SDN/wkZLlSRmWoO4XjoTTfufgaCgXTVI/8MBUXN3C5Kkoa6Jp85DZjC2wf04W 5zmYu8D4+7x1XhIYxdSsCRIERvV0lFjGdN788237PxGzXXvNaYNGL4VtPXGRM957hh24 /Zmj3BNC7AwR1Eo8sblwN4P+Ze+O+oJrN1YeKxDSi7T796tpi4rBrqVu4ygIiSQ6V1ea ntVuCJrPlMT0HzUauagKqw9sDcbJtmWoQD15O9UkaxHT6OvpdgMQmDMpIuRW3RLHxvLm OFPvi6W6+FXczHkXNWBfzsZPOro21B2OrSa4OuRcmpQCbBgbpZ+S3Ye6U/TxjSSDu57M mx2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681560561; x=1684152561; 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=7bl5SFQ2vJygxB6ULQ7owEqW0w5QgVbsAK3PYNhUFh4=; b=WdVFcMZnAQ4e7pQxd3V0wJ40xMoOIkcXDsY+HzR1i2XfhCZvXTMCFZBB4qSm+usuBl jHecQ/bASF+ZHddpJooeLL8hVPOLEMV5mTODwJoEzJxLdOFJtluKD0kUeDJfDiE5iSYq TvXlLE6vo/hLrxb2TXx4fE4YxKEWg/fAVElQJDezva1Rz1/hFva5MPsbobZ1FPGEtRd/ f2zU3ae1r2Y8u644hbD7uc0iuO8j+NQL+5JCg/oNdlpFDcOfaxPJ8fifUdrx5Gty1T64 jPI6OOLD6Nk0YXp6oGK1OwxAOcVZ4WN8QBu+2N52cckWlLn775cY9af5uLxV2kbhI84n XUzA== X-Gm-Message-State: AAQBX9cc4V6vvOtJOdTUZqlGfkDgGgA/T8LUGXeCN8lM+uSEShwaXcyx fKiq0H47lIu9Tq4KUPQprAM= X-Google-Smtp-Source: AKy350Yysqw/G21F2cEQ1bzpOiU/6gRNUP/bJK1jn3guibsBFaVe0RGWhuMX5MIUHG1wPs+pj7mvig== X-Received: by 2002:a05:600c:204c:b0:3f0:aeac:2f9c with SMTP id p12-20020a05600c204c00b003f0aeac2f9cmr4917397wmg.7.1681560561281; Sat, 15 Apr 2023 05:09:21 -0700 (PDT) Received: from lucifer.home ([2a00:23c5:dc8c:8701:1663:9a35:5a7b:1d76]) by smtp.googlemail.com with ESMTPSA id 15-20020a05600c230f00b003f16fdc6233sm134903wmo.47.2023.04.15.05.09.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Apr 2023 05:09:20 -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 , Lorenzo Stoakes Subject: [PATCH v3 1/7] mm/gup: remove unused vmas parameter from get_user_pages() Date: Sat, 15 Apr 2023 13:09:18 +0100 Message-Id: <28967f170eceeebf2591a5e4370d0642e0516f9b.1681558407.git.lstoakes@gmail.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" No invocation of get_user_pages() uses 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. Signed-off-by: Lorenzo Stoakes Suggested-by: Matthew Wilcox (Oracle) Acked-by: Greg Kroah-Hartman Acked-by: David Hildenbrand --- 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/ioct= l.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; =20 - ret =3D get_user_pages(src, 1, 0, &src_page, NULL); + ret =3D get_user_pages(src, 1, 0, &src_page); if (ret < 1) return -EFAULT; =20 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/r= adeon_ttm.c index 1e8e287e113c..0597540f0dde 100644 --- a/drivers/gpu/drm/radeon/radeon_ttm.c +++ b/drivers/gpu/drm/radeon/radeon_ttm.c @@ -362,7 +362,7 @@ static int radeon_ttm_tt_pin_userptr(struct ttm_device = *bdev, struct ttm_tt *ttm struct page **pages =3D ttm->pages + pinned; =20 r =3D get_user_pages(userptr, num_pages, write ? FOLL_WRITE : 0, - pages, NULL); + pages); if (r < 0) goto release_pages; =20 diff --git a/drivers/misc/sgi-gru/grufault.c b/drivers/misc/sgi-gru/grufaul= t.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 =3D PAGE_SHIFT; #endif - if (get_user_pages(vaddr, 1, write ? FOLL_WRITE : 0, &page, NULL) <=3D 0) + if (get_user_pages(vaddr, 1, write ? FOLL_WRITE : 0, &page) <=3D 0) return -EFAULT; *paddr =3D page_to_phys(page); put_page(page); diff --git a/include/linux/mm.h b/include/linux/mm.h index 37554b08bb28..b14cc4972d0b 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2380,8 +2380,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 1f72a717232b..7e454d6b157e 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -2251,8 +2251,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 belong= s to @@ -2260,16 +2258,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 =3D 1; =20 - 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; =20 return __get_user_pages_locked(current->mm, start, nr_pages, pages, - vmas, &locked, gup_flags); + NULL, &locked, gup_flags); } EXPORT_SYMBOL(get_user_pages); =20 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 =3D get_user_pages(addr, nr, gup->gup_flags, pages + i, - NULL); + nr =3D get_user_pages(addr, nr, gup->gup_flags, pages + i); break; case PIN_FAST_BENCHMARK: nr =3D 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 =3D get_user_pages(addr, nr, gup->gup_flags, - pages + i, NULL); + pages + i); break; default: ret =3D -EINVAL; diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index d255964ec331..7f31e0a4adb5 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -2474,7 +2474,7 @@ static inline int check_user_page_hwpoison(unsigned l= ong addr) { int rc, flags =3D FOLL_HWPOISON | FOLL_WRITE; =20 - rc =3D get_user_pages(addr, 1, flags, NULL, NULL); + rc =3D get_user_pages(addr, 1, flags, NULL); return rc =3D=3D -EHWPOISON; } =20 --=20 2.40.0 From nobody Thu Dec 18 07:50:40 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9C515C7619A for ; Sat, 15 Apr 2023 12:09:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230034AbjDOMJ3 (ORCPT ); Sat, 15 Apr 2023 08:09:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229904AbjDOMJ0 (ORCPT ); Sat, 15 Apr 2023 08:09:26 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 739254EE9; Sat, 15 Apr 2023 05:09:25 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id bd13-20020a05600c1f0d00b003f14c42cc99so1843817wmb.2; Sat, 15 Apr 2023 05:09:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681560564; x=1684152564; 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=J+LSahXs7vXHVGQn1uT2igLaiQzqbh9LfXfVKe7mEnQ=; b=GsxnOitYpi73oLhTi6FjVEXHbNNB2I1m+LTWchC6U9ognod3QRNbzxwZCHEWBtDhe1 6DkMMTmq001Yy+AOQ7R1KYIg7r1GVSrp1RMbGkRCFI5uJbbDiUh2Osw1wBbs/Lrj5r8b c88Clz1Eewi+NicYztqrNHk93PEk1mE/B1kj0IjymWDErCqKvYUQtGrzh9lI3TOMC0Zr AdzXrOUeAelvmsbu2JOIKoGC6gAidmka43ibRiAwKHjzsNMmoAzks5fQgfTZiEyBp/NZ tepv+9YlS6JIp0PWTA2p88c2oQslYAzfhDr188x7TBPTSZ88a5WAWUA6TFGit6GgjSLG QKIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681560564; x=1684152564; 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=J+LSahXs7vXHVGQn1uT2igLaiQzqbh9LfXfVKe7mEnQ=; b=Yf0n7TrU0mWq8yPfvVtcMl4T4y5H16wa+vY2KqgPRprtqSKD/fEzNmzk5p3qOdp44Y XZQeOaF3aL4TD2xNQcaok3TwUqUT7LIRPX8ctDSrA7L9RM5osqc5PzlFvm4t0z31z1g7 gsukUoLJUHqQBUUQnLGywFnQuucUYIsqn0KsWv0kojbZKIE9/EcAtaTYRs49/bP5YCKm oaDm9WbRpT6dHrh1LRUAqb7OINtRyX2BOKA/MyOlH6xIvlXT0e2h6NIK1zx/omThMa/k iQEE6pHwvsDqzwcXYcntVUcJ9awXhPWK+2Zu0hRC5KBPdDfFRQfbI0CgfJ2HzTDPAUVy Eliw== X-Gm-Message-State: AAQBX9ebtpgqJx/6uYqArR47rmSGR4M6irf0v+fNtmDw+cutktFOgSib 5i2ZQLMWsOOrxhVhrrOWJPBlc81kG5DENw== X-Google-Smtp-Source: AKy350aKB0tm+8SA/HZcPhTfSTG7LR/yw/OdGCM9lH11ZxILot8tUnno6Y2e/17DZKVXVtbkRaIQaA== X-Received: by 2002:a7b:cd88:0:b0:3f0:44d1:3ba5 with SMTP id y8-20020a7bcd88000000b003f044d13ba5mr6453227wmj.5.1681560563832; Sat, 15 Apr 2023 05:09:23 -0700 (PDT) Received: from lucifer.home ([2a00:23c5:dc8c:8701:1663:9a35:5a7b:1d76]) by smtp.googlemail.com with ESMTPSA id p22-20020a05600c205600b003f16f362ae7sm631546wmg.21.2023.04.15.05.09.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Apr 2023 05:09:23 -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 , Lorenzo Stoakes Subject: [PATCH v3 2/7] mm/gup: remove unused vmas parameter from pin_user_pages_remote() Date: Sat, 15 Apr 2023 13:09:21 +0100 Message-Id: <59022490ef05da7310e6abd7f42df933bebdda2a.1681558407.git.lstoakes@gmail.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Lorenzo Stoakes Acked-by: David Hildenbrand --- 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 f8d92c9bb65b..9d55a2188a64 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 =3D 1; } rc =3D pin_user_pages_remote(pages->source_mm, uptr, npages, - user->gup_flags, user->upages, NULL, + user->gup_flags, user->upages, &user->locked); } if (rc <=3D 0) { @@ -1787,7 +1787,7 @@ static int iopt_pages_rw_page(struct iopt_pages *page= s, unsigned long index, rc =3D 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 !=3D 1) { if (WARN_ON(rc >=3D 0)) diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type= 1.c index 493c31de0edb..e6dc8fec3ed5 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, unsigne= d long vaddr, =20 mmap_read_lock(mm); ret =3D pin_user_pages_remote(mm, vaddr, npages, flags | FOLL_LONGTERM, - pages, NULL, NULL); + pages, NULL); if (ret > 0) { int i; =20 diff --git a/include/linux/mm.h b/include/linux/mm.h index b14cc4972d0b..ec9875c59f6d 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2378,7 +2378,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 7e454d6b157e..931c805bc32b 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -3093,8 +3093,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. @@ -3109,14 +3107,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 =3D 1; =20 - 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 =3D pin_user_pages_remote(mm, pa, pinned_pages, flags, process_pages, - NULL, &locked); + &locked); if (locked) mmap_read_unlock(mm); if (pinned_pages <=3D 0) --=20 2.40.0 From nobody Thu Dec 18 07:50:40 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C7815C7619A for ; Sat, 15 Apr 2023 12:09:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230126AbjDOMJi (ORCPT ); Sat, 15 Apr 2023 08:09:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230044AbjDOMJe (ORCPT ); Sat, 15 Apr 2023 08:09:34 -0400 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4497059FE; Sat, 15 Apr 2023 05:09:29 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id n42-20020a05600c3baa00b003f0b12814aaso2287249wms.0; Sat, 15 Apr 2023 05:09:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681560567; x=1684152567; 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=W0l2+WhOTuhsjrgo5218GoveeiorDwRw7Vzzp86RCdQ=; b=ldmw31RqwDsq19kNUyAGwCe6feARcBsKOWHer9UDyhHpXBW86bINZ4rpI99CYQXM3+ JERVDUA0BVrG5md+jDxa0acQWcQavONMHScc6SB/3xaQzbenQK0QpbQbIkLpaLP9jAfG e/8lzW37JCyFs7Z17XxvJnEXXn7RIxRDv594gU7u7JgSZMJp9Uy9WDSppvCABKPg9q6P 6lgN2qvP2iE7QGZPWYRob5VjTGLMpqT1ukkX4auc09mbz9UYoKDOMgZczOt3ZuXY57kC GvCT2JFtQmnaasrqUJ6+X5DcdjMmScBCDHnK/ROGEGVUOw13vr7fvIAtwDo3nrFrASqg 40qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681560567; x=1684152567; 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=W0l2+WhOTuhsjrgo5218GoveeiorDwRw7Vzzp86RCdQ=; b=BKWXoOEa9ndBXj8HrZT0P7lohYLgeCH+08eLYPjmTh8aSZ/5DvVhdnwKZzBIwq65CB 86H0JF3M6psVMRAE0WjA6Mzy1nvjcL33hqHr4ndXXS9x65ekWxNj+DQlDMoWFV3KI1oU Ef9LLY/ig7gjQbsrng/1fAZ7EMTE9hx7PihchW6TKsf294MBAFasPcVzJGsXxyRFewGW SRdVUorLIR80lzryLHO+3lvRilFWhCRNjYEG6Jh/7JuZ6G7/YWeThIxFQC7jBldEKaME ZmysX2ROmWl7lqGa079dt8dlen4lTmsf6NFJabMj4eSGO1pbSDd+dpsq/dE73GPbFnJx K65Q== X-Gm-Message-State: AAQBX9fz64U5JLNkZxvZGYRz/5DfslXIsKhQ+atT5VbWQ5aEOamHY3sI 7dGr9srfg66t4P/kAjnAEMw= X-Google-Smtp-Source: AKy350a3KTToXZy6mk4WHVMLQX+oM6Sg5f2Asfiie67hTn0jXqMQSjIUSB1JD5MwmpH2ws8BySgnig== X-Received: by 2002:a7b:c7c9:0:b0:3f1:6ecf:537 with SMTP id z9-20020a7bc7c9000000b003f16ecf0537mr672424wmk.33.1681560567358; Sat, 15 Apr 2023 05:09:27 -0700 (PDT) Received: from lucifer.home ([2a00:23c5:dc8c:8701:1663:9a35:5a7b:1d76]) by smtp.googlemail.com with ESMTPSA id q21-20020a05600c46d500b003f03d483966sm10428181wmo.44.2023.04.15.05.09.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Apr 2023 05:09:26 -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 , Lorenzo Stoakes Subject: [PATCH v3 3/7] mm/gup: remove vmas parameter from get_user_pages_remote() Date: Sat, 15 Apr 2023 13:09:24 +0100 Message-Id: <523f0764f4979276a6d4b89cbad9af9124e4bf0a.1681558407.git.lstoakes@gmail.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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. This forms part of a broader set of patches intended to eliminate the vmas parameter altogether. Signed-off-by: Lorenzo Stoakes Acked-by: David Hildenbrand Reviewed-by: Catalin Marinas --- arch/arm64/kernel/mte.c | 7 ++++--- arch/s390/kvm/interrupt.c | 2 +- fs/exec.c | 2 +- include/linux/mm.h | 2 +- kernel/events/uprobes.c | 14 +++++++++----- mm/gup.c | 12 ++++-------- mm/memory.c | 8 ++++++-- mm/rmap.c | 2 +- security/tomoyo/domain.c | 2 +- virt/kvm/async_pf.c | 3 +-- 10 files changed, 29 insertions(+), 25 deletions(-) diff --git a/arch/arm64/kernel/mte.c b/arch/arm64/kernel/mte.c index f5bcb0dc6267..904785697e91 100644 --- a/arch/arm64/kernel/mte.c +++ b/arch/arm64/kernel/mte.c @@ -419,7 +419,6 @@ 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 =3D kiov->iov_base; size_t len =3D kiov->iov_len; int ret; @@ -432,12 +431,13 @@ static int __access_remote_tags(struct mm_struct *mm,= unsigned long addr, return -EIO; =20 while (len) { + struct vm_area_struct *vma; unsigned long tags, offset; void *maddr; struct page *page =3D NULL; =20 ret =3D get_user_pages_remote(mm, addr, 1, gup_flags, &page, - &vma, NULL); + NULL); if (ret <=3D 0) break; =20 @@ -448,7 +448,8 @@ static int __access_remote_tags(struct mm_struct *mm, u= nsigned long addr, * would cause the existing tags to be cleared if the page * was never mapped with PROT_MTE. */ - if (!(vma->vm_flags & VM_MTE)) { + vma =3D vma_lookup(mm, addr); + if (WARN_ON_ONCE(!vma) || !(vma->vm_flags & VM_MTE)) { ret =3D -EOPNOTSUPP; put_page(page); break; diff --git a/arch/s390/kvm/interrupt.c b/arch/s390/kvm/interrupt.c index 9250fde1f97d..c19d0cb7d2f2 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) =20 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 87cf3a2f0e9a..d8d48ee15aac 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -219,7 +219,7 @@ static struct page *get_arg_page(struct linux_binprm *b= prm, unsigned long pos, */ mmap_read_lock(bprm->mm); ret =3D get_user_pages_remote(bprm->mm, pos, 1, gup_flags, - &page, NULL, NULL); + &page, NULL); mmap_read_unlock(bprm->mm); if (ret <=3D 0) return NULL; diff --git a/include/linux/mm.h b/include/linux/mm.h index ec9875c59f6d..1bfe73a2b6d3 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2374,7 +2374,7 @@ extern int __access_remote_vm(struct mm_struct *mm, u= nsigned long addr, 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); long pin_user_pages_remote(struct mm_struct *mm, unsigned long start, unsigned long nr_pages, unsigned int gup_flags, struct page **pages, diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c index 59887c69d54c..c5ed6bb340f7 100644 --- a/kernel/events/uprobes.c +++ b/kernel/events/uprobes.c @@ -365,7 +365,6 @@ __update_ref_ctr(struct mm_struct *mm, unsigned long va= ddr, short d) { void *kaddr; struct page *page; - struct vm_area_struct *vma; int ret; short *ptr; =20 @@ -373,7 +372,7 @@ __update_ref_ctr(struct mm_struct *mm, unsigned long va= ddr, short d) return -EINVAL; =20 ret =3D get_user_pages_remote(mm, vaddr, 1, - FOLL_WRITE, &page, &vma, NULL); + FOLL_WRITE, &page, NULL); if (unlikely(ret <=3D 0)) { /* * We are asking for 1 page. If get_user_pages_remote() fails, @@ -475,10 +474,16 @@ int uprobe_write_opcode(struct arch_uprobe *auprobe, = struct mm_struct *mm, gup_flags |=3D FOLL_SPLIT_PMD; /* Read the page with vaddr into memory */ ret =3D get_user_pages_remote(mm, vaddr, 1, gup_flags, - &old_page, &vma, NULL); + &old_page, NULL); if (ret <=3D 0) return ret; =20 + vma =3D vma_lookup(mm, vaddr); + if (WARN_ON_ONCE(!vma)) { + ret =3D -EINVAL; + goto put_old; + } + ret =3D verify_opcode(old_page, vaddr, &opcode); if (ret <=3D 0) goto put_old; @@ -2027,8 +2032,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsi= gned long vaddr) * but we treat this as a 'remote' access since it is * essentially a kernel access to the memory. */ - result =3D get_user_pages_remote(mm, vaddr, 1, FOLL_FORCE, &page, - NULL, NULL); + result =3D get_user_pages_remote(mm, vaddr, 1, FOLL_FORCE, &page, NULL); if (result < 0) return result; =20 diff --git a/mm/gup.c b/mm/gup.c index 931c805bc32b..9440aa54c741 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -2165,8 +2165,6 @@ static bool is_valid_gup_args(struct page **pages, st= ruct 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. @@ -2181,8 +2179,6 @@ static bool is_valid_gup_args(struct page **pages, st= ruct 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 referen= ce @@ -2219,15 +2215,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 =3D 1; =20 - 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; =20 - 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); } @@ -2237,7 +2233,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 8ddb10199e8d..310bfb910378 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5591,7 +5591,9 @@ int __access_remote_vm(struct mm_struct *mm, unsigned= long addr, void *buf, struct page *page =3D NULL; =20 ret =3D get_user_pages_remote(mm, addr, 1, - gup_flags, &page, &vma, NULL); + gup_flags, &page, NULL); + vma =3D vma_lookup(mm, addr); + if (ret <=3D 0) { #ifndef CONFIG_HAVE_IOREMAP_PROT break; @@ -5600,7 +5602,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 =3D vma_lookup(mm, addr); if (!vma) break; if (vma->vm_ops && vma->vm_ops->access) @@ -5610,6 +5611,9 @@ int __access_remote_vm(struct mm_struct *mm, unsigned= long addr, void *buf, break; bytes =3D ret; #endif + } else if (unlikely(!vma)) { + VM_WARN_ON_ONCE(1); + break; } else { bytes =3D len; offset =3D addr & (PAGE_SIZE-1); diff --git a/mm/rmap.c b/mm/rmap.c index ba901c416785..756ea8a9bb90 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -2324,7 +2324,7 @@ int make_device_exclusive_range(struct mm_struct *mm,= unsigned long start, =20 npages =3D get_user_pages_remote(mm, start, npages, FOLL_GET | FOLL_WRITE | FOLL_SPLIT_PMD, - pages, NULL, NULL); + pages, NULL); if (npages < 0) return npages; =20 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, unsign= ed long pos, */ mmap_read_lock(bprm->mm); ret =3D get_user_pages_remote(bprm->mm, pos, 1, - FOLL_FORCE, &page, NULL, NULL); + FOLL_FORCE, &page, NULL); mmap_read_unlock(bprm->mm); if (ret <=3D 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); =20 --=20 2.40.0 From nobody Thu Dec 18 07:50:40 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 56457C77B71 for ; Sat, 15 Apr 2023 12:09:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229967AbjDOMJn (ORCPT ); Sat, 15 Apr 2023 08:09:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230063AbjDOMJf (ORCPT ); Sat, 15 Apr 2023 08:09:35 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B837D6A72 for ; Sat, 15 Apr 2023 05:09:30 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id v10so4945334wmn.5 for ; Sat, 15 Apr 2023 05:09:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681560570; x=1684152570; 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=N3KXMf3LCMhF+M2dvABgEBrAeCcDHD/N5/gKopMor18=; b=HCQPeahSRNGA1+644YmdKAsb7uhy41UDRl+Ffk+UBiugmtIJ1UwebL3WK05/E5kQmt e0FgpQGGYiRlu/wuWS+upcjPzRo/KEPrqFXftML9a6NJw2gwQuq8ybTF4Hf1RlUxJfAY YCofypjnM0rrSC8pQ0qMbKc8l5i4lFRVFxiMMcvljNC5UIulGywa/jzT/TJC5O/QgIj0 tF0Ccj8C42JwnT/REe98VBm2rcVMpSt4lEWhidXsa/PABiFwo9hrnEJbsrCxrUdRN9de /9JxRzc+C+mClhTZtiUC0cAxUJqF90LHfRPAET67CX47HLB+cTt7nwocKuzhaKsUsBVY 4Rmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681560570; x=1684152570; 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=N3KXMf3LCMhF+M2dvABgEBrAeCcDHD/N5/gKopMor18=; b=PuQRCYE7d739Tq6iAYodZzbvUogHAy75BRpE/F6OYH40ldhvrb11QFJiY25GiPfOaE DjJESv0Erj8J1Y21QkGK1/l6XJxlVPGkQIKqFbRZAyd7GdDaOzcj4TSsLBKCb7R4Yoqy WlUe2/5UBj0tpqNu2BXn5iPSZbq7AjSeoYaOGvJ3Ky4f9k5Mz2DW1Evzm70mEwMbqy6Q VuaJNd/gJXUsJrT8dmNE7zDK47MG+rS+foWVOvKP5fS73rxeFIIzHSUd5GNr1GqtxAbW BvWCgedaG9caNPT9sGraQpsCUGXIG0tBmb69r2DMNQS5EoFOiMsj7v/Wi29W79E48c93 lltg== X-Gm-Message-State: AAQBX9cTm9H6KV7YKuwfxUXE/hlrRG+6JkFwY0qY2I1wHypo4r4FamiP SRmwvBZhQ/xidIvScZ67SUxDpwLj57cMkQ== X-Google-Smtp-Source: AKy350ZW9TkFIfQVYumPSBdggPeeuEhDPf7snltP+gAOWpvxGUiwgsz+5dP35izb+1pjtOjGL6ewjQ== X-Received: by 2002:a05:600c:229a:b0:3f0:a098:f503 with SMTP id 26-20020a05600c229a00b003f0a098f503mr6725468wmf.14.1681560569972; Sat, 15 Apr 2023 05:09:29 -0700 (PDT) Received: from lucifer.home ([2a00:23c5:dc8c:8701:1663:9a35:5a7b:1d76]) by smtp.googlemail.com with ESMTPSA id n16-20020a05600c3b9000b003dd1bd0b915sm10301859wms.22.2023.04.15.05.09.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Apr 2023 05:09:29 -0700 (PDT) From: Lorenzo Stoakes To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton Cc: Matthew Wilcox , David Hildenbrand , Lorenzo Stoakes Subject: [PATCH v3 4/7] mm/gup: introduce the FOLL_SAME_FILE GUP flag Date: Sat, 15 Apr 2023 13:09:27 +0100 Message-Id: <2feedd2bad6fd1ec4bc4639f9d9012c5ae2faf1f.1681558407.git.lstoakes@gmail.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This flag causes GUP to assert that all VMAs within the input range possess the same vma->vm_file. If not, the operation fails. This is part of a patch series which eliminates the vmas parameter from the GUP API, implementing the one remaining assertion within the entire kernel that requires access to the VMAs associated with a GUP range. Signed-off-by: Lorenzo Stoakes --- include/linux/mm_types.h | 2 ++ mm/gup.c | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 3fc9e680f174..84d1aec9dbab 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -1185,6 +1185,8 @@ enum { FOLL_PCI_P2PDMA =3D 1 << 10, /* allow interrupts from generic signals */ FOLL_INTERRUPTIBLE =3D 1 << 11, + /* assert that the range spans VMAs with the same vma->vm_file */ + FOLL_SAME_FILE =3D 1 << 12, =20 /* See also internal only FOLL flags in mm/internal.h */ }; diff --git a/mm/gup.c b/mm/gup.c index 9440aa54c741..3954ce499a4a 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -959,7 +959,8 @@ static int faultin_page(struct vm_area_struct *vma, return 0; } =20 -static int check_vma_flags(struct vm_area_struct *vma, unsigned long gup_f= lags) +static int check_vma_flags(struct vm_area_struct *vma, struct file *file, + unsigned long gup_flags) { vm_flags_t vm_flags =3D vma->vm_flags; int write =3D (gup_flags & FOLL_WRITE); @@ -968,7 +969,7 @@ static int check_vma_flags(struct vm_area_struct *vma, = unsigned long gup_flags) if (vm_flags & (VM_IO | VM_PFNMAP)) return -EFAULT; =20 - if (gup_flags & FOLL_ANON && !vma_is_anonymous(vma)) + if ((gup_flags & FOLL_ANON) && !vma_is_anonymous(vma)) return -EFAULT; =20 if ((gup_flags & FOLL_LONGTERM) && vma_is_fsdax(vma)) @@ -977,6 +978,9 @@ static int check_vma_flags(struct vm_area_struct *vma, = unsigned long gup_flags) if (vma_is_secretmem(vma)) return -EFAULT; =20 + if ((gup_flags & FOLL_SAME_FILE) && vma->vm_file !=3D file) + return -EFAULT; + if (write) { if (!(vm_flags & VM_WRITE)) { if (!(gup_flags & FOLL_FORCE)) @@ -1081,6 +1085,7 @@ static long __get_user_pages(struct mm_struct *mm, long ret =3D 0, i =3D 0; struct vm_area_struct *vma =3D NULL; struct follow_page_context ctx =3D { NULL }; + struct file *file =3D NULL; =20 if (!nr_pages) return 0; @@ -1111,10 +1116,13 @@ static long __get_user_pages(struct mm_struct *mm, ret =3D -EFAULT; goto out; } - ret =3D check_vma_flags(vma, gup_flags); + ret =3D check_vma_flags(vma, i =3D=3D 0 ? vma->vm_file : file, + gup_flags); if (ret) goto out; =20 + file =3D vma->vm_file; + if (is_vm_hugetlb_page(vma)) { i =3D follow_hugetlb_page(mm, vma, pages, vmas, &start, &nr_pages, i, @@ -1595,7 +1603,7 @@ long faultin_vma_page_range(struct vm_area_struct *vm= a, unsigned long start, * We want to report -EINVAL instead of -EFAULT for any permission * problems or incompatible mappings. */ - if (check_vma_flags(vma, gup_flags)) + if (check_vma_flags(vma, vma->vm_file, gup_flags)) return -EINVAL; =20 ret =3D __get_user_pages(mm, start, nr_pages, gup_flags, --=20 2.40.0 From nobody Thu Dec 18 07:50:40 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0E566C77B71 for ; Sat, 15 Apr 2023 12:10:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230233AbjDOMJ7 (ORCPT ); Sat, 15 Apr 2023 08:09:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230156AbjDOMJq (ORCPT ); Sat, 15 Apr 2023 08:09:46 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B24E59EDB; Sat, 15 Apr 2023 05:09:34 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-3f09ec7a5c6so3720935e9.2; Sat, 15 Apr 2023 05:09:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681560572; x=1684152572; 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=ogbzg8OyWbIWXrChHJ9Cs2MTyuvpbtikA67CTEycjjg=; b=caKhPvxuQxF4KgsYZ2h7A9kGXFx/HVLs5+b1E8jpXvmkRbh5hbUgTMIc9WSAuMO6Ly jTYLKrBLpZi6/0WhGV9z/aqQ5Pxo/3kkEAx3o+LVW213AtNMndeAAnq2g5hhIMMNJAzc yXOWEjtSbi7UQBtuH3VmDsWexLmGFjSvBTy3TKK9WAuFHpG8guRq7BRYyfoqhjPvcPX4 E6IJRhFlaRvWRGR4xIKyRL5K9ObYsekxLCXxEzjWNCldXy/01x2RhZ91qg1qnK3h4MY1 T5+DH4QohG0gqfmP8ZI1d2zSq8QDoh9utsJOmSxsduIK8KcT7x7c/F/RM7zxoi9YGKMW Ndlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681560572; x=1684152572; 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=ogbzg8OyWbIWXrChHJ9Cs2MTyuvpbtikA67CTEycjjg=; b=KhYIHx3Ou+MbjsF14MDcnid00WlMUrXTzVSP/LD0f2j9oGhxnBMSakUT/zbm9HGS12 OSVWXHUqxZAtIH8PvF8neC61Lxp+C/+GsuPiuhiybdnkXZXBYo9f3JuhCd2kZmvhxId8 Nta95tlcUmDtaoQFwaS1mdrG/qSlkxuheEkK6clTgmOrf9yel/4N/yZiW8c0e3roSpLd 7oMpg1a/UuJLddqMgzFDm02U8nu6/cfnSELZfWA8xdqOjkKnsgAgmUxJeqtogWBrKtLJ pdTG25T987Nes9siSRyhca/iDO5eNDL0CVBjuwpp5/daCF6FGXHU3hbO3LlNXw0vb+fg TGAA== X-Gm-Message-State: AAQBX9flledA/paRY5kobRbgEtZpzTH/Ng5tzyu/QkAKuoG1HT3PbEus npEyTCw5t7UMs2ha8RGakpE= X-Google-Smtp-Source: AKy350bwP6PWorDhaoLcU09MiqExRCfP6vqBOwGgiv4blXxkUTfR0MfB3ffsxDJBsvhcGMj8Lvo56w== X-Received: by 2002:adf:ec88:0:b0:2cf:2dcc:3421 with SMTP id z8-20020adfec88000000b002cf2dcc3421mr1382084wrn.5.1681560572590; Sat, 15 Apr 2023 05:09:32 -0700 (PDT) Received: from lucifer.home ([2a00:23c5:dc8c:8701:1663:9a35:5a7b:1d76]) by smtp.googlemail.com with ESMTPSA id x14-20020adfdd8e000000b002efb4f2d240sm999141wrl.87.2023.04.15.05.09.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Apr 2023 05:09:31 -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, Lorenzo Stoakes Subject: [PATCH v3 5/7] io_uring: rsrc: use FOLL_SAME_FILE on pin_user_pages() Date: Sat, 15 Apr 2023 13:09:30 +0100 Message-Id: X-Mailer: git-send-email 2.40.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Commit edd478269640 ("io_uring/rsrc: disallow multi-source reg buffers") prevents io_pin_pages() from pinning pages spanning multiple VMAs with permitted characteristics (anon/huge), requiring that all VMAs share the same vm_file. The newly introduced FOLL_SAME_FILE flag permits this to be expressed as a GUP flag rather than having to retrieve VMAs to perform the check. We then only need to perform a VMA lookup for the first VMA to assert the anon/hugepage requirement as we know the rest of the VMAs will possess the same characteristics. Doing this eliminates the one instance of vmas being used by pin_user_pages(). Signed-off-by: Lorenzo Stoakes Suggested-by: Matthew Wilcox (Oracle) --- io_uring/rsrc.c | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c index 7a43aed8e395..56de4d7bfc2b 100644 --- a/io_uring/rsrc.c +++ b/io_uring/rsrc.c @@ -1141,9 +1141,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 *npa= ges) { unsigned long start, end, nr_pages; - struct vm_area_struct **vmas =3D NULL; struct page **pages =3D NULL; - int i, pret, ret =3D -ENOMEM; + int pret, ret =3D -ENOMEM; =20 end =3D (ubuf + len + PAGE_SIZE - 1) >> PAGE_SHIFT; start =3D ubuf >> PAGE_SHIFT; @@ -1153,31 +1152,29 @@ struct page **io_pin_pages(unsigned long ubuf, unsi= gned long len, int *npages) if (!pages) goto done; =20 - vmas =3D kvmalloc_array(nr_pages, sizeof(struct vm_area_struct *), - GFP_KERNEL); - if (!vmas) - goto done; - ret =3D 0; mmap_read_lock(current->mm); - pret =3D pin_user_pages(ubuf, nr_pages, FOLL_WRITE | FOLL_LONGTERM, - pages, vmas); + pret =3D pin_user_pages(ubuf, nr_pages, + FOLL_WRITE | FOLL_LONGTERM | FOLL_SAME_FILE, + pages, NULL); if (pret =3D=3D nr_pages) { - struct file *file =3D vmas[0]->vm_file; + /* + * lookup the first VMA, we require that all VMAs in range + * maintain the same file characteristics, as enforced by + * FOLL_SAME_FILE + */ + struct vm_area_struct *vma =3D vma_lookup(current->mm, ubuf); + struct file *file; =20 - /* don't support file backed memory */ - for (i =3D 0; i < nr_pages; i++) { - if (vmas[i]->vm_file !=3D file) { - ret =3D -EINVAL; - break; - } - if (!file) - continue; - if (!vma_is_shmem(vmas[i]) && !is_file_hugepages(file)) { + if (WARN_ON_ONCE(!vma)) { + ret =3D -EINVAL; + } else { + /* don't support file backed memory */ + file =3D vma->vm_file; + if (file && !vma_is_shmem(vma) && !is_file_hugepages(file)) ret =3D -EOPNOTSUPP; - break; - } } + *npages =3D nr_pages; } else { ret =3D pret < 0 ? pret : -EFAULT; @@ -1194,7 +1191,6 @@ struct page **io_pin_pages(unsigned long ubuf, unsign= ed long len, int *npages) } ret =3D 0; done: - kvfree(vmas); if (ret < 0) { kvfree(pages); pages =3D ERR_PTR(ret); --=20 2.40.0 From nobody Thu Dec 18 07:50:40 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4CF5FC77B7D for ; Sat, 15 Apr 2023 12:10:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230099AbjDOMKD (ORCPT ); Sat, 15 Apr 2023 08:10:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230203AbjDOMJ4 (ORCPT ); Sat, 15 Apr 2023 08:09:56 -0400 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 251C25243; Sat, 15 Apr 2023 05:09:37 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-3f09a3c8bbbso1985085e9.0; Sat, 15 Apr 2023 05:09:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681560575; x=1684152575; 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=K8x3ikmaTJACOYzpIpbcvsaXlC6/cI+6Eg2IWvlQkq0=; b=s6CnqnzBZ6THc6cnIXQ9tFiKd6HkuMO7PzqDl5qYoVBPz6TLY1hkf210w8sOnAzrei v9NRZuqzkZm3ujvdTD4Q/xqsKFPfppKZJkMHKOw1AXAo0XZJ/iNVur/2UqE3Jlv29kyX WOn43QOaq8pv1V3qHMqN6IwqHfyZW68QFzHs6Q02KpmsgBu7UGSYRrSzvpVoPUtTl+Mh FXMcaHBNr48f9KhhS0WYsUzECx59vCwrezWsHbg5B0XWjTD0sne3p5XHAreuf1/PzvZU 3+QyOXL//9FA9+lL8VD4Lx7D8n+ic1FTN1z4dE6iaHk0DOWVvQ9otbUTysRkeHkeJynd 4YHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681560575; x=1684152575; 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=K8x3ikmaTJACOYzpIpbcvsaXlC6/cI+6Eg2IWvlQkq0=; b=HTDfjj++AwsLL5WAtuB31ot1KMCIeo4fq3CsmppmIUxX5aq5sxVQwSKswrg7IWFSAo mLAs+juZi2GV7BzbE8DF++daRC3EaSvNAFWAC8ifWeQl0Em7xlxac+TR2vWXdJqA8g4b LlHKi+qkz8bWhTe6vPiesENMSS4XPrmPvh7xzGB6j0io/9FCzSvcGqgEcNMAEzK90aEW jgp2D79936OkzGs8X7XVZwVlKskkIIDkCbvBQlSQuz3mJDX/7HqXrZAAHlAmgLtbP/ED 7ZIZIG8cSxiToW5/Uj76imEcBBCsEDOYs06pado0u4RNc+fjNZnZgAx3EThEA0Dg6FfC DlVw== X-Gm-Message-State: AAQBX9feUpSUZXvsGfhYPOCtwn7JNebkpx3wOJ3675H5UbiJnMs4qbiY OccfnP+Oby646pqGJlv4ftg6hpzTiwvqrA== X-Google-Smtp-Source: AKy350YomYNfdZqxeUoplG58e3G8aFqN6nmBy7aau2fgnqPuY2DvZIwHvG83m+klTmm1CrIhE9BoRQ== X-Received: by 2002:a5d:6a42:0:b0:2f2:3a72:1cfa with SMTP id t2-20020a5d6a42000000b002f23a721cfamr1388788wrw.15.1681560575329; Sat, 15 Apr 2023 05:09:35 -0700 (PDT) Received: from lucifer.home ([2a00:23c5:dc8c:8701:1663:9a35:5a7b:1d76]) by smtp.googlemail.com with ESMTPSA id t5-20020adfeb85000000b002e71156b0fcsm5651091wrn.6.2023.04.15.05.09.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Apr 2023 05:09:34 -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, Lorenzo Stoakes Subject: [PATCH v3 6/7] mm/gup: remove vmas parameter from pin_user_pages() Date: Sat, 15 Apr 2023 13:09:32 +0100 Message-Id: X-Mailer: git-send-email 2.40.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" After the introduction of FOLL_SAME_FILE we no longer require vmas for any invocation of pin_user_pages(), so eliminate this parameter from the function and all callers. This clears the way to removing the vmas parameter from GUP altogether. Signed-off-by: Lorenzo Stoakes Acked-by: David Hildenbrand Acked-by: Dennis Dalessandro --- 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/book3s6= 4/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, uns= igned long ua, =20 ret =3D pin_user_pages(ua + (entry << PAGE_SHIFT), n, FOLL_WRITE | FOLL_LONGTERM, - mem->hpages + entry, NULL); + mem->hpages + entry); if (ret =3D=3D n) { pinned +=3D n; continue; diff --git a/drivers/infiniband/hw/qib/qib_user_pages.c b/drivers/infiniban= d/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 =3D 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, siz= e_t size, int writable, ret =3D pin_user_pages(cur_base, min_t(unsigned long, npages, PAGE_SIZE / sizeof(struct page *)), - gup_flags, page_list, NULL); + gup_flags, page_list); =20 if (ret < 0) goto out; diff --git a/drivers/infiniband/sw/siw/siw_mem.c b/drivers/infiniband/sw/si= w/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 =3D plist; while (nents) { rv =3D pin_user_pages(first_page_va, nents, foll_flags, - plist, NULL); + plist); if (rv < 0) goto out_sem_up; =20 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 videobu= f_dmabuf *dma, data, size, dma->nr_pages); =20 err =3D pin_user_pages(data & PAGE_MASK, dma->nr_pages, gup_flags, - dma->pages, NULL); + dma->pages); =20 if (err !=3D dma->nr_pages) { dma->nr_pages =3D (err >=3D 0) ? err : 0; diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vd= use_dev.c index 0c3b48616a9f..1f80254604f0 100644 --- a/drivers/vdpa/vdpa_user/vduse_dev.c +++ b/drivers/vdpa/vdpa_user/vduse_dev.c @@ -995,7 +995,7 @@ static int vduse_dev_reg_umem(struct vduse_dev *dev, goto out; =20 pinned =3D pin_user_pages(uaddr, npages, FOLL_LONGTERM | FOLL_WRITE, - page_list, NULL); + page_list); if (pinned !=3D npages) { ret =3D pinned < 0 ? pinned : -ENOMEM; goto out; diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c index 7be9d9d8f01c..4317128c1c62 100644 --- a/drivers/vhost/vdpa.c +++ b/drivers/vhost/vdpa.c @@ -952,7 +952,7 @@ static int vhost_vdpa_pa_map(struct vhost_vdpa *v, while (npages) { sz2pin =3D min_t(unsigned long, npages, list_size); pinned =3D pin_user_pages(cur_base, sz2pin, - gup_flags, page_list, NULL); + gup_flags, page_list); if (sz2pin !=3D pinned) { if (pinned < 0) { ret =3D pinned; diff --git a/include/linux/mm.h b/include/linux/mm.h index 1bfe73a2b6d3..363e3d0d46f4 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2382,8 +2382,7 @@ long pin_user_pages_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 56de4d7bfc2b..bd45681de660 100644 --- a/io_uring/rsrc.c +++ b/io_uring/rsrc.c @@ -1156,7 +1156,7 @@ struct page **io_pin_pages(unsigned long ubuf, unsign= ed long len, int *npages) mmap_read_lock(current->mm); pret =3D pin_user_pages(ubuf, nr_pages, FOLL_WRITE | FOLL_LONGTERM | FOLL_SAME_FILE, - pages, NULL); + pages); if (pret =3D=3D nr_pages) { /* * lookup the first VMA, we require that all VMAs in range diff --git a/mm/gup.c b/mm/gup.c index 3954ce499a4a..714970ef3b30 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -3132,8 +3132,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. @@ -3142,15 +3140,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 =3D 1; =20 - 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); =20 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 =3D pin_user_pages(addr, nr, gup->gup_flags, pages + i, - NULL); + nr =3D pin_user_pages(addr, nr, gup->gup_flags, pages + i); break; case PIN_LONGTERM_BENCHMARK: nr =3D 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 =3D pin_user_pages(addr, nr, gup->gup_flags, - pages + i, NULL); + pages + i); else nr =3D 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 =3D pin_user_pages(addr, remaining_pages, - gup_flags, pages, NULL); + gup_flags, pages); if (cur_pages < 0) { pin_longterm_test_stop(); ret =3D 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, un= signed long address) =20 mmap_read_lock(current->mm); npgs =3D 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); =20 if (npgs !=3D umem->npgs) { --=20 2.40.0 From nobody Thu Dec 18 07:50:40 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4E9AEC77B71 for ; Sat, 15 Apr 2023 12:10:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230213AbjDOMKO (ORCPT ); Sat, 15 Apr 2023 08:10:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230164AbjDOMJ6 (ORCPT ); Sat, 15 Apr 2023 08:09:58 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA61961B9 for ; Sat, 15 Apr 2023 05:09:39 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-3f09ec7a5c6so3721125e9.2 for ; Sat, 15 Apr 2023 05:09:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681560578; x=1684152578; 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=uCs/sZPWJX1gtmxe2QOizxEtYJfYeMRPWTDbu9h9OZw=; b=YiAIwHkEdr1/ZOqe4wrEnjAkwubUYyEEsIgZJmhmGfHlK0LKA53CcITGmXAghMQBuz 6MRaBAU4wGJycNw7yeijfstj6n9tZPM2lh9Cywavhxrkhfw7TcyV4hZ22Y7J+qTNZ056 LTQzBaMljW/5rTInhGkr/FyQne/l2VdWGonxsOZEpVVOo8HWpqx+T82g+AJotzXhUID2 6KX1iDN6jZqcoVqLiJceQkLrDr8d009jVLk4taTeTmD7nll7Oaz2v1IrIw28a4UR6rZs 1Fw2fsLN4dHsXX19tJ1xX4DQJRFRvi54ASHGEqFMM2Lo2jtrFl5LOSrd5TEoi32AUHDN POEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681560578; x=1684152578; 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=uCs/sZPWJX1gtmxe2QOizxEtYJfYeMRPWTDbu9h9OZw=; b=cJFV2oiocb7pdUQ0vHN5wNS53Pl1+cZkwH7Zwah50HnLL5iy7iVu+LwRah8i1wrjvU oVRuYN1AcRTVH14kxAEDAPpON2trC3wIUc39A2mYixNkmGwrQnSYoEoFBzT15RIYu0uT gf4lF6h2SfmbyM/l4JBy1102y4BjE/lbjIUYG8A/usr0t0g/4oE4eSYLDn0CpHTq74tS b2Gtj4QrKlT3QQ5pMSp/oswQgFI3pAwzEdfbum5UDsSPi99j8/8PjOsNFIzaA05dIJjD B+QWImmYJeUJg8+GtYfLxk8D3JO8SGXs/z5RFqHLhiTY17Om2ZcLxLBMPytxpMiPRqVN EDFA== X-Gm-Message-State: AAQBX9ejRx58qBPnfmZ8LrGjptlOZxKYRymyG2pxzKh3O+ofXbJOsdQt i32guXkPDlBE3GD/YNvy2mc= X-Google-Smtp-Source: AKy350ZY0kxE6Dj9vHHELAdPslsinf/e7e/CwaX0yrhE9WGneZun20b+Rt4XRweObiUEpVFsW7zlKw== X-Received: by 2002:adf:efd0:0:b0:2db:bdc2:f8da with SMTP id i16-20020adfefd0000000b002dbbdc2f8damr1451812wrp.71.1681560577772; Sat, 15 Apr 2023 05:09:37 -0700 (PDT) Received: from lucifer.home ([2a00:23c5:dc8c:8701:1663:9a35:5a7b:1d76]) by smtp.googlemail.com with ESMTPSA id z12-20020a5d440c000000b002f5fa5fb793sm5487919wrq.60.2023.04.15.05.09.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Apr 2023 05:09:36 -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 , Lorenzo Stoakes Subject: [PATCH v3 7/7] mm/gup: remove vmas array from internal GUP functions Date: Sat, 15 Apr 2023 13:09:35 +0100 Message-Id: <217d9369b15d657128746beeaf6d65c03214df42.1681558407.git.lstoakes@gmail.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Lorenzo Stoakes Acked-by: David Hildenbrand --- 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 28703fe22386..2735e7a2b998 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -141,9 +141,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); @@ -297,9 +296,8 @@ static inline struct page *hugetlb_follow_page_mask(str= uct vm_area_struct *vma, =20 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 714970ef3b30..385e428a4acb 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -1028,8 +1028,6 @@ static int check_vma_flags(struct vm_area_struct *vma= , struct file *file, * @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 @@ -1043,8 +1041,6 @@ static int check_vma_flags(struct vm_area_struct *vma= , struct file *file, * * 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 @@ -1080,7 +1076,7 @@ static int check_vma_flags(struct vm_area_struct *vma= , struct file *file, 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 =3D 0, i =3D 0; struct vm_area_struct *vma =3D NULL; @@ -1124,9 +1120,9 @@ static long __get_user_pages(struct mm_struct *mm, file =3D vma->vm_file; =20 if (is_vm_hugetlb_page(vma)) { - i =3D follow_hugetlb_page(mm, vma, pages, vmas, - &start, &nr_pages, i, - gup_flags, locked); + i =3D follow_hugetlb_page(mm, vma, pages, + &start, &nr_pages, i, + gup_flags, locked); if (!*locked) { /* * We've got a VM_FAULT_RETRY @@ -1191,10 +1187,6 @@ static long __get_user_pages(struct mm_struct *mm, ctx.page_mask =3D 0; } next_page: - if (vmas) { - vmas[i] =3D vma; - ctx.page_mask =3D 0; - } page_increm =3D 1 + (~(start >> PAGE_SHIFT) & ctx.page_mask); if (page_increm > nr_pages) page_increm =3D nr_pages; @@ -1349,7 +1341,6 @@ static __always_inline long __get_user_pages_locked(s= truct mm_struct *mm, unsigned long start, unsigned long nr_pages, struct page **pages, - struct vm_area_struct **vmas, int *locked, unsigned int flags) { @@ -1387,7 +1378,7 @@ static __always_inline long __get_user_pages_locked(s= truct mm_struct *mm, pages_done =3D 0; for (;;) { ret =3D __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 =3D ret; @@ -1451,7 +1442,7 @@ static __always_inline long __get_user_pages_locked(s= truct mm_struct *mm, =20 *locked =3D 1; ret =3D __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 !=3D 0); @@ -1549,7 +1540,7 @@ long populate_vma_page_range(struct vm_area_struct *v= ma, * not result in a stack expansion that recurses back here. */ ret =3D __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; } @@ -1607,7 +1598,7 @@ long faultin_vma_page_range(struct vm_area_struct *vm= a, unsigned long start, return -EINVAL; =20 ret =3D __get_user_pages(mm, start, nr_pages, gup_flags, - NULL, NULL, locked); + NULL, locked); lru_add_drain(); return ret; } @@ -1675,8 +1666,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 st= art, 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 =3D false; @@ -1720,8 +1710,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] =3D vma; + start =3D (start + PAGE_SIZE) & PAGE_MASK; } =20 @@ -1902,8 +1891,7 @@ struct page *get_dump_page(unsigned long addr) int locked =3D 0; int ret; =20 - ret =3D __get_user_pages_locked(current->mm, addr, 1, &page, NULL, - &locked, + ret =3D __get_user_pages_locked(current->mm, addr, 1, &page, &locked, FOLL_FORCE | FOLL_DUMP | FOLL_GET); return (ret =3D=3D 1) ? page : NULL; } @@ -2076,7 +2064,6 @@ static long __gup_longterm_locked(struct mm_struct *m= m, unsigned long start, unsigned long nr_pages, struct page **pages, - struct vm_area_struct **vmas, int *locked, unsigned int gup_flags) { @@ -2084,13 +2071,13 @@ static long __gup_longterm_locked(struct mm_struct = *mm, long rc, nr_pinned_pages; =20 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); =20 flags =3D memalloc_pin_save(); do { nr_pinned_pages =3D __get_user_pages_locked(mm, start, nr_pages, - pages, vmas, locked, + pages, locked, gup_flags); if (nr_pinned_pages <=3D 0) { rc =3D nr_pinned_pages; @@ -2108,9 +2095,8 @@ static long __gup_longterm_locked(struct mm_struct *m= m, * 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 =3D *gup_flags_p; =20 @@ -2152,13 +2138,6 @@ static bool is_valid_gup_args(struct page **pages, s= truct vm_area_struct **vmas, (gup_flags & FOLL_PCI_P2PDMA))) return false; =20 - /* - * 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 =3D gup_flags; return true; } @@ -2227,11 +2206,11 @@ long get_user_pages_remote(struct mm_struct *mm, { int local_locked =3D 1; =20 - 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; =20 - 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); } @@ -2266,11 +2245,11 @@ long get_user_pages(unsigned long start, unsigned l= ong nr_pages, { int locked =3D 1; =20 - 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; =20 return __get_user_pages_locked(current->mm, start, nr_pages, pages, - NULL, &locked, gup_flags); + &locked, gup_flags); } EXPORT_SYMBOL(get_user_pages); =20 @@ -2294,12 +2273,12 @@ long get_user_pages_unlocked(unsigned long start, u= nsigned long nr_pages, { int locked =3D 0; =20 - 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; =20 return __get_user_pages_locked(current->mm, start, nr_pages, pages, - NULL, &locked, gup_flags); + &locked, gup_flags); } EXPORT_SYMBOL(get_user_pages_unlocked); =20 @@ -2982,7 +2961,7 @@ static int internal_get_user_pages_fast(unsigned long= start, start +=3D nr_pinned << PAGE_SHIFT; pages +=3D nr_pinned; ret =3D __gup_longterm_locked(current->mm, start, nr_pages - nr_pinned, - pages, NULL, &locked, + pages, &locked, gup_flags | FOLL_TOUCH | FOLL_UNLOCKABLE); if (ret < 0) { /* @@ -3024,7 +3003,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; =20 @@ -3057,7 +3036,7 @@ int get_user_pages_fast(unsigned long start, int nr_p= ages, * 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); } @@ -3082,7 +3061,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); } @@ -3115,10 +3094,10 @@ long pin_user_pages_remote(struct mm_struct *mm, { int local_locked =3D 1; =20 - 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); } @@ -3144,10 +3123,10 @@ long pin_user_pages(unsigned long start, unsigned l= ong nr_pages, { int locked =3D 1; =20 - 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); =20 @@ -3161,11 +3140,11 @@ long pin_user_pages_unlocked(unsigned long start, u= nsigned long nr_pages, { int locked =3D 0; =20 - 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; =20 - 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 a08fb47fb200..85138a0394b9 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -6371,17 +6371,14 @@ int hugetlb_mfill_atomic_pte(pte_t *dst_pte, } #endif /* CONFIG_USERFAULTFD */ =20 -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; =20 for (nr =3D 0; nr < refs; nr++) { if (likely(pages)) pages[nr] =3D nth_page(page, nr); - if (vmas) - vmas[nr] =3D vma; } } =20 @@ -6454,9 +6451,9 @@ struct page *hugetlb_follow_page_mask(struct vm_area_= struct *vma, } =20 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 =3D *position; @@ -6584,7 +6581,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 >=3D pages_per_huge_page(h))) { vaddr +=3D huge_page_size(h); @@ -6599,11 +6596,10 @@ long follow_hugetlb_page(struct mm_struct *mm, stru= ct vm_area_struct *vma, refs =3D min3(pages_per_huge_page(h) - pfn_offset, remainder, (vma->vm_end - ALIGN_DOWN(vaddr, PAGE_SIZE)) >> PAGE_SHIFT); =20 - 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); =20 if (pages) { /* --=20 2.40.0