From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (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 B67F03CAE95 for ; Fri, 17 Apr 2026 15:08:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776438537; cv=none; b=CenHtcMfao9vP/kEtSHu2MFS5KRDv10NQak2xa+L2rNEH+JfOoO1hmCfkgFAxnPClgFwYsKabH3g2xWL6cLRnfgLpdXsnJxezJYf2w0Bh9JcHpLGWk+BqC0D/CsyK7HdEFgfCOEICCp8D4R3pr0rIqbwDKDlvR2EjeGe3TALkA8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776438537; c=relaxed/simple; bh=j9S7XoBHRXniwPgIJFDk5NPcfH9xwCMZ3L+l+u5+avg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UBQlniNXiy6g2kTD65RHsNYEj0uKRoWw4l9yB9Fa54TncuLYxzuBWbEhNGzPUAOxqNshFta2KqYW237gIBVgqT1ViQW8WV+2c0D5WV6KjqETqkt86U6y1xUdpWPX/fQGRSJAkvPR3dnRXH+YtsdYG1cBJYe5CBnZscXL2sLrqXg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=XtWcRed5; arc=none smtp.client-ip=148.163.158.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="XtWcRed5" Received: from pps.filterd (m0353725.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 63H9fZku1733164; Fri, 17 Apr 2026 15:08:35 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=UKca5QJQ1hxgTQwHY K4x+LZXd06rJ/B93mnhlgY1RYI=; b=XtWcRed5o6MfKsH6GiH1k3GOFR1dcvfHd N8kuTawPEG3JQy5Qigxb4ABu4RjjQXsfWeMaogbBNUl0GzUtLSJvSmSHAkmvfwt2 A1AsV0fyxJfeCKgh7z4njQB43ndofe+1xpxHT6LGNq6R7Fj7QQJV3tGDVl7IHuZT FXxyRuwhuLJUNCErvwpp9o4SLtHGxD+jdNl/P5jJFedTzjNLZsBnncP9LFAKwHsu P4+z9EfEPgxgiOLTvx2bRwUfwlvkOpu88Z3YVjS9w9K7gik3vSqASOPSK6hMdWlG /2zyKnKJyRJFEH1y6L8zypQ28O5tFFFUrECsYa3ErEkeg5RhznTzQ== Received: from ppma21.wdc07v.mail.ibm.com (5b.69.3da9.ip4.static.sl-reverse.com [169.61.105.91]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4dh89mhw5h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 17 Apr 2026 15:08:34 +0000 (GMT) Received: from pps.filterd (ppma21.wdc07v.mail.ibm.com [127.0.0.1]) by ppma21.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 63HCQfqh003586; Fri, 17 Apr 2026 15:08:34 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4dg1mnqpda-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 17 Apr 2026 15:08:33 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 63HF8U8737421500 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 17 Apr 2026 15:08:30 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0B8A120043; Fri, 17 Apr 2026 15:08:30 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D09E42004B; Fri, 17 Apr 2026 15:08:29 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.87.85.9]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 17 Apr 2026 15:08:29 +0000 (GMT) From: Jens Remus To: Catalin Marinas , Will Deacon , Steven Rostedt , Josh Poimboeuf , Indu Bhagat , Peter Zijlstra , Dylan Hatch , Weinan Liu Cc: Jens Remus , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Heiko Carstens , Ilya Leoshkevich Subject: [PATCH v1 2/4] arm64/uaccess: Add unsafe_copy_from_user() implementation Date: Fri, 17 Apr 2026 17:08:25 +0200 Message-ID: <20260417150827.1183376-3-jremus@linux.ibm.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260417150827.1183376-1-jremus@linux.ibm.com> References: <20260417150827.1183376-1-jremus@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Authority-Analysis: v=2.4 cv=I/dVgtgg c=1 sm=1 tr=0 ts=69e24cf3 cx=c_pps a=GFwsV6G8L6GxiO2Y/PsHdQ==:117 a=GFwsV6G8L6GxiO2Y/PsHdQ==:17 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=V8glGbnc2Ofi9Qvn3v5h:22 a=VwQbUJbxAAAA:8 a=VnNF1IyMAAAA:8 a=DR0qyCAueFOdPjQfhtcA:9 X-Proofpoint-GUID: VN9voE7jdsiIXsDy1wB_9tHxLAk6-xBY X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDE3MDE0OSBTYWx0ZWRfX8Y4dfi4g+C4l LIqjVSU/ldhZASrP7sosUM6uB6+TgFVMy765zyYhcLmysM5RhlC8VYnven32mUaUdk4pua/womj gTxVXgAbZdPPcFxMYgG3qeZZmP7hbcXKIU2T7vGAMvUoBsp0XB8NggB5oLxiiNZLVGHIasS+Smg yhQ/I74huTn/vfD+J9FSlX3sFsjeZR+X7mn4bE68+2wCJO58Lru7yFFBJltds7yfzqDek88nOad /nX75gbqcQhFMBXTifZ9H8EiXqt50j+oZeafMgcsHYsrbp5EW5UiPMTMBLitr3PWJUcoRLppgLD MW84nipmN1R71sLWTapTUzwFNtgdq36L/p08qi6yaZBcOXWxdlKOeTRD5XLe0nUOREn2H5nKoqP 6bwlttkIRVyLcRNBPvwQ1gg5BOdrno1dskGEwJOlB1oJyR4lz2KJBSHeEPvkRAhIA7y3Pq1dLTV GeOKM04tNJAcY6MVxUA== X-Proofpoint-ORIG-GUID: baHr-ceya3FGTbt7zWUuPEtJIg5w4-or X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-04-17_01,2026-04-17_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 bulkscore=0 clxscore=1011 adultscore=0 lowpriorityscore=0 suspectscore=0 impostorscore=0 phishscore=0 spamscore=0 priorityscore=1501 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2604070000 definitions=main-2604170149 This replicates Josh's x86 patch "x86/uaccess: Add unsafe_copy_from_user() implementation" [1] for arm64. Add an arm64 implementation of unsafe_copy_from_user() similar to the existing unsafe_copy_to_user(). For this purpose rename the unsafe_copy_loop() helper to unsafe_copy_to_user_loop() and introduce a unsafe_copy_from_user_loop() helper. While at it rename the unsafe_copy_to_user() local variables __ucu_{dst|src|len} to __{dst|src|len} and change their pointer type to void * to align to the x86 patch. [1]: x86/uaccess: Add unsafe_copy_from_user() implementation, https://lore.kernel.org/all/20251119132323.1281768-4-jremus@linux.ibm.com/ Signed-off-by: Jens Remus --- arch/arm64/include/asm/uaccess.h | 39 ++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h index 9810106a3f66..37d7d16b86a9 100644 --- a/arch/arm64/include/asm/uaccess.h +++ b/arch/arm64/include/asm/uaccess.h @@ -437,7 +437,7 @@ static inline void user_access_restore(unsigned long enabled) { } * 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); \ @@ -445,15 +445,34 @@ static inline void user_access_restore(unsigned long enabled) { } 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) #define INLINE_COPY_TO_USER -- 2.51.0