From patchwork Thu Oct 26 12:44:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13437564 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5096DC25B6E for ; Thu, 26 Oct 2023 12:47:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345083AbjJZMrr (ORCPT ); Thu, 26 Oct 2023 08:47:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235108AbjJZMrb (ORCPT ); Thu, 26 Oct 2023 08:47:31 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6F4610E7; Thu, 26 Oct 2023 05:47:16 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7D89FC43395; Thu, 26 Oct 2023 12:47:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1698324436; bh=dWbKym9V/87gXqrTEOw7Gdze+KmteiyxYpdHGQXYWrg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=eLP82xOI+jsgEF6T9OjGdATQh0IsYAp1RZfl0g2ShRuTCJ304wEzfeOFAoEPJyXQv 7pVHzDt4dS7wamb+A9ptRGSAPS1QqRsoEfMWpuT0riYj/yyS7NNrE/69R5FSycqdXr 4eyKS9SvESRTC27UUYBBVAYLZ2BZNVQqYpQlVMlgBuIVxqKTXjPe8IHHiSirx1yktW japheYAkxvdb3N0zZIsUGqQrQ6rVAw2FVCgI/7+YP18/mup2OZwcQHDaNoGHh6EqCc joudoMKqaUb45t67pcqIdLZIOHOw90yk/Wf98+HkCKQl82Nhz0CJJJx/oVTGI+VTY8 1b1mCs4AZJ/cQ== From: Mark Brown Date: Thu, 26 Oct 2023 13:44:27 +0100 Subject: [PATCH 13/21] arm64/ptrace: Expose FPMR via ptrace MIME-Version: 1.0 Message-Id: <20231026-arm64-2023-dpisa-v1-13-8470dd989bb2@kernel.org> References: <20231026-arm64-2023-dpisa-v1-0-8470dd989bb2@kernel.org> In-Reply-To: <20231026-arm64-2023-dpisa-v1-0-8470dd989bb2@kernel.org> To: Catalin Marinas , Will Deacon , Marc Zyngier , Oliver Upton , James Morse , Suzuki K Poulose , Jonathan Corbet , Shuah Khan Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kvmarm@lists.linux.dev, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, Mark Brown X-Mailer: b4 0.13-dev-0438c X-Developer-Signature: v=1; a=openpgp-sha256; l=2850; i=broonie@kernel.org; h=from:subject:message-id; bh=dWbKym9V/87gXqrTEOw7Gdze+KmteiyxYpdHGQXYWrg=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBlOl+ekg/UMcni812l8Ig/UJoR0JEl6TkGXxfX0PmS bCIIHIaJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZTpfngAKCRAk1otyXVSH0AZ5B/ 0d/SQSBlLCWftYb2aRs9U0zGgeVFxx+EzKrW0G8CkaEXWZ9kueyv9nVGQ3l54FLgVkRzKrRHI+VYpH LINBRNt/MUZgyjU1AQbsa0aYU9BLUDf5DmCVC8RGiOMsow0dZaO1uEEbCV5+34ITf3aP9Mvlf7h2zW r4j9EcICg3fAuTqcO53k6wwiu/qtRoxpA3E1/odRccMAGDFrVTYUiom5igbJiItOHs+7DasI0tCdJX cnk+hjW4j/0QoaBYdgQp3GLqgx9Aj/1a/eS9inD8eFVKpZaTZmYPfeUQgfbY0dDXhpWy1X/h1EaAg0 DdkjbPR2AjdhvNbI1eFumhMUy/qWrR X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Add a new regset to expose FPMR via ptrace. It is not added to the FPSIMD registers since that structure is exposed elsewhere without any allowance for extension we don't add there. Signed-off-by: Mark Brown --- arch/arm64/kernel/ptrace.c | 42 ++++++++++++++++++++++++++++++++++++++++++ include/uapi/linux/elf.h | 1 + 2 files changed, 43 insertions(+) diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c index 20d7ef82de90..cfb8a4d213be 100644 --- a/arch/arm64/kernel/ptrace.c +++ b/arch/arm64/kernel/ptrace.c @@ -697,6 +697,39 @@ static int tls_set(struct task_struct *target, const struct user_regset *regset, return ret; } +static int fpmr_get(struct task_struct *target, const struct user_regset *regset, + struct membuf to) +{ + if (!system_supports_fpmr()) + return -EINVAL; + + if (target == current) + fpsimd_preserve_current_state(); + + return membuf_store(&to, target->thread.fpmr); +} + +static int fpmr_set(struct task_struct *target, const struct user_regset *regset, + unsigned int pos, unsigned int count, + const void *kbuf, const void __user *ubuf) +{ + int ret; + unsigned long fpmr; + + if (!system_supports_fpmr()) + return -EINVAL; + + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &fpmr, 0, count); + if (ret) + return ret; + + target->thread.fpmr = fpmr; + + fpsimd_flush_task_state(target); + + return 0; +} + static int system_call_get(struct task_struct *target, const struct user_regset *regset, struct membuf to) @@ -1417,6 +1450,7 @@ enum aarch64_regset { REGSET_HW_BREAK, REGSET_HW_WATCH, #endif + REGSET_FPMR, REGSET_SYSTEM_CALL, #ifdef CONFIG_ARM64_SVE REGSET_SVE, @@ -1495,6 +1529,14 @@ static const struct user_regset aarch64_regsets[] = { .regset_get = system_call_get, .set = system_call_set, }, + [REGSET_FPMR] = { + .core_note_type = NT_ARM_FPMR, + .n = 1, + .size = sizeof(u64), + .align = sizeof(u64), + .regset_get = fpmr_get, + .set = fpmr_set, + }, #ifdef CONFIG_ARM64_SVE [REGSET_SVE] = { /* Scalable Vector Extension */ .core_note_type = NT_ARM_SVE, diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h index 9b731976ce2f..4c8b4641a306 100644 --- a/include/uapi/linux/elf.h +++ b/include/uapi/linux/elf.h @@ -440,6 +440,7 @@ typedef struct elf64_shdr { #define NT_ARM_SSVE 0x40b /* ARM Streaming SVE registers */ #define NT_ARM_ZA 0x40c /* ARM SME ZA registers */ #define NT_ARM_ZT 0x40d /* ARM SME ZT registers */ +#define NT_ARM_FPMR 0x40e /* ARM floating point mode register */ #define NT_ARC_V2 0x600 /* ARCv2 accumulator/extra registers */ #define NT_VMCOREDD 0x700 /* Vmcore Device Dump Note */ #define NT_MIPS_DSP 0x800 /* MIPS DSP ASE registers */