From patchwork Thu Oct 31 19:25:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 840220 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 24F001C9DD5; Thu, 31 Oct 2024 19:25:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730402741; cv=none; b=mxOLXbR9d5RbEu5y5EdVlWXKr8OdGlS1vWcbu0mhZtoOEP4gj7Pzu9vB2CgijfZ4ATMlTdxyXmTc7/BypoGYFZkgobOSUkWGjVzUqzDvJeShLOP1XBEu4PexTpVRop/kryO7oJtyq+0biWR28InPudZcPaL1dvlQ0r3+lvDP8SU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730402741; c=relaxed/simple; bh=3IHBZG41Ax5C8Y87eab6f2STvjmpFgx/xYVREZBq1zQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Qo/cSn8KfZY+4bz6kmbzcE5JsnzQEqkWQztEu2m38FNMWWaN0N/UYtaEav5YIO7rCn+MYsARb8Oqsn7WlQDY00dQsZP5jVfJw1HlI4MrzfouG7DO5mCKcfaDfEMIKRXTJQf3ouo/nN+pi2x2J2hiOykxgpyTYg7tfJfLHY7qYzs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=H/3sYoaB; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="H/3sYoaB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2892FC4CED2; Thu, 31 Oct 2024 19:25:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730402740; bh=3IHBZG41Ax5C8Y87eab6f2STvjmpFgx/xYVREZBq1zQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=H/3sYoaBo99EMQNcEhRZiINYVfTyVIQ9z9eH9mDQLPy8BYLpfxWXhOjB3d5lWtgZm lF5NHx25ZZJEzC5pcmAl7pSAAkr3MzYglhHS0M1Bu/4oARTjnWYuyP30hK1e8TM1N8 28IzLxgonzZAg8meitifnLFcr0aBHqXyCgj7qNrZZqUj1aP+Y72+bljbu/4hkfXlB+ Iab3+ntLTo4gaW+cqD0SuCMVHbymiGnjEDuTpWDedrL/yhby+92sVJF/rYCjVLAykI zxVTFyE5CRTj+7CakXvSSQBz79AFhtcW+PZWEFPFEePnvJ/nOdsGRqXAMe0diN+0UI cqJZu8VVOtQZA== From: Mark Brown Date: Thu, 31 Oct 2024 19:25:02 +0000 Subject: [PATCH RFT v12 1/8] arm64/gcs: Return a success value from gcs_alloc_thread_stack() Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241031-clone3-shadow-stack-v12-1-7183eb8bee17@kernel.org> References: <20241031-clone3-shadow-stack-v12-0-7183eb8bee17@kernel.org> In-Reply-To: <20241031-clone3-shadow-stack-v12-0-7183eb8bee17@kernel.org> To: "Rick P. Edgecombe" , Deepak Gupta , Szabolcs Nagy , "H.J. Lu" , Florian Weimer , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , Christian Brauner , Shuah Khan Cc: linux-kernel@vger.kernel.org, Catalin Marinas , Will Deacon , jannh@google.com, bsegall@google.com, Yury Khrustalev , Wilco Dijkstra , linux-kselftest@vger.kernel.org, linux-api@vger.kernel.org, Mark Brown , Kees Cook X-Mailer: b4 0.15-dev-9b746 X-Developer-Signature: v=1; a=openpgp-sha256; l=3875; i=broonie@kernel.org; h=from:subject:message-id; bh=3IHBZG41Ax5C8Y87eab6f2STvjmpFgx/xYVREZBq1zQ=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBnI9miqIix6BI2w5RzmaBqBK8lPiW5S1nCKem/ce4n qbbymqSJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZyPZogAKCRAk1otyXVSH0BkIB/ 4gRmT/yCoH85wQoYLe3z0NzyGc32DlrISXeWzun3PyobXdl9JdrGCM+Qk1fHPaqo8NZ/C2v9r4YhEP 8FIc08SIxMCNaGtSCyzXYbr1i/743AVFEjplKuXhq6VxSvqlFlkgVJ1+MZMlWiPYoIHua3dYZ1j1kR EHjJ+J+79J57Cu9elIjYTo5ygK+eNj0zCxrarwUhy7y9ldFmgJzfkZw8z5v7xynGz7FbGlbH7RnUfT Xj9+aRhmOi6XvV6NrFMiFHAwDvK0rkOLpVwFz5Kc3B6LVzLY1JYFLJH8uiQr0IHeh58WtDgkCwiagK juET9UYPYdxKqUvoJ/Sa2UmFgf8f9p X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB Currently as a result of templating from x86 code gcs_alloc_thread_stack() returns a pointer as an unsigned int however on arm64 we don't actually use this pointer value as anything other than a pass/fail flag. Simplify the interface to just return an int with 0 on success and a negative error code on failure. Acked-by: Deepak Gupta Signed-off-by: Mark Brown --- arch/arm64/include/asm/gcs.h | 8 ++++---- arch/arm64/kernel/process.c | 8 ++++---- arch/arm64/mm/gcs.c | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/arch/arm64/include/asm/gcs.h b/arch/arm64/include/asm/gcs.h index f50660603ecf5dc09a92740062df3a089b02b219..d8923b5f03b776252aca76ce316ef57399d71fa9 100644 --- a/arch/arm64/include/asm/gcs.h +++ b/arch/arm64/include/asm/gcs.h @@ -64,8 +64,8 @@ static inline bool task_gcs_el0_enabled(struct task_struct *task) void gcs_set_el0_mode(struct task_struct *task); void gcs_free(struct task_struct *task); void gcs_preserve_current_state(void); -unsigned long gcs_alloc_thread_stack(struct task_struct *tsk, - const struct kernel_clone_args *args); +int gcs_alloc_thread_stack(struct task_struct *tsk, + const struct kernel_clone_args *args); static inline int gcs_check_locked(struct task_struct *task, unsigned long new_val) @@ -91,8 +91,8 @@ static inline bool task_gcs_el0_enabled(struct task_struct *task) static inline void gcs_set_el0_mode(struct task_struct *task) { } static inline void gcs_free(struct task_struct *task) { } static inline void gcs_preserve_current_state(void) { } -static inline unsigned long gcs_alloc_thread_stack(struct task_struct *tsk, - const struct kernel_clone_args *args) +static inline int gcs_alloc_thread_stack(struct task_struct *tsk, + const struct kernel_clone_args *args) { return -ENOTSUPP; } diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c index fdd095480c3ffb8c13fd4e7c9abc79e88143e08b..8ebd11c29792524dfeeade9cc7826b007329aa6a 100644 --- a/arch/arm64/kernel/process.c +++ b/arch/arm64/kernel/process.c @@ -297,7 +297,7 @@ static void flush_gcs(void) static int copy_thread_gcs(struct task_struct *p, const struct kernel_clone_args *args) { - unsigned long gcs; + int ret; if (!system_supports_gcs()) return 0; @@ -305,9 +305,9 @@ static int copy_thread_gcs(struct task_struct *p, p->thread.gcs_base = 0; p->thread.gcs_size = 0; - gcs = gcs_alloc_thread_stack(p, args); - if (IS_ERR_VALUE(gcs)) - return PTR_ERR((void *)gcs); + ret = gcs_alloc_thread_stack(p, args); + if (ret != 0) + return ret; p->thread.gcs_el0_mode = current->thread.gcs_el0_mode; p->thread.gcs_el0_locked = current->thread.gcs_el0_locked; diff --git a/arch/arm64/mm/gcs.c b/arch/arm64/mm/gcs.c index 5c46ec527b1cdaa8f52cff445d70ba0f8509d086..1f633a482558b59aac5427963d42b37fce08c8a6 100644 --- a/arch/arm64/mm/gcs.c +++ b/arch/arm64/mm/gcs.c @@ -38,8 +38,8 @@ static unsigned long gcs_size(unsigned long size) return max(PAGE_SIZE, size); } -unsigned long gcs_alloc_thread_stack(struct task_struct *tsk, - const struct kernel_clone_args *args) +int gcs_alloc_thread_stack(struct task_struct *tsk, + const struct kernel_clone_args *args) { unsigned long addr, size; @@ -59,13 +59,13 @@ unsigned long gcs_alloc_thread_stack(struct task_struct *tsk, size = gcs_size(size); addr = alloc_gcs(0, size); if (IS_ERR_VALUE(addr)) - return addr; + return PTR_ERR((void *)addr); tsk->thread.gcs_base = addr; tsk->thread.gcs_size = size; tsk->thread.gcspr_el0 = addr + size - sizeof(u64); - return addr; + return 0; } SYSCALL_DEFINE3(map_shadow_stack, unsigned long, addr, unsigned long, size, unsigned int, flags)