From nobody Sat Feb 7 09:59:17 2026 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (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 8BE4B35E556; Tue, 27 Jan 2026 15:06:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.156.1 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769526420; cv=none; b=uyBxIqC5Abq4htMqwNJM0pSVeKaiW71y7QkhWBf3RaQw59KM9yYuqy44Whbw6dIb7VPUVw7btzLU7+wPt64DxntFrDiJ4AcVGChuUf0bXDuQ6DkwzdyhQdEG+kyC30xMH9ts7U8vjoodkOIB8rchS+kkpWjpsTcJUGJEI2Gky4M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769526420; c=relaxed/simple; bh=E3AoU/0zb/U2ONsLGDm0BbnsBUvwFFhH5i9sfX1y5Dg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sNk5i9UeqVinUpRS8p8NvReCKAOEUvH5KH17YnVzILfQfnhz9dkSdeZy/rTXNQe0b/rKPOTpUhkGSom90wwyWdpReUczNbiRb93bm3d2WrpOQCaXPQl51Ouf3xnYjHqs3KOSIlIqEgKsP+swjR8XZTZogN5iTPWPsBNHmfx//S8= 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=gJFysdCM; arc=none smtp.client-ip=148.163.156.1 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="gJFysdCM" Received: from pps.filterd (m0356517.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 60R6lnHn007318; Tue, 27 Jan 2026 15:06:08 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=Iv/QDF4F57jd/avnh h5oZwrTLD1Pr75CntdhW6Ulg6c=; b=gJFysdCMw1sIwtMoLFA4bXWkEuYTlzU+C CLFGgETXrSVVVOgf3oY7SOJLj2LWi06ciKfTNe1X5NqXVMdAdOlpX+geX5Sda+Ck yXyAWtw6viiiN+uJFfsbD9By3horReF8G1QCdCb9BBbAwNnPIdUOVVcB2u6xx3IQ paE2qYQaTohQr5Lj1Qrzy1BiPHcfJ21ynwDvXSZEUaHwlkBEkCXCu9BUQ3ght7HW jc5t1hQ4spxvJNzgsIxIlOozhm9XeJEtltnqRDiVmO77xRfWnN3Yi/BOIVApN2cX VkyYXtvZuJjIcW7f8yVc21ZUZtdc2QAD0eospn857roxBTG+whn2Q== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4bvnt7p1ky-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 27 Jan 2026 15:06:08 +0000 (GMT) Received: from m0356517.ppops.net (m0356517.ppops.net [127.0.0.1]) by pps.reinject (8.18.1.12/8.18.0.8) with ESMTP id 60REpwUh002598; Tue, 27 Jan 2026 15:06:07 GMT Received: from ppma23.wdc07v.mail.ibm.com (5d.69.3da9.ip4.static.sl-reverse.com [169.61.105.93]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4bvnt7p1kq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 27 Jan 2026 15:06:07 +0000 (GMT) Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 60RDK24o026513; Tue, 27 Jan 2026 15:06:06 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4bw9wk91jx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 27 Jan 2026 15:06:05 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 60RF61g019071292 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 27 Jan 2026 15:06:01 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B292E20040; Tue, 27 Jan 2026 15:06:01 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5C7142004B; Tue, 27 Jan 2026 15:06:01 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.87.85.9]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 27 Jan 2026 15:06:01 +0000 (GMT) From: Jens Remus To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, bpf@vger.kernel.org, x86@kernel.org, linux-mm@kvack.org, Steven Rostedt Cc: Jens Remus , Josh Poimboeuf , Masami Hiramatsu , Mathieu Desnoyers , Peter Zijlstra , Ingo Molnar , Jiri Olsa , Arnaldo Carvalho de Melo , Namhyung Kim , Thomas Gleixner , Andrii Nakryiko , Indu Bhagat , "Jose E. Marchesi" , Beau Belgrave , Linus Torvalds , Andrew Morton , Florian Weimer , Kees Cook , "Carlos O'Donell" , Sam James , Dylan Hatch , Borislav Petkov , Dave Hansen , David Hildenbrand , "H. Peter Anvin" , "Liam R. Howlett" , Lorenzo Stoakes , Michal Hocko , Mike Rapoport , Suren Baghdasaryan , Vlastimil Babka , Heiko Carstens , Vasily Gorbik Subject: [PATCH v13 12/18] unwind_user: Enable archs that pass RA in a register Date: Tue, 27 Jan 2026 16:05:47 +0100 Message-ID: <20260127150554.2760964-13-jremus@linux.ibm.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260127150554.2760964-1-jremus@linux.ibm.com> References: <20260127150554.2760964-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: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: gN9Ie2oXE6XmK2pw2kxSTY9196utoeeB X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMTI3MDEyMSBTYWx0ZWRfX8+H9rMU1UBVG CK5vKwe6dghhRv0aEhpPl32RezsG5njc2bVoPZxqxHDt/ZTiHjd3xjC1fwJ9/wrZ1bI6PIFQHEp VuA/xlyfKuRsWxznKqabE8Mp4Z8+QhkMLOpfo83t+2j2NSCzqWm7ScLSNVEd9hg6spJE65OjJc8 KdeCu9e1zobAxHqE3ytt1nAs5zMPRu1iWOPTMgyXDPl/xVBYF0gCQX4DM3sKBgPiC0uSjzQp6u/ x7q3M7rzlR5U2Xhkn4tDioKSl4DBbPWatJfrKH2Hz3FVAyxpjuHrhtAdfGQ4jopp3PY9dmScZht uO+pKk8VhY5B1ohbiyFTlz7UdkRLy+0rNLcO6no5iKQintm/yedr77cBr0W3GTDcR2wF/Z/BSLI H3udbZyodkg4IUpQu/Q9S3lnyc+rmMv1Nmsb63etHcoAtJB5Crdyi5AflgOtPHpwRS/iRn2DQjj eJcVwkofOMw+X2eTJwA== X-Authority-Analysis: v=2.4 cv=Zs3g6t7G c=1 sm=1 tr=0 ts=6978d460 cx=c_pps a=3Bg1Hr4SwmMryq2xdFQyZA==:117 a=3Bg1Hr4SwmMryq2xdFQyZA==:17 a=vUbySO9Y5rIA:10 a=VkNPw1HP01LnGYTKEx00:22 a=VwQbUJbxAAAA:8 a=VnNF1IyMAAAA:8 a=7d_E57ReAAAA:8 a=JfrnYn6hAAAA:8 a=yPCof4ZbAAAA:8 a=mDV3o1hIAAAA:8 a=yMhMjlubAAAA:8 a=Z4Rwk6OoAAAA:8 a=20KFwNOVAAAA:8 a=7mOBRU54AAAA:8 a=BZmVhOMqpLk0IJKryeUA:9 a=jhqOcbufqs7Y1TYCrUUU:22 a=1CNFftbPRP8L7MoqJWF3:22 a=HkZW87K1Qel5hWWM3VKY:22 a=wa9RWnbW_A1YIeRBVszw:22 X-Proofpoint-ORIG-GUID: tbgXXc5An2wsk3YCAZR6rR_lesBL9Ea- X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-01-27_03,2026-01-27_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 lowpriorityscore=0 adultscore=0 phishscore=0 suspectscore=0 bulkscore=0 impostorscore=0 priorityscore=1501 malwarescore=0 spamscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2601150000 definitions=main-2601270121 Content-Type: text/plain; charset="utf-8" Not all architectures have the return address (RA) in user space saved on the stack on function entry, such as x86-64 does due to its CALL instruction pushing the RA onto the stack. Architectures/ABIs, such as s390, also do not necessarily enforce to save the RA in user space on the stack in the function prologue or even at all, for instance in leaf functions. Treat a RA offset from CFA of zero as indication that the RA is not saved (on the stack). For the topmost frame treat it as indication that the RA is in the link/RA register, such as on arm64 and s390, and obtain it from there. For non-topmost frames treat it as error, as the RA must be saved. Additionally allow the SP to be unchanged in the topmost frame, for architectures where SP at function entry =3D=3D SP at call site, such as arm64 and s390. Note that treating a RA offset from CFA of zero as indication that the RA is not saved on the stack additionally allows for architectures, such as s390, where the frame pointer (FP) may be saved without the RA being saved as well. Provided that such architectures represent this in SFrame by encoding the "missing" RA offset using a padding RA offset with a value of zero. Cc: Steven Rostedt Cc: Josh Poimboeuf Cc: Masami Hiramatsu Cc: Mathieu Desnoyers Cc: Peter Zijlstra Cc: Ingo Molnar Cc: Jiri Olsa Cc: Arnaldo Carvalho de Melo Cc: Namhyung Kim Cc: Thomas Gleixner Cc: Andrii Nakryiko Cc: Indu Bhagat Cc: "Jose E. Marchesi" Cc: Beau Belgrave Cc: Jens Remus Cc: Linus Torvalds Cc: Andrew Morton Cc: Florian Weimer Cc: Sam James Cc: Kees Cook Cc: "Carlos O'Donell" Signed-off-by: Jens Remus --- Notes (jremus): Changes in v13: - New patch. Based on my s390 sframe support series patch "unwind_user: Enable archs that pass RA in a register": https://lore.kernel.org/all/20251208171559.2029709-11-jremus@linux.ib= m.com/ include/linux/unwind_user.h | 9 +++++++++ kernel/unwind/sframe.c | 6 ++---- kernel/unwind/user.c | 17 +++++++++++++---- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/include/linux/unwind_user.h b/include/linux/unwind_user.h index 64618618febd..bc2edae39955 100644 --- a/include/linux/unwind_user.h +++ b/include/linux/unwind_user.h @@ -23,6 +23,15 @@ static inline bool unwind_user_at_function_start(struct = pt_regs *regs) #define unwind_user_at_function_start unwind_user_at_function_start #endif =20 +#ifndef unwind_user_get_ra_reg +static inline int unwind_user_get_ra_reg(unsigned long *val) +{ + WARN_ON_ONCE(1); + return -EINVAL; +} +#define unwind_user_get_ra_reg unwind_user_get_ra_reg +#endif + int unwind_user(struct unwind_stacktrace *trace, unsigned int max_entries); =20 #endif /* _LINUX_UNWIND_USER_H */ diff --git a/kernel/unwind/sframe.c b/kernel/unwind/sframe.c index cf353bdbc907..fc905504ddde 100644 --- a/kernel/unwind/sframe.c +++ b/kernel/unwind/sframe.c @@ -243,10 +243,8 @@ static __always_inline int __read_fre(struct sframe_se= ction *sec, dataword_count--; =20 ra_off =3D sec->ra_off; - if (!ra_off) { - if (!dataword_count--) - return -EFAULT; - + if (!ra_off && dataword_count) { + dataword_count--; UNSAFE_GET_USER_INC(ra_off, cur, dataword_size, Efault); } =20 diff --git a/kernel/unwind/user.c b/kernel/unwind/user.c index fdb1001e3750..9ceef9b2b8db 100644 --- a/kernel/unwind/user.c +++ b/kernel/unwind/user.c @@ -48,8 +48,12 @@ static int unwind_user_next_common(struct unwind_user_st= ate *state, } cfa +=3D frame->cfa_off; =20 - /* Make sure that stack is not going in wrong direction */ - if (cfa <=3D state->sp) + /* + * Make sure that stack is not going in wrong direction. Allow SP + * to be unchanged for the topmost frame, by subtracting topmost, + * which is either 0 or 1. + */ + if (cfa <=3D state->sp - state->topmost) return -EINVAL; =20 /* Make sure that the address is word aligned */ @@ -57,8 +61,13 @@ static int unwind_user_next_common(struct unwind_user_st= ate *state, return -EINVAL; =20 /* Get the Return Address (RA) */ - if (get_user_word(&ra, cfa, frame->ra_off, state->ws)) - return -EINVAL; + if (frame->ra_off) { + if (get_user_word(&ra, cfa, frame->ra_off, state->ws)) + return -EINVAL; + } else { + if (!state->topmost || unwind_user_get_ra_reg(&ra)) + return -EINVAL; + } =20 /* Get the Frame Pointer (FP) */ if (frame->fp_off && get_user_word(&fp, cfa, frame->fp_off, state->ws)) --=20 2.51.0