From patchwork Tue Apr 18 15:49:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13215860 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 A0647C6FD18 for ; Tue, 18 Apr 2023 15:49:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2C9F18E0006; Tue, 18 Apr 2023 11:49:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 27A488E0001; Tue, 18 Apr 2023 11:49:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0F3A78E0006; Tue, 18 Apr 2023 11:49:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 016348E0001 for ; Tue, 18 Apr 2023 11:49:09 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 819E51603A4 for ; Tue, 18 Apr 2023 15:49:09 +0000 (UTC) X-FDA: 80694945618.04.B551CC3 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) by imf14.hostedemail.com (Postfix) with ESMTP id 8D4CF100016 for ; Tue, 18 Apr 2023 15:49:07 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=OiQvNtaq; spf=pass (imf14.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.41 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=1681832947; 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=zNGggXBj/YjGZ6A1qh5gK0cjgPin4WDFdJ7XH94R/L0=; b=k3uIHDDxv/atEag2fTmyDPRtz9RAcIVq/z78G62sIk/3OJISMAB7limrp+lWKR0C+u7ura 8bk4Lx+uf0we0oaxJALCEW2NnY2th1FQ4hOs+vdZ+YkEqk6dXi0S7w8v5Ny+LRmqAGAd2F ihkZ1Z9Hy3uZrwSbWe8lk2YVU0XnFuE= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=OiQvNtaq; spf=pass (imf14.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.41 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=1681832947; a=rsa-sha256; cv=none; b=zgZpcYgOM9iFK5NNoByHGA5sdLs4xaIZfH/pNHZougXyXYWanEVlmDTAznKRPJnEpqeIFT yfDiqp+DL0q+DLiWrdLtwx7lfu9LtOnxFm36oDULxYVBGS0pLGaZuemg+9dl71zsWM/ZH/ sBcaj25awSHQB3LUvaaJLoOXri1pBkI= Received: by mail-wm1-f41.google.com with SMTP id v3so2733389wml.0 for ; Tue, 18 Apr 2023 08:49:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681832945; x=1684424945; 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=zNGggXBj/YjGZ6A1qh5gK0cjgPin4WDFdJ7XH94R/L0=; b=OiQvNtaqgJRCAYJ8jvAV8Xh4/ZhOEeIv/7kqlcQP7y77S10eRaMu/KoKTTn10guuJx +g9qM3hN+0NgWuLJJ2gFxsXY0TzW/PmfC8yv55989lJVOFi1c9Ss8OguqvqnEZrWL3Lo nhP8qL16xIQKQK7tChr0XkG3WJ/Ls3sJK1RDELyqSOuMYP7WgNHJI+/TgUfi+vgT9QNm B4IzhlNPq8bcnHxV0WZTnO22pTjwgEarf6cgrYriGpwClEEM11Zepaxamd43fYa7opWd gq5ASY0R6rj9Dc6bwpOO4hUJ7lTQSuwSu6fENmYXJ9glcRpzzYFs/2VjTUCah8x/baBI XbEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681832945; x=1684424945; 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=zNGggXBj/YjGZ6A1qh5gK0cjgPin4WDFdJ7XH94R/L0=; b=EkO5kTYyCQB8AKvEg9aJDvuMExUHxqtdJRPgR9ZTGmCU0TfaUWtVKmedDmcTTVq/8y tL7b921IO/h5796RDPrT/D3nO+37krAbHN0eOd8/aVQ6fxj5/cron47okn/jHczV3Fiy 4RZIJMOMGnfiNZlXdvf+7Nphoji7IIRyqx9YBZmRVYd7MoJS8BCQBOG9llKLGBVVaOQe pN0gbN9Jnb7GfU29XMMMpfRMEx4c7PgFd3FvOn/Nl97AHVyLlTCP/uGGxAv1l3mlWrTS 8WqbHvEP0vV1FxJdzOZlXFlv+mKkVaKR1yl7WBUntUaEp71tKfrI9LULzt9le8YseNdo I7iw== X-Gm-Message-State: AAQBX9eN44DOjUeJDl7qBFBouZXdo3Rh68CFCEOPW/R4DrIlzDQSK/Bc Wv1sjIHn6TjaX/IYQ2vaYBBLzqqzEg3FyQ== X-Google-Smtp-Source: AKy350aHDRRWyxYtdICupSbabDM0SYNg7JwpwlKjL5bja7KYaQer4ZpvTkwbrAwjYCA1wLTr85S01Q== X-Received: by 2002:a05:600c:22c4:b0:3ed:88f5:160a with SMTP id 4-20020a05600c22c400b003ed88f5160amr14355036wmg.11.1681832945586; Tue, 18 Apr 2023 08:49:05 -0700 (PDT) Received: from lucifer.home (host86-156-84-164.range86-156.btcentralplus.com. [86.156.84.164]) by smtp.googlemail.com with ESMTPSA id 26-20020a05600c021a00b003f17848673fsm2934468wmi.27.2023.04.18.08.49.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Apr 2023 08:49:04 -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 , Jason Gunthorpe Subject: [PATCH v4 1/6] mm/gup: remove unused vmas parameter from get_user_pages() Date: Tue, 18 Apr 2023 16:49:01 +0100 Message-Id: X-Mailer: git-send-email 2.40.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 8D4CF100016 X-Stat-Signature: 4q359kj314ebhtz49ba6z8cr6isch5nm X-Rspam-User: X-HE-Tag: 1681832947-366938 X-HE-Meta: U2FsdGVkX1+viEikfn2rBtOfMWhFSJHBV+R1ASl+0QqjqI/bzztSU91OIl9O7+F1CJT4PYGcpzD+DIe+5G9lWvgCNyNpEjzl9YvAv8PP1k9QmA/5SwIEm4ZdllYRujjhPabnabN0atTUb/EmEuflrrGbyc2D8WuwFFSiv9Mp7JjU4CQJe5dInR/03gtlq+4uLCD7X2F/7H3IvQtzLAXjIKSoze6pO4URVO/WBfp4sKo3k/jWAYdP9u34l72IW60TUOeavzCbhnwqeVtDOVswIFRk3reb7KpKmlrz9sGF3CPKGB1M5fi3ZFNMHgPaOoY/v2+PPiSGWWe1Iu5a2js3GDsmObYDpX1gLguSSWYFFUXYKJbMjLl8DX4qZSQHGNKg0TeTTVCIIVqbtzCwRwzV/DO+nIqh/10RERfZkIeylalS7kbef/CNmOgC7lIfAYmqFA9wDoLmQFZGAwFFEUIabT7FPtfkLfpWnhyF+5czfSDQK7wBpl0f4vuSyNYMavgaO5B+t8mYK4rQ7vfOLmgv723WkE4iQI/e9BKLsRcZihFMlK+Gddz4yvVTZJ4gP1HEhh4OwItAiIZqNW1sM7KWCAwitP3eXDzC2nvHGOsp5YxfHWkr2tfaGPSErWTEu1b3upF31WQKh6D9RjiwV2exogAc9BZSprgBp+72L75YjYc9mC5bWTgqOKN2xcjqNQJfuMup2Tvn67yvrurzYYSX5XTNSwKCeIYqHY7w04tDe3ZTdqVJ346xm0RJeWpWgLP67uHp9ljbTMmokvI4BUQs6O6DgQYz6pp5a3AmZmgc9PN3JIihoElcOvwPVQKQkn1773ajNcpkuO6QFp4HI4urzEG2HYqd53jyQ3uvF32PoQXjH9MpSDozOWrQMyfDAXuGl6jd2+6xHXwEVBIl1z+QDxHiOOeN1TcWG+rHv7mr1iWQbyt3LpGA9V68YlJ/ehij2HMDJ6vJjCRmeZ5Fb6i JpgO9SQH EnxOftjmBRJ6vYXUyNkMHHIwQO0kW2xvwkW1tVErCOEoeedsf5dmiJJs1PRa16taBEIVZlhGxwm/M/6Q0WpSYC7qmz7xujubsjv9+2E3KktI0CKHEWUeOMWtK//hkIk593E3ToItkhP2LtEv9+WvII5VmAP43hcTWXTqLrkhvWelyo8LBTFGPikUhPWsJh4Cv4vwpbajwJ7O2yTXmV0v0fi2M4WxzMB5Qv2tTpodwq3akd+JRJCrdinNuK1/xvyF6vg0nZAkYRFkATZCmIBPeO4MKmUwmrF9uFMeCNr3HWL+JyLM8F17KC3Nd11YZyICkfR32PD8vaDlNTY9NA4pyrYUY7Hyooz0m00dk+YsUWvL2wKGpwnqzGMNDnAsR8swUdGIU7A1BpNhnTHIo58mB6YZIE2Q9pI0UHLyf7U97kYC0aHXjtdcb5s6hJKuGGDpYEAY11KsGr6W38htJFYdpDz1PH6eRvvAIW+KehBP5+WW/Hfuf8Bz9sGRf5Nd2N4bcGyfxzt7c7vTGRvwFttpHN1hDrh45QxqnliPbh+a2ldcMX4y30UYoaf7AScNG0ytSGiMewr/1CozBugULA2Jthxkc7itZWTx8AhMJCwUcxtXRUnoiy4umIV+ssl9pftoADmnP4YWL1nZv/qfaNGSAtVVqc+Am9QrB/tWRdzXbThgtxdw= 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() 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. Suggested-by: Matthew Wilcox (Oracle) Acked-by: Greg Kroah-Hartman Acked-by: David Hildenbrand Reviewed-by: Jason Gunthorpe Signed-off-by: Lorenzo Stoakes Acked-by: Christian König for the radeon parts. Acked-by: Jarkko Sakkinen --- 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 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 = 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 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 belongs 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 = 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 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 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 Tue Apr 18 15:49:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13215861 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 C8793C77B7E for ; Tue, 18 Apr 2023 15:49:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 625538E0007; Tue, 18 Apr 2023 11:49:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5AE1F8E0001; Tue, 18 Apr 2023 11:49:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 44F0B8E0007; Tue, 18 Apr 2023 11:49:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 36D8A8E0001 for ; Tue, 18 Apr 2023 11:49:12 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 106E41A037B for ; Tue, 18 Apr 2023 15:49:12 +0000 (UTC) X-FDA: 80694945744.08.0C1EDF2 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) by imf08.hostedemail.com (Postfix) with ESMTP id 249D0160019 for ; Tue, 18 Apr 2023 15:49:09 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=J+hC8F71; spf=pass (imf08.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.46 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=1681832950; 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=NPDSA+x4oz9imX3uiByE603i/j50qlmE+SnCawov5Gk=; b=ovu2Y4boOzffHh6Dy5QuGcMI8ndQ/1NrlQno1FSgxRWetki/+kOVpxRpMSSU79tOrP7HfG 1LTMaIskGAk0PLh7t9K7ehDYfcr4Bz04R7O0fUMI3qW1e+yHtEvT98QRiiwb8GB0haC8V+ jjAQ/uYD9IB+g+NWDdsIwNJhZFs9qcM= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=J+hC8F71; spf=pass (imf08.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.46 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=1681832950; a=rsa-sha256; cv=none; b=FT7Zp7v5dIGcZdpFc8I6j8lxIHtPTVvVvbtctduYGNSRteSyvyjruqUgbwsOn9y4Okr2d5 dZNgoT0MnM9zPCVLECGo4kf5ZdECc5TU77B0x2WDvsR6Lcqb1yxLTHEcOFOxR+LQdcQ/0c bMT6XHuke/5PJp2egsa7ZoDc3h5g+48= Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-3f09b4a1584so18211225e9.2 for ; Tue, 18 Apr 2023 08:49:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681832948; x=1684424948; 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=NPDSA+x4oz9imX3uiByE603i/j50qlmE+SnCawov5Gk=; b=J+hC8F71kco8Juht/1xZ6HvwdaZ1yKC/66ZDQkDWwb6JRvwGxhNRTSXnHHz42bMO25 DmuRwo9hXxa4Kcc+fn0Bc7/oB557sS2XTIiHyGcE56cNznhhujRB3aVvEU0i/VqEHHSN 4QQBvP+edSPhv2Q/URS3BYuFpezdoIpB65jUr4OluO2ZqtdoK/GzsDzTDVHPTG+yfsLM UnejDVErRWK6ELXtmYEklX4B8FWPaFJvA4bkW48mkxb9pTwpbAO7dtiwxsqhXil0ddt+ fMBxrFS7p6BsoAX4kPiFEgZHEnWVhrX5x3Cprq2UOwpQyBDI2OPIJz4zPj/LDfgyljp9 CSLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681832948; x=1684424948; 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=NPDSA+x4oz9imX3uiByE603i/j50qlmE+SnCawov5Gk=; b=lG1qTce6JaN5I6p2HB4H3mCqzhbHjnbExgKln4G7PY2xXhZBIMB6QiFi1pcMPl7KK+ DvJo7I/fDR2IMVArvCIwVf45S9WOzVfXnTvk3WzwxOeZtWveExK3lfdXvIgucpQE5AVu ri5XsB0Du/4NcrZIiAHyrHg+cpKQTo4fDlfYy8d615lsNCiFPsaO+q87WLcRz2bOfUw0 ZUzFKt1/PrW439hhEzLjELfItlqRVbsisZUwKZ02gU79l8JifFKVClExYZ/yAJhPa1nu EmV08j3S8gaOMnS7Vj04c/YHXoMv2ufMctwVGraGQbxrKaBuuwfN5iTKtA4wRYdgUEm6 V3AA== X-Gm-Message-State: AAQBX9dZG+dyER9A1eYW1CdMv05DXCpQvmK+sn4gLqBN6PafMo/ybm6H d4dZr8MBmeHAaP2S20nwxYEXzcCROBYLrw== X-Google-Smtp-Source: AKy350YiLSJ7u9SiqFEKwv2I6butZKhidTn4j0OJ/5851Zru7xsHmoegW+XNWDQ016eO2V5AEiXTdQ== X-Received: by 2002:adf:dbce:0:b0:2f9:5841:a4d4 with SMTP id e14-20020adfdbce000000b002f95841a4d4mr2063234wrj.27.1681832948536; Tue, 18 Apr 2023 08:49:08 -0700 (PDT) Received: from lucifer.home (host86-156-84-164.range86-156.btcentralplus.com. [86.156.84.164]) by smtp.googlemail.com with ESMTPSA id p11-20020a5d458b000000b002efb31d3c24sm13352583wrq.32.2023.04.18.08.49.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Apr 2023 08:49:07 -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 , Jason Gunthorpe Subject: [PATCH v4 2/6] mm/gup: remove unused vmas parameter from pin_user_pages_remote() Date: Tue, 18 Apr 2023 16:49:05 +0100 Message-Id: X-Mailer: git-send-email 2.40.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 249D0160019 X-Stat-Signature: hbadmst48cohddc3gztguhpnawgw1x8o X-HE-Tag: 1681832949-5457 X-HE-Meta: U2FsdGVkX18Ze97sR4BAGEQbvosV+IZeK7jvip6QV951Ytmy37TfuR2GYTvmg2h++3K295Yup4nJpyl4RWytloDyoA0YyCv7j1dW4DMntSiBNB5tpDJIbCb8Q5yGd0yVX+QQM7RlajeGgikC013VQOEVWWwN5I05F5zG9QXjNR8HA1lo2Tp6a0WEibW8hUQQdBUhA4bWDDM6DGPXlCcrc/BoCrriVcmlOxt5EfQUjHh1itOCRhFvdZ2KDDbepqBK7iladsRFSGqJlcddVOrgSrppA6BTJSSe8rg96j14uKO9MiexVPvkypTr6+fczdPBAaduYsrp9CsnyAyKDmf1s1EuAcGbam0g4IPxVBpYd0Xdmx3r6KyqedyDVdlNRyAwY2lpHUezQ3B6Zwwb00zgy2qFgSQdFhlfCWh/xPB30ynWGp5CVuVd/OEp/3fXIp+yCf1ksx1nkomfon0k/3mZeyo2r4qqBzwwDHqOmXk0Oojk2g2LXV2/NvYqUHgdPDCO0hwdYPQac3qS7tr7KkI1UtNQhNVXIpoJ0vJy0KK1KUIk4lZUL/sPd92+39uGXAT5ZmSLxWgNLKIsXSDxAMv81AacgtrrTCbkaxOjnEVagcSblC09KSulD/Wq+qUzIN/vn0R9Dbq9+PydzSC4nkavO5ksGNqzLrN4v4V+YxOz/0/kysRTul6g6Q4vmKYi+jgaBG4vS31hFVZtoLmMn8FIwGM8RkSxs34xyskoURsENks8z/ob3XP/uaUfuBfjeSsaznxyw/cW/+Ck2ragA1EmkL+ubdPeLjo8fTVA3/3lmsb1W1ZS4JxZBhspoa+J8UXKqofhClrX9qflMMCyJ3rz6iko/vd1JttaTgeWTCcOMSlV5n2nzuAHnWK+B8y4oM/PdkJK6VP3dmO0N06OJ/G6Ejkdr4ax3SBvL0WU+LpPdRKL8JjyzkSW8D1lQLjgC8HOPTxvQyUaGnYZ4BX/j0U GEQWpWHO i0nCzMeTOZz0P6NFoWs2BH8m9+lc2jCY+4oGfQt+JoFzIOGs9hKe3jNCzZ9sx5RJ9HVE6ZcSVHpZ7r2xDBAGz1rdyu0qruHDz1DIfRFlKS8ODP19OVyDEmFq1HICkRJ6HLXrVItUWLD2b59xUwkOB7F5hLpWT+zOrp3wD3OImKsNaryQHn9++HiQ6J6zKRjgOz6RixLrz4fk4p8LYtWbOQ0zuxZ7vojNhzeABOQxQDHeaqaMq8Xl8tARBBespvg+dAy1umgTrwqu3caZxTZDuQSTOEz8doIEGSpNukEUsC7jc3P/bFaiY5j/N19LnPtzE0WiJEhzM93cQgAETU6aLFRKfTA2DL4e5T0ijMAnOk08QAlXUeDSfSq7putXii0ipr812ncnTmJ0volQWuo5gC4or6VLtCt5jdI1APYIt5CR/nbhbaNvLfujlUwTOcfCmp5RuT8/iSUEktbioAw3EM65Zu6oo/E2MrzZGCSoEZmGQ9Im1NYQs6uki9xmda/vYxEo3oII3jE6ispZdEma9uzAkjyun0cXzJEWE1HwXI+SL5BYv20mKwMEcCg== 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 --- 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 = 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) { @@ -1787,7 +1787,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 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, 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 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 = 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 Tue Apr 18 15:49:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13215867 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 D0553C77B7D for ; Tue, 18 Apr 2023 15:49:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6C1918E0008; Tue, 18 Apr 2023 11:49:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 64A678E0001; Tue, 18 Apr 2023 11:49:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4C50D8E0008; Tue, 18 Apr 2023 11:49:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 3C8098E0001 for ; Tue, 18 Apr 2023 11:49:17 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id DDCD7A0375 for ; Tue, 18 Apr 2023 15:49:16 +0000 (UTC) X-FDA: 80694945912.24.CF51817 Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) by imf23.hostedemail.com (Postfix) with ESMTP id CD54514001B for ; Tue, 18 Apr 2023 15:49:13 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b="dQ/UuKqs"; spf=pass (imf23.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.221.46 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=1681832953; 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=UpDTnbIF542CSHK255t29C0dsriOPjDrlIOTnq6VGhg=; b=cK71neaNRBiYP/Y0BNkIlZk6cDe9fLp6v8ZOqvhcqO+skdE4w9nDqcUMMPII0i3d2JwtIh Pv+ZLbwuSGnneZ7aM0RN9pchaHyQ8do2iM0OmrMrp6xxU8/AO6neL3KgkbWexVvPPa/tZt 7TG87og38bDxGLmJFsFyDA9xX+6OS8I= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b="dQ/UuKqs"; spf=pass (imf23.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.221.46 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=1681832953; a=rsa-sha256; cv=none; b=51cJo8sBTzo2qnrquDxmWWiXe49oxZqd3ispDr52jYHLMYq5dUD1esNzqIQRMGeqa71350 yL/p5TuG4i3mTLu+fUlfUSkC0kXY8GB2NIRgwqOxrwIvaQ42pISfw3BFUzC4M2IdpuPU0j SQJ0upky3Fa19RLqMIGCvkhzBI1CiFI= Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-2f40b891420so2567286f8f.0 for ; Tue, 18 Apr 2023 08:49:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681832952; x=1684424952; 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=UpDTnbIF542CSHK255t29C0dsriOPjDrlIOTnq6VGhg=; b=dQ/UuKqsfe7uYvWeE5Pns5rtVd/0AdPad8c6UcyQo+zRskVc5bILEFh+J+6CCSO2kB EQFeaaF6avE2fcC6GNrRKY+SbeSrwYTTV+HgN1j0eSYVYP8/UkNn49BMZvplcC8SFFiJ kT68gM1qGUkiZoWqhPxmjveTuQXDah1AOW2VZX/EN4P9WCTE1SPbZtTO43LrVfB12rJf HyAHHKgmiIS9VMKrGTV3L5McvFJAzvLANCZzingrQGv819mJXKz10LaT85JPYPpzyFE4 8YTBz1NpC4zpqv0L+IeiVh6WgfmFVhz+XnMhKpUP1RVuAoO9uQO+k8AEsFVgT0uaZXKy 4lYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681832952; x=1684424952; 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=UpDTnbIF542CSHK255t29C0dsriOPjDrlIOTnq6VGhg=; b=CL5yJvmBwgmPpby86MU5c55hHZi0DXD5ckyZcwlRq3V4lnYh8sF63DclyCKhNUMKNM rYeYLG3FbYsRVB7OV/3DKuW2pHJkxWd54PW2VyY8dnFn/RqKtcsZ9iyR/xc8E1BelZuM +k3Detxmkf1H2B5kfEPVXdMNESiK4IsMn/GO9U+ybsb1zQ1fifUyWfE0oO2IuJjfXRXe HC6uZazfrbws3cuRsKjpJcYNuJPF+KlwEW077oMtllT/X4VtaKIrULc6ehq1r7PBjNlQ L/oeO/Ah65DFcAr1VSMgh/m5oxJhDgd/7SAVBNCkdUDZALt7zrQroHU9O+3SSuoX+VEd cWEw== X-Gm-Message-State: AAQBX9dqZ8DPPkSNQ/dWGFyI5sCfImB22kvRKsWmKrLuUErSrrUKUuWT aNrsPwYgjwDTQ1rTOjz7wAlWUDQ5BXrcdQ== X-Google-Smtp-Source: AKy350bVV4uQ8lR+SE5X/kHt9mn8be5pAW7rko/h8BvM6/W0i2CW942gZ/uHrHsWr5XB841GP2+ddg== X-Received: by 2002:adf:f8d1:0:b0:2e6:3804:5be with SMTP id f17-20020adff8d1000000b002e6380405bemr2239587wrq.59.1681832951798; Tue, 18 Apr 2023 08:49:11 -0700 (PDT) Received: from lucifer.home (host86-156-84-164.range86-156.btcentralplus.com. [86.156.84.164]) by smtp.googlemail.com with ESMTPSA id l12-20020a1c790c000000b003f179fc6d8esm2254274wme.44.2023.04.18.08.49.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Apr 2023 08:49:11 -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 v4 3/6] mm/gup: remove vmas parameter from get_user_pages_remote() Date: Tue, 18 Apr 2023 16:49:08 +0100 Message-Id: <7c6f1ae88320bf11d2f583178a3d9e653e06ac63.1681831798.git.lstoakes@gmail.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: 6iugzqtnqszqefiuzf6ku7s81ka9e694 X-Rspamd-Queue-Id: CD54514001B X-HE-Tag: 1681832953-362033 X-HE-Meta: U2FsdGVkX19VcllJKSxRo2dd4OjjwZqk3obDvKllpUBt/RdlwwmQ8wuyeKfD1Ws2iawnUvKz56KUxnteIPFJ8YL98II1Zeh3prFk0LZLBNRCpnoRKrKGab89oJiPqg9713VyTsROUHmCaBRNshLgLwqpHt0JoUuxaWLj4CFB+dILMof80oN9uiDLY1DjG6FjdocK0rw2tRS9VZAToTJaj7CPlGxW6MFZVBUW3rw0RbKPCEYRixg8JxCDcjrAHYiUXVnc5K4LBUSIiIvzJ2RMFjAG1Txjmfn+5d9erw0Eh7vpYQ4OZSVN3IAgSI0/pbEayrFiTSXHTItJMhqpAB/aHHSxSiMGkcRCXjn46NJWIU6dmCmLL9EEP6wlaj/Iez/A1wZM5VEuGHqm6yFJgZjUSaNIDNTWKm4684eyMOgDwsUdkYSRlqa8DS8VphZddf9KTsjBlTXm3yN+lRBUoAmaMOrpoTwPFq1M3xP9zrM/dMWaUyyYcitr3y513Cq7xavTjjpx/TZtWgIG5dgk/OVpFp7fcQbBoshCFDnDvBDX0xIYJVYuQm90M2MDDexRtehxpOEBtyF7vw6c4XpjYrRCQHLouDXtIFbheMJfsmdODyvPb/WcZa6pAbDGBjRmAF0DC2BJSV++b6EjgtlELZimiEaPBRfVCv4v+X5kTTBOK/XHhMoP5TWbITG594bpLnfBr6iqjvY3j0MohF4DVKjDBDfmamWT0tKtZRhf/kWFxKbJCbimjIiHOUFpZL3kJi0dWsSsUY1nXfljn5eoCyC91nBZ14m+14+AJWEPOSq/t+01Tta0GqjZ6NBX9Lf8MYNzCzTTytfMh8YRnGjbDxb1S7bs9uaXV2AiUhwAKmMwjQzaANq5bufpRAI6gAolW/OCz7qeIjccIvVd4PbR/KKvSMH+uVg4fWVjJldCYfakvIBQNs6QVD/QOiWfdHyCFcMJriZHLNlw75WUHwSZrL9 iV2fmcI6 KFwbNAmnsWjFUV4qz2mwgrNZQBHTtuf9gODZZ4pKFwROFQNnTby6FhyfJWBrgG6E3ZamtUKl4oVusnvJMEDOkjZI8pyVd5jBdEovssDfXxT1TuRFYCstCH+AjGVLbG2kERY+l1NVhnwFCO842HbkMcRiATA0JnbKhp86kvF3sYsPtiaLETS+88OJXOm30DvucCFoqqpAGnVKO9LmKtm0ATKMQnxofk/Wo+d2BTk8P5UKXbI1/Bq4tozP3yDk8BaXB++eAkHdvJuFUDfrOzSSX+Xl+MFMKoTbml69eIvb7w323l696gDvjksnmj109iZQ/ek6CIcT7dwUVKnXLc35sSr5aRJ5KaLz16j+yCCF9EQX+x+IrW8IkrKuAm/ii/NeyC4rDYWu4e/7HQvVh1PzebZyM7JmfRVAk1eHUEETgU6NeGllFZ3TaNXDnh/H6EUE3PQ1mBtfagHDbcfZ8Ta1iMQIrAG34Rr9BKwkWMijDarXO0RV6nm3gCwO2yUc6j70cyjf8Pq5cnXYzNncGOM8nMzZN083BZnOnG7/H/9aO4UKSgDCfdIbrRaBeSLkLL/8JAIVmZEKTEX8CZK5vpxN8JUUjGQ== 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 Signed-off-by: Lorenzo Stoakes Reviewed-by: Janosch Frank --- 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 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) 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 *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 ec9875c59f6d..0c236e2f25e2 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2364,6 +2364,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, @@ -2372,13 +2375,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 931c805bc32b..9440aa54c741 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -2165,8 +2165,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. @@ -2181,8 +2179,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 @@ -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 = 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); } @@ -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..61b7192acf98 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5577,7 +5577,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; @@ -5586,13 +5585,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 @@ -5600,7 +5601,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 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, 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 Tue Apr 18 15:49:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13215866 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 4C9AFC77B75 for ; Tue, 18 Apr 2023 15:49:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D03338E0009; Tue, 18 Apr 2023 11:49:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CB3778E0001; Tue, 18 Apr 2023 11:49:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A916D8E0009; Tue, 18 Apr 2023 11:49:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 994598E0001 for ; Tue, 18 Apr 2023 11:49:18 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 605F4C037F for ; Tue, 18 Apr 2023 15:49:18 +0000 (UTC) X-FDA: 80694945996.07.624E015 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) by imf26.hostedemail.com (Postfix) with ESMTP id 7670214001C for ; Tue, 18 Apr 2023 15:49:16 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=RxtxdKNe; spf=pass (imf26.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.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=1681832956; 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=HeNjOFrTuZuCuhpkRwg6ivljw7cwq/rMRsd+qVjznzY=; b=WqTLlGzj7vZQ4COaGuomIO2f7fAGRXLFXN/JXzy9LzVY1mmttfd0CiFJslMiOecw7j2+2z G65gefoTUqvq/i8wsUiBkO4SgxtWQ68g4T54e6+Zh+g3hjIbX3oKLBikHoHTWL787wEudu uD8tUDT6s9i9n0uw5BUquj+La3v++w0= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=RxtxdKNe; spf=pass (imf26.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.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=1681832956; a=rsa-sha256; cv=none; b=SMWO3AFG8Y0bcc7ba3+cznXvjP7iepa6njdoZZb/Bd39GptbB7P1xueOvLDyN51WHqhqVF lRJef1ifidtPIlHGVIXqfGu5vQyWgufGQGuaANeYDgjAyCRXHyy6yullx3ScYsWHgP7RkX 18oTiSyU0XVzT3JTJ/NhkMSqVIn0uIQ= Received: by mail-wm1-f48.google.com with SMTP id l31-20020a05600c1d1f00b003f1718d89b2so109563wms.0 for ; Tue, 18 Apr 2023 08:49:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681832955; x=1684424955; 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=HeNjOFrTuZuCuhpkRwg6ivljw7cwq/rMRsd+qVjznzY=; b=RxtxdKNe4EOZeD/rsX9M86UlJh03a7oh+S5LkToD8wsEvZ7jKSdBSVphhFX2sOoDAJ bGzpAmPKEejxjg71GV52q7a27iyL/xYy4M/d2kApUF7C+GZ+i6FY2vODi6xC59fYPoKX c+ffAJ2BlU+6VKn6AhApQvJ4O+X8GOQrRqOzCoMjjEYTHeon9FGJpOWOo8nVtRq5dUSY /k/khXDfWND879oTdy2gnPRzduT+fU2tXidyBOXmbllH62qMwYg4xOhgBDPojHgESj5i guCcOU/kpK4NndpXwN8LmeA2Ce3BkwTQv/1Bnqhj2uDLwF2BOWRuyAOyl5jBHW0QJa1g Sg9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681832955; x=1684424955; 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=HeNjOFrTuZuCuhpkRwg6ivljw7cwq/rMRsd+qVjznzY=; b=DJxDxRbwZd9ujrRJ+qsv+kEFGExKDe28JsSLUfXn/IsSDlIWnlEkZrQ/BRzVID9XS4 bi+54ch8su1V41zlqujgKqfM7lk6xbMdzb53DFqQxStcmP/vHv1sPUn794D0OEFuIyn5 5FLqIOWabZqSvo1RpGx5/VeXC4AdAjj5o4wN5KJtKyY4zba93ValmA3PzrmVzdLRM81X axapBwRDXUu4jiI7jg5vHZcPc7qNO2R0TCP2co51amkwfAKKpsn81j4rtZMyj3T0gHbV Kjn0sW2jxHCbbJ9AiX2xCwxywnS80XVr5XAEGiFTAQsu9OMbJGU3LTzl+JwbHctVW0+0 V3DA== X-Gm-Message-State: AAQBX9fe6D4zliNJhkBiIIX+7yyCfKoS59E77Mh0ryWqQKkeNIMYR61e MvLVgJlQnjAsEvxjd2muscs6CiimQ8/UhA== X-Google-Smtp-Source: AKy350Zx/7jVACHVDEd59MlmNb4yh3Qa9I4tP2Z8+vUyRAqrt3dGiF4TfRMd44P/Wpn+tmYhFgyqMQ== X-Received: by 2002:a7b:ce97:0:b0:3f1:6fea:790a with SMTP id q23-20020a7bce97000000b003f16fea790amr7103576wmj.30.1681832954636; Tue, 18 Apr 2023 08:49:14 -0700 (PDT) Received: from lucifer.home (host86-156-84-164.range86-156.btcentralplus.com. [86.156.84.164]) by smtp.googlemail.com with ESMTPSA id k10-20020a7bc40a000000b003f1736fdfedsm6708400wmi.10.2023.04.18.08.49.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Apr 2023 08:49:13 -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 v4 4/6] io_uring: rsrc: avoid use of vmas parameter in pin_user_pages() Date: Tue, 18 Apr 2023 16:49:12 +0100 Message-Id: <956f4fc2204f23e4c00e9602ded80cb4e7b5df9b.1681831798.git.lstoakes@gmail.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 7670214001C X-Stat-Signature: 64n3qo64c5aicmb6z67t5di3uxk3i116 X-HE-Tag: 1681832956-1148 X-HE-Meta: U2FsdGVkX19A4x0uJSUppcrm6CsVXqtMSBqTcLDopaZqsZda/fGXygXgzxvWZeBzeqZ/cXaQCBLecMiHuJyN3UdsPxjuFr2Y8sxMoLGck+iKt2OB82pep+wUjdoVl3swrSguKpuKHdpwEElI/Ok5umOkMxugYGEFN/Unoj2vZiHyQ/9bntePAvRhCGidT/FEO40lZWr39XBylcWnYoRSKlcoZkdKaixyUUS5LTbW0DC+ZDh92oXS2pzFe4MXFqld7cX7PRcAgviDdXq+dCZ9KerTRsEhP+seSCBuEubqWvvNz9V6rGSaDJe/zwk8nfPEfJZOzNZHaPvSUu+FAp9Vyhc/cwE0NS8hhRYrICpyOOo7kTp+tsQwGKT3LGV4ZlRcPL4YhibvESYNdqfmfkvuGkQkgMR2gvVK6MJT2LoLbzspJ0HOABbQn3NqCX40gRiVh8QGJDvsjm5XXwbYFwNJ5VVv2PKHtc/PKjDS7Ii/xzKolkmeUhJwkf3kc6bidJ+4tBtEPiZHEslunTq5eOt0o2CklIXPAdm/nQs6vzrDwoXeKz9mLdlVZl3Ra/NsAnZaYsgFAsoJKj2mGtSPwpQPFH/MZgsM6pcDEq6+0IX2DEu71MAFZCfH6e4Md0HwB1+S1zTN9Z8NUGqUvcd0cS/ZS+Ndnl8LxLsyC36ATDDvyCz9dAW9QPxA4eaLwStS8nMXe6PlgqapeDTI7vxYgG2hT4p4K9YupSWkRVd9e92vZN16fa6vatY4jCkOSE6veCSMJCTgqIGGt/Np3FMFWUlCmhGlWeX7KypQpv8ypwsa/NtSXfltrF4elGSvtHgU3+9yoi9324MyHVECH6XY9m2MM8gNZY/JJHt85UIAHCxhsMWKKOZPZNqXZJuA2n4rjhNU8nxgLld1IVltReRhLQi7+HjNKzIScjlc8uNBvIHddjZ8obqWYVN5jg5Cmyduxo7vHqdHiG3LAhec53esnC3 HDaY/7mA WN4Y47WtiXf6phlxRlPUtnu8yL1S5z+STjDPh5r1I2ReqtXHSLAjz5SumWQr+q42cioZiUkOAQCBbdGpWCcVWUS7ivAKMP6dQE3voCgGMTy/HCiraAe6/sg4x1nGXjaCmm2MsIK+am8e7qnZt2eBh2HAdvq+y9zyFxXJr9D4zt+IwziyE4zCQuCWyA2Oh30WXvgsVE+aPv1H8eSqIRRPnnNTRSD84jusLOQnsLx1nvIe+MwrARcEKfs1hvn2EdeUKFRA0M3GZIRqt7D8mgxf9XNKzj/79uqYygKfG7j4bIIOULdMp4zXvfM9PZiOXAGgo06RNbZavOmFFW3v3+aH3t2aw/ihAR/zrcGcSuXH+X6+GCvj2OvhXNtgkW9YlfqEcLY7AR4HDX0k6eYqXr2J0IZPV8RTOMq3kOXC89XIIbC2fOGRVQwJX1oKpPy6gPfO9G5F2XVXWzgFICiRJ7KIZCjNEjaKs9f4OKGcwVzweUnehiH2HzQ8bQU9DF2IN5tqGiCJb+NYiqfqTP7gU6HIsN0/DXu+G62U3liCkwk0TiN/v/AV83QhTjlNulX4Abr/Q9qYpKqzO7Da3F3Dk7Eapc4n+5c2HrFIH2ON+Y09jqJ2hV4tG97eFjYLhleTcXZ8WToXG 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 shortly to remove pin_user_pages(), and instead perform the required VMA checks ourselves. In most cases there will be a single VMA so this should caues no undue impact on an already slow path. Doing this eliminates the one instance of vmas being used by pin_user_pages(). Suggested-by: Matthew Wilcox (Oracle) Signed-off-by: Lorenzo Stoakes --- io_uring/rsrc.c | 55 ++++++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c index 7a43aed8e395..3a927df9d913 100644 --- a/io_uring/rsrc.c +++ b/io_uring/rsrc.c @@ -1138,12 +1138,37 @@ static int io_buffer_account_pin(struct io_ring_ctx *ctx, struct page **pages, return ret; } +static int check_vmas_locked(unsigned long addr, unsigned long len) +{ + struct file *file; + VMA_ITERATOR(vmi, current->mm, addr); + struct vm_area_struct *vma = vma_next(&vmi); + unsigned long end = addr + len; + + if (WARN_ON_ONCE(!vma)) + return -EINVAL; + + file = vma->vm_file; + if (file && !is_file_hugepages(file)) + return -EOPNOTSUPP; + + /* don't support file backed memory */ + for_each_vma_range(vmi, vma, end) { + if (vma->vm_file != file) + return -EINVAL; + + if (file && !vma_is_shmem(vma)) + return -EOPNOTSUPP; + } + + return 0; +} + 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; @@ -1153,31 +1178,14 @@ 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) { - struct file *file = vmas[0]->vm_file; + pages, NULL); - /* don't support file backed memory */ - for (i = 0; i < nr_pages; i++) { - if (vmas[i]->vm_file != file) { - ret = -EINVAL; - break; - } - if (!file) - continue; - if (!vma_is_shmem(vmas[i]) && !is_file_hugepages(file)) { - ret = -EOPNOTSUPP; - break; - } - } + if (pret == nr_pages) { + ret = check_vmas_locked(ubuf, len); *npages = nr_pages; } else { ret = pret < 0 ? pret : -EFAULT; @@ -1194,7 +1202,6 @@ struct page **io_pin_pages(unsigned long ubuf, unsigned long len, int *npages) } ret = 0; done: - kvfree(vmas); if (ret < 0) { kvfree(pages); pages = ERR_PTR(ret); From patchwork Tue Apr 18 15:49:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13215868 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 5C720C77B75 for ; Tue, 18 Apr 2023 15:49:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EB2C38E0005; Tue, 18 Apr 2023 11:49:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E61548E0001; Tue, 18 Apr 2023 11:49:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CB3E08E0005; Tue, 18 Apr 2023 11:49:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id B91D38E0001 for ; Tue, 18 Apr 2023 11:49:23 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 7D4841A037D for ; Tue, 18 Apr 2023 15:49:23 +0000 (UTC) X-FDA: 80694946206.17.6423B85 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) by imf12.hostedemail.com (Postfix) with ESMTP id 8CC294001E for ; Tue, 18 Apr 2023 15:49:20 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=ntPGEolI; spf=pass (imf12.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.54 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=1681832960; 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=bb9irq9nW0pE8CSgWK7K74C7UlngMlVehaGXPHyB9ic=; b=QSFil5/ClGfAETP+1L9o14C1fr96L3j8Gs+ipOEmlT4x90zWF3SRVVjRQhaEK4U8Dud8s2 NV3N2P1BuYIIFau2dVzAniLDMVBFWk7ebAZx1jdxSV9r7hh0blFapHgtFAROtcCHcxJOn1 tWIVjvTsd1OIKxnLUTJ+Ck5MCQDPRvk= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=ntPGEolI; spf=pass (imf12.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.54 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=1681832960; a=rsa-sha256; cv=none; b=ad4ViLypLhMFgRggxHA5wAkCLoIqf4PIHmW9s4H7oN8mpSTEXdqcIIkYFllf7Vf+HD0WKh sAsNOj9kr539vdgt8adc5rGHTeA9tYRVie0fq+nKYwFBN/PD7rryKrmbkZwMPPgZT9ktsJ dmKidPAVAj2VAIQUcwpk1Wj1f3b8O7A= Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-3f16b99b990so23356465e9.0 for ; Tue, 18 Apr 2023 08:49:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681832959; x=1684424959; 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=bb9irq9nW0pE8CSgWK7K74C7UlngMlVehaGXPHyB9ic=; b=ntPGEolIZioWsoNupmOxdO7kt9WWHTCzJGRt3JeOtVCC+SVzkwa/NyZv9ukI232TBR /SaCFFfiuP+yU+Tf4o6hIp9U3tMU7b5AGvSvrrMr/kY7AUvOlJsfmn/RQNibRrHgleWU Q0at44oFe6V5iGpVwBJFEZ3d5+4yn9KmVpC5vgqz7XRwVwkxwq8sWQ2UENZIsQIky+JT qXGN3nxRBzi/n1aZEOK/lypItYhx6fff2XHtr4sPyCmoOrbTguhoA2ytCDf6KlYdpsSq cW2A33nEC11LJt6wWbm/o8z0hOIUZVu16DMDL5s3z6+SJ06YGDg5S72COZQ6YFGJuGon x+uA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681832959; x=1684424959; 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=bb9irq9nW0pE8CSgWK7K74C7UlngMlVehaGXPHyB9ic=; b=VBxWWScTY3EMJG3Rizfug3cNWYoXIarhRPosQYYrc97bZyx+k/rbakzKD3h1DC4ePl cMMnZhtX5+6huuJz5EvUYhYOHFARMKgMA2cRhEGqvK53f7X0a5bwmqzUcttDS6dQQwFW 9MxJD5H4lYQBrHopREcOzPb5pAoejPNk/Bk1sCUicO1VMrtuJheXt+f01UMgOtWPnptU zWD8tFuQ5Fcyw2evFCi9LlE3d84fVC/Of3Sp/ibZj7vMohc/ugHqxydF9Bdg3MP8JS9Q HKZ0nK1cnRjqAPs5aAHA9Dzbh5tEWZGiUMXVpPzjjHQFl6ODKBlS01lXHkdi717OeUHx w6qw== X-Gm-Message-State: AAQBX9dhpZdvzQZoWEVesVwER94s6+GZ7EYvlqklC8dxT3rgJNeluMi4 6kj/fvJy9JyC/J/2zVLCyIxMjgRJTzT8+g== X-Google-Smtp-Source: AKy350aikpx9A03wx1BpHW1zS7E+sdV29dDZkTBMa7IL0AbouX1s8BmVCcsrkL1ZD5YHaD7cPB+wCQ== X-Received: by 2002:a5d:5001:0:b0:2d1:e517:4992 with SMTP id e1-20020a5d5001000000b002d1e5174992mr2266976wrt.69.1681832958700; Tue, 18 Apr 2023 08:49:18 -0700 (PDT) Received: from lucifer.home (host86-156-84-164.range86-156.btcentralplus.com. [86.156.84.164]) by smtp.googlemail.com with ESMTPSA id z16-20020a5d4c90000000b002c7163660a9sm13381191wrs.105.2023.04.18.08.49.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Apr 2023 08:49:18 -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 v4 5/6] mm/gup: remove vmas parameter from pin_user_pages() Date: Tue, 18 Apr 2023 16:49:14 +0100 Message-Id: <765b2fdba141b40f72d389e942286456bf5c9f7c.1681831798.git.lstoakes@gmail.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 8CC294001E X-Stat-Signature: eqmosacysgfhdr75gf5x145tim7qy5a1 X-Rspam-User: X-HE-Tag: 1681832960-69984 X-HE-Meta: U2FsdGVkX1+4AtyUiuqB5WsTlwdglyzRA26gGjpL2b0DM72cUouPJW1UujwkHUpOQFLJU4F79u3200Sk0/nUHUn3TlXOpEaN9RdbmqgaM/Jp9Nnx9ED4g1pMstQTOB//qw3cg45h2t0kb6oSam+5U3Por2DhI3sioempJW/Ejjr9nXhMGMWVJGMMfLW7Gk5c899JJCgGc0oil2AcYQIChGhUkpU5tgnPo/77lhVM0MXpMPcoqvFHeAo5Qstg1DiKtS5/odMNf2+BTn2ZaVOoUNjpg3vvrntkmcr581NnWDSpyFAZ5E7up7mNJN8AGvgr1KkC8XdsQdHCosTLQIPdMh7jZm5NleEv9D17MSd3hnPRYEWuUYjvDjFrwmbonkv6oZwcFmHDH1eJ0lycxVFu+Es4bt2lf7rcfxV0CdSb+5PGxJqPqwZ+MNHkrJjzYRs2a/0YygjJEP3IKwxXuVMAmi7jSazIqj7YrpBkmxBWDSsuoCX5kGI2ew9H+PbdozCN96ceWg0D9lqWIEjzlX7IlkQ0314gsA3k6919ZaplA9iQflPOveo22PShbi8yC9C7nT+lN4eXS5O2/HbHH/UwZkHpFwHt6WIpXHnUNP011nN/BK5pUJVnrtedcgzMO5gAmQfD1xFZOYbP4XUUTgU5WoED5pchUnisByZf3P9d1RlRdNhmqj06wZNWUuEYcuMqv4J5COK5qhqDk//+Il+4ULVgFNVSbe+u7bof1fSqwgHtiFUniw0uGG9/Fu7Hywfdi4EkZPjEwY8JtA0Ah/+rLDb80fjTzVUdYBOAZW30XbFjxrBoU56nu7elkfwYLCilHLRJbrLzqP1tG2rsW895PuLW4qHErRy8vXG9n65fTrYEquMG0vCuqoIE3Pdlv+dJ5bIJ0QHU82+DJwtwPXUgTpPO5CpVbQM0Blv+m4oRF0GEgBHgOVe7gCM9q+LNRnh4Vkf+ApvM58A72XZpXDh 7VuJteL2 roUc3uawSMQPL6kCYePn1kFIrRLJD5MIhk2LqM0AbRMdvSr5YGihfQjjRTR1hXURnfvr30Xcq7wFYxBJvKFZAblSH1X34AUaD61RH6oZZyWkrQzLCluui0wChxUTU/y1Q4vHzbI1LhUbJ3Q9oOQPhnilYprx+Rd3c1NubKjdVE5HmmJEJ0FKpX6+R3ysV44g/RUyw3hxyP9vV6KLVfQBbsA/gAz2fgEDShP4jXV4aCdJaL0W72KXoOedUyumNEDCoBVKp85Q8MXQrtRCkaKnPxD6aXrKCS8XChK8zyXN2+QBuVCjmQiutGjoc/crWiRCHZsRc7CoQ+6AiNnqxGKiQNy4Ve7/pRFYYj5Y60rs0OkrSig2Y96Dsu/LSJHT3V9TebiwhgU4BtNKDxhh/KFBnNr9dBOno21q93v+xvSDOlQ0O0yyhtdzTlrKnPe5NUXwAD8s5RgzjgoekJxdv10FOI8ZOBHcO/Og704hprRdbyTu5IcVcvlldsgOoxHXLHHFg6rlRDOJ/ecx84AB9uGMv1/ifFyc9EdMIGpGjFKLtN/YTstXjELFUaQ63OycLcF9YibWih1B7oTJUBuo+adpOG7YYWxyCsk9LumbwhNazsWSQEyIHDAw08aU39pk5+9HBiqECj2wDUA7XvATszkulDzKR0Le6tLILfWnE 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 --- 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 | 4 +--- mm/gup.c | 9 +++------ mm/gup_test.c | 9 ++++----- net/xdp/xdp_umem.c | 2 +- 12 files changed, 17 insertions(+), 24 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 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; 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 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 = 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 0c236e2f25e2..d02c42d37bfc 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2410,8 +2410,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 3a927df9d913..82d90b97c17b 100644 --- a/io_uring/rsrc.c +++ b/io_uring/rsrc.c @@ -1180,10 +1180,8 @@ 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) { ret = check_vmas_locked(ubuf, len); *npages = nr_pages; diff --git a/mm/gup.c b/mm/gup.c index 9440aa54c741..dffbfa623aae 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -3124,8 +3124,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. @@ -3134,15 +3132,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 Tue Apr 18 15:49:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13215869 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 715B2C6FD18 for ; Tue, 18 Apr 2023 15:49:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0CEDB8E0006; Tue, 18 Apr 2023 11:49:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0088A8E0001; Tue, 18 Apr 2023 11:49:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D28ED8E0006; Tue, 18 Apr 2023 11:49:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id BD1BD8E0001 for ; Tue, 18 Apr 2023 11:49:25 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 73D281C63E2 for ; Tue, 18 Apr 2023 15:49:25 +0000 (UTC) X-FDA: 80694946290.30.1D4C245 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) by imf07.hostedemail.com (Postfix) with ESMTP id 7FD404001F for ; Tue, 18 Apr 2023 15:49:23 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=LsgKPM+J; spf=pass (imf07.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.53 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=1681832963; 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=qg6vLTyUNdrbtpYgQjsRPnv4rLumWw2PGGtB2gnN34w=; b=5r5yoVOx3T05uZiA3U9UygqsQd8Fqr5PPeSt/4vzXXCGWn6Gn4qt17U5H0hSuf4Puirdui tzDOmsZWtUY5uA7S8pqjjyr9KDOsLj1pwic9W41+47BxNOscwbM1UaETVpK5G+3mI+Dn45 XPUJ9uv7QGSWAWxeWOUsyrrp4E09qxE= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=LsgKPM+J; spf=pass (imf07.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.53 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=1681832963; a=rsa-sha256; cv=none; b=4z2MeOJzMknxmhbDrofERARgcJmreCHB46aF/uQWjzgBm/SQE+ST0RUiV/v/GexiWJ9n6y ABjiuC5Yf7/mk4Id66WKuaLonCUil5CuVd79KqWgg1taF6ExfX3ITA74AQ/p71wYndqkYI 1fHhttE3wD0OJ1W+GAK5ByTVlAxCgz0= Received: by mail-wm1-f53.google.com with SMTP id iw7-20020a05600c54c700b003f16fce55b5so109061wmb.0 for ; Tue, 18 Apr 2023 08:49:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681832962; x=1684424962; 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=qg6vLTyUNdrbtpYgQjsRPnv4rLumWw2PGGtB2gnN34w=; b=LsgKPM+JfwB8t+zvceBvqJsfyMwpG+f4OXVIaeHGhHFUrfkFWlEBhTvaSU3gw+hRe+ qQMXN9S+jNMrW+YTUp2pG8PK7lzE36O33zxwD6eydrG7C23kn0+o+s6B1hDOuSag+Inx HjmD6rivSn49IvYR/lAGFIP7kZXq6ytIoo78PhA8Wc9Fb8k4rgaMFljzd9GYV7adeMr3 hr1hy/knJWLIWsgevWsod6Ic655wTSw/Jc81P2DzR9AuRBH3BhpGS7iRHZOZM6nSWZjZ Rjp8goxXr8L5fOiiJtSmP1CYA+4DVU29Sz2o2DFZ84OHu8I74gd40oorqWnFX3AxTVub dBUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681832962; x=1684424962; 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=qg6vLTyUNdrbtpYgQjsRPnv4rLumWw2PGGtB2gnN34w=; b=QU05bDFLGQ38J/TGMoGyyAMASKOTl7bsYN37xfQYgc5Bp8jz5drTcHkzt29BEEWjFl mqjw2XKSyza4tU0VpEnZOo33jOIlM8oV6MpS1TQvQ4GsEGPhggKpPSP3Nzmeqlg6FJIL CVf1JlvFdggV2jTzdtfNqhHIQ2FYpn2Apta7zHoYKe4e9tRND4qZD60l29OjyqzTcXLF 8gEkqzvzIugOAhfcCKIkTgmJsbQZ8Oq+VBRs63lYIdoVxN/Hy2Ou+gi/lxWsG1aNvXEA eFBg/XkbuAoPGCMWVq8+0MBkN0KOQXm7Sdk22hraLIvg7AqTEe3vs0A+WUq4eGgXjT1B JSPg== X-Gm-Message-State: AAQBX9fzpZZRNBedk7rJ7dgK8Ur1NtwqaRBNJ/Jrvj6vPVpEMoTnZni3 V2+TA26oaHhmPxpKkLfMCgCAtYLbkwsBzw== X-Google-Smtp-Source: AKy350bh6cShAYImzTwiTfrHt8UQNXihH8sy9eIV4mE7cT9LzCaWTpOh9M+tQM44gffs9hn1OK3uyw== X-Received: by 2002:a05:600c:3642:b0:3ed:f5b5:37fc with SMTP id y2-20020a05600c364200b003edf5b537fcmr13145329wmq.1.1681832961709; Tue, 18 Apr 2023 08:49:21 -0700 (PDT) Received: from lucifer.home (host86-156-84-164.range86-156.btcentralplus.com. [86.156.84.164]) by smtp.googlemail.com with ESMTPSA id s12-20020a5d69cc000000b002cfe3f842c8sm13435030wrw.56.2023.04.18.08.49.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Apr 2023 08:49:20 -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 v4 6/6] mm/gup: remove vmas array from internal GUP functions Date: Tue, 18 Apr 2023 16:49:18 +0100 Message-Id: <6d68a7098953bd3584ea20e80e689aec37ae0497.1681831798.git.lstoakes@gmail.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 7FD404001F X-Stat-Signature: to6dfygsp9eiufw8gie481iiy15fr3hq X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1681832963-482878 X-HE-Meta: U2FsdGVkX19Kz/Y2+v3Roi+Cwtf+RWxvbGSQ8MVJ8NKJY2OlO59pwMC23zQUEeMl7GeuDam3ZX2BU7xlpxFsS8biASIr/KoPHmfHAaM/zvjVUcPGnwtGloyTvN+Ps1y5Bi8exxviOcEKYKYStSlmFxkJ4/eJu42RYJqjDrbTSSzMsMIl/MKkDIh2qJku8U03deOvPDzCURfveBG8Wq3UvFXc3BuGeYLsvcxr5VKDoHGqw+Qjv0A/Uze2pA09M8latAH9Rf2Z128zeLH5jJ3Atvbe5yPAwpl/XFXflS3L9Po3wVqcDf6lDSlEBslET/K8LfV7UurNeSJ/JZ09QLJ+w6Ju324LOV4b8lg0/pGi0nZR4rvf4MES/aySHo5IFIiBlUFwAjYgQ7BxA42Y1TVBKhmIkXMQVyBT2QhT78SVmd30XpMJpbkF/5WuakRzUNyyv3BhfV2qGMli6mGnfHpiNVsag4Ev2Qi/dHfM4ZzK5JS8/S93ZEgQhH7DuzJosOzdXW1kujfTV5WyorKmwE4QkKExsp+0B4PXY9XX4mMsrZ3Wm8plYYLtz1PQKM/UD5tO1T/L+CSUkRcQbNGiz46hUz6vDZHFFsH57/jvX44YNtH7nJg7ZmjjilavV5nZAdLCWXbH4nyLgfhrZnITSlwahVEzHRrOiijJJ1n7hk81W6bQD1zT4iAXKPjMBjrAeYzvVeebQoeVQa1JsXbjOgTKoJpwMPWi/FNd69W1KNGeNIhMEiziNn1SYUZz9GZ4+zF38GW5gfek7Js6TQZMyo10FBhiqaWNZAvaPz7hDaCu9va5y9oD9HnChnHJS1wMa4JXgYbriWQ6tbTV/39XZOZiweIIyfQzunQOiLQg1v78ekCzDVPwfsTdF22f8J3/3R0xnvTztwxHD9lrwJZ9PIwN1WR/FW+SmsoZmeCqK9niqGi3ysVlr8hQC1u5vEP+X1iAo0bXgJUJONNTx1XnvZF XWbuMo5h c2sfViJ/kzlJhXO8h3WmRMiZeIWTPke4b/r0WkcLT2VySYgwVJgsHGWYasWabUqoodg8ENvWi7rXOm3QVAASl5kn9dhIZ/OPRMi48lCza+ohrUKidubB4fPBNpibREn2OMBcBoexIk5BuBz0U/tFaRpad7h1aHbNTcM0Lkc/4yoxFnkpHA6bMTryn7gobYBEY1IrldF5Fy7RUwYZ77znI/+YDs9J5jPFRKnhxP4DdYUEWYoOvpBThAm+2SAuZXbGKxDB1ffy2FIi1ncVbaja1mPoiIlVeNL1+xhXcZMXT0PGo1calDwoVIZBpC+P9gYC4Z20ZfoxIBNSPmb9YJ3Czqn9CL+gl/iBr3cYeTX8GK/BpoEPOZh4r+VNPltXlkwZ+AD6Uvr0eZlLP726qS6nFooyh03MH3zX1oiPOwtkfVF6qolTTH8tn0SmEWml2ThKofDv6K3rqGZbjwu5AayX3RxqPyZQSq9Qvsihq 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 --- 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(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 dffbfa623aae..7d548d5a21a6 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -1024,8 +1024,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 @@ -1039,8 +1037,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 @@ -1076,7 +1072,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; @@ -1116,9 +1112,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 @@ -1183,10 +1179,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; @@ -1341,7 +1333,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) { @@ -1379,7 +1370,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; @@ -1443,7 +1434,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); @@ -1541,7 +1532,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; } @@ -1599,7 +1590,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; } @@ -1667,8 +1658,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; @@ -1712,8 +1702,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; } @@ -1894,8 +1883,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; } @@ -2068,7 +2056,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) { @@ -2076,13 +2063,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; @@ -2100,9 +2087,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; @@ -2144,13 +2130,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; } @@ -2219,11 +2198,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); } @@ -2258,11 +2237,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); @@ -2286,12 +2265,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); @@ -2974,7 +2953,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) { /* @@ -3016,7 +2995,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; @@ -3049,7 +3028,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); } @@ -3074,7 +3053,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); } @@ -3107,10 +3086,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); } @@ -3136,10 +3115,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); @@ -3153,11 +3132,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 7747160f6de8..ae9a08c1fdde 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -6380,17 +6380,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; } } @@ -6463,9 +6460,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; @@ -6593,7 +6590,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); @@ -6608,11 +6605,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) { /*