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 EBB43CD4841 for ; Mon, 11 May 2026 09:22:31 +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=M96zxZPatF26akwGMoN/Jm8ZM7NxqwXO82D+mNsYpao=; b=VlsWB+YVhEWriygIDiWVKVq1Av eNunCsm4ewST7d427Q1gU4+oBmWFlm5y0ea7NUwZ5KFL02wB5HdzOI2KQPGF68C3aV/VljJRRqAJ/ LmPDziX6SLVe18uYH4qSLJ8qkXKKYhwTwSOrBX1QJ6HVmfvATe+fYQO6qmh89+wg3SwsUgVv6nlHs ZjIu5hN3JeGGuCKsqZn7zcgd00459JQQ6BuZ4zlK+3j0+ongi4tlt/BfVB8uTCU7Nmr16r/9YMWo2 +j9IilVafKe8/ZE9zabdeesZayCenpVDQzhzDVNa8YsS4XPAzoYi1Xcje5F5WHO88la6jeX8U3ptt isA/Lt0Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wMMqD-0000000CtBX-1Kno; Mon, 11 May 2026 09:22:22 +0000 Received: from canpmsgout10.his.huawei.com ([113.46.200.225]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wMMq0-0000000CswV-10Ko for linux-arm-kernel@lists.infradead.org; Mon, 11 May 2026 09:22:12 +0000 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> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.90.53.73] X-ClientProxiedBy: kwepems200002.china.huawei.com (7.221.188.68) To dggpemf500011.china.huawei.com (7.185.36.131) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260511_022208_610987_BF1F0D2F X-CRM114-Status: GOOD ( 12.29 ) 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: 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, unsigned long flags) 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)); - 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