From patchwork Thu Oct 10 11:33:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13830011 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 4651ECF11D0 for ; Thu, 10 Oct 2024 12:01:45 +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=hNYBR6ZSh2a4w1mSh6FqJlsw/BqZTd6AKV7VHjOwsQw=; b=jAJSRwFCT1TnzTwXmPKPnKmKj+ DkjQnfqPH24puVyY6oRHDsfDlPijKNe0w4f2BQtT1mQvWpMfS5IFGKSvmkYR6RoZ4lPeFYSKkjCdN YeiVjH/vUdfXG0a1/6EtWkmOf179jlFikbOzuiZJhKV/Gcp+uFm0i8Q1Us0Ix69QoRX57qIZryw/v RuicSfFfwozSOttRSIiEs3paFfAA82xhnYWnxuD2bc0dG1BSgBDSwKlK/XFrNzkCtbJO2XLijFoQf KDOZtSe8cs89So42rTVng9KhyhqREpu5bw8FKVukBP2wxzX6Cww+xusu24jgpIx0k/lhJS3XedRSJ UF+31Obg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1syrrJ-0000000CdY1-3Tcf; Thu, 10 Oct 2024 12:01:33 +0000 Received: from mail-ej1-x62b.google.com ([2a00:1450:4864:20::62b]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1syrQs-0000000CYKl-0aHV for linux-arm-kernel@lists.infradead.org; Thu, 10 Oct 2024 11:34:19 +0000 Received: by mail-ej1-x62b.google.com with SMTP id a640c23a62f3a-a9953bdc341so19032266b.2 for ; Thu, 10 Oct 2024 04:34:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1728560053; x=1729164853; 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=hNYBR6ZSh2a4w1mSh6FqJlsw/BqZTd6AKV7VHjOwsQw=; b=h9t5lPok6XSzJtiKtvC1kP5M2Iug4yqsNj0BwyV9R6aAzqPykp5P4nwNrJ9ocl439w zI1miKwB86SNixAj49GarceyoSfpFfy2OX4JvbgFTK6OH6qP5YS95En2/+py6NOoyXur xxhpfowy+0fRI76voPV1itCDponWGRyVj0zbugjGRpg/wRg6gG2CIFn1P7LR5f5SNRms 5MU44GIyZd0gNV6TM7DpT9kUoLtHXB4yX6NSVfg5iG1LiOXoAKGXzUKM2NXeC3LyKoYz AZ4ekyPWo20ynsSKE+Sa2kvzMuc1FTyI9Efcc46p08nlW1ASUbHqYWHlxtITLVUyFsrh NLNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728560053; x=1729164853; 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=hNYBR6ZSh2a4w1mSh6FqJlsw/BqZTd6AKV7VHjOwsQw=; b=dl41tv7pGC6CRZ9k9IfBceGD7znRangB8W4gbWh0PRvjeCXY/q1AHXoCbtnRDAsD38 +Qz519+Zp1w7HQ8ChXYIbeaorzPuCPCdyNsIGh28ln8sRd7OR2PnVPV6HyFlV3QX7lPA /8XEdxk5XEaSKGZWZoor/y/hk4nPc9c8omeqY5FBmhawgZ/CCtHr3v/AeK44wma8wsks 3bVWUPaVDnsgSAuNXe0D5E23TECGc9hR4Df9Jesoul+LpZljJu1OAv7mpRHtZIUaJmBp I8c7O5lNzQDLt5gyIF3/fRu2zwD65E/oJqjlXwS/vE8Y9LQln0dsEY54NLgtbYVIzubd RVjw== X-Gm-Message-State: AOJu0YzV835Q69CnU18876OSKLtZ1vrLP9iZBO93FbYTKIf12q71yXv1 p33Kv20u9rjsG43QUBrMR1cZ1erlwaLIORpUVdosbQu0OCXolgEoz2zGz5EU4Fg= X-Google-Smtp-Source: AGHT+IHL5fhjnV7jrHCiVi1KTSPjzJB1MdYFxv8NsvHT8D9zQW+FbMo3EZMj/2II5YwtAlSsYXswMA== X-Received: by 2002:a17:906:d259:b0:a99:42e7:21f with SMTP id a640c23a62f3a-a998d224f32mr538373366b.37.1728560052587; Thu, 10 Oct 2024 04:34:12 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a7f25406sm77619066b.69.2024.10.10.04.34.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2024 04:34:12 -0700 (PDT) From: Linus Walleij Date: Thu, 10 Oct 2024 13:33:55 +0200 Subject: [PATCH RFC 17/28] ARM: entry: Implement syscall_exit_to_user_mode() MIME-Version: 1.0 Message-Id: <20241010-arm-generic-entry-v1-17-b94f451d087b@linaro.org> References: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org> In-Reply-To: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org> To: 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.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241010_043414_225191_25DDE356 X-CRM114-Status: GOOD ( 15.59 ) 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 Mirroring syscall_enter_from_user_mode() we create the sibling call syscall_exit_to_user_mode() and start to move some stuff over from assembly, first the rseq call and the interrupt disablement. Signed-off-by: Linus Walleij --- arch/arm/include/asm/entry.h | 1 + arch/arm/include/asm/signal.h | 1 - arch/arm/kernel/entry-common.S | 10 ++-------- arch/arm/kernel/entry.c | 8 ++++++++ arch/arm/kernel/signal.c | 7 ------- 5 files changed, 11 insertions(+), 16 deletions(-) diff --git a/arch/arm/include/asm/entry.h b/arch/arm/include/asm/entry.h index e259b074caef..8b8cc9a1eefb 100644 --- a/arch/arm/include/asm/entry.h +++ b/arch/arm/include/asm/entry.h @@ -9,6 +9,7 @@ struct pt_regs; * to generic entry once they are semantically equivalent. */ long syscall_enter_from_user_mode(struct pt_regs *regs, long); +void syscall_exit_to_user_mode(struct pt_regs *regs); void irqentry_enter_from_user_mode(struct pt_regs *regs); void irqentry_exit_to_user_mode(struct pt_regs *regs); diff --git a/arch/arm/include/asm/signal.h b/arch/arm/include/asm/signal.h index 7acccc96840c..bb753cd3e29f 100644 --- a/arch/arm/include/asm/signal.h +++ b/arch/arm/include/asm/signal.h @@ -23,7 +23,6 @@ typedef struct { #include -void do_rseq_syscall(struct pt_regs *regs); void do_work_pending(struct pt_regs *regs, unsigned int thread_flags); #endif diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S index df564388905e..3559e0a9f5e0 100644 --- a/arch/arm/kernel/entry-common.S +++ b/arch/arm/kernel/entry-common.S @@ -65,12 +65,9 @@ ret_fast_syscall: UNWIND(.fnstart ) UNWIND(.cantunwind ) add sp, sp, #(S_R0 + S_OFF) -#if IS_ENABLED(CONFIG_DEBUG_RSEQ) /* do_rseq_syscall needs interrupts enabled. */ mov r0, sp @ 'regs' - bl do_rseq_syscall -#endif - disable_irq_notrace @ disable interrupts + bl syscall_exit_to_user_mode ldr r1, [tsk, #TI_FLAGS] @ re-check for syscall tracing movs r1, r1, lsl #16 beq no_work_pending @@ -97,13 +94,10 @@ ENDPROC(ret_fast_syscall) * do_work_pending() will update this state if necessary. */ ENTRY(ret_to_user) -#if IS_ENABLED(CONFIG_DEBUG_RSEQ) /* do_rseq_syscall needs interrupts enabled. */ enable_irq_notrace @ enable interrupts mov r0, sp @ 'regs' - bl do_rseq_syscall -#endif - disable_irq_notrace @ disable interrupts + bl syscall_exit_to_user_mode ENTRY(ret_to_user_from_irq) ldr r1, [tsk, #TI_FLAGS] movs r1, r1, lsl #16 diff --git a/arch/arm/kernel/entry.c b/arch/arm/kernel/entry.c index 1973947c7ad7..472338047337 100644 --- a/arch/arm/kernel/entry.c +++ b/arch/arm/kernel/entry.c @@ -1,7 +1,9 @@ // SPDX-License-Identifier: GPL-2.0 #include +#include #include #include +#include long syscall_enter_from_user_mode(struct pt_regs *regs, long syscall) { @@ -14,6 +16,12 @@ long syscall_enter_from_user_mode(struct pt_regs *regs, long syscall) return syscall; } +void syscall_exit_to_user_mode(struct pt_regs *regs) +{ + rseq_syscall(regs); + local_irq_disable(); +} + noinstr void irqentry_enter_from_user_mode(struct pt_regs *regs) { trace_hardirqs_off(); diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c index 7b1a16e86b23..03b20637a2e1 100644 --- a/arch/arm/kernel/signal.c +++ b/arch/arm/kernel/signal.c @@ -659,13 +659,6 @@ struct page *get_signal_page(void) return page; } -#ifdef CONFIG_DEBUG_RSEQ -asmlinkage void do_rseq_syscall(struct pt_regs *regs) -{ - rseq_syscall(regs); -} -#endif - /* * Compile-time assertions for siginfo_t offsets. Check NSIG* as well, as * changes likely come with new fields that should be added below.