From patchwork Thu Oct 10 11:33:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13829993 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 E4856CF11D2 for ; Thu, 10 Oct 2024 11:43:01 +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=FhwutFaJAhBwzUvxWfpVZxdfXLNUR2eiL6c/Y41YU9M=; b=2TzLo/LIXLNRtx+wnCFLQrngr4 2h49vp9c/lqgpzNGnidBFV3aZT4liqrELs4HAjBNq7afvkuvojtXZu8cpGXF8Kcgz7SxDUUvqtiVQ fF0P8DVLxDlpa5lGaFn8xD2nmlko7OLTB1pTSi6C67HTFtPBgFjI3O8aMJq6UBVR9FU+kEjCMAQ3+ dvottwTO7579lCiI60QfTQdAsAgVALvS9oS65785/x3EPXwz7gMN1irFusEFZjOjcjcXWmOPARTmZ aBIxPZpMuES6L6Q1lXxHcc7K+U2INThBZJG/LmlRQzUaII6/mKzbP5QLASceaRCGoV+SB8Bhjs/zv +gH/85Ug==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1syrZC-0000000CaTB-27qw; Thu, 10 Oct 2024 11:42:50 +0000 Received: from mail-ej1-x62c.google.com ([2a00:1450:4864:20::62c]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1syrQY-0000000CYBF-0m1R for linux-arm-kernel@lists.infradead.org; Thu, 10 Oct 2024 11:33:59 +0000 Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-a99415adecaso340232266b.0 for ; Thu, 10 Oct 2024 04:33:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1728560032; x=1729164832; 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=FhwutFaJAhBwzUvxWfpVZxdfXLNUR2eiL6c/Y41YU9M=; b=ipomTfq3QAuPECC8zB0yxzPijzl6L3G2hbVFlRrrxgJnihN0xDuCXmSXHuURmqXSsU vB1fh7c/9e5Mem7q81JgKGwi2KCTTMiACQWaFQzQRten2E08Ar6NO4gY7B+pDZG9YZ9Z 76lCI6gEP5CJkxbNxXecqluvpYQnaCR/wwYDegmCQeFJEQ8VV/Bu8C+SOw6XxdjCNRZ6 Fo9kzkwCIZOzzbfJkMlPyvOAPUTi8HdWcjvBUeSLIoZNqkfggIzwJfUUYCYSf67ZVl8t TPqtysNXrKutlKWk3UiRKdPooQBdKdYuGADDIfnfyn4VqNLMss9o1tOUZ+Y6yYyGpOiG 8ayg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728560032; x=1729164832; 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=FhwutFaJAhBwzUvxWfpVZxdfXLNUR2eiL6c/Y41YU9M=; b=JKGsrpWiBMEOiknUilGxcW/xOzF/jswO70OdXmpliY1mPfZZk4oB4VSFflgaqhP4+m GsP48CzQbh5VvjeRWHppTLHAb49LQlXfMR0+tKONUFqGMmaR4d0m7KzL/D9vrhxW9O9y YXFjg3RlSGxs6Rf//d6JIG9xl/J6Omz4tDHSDqQ/r0tZqzU3e0Uq4IorPo6w8LHxcYNg gn65DeuWRaAOvnxsqnMIWlogMhnwuIZc07LhQBfpW5O8xbJzlkMe/y1bho58K4+ka2/i zfdx1p38JlB9tKMaexxPDRVIa1j5An81hhvoTjqAN0id0iEJl7ERAuom4MLLhDKMuboZ YJmQ== X-Gm-Message-State: AOJu0YwhggdrwLq1MWOyegUvqQq70yB5wXXQnPbTVb/jBwP4N9jkFcWG YDPvPg/o9fVvIcZGAGe7ql6DtLu9CQDXKxbJxSQjbGkazGNqJ5hjFE6zO1sRTW4= X-Google-Smtp-Source: AGHT+IFaoE3sZWLkTplU7TDESmJsAO9u+n0GW9GsY4BElZ/Wg4eEpzfSZ1AqFssYL+f+8cp61QXAgw== X-Received: by 2002:a17:906:6a11:b0:a86:8f9b:ef6e with SMTP id a640c23a62f3a-a99a10f7328mr306580766b.13.1728560032206; Thu, 10 Oct 2024 04:33:52 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a7f25406sm77619066b.69.2024.10.10.04.33.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2024 04:33:50 -0700 (PDT) From: Linus Walleij Date: Thu, 10 Oct 2024 13:33:43 +0200 Subject: [PATCH RFC 05/28] ARM: process: Remove local restart MIME-Version: 1.0 Message-Id: <20241010-arm-generic-entry-v1-5-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_043354_264071_B7B48409 X-CRM114-Status: GOOD ( 22.67 ) 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 ARM kernel contains a quirk to handle syscall restarts inside the kernel without exiting to userspace. The generic entry cannot handle this. Rename do_signal() to arch_do_signal_or_restart() to fit with the upcoming generic entry conversion. This is essentially a revert of commit 81783786d5cf "ARM: 7473/1: deal with handlerless restarts without leaving the kernel" from 2012. Other solutions may be possible, such as checking the PC after do_work_pending and assume it is a local restart if that address is inside the kernel, or modifying the generic entry code to track local restarts like ARM does and pass that information back. Signed-off-by: Linus Walleij --- arch/arm/include/asm/signal.h | 3 +-- arch/arm/kernel/entry-common.S | 9 +-------- arch/arm/kernel/signal.c | 28 +++++++++------------------- 3 files changed, 11 insertions(+), 29 deletions(-) diff --git a/arch/arm/include/asm/signal.h b/arch/arm/include/asm/signal.h index 8b84092d1518..7acccc96840c 100644 --- a/arch/arm/include/asm/signal.h +++ b/arch/arm/include/asm/signal.h @@ -24,7 +24,6 @@ typedef struct { #include void do_rseq_syscall(struct pt_regs *regs); -int do_work_pending(struct pt_regs *regs, unsigned int thread_flags, - int syscall); +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 df6961a1006b..da5c2d4b62e5 100644 --- a/arch/arm/kernel/entry-common.S +++ b/arch/arm/kernel/entry-common.S @@ -86,14 +86,8 @@ ENDPROC(ret_fast_syscall) bne __sys_trace_return_nosave slow_work_pending: mov r0, sp @ 'regs' - mov r2, why @ 'syscall' bl do_work_pending - cmp r0, #0 - beq no_work_pending - movlt scno, #(__NR_restart_syscall - __NR_SYSCALL_BASE) - str scno, [tsk, #TI_ABI_SYSCALL] @ make sure tracers see update - ldmia sp, {r0 - r6} @ have to reload r0 - r6 - b local_restart @ ... and off we go + b no_work_pending ENDPROC(ret_fast_syscall) /* @@ -266,7 +260,6 @@ ENTRY(vector_swi) */ TRACE( ldmia sp, {r0 - r3} ) -local_restart: ldr r10, [tsk, #TI_FLAGS] @ check for syscall tracing stmdb sp!, {r4, r5} @ push fifth and sixth args diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c index 79a6730fa0eb..7b1a16e86b23 100644 --- a/arch/arm/kernel/signal.c +++ b/arch/arm/kernel/signal.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include "signal.h" @@ -534,9 +535,10 @@ static void handle_signal(struct ksignal *ksig, struct pt_regs *regs) * the kernel can handle, and then we build all the user-level signal handling * stack-frames in one go after that. */ -static int do_signal(struct pt_regs *regs, int syscall) +static void arch_do_signal_or_restart(struct pt_regs *regs) { unsigned int retval = 0, continue_addr = 0, restart_addr = 0; + bool syscall = (syscall_get_nr(current, regs) != -1); struct ksignal ksig; int restart = 0; @@ -590,16 +592,14 @@ static int do_signal(struct pt_regs *regs, int syscall) } else { /* no handler */ restore_saved_sigmask(); - if (unlikely(restart) && regs->ARM_pc == restart_addr) { + if (unlikely(restart) && regs->ARM_pc == restart_addr) regs->ARM_pc = continue_addr; - return restart; - } } - return 0; + return; } -asmlinkage int -do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall) +asmlinkage void +do_work_pending(struct pt_regs *regs, unsigned int thread_flags) { /* * The assembly code enters us with IRQs off, but it hasn't @@ -612,19 +612,10 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall) schedule(); } else { if (unlikely(!user_mode(regs))) - return 0; + return; local_irq_enable(); if (thread_flags & (_TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL)) { - int restart = do_signal(regs, syscall); - if (unlikely(restart)) { - /* - * Restart without handlers. - * Deal with it without leaving - * the kernel space. - */ - return restart; - } - syscall = 0; + arch_do_signal_or_restart(regs); } else if (thread_flags & _TIF_UPROBE) { uprobe_notify_resume(regs); } else { @@ -634,7 +625,6 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall) local_irq_disable(); thread_flags = read_thread_flags(); } while (thread_flags & _TIF_WORK_MASK); - return 0; } struct page *get_signal_page(void)