From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 17C60108B8F0 for ; Fri, 20 Mar 2026 10:25:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date :Subject:To:From:Reply-To:Cc:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=LEfH1l17IwnqI0yEb/YqvlzcfHZXhejlA8hj/07tKIY=; b=uKqPYMFpc156Mq6Tm7NJvmeqsA Njp0230pbMkR2p9A7Q7Hbp0nol+7031zw/VLiqZE7+x8vtPO7HyB5r179SbsBjvPhiAhePwK8I+rt XPluEfzyWy2lUMVbU/ecDgbsrtuHJOH1+G5NtBH5DwQnol0i6e2cAGU4Ab2+/7wOfbdJ11dTZ+Cg2 Kwqn1ilVivCEzKtqiFG5Gb15dd7pwVarfsuyApDn0WIZXOBU+oku3naJ1PQY0OzFinlA+F6+2FBMo Tcq6ufrsMxRaDrN3as/ZEWmJbnN+YeKnpbXFg+noL+8YjFgLhi8BTDec55ZESm7Ua6WdH1x3NIt4l 5XYy0TaA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1w3X3B-0000000CaPS-3ZsL; Fri, 20 Mar 2026 10:25:53 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1w3X2v-0000000CaHR-31vc for linux-arm-kernel@bombadil.infradead.org; Fri, 20 Mar 2026 10:25:37 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:Content-Transfer-Encoding :MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:To:From:Sender: Reply-To:Cc:Content-ID:Content-Description; bh=LEfH1l17IwnqI0yEb/YqvlzcfHZXhejlA8hj/07tKIY=; b=Ydh4S6Og1mS2puVtUZGL6/24Ne PFHRQGhCNAApDzAhcEReEp8UJ1fMQCtM2BVetVyHH7UjgZ1HQxnfC9OiU58fHklcBwN3KSOwCW99Y niXgg6WJmXgn8cXcbdSDhKYLPcYVJBJPD+CIq0Oq8OKjQXQ8V4D66DE/OZkzL7NduSFgqMXwJtaBo bXnL7M5rqBPI0e3ks/UZ2K9WTQMMAHzrZCsqzmk3thjXIb4ZpX2SKMnTIcgoWK11ZO/O1Udg9M7bM pNTXUg/YhFwaU5RAJnBT0MbuYZhYm5VQLYF91q1OiBKk2H5wYOdS1D/e1gX2bmCjoAUCvfRXTLvqD cO42ji0w==; Received: from canpmsgout08.his.huawei.com ([113.46.200.223]) by desiato.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1w3X2r-0000000FJm9-3Mmv for linux-arm-kernel@lists.infradead.org; Fri, 20 Mar 2026 10:25:36 +0000 dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=LEfH1l17IwnqI0yEb/YqvlzcfHZXhejlA8hj/07tKIY=; b=jqkJ9HaOGiciQ1MIlduph6HJDKepEEZGGvXfvHQldBhMz4E6hBjVXJyGZdEmcvM7zgJ2jC0Xb Xbdgv1cEmiqo1dqO/WdrLu1N28q31l/1/u+TS4MibYM7B3j2e/30jxXEt74/KcFcJbhFka6vnwC JRcgyi+4h4ib7EDgPOMtUaE= Received: from mail.maildlp.com (unknown [172.19.163.214]) by canpmsgout08.his.huawei.com (SkyGuard) with ESMTPS id 4fcdqc6cy0zmV7M; Fri, 20 Mar 2026 18:20:28 +0800 (CST) Received: from dggpemf500011.china.huawei.com (unknown [7.185.36.131]) by mail.maildlp.com (Postfix) with ESMTPS id ADE9E40561; Fri, 20 Mar 2026 18:25:30 +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; Fri, 20 Mar 2026 18:25:29 +0800 From: Jinjie Ruan To: , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v14 08/10] arm64/ptrace: Skip syscall exit reporting for PTRACE_SYSEMU_SINGLESTEP Date: Fri, 20 Mar 2026 18:26:18 +0800 Message-ID: <20260320102620.1336796-9-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260320102620.1336796-1-ruanjinjie@huawei.com> References: <20260320102620.1336796-1-ruanjinjie@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.90.53.73] X-ClientProxiedBy: kwepems100002.china.huawei.com (7.221.188.206) To dggpemf500011.china.huawei.com (7.185.36.131) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260320_102534_435895_B8977459 X-CRM114-Status: GOOD ( 11.92 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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: 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 c494fec68e35..e3b74add88e7 100644 --- a/arch/arm64/kernel/ptrace.c +++ b/arch/arm64/kernel/ptrace.c @@ -2454,14 +2454,25 @@ int syscall_trace_enter(struct pt_regs *regs, unsigned long flags) return ret ? : syscall; } +static inline bool report_single_step(unsigned long flags) +{ + if (flags & _TIF_SYSCALL_EMU) + return false; + + return flags & _TIF_SINGLESTEP; +} + static 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)); - if (flags & (_TIF_SYSCALL_TRACE | _TIF_SINGLESTEP)) + step = report_single_step(flags); + if (step || flags & _TIF_SYSCALL_TRACE) report_syscall_exit(regs); } -- 2.34.1