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 1F781157A72; Tue, 8 Jul 2025 02:11:58 +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=1751940719; cv=none; b=aMSEA2j1JS2KRWEmpzhor+V+LUe4fnNPvJ7fJlWWtjtbseuEAvDd2kc/pVY5Pz1dCBPMMzXu/4ZzwX+Cyn2UIkGBsiXVD7u+x/iqmGDcWXKHgyHiO2y6CgrJVqDlqbxS8/l0ZAtMt17mGEn2AZyCgNkcUZUgWN/R1Ao/d9etytM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751940719; c=relaxed/simple; bh=ckTATXCHrvGOC+WZsqQof/3QKuBCz763BBzol3sDKjI=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=QoQihxQrEwKT3VfmDk4mazVay0qOzqXjceK4nxB1sdLCZeO/xh0fixhqJ3zBP+22rFA3YfyF5vwuJ/9aJhpMSU5UOXsX1pulNfnDAwYoqsn7PAvBsYX5e8gRRlFx9KxMddO0m1AABcRyO8hIkBc8197cRYSFWbb12XkjcvxAFj8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ofnIIwI7; 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="ofnIIwI7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id ACE87C113CF; Tue, 8 Jul 2025 02:11:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751940718; bh=ckTATXCHrvGOC+WZsqQof/3QKuBCz763BBzol3sDKjI=; h=Date:From:To:Cc:Subject:References:From; b=ofnIIwI7PS1T8WQKSafoAShNse+Hq8QtKkuNEiJif+r0N2fw3K4arHLO9yfL6gAu4 w4+hDxz519FskchMvlmWy3OiHR6/Z8TJez1DhNSfuGHQeDBaxEHmuhaDDdPifAT9mX oYpKKLgpQqD9nsIwyO3NB+iEWq+0MyTYr/Kqh83xxW3iRAfpmRflP7lijK/r/aO76b IDj7EPOflJc6Ke2qGjQ3OyrI2YFcYyT3ntecH0aPF4nzeQlA2gKxzAPILckuYm1Dhm t48UEppWpt34tF/kXehmzupVbXa0dcbuliLSt+uq95KmlLyWOs4eZJtqs9ra+F53Zg 5jGoKIIhmuwwQ== Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1uYxoN-00000000Dc3-06pt; Mon, 07 Jul 2025 22:11:59 -0400 Message-ID: <20250708021158.877986536@kernel.org> User-Agent: quilt/0.68 Date: Mon, 07 Jul 2025 22:11:18 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, bpf@vger.kernel.org, x86@kernel.org Cc: Masami Hiramatsu , Mathieu Desnoyers , Josh Poimboeuf , Peter Zijlstra , Ingo Molnar , Jiri Olsa , Namhyung Kim , Thomas Gleixner , Andrii Nakryiko , Indu Bhagat , "Jose E. Marchesi" , Beau Belgrave , Jens Remus , Linus Torvalds , Andrew Morton , Jens Axboe , Florian Weimer , Sam James Subject: [PATCH v8 03/12] x86/uaccess: Add unsafe_copy_from_user() implementation References: <20250708021115.894007410@kernel.org> Precedence: bulk X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 From: Josh Poimboeuf Add an x86 implementation of unsafe_copy_from_user() similar to the existing unsafe_copy_to_user(). Signed-off-by: Josh Poimboeuf Signed-off-by: Steven Rostedt (Google) --- arch/x86/include/asm/uaccess.h | 39 +++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h index 3a7755c1a441..3caf02d0503e 100644 --- a/arch/x86/include/asm/uaccess.h +++ b/arch/x86/include/asm/uaccess.h @@ -599,7 +599,7 @@ _label: \ * We want the unsafe accessors to always be inlined and use * the error labels - thus the macro games. */ -#define unsafe_copy_loop(dst, src, len, type, label) \ +#define unsafe_copy_to_user_loop(dst, src, len, type, label) \ while (len >= sizeof(type)) { \ unsafe_put_user(*(type *)(src),(type __user *)(dst),label); \ dst += sizeof(type); \ @@ -607,15 +607,34 @@ _label: \ len -= sizeof(type); \ } -#define unsafe_copy_to_user(_dst,_src,_len,label) \ -do { \ - char __user *__ucu_dst = (_dst); \ - const char *__ucu_src = (_src); \ - size_t __ucu_len = (_len); \ - unsafe_copy_loop(__ucu_dst, __ucu_src, __ucu_len, u64, label); \ - unsafe_copy_loop(__ucu_dst, __ucu_src, __ucu_len, u32, label); \ - unsafe_copy_loop(__ucu_dst, __ucu_src, __ucu_len, u16, label); \ - unsafe_copy_loop(__ucu_dst, __ucu_src, __ucu_len, u8, label); \ +#define unsafe_copy_to_user(_dst, _src, _len, label) \ +do { \ + void __user *__dst = (_dst); \ + const void *__src = (_src); \ + size_t __len = (_len); \ + unsafe_copy_to_user_loop(__dst, __src, __len, u64, label); \ + unsafe_copy_to_user_loop(__dst, __src, __len, u32, label); \ + unsafe_copy_to_user_loop(__dst, __src, __len, u16, label); \ + unsafe_copy_to_user_loop(__dst, __src, __len, u8, label); \ +} while (0) + +#define unsafe_copy_from_user_loop(dst, src, len, type, label) \ + while (len >= sizeof(type)) { \ + unsafe_get_user(*(type *)(dst), (type __user *)(src), label); \ + dst += sizeof(type); \ + src += sizeof(type); \ + len -= sizeof(type); \ + } + +#define unsafe_copy_from_user(_dst, _src, _len, label) \ +do { \ + void *__dst = (_dst); \ + void __user *__src = (_src); \ + size_t __len = (_len); \ + unsafe_copy_from_user_loop(__dst, __src, __len, u64, label); \ + unsafe_copy_from_user_loop(__dst, __src, __len, u32, label); \ + unsafe_copy_from_user_loop(__dst, __src, __len, u16, label); \ + unsafe_copy_from_user_loop(__dst, __src, __len, u8, label); \ } while (0) #ifdef CONFIG_CC_HAS_ASM_GOTO_OUTPUT -- 2.47.2