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 lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (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 43C6EC43458 for ; Mon, 29 Jun 2026 13:08:07 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4gpmlh485lz2yfS; Mon, 29 Jun 2026 23:07:28 +1000 (AEST) Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip=113.46.200.221 ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1782738448; cv=none; b=PXNvLe3tmLgEHtl4KWDS3rQlikRxPHlbZ0zTpv6qkZ/Bpcb+Ku/IJLXMU/aD7YedIxkVPKgcf0Y8yI+84rHXondoADGVv8C+KCxcErmOLFLVuD6U2KCxZmnb9khcR5sPt67IssIvkWrgb0QP1c7CsgIKHjwm97KtRv7FmPtnxy+mzy/KSTPCBel2LN4JKVbZgthaZmYvW0fyNCB6MtZ70iCqgV8K56vxcE+u/CHFSe0Je4zChMaCkpsTb0iZ46g6LEQlDLK3HZ6rC9c/mW+nzgWpGE8i3FHIz53f7B1S/6ADnN0kvrDamOfRvRhJeBfIX6QdMY6oETqKJBetgkA1OQ== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1782738448; c=relaxed/relaxed; bh=qBDPSugJUvIfnZFt1AXtvZwTdTLodNQ1FcaAm4R/gOE=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=FleTjWNXTYNcwxtcG+29uGQ4odLPSkhwKL1ai7v3eVjZKqAkVnLo4Xo1wBsLBQOjV0dI99KiT5jsfNTcKczwRMAnQT86d5YbiZ2zbBmnB4oMokz8Dd0p7z2GfP0ul+TwxLzDReV4pVWVWE6rE0JcfcM0wIb0ROtHKmxKqz1CsRlsgiFSYQ0SYE/n2Op0aQ5JSwuBgEAaqzsI6ckKHJ423ngSlmxeCJXxk3DlHvJF5etSgzE8wUh8DD76KPg6Dt6ubIZV4l2YbmsqwkhFuuLi84ob1BsnWbHZKbAXPZoSITgX58S2AqX0cFlEhKwcG4kfGQuNsaNkCQxdpJhECyqrHQ== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; dkim=pass (1024-bit key; unprotected) header.d=huawei.com header.i=@huawei.com header.a=rsa-sha256 header.s=dkim header.b=a269f39o; dkim-atps=neutral; spf=pass (client-ip=113.46.200.221; helo=canpmsgout06.his.huawei.com; envelope-from=ruanjinjie@huawei.com; receiver=lists.ozlabs.org) smtp.mailfrom=huawei.com Authentication-Results: lists.ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=huawei.com header.i=@huawei.com header.a=rsa-sha256 header.s=dkim header.b=a269f39o; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=huawei.com (client-ip=113.46.200.221; helo=canpmsgout06.his.huawei.com; envelope-from=ruanjinjie@huawei.com; receiver=lists.ozlabs.org) Received: from canpmsgout06.his.huawei.com (canpmsgout06.his.huawei.com [113.46.200.221]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4gpmlg2nFhz2ydn for ; Mon, 29 Jun 2026 23:07:27 +1000 (AEST) dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=qBDPSugJUvIfnZFt1AXtvZwTdTLodNQ1FcaAm4R/gOE=; b=a269f39ox2X1MkTEyXI82z8wRlh2JJbv7SBilR9vhgvdV6uTWvBdihcfse78JQYIlqynYIW5F E2XShrMwv0B62uSV2EBMVz/eH8zWz7eWC0+h8ubQLYc/rHkR7n0f5d0u1u+DXWnEfvHEbSxO0ei r7hDy9OeAn/yHuDDWTkavPM= Received: from mail.maildlp.com (unknown [172.19.162.197]) by canpmsgout06.his.huawei.com (SkyGuard) with ESMTPS id 4gpmY51TlgzRhRT; Mon, 29 Jun 2026 20:58:17 +0800 (CST) Received: from dggpemf500011.china.huawei.com (unknown [7.185.36.131]) by mail.maildlp.com (Postfix) with ESMTPS id 6B76140579; Mon, 29 Jun 2026 21:07:24 +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, 29 Jun 2026 21:07:20 +0800 From: Jinjie Ruan To: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v16 11/18] arm64: ptrace: Align syscall exit work semantics with generic entry Date: Mon, 29 Jun 2026 21:06:09 +0800 Message-ID: <20260629130616.642022-12-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260629130616.642022-1-ruanjinjie@huawei.com> References: <20260629130616.642022-1-ruanjinjie@huawei.com> X-Mailing-List: linuxppc-dev@lists.ozlabs.org List-Id: List-Help: List-Owner: List-Post: List-Archive: , List-Subscribe: , , List-Unsubscribe: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.90.53.73] X-ClientProxiedBy: kwepems500001.china.huawei.com (7.221.188.70) To dggpemf500011.china.huawei.com (7.185.36.131) Streamline syscall_exit_to_user_mode_work() to align arm64's syscall exit behavior with the generic entry framework. [Rationale] 1. Unconditional RSEQ Execution: Relocate rseq_syscall() from the slow-path helper to the very beginning of syscall_exit_to_user_mode_work(). This ensures that RSEQ validation executes unconditionally across all exit scenarios, preventing it from being incorrectly bypassed on fast paths when CONFIG_DEBUG_RSEQ is active. 2. Centralized Exit Work Gating: Introduce the `_TIF_SYSCALL_EXIT_WORK` mask to aggregate exit thread flags and gate the execution of syscall_exit_work(). Gating audit_syscall_exit() behind this exit-time check introduces no functional changes. The `SYSCALL_AUDIT` flag and its context are statically allocated via audit_alloc() at fork time and only freed via audit_free() at do_exit(). Since the flag remains persistent and static throughout syscall execution, checking `_TIF_SYSCALL_AUDIT` in the mask is fully equivalent to evaluating audit_context() inside audit_syscall_exit(). [Changes] - Introduce the `_TIF_SYSCALL_EXIT_WORK` mask to bundle exit-specific flags. - Relocate rseq_syscall() to run unconditionally on the outermost layer. - Gate syscall_exit_work() via the new aggregated flag check to mirror the generic entry loop behavior. No functional changes intended. Cc: Mark Rutland Cc: Will Deacon Cc: Catalin Marinas Cc: Ada Couprie Diaz Signed-off-by: Jinjie Ruan --- arch/arm64/include/asm/syscall.h | 6 +++++- arch/arm64/include/asm/thread_info.h | 3 +++ arch/arm64/kernel/ptrace.c | 3 --- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/arch/arm64/include/asm/syscall.h b/arch/arm64/include/asm/syscall.h index 72461c22bb5e..b982398f8765 100644 --- a/arch/arm64/include/asm/syscall.h +++ b/arch/arm64/include/asm/syscall.h @@ -8,6 +8,7 @@ #include #include #include +#include typedef long (*syscall_fn_t)(const struct pt_regs *regs); @@ -127,7 +128,10 @@ static __always_inline void syscall_exit_to_user_mode_work(struct pt_regs *regs) { unsigned long flags = read_thread_flags(); - syscall_exit_work(regs, flags); + rseq_syscall(regs); + + if (unlikely(flags & _TIF_SYSCALL_EXIT_WORK) || flags & _TIF_SINGLESTEP) + 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 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) +#define _TIF_SYSCALL_EXIT_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \ + _TIF_SYSCALL_TRACEPOINT) + #ifdef CONFIG_SHADOW_CALL_STACK #define INIT_SCS \ .scs_base = init_shadow_call_stack, \ diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c index 9ebe3389451c..05ceb9f2d038 100644 --- a/arch/arm64/kernel/ptrace.c +++ b/arch/arm64/kernel/ptrace.c @@ -28,7 +28,6 @@ #include #include #include -#include #include #include @@ -2455,8 +2454,6 @@ int syscall_trace_enter(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); if (flags & _TIF_SYSCALL_TRACEPOINT) -- 2.34.1