From patchwork Tue Jan 7 09:41:27 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13928594 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 276DAE77197 for ; Tue, 7 Jan 2025 09:56:11 +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:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=obIcK06NDnAV5qCp4HaVvaBhtHVYu9G8V01JmlqBhdo=; b=mz8qeLVVwAqvnycUXEBYrjjpw3 TKe/K/hAEdYPET3I6J0Bix+OFyDKjzDlPQBLR1X8TSmUzjLAgCrlH/bvqVCciUMIV4f8WMqd9SEjU 4EtC9nriS53HVDlgoHDTfsTCQ/lj3XCfugzerOMtzTrLLWqctobEC+u4r4tvESPC58fJ0b7oYNgEG kzA3JfkOles8BqaZ64CHgs1NA7u4hGCWy4ng6Srbct7nsH1polcSk7iLxAfBceKF/J4ljj9mUQy02 4WxpNZk7eY/+SC3kkoIo0tLZOW8e9J0IRllJz0Jlq2xC4LmjWFCn69W9puehPERQAVqUNwflyYbCZ oxgqrIfw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tV6JX-00000004EHp-2xbi; Tue, 07 Jan 2025 09:55:55 +0000 Received: from mail-ej1-x633.google.com ([2a00:1450:4864:20::633]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tV65m-00000004APy-1iCH for linux-arm-kernel@lists.infradead.org; Tue, 07 Jan 2025 09:41:46 +0000 Received: by mail-ej1-x633.google.com with SMTP id a640c23a62f3a-aa67ac42819so2212120966b.0 for ; Tue, 07 Jan 2025 01:41:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1736242901; x=1736847701; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=obIcK06NDnAV5qCp4HaVvaBhtHVYu9G8V01JmlqBhdo=; b=BWla7339edEFAImFESrBJ+7jY17fVmN8cx5rVLi8n+E0h8XuqSLXKEZmYIU2Rdlng5 zGhTYxxpT+wFfB95KTaDGvwwwmWIVehMl5a4NC0WdwKM2rVswFEHfy2gP7nJTE4/cbGu zlIpQi0QiG9WmRk2KuNWMaI+kSzFMQd6yAjyI7VE2ee5+4tCxJV4F6r5NmgKn0VuI4KX Ogdxl+tdSvZXBFuOwxemgc+aAAYj+y3J6XcO4ydNlQv8G1BsqEwLLSUtI9f+aR547P2+ B6IYTY6+ChEo5+Wyr4CqOdq/97gJOGr6rdUGfON0AJPWEgeGNov7jY5/fgTd/CmR1dDX rShA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736242901; x=1736847701; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=obIcK06NDnAV5qCp4HaVvaBhtHVYu9G8V01JmlqBhdo=; b=T5o9wNqeKUDn8FKwR7/tgh9es5eV9iK75vf+xaHmxZlH3OqZBRKMWZZ6DOmTh2DluP IwH+y9idKhQJEX3CW5e6dcUXG/rT122zP2yyZ6++9pik1DVKWPeuNiYQskYYfnTF5Tjp 1YUwndRi1CsZIIpdh1Kq3jhYToQhWr2pRS58A83PEwNUH6GhF99hgpVeSKrR8rJvjU8a 7eO/BGm4t0wvqzjU8K4JoiS7uL5sptJo7YxHJ7GK9FUHzcBHjAQy0c8LPRszw3kd0WZp XeAim7WEfFoKY2us7eTd7qh5FRvyEgLRUEkH1d0q1L8W9H0BZ6HMXoKbgp6DKkwZNBVn sLmg== X-Gm-Message-State: AOJu0YxjKbRWxjSIQumYJOIjzqJO9xe0CYptfepQdKj2tOFpKbExp8xg QJPyW5nROyCwJdRDDCRZvdQNZ4/gGeL8qE52GS9n+90WpzE809LZ4QMA/7ZMvtA= X-Gm-Gg: ASbGncvw9emlk7QckuOZpCESw7w4uyzxw1DTk/xkSBBX6Mxrz0De1rl1vgrx409hqN1 iG2MllBQ8n1sKf29FGFPsl/2xoRoLDeEIERGhKy34y7y6ofvWfcHZAZbhUtIfptSprIac6Z9nE9 qhr98klFc5ZWHHSSljIXLcBprmyQv1purfa74wxNUuQQuhK6pJPWVUQv+krV8H5vwZhYTI0C+fK afFiw23deTwgeLY/29RMMZTvQv+4BV1fgvu4fzxffpadzAqhIovg2SnN2rN7h+TXz0= X-Google-Smtp-Source: AGHT+IEZWsPMIYjNv7jxdVj3hAXsMC1BoKsd7O3ruCr9H4/wtm3VV0KAm67GFUnre39yZsgN9rJvNA== X-Received: by 2002:a17:907:944d:b0:aa6:84d4:8021 with SMTP id a640c23a62f3a-aac34a07e84mr5339810166b.61.1736242900971; Tue, 07 Jan 2025 01:41:40 -0800 (PST) Received: from [192.168.1.140] ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aac0f012229sm2356901166b.133.2025.01.07.01.41.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jan 2025 01:41:40 -0800 (PST) From: Linus Walleij Date: Tue, 07 Jan 2025 10:41:27 +0100 Subject: [PATCH RFC v3 11/30] ARM: entry: Merge the common and trace entry code MIME-Version: 1.0 Message-Id: <20250107-arm-generic-entry-v3-11-4e5f3c15db2d@linaro.org> References: <20250107-arm-generic-entry-v3-0-4e5f3c15db2d@linaro.org> In-Reply-To: <20250107-arm-generic-entry-v3-0-4e5f3c15db2d@linaro.org> To: Dmitry Vyukov , Oleg Nesterov , Russell King , Kees Cook , Andy Lutomirski , Will Drewry , Frederic Weisbecker , "Paul E. McKenney" , Jinjie Ruan , Arnd Bergmann , Ard Biesheuvel , Al Viro Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Linus Walleij X-Mailer: b4 0.14.2 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250107_014142_451547_55547B80 X-CRM114-Status: GOOD ( 24.25 ) 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 The trace entry code now can handle recursive and complex calls in C using stack. Move the common code over to using that approach. We now use the ret_fast_syscall return path also when tracing, which appears to work just fine. Signed-off-by: Linus Walleij --- arch/arm/include/asm/syscall.h | 3 +-- arch/arm/kernel/entry-common.S | 61 +++++++++--------------------------------- arch/arm/kernel/syscall.c | 35 +++++++++++------------- 3 files changed, 28 insertions(+), 71 deletions(-) diff --git a/arch/arm/include/asm/syscall.h b/arch/arm/include/asm/syscall.h index cb0073c4151bf70a82d15e17a95b6b6f48b245d6..9c664d8c5718f58034f442c20a030b59faf65dd9 100644 --- a/arch/arm/include/asm/syscall.h +++ b/arch/arm/include/asm/syscall.h @@ -19,8 +19,7 @@ extern const unsigned long sys_call_table[]; -int invoke_syscall(void *table, struct pt_regs *regs, int scno, void *retp); -void invoke_syscall_trace(void *table, struct pt_regs *regs); +int invoke_syscall_trace(void *table, struct pt_regs *regs, int scno); static inline int syscall_get_nr(struct task_struct *task, struct pt_regs *regs) diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S index dbc947d301ec11bb13007cb4bb161c035ede5c10..f0f1f8723965313b287158fb2a238908db72fcd2 100644 --- a/arch/arm/kernel/entry-common.S +++ b/arch/arm/kernel/entry-common.S @@ -39,7 +39,6 @@ saved_pc .req lr * from those features make this path too inefficient. */ ret_fast_syscall: -__ret_fast_syscall: UNWIND(.fnstart ) UNWIND(.cantunwind ) disable_irq_notrace @ disable interrupts @@ -47,13 +46,13 @@ __ret_fast_syscall: movs r1, r1, lsl #16 bne fast_work_pending - restore_user_regs fast = 1, offset = S_OFF + restore_user_regs fast = 0, offset = S_OFF UNWIND(.fnend ) ENDPROC(ret_fast_syscall) /* Ok, we need to do extra processing, enter the slow path. */ fast_work_pending: - str r0, [sp, #S_R0+S_OFF]! @ returned r0 + add sp, sp, #(S_R0 + S_OFF) /* fall through to work_pending */ #else /* @@ -63,10 +62,9 @@ fast_work_pending: * call. */ ret_fast_syscall: -__ret_fast_syscall: UNWIND(.fnstart ) UNWIND(.cantunwind ) - str r0, [sp, #S_R0 + S_OFF]! @ save returned r0 + add sp, sp, #(S_R0 + S_OFF) #if IS_ENABLED(CONFIG_DEBUG_RSEQ) /* do_rseq_syscall needs interrupts enabled. */ mov r0, sp @ 'regs' @@ -83,7 +81,9 @@ ENDPROC(ret_fast_syscall) #endif tst r1, #_TIF_SYSCALL_WORK - bne __sys_trace_return_nosave + beq slow_work_pending + b ret_to_user + slow_work_pending: mov r0, sp @ 'regs' bl do_work_pending @@ -257,19 +257,15 @@ ENTRY(vector_swi) str scno, [tsk, #TI_ABI_SYSCALL] #endif mov r1, sp @ put regs into r1 - ldr r10, [tsk, #TI_FLAGS] @ check for syscall tracing stmdb sp!, {r4, r5} @ push fifth and sixth args - - tst r10, #_TIF_SYSCALL_WORK @ are we tracing syscalls? - bne __sys_trace - mov r0, tbl - /* r1 already contains regs */ mov r2, scno @ syscall number from r7 - /* We return here no matter what, also pass this as an argument */ - badr lr, __ret_fast_syscall - mov r3, lr - b invoke_syscall + bl invoke_syscall_trace + cmp r0, #0 + beq ret_fast_syscall + /* This path taken when tracing */ + add sp, sp, #(S_R0 + S_OFF) + b ret_to_user #if defined(CONFIG_OABI_COMPAT) || !defined(CONFIG_AEABI) /* @@ -289,20 +285,6 @@ ENTRY(vector_swi) ENDPROC(vector_swi) .ltorg - /* - * This is the really slow path. We're going to be doing - * context switches, and waiting for our parent to respond. - */ -__sys_trace: - add r1, sp, #S_R0 + S_OFF @ pointer to regs - mov r0, tbl - bl invoke_syscall_trace - add sp, sp, #S_OFF @ restore stack pointer - b ret_to_user - -__sys_trace_return_nosave: - b ret_to_user - .macro syscall_table_start, sym .equ __sys_nr, 0 .type \sym, #object @@ -402,25 +384,6 @@ sys_mmap2: b sys_mmap_pgoff ENDPROC(sys_mmap2) -/* - * This call wants: - * r0: syscall table - * r1: regs - * r2: syscall number - * r3: pointer to return function - */ -SYM_TYPED_FUNC_START(invoke_syscall_asm) -#ifdef CONFIG_CPU_SPECTRE - csdb -#endif - mov tbl, r0 - mov scno, r2 - mov lr, r3 @ return address - ldmia r1, {r0 - r3} @ reload r0-r3 - /* Arguments 5 and 6 are (hopefully) on the stack */ - ldr pc, [tbl, scno, lsl #2] @ call sys_* routine -SYM_FUNC_END(invoke_syscall_asm) - /* * This call wants: * r0: syscall table diff --git a/arch/arm/kernel/syscall.c b/arch/arm/kernel/syscall.c index e90f04f35b3485968a1e9046cf0889f56cca92e5..36330023b5484399a4ca2fdb5727b410e2c74b6f 100644 --- a/arch/arm/kernel/syscall.c +++ b/arch/arm/kernel/syscall.c @@ -3,50 +3,45 @@ #include #include -int invoke_syscall_asm(void *table, struct pt_regs *regs, int scno, void *retp); -__ADDRESSABLE(invoke_syscall_asm); - -__visible int invoke_syscall(void *table, struct pt_regs *regs, int scno, void *retp) +static inline bool has_syscall_work(unsigned long flags) { - if (scno < NR_syscalls) - /* Doing this with return makes sure the stack gets pop:ed */ - return invoke_syscall_asm(table, regs, scno, retp); - - if (scno >= __ARM_NR_BASE) - return arm_syscall(scno, regs); - - return sys_ni_syscall(); + return unlikely(flags & _TIF_SYSCALL_WORK); } int invoke_syscall_trace_asm(void *table, struct pt_regs *regs, int scno); __ADDRESSABLE(invoke_syscall_trace_asm); -__visible void invoke_syscall_trace(void *table, struct pt_regs *regs) +__visible int invoke_syscall_trace(void *table, struct pt_regs *regs, int scno) { - int scno; + unsigned long flags = read_thread_flags(); int ret; - scno = syscall_trace_enter(regs); - if (scno == -1) - goto trace_exit_nosave; + if (has_syscall_work(flags)) { + scno = syscall_trace_enter(regs); + if (scno == -1) + goto trace_exit_nosave; + } if (scno < NR_syscalls) { ret = invoke_syscall_trace_asm(table, regs, scno); - goto trace_exit_save; + goto exit_save; } if (scno >= __ARM_NR_BASE) { ret = arm_syscall(scno, regs); - goto trace_exit_save; + goto exit_save; } ret = sys_ni_syscall(); -trace_exit_save: +exit_save: /* Save return value from syscall */ regs->ARM_r0 = ret; + if (!has_syscall_work(flags)) + return 0; trace_exit_nosave: local_irq_enable(); syscall_trace_exit(regs); + return 1; }