From patchwork Fri Nov 24 16:35:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joey Gouly X-Patchwork-Id: 13467930 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 BE53AC61DF4 for ; Fri, 24 Nov 2023 16:36:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 295F96B02D3; Fri, 24 Nov 2023 11:36:02 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1F1636B02D8; Fri, 24 Nov 2023 11:36:02 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0921C6B02D9; Fri, 24 Nov 2023 11:36:02 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id E395B6B02D3 for ; Fri, 24 Nov 2023 11:36:01 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id BA76E80169 for ; Fri, 24 Nov 2023 16:36:01 +0000 (UTC) X-FDA: 81493399722.11.090C495 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf22.hostedemail.com (Postfix) with ESMTP id 0CF44C0024 for ; Fri, 24 Nov 2023 16:35:59 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf22.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1700843760; 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=qUaS7QEc6zdXjEuoo98xIG4PWjCZtryd+rezrEZdN8U=; b=Aw4bHfKgyGVKegn++9TuDyPrKusnEqoX3ierqlOwX5l4Dfm6cZoyked1Ao5SEvZmoTeRiI cPtG/PXAkf7HBAfdKJV2gajf4EZdVd9js9+cnJbDT8OuLsAIBfkpvN1eAmY2XHXBvrPBtF PYOzH/82UHme0QQTzD4V373csdrRidQ= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf22.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700843760; a=rsa-sha256; cv=none; b=3MGez2EX9ckrp4twoW2T3OJrlOU9gOUcZMumST0zai9uZNzH7dR+q7qLu1PXw485Wtdn7w saJMQC22kDHtLcqqN6HY7Ab2Bov/w6TrXmVSSkQvn2ls1QaB70GeAGkdrozWj8wtIcK9L7 MaVyKfL915aX1ME1wjpjbiEDrGZNdhI= 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 CCD391BF7; Fri, 24 Nov 2023 08:36:45 -0800 (PST) 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 28CEF3F73F; Fri, 24 Nov 2023 08:35:57 -0800 (PST) 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 v3 15/25] arm64: add POE signal support Date: Fri, 24 Nov 2023 16:35:00 +0000 Message-Id: <20231124163510.1835740-16-joey.gouly@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231124163510.1835740-1-joey.gouly@arm.com> References: <20231124163510.1835740-1-joey.gouly@arm.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: psj8pke6k35dne1gd7zphxkgz5igeui7 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 0CF44C0024 X-HE-Tag: 1700843759-921534 X-HE-Meta: U2FsdGVkX19cvqPFhJLOT82a8OJD/EsevLwzOlU1SZTfqtsmnYqUa09zjsx9jM4rApJ+AgSGz2fimJfvr36nOIUSI2503LhpuEmvcRT42u9lymoHUr4ziip6i66/32KGKBwgKNT3yBY+uDCaZj1k3xIDikThBCKBQyWF6jtKWjiEuzAC8fkDGf+Jv+XnxG8lZALdth/r5bLvscdrXwtAOXRNElbgpl4GfVwcwoD2Fhn2+K00EIvvQB05x1u5DpOk//SJLXoWItUuNHWEP0QXADKDYzrSdy+zIPaobBQX1Iq2jZdRZRwx2q4XV3dIpS9yh9ymuAWpv/8YBR6VjioYOWNM7PoHpB89a9sVlrj4Zm1gWUralxmPVvBGbDERp6TnfkJdJSM93pSSWYkk6qLEUH4u02pjkS4o8ta4XyMvVLRD6xSa4bKlKfiZ2Y645A9vZ1GFqF3Lqsv70sgiu2Xgk0f+bZEDFfoVu01g8OhHUuzFz1Zu4Ay5O7HCN5G9bGlhXcwG0A07cL/rgL2gfytKvOgCFMqWxqmBKIsPrTN/J3Ir26KNweteeqkGVaDxXyGQvfszsmD7P4PGNho3zOOkpWZ87XwN6b2bGuSJJfYKDe/yQXzzyBG62I93iQi0bkJqgRVYf5rc2IeRCIH8LcjO2c+iprhEOuTblGGMHnsQSPa5n5NH8n7rdk3zoRZ2LVWgm9kaHaNheRgrUKNvkia4uaPCzhzdljmPJOAPsE2APXD7nZkJJL7Y1zmLfnoPv22qTpMJcZjgWHEZxdeWe+qTp0cunU2sLZ6OBDjYZBqu76+ryK8zdJPvoqSyrRoVwGfogij9uIDH2JCTQVsDBRUCVTLitNp7MCiqti0ROYDqzTvdBHV6wnraoT6QmkzBGBe0KUA3I/FvyPagc+Giz5KpKnpoNvkjQZsOCr3aMufW7tcR/W4OUfLZw2nm344e+VJbcobnjPF/W27S+d8s6H9 +iKEOX4e AZBej0QHjBE/el02SLagfT7HVvV/rm84a/MmmHWn8qJZ3aQtBELhyg+m28AMG66FvC2BWZa+s4QYeP+HIwKrMW3IKt+vXWKx+WoaQFxyFycX5jyfNUJUxr4qEJm6eBL4kdcY6OS7W6QQ+L5tPgmuQkyn4pie/xdzwoyjLXN7ux6icEyE8rLZ0kyvJUaqLPYix2hewhuNyShszI2Iozv2rricfjA0bZr6iG8Ma 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 Acked-by: Szabolcs Nagy --- 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