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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 25559FF8860 for ; Mon, 27 Apr 2026 17:17:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=BPNbmpE378SDR0albN3uUkse5xd3MAMC7j8Z5wC8tqY=; b=M2efOpSS/zts0mbaWBx48MDErN +WZcwxMEX6YjBOpaFUuCgnAMb1P5c1x3qT5KWn6MAANqpRRdr0/9QypyL7bo4Zme5FZYJNaGq1MvY jSw61ShYY96zC9ZtrP1BKgFiDzmD8Lrybuj2Bj/c+LsZrze84+a5RWPoI15gm73KBZNZwM/RoI7Uq 5ITfV/PmhpmVTfZU/4ciI0CUnleG1mOfhdwMhUgI2BlWGFfezWtVCt9wQC9FrFK237suj01vPDHRh T/mJaay1i/u3vkuTF0oWMyKBS9bTXy9GQ9FI6HQq3Y8U/CXEKEEPfzEmIpGF5qEILTDCK1xnEPKPd O/UyZQfg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1wHPa7-0000000HQPZ-2w9L; Mon, 27 Apr 2026 17:17:15 +0000 Received: from sea.source.kernel.org ([172.234.252.31]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1wHPa5-0000000HQOC-2FiG; Mon, 27 Apr 2026 17:17:14 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id 12679437DE; Mon, 27 Apr 2026 17:17:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AC974C2BCB5; Mon, 27 Apr 2026 17:16:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777310232; bh=745VKRe61Lf8afs4o89V2mPmcfGcqMzEwAyCkwUFzR4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ccnzw+capg6i/qeCJEEZZnJkaeh2P8NEABjGdQ84B8/8ElHQuhaIfwHK4KyIZjuzW fShA2udW2NQ0Ct7kJfcn/Kb043ljqkq7hTjPsRqwiNPGH9FmgvMogRNjEATWGrG26g 6zW5qtX0OAMj+t+S60HkjDsyGYMrisyc3m/7o9VPvVvQnsaPOrT5y+ZTzyh8Xto7fx AWFGU9d3c0Mo3tNoddRUR02dQmZ5LMWSNNkmTWtszo39IueJ4zsAp4+3T5NcIhGntz oVxgjUbjxhRTuJF8KweLMZaWvhi+rfu1/RR3XrUIQOPEazAae4t8SpoXJ0czDjJbhT 7qOjNG8l7cqnA== From: "Christophe Leroy (CS GROUP)" To: Yury Norov , Andrew Morton , Linus Torvalds , David Laight , Thomas Gleixner Cc: "Christophe Leroy (CS GROUP)" , linux-alpha@vger.kernel.org, linux-kernel@vger.kernel.org, linux-snps-arc@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, sparclinux@vger.kernel.org, linux-um@lists.infradead.org, dmaengine@vger.kernel.org, linux-efi@vger.kernel.org, linux-fsi@lists.ozlabs.org, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, linux-wpan@vger.kernel.org, netdev@vger.kernel.org, linux-wireless@vger.kernel.org, linux-spi@vger.kernel.org, linux-media@vger.kernel.org, linux-staging@lists.linux.dev, linux-serial@vger.kernel.org, linux-usb@vger.kernel.org, xen-devel@lists.xenproject.org, linux-fsdevel@vger.kernel.org, ocfs2-devel@lists.linux.dev, bpf@vger.kernel.org, kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-x25@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-sound@vger.kernel.org, sound-open-firmware@alsa-project.org, linux-csky@vger.kernel.org, linux-hexagon@vger.kernel.org, loongarch@lists.linux.dev, linux-m68k@lists.linux-m68k.org, linux-openrisc@vger.kernel.org, linux-parisc@vger.kernel.org, linux-sh@vger.kernel.org, linux-arch@vger.kernel.org Subject: [RFC PATCH v1 1/9] uaccess: Split check_zeroed_user() out of usercopy.c Date: Mon, 27 Apr 2026 19:13:42 +0200 Message-ID: X-Mailer: git-send-email 2.49.0 In-Reply-To: References: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4389; i=chleroy@kernel.org; h=from:subject:message-id; bh=745VKRe61Lf8afs4o89V2mPmcfGcqMzEwAyCkwUFzR4=; b=owGbwMvMwCV2d0KB2p7V54MZT6slMWS+nxmtvkzq83WmyICs092/GNmylHyYwx1uy/R0rjqso Tc19NiJjlIWBjEuBlkxRZbj/7l3zej6kpo/dZc+zBxWJpAhDFycAjCRrBxGhr1T21lnr9ow8bLw mlcX9LlDfR53LmTbs/fCv2dGAh23RTkY/gpGWFpU+sbMuNm2suHwI9OT2xZsfrLc1dbD4+idxHd 72DkA X-Developer-Key: i=chleroy@kernel.org; a=openpgp; fpr=10FFE6F8B390DE17ACC2632368A92FEB01B8DD78 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260427_101713_623666_383C1FCF X-CRM114-Status: GOOD ( 12.56 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Until commit f5a1a536fa14 ("lib: introduce copy_struct_from_user() helper"), lib/usercopy.c was containing only the out-line version of user copy fonctions. That commit added function check_zeroed_user() into the same file. Move that function into a new file named usercheck.c, so that next patch can change usercopy.c build to a conditional build. Signed-off-by: Christophe Leroy (CS GROUP) --- lib/Makefile | 1 + lib/{usercopy.c => usercheck.c} | 22 ------------ lib/usercopy.c | 62 --------------------------------- 3 files changed, 1 insertion(+), 84 deletions(-) copy lib/{usercopy.c => usercheck.c} (73%) diff --git a/lib/Makefile b/lib/Makefile index f33a24bf1c19..7c0334d7675b 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -59,6 +59,7 @@ obj-y += bcd.o sort.o parser.o debug_locks.o random32.o \ percpu-refcount.o rhashtable.o base64.o \ once.o refcount.o rcuref.o usercopy.o errseq.o bucket_locks.o \ generic-radix-tree.o bitmap-str.o +obj-y += usercheck.o obj-y += string_helpers.o obj-y += hexdump.o obj-$(CONFIG_TEST_HEXDUMP) += test_hexdump.o diff --git a/lib/usercopy.c b/lib/usercheck.c similarity index 73% copy from lib/usercopy.c copy to lib/usercheck.c index b00a3a957de6..15b0d9a18435 100644 --- a/lib/usercopy.c +++ b/lib/usercheck.c @@ -2,32 +2,10 @@ #include #include #include -#include -#include #include -#include -#include #include #include -/* out-of-line parts */ - -#if !defined(INLINE_COPY_FROM_USER) -unsigned long _copy_from_user(void *to, const void __user *from, unsigned long n) -{ - return _inline_copy_from_user(to, from, n); -} -EXPORT_SYMBOL(_copy_from_user); -#endif - -#if !defined(INLINE_COPY_TO_USER) -unsigned long _copy_to_user(void __user *to, const void *from, unsigned long n) -{ - return _inline_copy_to_user(to, from, n); -} -EXPORT_SYMBOL(_copy_to_user); -#endif - /** * check_zeroed_user: check if a userspace buffer only contains zero bytes * @from: Source address, in userspace. diff --git a/lib/usercopy.c b/lib/usercopy.c index b00a3a957de6..7a93f56d81dd 100644 --- a/lib/usercopy.c +++ b/lib/usercopy.c @@ -1,14 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 -#include -#include #include -#include -#include -#include -#include -#include #include -#include /* out-of-line parts */ @@ -27,57 +19,3 @@ unsigned long _copy_to_user(void __user *to, const void *from, unsigned long n) } EXPORT_SYMBOL(_copy_to_user); #endif - -/** - * check_zeroed_user: check if a userspace buffer only contains zero bytes - * @from: Source address, in userspace. - * @size: Size of buffer. - * - * This is effectively shorthand for "memchr_inv(from, 0, size) == NULL" for - * userspace addresses (and is more efficient because we don't care where the - * first non-zero byte is). - * - * Returns: - * * 0: There were non-zero bytes present in the buffer. - * * 1: The buffer was full of zero bytes. - * * -EFAULT: access to userspace failed. - */ -int check_zeroed_user(const void __user *from, size_t size) -{ - unsigned long val; - uintptr_t align = (uintptr_t) from % sizeof(unsigned long); - - if (unlikely(size == 0)) - return 1; - - from -= align; - size += align; - - if (!user_read_access_begin(from, size)) - return -EFAULT; - - unsafe_get_user(val, (unsigned long __user *) from, err_fault); - if (align) - val &= ~aligned_byte_mask(align); - - while (size > sizeof(unsigned long)) { - if (unlikely(val)) - goto done; - - from += sizeof(unsigned long); - size -= sizeof(unsigned long); - - unsafe_get_user(val, (unsigned long __user *) from, err_fault); - } - - if (size < sizeof(unsigned long)) - val &= aligned_byte_mask(size); - -done: - user_read_access_end(); - return (val == 0); -err_fault: - user_read_access_end(); - return -EFAULT; -} -EXPORT_SYMBOL(check_zeroed_user); -- 2.49.0