From patchwork Thu Oct 10 11:33:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13829995 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 909B7CF11D2 for ; Thu, 10 Oct 2024 11:45:43 +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=wUlF8zw6dAVB0pDGKJAXIn96hGOC+sJV5+syU6CZdaU=; b=XFmj7kIFXkFzqTaCpgfCzY8Nvv xYdUyI19AI1BfRFBWZfri9JQv57OiKWLMoLSS7+0bKanPAo61DWlkrho/YXAezpvTvs++EVOAJ5WU yYc8SK0lPhvIYf55IEXZ0X5/jii0vX4yJJwwHdyMOR7NeUOZ9tM5hfxr5zN6vw8QfYM6qKfGs3sxe Aij11B8WXya+NUFYzDbbXXCKbygv6YXL549IhFkgYtppRlb8fAWFh6JhEDZXnuNnT3/SzmoTyqPrC JD1VTAcvhKm6yg0fhmA4g+eUrOPhPllw2Q+hg1+6hx0YNBkBRiQkohRzad2yEcE0mwJca1mkaY849 20awXQTQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1syrbp-0000000Catj-3THs; Thu, 10 Oct 2024 11:45:33 +0000 Received: from mail-ed1-x52b.google.com ([2a00:1450:4864:20::52b]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1syrQb-0000000CYD0-0Zbo for linux-arm-kernel@lists.infradead.org; Thu, 10 Oct 2024 11:34:01 +0000 Received: by mail-ed1-x52b.google.com with SMTP id 4fb4d7f45d1cf-5c87c7d6ad4so1031894a12.3 for ; Thu, 10 Oct 2024 04:33:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1728560035; x=1729164835; 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=wUlF8zw6dAVB0pDGKJAXIn96hGOC+sJV5+syU6CZdaU=; b=QRNrKo6nkuZKbMzJ4QkUN6zNtfWlknULyhMuyuRhQwkG9VrBkYqawwwMOVcyL1/egC LNP+B4OGjRhKDWlbWNXba4lNiSFGe5Aa8hJT2XlqW6+xVJj8tvka5sEZDhJEJwvJRYt8 HFqlgDJLZJNbuOZDFKok7HbEVjrzm2rT5zIY1g0tdPAI4lZG8Y1IDyTl+K32VohXD05Z kVCJMs6yLbPtn5+Swgy6proubby/Dh5PvK1BAd6FlrEatoMpCFEcjNgd7wxYFHG+QPPW JzlBvRMSku6CWS8yXpaKE1YxOUeoG2gyUQDtfybfc2PzzWZuImlAEtYqF4Ktu0Y0A3bd DmcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728560035; x=1729164835; 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=wUlF8zw6dAVB0pDGKJAXIn96hGOC+sJV5+syU6CZdaU=; b=h57gTVLW3ue8qohvmwCwH40tsg+bNcsnVn6FWFWJtURUAgA5ududMXsJq9ydw9zNS7 vjLWPvEJ0X6D1H5z5TWMm3SVLzBbKXsrTKsv1ky495WN6rVLi8KLqy4m4ZCAjj7Jj6zV H5PrFGA+c/5mvpXrMfpJ2elD/Vc1HgwTjCoGmXUVVbn1JrBGVJ9HyO5i7xqEgvmPVlM6 SD9MGCheX/WKDX4CoO/WB650aofIBq57NCENrIA3iq1wu41d3WkdV5xVK4kYRXRvAbn2 MR8eKcSSqMybDaoKCiBb/d3H4F4lndQPXqMH8NguZQYBeWwwdR3EA3SOTkDULcEJ1zyQ 35Gg== X-Gm-Message-State: AOJu0Ywe/q+HHTpzcha3FwfF0NYIKXsZxeophn950g4TrZ/kwo7pI92y gwIkREo11677otC7G0mdquyNuHqEpiyHyuBY/ulebJaPNvxU2sTyPDFx0NGzBVk= X-Google-Smtp-Source: AGHT+IEIU5Pj5ZFEwE9UNRPJZ2YyGwVO4NXzcsvArZ+4K3EO08VhOOCr6/3XirfwIGeg5+bwIqCr5w== X-Received: by 2002:a17:907:5083:b0:a99:8edf:a367 with SMTP id a640c23a62f3a-a998edfa4cbmr371973966b.57.1728560035569; Thu, 10 Oct 2024 04:33:55 -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.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2024 04:33:54 -0700 (PDT) From: Linus Walleij Date: Thu, 10 Oct 2024 13:33:45 +0200 Subject: [PATCH RFC 07/28] ARM: entry: Rewrite two asm calls in C MIME-Version: 1.0 Message-Id: <20241010-arm-generic-entry-v1-7-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_043357_431879_3E6ED160 X-CRM114-Status: GOOD ( 17.45 ) 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 normal and trace entry code calls out to arm_syscall() and sys_ni_syscall() from assembly, but these calls can be moved over to the new C implementation. Signed-off-by: Linus Walleij --- arch/arm/include/asm/traps.h | 2 +- arch/arm/kernel/entry-common.S | 23 +++++------------------ arch/arm/kernel/syscall.c | 13 +++++++++++-- arch/arm/kernel/traps.c | 2 +- 4 files changed, 18 insertions(+), 22 deletions(-) diff --git a/arch/arm/include/asm/traps.h b/arch/arm/include/asm/traps.h index 2621b9fb9b19..b888912c2450 100644 --- a/arch/arm/include/asm/traps.h +++ b/arch/arm/include/asm/traps.h @@ -40,7 +40,7 @@ asmlinkage void dump_backtrace_stm(u32 *stack, u32 instruction, const char *logl asmlinkage void do_undefinstr(struct pt_regs *regs); asmlinkage void handle_fiq_as_nmi(struct pt_regs *regs); asmlinkage void bad_mode(struct pt_regs *regs, int reason); -asmlinkage int arm_syscall(int no, struct pt_regs *regs); +int arm_syscall(int no, struct pt_regs *regs); asmlinkage void baddataabort(int code, unsigned long instr, struct pt_regs *regs); asmlinkage void __div0(void); asmlinkage void handle_bad_stack(struct pt_regs *regs); diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S index 57aa1084a047..77801d039b5f 100644 --- a/arch/arm/kernel/entry-common.S +++ b/arch/arm/kernel/entry-common.S @@ -264,18 +264,10 @@ ENTRY(vector_swi) mov r0, tbl /* r1 already contains regs */ mov r2, scno @ syscall number from r7 - badr r3, __ret_fast_syscall - bl invoke_syscall - - /* Restore regs into r1 and lr after C call */ + /* We return here no matter what, also pass this as an argument */ badr lr, __ret_fast_syscall - add r1, sp, #S_OFF - -2: cmp scno, #(__ARM_NR_BASE - __NR_SYSCALL_BASE) - eor r0, scno, #__NR_SYSCALL_BASE @ put OS number back - bcs arm_syscall - mov why, #0 @ no longer a real syscall - b sys_ni_syscall @ not private func + mov r3, lr + b invoke_syscall #if defined(CONFIG_OABI_COMPAT) || !defined(CONFIG_AEABI) /* @@ -308,13 +300,8 @@ __sys_trace: mov r0, tbl badr r3, __sys_trace_return bl invoke_syscall_trace - - /* Restore regs into r1 and lr after C call */ - add r1, sp, #S_R0 + S_OFF @ pointer to regs - badr lr, __sys_trace_return - - cmp scno, #-1 @ skip the syscall? - bne 2b + cmp r0, #-1 + bne __sys_trace_return add sp, sp, #S_OFF @ restore stack __sys_trace_return_nosave: diff --git a/arch/arm/kernel/syscall.c b/arch/arm/kernel/syscall.c index be193266299f..d1259c6d2805 100644 --- a/arch/arm/kernel/syscall.c +++ b/arch/arm/kernel/syscall.c @@ -11,16 +11,25 @@ __visible int invoke_syscall(void *table, struct pt_regs *regs, int scno, void * /* Doing this with return makes sure the stack gets pop:ed */ return invoke_syscall_asm(table, regs, scno, retp); - return 0; + if (scno >= __ARM_NR_BASE) + return arm_syscall(scno, regs); + + return sys_ni_syscall(); } int invoke_syscall_trace_asm(void *table, struct pt_regs *regs, int scno, void *retp); __visible int invoke_syscall_trace(void *table, struct pt_regs *regs, int scno, void *retp) { + if (scno == -1) + return -1; + if (scno < NR_syscalls) /* Doing this with return makes sure the stack gets pop:ed */ return invoke_syscall_trace_asm(table, regs, scno, retp); - return 0; + if (scno >= __ARM_NR_BASE) + return arm_syscall(scno, regs); + + return sys_ni_syscall(); } diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c index 480e307501bb..42f6bb593eb4 100644 --- a/arch/arm/kernel/traps.c +++ b/arch/arm/kernel/traps.c @@ -606,7 +606,7 @@ do_cache_op(unsigned long start, unsigned long end, int flags) * 0x9f0000 - 0x9fffff are some more esoteric system calls */ #define NR(x) ((__ARM_NR_##x) - __ARM_NR_BASE) -asmlinkage int arm_syscall(int no, struct pt_regs *regs) +int arm_syscall(int no, struct pt_regs *regs) { if ((no >> 16) != (__ARM_NR_BASE>> 16)) return bad_syscall(no, regs);