From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8ABB81E47DC for ; Tue, 7 Jan 2025 09:41:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736242900; cv=none; b=FlClDzOVWfgDruzs35QwAJ53biVoouorcHOiJTdwmncAz8b1u6jcXDjU/fwl14Ht58NAVdW1Brw22bHY74ikDQoqTV5RVs31bjoADuaG4uccWrWbtAExX9W3zAoClFiFG9KLE1i0WPjSUsziIi+2B52BUwz+pxXywBtqTFAmsYo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736242900; c=relaxed/simple; bh=KaP2h1Ww/LieeePeBp0IcfRkel9gJ7VjTqt7/8NkO3Q=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=AdL7+DYOEHlsK1DErj+umIcNa5rG75hPhvV8+meqf5EiDnpXyNNzEWHg+QXId83pwCGoAEs6QBoDcDF/ecVLl+p4AcIGjM2CqCAjvZtHC0oVnV5a4u/+pL7CyZ+LYvyzPSpCR/vmhjpLPJPyS9fsVkqENFidGQKExHxt6+TXFDk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=MXuJDX+i; arc=none smtp.client-ip=209.85.208.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="MXuJDX+i" Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-5d3d143376dso22532578a12.3 for ; Tue, 07 Jan 2025 01:41:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1736242895; x=1736847695; darn=vger.kernel.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=KCIOsAtrOIwVuMz8AAsW+bZvUjPbPot+cHp/DueUyE0=; b=MXuJDX+ivcKFLZquNBVFjHQdNf3DtBTNteuM3BFM/hYuTd2LottQmtMZz9Bwvu42zt xW0A/9W9v0GRVBujrlSYifqlIPS8g09q9v7FogqWEosdhZENMpCbXIu/uvld+gmfMDor c7xkmZjqXJREUIsn8SYCVcx7nRAlXP7ZU/84mkc6nLfcZox0Nk8MxqSF2g9kAcCIbhuN LXADQCwRFp9qZAcHUxpT6ehI7ldB1fdWpb0KXAj91jP+uxU1iGu2Z8vBmxHMxVWAp7rK lxbhx3ZSQEMiuBrueJ2xvOGISWB66fx4RC0ykkyKl3O1Pbw6YA3Cily28ZWUwWqY7KXB hJhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736242895; x=1736847695; 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=KCIOsAtrOIwVuMz8AAsW+bZvUjPbPot+cHp/DueUyE0=; b=cTzpkErKxw+IZ02tWO+0QRRyx+Kbt/ie8fZDWnKBGXa2tdnUqzL7UHTzU5ZyTWfjw8 o2Qw+DxXOzrbop9zBX75Bg6YlVLqxhnoXD3s3c/VP+SqZDBKYtTmgaLA75W10vfH+8u3 ot9jW6Rlqgk6xDMBqvAoepKOCRnAMK+qcs8fd9L39laHVtoklbvxcDOGxeX1uHx+uuuv uxSmo4mg+2g9HlA4isy6oQ8pldH2p5RR5HltUCvFVQPwbdYqwgCRGHu9JeLJFIIlESjt 9Bg1la5ixy0lX+V6QBPvX/i9vjvebs94lIK4L4UG+7Y5AhXS4FHPR2aeNZdSBuFTcE5H +ioA== X-Forwarded-Encrypted: i=1; AJvYcCWvebvq4NA99YT7EMS36P9YQlbV+Oy8Vju2Ph1x8JOxmaFw/OhsDAKTY7Ow8UlIAaezC7Oy1DVrE/oSOZs=@vger.kernel.org X-Gm-Message-State: AOJu0YwUHhqzmSJhCx9k/xhMMr6puAAIllrycsw0DZ+/J46R0YCbJ3yS ydktsq9JcwBFXavAaqpp+MA1XdD3CzyHjUvtRdGb7OllJGHGBf7V4MdYaYCD9es= X-Gm-Gg: ASbGnctb6zZvW9DGu1r23+r+nFAbRIkm/+PyQDMzSOysL57OnAcwTmJ830mAxZqejEi fWX2oDccOhxQkQrJswpMqCZlW53p8jn/Hk5Q/+WNLGxIRF9x9Zm4gavZbBOeRY+zXbyz530CB/s 0eFF/0aKf+/oWGvphWlgx7fq0i1e405X8Ks3w44nniM7Sn1+Ps37Fcp9VggetPM7feI1HFL9UEm WRbIfr1aLIEyT3gGJNTr/qsBpi8W2dK6liur+sliLOVqKtJXROkUVc2yOpHJcTrCQ4= X-Google-Smtp-Source: AGHT+IGsYLeEIV9Svcr+n7wuZvUGXSmBLy0vRkLLhWqpBA9vLSf8rLeHtiJVrepCoMzwbdEyg/jczw== X-Received: by 2002:a17:907:9345:b0:aae:ea52:3a5 with SMTP id a640c23a62f3a-aaeea5204bemr4516811766b.44.1736242894733; Tue, 07 Jan 2025 01:41:34 -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.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jan 2025 01:41:34 -0800 (PST) From: Linus Walleij Date: Tue, 07 Jan 2025 10:41:23 +0100 Subject: [PATCH RFC v3 07/30] ARM: entry: Rewrite two asm calls in C Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20250107-arm-generic-entry-v3-7-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 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 2621b9fb9b19b064aa40a8ab4a3a89067b98a010..b888912c2450e0e8eec8139166c7292f283545c7 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 57aa1084a0476e9c218cd100ce4fdf4aaa748234..77801d039b5f6562b231a6fd4979e318c7e736a6 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 edc0ac88ec60ce3f23149a526de7dc1205906552..d637dc74b1c70415933898fbcadbedc71df5f654 100644 --- a/arch/arm/kernel/syscall.c +++ b/arch/arm/kernel/syscall.c @@ -12,7 +12,10 @@ __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); @@ -20,9 +23,15 @@ __ADDRESSABLE(invoke_syscall_trace_asm); __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 6ea645939573fb65ed36f5435a9c94e98828f45b..942c77767919466d5b89d83d8eb77032b119473e 100644 --- a/arch/arm/kernel/traps.c +++ b/arch/arm/kernel/traps.c @@ -609,7 +609,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); -- 2.47.1