From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) (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 2A3A51E2308 for ; Tue, 7 Jan 2025 09:41:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.52 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736242896; cv=none; b=rJhSoHrQyDoPRC7jIgGh2Wc8m4cGw8zvjpOXkzToGCWTCKSm28L4nOZI0HRPoj8eAEpPxhOu9RQTOsnXW9cUktAfR4B2pQsF30ylzXJo3bYWWLglBYScPlsY0YbweJo+TtrMWYcxHv8rHMpTqnqhD1OoSaQUaE9gS9D9OGLqetc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736242896; c=relaxed/simple; bh=sIiH6za4rmEx1e8Z6wFW51ZIfOZuzN3vN5bSqgiYIBI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=l0DVbFBq9co+qr50fQRTGGFWOKE+RKq+Q7Ow/9jNSZKp3UI5No0e/ymHQS1lr5pJFQGToNw48tQm85Av2tgLRTPuukQ6TcSFIkx+Klk9EjyQXAQ3PThCoBtiQ+z3sxHH9LlpAtk8eDxA5qTrk2bz8wIfmyWWqh2lYOArwFBQ2cQ= 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=Nn2VGNh4; arc=none smtp.client-ip=209.85.218.52 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="Nn2VGNh4" Received: by mail-ej1-f52.google.com with SMTP id a640c23a62f3a-aa692211331so2940843666b.1 for ; Tue, 07 Jan 2025 01:41:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1736242891; x=1736847691; 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=XcwyQnV8bm55i5QCWMqzeBKQ01GSNdA6efjZ9lsGDLQ=; b=Nn2VGNh49FcT94GLo9pKBvwROVNpen+tLas1qT7SwO4q0ZUfn60EeRVKAljQJC5XCC 8oVwiMGKGWOtWe4Qvd9mUfcHLLp/LM19jo8wzed3Hf3qDtWTeBGkODSpMoWv2vKdl1ma drdXK3J+K7HKgAMg/j3DM6eppEvfF+0r580EjUCthHP+tNk+oQVn3ruaSRUFxuaVihpd ooy0YN6ZizI6WzK7tj5E1qVKYIRZnLyKxZ1w38jeAxx23IpO//Eza+mGtBIfhduKAhOc aG3jURdpAiwARiH6CWIqc/8zOqg76afDlp6TVXdWKCBhZoofBv7jq+EokbEIwbW6igSd RxOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736242891; x=1736847691; 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=XcwyQnV8bm55i5QCWMqzeBKQ01GSNdA6efjZ9lsGDLQ=; b=hSuRtZ/n82MBSkE6Qp3WQspIKFc1XqHBureKEG0ZIIY43ujjCGTWXj7IihL0SR5aNf LGTnG/7BKSsSmIAmnrwF4tWavYS85WqVqAvsNbEsvedSdpzrU/2cwFMsit9HUI8HshqV jsRT3+oEak26c3hX7AQRHZale6jffI+VGhXTxuaKMQF7qkc+w1azV++cLddpM3I+IS6O tz7giaS7717W7Xj8grl80+1O4QREVXzu9D2TAxIgQABrHLeyftE/BoJpUnDWkoS4ElI2 7LOOxffT9RjVPUJS04dENroWn2vGCK6EdYI0zFEXc6oE/4zwvCZfKsgNhBHUoSBtwAp6 eCLw== X-Forwarded-Encrypted: i=1; AJvYcCV2GX5zYo0oxcNXNMw39ZpLSg4ZH0rpAAmuFiTS2K5bVbwThqyQGj6fmlN/+LFz9W8ZPxYuuCia/XAf+5M=@vger.kernel.org X-Gm-Message-State: AOJu0YwGengJ3GJ5ZLzhaSCUklJLdSkO2C+4gHyP5GfxYbysd3AHKKjU I9tQZSNg32hL8YK3Ge0CgjqqyjIfuQHyt9WLskrD7LZ9rxKupmCh6phwpbjYzx0= X-Gm-Gg: ASbGncv9wgahsMlkeNrVkHHpIbLuTF4lQYQhAGFlQ3xD2vfzfrUGfaR4nuvIOW5BXVh l3EK0s+nv+HyWtNLwIuFvuFGiP2IK2Wd02CZTEuRGQo5tkv905OIqL51P03akeWH0zN4rx7BjVY ds2WiMSnZz7EAwHbgHJ99Bwc5HexLss6Wn3OnLCPNHN0Zk/9qNsFWNJ973QDQfm9RGIm733UmIk z4XRDWpk27Oa/5/YeSeQcDy5ru8m+I2lL00xpMgP8iWPvoWnD5xnIazbPnpzIc85yE= X-Google-Smtp-Source: AGHT+IEjUOoCAFXZRMy0I9gsQuvhr/I63Fh4EkcJ8plhvbLKJ7YnsQGNvkDK0foSGl9cEXw6e8AViQ== X-Received: by 2002:a17:907:3d8f:b0:aae:83c7:6ce7 with SMTP id a640c23a62f3a-ab28d07ba93mr230343166b.0.1736242891330; Tue, 07 Jan 2025 01:41:31 -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.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jan 2025 01:41:30 -0800 (PST) From: Linus Walleij Date: Tue, 07 Jan 2025 10:41:20 +0100 Subject: [PATCH RFC v3 04/30] ARM: process: Rewrite ret_from_fork i 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-4-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 Move the direct assembly call to schedule_tail() and the call starting a kernel thread into a C version of ret_from_fork() in process.c and rename the old ret_from_fork to ret_from_fork_asm following the pattern in x86. Leave a comment on what we will do when we get to switching to generic entry with this as a base. Signed-off-by: Linus Walleij --- arch/arm/include/asm/switch_to.h | 4 ++++ arch/arm/kernel/entry-common.S | 22 +++++++++++++++------- arch/arm/kernel/process.c | 24 ++++++++++++++++++++++-- 3 files changed, 41 insertions(+), 9 deletions(-) diff --git a/arch/arm/include/asm/switch_to.h b/arch/arm/include/asm/switch_to.h index 9372348516ce9b80fa713966943d0bc622e86066..18d084aff5a4faa7cc5e40d48fbc4aa97a89b0c6 100644 --- a/arch/arm/include/asm/switch_to.h +++ b/arch/arm/include/asm/switch_to.h @@ -17,6 +17,10 @@ #define __complete_pending_tlbi() #endif +asmlinkage void ret_from_fork_asm(void); +__visible void ret_from_fork(struct task_struct *prev, struct pt_regs *regs, + int (*fn)(void *), void *fn_arg); + /* * switch_to(prev, next) should switch from task `prev' to `next' * `prev' will never be the same as `next'. schedule() itself diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S index 2f93c2f6d5b8fdf6aaf3dda0192bde144fcf238d..df6961a1006b7a0f3522728812bf52ccb849e511 100644 --- a/arch/arm/kernel/entry-common.S +++ b/arch/arm/kernel/entry-common.S @@ -5,6 +5,7 @@ * Copyright (C) 2000 Russell King */ +#include #include #include #include @@ -128,15 +129,22 @@ ENDPROC(ret_to_user) /* * This is how we return from a fork. */ -ENTRY(ret_from_fork) - bl schedule_tail - cmp r5, #0 - movne r0, r4 - badrne lr, 1f - retne r5 +SYM_TYPED_FUNC_START(ret_from_fork_asm) + /* + * ret_from_fork() expects: + * r0: prev + * r1: regs + * r2: fn() for kernel process or NULL + * r3: fn_arg for kernel process or N/A + */ + mov r1, sp + mov r2, r5 + mov r3, r4 + bl ret_from_fork + mov r0, #0 1: get_thread_info tsk b ret_to_user -ENDPROC(ret_from_fork) +SYM_FUNC_END(ret_from_fork_asm) /*============================================================================= * SWI handler diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c index e16ed102960cb01d625e2ccc484f238b824b03b3..81c1c3f988344185917cf4e53d0d8ee47ae912f4 100644 --- a/arch/arm/kernel/process.c +++ b/arch/arm/kernel/process.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -230,7 +231,26 @@ void flush_thread(void) thread_notify(THREAD_NOTIFY_FLUSH, thread); } -asmlinkage void ret_from_fork(void) __asm__("ret_from_fork"); +/* The assembly stub sets up the parameters and calls ret_from_fork() */ +asmlinkage void ret_from_fork_asm(void) __asm__("ret_from_fork_asm"); + +__visible void ret_from_fork(struct task_struct *prev, struct pt_regs *regs, + int (*fn)(void *), void *fn_arg) +{ + schedule_tail(prev); + + /* Is this a kernel thread? */ + if (unlikely(fn)) { + fn(fn_arg); + /* + * A kernel thread is allowed to return here after successfully + * calling kernel_execve(). Exit to userspace to complete the + * execve() syscall. + */ + } + + /* syscall_exit_to_user_mode(regs); here once we switch to generic entry */ +} int copy_thread(struct task_struct *p, const struct kernel_clone_args *args) { @@ -263,7 +283,7 @@ int copy_thread(struct task_struct *p, const struct kernel_clone_args *args) thread->cpu_context.r5 = (unsigned long)args->fn; childregs->ARM_cpsr = SVC_MODE; } - thread->cpu_context.pc = (unsigned long)ret_from_fork; + thread->cpu_context.pc = (unsigned long)ret_from_fork_asm; thread->cpu_context.sp = (unsigned long)childregs; clear_ptrace_hw_breakpoint(p); -- 2.47.1