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 61C0E420E9D; Fri, 21 Aug 2026 19:53:46 +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=1787342030; cv=none; b=PR0l3NXXHwfulewVCLv5vCJxmY0rLJjg9Y8ZXSuahfbRzCL1RYeKLr0uEmfUmLTE9jOvuLWLTjeBZalx14KXKn/a/qyWUxD4S6d4AKHdyf5iXsJSXeZ1Y01Ahj5V5RUTN9yjt0Xjdm7Xgy+GGVniA4jVwR5ofSrp4IosxfXrd9M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787342030; c=relaxed/simple; bh=O0SPzgf2EQOjoZmBiRzcLTE+OD7iWiK8l5BG6BpKfwo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GAKGTM5FG8dznr5pNWu0JJ3Vx4RaiisPyewPuI+ft/1wp1BmABL/W8GE0yealzwvBfCeeKDaEzupJ52XImp9zw0rxp+07mqNLGzJrfLuaQVHRCVYWiRawVsxxBC2+GAejuRvwaTs2Ao826t9enzgl7YJCVJEDDpqtrhNyV9Y4+M= 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=i77TMcAU; 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="i77TMcAU" Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 67LIVl2R2387663; Fri, 21 Aug 2026 19:53:15 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=Uy5/N5srkznANn5S/ Kowiheg8PnzcVvDEkJYvUPZGHQ=; b=i77TMcAU/Pas0MUbV9e0PsBF8MGyKTcoA 3mX7s8j8atxV0xDRtb77jTZ5m3LFU6+ZgZUI9Oz5mqRlOizPTvjgdQAO+/aVs/W8 F1n5h90Rk2ldP5BN4xN2c5KgQOF4mxw5oUiJ9PEmsK1383/I/s0J5aI1rXIHi5i1 +zvsYLY+CnnhJ76PZmsjudnrTJqjZ5vYc1pr94AOnVVvfuaecWqBbRTz13OuPMLU zaPJy+cEgQ0XNIcRF6ODLuLt8iFSClqPjY/rxSLu9s3H4xNfmfHkFNgIcQ/BX6pq lHpMFQb36A9ZmEUy7TJoWogv7OWF/qBex29ouOBE2F0IN1E0kVB3g== Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4g4yu4kns9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 21 Aug 2026 19:53:15 +0000 (GMT) Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.18.1.7/8.18.1.7) with ESMTP id 67LJfGoj008687; Fri, 21 Aug 2026 19:53:14 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 4g354yxdws-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 21 Aug 2026 19:53:14 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 67LJrAum28312130 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Aug 2026 19:53:10 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4732320040; Fri, 21 Aug 2026 19:53:10 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0625A20043; Fri, 21 Aug 2026 19:53:10 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.87.85.9]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 21 Aug 2026 19:53:09 +0000 (GMT) From: Jens Remus To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-s390@vger.kernel.org, x86@kernel.org, Steven Rostedt , Josh Poimboeuf , Peter Zijlstra , Mathieu Desnoyers Cc: Jens Remus , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Ilya Leoshkevich , Indu Bhagat , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Namhyung Kim , Andrii Nakryiko , Kees Cook , Sam James , Fangrui Song , "Steven Rostedt (Google)" Subject: [RFC PATCH v2 18/24] x86/uaccess: Add unsafe_copy_from_user() implementation Date: Fri, 21 Aug 2026 21:52:53 +0200 Message-ID: <20260821195259.2688377-19-jremus@linux.ibm.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260821195259.2688377-1-jremus@linux.ibm.com> References: <20260821195259.2688377-1-jremus@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-s390@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=CpuPtH4D c=1 sm=1 tr=0 ts=6a88acab cx=c_pps a=aDMHemPKRhS1OARIsFnwRA==:117 a=aDMHemPKRhS1OARIsFnwRA==:17 a=Sv0fKeRqtYgA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=RzCfie-kr_QcCd8fBx8p:22 a=VwQbUJbxAAAA:8 a=VnNF1IyMAAAA:8 a=meVymXHHAAAA:8 a=pGLkceISAAAA:8 a=gpC398cPzQKiNBT45cIA:9 a=2JgSa4NbpEOStq-L5dxp:22 X-Proofpoint-ORIG-GUID: sBCi4w2KoxmTUXnn0_0RtLncFVsZNQzo X-Proofpoint-GUID: sPjoGvRGfAWM15i-VustWF0lJ8p8_rdW X-Proofpoint-Spam-Info: AW1haW4tMjYwODIxMDE1NSBTYWx0ZWRfX0qCDoMY+00of ctdtxIBGk9NFW42OBk7P2uso30HM7Dsjb1O+WUj9ZPszRu54jEdi7jgSbbhLBvIl/pth37dikRP nDHrsFFj87/FaNoqs9Yp/W1/Q0DZj6w= X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwODIxMDE1NSBTYWx0ZWRfX3Yd14KcwHlvk qzbGe92HjycmeduiWearIOfZyNKiHAQn+Lfizu/dzNmap8K0O6scMEug4m+5aP7Y0aStuAGnrSj 5s9AsJWOOhherYY/E5ZgfS0RY2ZBFCTPSNaWFT4B78l36ESp+ypVPEjzKNaciLnYVX/23Q5xdvk /nvEdM0lLSBVtBjUsnA4zkn8jhSZ3/muqSum+upgaLX+gZ59/ybSEKnD3saq+4jjKl+CTmxYlwV sHB8SNCPHW3HZsfFVsPE8Rk8Tm7/zVI9NyU2HYE9hzdlCY8ENOP7zjS72UThqfINvNyGUCmyJqy VlcOErGmxy1hXyv7lIIZCtpmqFvjqfQEtEVB6kh7GD6bAP5qrhBEQ0W1wwCG7NlM6Z7aKCkurtD IC1rK6vkUUZ2HwuOKWDfTWPXNdQaR0OrrDdPxiVwzHUKF3uaWI116hnZjGJHTFwnidS2SK3/N4W MEdpWxGGFMJlBJii2mQ== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-08-21_06,2026-08-21_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 adultscore=0 bulkscore=0 malwarescore=0 phishscore=0 lowpriorityscore=0 spamscore=0 clxscore=1015 priorityscore=1501 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2608210155 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) Reviewed-by: Indu Bhagat Signed-off-by: Jens Remus --- Notes (jremus): Cherry-picked from "[PATCH v16 00/20] unwind_deferred: Implement sframe handling" series: https://lore.kernel.org/all/20260521142546.3908498-5-jremus@linux.ibm.com/ 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 3a0dd3c2b233..235886106f31 100644 --- a/arch/x86/include/asm/uaccess.h +++ b/arch/x86/include/asm/uaccess.h @@ -598,7 +598,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); \ @@ -606,15 +606,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); \ + const 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.53.0