From patchwork Wed Mar 6 23:14:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13584759 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 9FD37C54E41 for ; Wed, 6 Mar 2024 23:16:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :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=vWEEgMcu91d7rysGdHHjbmXIh9Vy4Ke1sm+pr1LE6Sk=; b=IIAn7naJO8cY0P /QuMGxw0wEoi1wgeTAHm9xsJzRZww7oxJtT3cFItSfONnDNlJX5D+dcTaBiuIDo0yw8cU3R6xI1ZI +qpNlbnDgOvigbDl7yvCpvoAoNgNSLXSkEK/0qjG/wkPAY38wUQFWPiZ/D8V4tciKD4MrClrmQdD1 R+jKsbKJtTxkRERcFrYOut+bJ4NwGL2uDPhR3Kfpo9/Wo5gSLGr1OIC99ZNRH3hIdU3DTFrTx3Kp1 dyQJppnYJeBriUe7/EF0AdVreULohEjmoBhg1dzH+/g2D+6zxjFgIZqXHtm43Ztt8ieI7IBQCeUFa vYXryOgoHVX/ClFqusnw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1ri0UN-00000002CBA-1KAS; Wed, 06 Mar 2024 23:15:55 +0000 Received: from sin.source.kernel.org ([145.40.73.55]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1ri0UA-00000002Byo-0Hm8 for linux-arm-kernel@lists.infradead.org; Wed, 06 Mar 2024 23:15:45 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 3D4C2CE223F; Wed, 6 Mar 2024 23:15:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BF92FC433C7; Wed, 6 Mar 2024 23:15:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709766939; bh=+3OJGPcA4gocLlF8dxkHh0A2qtaF5oUm15PD13fHwu4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=EArEt74olpI6KRT5KcicLl481sZiXKM6wufTOfVETy7pvg3ILClm6vIcXZcp55gHL 2CzEBBYGYo2sHPWOd9RG1nT/BzWw0JT44PSQPGgrbNT9u/o8gZ3WxbTHuMI5ZcXkhS O+OWB0SdSD6gJYZnEciIkgfWZW8CJyd3Tq55So+gPt1PWP3eudNbiP58e6R4P+sG/z UTnb2atq9Uh2JVlWnt12X1jNbMoClp/KlD638N5zcE7DVWabbISrvGDaPLYSDui+A6 yWKCr3x2MOOopeuvmegEY2jIXe29NJCKT6sga6I4bQ4XALR0FZHAJ725A1OuRp2k3w IvpaK7nnqUdMA== From: Mark Brown Date: Wed, 06 Mar 2024 23:14:50 +0000 Subject: [PATCH v5 5/9] arm64/ptrace: Expose FPMR via ptrace MIME-Version: 1.0 Message-Id: <20240306-arm64-2023-dpisa-v5-5-c568edc8ed7f@kernel.org> References: <20240306-arm64-2023-dpisa-v5-0-c568edc8ed7f@kernel.org> In-Reply-To: <20240306-arm64-2023-dpisa-v5-0-c568edc8ed7f@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, Dave Martin , kvmarm@lists.linux.dev, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, Mark Brown X-Mailer: b4 0.13-dev-a684c X-Developer-Signature: v=1; a=openpgp-sha256; l=2856; i=broonie@kernel.org; h=from:subject:message-id; bh=+3OJGPcA4gocLlF8dxkHh0A2qtaF5oUm15PD13fHwu4=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBl6PkElRcXs+yiabpULUsTdQJagvaDXtIMEnxgYOr0 euD6GdOJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZej5BAAKCRAk1otyXVSH0AsGB/ 9Bg13kv/TAR3bL527teaV3G28XZwQ3JQers7/RqVeUIYIjeQJWryi8Q7ES+GfAgGPd2kMb36QgE9ng p5eH5aN4VHw/fBMB6gz1yRx4JeqhIlyyH7e49VeQLIdhMz8HXge4w8K9juaJH1x0YIycF2KdwbvFVd B8+fw1NJPnUgIFNSb6bis/LKUIWE+/XH7z+1Wne7862MhzMhD0SkFKK+fUowQNLsOY6b5eefIpc4J4 esqA9OxiqDYbETLWnL6XEe2V76eUMH4eoGln1pEPcwM7ICZ95/om+XzWpE8+hr1E+cFkEPvhe40yYp GjdlOIMOhTyq31TsI0Xjm0NaOqQ3es X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240306_151542_567658_BC8EA8AA X-CRM114-Status: GOOD ( 14.25 ) 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 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 dc6cf0e37194..aacb45bd36e6 100644 --- a/arch/arm64/kernel/ptrace.c +++ b/arch/arm64/kernel/ptrace.c @@ -698,6 +698,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.uw.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.uw.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) @@ -1419,6 +1452,7 @@ enum aarch64_regset { REGSET_HW_BREAK, REGSET_HW_WATCH, #endif + REGSET_FPMR, REGSET_SYSTEM_CALL, #ifdef CONFIG_ARM64_SVE REGSET_SVE, @@ -1497,6 +1531,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 9417309b7230..b54b313bcf07 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 */