From nobody Tue Dec 2 00:25:27 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 21C112D97A4; Tue, 25 Nov 2025 18:38:55 +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=1764095936; cv=none; b=Geel0Ub7hByVRiG4xu5Ur1GTqD5c9j561XrYm+l8rVZ673sSnVcKbRnTP0gguzcbv2Vbi0QOlFr55k9Nl/7LOcQDI8CKYBuxTnNlH6ojrFf7vcH7OqfgCTLQTWEJBkcIguLMma9iaJR0VEPiprNyT0ps2Wet4hX5QGrL6G/aqN0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764095936; c=relaxed/simple; bh=WZL3dOi9JF12AwW63UbE2JZ210f4aDb9qSF2OCoPSt4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EdlT/Ppe7snK3ou6ttdtsaa7yDLHkaqshCOAH5LOu24QmHyMRKLG0ZKDSKEvEmu7nZM3AECyMnuNb4092z0UEfn110rRU3vNIA6FSIJlYOwqF/XhisKz/Ujdj+/sboaqI06xa2Gp5aGKVg5L6v39bPSUa7Oqk+sIdLY8LjEqC00= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Q61Gs1EA; 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="Q61Gs1EA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3A2C6C116B1; Tue, 25 Nov 2025 18:38:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1764095935; bh=WZL3dOi9JF12AwW63UbE2JZ210f4aDb9qSF2OCoPSt4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q61Gs1EAVRvIBvIG7INuS6659atLrZ3mrAdYqaIQP9T9mulZuDwUaEDa6KxihCImK 3zkNoVetvUYBLQHvkH6Su1aRjeR+rG2rIV3O+dtxWmXfj0fHqYVYAs7x42M4jxGJ41 xdgTe+RwZtde+woZwmlY+uxbGpHPIOMLmhDwpiBVgMD1uNiDoGD1w92TrbWuwztTl8 BdT8zFGja/53Y3N9tJEA+E6oz6xYc3j7rsiKEW+MGSxZbnmHTtUiooOaiJXwgtdJDN P9dnSk8/p4aEkjeRj2n4YMQ4i7GWOclY/dcBy/rnHgtU5L3Ey8DoqRS6kitc+ohHGv DOAFSCTnuI40A== 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 v2 1/5] userfaultfd: move vma_can_userfault out of line Date: Tue, 25 Nov 2025 20:38:36 +0200 Message-ID: <20251125183840.2368510-2-rppt@kernel.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20251125183840.2368510-1-rppt@kernel.org> References: <20251125183840.2368510-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) Signed-off-by: Mike Rapoport (Microsoft) Reviewed-by: Liam R. Howlett --- 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.50.1