From nobody Thu Jun 11 16:09:34 2026 Received: from canpmsgout11.his.huawei.com (canpmsgout11.his.huawei.com [113.46.200.226]) (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 0C90A3BE16A for ; Mon, 11 May 2026 09:21:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.226 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778491317; cv=none; b=DcxhEsNCBeQjlsWTn25VEzuo2ZBckxQHUjLR+m8i9111CX1pq5IOKisGaMIGzpfY1gwSO9AuqDCMn9TVcI6jB2a4PNb4pRWq3eMz0DnKmY4teo1xR6fuUXzMsxerHs5nDYumCgse+O8GpSfniZMe/0VnHb8TIP+RAPhNp2QeIeQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778491317; c=relaxed/simple; bh=ALKqMJHTBFxayNkghR3TM2kbgIGqaD2M9E+CZfQIBSw=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=mOfetXlSgfRcP6LxC+RfNzW5q4/tvWGeS/zndNNq83MT2qTiTHd4th75hIp9fYjJhq9FfCjdYCtONT+ijGCc6BS4dCCnfCTNfJkV+9jiLD/bx9rEXaWI2o93c/ANEh4z/9fvVEaTXmTqBpK4xZmTdcOwb0KKC7QsZC5NCED3lU0= 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=AyPE2M62; arc=none smtp.client-ip=113.46.200.226 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="AyPE2M62" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=xjBehfNor6u2s7YFH6hquSqXuXzybcRErtfl/WoMw+I=; b=AyPE2M62vLQo6cfUp8QhEeQPIPp5alpjMGXaOPKiS2E5fYl3GfOFb0MFjnCpmoGJzQ0jrA2Yv ciNmugvE/zxkeZp4+9ZbjVTRNcLlz0kFd0N1YNNO3VX5JTQdoSOMRW2t27tzBwbVCfH2JBN/OjI QjLzYBR8zI/PDmZ08gFYHBg= Received: from mail.maildlp.com (unknown [172.19.162.92]) by canpmsgout11.his.huawei.com (SkyGuard) with ESMTPS id 4gDYvB2lfMzKm8x; Mon, 11 May 2026 17:14:14 +0800 (CST) Received: from dggpemf500011.china.huawei.com (unknown [7.185.36.131]) by mail.maildlp.com (Postfix) with ESMTPS id A31CD4056C; Mon, 11 May 2026 17:21:52 +0800 (CST) Received: from huawei.com (10.90.53.73) by dggpemf500011.china.huawei.com (7.185.36.131) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Mon, 11 May 2026 17:21:51 +0800 From: Jinjie Ruan To: , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v15 01/11] entry: Fix potential syscall truncation in syscall_trace_enter() Date: Mon, 11 May 2026 17:20:53 +0800 Message-ID: <20260511092103.1974980-2-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260511092103.1974980-1-ruanjinjie@huawei.com> References: <20260511092103.1974980-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: kwepems200002.china.huawei.com (7.221.188.68) To dggpemf500011.china.huawei.com (7.185.36.131) Content-Type: text/plain; charset="utf-8" In syscall_trace_enter(), the current logic returns "ret ? : syscall". While __secure_computing() currently only returns 0 (allow) or -1 (kill), this "ret ? : syscall" pattern is conceptually flawed. If __secure_computing() were to return a non-zero value that isn't -1, it would unintentionally override the actual system call number. This logic is redundant because if seccomp denies the syscall, the execution path should already be handled by the caller based on the error return, rather than conflating the return code with the syscall number. Fix it by explicitly returning the syscall number. This ensures the syscall register remains untainted by the trace return values and aligns with the expectation that seccomp-related interceptions are handled via the -1 return status. Cc: Thomas Gleixner Fixes: 142781e108b1 ("entry: Provide generic syscall entry functionality") Signed-off-by: Jinjie Ruan Reviewed-by: Linus Walleij --- include/linux/entry-common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/entry-common.h b/include/linux/entry-common.h index 416a3352261f..462a51fc044d 100644 --- a/include/linux/entry-common.h +++ b/include/linux/entry-common.h @@ -113,7 +113,7 @@ static __always_inline long syscall_trace_enter(struct = pt_regs *regs, unsigned l =20 syscall_enter_audit(regs, syscall); =20 - return ret ? : syscall; + return syscall; } =20 /** --=20 2.34.1 From nobody Thu Jun 11 16:09:34 2026 Received: from canpmsgout01.his.huawei.com (canpmsgout01.his.huawei.com [113.46.200.216]) (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 B50023BB9FC for ; Mon, 11 May 2026 09:21:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.216 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778491319; cv=none; b=bHnMLCNv4yDsTIEXu4Ak8zpY96UVIQ4aYiNuAAtrJntoKYC+J33cDVboIYBUXM++nc/b/3eNvFaQgYJzUCyezvoosheHCPtO5hFnO0zW1yIMGjXsba7fONYTNwemkKnz1lnaEAxY/PO7CjMOUwB/20nxOlf2ebLQ+S9SLlfkfVw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778491319; c=relaxed/simple; bh=F74+n5/9ceeB1gch5MBP3CEYmCU3DntudZJDcq/jf00=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qhFzx5Q4BaJcK5ffKpeEsw5oktNbWRhlNnnyUhnu6c0CT3CrV1WSwia3lfeDlnP9mMuaiypFmFW29M+hCAV8/UZ+mGEYvcAuvg4XpBf4m8WWx8ttbW6apjP2/LCFuQx2xCuonRg1kEGCWKRdroJXwcgVsUy69Gdmwti/p9VmtAM= 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=yraL6ssZ; arc=none smtp.client-ip=113.46.200.216 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="yraL6ssZ" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=3t2ot8j09mFgea9VNmviu92l2DEgtzfWg+2pijN9X4g=; b=yraL6ssZp2imOPlGy2MCvw0iTVgMOoQ3J5t+JQbZKq511XeQaO5q+858MIqJ1MiHBpUXaeEC6 5Mj+ggaa7VU3AZx5eFqnrA5FdR/sdVhqWARs5xAouHBmZg6CeKc33VDeyNojXNMN6J1M9CyqCMR uj//sGLGpzIo4wKPCvz5Qss= Received: from mail.maildlp.com (unknown [172.19.162.144]) by canpmsgout01.his.huawei.com (SkyGuard) with ESMTPS id 4gDYvC47Qqz1T4JS; Mon, 11 May 2026 17:14:15 +0800 (CST) Received: from dggpemf500011.china.huawei.com (unknown [7.185.36.131]) by mail.maildlp.com (Postfix) with ESMTPS id 1C8904056D; Mon, 11 May 2026 17:21:54 +0800 (CST) Received: from huawei.com (10.90.53.73) by dggpemf500011.china.huawei.com (7.185.36.131) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Mon, 11 May 2026 17:21:52 +0800 From: Jinjie Ruan To: , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v15 02/11] arm64/ptrace: Refactor syscall_trace_enter/exit() to accept flags parameter Date: Mon, 11 May 2026 17:20:54 +0800 Message-ID: <20260511092103.1974980-3-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260511092103.1974980-1-ruanjinjie@huawei.com> References: <20260511092103.1974980-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: kwepems200002.china.huawei.com (7.221.188.68) To dggpemf500011.china.huawei.com (7.185.36.131) Refactor syscall_trace_enter() and syscall_trace_exit() to move thread flag reading to the caller. This aligns arm64's syscall trace enter/exit function signature with generic entry framework. [Changes] 1. Function signature changes: - syscall_trace_enter(regs) =E2=86=92 syscall_trace_enter(regs, flags) - syscall_trace_exit(regs) =E2=86=92 syscall_trace_exit(regs, flags) 2. Move flags reading to caller: - Previously: read_thread_flags() called inside each function. - Now: caller (like el0_svc_common) passes flags as parameter. 3. Update syscall.c: - el0_svc_common() now passes flags to tracing functions and re-fetches flags before entry/exit to handle potential TIF updates. [Why this matters] - Aligns arm64 with the generic entry interface. - Makes future migration to generic entry framework. No functional changes intended. Cc: Mark Rutland Cc: Will Deacon Cc: Catalin Marinas Reviewed-by: Linus Walleij Reviewed-by: Yeoreum Yun Reviewed-by: Kevin Brodsky Signed-off-by: Jinjie Ruan --- arch/arm64/include/asm/syscall.h | 4 ++-- arch/arm64/kernel/ptrace.c | 7 ++----- arch/arm64/kernel/syscall.c | 6 ++++-- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/arch/arm64/include/asm/syscall.h b/arch/arm64/include/asm/sysc= all.h index 5e4c7fc44f73..30b203ef156b 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); -void syscall_trace_exit(struct pt_regs *regs); +int 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 ba5eab23fd90..e4d524ccbc7b 100644 --- a/arch/arm64/kernel/ptrace.c +++ b/arch/arm64/kernel/ptrace.c @@ -2408,9 +2408,8 @@ static void report_syscall_exit(struct pt_regs *regs) } } =20 -int syscall_trace_enter(struct pt_regs *regs) +int 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)) { @@ -2432,10 +2431,8 @@ int syscall_trace_enter(struct pt_regs *regs) return regs->syscallno; } =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(); - audit_syscall_exit(regs); =20 if (flags & _TIF_SYSCALL_TRACEPOINT) diff --git a/arch/arm64/kernel/syscall.c b/arch/arm64/kernel/syscall.c index 358ddfbf1401..f6f87b042995 100644 --- a/arch/arm64/kernel/syscall.c +++ b/arch/arm64/kernel/syscall.c @@ -113,7 +113,8 @@ 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); + flags =3D read_thread_flags(); + scno =3D syscall_trace_enter(regs, flags); if (scno =3D=3D NO_SYSCALL) goto trace_exit; } @@ -132,7 +133,8 @@ static void el0_svc_common(struct pt_regs *regs, int sc= no, int sc_nr, } =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 Jun 11 16:09:34 2026 Received: from canpmsgout01.his.huawei.com (canpmsgout01.his.huawei.com [113.46.200.216]) (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 AAC993BD642 for ; Mon, 11 May 2026 09:21:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.216 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778491319; cv=none; b=tq1bVJ8+gUhB1yMZEGxohpZzyMnH2jY/bdqBaDTbtNJZMWANNyxiwWdsyEPDJtolaYJ10T+B5s5fwLszfS106FBaxJvJ1NbRnFT58azyP6H5FTFKtAy0o+xNzzfMfEC2WfniHecow1fYE2C7asQtcPj7zFX1Logn8brA0LMe5Bs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778491319; c=relaxed/simple; bh=OY1r9vIvmG68liqPNga0/SrL9iPB6BA+xdbslRq4EkA=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Apb95rTf1hff6N7H56lmM3qCXgYi/5G7P5h7qesHc7hrGxueIe4XMm1eBcGR6UQF1nspTaKQ0q3jKyIrJ62ZiAjNanMBelIqkvESkxWEbZMEnaAc9JlL8FWseK0g2j9KMntA/zRQe057z/ruXqAQgMup2S9KR4JO1KGGTPQySbI= 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=4WY5Go4K; arc=none smtp.client-ip=113.46.200.216 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="4WY5Go4K" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=d1a21J/DT6jyDYs1WrnNDIORGxosTg5TGC6mPo0ri0Y=; b=4WY5Go4K76aUqku54jDBtdEY1X0fqcswrFggzWpZ1L1xLrZsEaJbRc7Yoq2b7kJ83Fi26ZPnO nvYJbxryrhZ854pvke+uaHIgZPsocqG6XiQJ59YPo7WwMnMVH9GcvTattrrfihV+n/+dZEN/BCt XTiz6/k1yY1VkKvRymaIW8A= Received: from mail.maildlp.com (unknown [172.19.162.223]) by canpmsgout01.his.huawei.com (SkyGuard) with ESMTPS id 4gDYvF07d5z1T4FV; Mon, 11 May 2026 17:14:17 +0800 (CST) Received: from dggpemf500011.china.huawei.com (unknown [7.185.36.131]) by mail.maildlp.com (Postfix) with ESMTPS id 84FB740561; Mon, 11 May 2026 17:21:55 +0800 (CST) Received: from huawei.com (10.90.53.73) by dggpemf500011.china.huawei.com (7.185.36.131) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Mon, 11 May 2026 17:21:54 +0800 From: Jinjie Ruan To: , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v15 03/11] arm64/ptrace: Use syscall_get_nr() helper for syscall_trace_enter() Date: Mon, 11 May 2026 17:20:55 +0800 Message-ID: <20260511092103.1974980-4-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260511092103.1974980-1-ruanjinjie@huawei.com> References: <20260511092103.1974980-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: kwepems200002.china.huawei.com (7.221.188.68) To dggpemf500011.china.huawei.com (7.185.36.131) Content-Type: text/plain; charset="utf-8" Use syscall_get_nr() to get syscall number for syscall_trace_enter(). This aligns arm64's internal tracing logic with the generic entry framework. [Changes] 1. Use syscall_get_nr() helper: - Replace direct regs->syscallno access with syscall_get_nr(current, regs). - This helper is functionally equivalent to direct access on arm64. 2. Re-read syscall number after tracepoint: - Re-fetch the syscall number after trace_sys_enter() as it may have been modified by BPF or ftrace probes, matching generic entry behavior. [Why this matters] - Aligns arm64 with the generic entry interface. - Makes future migration to generic entry framework. - Properly handles syscall number modifications by tracers. - Uses standard architecture-independent helpers. No functional changes intended. Cc: Mark Rutland Cc: Will Deacon Cc: Catalin Marinas Reviewed-by: Linus Walleij Reviewed-by: Yeoreum Yun Reviewed-by: Kevin Brodsky Signed-off-by: Jinjie Ruan --- arch/arm64/kernel/ptrace.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c index e4d524ccbc7b..8d296a07fbf7 100644 --- a/arch/arm64/kernel/ptrace.c +++ b/arch/arm64/kernel/ptrace.c @@ -2410,6 +2410,7 @@ static void report_syscall_exit(struct pt_regs *regs) =20 int syscall_trace_enter(struct pt_regs *regs, unsigned long flags) { + long syscall; int ret; =20 if (flags & (_TIF_SYSCALL_EMU | _TIF_SYSCALL_TRACE)) { @@ -2422,13 +2423,23 @@ int syscall_trace_enter(struct pt_regs *regs, unsig= ned long flags) if (secure_computing() =3D=3D -1) return NO_SYSCALL; =20 - if (test_thread_flag(TIF_SYSCALL_TRACEPOINT)) - trace_sys_enter(regs, regs->syscallno); + /* Either of the above might have changed the syscall number */ + syscall =3D syscall_get_nr(current, regs); =20 - audit_syscall_entry(regs->syscallno, regs->orig_x0, regs->regs[1], + if (test_thread_flag(TIF_SYSCALL_TRACEPOINT)) { + trace_sys_enter(regs, syscall); + + /* + * Probes or BPF hooks in the tracepoint may have changed the + * system call number as well. + */ + syscall =3D syscall_get_nr(current, regs); + } + + audit_syscall_entry(syscall, regs->orig_x0, regs->regs[1], regs->regs[2], regs->regs[3]); =20 - return regs->syscallno; + return syscall; } =20 void syscall_trace_exit(struct pt_regs *regs, unsigned long flags) --=20 2.34.1 From nobody Thu Jun 11 16:09:34 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 55B9E3C0639 for ; Mon, 11 May 2026 09:21:59 +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=1778491321; cv=none; b=WJ8OkQqpb+kdk0TH0yfH0CYOWpsLLyOXQ9FHI0/wyggo127Jvflmft+Npik5V+Fodrnjapp801x8h1X7gANaOKo4ohJniqIh0SeHMK3U2ON3AnmSZ/YX9kgJS+U5edUU+UYQ/VbmxgWk37NWAgQWsX4h/B1uFzAZGTNKIsTHSFw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778491321; c=relaxed/simple; bh=dqdrZQjKasgOzY0YEIKk9E4eHwFrbMutMRGiRnSP2m0=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=lLZbawn535K/02KBxMDlI+Z/PSnAOiyl3lkXESnm3FQ2gPqMj1TYgTLM96shXq7hBeyQjnl2g+Str+LMBmj1mzlNlSmTwdLcm+BHIeRHJ+zXYaz8KoDzU0VjfGDi2SGfekypHhAWlDUdUOllmEqH9QBMdsFzTyWWJO9HLeXTxjs= 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=cSLU3tSz; 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="cSLU3tSz" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=R8qYWnpqKAc3CsGsbqeXYsQ1vhM73dRDkO1eFhyrhzk=; b=cSLU3tSzaTZpOMI1rVd0UdYXZkYzYL2r9bx37f9BzctxaTz+30ddsCPJJztNoyqxJGIZrr3ye Z7uRHhB+9x54KGYg4VekfON7kNB/uRGwxRlFeo3OITd5sutA/hor6wNFHwqeQvxE8l6OQ5nBFjP wK15L5IJ3AIXZTwIWbIx2tg= Received: from mail.maildlp.com (unknown [172.19.163.104]) by canpmsgout05.his.huawei.com (SkyGuard) with ESMTPS id 4gDYvt4QGcz12LKK; Mon, 11 May 2026 17:14:50 +0800 (CST) Received: from dggpemf500011.china.huawei.com (unknown [7.185.36.131]) by mail.maildlp.com (Postfix) with ESMTPS id 00C654056D; Mon, 11 May 2026 17:21:57 +0800 (CST) Received: from huawei.com (10.90.53.73) by dggpemf500011.china.huawei.com (7.185.36.131) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Mon, 11 May 2026 17:21:55 +0800 From: Jinjie Ruan To: , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v15 04/11] arm64/ptrace: Expand secure_computing() in place Date: Mon, 11 May 2026 17:20:56 +0800 Message-ID: <20260511092103.1974980-5-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260511092103.1974980-1-ruanjinjie@huawei.com> References: <20260511092103.1974980-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: kwepems200002.china.huawei.com (7.221.188.68) To dggpemf500011.china.huawei.com (7.185.36.131) Content-Type: text/plain; charset="utf-8" Refactor syscall_trace_enter() by open-coding the seccomp check to align with the generic entry framework. [Background] The generic entry implementation expands the seccomp check in-place instead of using the secure_computing() wrapper. It directly tests SYSCALL_WORK_SECCOMP and calls the underlying __secure_computing() function to handle syscall filtering. [Changes] 1. Open-code seccomp check: - Instead of calling the secure_computing() wrapper, explicitly check the 'flags' parameter for _TIF_SECCOMP. - Call __secure_computing() directly if the flag is set. [Why this matters] - Aligns the arm64 syscall path with the generic entry implementation, simplifying future migration to the generic entry framework. - No functional changes are intended; seccomp behavior remains identical. Cc: Mark Rutland Cc: Will Deacon Cc: Catalin Marinas Reviewed-by: Linus Walleij Reviewed-by: Yeoreum Yun Reviewed-by: Kevin Brodsky Signed-off-by: Jinjie Ruan --- arch/arm64/kernel/ptrace.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c index 8d296a07fbf7..ba8cb5ec967b 100644 --- a/arch/arm64/kernel/ptrace.c +++ b/arch/arm64/kernel/ptrace.c @@ -2420,8 +2420,11 @@ int syscall_trace_enter(struct pt_regs *regs, unsign= ed long flags) } =20 /* Do the secure computing after ptrace; failures should be fast. */ - if (secure_computing() =3D=3D -1) - return NO_SYSCALL; + if (flags & _TIF_SECCOMP) { + ret =3D __secure_computing(); + if (ret =3D=3D -1) + return NO_SYSCALL; + } =20 /* Either of the above might have changed the syscall number */ syscall =3D syscall_get_nr(current, regs); --=20 2.34.1 From nobody Thu Jun 11 16:09:34 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 49A643C3432 for ; Mon, 11 May 2026 09:22:01 +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=1778491324; cv=none; b=jK/pVrt1f3BGqyxQ2TKbLbPKjAYwlDngkiGi9zJsf38HeodkwHTcsOa8qoDzkzHetuZ7JpLrYpi0PtCOTHAOBl6fivhVtfH4QmTvaLcqyJWuT1VeBibOp55k6j2EdvWz2MGcA+bVKqDqjhEO1CqjTl/R+61nbJHlLoEyDGa0SBo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778491324; c=relaxed/simple; bh=8egtd3rdx9eguJiY3hEoM742fZLJtAgwzdSBbnq36Y4=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=JZG9/cs18/aFEqrmmmMqb4R1D/syGF4ohwwTGUlSypl4u7DMfS8s6nyXQlsoAXoQvXxq5D/NKbeJLUYP+YbE9WSMinNbHY9KYk2OvJhaXA0lXC7UjVdBQz3V73xlQdxvphScBfoIDfsGyhMisJ3Tt0lONGXpbvxBq97nV83CGX4= 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=eViMSrSE; 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="eViMSrSE" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=Y0+aAwFLi92+TRI38jn2hv+CS+CcDbRx2xD0b1Cai4s=; b=eViMSrSEJO07cHxkhI1BqI/e3Keb8gBPPMBs+Gn2M8eApbLmx8akFffez5pN7JVmT2nCTG7cS WO9yu9xHEGNWJuJFPZq54OFFz8y6Ehf0H/1dxni7K1b4N0w2jvchYveg2MyWQ6ymxrAr77Xufsb CqKExTrAGaqqG7yi4c6K2kg= Received: from mail.maildlp.com (unknown [172.19.162.197]) by canpmsgout06.his.huawei.com (SkyGuard) with ESMTPS id 4gDYvL6JDdzRhSh; Mon, 11 May 2026 17:14:22 +0800 (CST) Received: from dggpemf500011.china.huawei.com (unknown [7.185.36.131]) by mail.maildlp.com (Postfix) with ESMTPS id 6B6AB40569; Mon, 11 May 2026 17:21:58 +0800 (CST) Received: from huawei.com (10.90.53.73) by dggpemf500011.china.huawei.com (7.185.36.131) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Mon, 11 May 2026 17:21:56 +0800 From: Jinjie Ruan To: , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v15 05/11] arm64/ptrace: Use syscall_get_arguments() helper for audit Date: Mon, 11 May 2026 17:20:57 +0800 Message-ID: <20260511092103.1974980-6-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260511092103.1974980-1-ruanjinjie@huawei.com> References: <20260511092103.1974980-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: kwepems200002.china.huawei.com (7.221.188.68) To dggpemf500011.china.huawei.com (7.185.36.131) Content-Type: text/plain; charset="utf-8" Extract syscall_enter_audit() helper and use syscall_get_arguments() to get syscall arguments, matching the generic entry implementation. The new code: - Checks audit_context() first to avoid unnecessary memcpy when audit is not active. - Uses syscall_get_arguments() helper instead of directly accessing regs fields. - Is now exactly equivalent to generic entry's syscall_enter_audit(). No functional changes. Cc: Mark Rutland Cc: Will Deacon Cc: Catalin Marinas Reviewed-by: Linus Walleij Reviewed-by: Yeoreum Yun Reviewed-by: Kevin Brodsky Signed-off-by: Jinjie Ruan --- arch/arm64/kernel/ptrace.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c index ba8cb5ec967b..20441e0f6328 100644 --- a/arch/arm64/kernel/ptrace.c +++ b/arch/arm64/kernel/ptrace.c @@ -2408,6 +2408,16 @@ static void report_syscall_exit(struct pt_regs *regs) } } =20 +static inline void syscall_enter_audit(struct pt_regs *regs, long syscall) +{ + if (unlikely(audit_context())) { + unsigned long args[6]; + + syscall_get_arguments(current, regs, args); + audit_syscall_entry(syscall, args[0], args[1], args[2], args[3]); + } +} + int syscall_trace_enter(struct pt_regs *regs, unsigned long flags) { long syscall; @@ -2439,8 +2449,7 @@ int syscall_trace_enter(struct pt_regs *regs, unsigne= d long flags) syscall =3D syscall_get_nr(current, regs); } =20 - audit_syscall_entry(syscall, regs->orig_x0, regs->regs[1], - regs->regs[2], regs->regs[3]); + syscall_enter_audit(regs, syscall); =20 return syscall; } --=20 2.34.1 From nobody Thu Jun 11 16:09:34 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 EEDFC3BE14A for ; Mon, 11 May 2026 09:22:01 +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=1778491324; cv=none; b=aCtQRgxTJapwYomcL5ZHL3A2UUch6xgAtJvf01nHPjj1+/d1A4LlinNFC+5Ziyk6Yao2AIxOyL0CmuM5+QSfxBQlLx5fxbP9ybr21lISG5v3do7Yr0uhAJCjmkHrAxrnjFbHD43eJLEaKqJm69aeyZ/RSOITfln1BjWB0FBBtAo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778491324; c=relaxed/simple; bh=By66Ga7WmO02ABr/XgSJweKjPvMypBFNaCYNAsWAXBA=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=K+q3l3+KpwCy+w2cU5wfNltZvPNv8GnOk9xpUoz2aJLqcEJNPwzqme0faG8j0svjg8ho31wrkLH/tCIYQtgSCRV/JP3yq7/aqLuBTPNqND1qvtivgymVWX/8/u4L95p76CBR14sb0dyXoq6J0F4IpxOPn+dFipk+pRUPGhz7u18= 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=xydvXXV2; 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="xydvXXV2" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=LbfiKYp0BjJiBaKRav7eVm8nvSFoVg8FGD5F8goH9yE=; b=xydvXXV2eSRteu3BRkV0wMQzyQ7j/Z+cYvWbIz79iBXTpsLGFBzY51vAPBd5Fkkx0vVcAeAq9 Rw79nTj9ZIMM25QOkd0RKbHt4jlONxY77Zzjl/8veCzC6vs0KUJklq+To1FNbArIwhWBctILlvs PMqg3mm0nJqhdXxczlUtnus= Received: from mail.maildlp.com (unknown [172.19.162.223]) by canpmsgout04.his.huawei.com (SkyGuard) with ESMTPS id 4gDYvK3JWvz1prKs; Mon, 11 May 2026 17:14:21 +0800 (CST) Received: from dggpemf500011.china.huawei.com (unknown [7.185.36.131]) by mail.maildlp.com (Postfix) with ESMTPS id D5C1040572; Mon, 11 May 2026 17:21:59 +0800 (CST) Received: from huawei.com (10.90.53.73) by dggpemf500011.china.huawei.com (7.185.36.131) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Mon, 11 May 2026 17:21:58 +0800 From: Jinjie Ruan To: , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v15 06/11] arm64: ptrace: Move rseq_syscall() before audit_syscall_exit() Date: Mon, 11 May 2026 17:20:58 +0800 Message-ID: <20260511092103.1974980-7-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260511092103.1974980-1-ruanjinjie@huawei.com> References: <20260511092103.1974980-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: kwepems200002.china.huawei.com (7.221.188.68) To dggpemf500011.china.huawei.com (7.185.36.131) 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_SETREGS. 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 Reviewed-by: Linus Walleij Reviewed-by: Yeoreum Yun Reviewed-by: Kevin Brodsky Signed-off-by: Jinjie Ruan --- 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 20441e0f6328..15a45eeb56da 100644 --- a/arch/arm64/kernel/ptrace.c +++ b/arch/arm64/kernel/ptrace.c @@ -2456,6 +2456,8 @@ int syscall_trace_enter(struct pt_regs *regs, unsigne= d long flags) =20 void syscall_trace_exit(struct pt_regs *regs, unsigned long flags) { + rseq_syscall(regs); + audit_syscall_exit(regs); =20 if (flags & _TIF_SYSCALL_TRACEPOINT) @@ -2463,8 +2465,6 @@ void syscall_trace_exit(struct pt_regs *regs, unsigne= d long flags) =20 if (flags & (_TIF_SYSCALL_TRACE | _TIF_SINGLESTEP)) report_syscall_exit(regs); - - rseq_syscall(regs); } =20 /* --=20 2.34.1 From nobody Thu Jun 11 16:09:34 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 406901E49F for ; Mon, 11 May 2026 09:22:04 +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=1778491326; cv=none; b=EBmh+uBEFlmdxGb+6kVuK2Gh0sFrq5BngtbxCpIyl/uhJ4Pj+f/VvSRaNZ+8Rq1FMo0gv167VqQyqe7sqm4qPjMyA1q5pk8g3gjGWM1nEA6dn0SCZJpcNq9gFvIfAMP28nkHh4Nk6AWvySdd9NemQKCppFN1B6cInlmHvv3+iEI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778491326; c=relaxed/simple; bh=5hWeIz2jr/5o2l93iBV/miMSMC1wsxEEyU5g5F9+2R8=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=XV5xVbzmTAlgNqr8aSwM1yJeAHaxfOeBs6wbnjhaH7czuvu4Jv73bz77DK2EuuswjJoquSfWA1KirboMxqve8U/zqkcStVm5H8CY5O0pbnenzfVvD7Hp0ETnMYnBd13l1wOsXak9ND+EubKGAy/acHhbRhcI4GPMJuY9mcjloi4= 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=efqEWLdn; 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="efqEWLdn" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=H41jepRbzKsmWnrdzhr6aJyxunmF1jWnbMyJErzNgrQ=; b=efqEWLdnU/91H/vAw2v4t5dsy47yDyd+SyPfD6F22lXtHYHWXsyVWt/GXLJ6poUmGo9fSna9v BU8yd49n8l4qnQCXBIU5UDcbLGqHgb13UJX8UGW+xGWGebyVJ/JlYk8L8halWW9P+arywlzJ5ny Fqn8ufDm4CkYtawriZz/E+o= Received: from mail.maildlp.com (unknown [172.19.163.15]) by canpmsgout10.his.huawei.com (SkyGuard) with ESMTPS id 4gDYvQ5wZ8z1K96p; Mon, 11 May 2026 17:14:26 +0800 (CST) Received: from dggpemf500011.china.huawei.com (unknown [7.185.36.131]) by mail.maildlp.com (Postfix) with ESMTPS id 5371740573; Mon, 11 May 2026 17:22:01 +0800 (CST) Received: from huawei.com (10.90.53.73) by dggpemf500011.china.huawei.com (7.185.36.131) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Mon, 11 May 2026 17:21:59 +0800 From: Jinjie Ruan To: , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v15 07/11] arm64: syscall: Introduce syscall_exit_to_user_mode_work() Date: Mon, 11 May 2026 17:20:59 +0800 Message-ID: <20260511092103.1974980-8-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260511092103.1974980-1-ruanjinjie@huawei.com> References: <20260511092103.1974980-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: kwepems200002.china.huawei.com (7.221.188.68) To dggpemf500011.china.huawei.com (7.185.36.131) Content-Type: text/plain; charset="utf-8" Refactor the system call exit path to align with the generic entry framework. This consolidates thread flag checking, rseq handling, and syscall tracing into a structure that mirrors the generic syscall_exit_to_user_mode_work() implementation. [Rationale] The generic entry code employs a hierarchical approach for syscall exit work: 1. syscall_exit_to_user_mode_work(): The entry point that handles rseq and checks if further exit work (tracing/audit) is required. 2. syscall_exit_work(): Performs the actual tracing, auditing, and ptrace reporting. [Changes] - Rename and Encapsulate: Rename syscall_trace_exit() to syscall_exit_work() and make it static, as it is now an internal helper for the exit path. - New Entry Point: Implement syscall_exit_to_user_mode_work() to replace the manual flag-reading logic in el0_svc_common(). This function now encapsulates the rseq_syscall() call and the conditional execution of syscall_exit_work(). - Simplify el0_svc_common(): Remove the complex conditional checks for tracing and CONFIG_DEBUG_RSEQ at the end of the syscall path, delegating this responsibility to the new helper. - Helper Migration: Move has_syscall_work() to asm/syscall.h to allow its reuse across ptrace.c and syscall.c. - Clean up RSEQ: Remove the explicit IS_ENABLED(CONFIG_DEBUG_RSEQ) check in the caller, as rseq_syscall() is already a no-op when the config is disabled. Cc: Mark Rutland Cc: Will Deacon Cc: Catalin Marinas Reviewed-by: Linus Walleij Reviewed-by: Yeoreum Yun Reviewed-by: Kevin Brodsky Signed-off-by: Jinjie Ruan --- v15 - Make syscall_exit_to_user_mode_work() __always_inline to keep the fast-path performance as Sashiko pointed out. --- arch/arm64/include/asm/syscall.h | 18 +++++++++++++++++- arch/arm64/kernel/ptrace.c | 5 +---- arch/arm64/kernel/syscall.c | 20 +------------------- 3 files changed, 19 insertions(+), 24 deletions(-) diff --git a/arch/arm64/include/asm/syscall.h b/arch/arm64/include/asm/sysc= all.h index 30b203ef156b..b331e09b937f 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,6 +122,21 @@ static inline int syscall_get_arch(struct task_struct = *task) } =20 int syscall_trace_enter(struct pt_regs *regs, unsigned long flags); -void syscall_trace_exit(struct pt_regs *regs, unsigned long flags); +void syscall_exit_work(struct pt_regs *regs, unsigned long flags); + +static inline bool has_syscall_work(unsigned long flags) +{ + return unlikely(flags & _TIF_SYSCALL_WORK); +} + +static __always_inline void syscall_exit_to_user_mode_work(struct pt_regs = *regs) +{ + unsigned long flags =3D read_thread_flags(); + + rseq_syscall(regs); + + if (has_syscall_work(flags) || flags & _TIF_SINGLESTEP) + syscall_exit_work(regs, flags); +} =20 #endif /* __ASM_SYSCALL_H */ diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c index 15a45eeb56da..256aa20377e1 100644 --- a/arch/arm64/kernel/ptrace.c +++ b/arch/arm64/kernel/ptrace.c @@ -28,7 +28,6 @@ #include #include #include -#include =20 #include #include @@ -2454,10 +2453,8 @@ int syscall_trace_enter(struct pt_regs *regs, unsign= ed long flags) return syscall; } =20 -void syscall_trace_exit(struct pt_regs *regs, unsigned long flags) +void syscall_exit_work(struct pt_regs *regs, unsigned long flags) { - rseq_syscall(regs); - audit_syscall_exit(regs); =20 if (flags & _TIF_SYSCALL_TRACEPOINT) diff --git a/arch/arm64/kernel/syscall.c b/arch/arm64/kernel/syscall.c index f6f87b042995..dac7bcc4bbdf 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[]) { @@ -120,21 +115,8 @@ 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 (!has_syscall_work(flags) && !(flags & _TIF_SINGLESTEP)) - return; - } - trace_exit: - flags =3D read_thread_flags(); - syscall_trace_exit(regs, flags); + syscall_exit_to_user_mode_work(regs); } =20 void do_el0_svc(struct pt_regs *regs) --=20 2.34.1 From nobody Thu Jun 11 16:09:34 2026 Received: from canpmsgout11.his.huawei.com (canpmsgout11.his.huawei.com [113.46.200.226]) (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 CBCBF3C4567 for ; Mon, 11 May 2026 09:22:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.226 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778491326; cv=none; b=m+jsM4pBVruxf7XhXkW6+82smbKMJjQRjPHKJReEhw1qGIak2i4gx85OOcQl/fHuW7HiRK2zXSE0ZjRzNXavsF/oGMXjfxFJtLv8klgn3uWyTHmHOd4f89KNlkvk/fPa3mdbEyntaiLF75y+0QkeK7NsqvE4cpOql8fK19ClOQc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778491326; c=relaxed/simple; bh=DZDkffldqf3AFzC4BwFm+x1Z+AQ9BN1n/FUeBnVvvN0=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=NUqib5g0AplSZWeVEFcs8J65Emj9OLRAWVn0/S9LAzRHcbx9O64AUps4f7WeKIXCaR9g5NYx7n7Ez/wJoaE17DlqKNUEMnRmwJr1xeT7aESkjcz/kuQ465i+PUbmBUOCSwzP2bKNXdaoRYyBjLMG5nOBk68sdnowhRoGowgXgM8= 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=MhUiDQb/; arc=none smtp.client-ip=113.46.200.226 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="MhUiDQb/" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=i/WRmpKmk9Twp2kERMJ4oyrCR8gGRW2SPU8/Sgnc8BQ=; b=MhUiDQb/aARm4DiKxRNFnTn5wFQCH2q5gZqdllMdBOvolooAiS1eUcgWSsIyq4dhfG5Gb0EFM XxqwkZvW4rHNGYvVdKbrQw9O8+3wVkzZW91LWUjkl8/Y1KZVf1r5ZvsnostRY4Bm/R7FLRz+lYM YKIRo5o6jtQpZd48i9mOUwI= Received: from mail.maildlp.com (unknown [172.19.162.92]) by canpmsgout11.his.huawei.com (SkyGuard) with ESMTPS id 4gDYvN3NsYzKm8x; Mon, 11 May 2026 17:14:24 +0800 (CST) Received: from dggpemf500011.china.huawei.com (unknown [7.185.36.131]) by mail.maildlp.com (Postfix) with ESMTPS id BC6E240562; Mon, 11 May 2026 17:22:02 +0800 (CST) Received: from huawei.com (10.90.53.73) by dggpemf500011.china.huawei.com (7.185.36.131) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Mon, 11 May 2026 17:22:01 +0800 From: Jinjie Ruan To: , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v15 08/11] arm64/ptrace: Define and use _TIF_SYSCALL_EXIT_WORK Date: Mon, 11 May 2026 17:21:00 +0800 Message-ID: <20260511092103.1974980-9-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260511092103.1974980-1-ruanjinjie@huawei.com> References: <20260511092103.1974980-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: kwepems200002.china.huawei.com (7.221.188.68) To dggpemf500011.china.huawei.com (7.185.36.131) Content-Type: text/plain; charset="utf-8" Introduce _TIF_SYSCALL_EXIT_WORK to filter out entry-only flags during the syscall exit path. This aligns arm64 with the generic entry framework's SYSCALL_WORK_EXIT semantics. [Rationale] The current syscall exit path uses _TIF_SYSCALL_WORK to decide whether to invoke syscall_exit_work(). However, _TIF_SYSCALL_WORK includes flags that are only relevant during syscall entry: 1. _TIF_SECCOMP: Seccomp filtering (__secure_computing) only runs on entry. There is no seccomp callback for syscall exit. 2. _TIF_SYSCALL_EMU: In PTRACE_SYSEMU mode, the syscall is intercepted and skipped on entry. Since the syscall is never executed, reporting a syscall exit stop is unnecessary. [Changes] - Define _TIF_SYSCALL_EXIT_WORK: A new mask containing only flags requiring exit processing: _TIF_SYSCALL_TRACE, _TIF_SYSCALL_AUDIT, and _TIF_SYSCALL_TRACEPOINT. - Update exit path: Use _TIF_SYSCALL_EXIT_WORK in syscall_exit_to_user_mode_work() to avoid redundant calls to audit and ptrace reporting when only entry-flags are set. - Cleanup: Remove the has_syscall_work() helper as it is no longer needed. Direct flag comparison is now used to distinguish between entry and exit work requirements. [Impact] audit_syscall_exit() and report_syscall_exit() will no longer be triggered for seccomp-only or emu-only syscalls. This matches the generic entry behavior and improves efficiency by skipping unnecessary exit processing. Cc: Mark Rutland Cc: Will Deacon Cc: Catalin Marinas Reviewed-by: Linus Walleij Reviewed-by: Yeoreum Yun Signed-off-by: Jinjie Ruan --- arch/arm64/include/asm/syscall.h | 7 +------ arch/arm64/include/asm/thread_info.h | 3 +++ arch/arm64/kernel/syscall.c | 2 +- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/arch/arm64/include/asm/syscall.h b/arch/arm64/include/asm/sysc= all.h index b331e09b937f..b982398f8765 100644 --- a/arch/arm64/include/asm/syscall.h +++ b/arch/arm64/include/asm/syscall.h @@ -124,18 +124,13 @@ static inline int syscall_get_arch(struct task_struct= *task) int syscall_trace_enter(struct pt_regs *regs, unsigned long flags); void syscall_exit_work(struct pt_regs *regs, unsigned long flags); =20 -static inline bool has_syscall_work(unsigned long flags) -{ - return unlikely(flags & _TIF_SYSCALL_WORK); -} - static __always_inline void syscall_exit_to_user_mode_work(struct pt_regs = *regs) { unsigned long flags =3D read_thread_flags(); =20 rseq_syscall(regs); =20 - if (has_syscall_work(flags) || flags & _TIF_SINGLESTEP) + if (unlikely(flags & _TIF_SYSCALL_EXIT_WORK) || flags & _TIF_SINGLESTEP) syscall_exit_work(regs, flags); } =20 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/syscall.c b/arch/arm64/kernel/syscall.c index dac7bcc4bbdf..6ac71a0282d5 100644 --- a/arch/arm64/kernel/syscall.c +++ b/arch/arm64/kernel/syscall.c @@ -90,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 --=20 2.34.1 From nobody Thu Jun 11 16:09:34 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 1DAFA3C555B for ; Mon, 11 May 2026 09:22:05 +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=1778491327; cv=none; b=qYGWruuvZt1jWOcxKw9HIBv5MBAXJ45TtRrBCic0hR42zpNxWRnRRZp/eUMa9zdpVNYW6vUu9cZlRpxWlKub+j1ranNXiEp+i06uHw2n+gprKWrZM30aMPcTvmKSDY9G+Sprt9Fe4EceZbn4PQNmcqPyzfi12LcaYJz4GemBIO8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778491327; c=relaxed/simple; bh=Gwi5CEqQY1GSoI/Cr+oXGJiJVUGYVvtrwpoR52ZEd1E=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hVuBUa/ol0uKpJUvBW4BYciqC9d0qGyIq4V7vcQe63EcKRtIbZIF4TB8ynGZ7+4Cb7luiosL9Cwrmoqu4YMIko9FzZPbG9vp+SRZe7FXYSRs7174vgPFcWK/WEUrR+VyAwM6iZgN2UuyG4aKhGKyHNc3c1GQ3p6IyxwAVuOqOHw= 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=OTIJ1WYV; 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="OTIJ1WYV" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=M96zxZPatF26akwGMoN/Jm8ZM7NxqwXO82D+mNsYpao=; b=OTIJ1WYVmd6Z0XQAILnBkVc6Zr4ABLk2OVclSKXl5jT0RoU7VD82j1mw5dK9aHgY/klvOpUVg 4cZlihj5d1obBBFeLSwXo5c6ub4Qeq/lhlYwPI7WeC6MZU8UlDY89Ie1MQAnGiFQcQA7+NvME+Z KzfE1oPA//r2AfpS4bH2a4Q= Received: from mail.maildlp.com (unknown [172.19.163.163]) by canpmsgout10.his.huawei.com (SkyGuard) with ESMTPS id 4gDYvT5139z1K96p; Mon, 11 May 2026 17:14:29 +0800 (CST) Received: from dggpemf500011.china.huawei.com (unknown [7.185.36.131]) by mail.maildlp.com (Postfix) with ESMTPS id 35A824048B; Mon, 11 May 2026 17:22:04 +0800 (CST) Received: from huawei.com (10.90.53.73) by dggpemf500011.china.huawei.com (7.185.36.131) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Mon, 11 May 2026 17:22:02 +0800 From: Jinjie Ruan To: , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v15 09/11] arm64/ptrace: Skip syscall exit reporting for PTRACE_SYSEMU_SINGLESTEP Date: Mon, 11 May 2026 17:21:01 +0800 Message-ID: <20260511092103.1974980-10-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260511092103.1974980-1-ruanjinjie@huawei.com> References: <20260511092103.1974980-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: kwepems200002.china.huawei.com (7.221.188.68) To dggpemf500011.china.huawei.com (7.185.36.131) Content-Type: text/plain; charset="utf-8" Align the syscall exit reporting logic with the generic entry framework by skipping the exit stop when PTRACE_SYSEMU_SINGLESTEP is in effect. [Rationale] When a tracer uses PTRACE_SYSEMU_SINGLESTEP, both _TIF_SYSCALL_EMU and _TIF_SINGLESTEP flags are set. Currently, arm64 reports a syscall exit stop whenever _TIF_SINGLESTEP is set, regardless of the emulation state. However, as per the generic entry implementation (see include/linux/entry-common.h): "If SYSCALL_EMU is set, then the only reason to report is when SINGLESTEP is set (i.e. PTRACE_SYSEMU_SINGLESTEP). This syscall instruction has been already reported in syscall_trace_enter()." Since PTRACE_SYSEMU intercepts and skips the actual syscall execution, reporting a subsequent exit stop is redundant and inconsistent with the expected behavior of emulated system calls. [Changes] - Introduce report_single_step(): Add a helper to encapsulate the logic for deciding whether to report a single-step stop at syscall exit. It returns false if _TIF_SYSCALL_EMU is set, ensuring the emulated syscall does not trigger a duplicate report. - Update syscall_exit_work(): Use the new helper to determine the stepping state instead of directly checking _TIF_SINGLESTEP. [Impact] - PTRACE_SINGLESTEP: Continues to report exit stops for actual instructions. - PTRACE_SYSEMU: Continues to skip exit stops. - PTRACE_SYSEMU_SINGLESTEP: Now correctly skips the redundant exit stop, aligning arm64 with the generic entry infrastructure. Cc: Mark Rutland Cc: Will Deacon Cc: Catalin Marinas Reviewed-by: Linus Walleij Reviewed-by: Yeoreum Yun Signed-off-by: Jinjie Ruan --- arch/arm64/kernel/ptrace.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c index 256aa20377e1..ff8ee474ff31 100644 --- a/arch/arm64/kernel/ptrace.c +++ b/arch/arm64/kernel/ptrace.c @@ -2453,14 +2453,25 @@ int syscall_trace_enter(struct pt_regs *regs, unsig= ned long flags) return syscall; } =20 +static inline bool report_single_step(unsigned long flags) +{ + if (flags & _TIF_SYSCALL_EMU) + return false; + + return flags & _TIF_SINGLESTEP; +} + void syscall_exit_work(struct pt_regs *regs, unsigned long flags) { + bool step; + 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 --=20 2.34.1 From nobody Thu Jun 11 16:09:34 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 5BA2F3C8713 for ; Mon, 11 May 2026 09:22:07 +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=1778491329; cv=none; b=T2Q63Wz3gXnYOWrs7J/XK9hTzfKNwR/1V1FVGMFSBskso7oQg9FYONrSPmr3nh6GNnXATjmGs1Nt75yMNpG4q0em7c/OXQLHXg0ptBPESGC0lQt18YLR8A4yIdMmnJmFTJkqfFjRTnffmfhlOiwSeuSH9YK7g/860A7bPNB64ts= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778491329; c=relaxed/simple; bh=GUBIq+g/ecEaT6yGeTO98WIf2+TTorEBbTkjYpqtYDU=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=KtLQ3DmRAtAReb0gzkmIeY3YqkwWX11wym35IpJXTlhdk92+MzP6fNNFc0dpz7Lv5GoRDyjfKNXnZe0EyRQc/VdFbIxeVISH0HKfcmhA+rwY0lHgunaCsHK7kdfIiBA8i/saeRrIMoC7qfawRtv3sLiQIJ0/TOGN6Ifp9F0GWY0= 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=CkE/Uemg; 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="CkE/Uemg" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=sDAbBK0gDWIHpzVtm1kT10TBleqgRZVICZfHfQaXsiM=; b=CkE/Uemg7Kbmf8wt+dKmX4cMPX+3LwgxyePeigaXXtf6w4P0ttql7h6s1ktZMtzINKBrUL6pg i8Wrs1NJUEF+dOAexkFAVtylKuuisJKFqNg4WoUshP/0voiMeN1o1QjkPqsUsYGbvqXqnBeUMDG EOzXuZV5S2fqgOW9ZECBYiE= Received: from mail.maildlp.com (unknown [172.19.163.0]) by canpmsgout06.his.huawei.com (SkyGuard) with ESMTPS id 4gDYvV171wzRhW0; Mon, 11 May 2026 17:14:30 +0800 (CST) Received: from dggpemf500011.china.huawei.com (unknown [7.185.36.131]) by mail.maildlp.com (Postfix) with ESMTPS id AD2A340537; Mon, 11 May 2026 17:22:05 +0800 (CST) Received: from huawei.com (10.90.53.73) by dggpemf500011.china.huawei.com (7.185.36.131) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Mon, 11 May 2026 17:22:04 +0800 From: Jinjie Ruan To: , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v15 10/11] arm64: entry: Convert to generic entry Date: Mon, 11 May 2026 17:21:02 +0800 Message-ID: <20260511092103.1974980-11-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260511092103.1974980-1-ruanjinjie@huawei.com> References: <20260511092103.1974980-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: kwepems200002.china.huawei.com (7.221.188.68) To dggpemf500011.china.huawei.com (7.185.36.131) 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, and LoongArch, consolidating architecture-specific syscall tracing and auditing into the common kernel entry infrastructure. [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 arch_ptrace_report_syscall_entry() and _exit() by porting the existing arm64 logic to the generic interface. - Add arch_syscall_is_vdso_sigreturn() to asm/syscall.h to support Syscall User Dispatch (SUD). 4. Cleanup and Refactoring: - Remove redundant arm64-specific syscall tracing functions from ptrace.c, including syscall_trace_enter(), syscall_exit_work(), and related audit/step helpers. - 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. Cc: Mark Rutland Cc: Will Deacon Cc: Catalin Marinas Cc: Thomas Gleixner Cc: Peter Zijlstra 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 --- arch/arm64/Kconfig | 2 +- arch/arm64/include/asm/entry-common.h | 76 ++++++++++++++ arch/arm64/include/asm/syscall.h | 21 ++-- arch/arm64/include/asm/thread_info.h | 19 +--- arch/arm64/kernel/debug-monitors.c | 7 ++ arch/arm64/kernel/ptrace.c | 143 -------------------------- arch/arm64/kernel/signal.c | 2 +- arch/arm64/kernel/syscall.c | 7 +- 8 files changed, 103 insertions(+), 174 deletions(-) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index fe60738e5943..dd5bb1d4b161 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -128,9 +128,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 cab8cd78f693..d8bf4bf342e8 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,73 @@ 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 int arch_ptrace_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_entry(regs); + if (ret) + forget_syscall(regs); + regs->regs[regno] =3D saved_reg; + + return ret; +} + +#define arch_ptrace_report_syscall_entry arch_ptrace_report_syscall_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 b982398f8765..f9fbb33600d8 100644 --- a/arch/arm64/include/asm/syscall.h +++ b/arch/arm64/include/asm/syscall.h @@ -10,6 +10,9 @@ #include #include =20 +#include +#include + typedef long (*syscall_fn_t)(const struct pt_regs *regs); =20 extern const syscall_fn_t sys_call_table[]; @@ -121,17 +124,19 @@ static inline int syscall_get_arch(struct task_struct= *task) return AUDIT_ARCH_AARCH64; } =20 -int syscall_trace_enter(struct pt_regs *regs, unsigned long flags); -void syscall_exit_work(struct pt_regs *regs, unsigned long flags); - -static __always_inline void syscall_exit_to_user_mode_work(struct pt_regs = *regs) +static inline bool arch_syscall_is_vdso_sigreturn(struct pt_regs *regs) { - unsigned long flags =3D read_thread_flags(); + unsigned long sigtramp; =20 - rseq_syscall(regs); +#ifdef CONFIG_COMPAT + if (is_compat_task()) { + unsigned long sigpage =3D (unsigned long)current->mm->context.sigpage; =20 - if (unlikely(flags & _TIF_SYSCALL_EXIT_WORK) || flags & _TIF_SINGLESTEP) - syscall_exit_work(regs, flags); + return regs->pc >=3D sigpage && regs->pc < (sigpage + PAGE_SIZE); + } +#endif + sigtramp =3D (unsigned long)VDSO_SYMBOL(current->mm->context.vdso, sigtra= mp); + return regs->pc =3D=3D (sigtramp + 8); } =20 #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 29307642f4c9..e67643a70405 100644 --- a/arch/arm64/kernel/debug-monitors.c +++ b/arch/arm64/kernel/debug-monitors.c @@ -385,11 +385,18 @@ 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 a trap is triggered once stepping out of a system + * call prior to executing any user instruction. + */ + 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/ptrace.c b/arch/arm64/kernel/ptrace.c index ff8ee474ff31..9acc314bc376 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; @@ -2338,143 +2332,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_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); - } -} - -static inline void syscall_enter_audit(struct pt_regs *regs, long syscall) -{ - if (unlikely(audit_context())) { - unsigned long args[6]; - - syscall_get_arguments(current, regs, args); - audit_syscall_entry(syscall, args[0], args[1], args[2], args[3]); - } -} - -int syscall_trace_enter(struct pt_regs *regs, unsigned long flags) -{ - long syscall; - int ret; - - if (flags & (_TIF_SYSCALL_EMU | _TIF_SYSCALL_TRACE)) { - ret =3D report_syscall_entry(regs); - if (ret || (flags & _TIF_SYSCALL_EMU)) - return NO_SYSCALL; - } - - /* Do the secure computing after ptrace; failures should be fast. */ - if (flags & _TIF_SECCOMP) { - ret =3D __secure_computing(); - if (ret =3D=3D -1) - return NO_SYSCALL; - } - - /* Either of the above might have changed the syscall number */ - syscall =3D syscall_get_nr(current, regs); - - if (test_thread_flag(TIF_SYSCALL_TRACEPOINT)) { - trace_sys_enter(regs, syscall); - - /* - * Probes or BPF hooks in the tracepoint may have changed the - * system call number as well. - */ - syscall =3D syscall_get_nr(current, regs); - } - - syscall_enter_audit(regs, syscall); - - return syscall; -} - -static inline bool report_single_step(unsigned long flags) -{ - if (flags & _TIF_SYSCALL_EMU) - return false; - - return flags & _TIF_SINGLESTEP; -} - -void 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 08ffc5a5aea4..7ca30ee41e7a 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 6ac71a0282d5..f83673e38901 100644 --- a/arch/arm64/kernel/syscall.c +++ b/arch/arm64/kernel/syscall.c @@ -2,6 +2,7 @@ =20 #include #include +#include #include #include #include @@ -57,6 +58,7 @@ static void invoke_syscall(struct pt_regs *regs, unsigned= int scno, static void el0_svc_common(struct pt_regs *regs, int scno, int sc_nr, const syscall_fn_t syscall_table[]) { + unsigned long work =3D READ_ONCE(current_thread_info()->syscall_work); unsigned long flags =3D read_thread_flags(); =20 regs->orig_x0 =3D regs->regs[0]; @@ -90,7 +92,7 @@ static void el0_svc_common(struct pt_regs *regs, int scno= , int sc_nr, return; } =20 - if (unlikely(flags & _TIF_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,8 +110,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); - flags =3D read_thread_flags(); - scno =3D syscall_trace_enter(regs, flags); + scno =3D syscall_trace_enter(regs, work); if (scno =3D=3D NO_SYSCALL) goto trace_exit; } --=20 2.34.1 From nobody Thu Jun 11 16:09:34 2026 Received: from canpmsgout07.his.huawei.com (canpmsgout07.his.huawei.com [113.46.200.222]) (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 51B753CA4A3 for ; Mon, 11 May 2026 09:22:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.222 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778491331; cv=none; b=ts8AzFxbf3ERPHg7KlyI/ZLcFwdcrSOH2xIfPeHpqDFUIrB8zjx+8vFZ95WybGA2Uy2QsCRm5Fq+kpBupDSTzqQmLlTEFRYSXgnt5CDPj4exEWvLSvKW0NOnMJ5NIfYp/nwP0DL8aD2VCRYb5aLd0tGpysqoZIGDnQfiWgXS5sM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778491331; c=relaxed/simple; bh=cFwdYAscBlrwhKWo1VJ9yqx2HcaKYr2TiktnlvFMe8A=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MH8xG0faodUqft1R5r6cF7LedWpaELBl4bVNpav/iJxKIRK+mzDy0aUu5p/d7DnJwRjy4xOUgzGDFELZhEtBqJUflvcTdCTtiq+eGelknGwqqME+N4nbwr44nW+XPj06mqbQM73armETa67lZRLRvI2HfJJkCBuTBsrnPnmxDI4= 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=l+XPfAnK; arc=none smtp.client-ip=113.46.200.222 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="l+XPfAnK" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=v3G53X7g6bOP0NpyI5i+7EzCeYKLsZM3lQPwaHyXLHE=; b=l+XPfAnKKUD989KzwVPluz7Nx0WBno86jubP79mbZt2rt7nZSzHZm2eMUXiOjya0k8WNiLwmW dz+faaCpW8CxYVd8CjVLvG1zOZlotxaueQE1mkiA6roAAsRmGeqQOZ6E3Yu67HfxuJXCYkt5PSj UNEsJOaqYHk40lL0qmFmLxk= Received: from mail.maildlp.com (unknown [172.19.163.127]) by canpmsgout07.his.huawei.com (SkyGuard) with ESMTPS id 4gDYvW4ks0zLlSL; Mon, 11 May 2026 17:14:31 +0800 (CST) Received: from dggpemf500011.china.huawei.com (unknown [7.185.36.131]) by mail.maildlp.com (Postfix) with ESMTPS id 15FF2402AB; Mon, 11 May 2026 17:22:07 +0800 (CST) Received: from huawei.com (10.90.53.73) by dggpemf500011.china.huawei.com (7.185.36.131) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Mon, 11 May 2026 17:22:05 +0800 From: Jinjie Ruan To: , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v15 11/11] arm64: Inline el0_svc_common() Date: Mon, 11 May 2026 17:21:03 +0800 Message-ID: <20260511092103.1974980-12-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260511092103.1974980-1-ruanjinjie@huawei.com> References: <20260511092103.1974980-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: kwepems200002.china.huawei.com (7.221.188.68) To dggpemf500011.china.huawei.com (7.185.36.131) 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 Reviewed-by: Linus Walleij Reviewed-by: Yeoreum Yun Reviewed-by: Kevin Brodsky Signed-off-by: Jinjie Ruan --- 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 f83673e38901..a686b48b245d 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 work =3D READ_ONCE(current_thread_info()->syscall_work); unsigned long flags =3D read_thread_flags(); --=20 2.34.1