From mboxrd@z Thu Jan 1 00:00:00 1970 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 4637DC77B71 for ; Fri, 14 Apr 2023 23:25:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CD84B900002; Fri, 14 Apr 2023 19:25:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C87D96B007B; Fri, 14 Apr 2023 19:25:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B4F76900002; Fri, 14 Apr 2023 19:25:26 -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 A255E6B0078 for ; Fri, 14 Apr 2023 19:25:26 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 690FD12048F for ; Fri, 14 Apr 2023 23:25:26 +0000 (UTC) X-FDA: 80681580252.16.4A676A2 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) by imf20.hostedemail.com (Postfix) with ESMTP id 9FD2B1C000D for ; Fri, 14 Apr 2023 23:25:24 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=LfX28vym; spf=pass (imf20.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=1681514724; 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:references:dkim-signature; bh=SzMqnrR+tN/MEPcRsyL9VzoIEGZmVyA24hgPlZN4NM4=; b=4ITx+LGIrLiQi/rYDkmQS75iLQqw1+msLelkW+M2Z3mxHGpCDO14N6TEk8phloAovU5a7n X4fMpN94Ug5A5FVZmF4qikBSdtDSs9aT6RTvqWciSaVFw2NSL6eJysV+7Qu/05FWl+IMe3 o9mMSG9BF18o0rwsHesAUrX8JX9iNcU= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=LfX28vym; spf=pass (imf20.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=1681514724; a=rsa-sha256; cv=none; b=zJLf9n2feAULOqUggcRLd5qa7KCaOf3iAYM/9v/yXIVzSH27l/6+y66EZKvWORysiadyqA 09v4k8UVlYgb18eWB+Gokk6sP2B5xJF5zQ4GKtrifp/xFBNETKHCfdDtHbUFPtkoDHNrBu xx6Npb0vojlgE8RQ8BsXyr0+64z9K0k= Received: by mail-wm1-f41.google.com with SMTP id k36-20020a05600c1ca400b003f0a7c483feso3534979wms.4 for ; Fri, 14 Apr 2023 16:25:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681514723; x=1684106723; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=SzMqnrR+tN/MEPcRsyL9VzoIEGZmVyA24hgPlZN4NM4=; b=LfX28vymWuYSrDWvAI083FFztLVxgWPmxcvfDUBNJ9rRWO03XXO2iR2mgkMGn23x9G NMxVYndO8CY/9P/sLU/G0UyzOmv3Y8yGxrTDR62qmCNGBWb5PLMtk/dCO8W+x7aP3N8h XubOGhLIutKH9SdLrGIujsD9El/E/oJa5qEaoOkEVg9vlqsPAthAXkUQzZe6b3wJsVcC v3lS6RFv7DxJ3t2M+6NJgWIqA2nC0/5KCN9xJYTDJYBa2zMtpz3xGRbXQpqfFI6xmqiX qOd/rrOyTxYuG5sM+7qliN0SvzvKXKKJZPq5DWeOkkwZ9tm3FIev1Ck+eGlYG1ZzJPO2 0Vbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681514723; x=1684106723; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=SzMqnrR+tN/MEPcRsyL9VzoIEGZmVyA24hgPlZN4NM4=; b=iTh7+01XbNFGcfmAErlw+/k7ELt2wB86FH8bZRC4XwONImcDMI0F8Y675uehqcY1Qx OTpDMKCLVHgV7WxNqqkNVQL9zc2M5OpwcLDACMEmgK/14tiKkGV479JmP/YzIdi+dEmj 7KL+7Y6bOBVlQPNQ7xPfJp4QNKuoA9eWyWSF2T1lTQzVyt44e+O1dwzUmvO9CBB2xwgx zPHid6rTXG8mVnG9I5iVIMkfLh+x88N1Cw6zkhmq/5fWO//51EyGfl1toEZ6zd2ms6ji yOSrwNKkeBI2tqY+ePhYwmyydaWgB4jOp4DPHIO2PysoyFIsg/RMHoajKOd0C3oPH0qL xj3Q== X-Gm-Message-State: AAQBX9e+EiTHjFgCC/uqAPsYTh8p8e+ZaXGQglMNjx5Fnu2BDwMV9msV Xh06DWgYYgPt6ZdEtlQ+tdK6ccouF24= X-Google-Smtp-Source: AKy350biPOcCW1z56yjSERudJDU7KCFOO8gOfCAnypvaFtUp0YN4dn5TtlCmrrayE9mwoKTEBO4oOA== X-Received: by 2002:a1c:f719:0:b0:3f0:3368:5f7f with SMTP id v25-20020a1cf719000000b003f033685f7fmr5549118wmh.31.1681514722658; Fri, 14 Apr 2023 16:25:22 -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 q9-20020a1ce909000000b003ee20b4b2dasm5230037wmc.46.2023.04.14.16.25.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Apr 2023 16:25:21 -0700 (PDT) From: Lorenzo Stoakes To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton Cc: Matthew Wilcox , David Hildenbrand , Lorenzo Stoakes Subject: [PATCH 0/7] remove the vmas parameter from GUP APIs Date: Sat, 15 Apr 2023 00:25:10 +0100 Message-Id: X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 9FD2B1C000D X-Stat-Signature: s1udiu1a7qadb85kxtswd7q7ed4qzc67 X-Rspam-User: X-HE-Tag: 1681514724-702969 X-HE-Meta: U2FsdGVkX19sBzxh4ubusmqIpjw3yjkWdmK0xqQGJXiwWPMUbhkxzLtVc4USLbe2Egv1H/ClporE8DlJ1FPK017rgHps/mfUyH4/duZ9ZAxb0CMku/nWICeY0U0s9SCmTIspb0YnvqcgqTn2F5d9kYmNSeNF1Jz/s/A3PlLoD2TxWafPIPh3Ni1TzTKGFyw5w20/lr9Fu95yN02eo1E9caWbIUa76fMYpUaDWx56snQ8YJUEMELyc+7pgyq4dheFwoMSP0ZSi1h27MAx2AfSez07sBG4e5afYRmc9PoTCH70Pxes5UlutLif9VKuOGqBuxY7qSsduQN0N12uuo5SSBDGK0+UesXu9TZMM/ospgOHZ/Pq509Fi77u9glYrMyF13B3SsyqNk8cyGKgaE30oPDdL3rJcgr2Jwff1N9rNBAYy7v57QnjX1COMtweJouHA2VEnnR924+0RQ9BEYxY70MU4bnsLSku96Gd5fdpTml2/VdggCn9acx7EDfGiU5lD0eB3n/MtNM6A6K2AU8OA5VIjnqR3KIXYGScuDTjFFbvFJGbPMkU3uFWGnn4hevochR7qD6Q2B2Vuc5KJ2lt9zC2GYOtfAOdeKC6irRvwuH9t3uWfhAsVtgw+/Z4osOFUqQuV3NLHy1ivOfMWaBqUSGcKMBVB6kpexB6mhGSC4VEIvhPe9fWlpP44RrgNe+2zpdGbcU0/Kfdw4udnDccEsqwf5Tqku0ZHCNenANaI7jMMuJKXKhOFEOtHIpA1YbJ83YQSk0iMKL5GKPcrVFo4N1vRMpGE9WELvct6qgw+KqHTnNfRumR7mk1zwofEki12Xk7XmZ7zlH4XL2cRkyQxEYP/+p5RAgb6zDzfd57D0LBZImJP4FYSGthyXBfpReRXIx7NCe0UGyXcB57kfuozPA8yYxOeRoMmdBkiRlzvp4OEIUKY71f5BcSWrXibUcY4573CaxjQARYrL3um7b XsWiuVQo PJ/oiNlrOslHc6MSUB/2ZRda2IQZbWyX0msBlzQ77y45ALtHJ6x+jTLC90RILOTWVEdMg4inkjgFV3xL5tbFLHPDCOjAfSqbo1+KoCUw4NDIYEmHxu1FUo2n/P0TzRRrmsRpvn6l2mt8e8kKZRO5iCb3srSpiEdUg22OtU3gWkc/qXi7NNR4p13ZnrSDCfpoM+c9R7F3bN/6QkaTBR3ssGnnbEtgealVnw5lGfJOetT2CNHIpINw82GUi+br4gF3OwpNDq54zgM9CTxXVD5rXzpQjvlTykiyRm+X1f5YU2uvSJfGrO30OnNsvp43rBKrXq9R3hGSTV2rNqN7NhRG4loxMstaSoAbqPr9ulLtyA/gd61A2iAo6Yo0b0HqO4gx3WWVFJ5JxxuNifotLwHa/xQet5QnHZ+ckuswktDWHh28oHh95nowUxiUHtw== 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: (pin_/get)_user_pages[_remote]() each provide an optional output parameter for an array of VMA objects associated with each page in the input range. These provide the means for VMAs to be returned, as long as mm->mmap_lock is never released during the GUP operation (i.e. the internal flag FOLL_UNLOCKABLE is not specified). In addition, these VMAs have also to only be accessed under the mmap_lock, and become invalidated the moment it is released. The vast majority of invocations do not use this functionality and of those that do, all but one retrieve a single VMA to perform checks upon. It is not egregious in the single VMA cases to simply replace the operation with a vma_lookup(). In these cases we duplicate the (fast) lookup on a slow path already under the mmap_lock. The special case is io_uring, where io_pin_pages() specifically needs to assert that all the VMAs possess the same vm->vm_file (possibly NULL) and they are either anonymous or hugetlb pages. To continue to provide this functionality, we introduce the FOLL_SAME_PAGE flag which asserts that the vma->vm_file remains the same throughout, erroring out if this is not the case. We can then replace the io_uring case by passing FOLL_SAME_FILE and looking up the first VMA manually and performing the required checks on this alone. The combination of the two amount to the same checks being performed (and avoids an allocation). Eliminating this parameter eliminates an entire class of errors - the vmas array used to become a set of dangling pointers if access after release of mmap_lock was attempted, this is simply no longer possible. In addition the API is simplified and now clearly expresses what it is for - applying the specified GUP flags and (if pinning) returning pinned pages. This change additionally opens the door to further potential improvements in GUP and the possible marrying of disparate code paths. Thanks to Matthew Wilcox for suggesting this refactoring! Lorenzo Stoakes (7): mm/gup: remove unused vmas parameter from get_user_pages() mm/gup: remove unused vmas parameter from pin_user_pages_remote() mm/gup: remove vmas parameter from get_user_pages_remote() mm/gup: introduce the FOLL_SAME_FILE GUP flag io_uring: rsrc: use FOLL_SAME_FILE on pin_user_pages() mm/gup: remove vmas parameter from pin_user_pages() mm/gup: remove vmas array from internal GUP functions arch/arm64/kernel/mte.c | 5 +- arch/powerpc/mm/book3s64/iommu_api.c | 2 +- arch/s390/kvm/interrupt.c | 2 +- arch/x86/kernel/cpu/sgx/ioctl.c | 2 +- drivers/gpu/drm/radeon/radeon_ttm.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/iommu/iommufd/pages.c | 4 +- drivers/media/v4l2-core/videobuf-dma-sg.c | 2 +- drivers/misc/sgi-gru/grufault.c | 2 +- drivers/vdpa/vdpa_user/vduse_dev.c | 2 +- drivers/vfio/vfio_iommu_type1.c | 2 +- drivers/vhost/vdpa.c | 2 +- fs/exec.c | 2 +- include/linux/hugetlb.h | 10 +- include/linux/mm.h | 10 +- include/linux/mm_types.h | 2 + io_uring/rsrc.c | 39 +++---- kernel/events/uprobes.c | 10 +- mm/gup.c | 121 ++++++++------------- mm/gup_test.c | 14 +-- mm/hugetlb.c | 24 ++-- mm/memory.c | 9 +- mm/process_vm_access.c | 2 +- mm/rmap.c | 2 +- net/xdp/xdp_umem.c | 2 +- security/tomoyo/domain.c | 2 +- virt/kvm/async_pf.c | 3 +- virt/kvm/kvm_main.c | 4 +- 30 files changed, 125 insertions(+), 164 deletions(-) -- 2.40.0