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 8ED46C433FE for ; Fri, 18 Nov 2022 16:24:18 +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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=yrBIpZinjNgTcDGPEDJdsS/px6r/YnQu2+CZKe5OnaE=; b=sE8upXaef7FTlf iGVRG5tvAYXtYzcTujID7fo1Ok45QpghAuX/9UbT6b0Bxjs1h8rwVctj5OeT4l24f18VxhpgqmoGa SeJRPGith46WvLYC3pX6AsG0V6tK9QQCsGugWUEGaEJGCsKXaYGHC92UdzzcjMukOfIfdNaoorUJa /AaYbPMXO99dWJHgb+t3LsZlGxu/B26R19RiQyuEHGO4cC6kxHIHcYe/eXAuVbvZLuVaWMdHrtL2D 3ugYdKFE1LI2nRlGrBKulDQmGslS2comc1jFxStP2H8wLxGKufQ3HfuV+1MdHW+i4u8TPyBwqWlNL cEijEXrhaehoV0jv769A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ow498-005GdS-5F; Fri, 18 Nov 2022 16:23:18 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ow48T-005GLC-Pe for linux-arm-kernel@lists.infradead.org; Fri, 18 Nov 2022 16:22:39 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 5C9966262C; Fri, 18 Nov 2022 16:22:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B6FDEC433D6; Fri, 18 Nov 2022 16:22:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668788556; bh=Wmv2LEhVgEZvOis0aMLF1tTysQJvE+cQ+HObHEooYGY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lxwlzgQGQqjOFce/Tx3USJUzhaM6ZiJYBhplVFVBc+E3Ygio7KP1qYXxLeJjVzRQZ vHVANCnRehWxGgwSrmixm/QZhXhW161XMfI/rmx9sCdYnb7mRVrvBhlgmArqqxLi7g 1dtW+s34ytHL5Zy0RkrN9PQcnNsxVp7Zq3LGsvx9NtUUzfBK+i7VBnMca7PjHZuAPe C8ZyRm4ofYv610dM3LtYy8gUhyevQSLuKLI6ZqOhldaBMhSVsPL+zMLaqfR7QcpoEW Gltdt+WW+tG6DMH8SPWkmZ6+jNv8x/gRuMMj3OIP6guCODuU6MdkDcJAAjMcb5sLrr aoun5RTmGuvfg== From: Mark Brown To: Catalin Marinas , Will Deacon , Shuah Khan , Shuah Khan Cc: Szabolcs Nagy , linux-arm-kernel@lists.infradead.org, Mark Brown Subject: [PATCH v3 3/5] arm64/signal: Include TPIDR2 in the signal context Date: Fri, 18 Nov 2022 16:22:22 +0000 Message-Id: <20221118162224.1068916-4-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221118162224.1068916-1-broonie@kernel.org> References: <20221118162224.1068916-1-broonie@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4981; i=broonie@kernel.org; h=from:subject; bh=Wmv2LEhVgEZvOis0aMLF1tTysQJvE+cQ+HObHEooYGY=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBjd7E9XYso9ZeTraKo8VqRKrxEHFtgG0I47fhz/mqm nhTsOy+JATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCY3exPQAKCRAk1otyXVSH0HIUB/ 9oI5Ko7Keb7HOqh6/pS3I9XVcwP65a9HjbihjLoliwm8b/0mK2aCBJt12V2DdKEMWWoRR2PM0up5Vh B+DlMsmcFJrg7a9Xg9bFmOlfCMOxTMYSVhr0sbrGhiTlwSNBvbKGQF/IXWGVBF4MfMtU70d2Ru7dAV G/PFMmc1J3yDFNnecYEwaw0R5vHL/bMOFTUBzlQfrvEchYPK59FtvfdvZwbU0LzBLwIE8A8s9OKRtL XCFrdFM2UUAFW5O8jD5HaTgwNlns+jEG2DczBKXs977AaZxKzQZTKg+EqP0rTc40i29Zni3q0+mkcM nN91dJmdyYL/9dUL7PC7SWL4OXauSU 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-20221118_082237_948880_9807AD70 X-CRM114-Status: GOOD ( 19.98 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add a new signal frame record for TPIDR2 using the same format as we already use for ESR with different magic, a header with the value from the register appended as the only data. If SME is supported then this record is always included. Signed-off-by: Mark Brown Reviewed-by: Szabolcs Nagy --- arch/arm64/include/uapi/asm/sigcontext.h | 8 ++++ arch/arm64/kernel/signal.c | 61 ++++++++++++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/arch/arm64/include/uapi/asm/sigcontext.h b/arch/arm64/include/uapi/asm/sigcontext.h index 4aaf31e3bf16..46ce097ca8c0 100644 --- a/arch/arm64/include/uapi/asm/sigcontext.h +++ b/arch/arm64/include/uapi/asm/sigcontext.h @@ -140,6 +140,14 @@ struct sve_context { #define SVE_SIG_FLAG_SM 0x1 /* Context describes streaming mode */ +/* TPIDR2_EL0 context */ +#define TPIDR2_MAGIC 0x54504902 + +struct tpidr2_context { + struct _aarch64_ctx head; + __u64 tpidr2; +}; + #define ZA_MAGIC 0x54366345 struct za_context { diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c index 9ad911f1647c..a04b1a85c5bf 100644 --- a/arch/arm64/kernel/signal.c +++ b/arch/arm64/kernel/signal.c @@ -56,6 +56,7 @@ struct rt_sigframe_user_layout { unsigned long fpsimd_offset; unsigned long esr_offset; unsigned long sve_offset; + unsigned long tpidr2_offset; unsigned long za_offset; unsigned long extra_offset; unsigned long end_offset; @@ -219,6 +220,7 @@ static int restore_fpsimd_context(struct fpsimd_context __user *ctx) struct user_ctxs { struct fpsimd_context __user *fpsimd; struct sve_context __user *sve; + struct tpidr2_context __user *tpidr2; struct za_context __user *za; }; @@ -358,6 +360,34 @@ extern int preserve_sve_context(void __user *ctx); #ifdef CONFIG_ARM64_SME +static int preserve_tpidr2_context(struct tpidr2_context __user *ctx) +{ + int err = 0; + + tls_preserve_current_state(); + + __put_user_error(TPIDR2_MAGIC, &ctx->head.magic, err); + __put_user_error(sizeof(*ctx), &ctx->head.size, err); + __put_user_error(current->thread.tpidr2_el0, &ctx->tpidr2, err); + + return err; +} + +static int restore_tpidr2_context(struct user_ctxs *user) +{ + u64 tpidr2_el0; + int err = 0; + + /* Magic and size were validated before calling this function */ + __get_user_error(tpidr2_el0, &user->tpidr2->tpidr2, err); + if (!err) { + current->thread.tpidr2_el0 = tpidr2_el0; + write_sysreg_s(current->thread.tpidr2_el0, SYS_TPIDR2_EL0); + } + + return err; +} + static int preserve_za_context(struct za_context __user *ctx) { int err = 0; @@ -447,6 +477,8 @@ static int restore_za_context(struct user_ctxs *user) #else /* ! CONFIG_ARM64_SME */ /* Turn any non-optimised out attempts to use these into a link error: */ +extern int preserve_tpidr2_context(void __user *ctx); +extern int restore_tpidr2_context(struct user_ctxs *user); extern int preserve_za_context(void __user *ctx); extern int restore_za_context(struct user_ctxs *user); @@ -465,6 +497,7 @@ static int parse_user_sigframe(struct user_ctxs *user, user->fpsimd = NULL; user->sve = NULL; + user->tpidr2 = NULL; user->za = NULL; if (!IS_ALIGNED((unsigned long)base, 16)) @@ -531,6 +564,19 @@ static int parse_user_sigframe(struct user_ctxs *user, user->sve = (struct sve_context __user *)head; break; + case TPIDR2_MAGIC: + if (!system_supports_tpidr2()) + goto invalid; + + if (user->tpidr2) + goto invalid; + + if (size != sizeof(*user->tpidr2)) + goto invalid; + + user->tpidr2 = (struct tpidr2_context __user *)head; + break; + case ZA_MAGIC: if (!system_supports_sme()) goto invalid; @@ -663,6 +709,9 @@ static int restore_sigframe(struct pt_regs *regs, err = restore_fpsimd_context(user.fpsimd); } + if (err == 0 && system_supports_tpidr2() && user.tpidr2) + err = restore_tpidr2_context(&user); + if (err == 0 && system_supports_sme() && user.za) err = restore_za_context(&user); @@ -757,6 +806,11 @@ static int setup_sigframe_layout(struct rt_sigframe_user_layout *user, else vl = task_get_sme_vl(current); + err = sigframe_alloc(user, &user->tpidr2_offset, + sizeof(struct tpidr2_context)); + if (err) + return err; + if (thread_za_enabled(¤t->thread)) vq = sve_vq_from_vl(vl); @@ -814,6 +868,13 @@ static int setup_sigframe(struct rt_sigframe_user_layout *user, err |= preserve_sve_context(sve_ctx); } + /* TPIDR2 if supported */ + if (system_supports_tpidr2() && err == 0) { + struct tpidr2_context __user *tpidr2_ctx = + apply_user_offset(user, user->tpidr2_offset); + err |= preserve_tpidr2_context(tpidr2_ctx); + } + /* ZA state if present */ if (system_supports_sme() && err == 0 && user->za_offset) { struct za_context __user *za_ctx = -- 2.30.2 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel