From patchwork Fri Oct 27 18:08:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joey Gouly X-Patchwork-Id: 13438786 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 29092C25B70 for ; Fri, 27 Oct 2023 18:09:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B1BAF6B03E4; Fri, 27 Oct 2023 14:09:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AA4696B03E5; Fri, 27 Oct 2023 14:09:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8F7616B03E6; Fri, 27 Oct 2023 14:09:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 7F3376B03E4 for ; Fri, 27 Oct 2023 14:09:43 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 52981C0B9F for ; Fri, 27 Oct 2023 18:09:43 +0000 (UTC) X-FDA: 81392029446.01.350194D Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf23.hostedemail.com (Postfix) with ESMTP id 8F9CD140015 for ; Fri, 27 Oct 2023 18:09:41 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=none; spf=pass (imf23.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1698430181; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QC1L1IlR3Wi8Kk/yFW1B4UagYZhdSEhKtKMAranTGHE=; b=R97JDKR9xXmasq3VL7y6E1UMXGoIHLNaIAyJlyeEyrKtAt11kCzbIYMAgo8z6Eplw/uljh spPRRX4/XZmszk2s1OkxcqUq5rHYj9sG1HsiNKJ+yDUDZtdycRww+wp9ZyNYu4/KX6+qU+ 7ojwGOse73pX384QaFbbQre+oVuyAxM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1698430181; a=rsa-sha256; cv=none; b=snEzqgSfgpn5rIK1b11bY7dg9P1KSOcu44r8btbSK45ZUGj9Zc9P6LtVF0kgKyem2qjK+c xpEN0u2ulrZCBUBlUXS2uanPMlv8VLcIRT935gY5PnNG1Bsks4s+oUDmoeCutiLlY/x9fW eNWm2l7frY39/NI4I+9QYgkAuDE9NLU= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=none; spf=pass (imf23.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@arm.com; dmarc=pass (policy=none) header.from=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 795911424; Fri, 27 Oct 2023 11:10:22 -0700 (PDT) Received: from e124191.cambridge.arm.com (e124191.cambridge.arm.com [10.1.197.45]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id ABCE63F64C; Fri, 27 Oct 2023 11:09:38 -0700 (PDT) From: Joey Gouly To: linux-arm-kernel@lists.infradead.org Cc: akpm@linux-foundation.org, aneesh.kumar@linux.ibm.com, broonie@kernel.org, catalin.marinas@arm.com, dave.hansen@linux.intel.com, joey.gouly@arm.com, maz@kernel.org, oliver.upton@linux.dev, shuah@kernel.org, will@kernel.org, kvmarm@lists.linux.dev, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, James Morse , Suzuki K Poulose , Zenghui Yu Subject: [PATCH v2 15/24] arm64: add POE signal support Date: Fri, 27 Oct 2023 19:08:41 +0100 Message-Id: <20231027180850.1068089-16-joey.gouly@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231027180850.1068089-1-joey.gouly@arm.com> References: <20231027180850.1068089-1-joey.gouly@arm.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 8F9CD140015 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: k7dqhyn1my16r8k4fyzmcoombpp4gmsm X-HE-Tag: 1698430181-743628 X-HE-Meta: U2FsdGVkX18Gxy0AZO1f+oouA5jlgINGCpaEIC3oJdOPRytgRhaXhUFTij3+onu7R8Ba/A+P5ZVCQObb6kBPR2lCih5vQ0QUf9bpeuofU5bB/GRiTIdaOEapxevxCdNWOo5UD9zMSlRjTFHS8v62jdAaL09pEtKZwPwElafEDvDF67EoL3++9kHdi6AjmpVkxPoFsFiegOmtfJZV+kQkK0FiNAYEbus7EewLoxw/rbMLEFp2IOV46HfnGWY2Z9JzyKFogmnfeRt+yJkfcBtmC/2pB6bR76MoQPleDisEAufRWt3dFuQUw24Hzcz/Tj+HGkgHYwYrLoBTdu7DkeLDARa4LaJ6c+kxi6hqEBe8+G9DmV6gqDjcEL2p70rJyllmgxaPHUgAkVQIr7XM4O0gRTgjcKuUka8AuzMjKQVTiHrvpoGNGUBpgZKZQAcPWCBDfL6Uat2SKgx2qQ8XTAUaan70pfTRR8VyAZfRrahMxgr2thp3ArXGc9CYuyJScsvZl3KraRcf1l5tOvkeMDvnZ/L15JR/c6WBkbWL0zXnO3i4l5sNBpL6ipqUDPFgEkQJLLhM+e0B4MpQdyQH5S2G2fh3iFm+F2CxXG+8tIL7a9KcSH/NUIz1K4qt9uYhJKSbVmtcS0zwIUDjj4XEhu0VjxBc23z2tcdy6NquHv2e+OEMAGeMlBZnkUqu7dAMumNhFGUCdQ9loF32OsvchhCd4omEss9z56nLnuB5bBEoNczcv9R5E6r83rvR+rsk1HD9bHfLXTMjLoVGzwVCHm39JSkf3d4mZmkt08aGGt2iNCmHeZVEUw4I9xVlq3xads8NHd/vmivIzlZeW4yOS1Qnb0f/Cz6o/wqu2aEsBICn2MUf2ziUkICoZbBAenKBjJPdHiR79XATUcuQxnZNKtrd/pzOhx8OVCd5dpdjj+11JfMOUmRNSvAdTO+s45jLdMHLrOWqve1QRWBt/EArTof LpWQTrq+ iozqJUhSqkh0M0Sv3hXXSY4fZE9ui+VYgpWCq1aY7xyvdnTO3Yy2jKP1hRNgWj/lu5XL2DXa6gJhy3IjZcZgdLa2bXODGWpXORZtkCFVyp25bwHOePtU4queTslcQxyFdsJjP3ca0YzQoOrBnP1IOuXJSMlvA+XS0npZDKey8JNX4PbZmx3Oa5yineGbZWv6+f9DRfNQskwOlBTN01OUDLibN8A== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Add PKEY support to signals, by saving and restoring POR_EL0 from the stackframe. Signed-off-by: Joey Gouly Cc: Catalin Marinas Cc: Will Deacon Reviewed-by: Mark Brown --- arch/arm64/include/uapi/asm/sigcontext.h | 7 ++++ arch/arm64/kernel/signal.c | 51 ++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/arch/arm64/include/uapi/asm/sigcontext.h b/arch/arm64/include/uapi/asm/sigcontext.h index f23c1dc3f002..cef85eeaf541 100644 --- a/arch/arm64/include/uapi/asm/sigcontext.h +++ b/arch/arm64/include/uapi/asm/sigcontext.h @@ -98,6 +98,13 @@ struct esr_context { __u64 esr; }; +#define POE_MAGIC 0x504f4530 + +struct poe_context { + struct _aarch64_ctx head; + __u64 por_el0; +}; + /* * extra_context: describes extra space in the signal frame for * additional structures that don't fit in sigcontext.__reserved[]. diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c index 0e8beb3349ea..379f364005bf 100644 --- a/arch/arm64/kernel/signal.c +++ b/arch/arm64/kernel/signal.c @@ -62,6 +62,7 @@ struct rt_sigframe_user_layout { unsigned long zt_offset; unsigned long extra_offset; unsigned long end_offset; + unsigned long poe_offset; }; #define BASE_SIGFRAME_SIZE round_up(sizeof(struct rt_sigframe), 16) @@ -182,6 +183,8 @@ struct user_ctxs { u32 za_size; struct zt_context __user *zt; u32 zt_size; + struct poe_context __user *poe; + u32 poe_size; }; static int preserve_fpsimd_context(struct fpsimd_context __user *ctx) @@ -227,6 +230,20 @@ static int restore_fpsimd_context(struct user_ctxs *user) return err ? -EFAULT : 0; } +static int restore_poe_context(struct user_ctxs *user) +{ + u64 por_el0; + int err = 0; + + if (user->poe_size != sizeof(*user->poe)) + return -EINVAL; + + __get_user_error(por_el0, &(user->poe->por_el0), err); + if (!err) + write_sysreg_s(por_el0, SYS_POR_EL0); + + return err; +} #ifdef CONFIG_ARM64_SVE @@ -590,6 +607,7 @@ static int parse_user_sigframe(struct user_ctxs *user, user->tpidr2 = NULL; user->za = NULL; user->zt = NULL; + user->poe = NULL; if (!IS_ALIGNED((unsigned long)base, 16)) goto invalid; @@ -640,6 +658,17 @@ static int parse_user_sigframe(struct user_ctxs *user, /* ignore */ break; + case POE_MAGIC: + if (!system_supports_poe()) + goto invalid; + + if (user->poe) + goto invalid; + + user->poe = (struct poe_context __user *)head; + user->poe_size = size; + break; + case SVE_MAGIC: if (!system_supports_sve() && !system_supports_sme()) goto invalid; @@ -812,6 +841,9 @@ static int restore_sigframe(struct pt_regs *regs, if (err == 0 && system_supports_sme2() && user.zt) err = restore_zt_context(&user); + if (err == 0 && system_supports_poe() && user.poe) + err = restore_poe_context(&user); + return err; } @@ -928,6 +960,13 @@ static int setup_sigframe_layout(struct rt_sigframe_user_layout *user, } } + if (system_supports_poe()) { + err = sigframe_alloc(user, &user->poe_offset, + sizeof(struct poe_context)); + if (err) + return err; + } + return sigframe_alloc_end(user); } @@ -968,6 +1007,15 @@ static int setup_sigframe(struct rt_sigframe_user_layout *user, __put_user_error(current->thread.fault_code, &esr_ctx->esr, err); } + if (system_supports_poe() && err == 0 && user->poe_offset) { + struct poe_context __user *poe_ctx = + apply_user_offset(user, user->poe_offset); + + __put_user_error(POE_MAGIC, &poe_ctx->head.magic, err); + __put_user_error(sizeof(*poe_ctx), &poe_ctx->head.size, err); + __put_user_error(read_sysreg_s(SYS_POR_EL0), &poe_ctx->por_el0, err); + } + /* Scalable Vector Extension state (including streaming), if present */ if ((system_supports_sve() || system_supports_sme()) && err == 0 && user->sve_offset) { @@ -1119,6 +1167,9 @@ static void setup_return(struct pt_regs *regs, struct k_sigaction *ka, sme_smstop(); } + if (system_supports_poe()) + write_sysreg_s(POR_EL0_INIT, SYS_POR_EL0); + if (ka->sa.sa_flags & SA_RESTORER) sigtramp = ka->sa.sa_restorer; else