From nobody Thu Sep 24 17:02:54 2026 Received: from canpmsgout04.his.huawei.com (canpmsgout04.his.huawei.com [113.46.200.219]) (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 ABFF436A03B for ; Tue, 22 Sep 2026 03:55:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.219 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790049308; cv=none; b=uH19IuwPc0dw3fTrukSXfNGorG7oTTEujF3qdAnv7vDuDSLypGvINDPW8/r2wPUUiKkBN9MiAJRA8SQVKAw/P7obGI/qL3XsAXGFlHXqnZhF8YQT9XhlTNYnlaCIr+kAjO3pHoRvOcLLgF40dNFv1xC+aqBQAPArBpyyQoGAoIM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790049308; c=relaxed/simple; bh=fDpfYkO1domCklYrNl+2fQmAn55V7a7r7iSqEQJkOSk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Jtcc/8v7knQWvKcZtxJjsYQQv/5ZI3swZn4vJO+TuLX2GxWjcEfuPitsfkJscGiNe8f2jgumSn//oAMAHJ780UjFtBafHG9X3qPhAAk5XA6YTES4nmrH0H07XzIwClyM7fVKTDY97If8Nfl1or/pFSX4y5vRG4j16rwulBG/22U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=YynlK7q2; arc=none smtp.client-ip=113.46.200.219 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="YynlK7q2" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=tHLvOEpJte+v4ZO1cJMq4vlDDVr7pXlP7ArOasD0uVI=; b=YynlK7q2swGyzTycfM3v9tvCkDDI3gY8vK4dsYYsmtf4Btr624h2j516phda/an5vR7KY3gPO BwSh82STuYGinpOaWvEsVbK+GiFKO18a7DzrhnsRIf7FwQ/2v31OBK2IkAzrAznRaEEQSPlakLs VCEi0GxehB+dJP0c4RNfSAQ= Received: from mail.maildlp.com (unknown [172.19.162.144]) by canpmsgout04.his.huawei.com (SkyGuard) with ESMTPS id 4hpmDF52hGz1prKW; Tue, 22 Sep 2026 11:43:57 +0800 (CST) Received: from kwepemk200008.china.huawei.com (unknown [7.202.194.74]) by mail.maildlp.com (Postfix) with ESMTPS id 35E4F4056D; Tue, 22 Sep 2026 11:55:01 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemk200008.china.huawei.com (7.202.194.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.45; Tue, 22 Sep 2026 11:55:00 +0800 From: Jinjie Ruan To: , , , , , , , , , , , , , , , , , , , , , , , CC: Subject: [PATCH v19 01/14] arm64: ptrace: Fix redundant syscall exit stop for PTRACE_SYSEMU_SINGLESTEP Date: Tue, 22 Sep 2026 11:54:57 +0800 Message-ID: <20260922035510.1090299-2-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260922035510.1090299-1-ruanjinjie@huawei.com> References: <20260922035510.1090299-1-ruanjinjie@huawei.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-ClientProxiedBy: kwepems200001.china.huawei.com (7.221.188.67) To kwepemk200008.china.huawei.com (7.202.194.74) Content-Type: text/plain; charset="utf-8" PTRACE_SYSEMU_SINGLESTEP sets both _TIF_SYSCALL_EMU and _TIF_SINGLESTEP. arm64 currently reports a syscall exit stop whenever _TIF_SINGLESTEP is set, regardless of emulation state. This violates the ptrace man page (Syscall-stops section): "If the tracee was restarted by PTRACE_SYSCALL or PTRACE_SYSEMU, the tracee enters syscall-enter-stop just prior to entering any system call (which will not be executed if the restart was using PTRACE_SYSEMU, regardless of any change made to registers at this point or how the tracee is restarted after this stop). ... If the tracee is continued using any other method (including PTRACE_SYSEMU), no syscall-exit-stop occurs. Note that all mentions PTRACE_SYSEMU apply equally to PTRACE_SYSEMU_SINGLESTEP." Fix by introducing report_single_step(), which returns false when _TIF_SYSCALL_EMU is set, skipping the redundant exit stop. Cc: Mark Rutland Cc: Will Deacon Cc: Catalin Marinas Cc: Oleg Nesterov Fixes: ac2081cdc4d9 ("arm64: ptrace: Consistently use pseudo-singlestep exc= eptions") Reviewed-by: Ada Couprie Diaz Reviewed-by: Linus Walleij Reviewed-by: Yeoreum Yun Signed-off-by: Jinjie Ruan Tested-by: Kees Cook --- arch/arm64/kernel/ptrace.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c index f743cbec1c3a..96462de75d4b 100644 --- a/arch/arm64/kernel/ptrace.c +++ b/arch/arm64/kernel/ptrace.c @@ -2482,16 +2482,26 @@ int syscall_trace_enter(struct pt_regs *regs) return regs->syscallno; } =20 +static inline bool report_single_step(unsigned long flags) +{ + if (flags & _TIF_SYSCALL_EMU) + return false; + + return flags & _TIF_SINGLESTEP; +} + void syscall_trace_exit(struct pt_regs *regs) { unsigned long flags =3D read_thread_flags(); + bool step; =20 audit_syscall_exit(regs); =20 if (flags & _TIF_SYSCALL_TRACEPOINT) trace_sys_exit(regs, syscall_get_return_value(current, regs)); =20 - if (flags & (_TIF_SYSCALL_TRACE | _TIF_SINGLESTEP)) + step =3D report_single_step(flags); + if (step || flags & _TIF_SYSCALL_TRACE) report_syscall_exit(regs); =20 rseq_syscall(regs); --=20 2.34.1 From nobody Thu Sep 24 17:02:54 2026 Received: from canpmsgout08.his.huawei.com (canpmsgout08.his.huawei.com [113.46.200.223]) (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 82BEB395273 for ; Tue, 22 Sep 2026 03:55:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.223 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790049309; cv=none; b=b0MHd5XV/bjac9PF0+h9owmPdIfrEL1BNrK50iSre+UuF6Uayxk4uScDWguUOMxNX+GPvmsNCmtU9vGbWD9cRdPOxqGJyIzPytrUD3gNCUNvkBWGotukY+WTIdw6BdenTgbWe8DLQGdZ6CtUxBYGkPN7sfVHVFg3eLPZakLmC4k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790049309; c=relaxed/simple; bh=qP7Ga2l4wky+Brm04a0wxnxWuLo1mllbMEOdTZXUKw4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=V1Fc6dINu27uBzHQpXYhil6FCq7tgrzRbayV6QMUy70VhDjNaw8B129PCuudTCXPIXX1mpvyokjwoLYZR0KLCifqKQLHYmwv8p8kUOaaneij6caRAKQq6i6BFggVJLAWFrC8NipXrK6+VY3iT6CCQht6BDb61aMb9oEB48J82ec= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=nKhTd97c; arc=none smtp.client-ip=113.46.200.223 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="nKhTd97c" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=58GAlSXrZmsy8fdewmLz6iTUjyWgElBvKbAVwCbtG2Y=; b=nKhTd97ccmDwKVhkOZQi9v1I0WWMy/RuRXcL3Ts99dDSqWxCrgdbmQuzTJv2VS1MHnu0REGiZ 0mNwzEkreHblGi/4WFLVX4ZWQztiqsTKwewReB2O4n/MT4XsIcP83Q52ZAW7y1DA6FM76lZchTu ghd/qCnvyxroF8CPUXpad08= Received: from mail.maildlp.com (unknown [172.19.163.200]) by canpmsgout08.his.huawei.com (SkyGuard) with ESMTPS id 4hpmC60nwZzmV8g; Tue, 22 Sep 2026 11:42:58 +0800 (CST) Received: from kwepemk200008.china.huawei.com (unknown [7.202.194.74]) by mail.maildlp.com (Postfix) with ESMTPS id E330940563; Tue, 22 Sep 2026 11:55:01 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemk200008.china.huawei.com (7.202.194.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.45; Tue, 22 Sep 2026 11:55:01 +0800 From: Jinjie Ruan To: , , , , , , , , , , , , , , , , , , , , , , , CC: Subject: [PATCH v19 02/14] arm64: ptrace: Rework audit_syscall_entry() Date: Tue, 22 Sep 2026 11:54:58 +0800 Message-ID: <20260922035510.1090299-3-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260922035510.1090299-1-ruanjinjie@huawei.com> References: <20260922035510.1090299-1-ruanjinjie@huawei.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-ClientProxiedBy: kwepems200001.china.huawei.com (7.221.188.67) To kwepemk200008.china.huawei.com (7.202.194.74) Content-Type: text/plain; charset="utf-8" Extract syscall_enter_audit() helper and switch to generic helpers to get syscall number and syscall arguments, matching the generic entry implementation. The new code: - Checks audit_context() first to avoid unnecessary work when audit is not active. - Use syscall_get_arguments() helper instead of directly accessing regs fields. - Use syscall_get_nr() helper to get syscall number instead of directly accessing regs->syscallno. - Now exactly equivalent to generic entry's syscall_enter_audit(). This is a preparation step for converting arm64 to the generic entry infrastructure. No functional changes intended. Cc: Mark Rutland Cc: Will Deacon Cc: Catalin Marinas Cc: Oleg Nesterov Reviewed-by: Ada Couprie Diaz Reviewed-by: Linus Walleij Reviewed-by: Yeoreum Yun Reviewed-by: Kevin Brodsky Signed-off-by: Jinjie Ruan Tested-by: Kees Cook --- arch/arm64/kernel/ptrace.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c index 96462de75d4b..573b5770698f 100644 --- a/arch/arm64/kernel/ptrace.c +++ b/arch/arm64/kernel/ptrace.c @@ -2458,6 +2458,19 @@ static void report_syscall_exit(struct pt_regs *regs) } } =20 +#ifdef CONFIG_AUDITSYSCALL +static inline void syscall_enter_audit(struct pt_regs *regs) +{ + long syscall =3D syscall_get_nr(current, regs); + unsigned long args[6]; + + syscall_get_arguments(current, regs, args); + __audit_syscall_entry(syscall, args[0], args[1], args[2], args[3]); +} +#else +static inline void syscall_enter_audit(struct pt_regs *regs) { } +#endif + int syscall_trace_enter(struct pt_regs *regs) { unsigned long flags =3D read_thread_flags(); @@ -2476,8 +2489,8 @@ int syscall_trace_enter(struct pt_regs *regs) if (test_thread_flag(TIF_SYSCALL_TRACEPOINT)) trace_sys_enter(regs, regs->syscallno); =20 - audit_syscall_entry(regs->syscallno, regs->orig_x0, regs->regs[1], - regs->regs[2], regs->regs[3]); + if (unlikely(audit_context())) + syscall_enter_audit(regs); =20 return regs->syscallno; } --=20 2.34.1 From nobody Thu Sep 24 17:02:54 2026 Received: from canpmsgout12.his.huawei.com (canpmsgout12.his.huawei.com [113.46.200.227]) (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 CC4E53C585A for ; Tue, 22 Sep 2026 03:55:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.227 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790049309; cv=none; b=tcM1gBg5pGzzf0yxgx77NIh7302iTU0J0oMIyr4tAnkKozEeZSlbcif0bdev95Bfgy8DcIIhL6r0fggWhnpzYrIor7cWmK4wa0gTVsClNRtd5S9WiXEjwGm7SuGDcw2/m9sTGpgE3XOI+4f1SCdyABv5SfUhQBP/qHEPzvj1SkY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790049309; c=relaxed/simple; bh=/HV3M5Y0YOBypowDYFCBI7ATzlHvdj6rcOCMjnEvQpI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RorXaZx7ArQh+kLt5Q7zN3AUbiJqjSz78SuInnQuK3aHCrGS/yKpIvW/lqJ2jMW7x6qGKC9/NFsyXkH8/n3rtvUR342wTZu0K4e+7be2919h+9avnMWB5LVx6M6erI8KfkbyDK3Vsgby1d+1QO6g7aFIIVtmjqDsKNpzXH7vVT8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=Djc5Tq+/; arc=none smtp.client-ip=113.46.200.227 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="Djc5Tq+/" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=nrkb1A7umndhy2bYSvMHLof4oRoyd+N2sYYHpptw3ug=; b=Djc5Tq+/LNX071Ft5LP7daTn17aGlAQb1ay4BuEc28LMAjTu+hkLPqzLQKZB3rSisYyPaGBeS i0ZNPL6LwKcQkLEqub0LHdGbgFbFP3XcHcDTX0G0cHAAcm1/yxnyXj8NrKGZekrI9osWs/4FY4P o1xdULl9KSUC4GD4Ap4b37c= Received: from mail.maildlp.com (unknown [172.19.163.200]) by canpmsgout12.his.huawei.com (SkyGuard) with ESMTPS id 4hpmDJ6WMwznTVd; Tue, 22 Sep 2026 11:44:00 +0800 (CST) Received: from kwepemk200008.china.huawei.com (unknown [7.202.194.74]) by mail.maildlp.com (Postfix) with ESMTPS id A4ECD40563; Tue, 22 Sep 2026 11:55:02 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemk200008.china.huawei.com (7.202.194.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.45; Tue, 22 Sep 2026 11:55:01 +0800 From: Jinjie Ruan To: , , , , , , , , , , , , , , , , , , , , , , , CC: Subject: [PATCH v19 03/14] arm64: ptrace: Open-code seccomp check in syscall_trace_enter() Date: Tue, 22 Sep 2026 11:54:59 +0800 Message-ID: <20260922035510.1090299-4-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260922035510.1090299-1-ruanjinjie@huawei.com> References: <20260922035510.1090299-1-ruanjinjie@huawei.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-ClientProxiedBy: kwepems200001.china.huawei.com (7.221.188.67) To kwepemk200008.china.huawei.com (7.202.194.74) Content-Type: text/plain; charset="utf-8" Refactor syscall_trace_enter() by open-coding the seccomp check to align with the generic entry framework. The generic entry implementation expands the seccomp check in-place by testing SYSCALL_WORK_SECCOMP and directly calling the underlying __seccomp_permit_syscall() function. Moreover, generic entry explicitly re-reads work flags after ptrace handling to ensure any updates to seccomp work flags during the ptrace stop are observed. Bring arm64 in line with this behavior: - Re-read thread flags after ptrace handling. - Test the updated flags for _TIF_SECCOMP and call __seccomp_permit_syscall(). No functional changes are intended; this change simplifies future migration to the generic entry framework. Cc: Mark Rutland Cc: Will Deacon Cc: Catalin Marinas Cc: Oleg Nesterov Link: https://lore.kernel.org/all/20260713025712.416366-1-ruanjinjie@huawei= .com/ Reviewed-by: Ada Couprie Diaz Reviewed-by: Linus Walleij Reviewed-by: Yeoreum Yun Reviewed-by: Kevin Brodsky Signed-off-by: Jinjie Ruan Tested-by: Kees Cook --- arch/arm64/kernel/ptrace.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c index 573b5770698f..f68de40fd351 100644 --- a/arch/arm64/kernel/ptrace.c +++ b/arch/arm64/kernel/ptrace.c @@ -2480,11 +2480,16 @@ int syscall_trace_enter(struct pt_regs *regs) ret =3D report_syscall_entry(regs); if (ret || (flags & _TIF_SYSCALL_EMU)) return NO_SYSCALL; + + /* ptrace might have changed thread flags */ + flags =3D read_thread_flags(); } =20 /* Do the secure computing after ptrace; failures should be fast. */ - if (!seccomp_permit_syscall()) - return NO_SYSCALL; + if (unlikely(flags & _TIF_SECCOMP)) { + if (!__seccomp_permit_syscall()) + return NO_SYSCALL; + } =20 if (test_thread_flag(TIF_SYSCALL_TRACEPOINT)) trace_sys_enter(regs, regs->syscallno); --=20 2.34.1 From nobody Thu Sep 24 17:02:54 2026 Received: from canpmsgout08.his.huawei.com (canpmsgout08.his.huawei.com [113.46.200.223]) (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 1F49A3C4176 for ; Tue, 22 Sep 2026 03:55:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.223 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790049311; cv=none; b=pUnl7IW6322udltS/KW6eoLyMCQrMTwVD7LwSPyC+cHjEHEdbo7DvyPsO3q4sOKi3qza2wDfWL7NdZTWAE1uf0Qu/z8T+EBnv7JSjuEK/cqBZI23I0CFFXhMG55QuChO94rEhpkjTqQoWhmRu7XHcWiBH4fLvy70x5OCa+YeysM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790049311; c=relaxed/simple; bh=gTfYVgbsourynEFFRLHVzmv054UqL2jzUDipr0tCZWI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=igyyx4ilwpaWn82mLnc24XFJ5AoK53Wts+jT/5/1nGOaFRvO3EhYH9yf1MBh2cA+uCLsbVbsTn5a9NhgkNh/VGeNhO7iKDm/zeM2HMOboaLtQXPCM0ma4e3RDmnFhZwqVumWrEbCntDrsivTIRM4Jy8VPe47sI71EVaHDOt7Sj0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=CI55k1s8; arc=none smtp.client-ip=113.46.200.223 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="CI55k1s8" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=8v5vI1JWIXqYRjjCFKnIB0QbZtanHWPI9v5k9fDpGKU=; b=CI55k1s8wDFFLe/iKGuV2MPFKgtOJlwhRAEawz5UW5Ki4XeUlccAJHZKC/KIyEGNxh8dvssyv MvBtTQYp/XWirvYt+c4SAsCX0QnKx7W/jel3qHjfqe9K4pd7pIQdGNKVE+TPN9KZIpcofqqIuVh DfNzZiDxBGVC1YrxNapDXYM= Received: from mail.maildlp.com (unknown [172.19.163.163]) by canpmsgout08.his.huawei.com (SkyGuard) with ESMTPS id 4hpmC73R0BzmVWY; Tue, 22 Sep 2026 11:42:59 +0800 (CST) Received: from kwepemk200008.china.huawei.com (unknown [7.202.194.74]) by mail.maildlp.com (Postfix) with ESMTPS id 484EB4057A; Tue, 22 Sep 2026 11:55:03 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemk200008.china.huawei.com (7.202.194.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.45; Tue, 22 Sep 2026 11:55:02 +0800 From: Jinjie Ruan To: , , , , , , , , , , , , , , , , , , , , , , , CC: Subject: [PATCH v19 04/14] arm64: ptrace: Rename and clean up syscall_trace_enter() Date: Tue, 22 Sep 2026 11:55:00 +0800 Message-ID: <20260922035510.1090299-5-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260922035510.1090299-1-ruanjinjie@huawei.com> References: <20260922035510.1090299-1-ruanjinjie@huawei.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-ClientProxiedBy: kwepems200001.china.huawei.com (7.221.188.67) To kwepemk200008.china.huawei.com (7.202.194.74) Content-Type: text/plain; charset="utf-8" Rename syscall_trace_enter() to arm64_syscall_trace_enter() to avoid name collisions and clarify the boundary when arm64 eventually switches to the generic entry infrastructure. In addition, replace direct accesses to regs->syscallno with the standard syscall_get_nr() helper for both trace_sys_enter() and the return value. This decouples the tracing logic from architecture-specific struct pt_regs layouts, aligning the implementation with the generic entry pattern. No functional changes intended; this is a preparation step for converting arm64 to the generic entry infrastructure. Cc: Mark Rutland Cc: Will Deacon Cc: Catalin Marinas Cc: Oleg Nesterov Cc: Linus Walleij Cc: "Russell King (Oracle)" Cc: Kees Cook Cc: Can Peng Cc: Li Qiang Cc: Ryan Roberts Reviewed-by: Linus Walleij Signed-off-by: Jinjie Ruan Tested-by: Kees Cook --- arch/arm64/include/asm/syscall.h | 2 +- arch/arm64/kernel/ptrace.c | 6 +++--- arch/arm64/kernel/syscall.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/arch/arm64/include/asm/syscall.h b/arch/arm64/include/asm/sysc= all.h index 5e4c7fc44f73..d1dabdcde41c 100644 --- a/arch/arm64/include/asm/syscall.h +++ b/arch/arm64/include/asm/syscall.h @@ -120,7 +120,7 @@ static inline int syscall_get_arch(struct task_struct *= task) return AUDIT_ARCH_AARCH64; } =20 -int syscall_trace_enter(struct pt_regs *regs); +int arm64_syscall_trace_enter(struct pt_regs *regs); void syscall_trace_exit(struct pt_regs *regs); =20 #endif /* __ASM_SYSCALL_H */ diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c index f68de40fd351..96c03922baa5 100644 --- a/arch/arm64/kernel/ptrace.c +++ b/arch/arm64/kernel/ptrace.c @@ -2471,7 +2471,7 @@ static inline void syscall_enter_audit(struct pt_regs= *regs) static inline void syscall_enter_audit(struct pt_regs *regs) { } #endif =20 -int syscall_trace_enter(struct pt_regs *regs) +int arm64_syscall_trace_enter(struct pt_regs *regs) { unsigned long flags =3D read_thread_flags(); int ret; @@ -2492,12 +2492,12 @@ int syscall_trace_enter(struct pt_regs *regs) } =20 if (test_thread_flag(TIF_SYSCALL_TRACEPOINT)) - trace_sys_enter(regs, regs->syscallno); + trace_sys_enter(regs, syscall_get_nr(current, regs)); =20 if (unlikely(audit_context())) syscall_enter_audit(regs); =20 - return regs->syscallno; + return syscall_get_nr(current, regs); } =20 static inline bool report_single_step(unsigned long flags) diff --git a/arch/arm64/kernel/syscall.c b/arch/arm64/kernel/syscall.c index 358ddfbf1401..3e78e159b2a1 100644 --- a/arch/arm64/kernel/syscall.c +++ b/arch/arm64/kernel/syscall.c @@ -113,7 +113,7 @@ static void el0_svc_common(struct pt_regs *regs, int sc= no, int sc_nr, */ if (scno =3D=3D NO_SYSCALL) syscall_set_return_value(current, regs, -ENOSYS, 0); - scno =3D syscall_trace_enter(regs); + scno =3D arm64_syscall_trace_enter(regs); if (scno =3D=3D NO_SYSCALL) goto trace_exit; } --=20 2.34.1 From nobody Thu Sep 24 17:02:54 2026 Received: from canpmsgout03.his.huawei.com (canpmsgout03.his.huawei.com [113.46.200.218]) (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 E419A2264AB for ; Tue, 22 Sep 2026 03:55:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.218 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790049310; cv=none; b=nnJeqljUgg/Z8mygiANTor46PjEY7E+K+g/3HrHMK7tYGNPurfbQIMk17trlMB1/Szs2aRbH7XizeOEdYR12vWFxD81aJ6CfOU3d2GaDcTlzK1Uo93i9XSsfccbx5rDzarq67MCJEu5ANfAxU1K0shJr6SkbeTRxwWToRcg8mKk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790049310; c=relaxed/simple; bh=/nBJbaw9/Qa37K7QFeT5mRWvdCSF1pKL6l8WRh5+Pw4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=otK0V73AYU0hCXp+bhG5q8BIkL8turEGnyfXRCBXoHPp/WSuAH5SAQl9x8ZI5rhcR1UjFVb1dxn0yw+lT4N1sxMryXxUA/LP2dY0WFxrkeeZQCzfuwnIqTjB1X0EUpt/Cu6Oqt2bUFwGLkcce47UTNuinS+DsCRSOxsnDJDRqvM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=PYV2F4rW; arc=none smtp.client-ip=113.46.200.218 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="PYV2F4rW" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=qaKQJBiemoQZr3vKvmWTuD+/3eNNt98af8vnN5I52Kg=; b=PYV2F4rWZ0nW3BC9o5lclyg9v9kcdyI2DE4h/YVnVeOvgLh5xKdTVpDaugLAXWRKwStq/8Qb0 i2W9Z8ByMzXEYkBQ+jRMxET3G6vNQAah2Pf+95s4neNKoFhlm/UtmMJC7TmoJn0HUvSl7G3f0VH O7PiiLmPCh8Q2KbkK+i8sAo= Received: from mail.maildlp.com (unknown [172.19.162.144]) by canpmsgout03.his.huawei.com (SkyGuard) with ESMTPS id 4hpmCJ0v5SzpStW; Tue, 22 Sep 2026 11:43:08 +0800 (CST) Received: from kwepemk200008.china.huawei.com (unknown [7.202.194.74]) by mail.maildlp.com (Postfix) with ESMTPS id D740E4056D; Tue, 22 Sep 2026 11:55:03 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemk200008.china.huawei.com (7.202.194.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.45; Tue, 22 Sep 2026 11:55:03 +0800 From: Jinjie Ruan To: , , , , , , , , , , , , , , , , , , , , , , , CC: Subject: [PATCH v19 05/14] arm64: ptrace: Protect rseq_syscall() from tracer PC modifications Date: Tue, 22 Sep 2026 11:55:01 +0800 Message-ID: <20260922035510.1090299-6-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260922035510.1090299-1-ruanjinjie@huawei.com> References: <20260922035510.1090299-1-ruanjinjie@huawei.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-ClientProxiedBy: kwepems200001.china.huawei.com (7.221.188.67) To kwepemk200008.china.huawei.com (7.202.194.74) Content-Type: text/plain; charset="utf-8" Move the rseq_syscall() check earlier in the syscall exit path to ensure it operates on the original instruction pointer (regs->pc) before any potential modification by a tracer. [Background] When CONFIG_DEBUG_RSEQ is enabled, rseq_syscall() verifies that a system call was not executed within an rseq critical section by examining regs->pc. If a violation is detected, it triggers a SIGSEGV. [Problem] Currently, arm64 invokes rseq_syscall() after report_syscall_exit(). However, during report_syscall_exit(), a ptrace tracer can modify the task's instruction pointer via PTRACE_SETREGSET (with NT_PRSTATUS). This leads to an inconsistency where rseq may analyze a post-trace PC instead of the actual PC at the time of syscall exit. [Why this matters] The rseq check is intended to validate the execution context of the syscall itself. Analyzing a tracer-modified PC can lead to incorrect detection or missed violations. Moving the check earlier ensures rseq sees the authentic state of the task. [Alignment] This change aligns arm64 with: - Generic entry, which calls rseq_syscall() first. - arm32 implementation, which also performs the check before audit. [Impact] There is no functional change to signal delivery; SIGSEGV will still be processed in arm64_exit_to_user_mode() at the end of the exit path. Cc: Mark Rutland Cc: Thomas Gleixner Cc: Will Deacon Cc: Catalin Marinas Cc: Oleg Nesterov Reviewed-by: Ada Couprie Diaz Reviewed-by: Linus Walleij Reviewed-by: Yeoreum Yun Reviewed-by: Kevin Brodsky Signed-off-by: Jinjie Ruan Tested-by: Kees Cook --- arch/arm64/kernel/ptrace.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c index 96c03922baa5..72df4b84ec9a 100644 --- a/arch/arm64/kernel/ptrace.c +++ b/arch/arm64/kernel/ptrace.c @@ -2513,6 +2513,8 @@ void syscall_trace_exit(struct pt_regs *regs) unsigned long flags =3D read_thread_flags(); bool step; =20 + rseq_syscall(regs); + audit_syscall_exit(regs); =20 if (flags & _TIF_SYSCALL_TRACEPOINT) @@ -2521,8 +2523,6 @@ void syscall_trace_exit(struct pt_regs *regs) step =3D report_single_step(flags); if (step || flags & _TIF_SYSCALL_TRACE) report_syscall_exit(regs); - - rseq_syscall(regs); } =20 /* --=20 2.34.1 From nobody Thu Sep 24 17:02:54 2026 Received: from canpmsgout05.his.huawei.com (canpmsgout05.his.huawei.com [113.46.200.220]) (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 85D4C3E00B5 for ; Tue, 22 Sep 2026 03:55:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.220 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790049310; cv=none; b=hhOTy+eY6stZPpJEBXpoHPwPvz8veNe3LSDLMX4IgaZIrxvynEkctyJTEm3G7aetXSg0sJvMbO7bns3qKtPH1DN2oc+qOBn/8ROZa0+jswH4SUPn0mGdelj5uD0XdF4ndaZBkWgvIbR9oIFGl7Y8z+g04rcvseCbyppcoHeHifY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790049310; c=relaxed/simple; bh=wyE7bOGVr+QuFdZe3xhnHtSx1OV+QrD6JYoWn09mTgM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=XynhHl1A1csYSBGvLP6EvcVLAW5/WHTs5t+i8LiQeuJWJ/Gh5SXs29DXmSmKys54sEbfjZQ5JU87YyOt6dm5OOFO50/TFRxYyiIfE2tq0AY9S9ZtydMBWz+uWPN4zXMIlxsD/2wkwy6DZta8Vvgw8MHxyjeQrSKXd1ZxbkHkRL8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=NYSnIatR; arc=none smtp.client-ip=113.46.200.220 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="NYSnIatR" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=hl1CLW9EawYLsWL2sQ6i6jSacYbM+KweN1L2uRVVyBU=; b=NYSnIatRnFwGK4SryCn9gfK2i73M8HdwpyiFezEjektd192Ba9f/f9zq57k6kSbsSfrDmKMH6 SLo8mNui356sjH0GKtXJdVcfRuVZIXOiSasYB/h6LtIlLpHZ40kDnKgMN4mO+d/vbeJMNRUdVFB VuZLc1JaaIESyQ26CTMKFso= Received: from mail.maildlp.com (unknown [172.19.162.144]) by canpmsgout05.his.huawei.com (SkyGuard) with ESMTPS id 4hpmDH55mQz12LHn; Tue, 22 Sep 2026 11:43:59 +0800 (CST) Received: from kwepemk200008.china.huawei.com (unknown [7.202.194.74]) by mail.maildlp.com (Postfix) with ESMTPS id 8D73F4056E; Tue, 22 Sep 2026 11:55:04 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemk200008.china.huawei.com (7.202.194.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.45; Tue, 22 Sep 2026 11:55:03 +0800 From: Jinjie Ruan To: , , , , , , , , , , , , , , , , , , , , , , , CC: Subject: [PATCH v19 06/14] arm64: syscall: Rework the syscall exit path in el0_svc_common() Date: Tue, 22 Sep 2026 11:55:02 +0800 Message-ID: <20260922035510.1090299-7-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260922035510.1090299-1-ruanjinjie@huawei.com> References: <20260922035510.1090299-1-ruanjinjie@huawei.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-ClientProxiedBy: kwepems200001.china.huawei.com (7.221.188.67) To kwepemk200008.china.huawei.com (7.202.194.74) Content-Type: text/plain; charset="utf-8" In preparation for moving arm64 over to the generic entry, invert the nested conditional flags check within el0_svc_common(). No functional changes. Cc: Mark Rutland Cc: Will Deacon Cc: Catalin Marinas Cc: Ada Couprie Diaz Cc: Linus Walleij Cc: Can Peng Cc: Li Qiang Cc: Ryan Roberts Reviewed-by: Linus Walleij Signed-off-by: Jinjie Ruan Tested-by: Kees Cook --- arch/arm64/kernel/syscall.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kernel/syscall.c b/arch/arm64/kernel/syscall.c index 3e78e159b2a1..b8d7d29a431b 100644 --- a/arch/arm64/kernel/syscall.c +++ b/arch/arm64/kernel/syscall.c @@ -127,8 +127,9 @@ static void el0_svc_common(struct pt_regs *regs, int sc= no, int sc_nr, */ if (!has_syscall_work(flags) && !IS_ENABLED(CONFIG_DEBUG_RSEQ)) { flags =3D read_thread_flags(); - if (!has_syscall_work(flags) && !(flags & _TIF_SINGLESTEP)) - return; + if (has_syscall_work(flags) || flags & _TIF_SINGLESTEP) + syscall_trace_exit(regs); + return; } =20 trace_exit: --=20 2.34.1 From nobody Thu Sep 24 17:02:54 2026 Received: from canpmsgout02.his.huawei.com (canpmsgout02.his.huawei.com [113.46.200.217]) (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 3132A3E1228 for ; Tue, 22 Sep 2026 03:55:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.217 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790049311; cv=none; b=EMYNDD9R0IGg72gsq6ea3gjffWVqq24cKXRg7GUZlyE5WC06qBwACJN3ehAdKJfo2Gazyr5/9nFdRp6g06CHMtRvwtgMEDplHGj+UjCTgjAjZcjkL9kIn50ArFO0dkkMTKS9Xpppbm5+0hpX9JfT98sb3EcmF6vlWUTCy8TXzMc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790049311; c=relaxed/simple; bh=JSDqn/fU02gaMGHzt85p/ssLNVfB/RzCep9u9gGhCbE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=PRnAJSGq0ZNLDkfwitwfAeVmwLqWnezoXqGtWVJsoDMPvQtYBajL+gSBhNdkW+uPWidmByAXYXndFxRqPbDK9/H9jIiEPfI00GLksR2/svz14DEkEwkC3OyS7njAlmr0IheC/QLK7f9DmPpXlPQsfeOckekNNWLAe9neaKrU1C8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=rlJXIxHN; arc=none smtp.client-ip=113.46.200.217 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="rlJXIxHN" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=jpZL2Yu7GriEl1/fc68kkVg/n8TJBHRv1iFl32R39RA=; b=rlJXIxHNybXKI1ei7SfdSLU7VPGYrwiorsYuQ/sXnhYN2KioTodHT7x6+y62UDoXbU3HaOCYN GtM8zPFfHxrGeEx6z0BBKmBFI7CNqE17Taa6APtxRbBZhLlsRMxEyERBmEy/9mTN1e5kVICbJv6 HLf/ZtGNxyTiZYQrgXmRm2E= Received: from mail.maildlp.com (unknown [172.19.163.104]) by canpmsgout02.his.huawei.com (SkyGuard) with ESMTPS id 4hpmCz1KW6zcb3P; Tue, 22 Sep 2026 11:43:43 +0800 (CST) Received: from kwepemk200008.china.huawei.com (unknown [7.202.194.74]) by mail.maildlp.com (Postfix) with ESMTPS id 36D274057F; Tue, 22 Sep 2026 11:55:05 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemk200008.china.huawei.com (7.202.194.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.45; Tue, 22 Sep 2026 11:55:04 +0800 From: Jinjie Ruan To: , , , , , , , , , , , , , , , , , , , , , , , CC: Subject: [PATCH v19 07/14] arm64: ptrace: Pass thread flags to trace enter/exit Date: Tue, 22 Sep 2026 11:55:03 +0800 Message-ID: <20260922035510.1090299-8-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260922035510.1090299-1-ruanjinjie@huawei.com> References: <20260922035510.1090299-1-ruanjinjie@huawei.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-ClientProxiedBy: kwepems200001.china.huawei.com (7.221.188.67) To kwepemk200008.china.huawei.com (7.202.194.74) Content-Type: text/plain; charset="utf-8" Move the reading of thread flags from inside arm64_syscall_trace_enter() and syscall_trace_exit() to their callers. This aligns the function signatures with the generic entry framework, where the caller is responsible for supplying the flags. In el0_svc_common(), the flags are now passed directly to the tracing functions, and re-read before the enter/exit path to reflect any updates. No functional change intended; this is a preparatory step for converting arm64 to the generic entry infrastructure. Cc: Mark Rutland Cc: Will Deacon Cc: Catalin Marinas Cc: Oleg Nesterov Cc: Linus Walleij Cc: Yeoreum Yun Cc: Kevin Brodsky Cc: Ada Couprie Diaz Cc: Can Peng Cc: Ryan Roberts Cc: Li Qiang Reviewed-by: Ada Couprie Diaz Reviewed-by: Linus Walleij Reviewed-by: Yeoreum Yun Reviewed-by: Kevin Brodsky Signed-off-by: Jinjie Ruan Tested-by: Kees Cook --- arch/arm64/include/asm/syscall.h | 4 ++-- arch/arm64/kernel/ptrace.c | 6 ++---- arch/arm64/kernel/syscall.c | 11 +++++++---- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/arch/arm64/include/asm/syscall.h b/arch/arm64/include/asm/sysc= all.h index d1dabdcde41c..696739f5a250 100644 --- a/arch/arm64/include/asm/syscall.h +++ b/arch/arm64/include/asm/syscall.h @@ -120,7 +120,7 @@ static inline int syscall_get_arch(struct task_struct *= task) return AUDIT_ARCH_AARCH64; } =20 -int arm64_syscall_trace_enter(struct pt_regs *regs); -void syscall_trace_exit(struct pt_regs *regs); +int arm64_syscall_trace_enter(struct pt_regs *regs, unsigned long flags); +void syscall_trace_exit(struct pt_regs *regs, unsigned long flags); =20 #endif /* __ASM_SYSCALL_H */ diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c index 72df4b84ec9a..ac90b05dbd11 100644 --- a/arch/arm64/kernel/ptrace.c +++ b/arch/arm64/kernel/ptrace.c @@ -2471,9 +2471,8 @@ static inline void syscall_enter_audit(struct pt_regs= *regs) static inline void syscall_enter_audit(struct pt_regs *regs) { } #endif =20 -int arm64_syscall_trace_enter(struct pt_regs *regs) +int arm64_syscall_trace_enter(struct pt_regs *regs, unsigned long flags) { - unsigned long flags =3D read_thread_flags(); int ret; =20 if (flags & (_TIF_SYSCALL_EMU | _TIF_SYSCALL_TRACE)) { @@ -2508,9 +2507,8 @@ static inline bool report_single_step(unsigned long f= lags) return flags & _TIF_SINGLESTEP; } =20 -void syscall_trace_exit(struct pt_regs *regs) +void syscall_trace_exit(struct pt_regs *regs, unsigned long flags) { - unsigned long flags =3D read_thread_flags(); bool step; =20 rseq_syscall(regs); diff --git a/arch/arm64/kernel/syscall.c b/arch/arm64/kernel/syscall.c index b8d7d29a431b..e778aac6fab9 100644 --- a/arch/arm64/kernel/syscall.c +++ b/arch/arm64/kernel/syscall.c @@ -113,7 +113,7 @@ static void el0_svc_common(struct pt_regs *regs, int sc= no, int sc_nr, */ if (scno =3D=3D NO_SYSCALL) syscall_set_return_value(current, regs, -ENOSYS, 0); - scno =3D arm64_syscall_trace_enter(regs); + scno =3D arm64_syscall_trace_enter(regs, read_thread_flags()); if (scno =3D=3D NO_SYSCALL) goto trace_exit; } @@ -127,13 +127,16 @@ static void el0_svc_common(struct pt_regs *regs, int = scno, int sc_nr, */ if (!has_syscall_work(flags) && !IS_ENABLED(CONFIG_DEBUG_RSEQ)) { flags =3D read_thread_flags(); - if (has_syscall_work(flags) || flags & _TIF_SINGLESTEP) - syscall_trace_exit(regs); + if (has_syscall_work(flags) || flags & _TIF_SINGLESTEP) { + flags =3D read_thread_flags(); + syscall_trace_exit(regs, flags); + } return; } =20 trace_exit: - syscall_trace_exit(regs); + flags =3D read_thread_flags(); + syscall_trace_exit(regs, flags); } =20 void do_el0_svc(struct pt_regs *regs) --=20 2.34.1 From nobody Thu Sep 24 17:02:54 2026 Received: from canpmsgout04.his.huawei.com (canpmsgout04.his.huawei.com [113.46.200.219]) (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 28A873D9557 for ; Tue, 22 Sep 2026 03:55:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.219 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790049310; cv=none; b=PFrSW8kUmZgrUzqoU6bK2kqB+Kfc2KHb06eIFzwMuvT/xHK1I7uSSo2120VCAT6UWzee9bPNpG7qkbSe3x4zvx9tl38Q4kSHmmMO6ncbHAB9QGzCcTyEygUW+KraFxCFGgqtvk9h/+DG1i6OccY1amtf3azicMvu9OqE72r/0p0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790049310; c=relaxed/simple; bh=9O4BS/2LCjUV4na/Pf4a2/cIXigBAgNbXGVfyGhz3cY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=WA9FCtY9R86N7ny9rKzcp+GN4QB6UrR4PC20FLS9nmxCQC8tMVeeNkipsXEbJARBx0/2pAX7yv4gDWrJ0S88CgRMzMSM70hCgYfAjjlEXsypi4HmkFJ5YLcOgINzPran91jcx3d2l5ZIcU4iZEwGIArM1km0kQyV3Gc3EOSECY4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=EnMiwqNP; arc=none smtp.client-ip=113.46.200.219 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="EnMiwqNP" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=BygUDatlIF1iDxxLJ/FKhjR0XU9vdmKuayXfRgYRzrk=; b=EnMiwqNPZZH1KtU3QXl6eSSolMSKyPdOOyHkkHliNHfp1tc/Z/1xYkadMBN8MYAMbh3hvIoNB sb3y/QXkorWi5FFwPSEb3gqP1sc4oZy883zBRddCdQJi78oAiH4l+YAuc//znWnbiQfu4KPMduE SMZ9O9fEQUlMavMZ/+YBsec= Received: from mail.maildlp.com (unknown [172.19.163.104]) by canpmsgout04.his.huawei.com (SkyGuard) with ESMTPS id 4hpmDL2m4Xz1prLc; Tue, 22 Sep 2026 11:44:02 +0800 (CST) Received: from kwepemk200008.china.huawei.com (unknown [7.202.194.74]) by mail.maildlp.com (Postfix) with ESMTPS id E060F4057F; Tue, 22 Sep 2026 11:55:05 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemk200008.china.huawei.com (7.202.194.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.45; Tue, 22 Sep 2026 11:55:05 +0800 From: Jinjie Ruan To: , , , , , , , , , , , , , , , , , , , , , , , CC: Subject: [PATCH v19 08/14] arm64: ptrace: Extract arm64_syscall_exit_to_user_mode_work() helper Date: Tue, 22 Sep 2026 11:55:04 +0800 Message-ID: <20260922035510.1090299-9-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260922035510.1090299-1-ruanjinjie@huawei.com> References: <20260922035510.1090299-1-ruanjinjie@huawei.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-ClientProxiedBy: kwepems200001.china.huawei.com (7.221.188.67) To kwepemk200008.china.huawei.com (7.202.194.74) Content-Type: text/plain; charset="utf-8" Introduce a helper arm64_syscall_exit_to_user_mode_work() that encapsulates the re-reading of thread flags and the call to syscall_trace_exit(). Use it in el0_svc_common() to replace the open-coded instances, removing the duplicated flags read and making the control flow simpler. This aligns the arm64 exit path with the pattern expected by the generic entry infrastructure, which uses a similar syscall_exit_to_user_mode_work() callback. No functional changes intended; this is a preparation step for converting arm64 to the generic entry infrastructure. Cc: Mark Rutland Cc: Will Deacon Cc: Catalin Marinas Cc: Ada Couprie Diaz Cc: Linus Walleij Cc: Yeoreum Yun Cc: Can Peng Cc: Li Qiang Cc: Ryan Roberts Reviewed-by: Linus Walleij Signed-off-by: Jinjie Ruan Tested-by: Kees Cook --- arch/arm64/include/asm/syscall.h | 7 +++++++ arch/arm64/kernel/syscall.c | 9 +++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/arch/arm64/include/asm/syscall.h b/arch/arm64/include/asm/sysc= all.h index 696739f5a250..3e4672ab4a4f 100644 --- a/arch/arm64/include/asm/syscall.h +++ b/arch/arm64/include/asm/syscall.h @@ -123,4 +123,11 @@ static inline int syscall_get_arch(struct task_struct = *task) int arm64_syscall_trace_enter(struct pt_regs *regs, unsigned long flags); void syscall_trace_exit(struct pt_regs *regs, unsigned long flags); =20 +static __always_inline void arm64_syscall_exit_to_user_mode_work(struct pt= _regs *regs) +{ + unsigned long flags =3D read_thread_flags(); + + syscall_trace_exit(regs, flags); +} + #endif /* __ASM_SYSCALL_H */ diff --git a/arch/arm64/kernel/syscall.c b/arch/arm64/kernel/syscall.c index e778aac6fab9..0061fc63e7ba 100644 --- a/arch/arm64/kernel/syscall.c +++ b/arch/arm64/kernel/syscall.c @@ -127,16 +127,13 @@ static void el0_svc_common(struct pt_regs *regs, int = scno, int sc_nr, */ if (!has_syscall_work(flags) && !IS_ENABLED(CONFIG_DEBUG_RSEQ)) { flags =3D read_thread_flags(); - if (has_syscall_work(flags) || flags & _TIF_SINGLESTEP) { - flags =3D read_thread_flags(); - syscall_trace_exit(regs, flags); - } + if (has_syscall_work(flags) || flags & _TIF_SINGLESTEP) + arm64_syscall_exit_to_user_mode_work(regs); return; } =20 trace_exit: - flags =3D read_thread_flags(); - syscall_trace_exit(regs, flags); + arm64_syscall_exit_to_user_mode_work(regs); } =20 void do_el0_svc(struct pt_regs *regs) --=20 2.34.1 From nobody Thu Sep 24 17:02:54 2026 Received: from canpmsgout06.his.huawei.com (canpmsgout06.his.huawei.com [113.46.200.221]) (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 1F0EB3E1D08 for ; Tue, 22 Sep 2026 03:55:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.221 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790049311; cv=none; b=rXy0BK47BbeD8AOgWWEqUpETxWXjHcmb1fxiAsg/a1Mn4VE+nYdWiv7+qxLAsXFsmMFsQAxRucnhAkKcA/lfq4MviW29YT9OcxFkQKW4lUhuCjcLf3Vn1Ia8Gn8GItK6sOqNOeLnQJs1TNk/kmUQZVGxVjZQEEY8k3K9hCE6IMU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790049311; c=relaxed/simple; bh=8Q5af/1TBKEmket3Yv2z43A6lQFLDl3cGJicjGGca2c=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=c4or0Ypg6mS/QNt8FyHjAIbqnPnX4lSemy5p/HUTvRqO4Ptgy4zQexqSSOQukBeN8sgU3DoUKhUKf18NwpkYa7ZG5CQHvcCqZZ8rjLshNPKfzkr0Yw6Mkg1ncPD8U0BE0ylryjnWZEH/WyNA2SPqfeYYkZuyOZYsI+VZUuhZj6I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=o/+rcPZb; arc=none smtp.client-ip=113.46.200.221 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="o/+rcPZb" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=XRwSzsikLLGYZX0w4W5xgQjrwFnh2SaAqnpEPHaJ74A=; b=o/+rcPZbtoHEt4tsjacgEriCleEjT4lMStnjsoPHr42eNnVnFZ2ewamXFAxB0hYJ5YmDGQjc8 HsKK3lUlaYLgMTsZxWCT3rC9ExONnvYApF9UdxGMR9BUf9pcKTJ7RinCGVaZfX3WnsQFMEKfjHk tVBuun5WNYTRPfT6bnGzAK0= Received: from mail.maildlp.com (unknown [172.19.163.0]) by canpmsgout06.his.huawei.com (SkyGuard) with ESMTPS id 4hpmCF329pzRhVN; Tue, 22 Sep 2026 11:43:05 +0800 (CST) Received: from kwepemk200008.china.huawei.com (unknown [7.202.194.74]) by mail.maildlp.com (Postfix) with ESMTPS id 8FAD940561; Tue, 22 Sep 2026 11:55:06 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemk200008.china.huawei.com (7.202.194.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.45; Tue, 22 Sep 2026 11:55:05 +0800 From: Jinjie Ruan To: , , , , , , , , , , , , , , , , , , , , , , , CC: Subject: [PATCH v19 09/14] arm64: ptrace: Align syscall exit work semantics with generic entry Date: Tue, 22 Sep 2026 11:55:05 +0800 Message-ID: <20260922035510.1090299-10-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260922035510.1090299-1-ruanjinjie@huawei.com> References: <20260922035510.1090299-1-ruanjinjie@huawei.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-ClientProxiedBy: kwepems200001.china.huawei.com (7.221.188.67) To kwepemk200008.china.huawei.com (7.202.194.74) Content-Type: text/plain; charset="utf-8" Refactor the syscall exit path to better match the generic entry framework. Specifically: - Introduce `_TIF_SYSCALL_EXIT_WORK` to aggregate exit-time thread flags (trace, audit, tracepoint). - Rename `syscall_trace_exit()` to `arm64_syscall_exit_work()` to better reflect its role. - Move `rseq_syscall()` out of `arm64_syscall_exit_work()` and into `arm64_syscall_exit_to_user_mode_work()` so that it runs unconditionally on all exits, consistent with generic entry. - Gate `arm64_syscall_exit_work()` behind the new flag check, mirroring the generic entry exit's pattern. Gating audit on `_TIF_SYSCALL_AUDIT` is equivalent to the previous `audit_context()` check: the audit context and flag are statically allocated at fork and freed at exit, remaining stable throughout syscall execution. No functional changes intended. Cc: Mark Rutland Cc: Will Deacon Cc: Catalin Marinas Cc: Ada Couprie Diaz Cc: Oleg Nesterov Cc: Linus Walleij Cc: "Russell King (Oracle)" Cc: Yeoreum Yun Cc: Kevin Brodsky Cc: Anshuman Khandual Cc: "David Hildenbrand (Red Hat)" Cc: Thomas Huth Cc: James Morse Reviewed-by: Linus Walleij Signed-off-by: Jinjie Ruan Tested-by: Kees Cook --- arch/arm64/include/asm/syscall.h | 8 ++++++-- arch/arm64/include/asm/thread_info.h | 3 +++ arch/arm64/kernel/ptrace.c | 5 +---- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/arch/arm64/include/asm/syscall.h b/arch/arm64/include/asm/sysc= all.h index 3e4672ab4a4f..7cc872fde019 100644 --- a/arch/arm64/include/asm/syscall.h +++ b/arch/arm64/include/asm/syscall.h @@ -8,6 +8,7 @@ #include #include #include +#include =20 typedef long (*syscall_fn_t)(const struct pt_regs *regs); =20 @@ -121,13 +122,16 @@ static inline int syscall_get_arch(struct task_struct= *task) } =20 int arm64_syscall_trace_enter(struct pt_regs *regs, unsigned long flags); -void syscall_trace_exit(struct pt_regs *regs, unsigned long flags); +void arm64_syscall_exit_work(struct pt_regs *regs, unsigned long flags); =20 static __always_inline void arm64_syscall_exit_to_user_mode_work(struct pt= _regs *regs) { unsigned long flags =3D read_thread_flags(); =20 - syscall_trace_exit(regs, flags); + rseq_syscall(regs); + + if (unlikely(flags & _TIF_SYSCALL_EXIT_WORK) || flags & _TIF_SINGLESTEP) + arm64_syscall_exit_work(regs, flags); } =20 #endif /* __ASM_SYSCALL_H */ diff --git a/arch/arm64/include/asm/thread_info.h b/arch/arm64/include/asm/= thread_info.h index 5d7fe3e153c8..56a2c9426a32 100644 --- a/arch/arm64/include/asm/thread_info.h +++ b/arch/arm64/include/asm/thread_info.h @@ -112,6 +112,9 @@ void arch_setup_new_exec(void); _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | \ _TIF_SYSCALL_EMU) =20 +#define _TIF_SYSCALL_EXIT_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \ + _TIF_SYSCALL_TRACEPOINT) + #ifdef CONFIG_SHADOW_CALL_STACK #define INIT_SCS \ .scs_base =3D init_shadow_call_stack, \ diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c index ac90b05dbd11..610a79c1072b 100644 --- a/arch/arm64/kernel/ptrace.c +++ b/arch/arm64/kernel/ptrace.c @@ -28,7 +28,6 @@ #include #include #include -#include =20 #include #include @@ -2507,12 +2506,10 @@ static inline bool report_single_step(unsigned long= flags) return flags & _TIF_SINGLESTEP; } =20 -void syscall_trace_exit(struct pt_regs *regs, unsigned long flags) +void arm64_syscall_exit_work(struct pt_regs *regs, unsigned long flags) { bool step; =20 - rseq_syscall(regs); - audit_syscall_exit(regs); =20 if (flags & _TIF_SYSCALL_TRACEPOINT) --=20 2.34.1 From nobody Thu Sep 24 17:02:54 2026 Received: from canpmsgout10.his.huawei.com (canpmsgout10.his.huawei.com [113.46.200.225]) (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 D70973E49CA for ; Tue, 22 Sep 2026 03:55:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.225 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790049325; cv=none; b=NF7ipST6BSokjFYeAKCkZxUlMIGITDp0fbwgSTekjT1zxeWmMgMR8pCzlcxHNk6oTEVKWFzjvL4Yo6IkdTkit/spz8GqbaPyRlXZN2b3vrKklRu00i96w/+tg8wUjBlkp65qa8MgcTK9R3gxemMA1AJT0heC0+8ciNlHQn0nf7E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790049325; c=relaxed/simple; bh=XnF7ZchgoTn351d8+4Dsk9g9zJQZEJ9aupHS+Arwin4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=F66hyFj3q0RCsQapEZacV/6jTLwFNrri2PWjKaYp5rDSUgGbB6MoIII0A3NMIz0b8F5Jsn2yRc2HROLANyL5CLGsk4/BIm0P6SI5HDhg2vcNoO++ITIcylbMYWN93HW4XERiqOfpF5OE3iXNLs2nlaZ26WcLZHA5lXQUtlButJI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=OiHrvaoN; arc=none smtp.client-ip=113.46.200.225 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="OiHrvaoN" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=1NYXPJThiERDr7PsLUNJoyQcRNDGxahI6/GYa+UXA/8=; b=OiHrvaoNwvj5QCJINxMcT+hVAiXxIQHG+7FEY1iT/t3Exve8t6aohY/nnbfJIxEX6Cv6e2npi 27wBfk3J61pBbwgc0jJQW2K341U+/jN29brmyfsii0TMwja6AOPVJiJJI0YmrzHZMQf8JZl8Q2R Sp6anRlQQaCTnk4dsuEnjB4= Received: from mail.maildlp.com (unknown [172.19.163.127]) by canpmsgout10.his.huawei.com (SkyGuard) with ESMTPS id 4hpmDN6Nnsz1K9Ck; Tue, 22 Sep 2026 11:44:04 +0800 (CST) Received: from kwepemk200008.china.huawei.com (unknown [7.202.194.74]) by mail.maildlp.com (Postfix) with ESMTPS id 4A3CA40572; Tue, 22 Sep 2026 11:55:07 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemk200008.china.huawei.com (7.202.194.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.45; Tue, 22 Sep 2026 11:55:06 +0800 From: Jinjie Ruan To: , , , , , , , , , , , , , , , , , , , , , , , CC: Subject: [PATCH v19 10/14] arm64: syscall: Use exit-specific flags check in el0_svc_common() Date: Tue, 22 Sep 2026 11:55:06 +0800 Message-ID: <20260922035510.1090299-11-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260922035510.1090299-1-ruanjinjie@huawei.com> References: <20260922035510.1090299-1-ruanjinjie@huawei.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-ClientProxiedBy: kwepems200001.china.huawei.com (7.221.188.67) To kwepemk200008.china.huawei.com (7.202.194.74) Content-Type: text/plain; charset="utf-8" The syscall exit path in el0_svc_common() re-evaluates all _TIF_SYSCALL_WORK flags, but this mask contains flags that only matter on entry: - _TIF_SECCOMP: seccomp filtering is entry-only - _TIF_SYSCALL_EMU: PTRACE_SYSEMU skips the syscall on entry Re-checking them on exit is unnecessary and may trigger redundant work. Switch to _TIF_SYSCALL_EXIT_WORK for the exit-path re-check to evaluate only exit-relevant flags (_TIF_SYSCALL_TRACE, _TIF_SYSCALL_AUDIT, and _TIF_SYSCALL_TRACEPOINT). No functional change intended. Cc: Mark Rutland Cc: Will Deacon Cc: Catalin Marinas Cc: Ada Couprie Diaz Cc: Linus Walleij Cc: Yeoreum Yun Cc: Kees Cook Cc: Can Peng Cc: Ryan Roberts Cc: Li Qiang Reviewed-by: Ada Couprie Diaz Reviewed-by: Linus Walleij Reviewed-by: Yeoreum Yun Signed-off-by: Jinjie Ruan Tested-by: Kees Cook --- arch/arm64/kernel/syscall.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm64/kernel/syscall.c b/arch/arm64/kernel/syscall.c index 0061fc63e7ba..f1f0b6f3e32b 100644 --- a/arch/arm64/kernel/syscall.c +++ b/arch/arm64/kernel/syscall.c @@ -127,7 +127,7 @@ static void el0_svc_common(struct pt_regs *regs, int sc= no, int sc_nr, */ if (!has_syscall_work(flags) && !IS_ENABLED(CONFIG_DEBUG_RSEQ)) { flags =3D read_thread_flags(); - if (has_syscall_work(flags) || flags & _TIF_SINGLESTEP) + if (unlikely(flags & _TIF_SYSCALL_EXIT_WORK) || flags & _TIF_SINGLESTEP) arm64_syscall_exit_to_user_mode_work(regs); return; } --=20 2.34.1 From nobody Thu Sep 24 17:02:54 2026 Received: from canpmsgout09.his.huawei.com (canpmsgout09.his.huawei.com [113.46.200.224]) (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 54C653E6DFA for ; Tue, 22 Sep 2026 03:55:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.224 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790049322; cv=none; b=dJ+9ZkYuU2yppJrEedjzWWsJunMd/vAjRoMO/VlPen4Osh34dOkPv7iJj5qeN3DnTPsmHXpXjJAGirnf9W8/wNK+oNeSDJEGU6mKvtu8YgupY4BdKEfa/lNNXtCUjNRXnCoPOJOSlnnSe4+w285mp2xBSoNCWcyn7i59uOwfxng= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790049322; c=relaxed/simple; bh=LFcEXN5us0/aNnXc3Qv6l0mgl+6HGzST3aSdPK3VdIE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=NjB6ulhXcICes+5W3VJBI+3mwQjMZcuZv+n8BCEG/sSco2dwlOet27lZyDOAO506YdNHaZMLi259WboJFzua6IXhisUkGw/ORd9mx6agnLpPp/Ls8+dWI9oWjRIQ2JqoUmfLsnvIaoMen6FrNqsCNhCV23t1f9CfctTasKL8WMc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=V5fFGiQN; arc=none smtp.client-ip=113.46.200.224 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="V5fFGiQN" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=yx0+6bmJUwYchjwyel5xwCampYzacYXb3fZxDXktPCY=; b=V5fFGiQNvfoyA6jIihnj5whhfzFuCQHZEBGCfng0X8glq7yEdqkqsufRbgKu+mgxuWtjpAz0/ YlBotJyGSz6WEqIG2nGsJkTbZ22/3T7cjzSN0BbgZWA6EU7J5KPGXvs7HnTxLUjf6rfSLuSnQkN EOdVmidjsMiU8J93Bub7TZ0= Received: from mail.maildlp.com (unknown [172.19.162.92]) by canpmsgout09.his.huawei.com (SkyGuard) with ESMTPS id 4hpmDQ2Mr2z1cyPY; Tue, 22 Sep 2026 11:44:06 +0800 (CST) Received: from kwepemk200008.china.huawei.com (unknown [7.202.194.74]) by mail.maildlp.com (Postfix) with ESMTPS id E448B40565; Tue, 22 Sep 2026 11:55:07 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemk200008.china.huawei.com (7.202.194.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.45; Tue, 22 Sep 2026 11:55:07 +0800 From: Jinjie Ruan To: , , , , , , , , , , , , , , , , , , , , , , , CC: Subject: [PATCH v19 11/14] arm64: syscall: Simplify el0_svc_common() syscall exit path Date: Tue, 22 Sep 2026 11:55:07 +0800 Message-ID: <20260922035510.1090299-12-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260922035510.1090299-1-ruanjinjie@huawei.com> References: <20260922035510.1090299-1-ruanjinjie@huawei.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-ClientProxiedBy: kwepems200001.china.huawei.com (7.221.188.67) To kwepemk200008.china.huawei.com (7.202.194.74) Content-Type: text/plain; charset="utf-8" Remove the redundant nested conditional check within the system call exit path of el0_svc_common() to streamline the exit sequence. The fast-path block is guarded by `!IS_ENABLED(CONFIG_DEBUG_RSEQ)`, so CONFIG_DEBUG_RSEQ is guaranteed to be disabled and the call of rseq_syscall() is a no-op. Under this constraint, the code logic inside the block becomes completely identical to what the arm64_syscall_exit_to_user_mode_work() helper already does. Replace that nested logic with a direct invocation of the helper, eliminating redundant code. Before: | if (... && !IS_ENABLED(CONFIG_DEBUG_RSEQ)) { | flags =3D read_thread_flags(); | if (unlikely(flags & _TIF_SYSCALL_EXIT_WORK) || flags & _TIF_SINGLESTEP) | arm64_syscall_exit_to_user_mode_work(regs); | return; | } | trace_exit: | arm64_syscall_exit_to_user_mode_work(regs); After simplify: | if (... && !IS_ENABLED(CONFIG_DEBUG_RSEQ)) { | arm64_syscall_exit_to_user_mode_work(regs); | return; | } | trace_exit: | arm64_syscall_exit_to_user_mode_work(regs); Furthermore, Since both the conditional fast-path and the fallback slow-path now uniformly invoke arm64_syscall_exit_to_user_mode_work(), this explicit conditional branch is entirely redundant regardless of whether the evaluation is true or false. Removing it collapses the duplicated logic into a single, unconditional path. Also remove has_syscall_work(). No functional changes. Cc: Mark Rutland Cc: Will Deacon Cc: Catalin Marinas Cc: Ada Couprie Diaz Cc: Linus Walleij Cc: Yeoreum Yun Cc: Can Peng Cc: Li Qiang Cc: Ryan Roberts Reviewed-by: Linus Walleij Signed-off-by: Jinjie Ruan Tested-by: Kees Cook --- arch/arm64/kernel/syscall.c | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/arch/arm64/kernel/syscall.c b/arch/arm64/kernel/syscall.c index f1f0b6f3e32b..3488afd45d20 100644 --- a/arch/arm64/kernel/syscall.c +++ b/arch/arm64/kernel/syscall.c @@ -54,11 +54,6 @@ static void invoke_syscall(struct pt_regs *regs, unsigne= d int scno, syscall_set_return_value(current, regs, 0, ret); } =20 -static inline bool has_syscall_work(unsigned long flags) -{ - return unlikely(flags & _TIF_SYSCALL_WORK); -} - static void el0_svc_common(struct pt_regs *regs, int scno, int sc_nr, const syscall_fn_t syscall_table[]) { @@ -95,7 +90,7 @@ static void el0_svc_common(struct pt_regs *regs, int scno= , int sc_nr, return; } =20 - if (has_syscall_work(flags)) { + if (unlikely(flags & _TIF_SYSCALL_WORK)) { /* * The de-facto standard way to skip a system call using ptrace * is to set the system call to -1 (NO_SYSCALL) and set x0 to a @@ -119,19 +114,6 @@ static void el0_svc_common(struct pt_regs *regs, int s= cno, int sc_nr, } =20 invoke_syscall(regs, scno, sc_nr, syscall_table); - - /* - * The tracing status may have changed under our feet, so we have to - * check again. However, if we were tracing entry, then we always trace - * exit regardless, as the old entry assembly did. - */ - if (!has_syscall_work(flags) && !IS_ENABLED(CONFIG_DEBUG_RSEQ)) { - flags =3D read_thread_flags(); - if (unlikely(flags & _TIF_SYSCALL_EXIT_WORK) || flags & _TIF_SINGLESTEP) - arm64_syscall_exit_to_user_mode_work(regs); - return; - } - trace_exit: arm64_syscall_exit_to_user_mode_work(regs); } --=20 2.34.1 From nobody Thu Sep 24 17:02:54 2026 Received: from canpmsgout02.his.huawei.com (canpmsgout02.his.huawei.com [113.46.200.217]) (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 9D3343E5592 for ; Tue, 22 Sep 2026 03:55:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.217 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790049316; cv=none; b=ikmJ98Af/whTN8jFh94XERIuxwJ5lXKfJjHQasctQfP4vs2PkL+QASKKBGYKYXAvcptShfZYasMz3JCzhNVGkyeiHLEBjwBXqLBlEBNeWO8VKDPk8s8rBpNOR7Byk/AqkqPvgpGeNi4Mn7hJ5Es+syDD1RbkPKb9pNzoKvMlWI8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790049316; c=relaxed/simple; bh=n+Tg869FhEEiTqPHyWfEnIX4Vwk/KH+sP2eHmVex2Tw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jQL+6MnLmDe9cXj6XkvhFfd8GE2Hoa1HdhYw2cuV4TpP2X42LcZzmBVTtGfJaLWJFn6NGlSScVcygcw7sqB/toIVAX2ZDKMmuMiWO4Uh+FD0owtBc3vhQL+RDjD58c/+elOENUXI6J+lfKSeBgPS0Ajp64pa41jM+CObzWbUR60= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=VHIMjQnS; arc=none smtp.client-ip=113.46.200.217 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="VHIMjQnS" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=fscORP/Ua4vjA6xBbJI+MbSVspWXri5IAzXeu3EhZoo=; b=VHIMjQnSXL4yFb4I+cGDBOANmgmDL1BLuwJObcJhqlstUtYFW+cVVi7X13XgRs/d+EO4rup4c 7QwlhmyBKpZk0VT9QOV8TwWk15BDGDkFvvE67nYT/ZH0wVPghPWITqhixBSmVJpqFPqLpX/T1+q bsmoLYKngSWHxZn8sHQP9D8= Received: from mail.maildlp.com (unknown [172.19.162.197]) by canpmsgout02.his.huawei.com (SkyGuard) with ESMTPS id 4hpmD24JCVzcb3J; Tue, 22 Sep 2026 11:43:46 +0800 (CST) Received: from kwepemk200008.china.huawei.com (unknown [7.202.194.74]) by mail.maildlp.com (Postfix) with ESMTPS id 9A7A440579; Tue, 22 Sep 2026 11:55:08 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemk200008.china.huawei.com (7.202.194.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.45; Tue, 22 Sep 2026 11:55:07 +0800 From: Jinjie Ruan To: , , , , , , , , , , , , , , , , , , , , , , , CC: Subject: [PATCH v19 12/14] arm64: ptrace: Make return type of arm64_syscall_trace_enter() bool Date: Tue, 22 Sep 2026 11:55:08 +0800 Message-ID: <20260922035510.1090299-13-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260922035510.1090299-1-ruanjinjie@huawei.com> References: <20260922035510.1090299-1-ruanjinjie@huawei.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-ClientProxiedBy: kwepems200001.china.huawei.com (7.221.188.67) To kwepemk200008.china.huawei.com (7.202.194.74) Content-Type: text/plain; charset="utf-8" In preparation for migrating arm64 to the generic entry infrastructure, decouple the decision to execute the syscall from the syscall number itself. The ptrace and seccomp now returns a boolean flag rather than overloading NO_SYSCALL (-1). Changes: - arm64_syscall_trace_enter() returns bool: - false: abort syscall execution - true: proceed, with syscall number reread from regs - If we decide to execute the syscall, reread the syscall number and check if it is NO_SYSCALL again. Because when a tracer sets the syscall number to -1 and provides a custom return value in x0, this avoids calling invoke_syscall() which would overwrite the custom value with -ENOSYS by sys_ni_syscall(). Behavioral impact (unchanged): - User-issued syscall(-1): unchanged, returns -ENOSYS. - Tracer skip with custom x0: unchanged, returns custom x0 - Tracer skip without setting x0: unchanged, returns original argument (garbage) - Normal syscalls and seccomp rejects: unaffected No functional changes. Cc: Mark Rutland Cc: Will Deacon Cc: Catalin Marinas Cc: Ada Couprie Diaz Cc: Oleg Nesterov Cc: Linus Walleij Cc: Kevin Brodsky Cc: Yeoreum Yun Cc: Can Peng Cc: Ryan Roberts Cc: Li Qiang Reviewed-by: Linus Walleij Signed-off-by: Jinjie Ruan Tested-by: Kees Cook --- arch/arm64/include/asm/syscall.h | 2 +- arch/arm64/kernel/ptrace.c | 8 ++++---- arch/arm64/kernel/syscall.c | 6 +++++- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/arch/arm64/include/asm/syscall.h b/arch/arm64/include/asm/sysc= all.h index 7cc872fde019..f19d4a8824ba 100644 --- a/arch/arm64/include/asm/syscall.h +++ b/arch/arm64/include/asm/syscall.h @@ -121,7 +121,7 @@ static inline int syscall_get_arch(struct task_struct *= task) return AUDIT_ARCH_AARCH64; } =20 -int arm64_syscall_trace_enter(struct pt_regs *regs, unsigned long flags); +bool arm64_syscall_trace_enter(struct pt_regs *regs, unsigned long flags); void arm64_syscall_exit_work(struct pt_regs *regs, unsigned long flags); =20 static __always_inline void arm64_syscall_exit_to_user_mode_work(struct pt= _regs *regs) diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c index 610a79c1072b..c304c062abbb 100644 --- a/arch/arm64/kernel/ptrace.c +++ b/arch/arm64/kernel/ptrace.c @@ -2470,14 +2470,14 @@ static inline void syscall_enter_audit(struct pt_re= gs *regs) static inline void syscall_enter_audit(struct pt_regs *regs) { } #endif =20 -int arm64_syscall_trace_enter(struct pt_regs *regs, unsigned long flags) +bool arm64_syscall_trace_enter(struct pt_regs *regs, unsigned long flags) { int ret; =20 if (flags & (_TIF_SYSCALL_EMU | _TIF_SYSCALL_TRACE)) { ret =3D report_syscall_entry(regs); if (ret || (flags & _TIF_SYSCALL_EMU)) - return NO_SYSCALL; + return false; =20 /* ptrace might have changed thread flags */ flags =3D read_thread_flags(); @@ -2486,7 +2486,7 @@ int arm64_syscall_trace_enter(struct pt_regs *regs, u= nsigned long flags) /* Do the secure computing after ptrace; failures should be fast. */ if (unlikely(flags & _TIF_SECCOMP)) { if (!__seccomp_permit_syscall()) - return NO_SYSCALL; + return false; } =20 if (test_thread_flag(TIF_SYSCALL_TRACEPOINT)) @@ -2495,7 +2495,7 @@ int arm64_syscall_trace_enter(struct pt_regs *regs, u= nsigned long flags) if (unlikely(audit_context())) syscall_enter_audit(regs); =20 - return syscall_get_nr(current, regs); + return true; } =20 static inline bool report_single_step(unsigned long flags) diff --git a/arch/arm64/kernel/syscall.c b/arch/arm64/kernel/syscall.c index 3488afd45d20..72c6e8b7ab21 100644 --- a/arch/arm64/kernel/syscall.c +++ b/arch/arm64/kernel/syscall.c @@ -108,7 +108,11 @@ static void el0_svc_common(struct pt_regs *regs, int s= cno, int sc_nr, */ if (scno =3D=3D NO_SYSCALL) syscall_set_return_value(current, regs, -ENOSYS, 0); - scno =3D arm64_syscall_trace_enter(regs, read_thread_flags()); + if (!arm64_syscall_trace_enter(regs, read_thread_flags())) + goto trace_exit; + + /* Reread the syscall number as it might have been modified */ + scno =3D syscall_get_nr(current, regs); if (scno =3D=3D NO_SYSCALL) goto trace_exit; } --=20 2.34.1 From nobody Thu Sep 24 17:02:54 2026 Received: from canpmsgout05.his.huawei.com (canpmsgout05.his.huawei.com [113.46.200.220]) (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 CBE943E8354 for ; Tue, 22 Sep 2026 03:55:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.220 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790049328; cv=none; b=Opxu9CBsCy5w/2gel17syHKmk7++ptcOkWk68PtoHz7uO2tP3F650Mk4o8e9v03NhszF9pHHXRwtf/WFUIm9ha4woIz0Aovdg+5WspGrUTp3VWQhZzYvGty13+PQx5vOcTKNuLIf+5poJ9+0lY3f3d2XajogxY1+6gGZhhrC5uQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790049328; c=relaxed/simple; bh=l7er5A5wQTTtVstiu7DIOgro0uYRwol33Wi4DiENfIY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=E8ynzOOjzvFZxSfuU9PBtY/WOZIE2kNdalpV0RQ++KAg7U56NBCsYtVQrk3yQZGWy372RbpeMKeGZ5DnHxRZCGpH9kr9ArCrFWhk5KS54PLZUVttJToTP2fcot5xmMto4fJxzM/u73rQ9/Hd/hNKCjqeULLh1nFMUeKsRdm47h4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=FVIh7tgt; arc=none smtp.client-ip=113.46.200.220 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="FVIh7tgt" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=INJ6bbeCup/ckMTnNO9Mr6CSf9NZxAua1NDRKXoKzGc=; b=FVIh7tgtH0HthMbe57igsJvSrP6RlxFkgcNlwVhQl0SOCheH5JwbW4sXwnUaBQzkLoR2kmXdv 5w4ZmU8Y8kfm8/A2AF95AArLv7rRwan82jjB9WusLFW66KrxVj/7aJrLZpS84MsWhDJLszl/dZ2 GZxjgxf/SuiL4XKGBLBysOc= Received: from mail.maildlp.com (unknown [172.19.162.140]) by canpmsgout05.his.huawei.com (SkyGuard) with ESMTPS id 4hpmDN3QZJz12LHk; Tue, 22 Sep 2026 11:44:04 +0800 (CST) Received: from kwepemk200008.china.huawei.com (unknown [7.202.194.74]) by mail.maildlp.com (Postfix) with ESMTPS id 541AC202E6; Tue, 22 Sep 2026 11:55:09 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemk200008.china.huawei.com (7.202.194.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.45; Tue, 22 Sep 2026 11:55:08 +0800 From: Jinjie Ruan To: , , , , , , , , , , , , , , , , , , , , , , , CC: Subject: [PATCH v19 13/14] arm64: entry: Convert to generic entry Date: Tue, 22 Sep 2026 11:55:09 +0800 Message-ID: <20260922035510.1090299-14-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260922035510.1090299-1-ruanjinjie@huawei.com> References: <20260922035510.1090299-1-ruanjinjie@huawei.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-ClientProxiedBy: kwepems200001.china.huawei.com (7.221.188.67) To kwepemk200008.china.huawei.com (7.202.194.74) Content-Type: text/plain; charset="utf-8" Implement the generic entry framework for arm64 to handle system call entry and exit. This follows the migration of x86, RISC-V, LoongArch, Powerpc and S390, consolidating architecture-specific syscall tracing and auditing into the common kernel entry infrastructure, making it easier to enable advanced features on arm64, such as "Syscall User Dispatch" and "rseq time slice extension" optimization. [Background] Arm64 has already adopted generic IRQ entry. Completing the conversion to the generic syscall entry framework reduces architectural divergence, simplifies maintenance, and allows arm64 to automatically benefit from improvements in the common entry code. [Changes] 1. Kconfig and Infrastructure: - Select GENERIC_ENTRY and remove GENERIC_IRQ_ENTRY (now implied). - Migrate struct thread_info to use the syscall_work field instead of TIF flags for syscall-related tasks. 2. Thread Info and Flags: - Remove definitions for TIF_SYSCALL_TRACE, TIF_SYSCALL_AUDIT, TIF_SYSCALL_TRACEPOINT, TIF_SECCOMP, and TIF_SYSCALL_EMU. - Replace _TIF_SYSCALL_WORK and _TIF_SYSCALL_EXIT_WORK with the generic SYSCALL_WORK bitmask. - Map single-step state to SYSCALL_EXIT_TRAP in debug-monitors.c. 3. Architecture-Specific Hooks (asm/entry-common.h): Implement following arch function by porting the existing arm64 logic to the generic interface: - arch_ptrace_report_syscall_permit_entry() - arch_ptrace_report_syscall_exit() 4. Cleanup and Refactoring: Remove redundant arm64-specific syscall tracing functions from ptrace.c, including following key functions and related audit/step helpers: - arm64_syscall_trace_enter() - arm64_syscall_exit_to_user_mode_work() - arm64_syscall_exit_work() - Update el0_svc_common() in syscall.c to use the generic syscall_work checks and entry/exit call sites. [Why this matters] - Unified Interface: Aligns arm64 with the modern kernel entry standard. - Improved Maintainability: Bug fixes in kernel/entry/common.c now apply to arm64 automatically. - Feature Readiness: Simplifies the implementation of future cross-architecture syscall features. [Compatibility] This conversion maintains full ABI compatibility with existing userspace. The ptrace register-saving behavior, seccomp filtering, and syscall tracing semantics remain identical to the previous implementation. Additionally, since arm64 now does not select HAVE_GENERIC_TIF_BITS, there is no functional change regarding rseq management, as those generic entry pathways remain a no-op for this architecture." Cc: Mark Rutland Cc: Will Deacon Cc: Catalin Marinas Cc: Thomas Gleixner Cc: Peter Zijlstra Cc: Oleg Nesterov Cc: Kees Cook Cc: Andy Lutomirski Cc: Will Drewry Cc: Ada Couprie Diaz Cc: Linus Walleij Cc: Kevin Brodsky Cc: Yeoreum Yun Cc: Thomas Huth Cc: James Morse Cc: Vladimir Murzin Tested-by: Ada Couprie Diaz Reviewed-by: Ada Couprie Diaz Reviewed-by: Linus Walleij Acked-by: Peter Zijlstra (Intel) Reviewed-by: Yeoreum Yun Reviewed-by: Kevin Brodsky Suggested-by: Kevin Brodsky Suggested-by: Mark Rutland Signed-off-by: Jinjie Ruan Tested-by: Kees Cook --- arch/arm64/Kconfig | 2 +- arch/arm64/include/asm/entry-common.h | 77 ++++++++++++++ arch/arm64/include/asm/syscall.h | 14 --- arch/arm64/include/asm/thread_info.h | 19 +--- arch/arm64/kernel/debug-monitors.c | 8 ++ arch/arm64/kernel/entry-common.c | 2 +- arch/arm64/kernel/ptrace.c | 138 -------------------------- arch/arm64/kernel/signal.c | 2 +- arch/arm64/kernel/syscall.c | 9 +- 9 files changed, 95 insertions(+), 176 deletions(-) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index b5a51b0ef944..3de3f728f4d8 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -129,9 +129,9 @@ config ARM64 select GENERIC_CPU_DEVICES select GENERIC_CPU_VULNERABILITIES select GENERIC_EARLY_IOREMAP + select GENERIC_ENTRY select GENERIC_IDLE_POLL_SETUP select GENERIC_IOREMAP - select GENERIC_IRQ_ENTRY select GENERIC_IRQ_IPI select GENERIC_IRQ_KEXEC_CLEAR_VM_FORWARD select GENERIC_IRQ_PROBE diff --git a/arch/arm64/include/asm/entry-common.h b/arch/arm64/include/asm= /entry-common.h index 1905765159aa..5fffa4347f5b 100644 --- a/arch/arm64/include/asm/entry-common.h +++ b/arch/arm64/include/asm/entry-common.h @@ -3,14 +3,21 @@ #ifndef _ASM_ARM64_ENTRY_COMMON_H #define _ASM_ARM64_ENTRY_COMMON_H =20 +#include #include =20 +#include #include #include #include #include #include =20 +enum ptrace_syscall_dir { + PTRACE_SYSCALL_ENTER =3D 0, + PTRACE_SYSCALL_EXIT, +}; + #define ARCH_EXIT_TO_USER_MODE_WORK (_TIF_MTE_ASYNC_FAULT | _TIF_FOREIGN_F= PSTATE) =20 static __always_inline void arch_exit_to_user_mode_work(struct pt_regs *re= gs, @@ -54,4 +61,74 @@ static inline bool arch_irqentry_exit_need_resched(void) =20 #define arch_irqentry_exit_need_resched arch_irqentry_exit_need_resched =20 +static __always_inline unsigned long ptrace_save_reg(struct pt_regs *regs, + enum ptrace_syscall_dir dir, + int *regno) +{ + unsigned long saved_reg; + + /* + * We have some ABI weirdness here in the way that we handle syscall + * exit stops because we indicate whether or not the stop has been + * signalled from syscall entry or syscall exit by clobbering a general + * purpose register (ip/r12 for AArch32, x7 for AArch64) in the tracee + * and restoring its old value after the stop. This means that: + * + * - Any writes by the tracer to this register during the stop are + * ignored/discarded. + * + * - The actual value of the register is not available during the stop, + * so the tracer cannot save it and restore it later. + * + * - Syscall stops behave differently to seccomp and pseudo-step traps + * (the latter do not nobble any registers). + */ + *regno =3D (is_compat_task() ? 12 : 7); + saved_reg =3D regs->regs[*regno]; + regs->regs[*regno] =3D dir; + + return saved_reg; +} + +static __always_inline bool arch_ptrace_report_syscall_permit_entry(struct= pt_regs *regs) +{ + unsigned long saved_reg; + bool permit; + int regno; + + saved_reg =3D ptrace_save_reg(regs, PTRACE_SYSCALL_ENTER, ®no); + permit =3D ptrace_report_syscall_permit_entry(regs); + if (!permit) + forget_syscall(regs); + regs->regs[regno] =3D saved_reg; + + return permit; +} + +#define arch_ptrace_report_syscall_permit_entry arch_ptrace_report_syscall= _permit_entry + +static __always_inline void arch_ptrace_report_syscall_exit(struct pt_regs= *regs, + int step) +{ + unsigned long saved_reg; + int regno; + + saved_reg =3D ptrace_save_reg(regs, PTRACE_SYSCALL_EXIT, ®no); + if (!step) { + ptrace_report_syscall_exit(regs, 0); + regs->regs[regno] =3D saved_reg; + } else { + regs->regs[regno] =3D saved_reg; + + /* + * Signal a pseudo-step exception since we are stepping but + * tracer modifications to the registers may have rewound the + * state machine. + */ + ptrace_report_syscall_exit(regs, 1); + } +} + +#define arch_ptrace_report_syscall_exit arch_ptrace_report_syscall_exit + #endif /* _ASM_ARM64_ENTRY_COMMON_H */ diff --git a/arch/arm64/include/asm/syscall.h b/arch/arm64/include/asm/sysc= all.h index f19d4a8824ba..e3e716575846 100644 --- a/arch/arm64/include/asm/syscall.h +++ b/arch/arm64/include/asm/syscall.h @@ -120,18 +120,4 @@ static inline int syscall_get_arch(struct task_struct = *task) =20 return AUDIT_ARCH_AARCH64; } - -bool arm64_syscall_trace_enter(struct pt_regs *regs, unsigned long flags); -void arm64_syscall_exit_work(struct pt_regs *regs, unsigned long flags); - -static __always_inline void arm64_syscall_exit_to_user_mode_work(struct pt= _regs *regs) -{ - unsigned long flags =3D read_thread_flags(); - - rseq_syscall(regs); - - if (unlikely(flags & _TIF_SYSCALL_EXIT_WORK) || flags & _TIF_SINGLESTEP) - arm64_syscall_exit_work(regs, flags); -} - #endif /* __ASM_SYSCALL_H */ diff --git a/arch/arm64/include/asm/thread_info.h b/arch/arm64/include/asm/= thread_info.h index 56a2c9426a32..3f621ba0f961 100644 --- a/arch/arm64/include/asm/thread_info.h +++ b/arch/arm64/include/asm/thread_info.h @@ -46,6 +46,7 @@ struct thread_info { u64 mpam_partid_pmg; #endif u32 cpu; + unsigned long syscall_work; /* SYSCALL_WORK_ flags */ }; =20 #define thread_saved_pc(tsk) \ @@ -68,11 +69,6 @@ void arch_setup_new_exec(void); #define TIF_UPROBE 5 /* uprobe breakpoint or singlestep */ #define TIF_MTE_ASYNC_FAULT 6 /* MTE Asynchronous Tag Check Fault */ #define TIF_NOTIFY_SIGNAL 7 /* signal notifications exist */ -#define TIF_SYSCALL_TRACE 8 /* syscall trace active */ -#define TIF_SYSCALL_AUDIT 9 /* syscall auditing */ -#define TIF_SYSCALL_TRACEPOINT 10 /* syscall tracepoint for ftrace */ -#define TIF_SECCOMP 11 /* syscall secure computing */ -#define TIF_SYSCALL_EMU 12 /* syscall emulation active */ #define TIF_PATCH_PENDING 13 /* pending live patching update */ #define TIF_MEMDIE 18 /* is terminating due to OOM killer */ #define TIF_FREEZE 19 @@ -94,27 +90,14 @@ void arch_setup_new_exec(void); #define _TIF_NEED_RESCHED_LAZY (1 << TIF_NEED_RESCHED_LAZY) #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME) #define _TIF_FOREIGN_FPSTATE (1 << TIF_FOREIGN_FPSTATE) -#define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE) -#define _TIF_SYSCALL_AUDIT (1 << TIF_SYSCALL_AUDIT) -#define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT) -#define _TIF_SECCOMP (1 << TIF_SECCOMP) -#define _TIF_SYSCALL_EMU (1 << TIF_SYSCALL_EMU) #define _TIF_PATCH_PENDING (1 << TIF_PATCH_PENDING) #define _TIF_UPROBE (1 << TIF_UPROBE) -#define _TIF_SINGLESTEP (1 << TIF_SINGLESTEP) #define _TIF_32BIT (1 << TIF_32BIT) #define _TIF_SVE (1 << TIF_SVE) #define _TIF_MTE_ASYNC_FAULT (1 << TIF_MTE_ASYNC_FAULT) #define _TIF_NOTIFY_SIGNAL (1 << TIF_NOTIFY_SIGNAL) #define _TIF_TSC_SIGSEGV (1 << TIF_TSC_SIGSEGV) =20 -#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \ - _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | \ - _TIF_SYSCALL_EMU) - -#define _TIF_SYSCALL_EXIT_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \ - _TIF_SYSCALL_TRACEPOINT) - #ifdef CONFIG_SHADOW_CALL_STACK #define INIT_SCS \ .scs_base =3D init_shadow_call_stack, \ diff --git a/arch/arm64/kernel/debug-monitors.c b/arch/arm64/kernel/debug-m= onitors.c index e271fbac5f82..5da530034e2e 100644 --- a/arch/arm64/kernel/debug-monitors.c +++ b/arch/arm64/kernel/debug-monitors.c @@ -382,11 +382,19 @@ void user_enable_single_step(struct task_struct *task) =20 if (!test_and_set_ti_thread_flag(ti, TIF_SINGLESTEP)) set_regs_spsr_ss(task_pt_regs(task)); + + /* + * Ensure that the generic entry code triggers a trap once stepping + * out of a system call prior to executing any user instruction, + * as the generic entry code does not natively check for TIF_SINGLESTEP. + */ + set_task_syscall_work(task, SYSCALL_EXIT_TRAP); } NOKPROBE_SYMBOL(user_enable_single_step); =20 void user_disable_single_step(struct task_struct *task) { clear_ti_thread_flag(task_thread_info(task), TIF_SINGLESTEP); + clear_task_syscall_work(task, SYSCALL_EXIT_TRAP); } NOKPROBE_SYMBOL(user_disable_single_step); diff --git a/arch/arm64/kernel/entry-common.c b/arch/arm64/kernel/entry-com= mon.c index 72c03ccea59f..e8b750a962e8 100644 --- a/arch/arm64/kernel/entry-common.c +++ b/arch/arm64/kernel/entry-common.c @@ -6,7 +6,7 @@ */ =20 #include -#include +#include #include #include #include diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c index c304c062abbb..df3b0d343d7d 100644 --- a/arch/arm64/kernel/ptrace.c +++ b/arch/arm64/kernel/ptrace.c @@ -8,7 +8,6 @@ * Copyright (C) 2012 ARM Ltd. */ =20 -#include #include #include #include @@ -18,7 +17,6 @@ #include #include #include -#include #include #include #include @@ -37,13 +35,9 @@ #include #include #include -#include #include #include =20 -#define CREATE_TRACE_POINTS -#include - struct pt_regs_offset { const char *name; int offset; @@ -2388,138 +2382,6 @@ long arch_ptrace(struct task_struct *child, long re= quest, return ptrace_request(child, request, addr, data); } =20 -enum ptrace_syscall_dir { - PTRACE_SYSCALL_ENTER =3D 0, - PTRACE_SYSCALL_EXIT, -}; - -static __always_inline unsigned long ptrace_save_reg(struct pt_regs *regs, - enum ptrace_syscall_dir dir, - int *regno) -{ - unsigned long saved_reg; - - /* - * We have some ABI weirdness here in the way that we handle syscall - * exit stops because we indicate whether or not the stop has been - * signalled from syscall entry or syscall exit by clobbering a general - * purpose register (ip/r12 for AArch32, x7 for AArch64) in the tracee - * and restoring its old value after the stop. This means that: - * - * - Any writes by the tracer to this register during the stop are - * ignored/discarded. - * - * - The actual value of the register is not available during the stop, - * so the tracer cannot save it and restore it later. - * - * - Syscall stops behave differently to seccomp and pseudo-step traps - * (the latter do not nobble any registers). - */ - *regno =3D (is_compat_task() ? 12 : 7); - saved_reg =3D regs->regs[*regno]; - regs->regs[*regno] =3D dir; - - return saved_reg; -} - -static int report_syscall_entry(struct pt_regs *regs) -{ - unsigned long saved_reg; - int regno, ret; - - saved_reg =3D ptrace_save_reg(regs, PTRACE_SYSCALL_ENTER, ®no); - ret =3D !ptrace_report_syscall_permit_entry(regs); - if (ret) - forget_syscall(regs); - regs->regs[regno] =3D saved_reg; - - return ret; -} - -static void report_syscall_exit(struct pt_regs *regs) -{ - unsigned long saved_reg; - int regno; - - saved_reg =3D ptrace_save_reg(regs, PTRACE_SYSCALL_EXIT, ®no); - if (!test_thread_flag(TIF_SINGLESTEP)) { - ptrace_report_syscall_exit(regs, 0); - regs->regs[regno] =3D saved_reg; - } else { - regs->regs[regno] =3D saved_reg; - - /* - * Signal a pseudo-step exception since we are stepping but - * tracer modifications to the registers may have rewound the - * state machine. - */ - ptrace_report_syscall_exit(regs, 1); - } -} - -#ifdef CONFIG_AUDITSYSCALL -static inline void syscall_enter_audit(struct pt_regs *regs) -{ - long syscall =3D syscall_get_nr(current, regs); - unsigned long args[6]; - - syscall_get_arguments(current, regs, args); - __audit_syscall_entry(syscall, args[0], args[1], args[2], args[3]); -} -#else -static inline void syscall_enter_audit(struct pt_regs *regs) { } -#endif - -bool arm64_syscall_trace_enter(struct pt_regs *regs, unsigned long flags) -{ - int ret; - - if (flags & (_TIF_SYSCALL_EMU | _TIF_SYSCALL_TRACE)) { - ret =3D report_syscall_entry(regs); - if (ret || (flags & _TIF_SYSCALL_EMU)) - return false; - - /* ptrace might have changed thread flags */ - flags =3D read_thread_flags(); - } - - /* Do the secure computing after ptrace; failures should be fast. */ - if (unlikely(flags & _TIF_SECCOMP)) { - if (!__seccomp_permit_syscall()) - return false; - } - - if (test_thread_flag(TIF_SYSCALL_TRACEPOINT)) - trace_sys_enter(regs, syscall_get_nr(current, regs)); - - if (unlikely(audit_context())) - syscall_enter_audit(regs); - - return true; -} - -static inline bool report_single_step(unsigned long flags) -{ - if (flags & _TIF_SYSCALL_EMU) - return false; - - return flags & _TIF_SINGLESTEP; -} - -void arm64_syscall_exit_work(struct pt_regs *regs, unsigned long flags) -{ - bool step; - - audit_syscall_exit(regs); - - if (flags & _TIF_SYSCALL_TRACEPOINT) - trace_sys_exit(regs, syscall_get_return_value(current, regs)); - - step =3D report_single_step(flags); - if (step || flags & _TIF_SYSCALL_TRACE) - report_syscall_exit(regs); -} - /* * SPSR_ELx bits which are always architecturally RES0 per ARM DDI 0487D.a. * We permit userspace to set SSBS (AArch64 bit 12, AArch32 bit 23) which = is diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c index 38e6fa204c17..093eebb9d764 100644 --- a/arch/arm64/kernel/signal.c +++ b/arch/arm64/kernel/signal.c @@ -8,8 +8,8 @@ =20 #include #include +#include #include -#include #include #include #include diff --git a/arch/arm64/kernel/syscall.c b/arch/arm64/kernel/syscall.c index 72c6e8b7ab21..4a13108defb0 100644 --- a/arch/arm64/kernel/syscall.c +++ b/arch/arm64/kernel/syscall.c @@ -2,6 +2,7 @@ =20 #include #include +#include #include #include #include @@ -58,6 +59,7 @@ static void el0_svc_common(struct pt_regs *regs, int scno= , int sc_nr, const syscall_fn_t syscall_table[]) { unsigned long flags =3D read_thread_flags(); + unsigned long work; =20 regs->orig_x0 =3D regs->regs[0]; regs->syscallno =3D scno; @@ -90,7 +92,8 @@ static void el0_svc_common(struct pt_regs *regs, int scno= , int sc_nr, return; } =20 - if (unlikely(flags & _TIF_SYSCALL_WORK)) { + work =3D READ_ONCE(current_thread_info()->syscall_work); + if (unlikely(work & SYSCALL_WORK_ENTER)) { /* * The de-facto standard way to skip a system call using ptrace * is to set the system call to -1 (NO_SYSCALL) and set x0 to a @@ -108,7 +111,7 @@ static void el0_svc_common(struct pt_regs *regs, int sc= no, int sc_nr, */ if (scno =3D=3D NO_SYSCALL) syscall_set_return_value(current, regs, -ENOSYS, 0); - if (!arm64_syscall_trace_enter(regs, read_thread_flags())) + if (!syscall_trace_enter(regs, work, scno)) goto trace_exit; =20 /* Reread the syscall number as it might have been modified */ @@ -119,7 +122,7 @@ static void el0_svc_common(struct pt_regs *regs, int sc= no, int sc_nr, =20 invoke_syscall(regs, scno, sc_nr, syscall_table); trace_exit: - arm64_syscall_exit_to_user_mode_work(regs); + syscall_exit_to_user_mode_work(regs); } =20 void do_el0_svc(struct pt_regs *regs) --=20 2.34.1 From nobody Thu Sep 24 17:02:54 2026 Received: from canpmsgout05.his.huawei.com (canpmsgout05.his.huawei.com [113.46.200.220]) (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 E1A2D3E3158 for ; Tue, 22 Sep 2026 03:55:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.220 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790049325; cv=none; b=FM6TpRyr0qrOcV1ZxrYqB6M8l1zvDe8V+CfvDBSkeIPQ86X4VL6nVEW1zq2FcBwWtHnKGSebLCjZR9fzkq/HXIYV4RduosEu1jQ82RsMKhN1rTkzSadNfmN6X3OiOjMGKpAg9V7kEZOmpzA8leYDZ5DDGq2z1nzUssIEBE/Nxws= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790049325; c=relaxed/simple; bh=EXc0AgE7KOWAxfYDlIo4kE7cCwVAC7MlfwLdEL4NER4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=L8mSsNsGDvLC7p/PV3ZyoOa3xMlN0uZv1iOK/NbqdEzlNAmoP2/Rqscm3DGqZM14upLJJvM0OFz/YR1NB9URH3WwjZYweHoTvpHMtTL6IlKttiF2kXr8UcEKuX2TsuqbS0rcGX0DDBX5/HPJWMweEsWRCWigO2RUKIKpdjpokGs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=mGl2ljTx; arc=none smtp.client-ip=113.46.200.220 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="mGl2ljTx" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=LUABVRK8vkPr+ZnlJEokAN5f4PEBrCtRXbRT40/wO3M=; b=mGl2ljTxJpmXAFa7qXwzV+3WdEwlujjBpT5OyfXQTWumvZ4u6XXwsBd+ivrO2Nfx9YV7yvsqi ykof6UmlrzQ4/c83wktZ/8OEvbHCD6IuK+PRoabGsVOZ7deRrY3GohUE4HkXnaCLotqCOGYkoML Yg3e4B3j6/EInpxYXgsHAdg= Received: from mail.maildlp.com (unknown [172.19.163.0]) by canpmsgout05.his.huawei.com (SkyGuard) with ESMTPS id 4hpmDP0d2vz12LJK; Tue, 22 Sep 2026 11:44:05 +0800 (CST) Received: from kwepemk200008.china.huawei.com (unknown [7.202.194.74]) by mail.maildlp.com (Postfix) with ESMTPS id EBA7440561; Tue, 22 Sep 2026 11:55:09 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemk200008.china.huawei.com (7.202.194.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.45; Tue, 22 Sep 2026 11:55:09 +0800 From: Jinjie Ruan To: , , , , , , , , , , , , , , , , , , , , , , , CC: Subject: [PATCH v19 14/14] arm64: Inline el0_svc_common() Date: Tue, 22 Sep 2026 11:55:10 +0800 Message-ID: <20260922035510.1090299-15-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260922035510.1090299-1-ruanjinjie@huawei.com> References: <20260922035510.1090299-1-ruanjinjie@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems200001.china.huawei.com (7.221.188.67) To kwepemk200008.china.huawei.com (7.202.194.74) After converting arm64 to Generic Entry framework, the compiler no longer inlines el0_svc_common() into its caller do_el0_svc(). This introduces a small but measurable overhead in the critical system call path. Manually forcing el0_svc_common() to be inlined restores the performance. Benchmarking with perf bench syscall basic on a Kunpeng 920 platform (based on v6.19-rc1) shows a ~1% performance uplift. Inlining this function reduces function prologue/epilogue overhead and allows for better compiler optimization in the hot system call dispatch path. | Metric | W/O this patch | With this patch | Change | | ---------- | -------------- | --------------- | --------- | | Total time | 2.195 [sec] | 2.171 [sec] | =E2=86=931.1% | | usecs/op | 0.219575 | 0.217192 | =E2=86=931.1% | | ops/sec | 4,554,260 | 4,604,225 | =E2=86=911.1% | Cc: Mark Rutland Cc: Will Deacon Cc: Catalin Marinas Cc: Linus Walleij Cc: Yeoreum Yun Cc: Ada Couprie Diaz Cc: Kevin Brodsky Cc: Li Qiang Cc: Ryan Roberts Cc: Can Peng Reviewed-by: Ada Couprie Diaz Reviewed-by: Linus Walleij Reviewed-by: Yeoreum Yun Reviewed-by: Kevin Brodsky Signed-off-by: Jinjie Ruan Tested-by: Kees Cook --- arch/arm64/kernel/syscall.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kernel/syscall.c b/arch/arm64/kernel/syscall.c index 4a13108defb0..2535cae9413d 100644 --- a/arch/arm64/kernel/syscall.c +++ b/arch/arm64/kernel/syscall.c @@ -55,8 +55,8 @@ static void invoke_syscall(struct pt_regs *regs, unsigned= int scno, syscall_set_return_value(current, regs, 0, ret); } =20 -static void el0_svc_common(struct pt_regs *regs, int scno, int sc_nr, - const syscall_fn_t syscall_table[]) +static __always_inline void el0_svc_common(struct pt_regs *regs, int scno,= int sc_nr, + const syscall_fn_t syscall_table[]) { unsigned long flags =3D read_thread_flags(); unsigned long work; --=20 2.34.1