From mboxrd@z Thu Jan 1 00:00:00 1970 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 4D2042D2481; Mon, 17 Nov 2025 11:46:46 +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=1763380006; cv=none; b=Ac14HjjpBHH5EJS7Y2LZ7uJIeH7/tTQbQJlayDvuvERVF5YEceXCjANALmiWccgAL2FZdgIK6/l20Hgxveonlb//hXhOIH5fxqhGYTRscKRE9GBMNSjWTaS3NN12wRLYFTqWZEmikNoyCauotd8avCG/yiJDk/utarW/WcIrDiE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763380006; c=relaxed/simple; bh=IWNZrq9x24Lzm+UDNOmC86glMjR/3VEA7eqKJIQ4L98=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=A7sTjZlGudkwKr18WoNp2IJVu5bM9XJ6WL2ajsAPNsrmCF3HtHd2vceLsRwJu9HNWSsxf2y9kWGg/GxP33oZ8S2geOb+vkO7jT7dvkHeKASDKwNRJsaAUGCgldFno+ZJ/BjVa9LwWcezf4wR3NX1yMiqbNMNUCikUKmblYOAPs4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IIkB+ZO6; 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="IIkB+ZO6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0743EC2BC86; Mon, 17 Nov 2025 11:46:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1763380005; bh=IWNZrq9x24Lzm+UDNOmC86glMjR/3VEA7eqKJIQ4L98=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IIkB+ZO6MY7IVFrcCRruJ75sEdHUJaBxiYEX3wpNhlMwR+KfO5mS+r/f4LAx/Bg1B gzoJ+o9mRcq0sk2EJsHo+hakZ6ACSrwuZvCb5dXrEvgB3m/9EaqNQS1n0bI4NUwlAv mJ7ZHwywcg3Ebnm/YytQK6R7fybylkM696PnKCwNMNTmiRX29PgXMr8M/IAUhVDZ2D B5gPzQG4AakfJizYk9MfNtMVw3bti63xXdQQsiRW9B+1OcbquuQdzhwnYNlgNP0m4M MM1hucigpwnuJVRP69L3D7uGZWm54HKgANVCUgTBHOJ76czq+vKF5TUD3sqy5tnXM/ apk0eplUMDpCQ== From: Mike Rapoport To: linux-mm@kvack.org Cc: Andrea Arcangeli , Andrew Morton , Baolin Wang , David Hildenbrand , Hugh Dickins , "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 Subject: [RFC PATCH 1/4] userfaultfd: move vma_can_userfault out of line Date: Mon, 17 Nov 2025 13:46:28 +0200 Message-ID: <20251117114631.2029447-2-rppt@kernel.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20251117114631.2029447-1-rppt@kernel.org> References: <20251117114631.2029447-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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. 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_struct *vma) return vma->vm_flags & __VM_UFFD_FLAGS; } -static inline bool vma_can_userfault(struct vm_area_struct *vma, - vm_flags_t vm_flags, - bool wp_async) -{ - vm_flags &= __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 == 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); 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, unsigned long dst_start, return moved ? moved : err; } +bool vma_can_userfault(struct vm_area_struct *vma, vm_flags_t vm_flags, + bool wp_async) +{ + vm_flags &= __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 == 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) { -- 2.50.1