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/jWAYdP9u34l72IW60TUOeavzCbhnwqeVtDOVswIFRk3reb7KpKml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nAsR8swUdGIU7A1BpNhnTHIo58mB6YZIE2Q9pI0UHLyf7U97kYC0aHXjtdcb5s6hJKuGGDpYEAY11KsGr6W38htJFYdpDz1PH6eRvvAIW+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; }