From patchwork Thu Oct 10 11:34:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13830023 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 A29CECF11D0 for ; Thu, 10 Oct 2024 12:10:00 +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=Y1Hv1gsrpr1we4HbxlxxqJW/y8rgdVZEtXO9KHxWDAg=; b=hvAGTzXIz2zKPf76okyEENbQ3o GUU+XEo/8TzAvymysU8ajftPYTfSFRCzweM5j0wY+06s1sbsMmKaVT2RpL9SXU21VmM0KHOFm5zQZ UpZ6X9HLu4KUqDzZuG/Ty0EWluWvuVJ9yVxUc/6FZH72k4VzH/n4LZzsHvAwjZtyhWTOLrv4AAJIN aOs+k+MVcYX76Eya6uHmqeF0PDnvUKVulNZhfZxYLwzJ3Y3HKRu4pMUt1UJnfN/3kgT3qkNOwV/Jn iL8lmPLhWcx5dPHSayNHFmSPnZR8XhI8m9nZzol9tpAQUCLILNX3/AO8WPSq1BchWEKFo/7b9j/2u yo1DBZMw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1syrzL-0000000Cf0D-3SbC; Thu, 10 Oct 2024 12:09:51 +0000 Received: from mail-ej1-x629.google.com ([2a00:1450:4864:20::629]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1syrR2-0000000CYPX-3onn for linux-arm-kernel@lists.infradead.org; Thu, 10 Oct 2024 11:34:31 +0000 Received: by mail-ej1-x629.google.com with SMTP id a640c23a62f3a-a994ecf79e7so133918066b.0 for ; Thu, 10 Oct 2024 04:34:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1728560063; x=1729164863; 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=Y1Hv1gsrpr1we4HbxlxxqJW/y8rgdVZEtXO9KHxWDAg=; b=iMCIPuSMYYIuq7pMO852Dq4+L4D8k0BSvsE9dJ1jcEStXCZ7K31/loE9w9BeAq5/Qq c77lvw47iqCBxem+aNDs+lyVbcSn216k8eLbIqqF68HBqTGRDfClJhkhIkE9fPVZFNlX dy2tZmhNAnZYIahAhFyiJNY2vOlVpsMZnrqSNlqB8PCIaYJ7Vxj33Eqa+136SpexBVYt bdRRNJoluAr/lwT4QrTLWa4y1tmZzBVO+6v2Qd6I6dt4Ru22B4ewndyB+bgeY94uchtS hLqXOj7gz2KM3+2kZV7RrSI2PMgzBlW9hgTRjLleUdhm+gHKecu6W+D5Jw0C7DZeYlWT 0tEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728560063; x=1729164863; 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=Y1Hv1gsrpr1we4HbxlxxqJW/y8rgdVZEtXO9KHxWDAg=; b=sJF+SwkhBPjsU6iwUAKAw90ZRUhSokT9N94iRVjrLpNHcUKzZNtOpLMfmvHs0BoNIi KzjU7N6zjP4dpYo/BkfvNgZ33+Zemr6rNttb5YEja8dIlqGlaByd1Tnq/Di0htX5eW6s OeXgBc05m8uGoKkh1WY6R7fGpeLW+XYnViWZE/K14MfZcGdajmlCFuEpqG/EQgAfmF8u qPcOkvGrgM2Ga/wyaOHeYSOFPEGo4oI5V2Og997RJcMHWzBon1ojEdQPxh1DoSO4O/+E OGNgv3OlP3Qwd96eL79VR8YcGhRv7nIoI9nRK792f/HKGAObmFDnZyaLmxOspyDAt7mx 1GRA== X-Gm-Message-State: AOJu0Yz/zYLW6poL53xig1XLF/JpAWCX3x65MAQH83/kqSwLoSxzrNlZ loy7uqREUaYLR6nmwimkWoOVVjmw8RkAc+RJgWw4BpP41RI7VXY1UutxA7ueXOo= X-Google-Smtp-Source: AGHT+IHJRHiR4KzKVHqPedhfFs92LdPjHSU6zPVuDKN5K3YQhsffs0YsSzQJndzJhUDXQSRYclCqMA== X-Received: by 2002:a17:907:e648:b0:a99:5985:bf39 with SMTP id a640c23a62f3a-a998d117e0amr515807466b.13.1728560063234; Thu, 10 Oct 2024 04:34:23 -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.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2024 04:34:22 -0700 (PDT) From: Linus Walleij Date: Thu, 10 Oct 2024 13:34:02 +0200 Subject: [PATCH RFC 24/28] ARM: entry: Complete syscall and IRQ transition to C MIME-Version: 1.0 Message-Id: <20241010-arm-generic-entry-v1-24-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_043425_048980_EB7C3E8D X-CRM114-Status: GOOD ( 17.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 This moves over the last few lines of assembly to C. The subtle change is that in return to userspace from syscall (SWI) or interrupt, we need to call do_work_pending() as soon as the thread flags are != 0, just checking for work with _TIF_SYSCALL_WORK is not enough (the machine will freeze if we do that). This is because do_work_pending() does not just handle work: it handles _TIF_NEED_RESCHED, _TIF_SIGPENDING, _TIF_NOTIFY_SIGNAL and _TIF_UPROBE as well. Signed-off-by: Linus Walleij --- arch/arm/kernel/entry-common.S | 13 +------------ arch/arm/kernel/entry.c | 19 +++++++++++++------ arch/arm/kernel/signal.c | 3 +-- 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S index e2ac6d3216b6..6b0f86786a7d 100644 --- a/arch/arm/kernel/entry-common.S +++ b/arch/arm/kernel/entry-common.S @@ -61,12 +61,7 @@ ENTRY(ret_to_user) enable_irq_notrace @ enable interrupts mov r0, sp @ 'regs' bl syscall_exit_to_user_mode - ldr r1, [tsk, #TI_FLAGS] - movs r1, r1, lsl #16 - beq 1f - mov r0, sp @ 'regs' - bl do_work_pending -1: + #ifdef CONFIG_GCC_PLUGIN_STACKLEAK bl stackleak_erase_on_task_stack #endif @@ -74,12 +69,6 @@ ENTRY(ret_to_user) ENDPROC(ret_to_user) ENTRY(ret_to_user_from_irq) - ldr r1, [tsk, #TI_FLAGS] - movs r1, r1, lsl #16 - beq no_work_pending - mov r0, sp @ 'regs' - bl do_work_pending -no_work_pending: asm_irqentry_exit_to_user_mode #ifdef CONFIG_GCC_PLUGIN_STACKLEAK diff --git a/arch/arm/kernel/entry.c b/arch/arm/kernel/entry.c index 88a7a699306a..d7fdb9df3331 100644 --- a/arch/arm/kernel/entry.c +++ b/arch/arm/kernel/entry.c @@ -6,11 +6,6 @@ #include #include -static inline bool has_syscall_work(unsigned long flags) -{ - return unlikely(flags & _TIF_SYSCALL_WORK); -} - long syscall_enter_from_user_mode(struct pt_regs *regs, long syscall) { trace_hardirqs_on(); @@ -28,7 +23,11 @@ void syscall_exit_to_user_mode(struct pt_regs *regs) rseq_syscall(regs); local_irq_disable(); - if (has_syscall_work(flags)) + /* + * It really matters that we check for flags != 0 and not + * just for pending work here! + */ + if (flags) do_work_pending(regs, flags); trace_hardirqs_on(); @@ -45,6 +44,14 @@ noinstr void irqentry_enter_from_user_mode(struct pt_regs *regs) noinstr void irqentry_exit_to_user_mode(struct pt_regs *regs) { + unsigned long flags = read_thread_flags(); + + /* + * It really matters that we check for flags != 0 and not + * just for pending work here! + */ + if (flags) + do_work_pending(regs, flags); trace_hardirqs_on(); /* This context tracking call has inverse naming */ user_enter_callable(); diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c index 03b20637a2e1..a39ee14ec5b7 100644 --- a/arch/arm/kernel/signal.c +++ b/arch/arm/kernel/signal.c @@ -598,8 +598,7 @@ static void arch_do_signal_or_restart(struct pt_regs *regs) return; } -asmlinkage void -do_work_pending(struct pt_regs *regs, unsigned int thread_flags) +void do_work_pending(struct pt_regs *regs, unsigned int thread_flags) { /* * The assembly code enters us with IRQs off, but it hasn't