From nobody Mon Dec 1 22:36:22 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3016222A7F9; Sun, 30 Nov 2025 11:18:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764501507; cv=none; b=CmsSTRCal6BHGQ0lgWZ4sRisxAD45r8RPPECm0kGLCsG8VPabpRbeIlWe2wyZloIifJ3W3WBBJvEqxrugpKg8BZfuBSgxttwSGi/9B7bco1ghAvOm/NKi6RmRLeSOP4VJQzHSkHMNuqyG1P+SZfmDL1IUnXXrGlyQ4YGn7xjc7M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764501507; c=relaxed/simple; bh=M3yfj9Aq9Ecb/VyGmdsiKpQj2lliUSutXUvuxf84MWc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FD9Xga0BMWJwZowQPKi/IDGNGjntA5dmkqwTmjb942s2LE5fSYUZoPtEpIvbU3pzyNGJktHAeHXo69utVbboQuJ0fbhkdbDrTp1U7Lhfv3U1pPToWbv7Vq82+w5BnnrS50ILsBI6rJ/jqXbrXU081x9QqIeWUmGCFdi3Ly6Ti/I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=u22qDJe9; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="u22qDJe9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 62A53C116B1; Sun, 30 Nov 2025 11:18:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1764501506; bh=M3yfj9Aq9Ecb/VyGmdsiKpQj2lliUSutXUvuxf84MWc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=u22qDJe9yyfE9b0SEkH5kKwgmFUHYDDFq+6wlb/PHEFZTcyJQHuwm7/PK3YmJmuig I/OaxNv/MX4j/UfdzT2pvMWImwdJFoo4+5PBgAV9kLt/bYyFRR8QEGiqmcBN5O8YnQ phtYcipFli54J+Kax26kfnNNeXL46lCU5aDEP+ZzNsQE96TzGu42rs6agH4zRymw/Y r0lu7M64VcpNcVq0wtXsraGDQk65Zt3/IrNhO19KlMjOHkpWsB/anS1B8UA5Yu1d1s zjhHAYN8Dreo7ziAunpNhRalMI8xuAzdN0zUQtvVx/KvdMEg0kpKB7fS2lIfOdXb0H OFmfIYFu2v0LA== From: Mike Rapoport To: linux-mm@kvack.org Cc: Andrea Arcangeli , Andrew Morton , Axel Rasmussen , Baolin Wang , David Hildenbrand , Hugh Dickins , James Houghton , "Liam R. Howlett" , Lorenzo Stoakes , Michal Hocko , Mike Rapoport , Nikita Kalyazin , Paolo Bonzini , Peter Xu , Sean Christopherson , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, "David Hildenbrand (Red Hat)" Subject: [PATCH v3 1/5] userfaultfd: move vma_can_userfault out of line Date: Sun, 30 Nov 2025 13:18:08 +0200 Message-ID: <20251130111812.699259-2-rppt@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251130111812.699259-1-rppt@kernel.org> References: <20251130111812.699259-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" vma_can_userfault() has grown pretty big and it's not called on performance critical path. Move it out of line. No functional changes. Reviewed-by: David Hildenbrand (Red Hat) Reviewed-by: Liam R. Howlett Signed-off-by: Mike Rapoport (Microsoft) --- include/linux/userfaultfd_k.h | 36 ++--------------------------------- mm/userfaultfd.c | 34 +++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 34 deletions(-) diff --git a/include/linux/userfaultfd_k.h b/include/linux/userfaultfd_k.h index c0e716aec26a..e4f43e7b063f 100644 --- a/include/linux/userfaultfd_k.h +++ b/include/linux/userfaultfd_k.h @@ -208,40 +208,8 @@ static inline bool userfaultfd_armed(struct vm_area_st= ruct *vma) return vma->vm_flags & __VM_UFFD_FLAGS; } =20 -static inline bool vma_can_userfault(struct vm_area_struct *vma, - vm_flags_t vm_flags, - bool wp_async) -{ - vm_flags &=3D __VM_UFFD_FLAGS; - - if (vma->vm_flags & VM_DROPPABLE) - return false; - - if ((vm_flags & VM_UFFD_MINOR) && - (!is_vm_hugetlb_page(vma) && !vma_is_shmem(vma))) - return false; - - /* - * If wp async enabled, and WP is the only mode enabled, allow any - * memory type. - */ - if (wp_async && (vm_flags =3D=3D VM_UFFD_WP)) - return true; - -#ifndef CONFIG_PTE_MARKER_UFFD_WP - /* - * If user requested uffd-wp but not enabled pte markers for - * uffd-wp, then shmem & hugetlbfs are not supported but only - * anonymous. - */ - if ((vm_flags & VM_UFFD_WP) && !vma_is_anonymous(vma)) - return false; -#endif - - /* By default, allow any of anon|shmem|hugetlb */ - return vma_is_anonymous(vma) || is_vm_hugetlb_page(vma) || - vma_is_shmem(vma); -} +bool vma_can_userfault(struct vm_area_struct *vma, vm_flags_t vm_flags, + bool wp_async); =20 static inline bool vma_has_uffd_without_event_remap(struct vm_area_struct = *vma) { diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c index af61b95c89e4..8dc964389b0d 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -1977,6 +1977,40 @@ ssize_t move_pages(struct userfaultfd_ctx *ctx, unsi= gned long dst_start, return moved ? moved : err; } =20 +bool vma_can_userfault(struct vm_area_struct *vma, vm_flags_t vm_flags, + bool wp_async) +{ + vm_flags &=3D __VM_UFFD_FLAGS; + + if (vma->vm_flags & VM_DROPPABLE) + return false; + + if ((vm_flags & VM_UFFD_MINOR) && + (!is_vm_hugetlb_page(vma) && !vma_is_shmem(vma))) + return false; + + /* + * If wp async enabled, and WP is the only mode enabled, allow any + * memory type. + */ + if (wp_async && (vm_flags =3D=3D VM_UFFD_WP)) + return true; + +#ifndef CONFIG_PTE_MARKER_UFFD_WP + /* + * If user requested uffd-wp but not enabled pte markers for + * uffd-wp, then shmem & hugetlbfs are not supported but only + * anonymous. + */ + if ((vm_flags & VM_UFFD_WP) && !vma_is_anonymous(vma)) + return false; +#endif + + /* By default, allow any of anon|shmem|hugetlb */ + return vma_is_anonymous(vma) || is_vm_hugetlb_page(vma) || + vma_is_shmem(vma); +} + static void userfaultfd_set_vm_flags(struct vm_area_struct *vma, vm_flags_t vm_flags) { --=20 2.51.0