From nobody Wed Jun 17 01:42:35 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 831103D47B8; Tue, 21 Apr 2026 14:43:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776782601; cv=none; b=FcTiPRZar4WjCAuTGdzY1U6lPduOk6wF5ZOxVQqAWOpCb3AYyeMG0LxSp6qMRY1sO/Zr9obh7DE76T447uKJaqyXzRaQs0vc5K9QhCWfpgjZC+Upa9csMqPPLKsbeYEdzPXnjBNNMs2324KpYKc7SscHgc98J4z/NKIuw95lr3o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776782601; c=relaxed/simple; bh=MxsGc+EBx86vViVnJi5hkAtx/3njsI58R9adW1EOEhM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TJLXVlPs+kT0M/QqWVnEzeGF5sB8qzWFvQjGWRTHpINjTvOlfu+Om/vacxSiScrHCHVAkL1aKyWdrDlCBv/8FliV7avcljMgcjRo7ghNB97jbIPN1N811FXSX15qfVTkgyIaahZVGMrW3VT5oyAZfz0OQNTobpfaOvFT26e915U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=FwSQrg72; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="FwSQrg72" 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 5AC53302C; Tue, 21 Apr 2026 07:43:13 -0700 (PDT) Received: from e123572-lin.arm.com (e123572-lin.cambridge.arm.com [10.1.194.54]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8AE743FAF5; Tue, 21 Apr 2026 07:43:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1776782598; bh=MxsGc+EBx86vViVnJi5hkAtx/3njsI58R9adW1EOEhM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FwSQrg72snbYiBgDHmR8iZL9vVLCGskUN9cWjinaurZnVDh0UizatL9rkSSH27eV8 yih9/Yypu4gmi6fXvdG3q75fJfAGZf1njQ+YQ/IT7k4I9bVTl8KuQwjpIMiUltfAaQ gOD2ycw3G9mTXWspT0VKRXLH0VvN53JrI17rOPP8= From: Kevin Brodsky To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Kevin Brodsky , Catalin Marinas , Joey Gouly , Mark Brown , Shuah Khan , Will Deacon , linux-kselftest@vger.kernel.org Subject: [PATCH 1/4] arm64: signal: Preserve POR_EL0 if poe_context is missing Date: Tue, 21 Apr 2026 15:42:49 +0100 Message-ID: <20260421144252.1440365-2-kevin.brodsky@arm.com> X-Mailer: git-send-email 2.51.2 In-Reply-To: <20260421144252.1440365-1-kevin.brodsky@arm.com> References: <20260421144252.1440365-1-kevin.brodsky@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Commit 2e8a1acea859 ("arm64: signal: Improve POR_EL0 handling to avoid uaccess failures") delayed the write to POR_EL0 in rt_sigreturn to avoid spurious uaccess failures. This change however relies on the poe_context frame record being present: on a system supporting POE, calling sigreturn without a poe_context record now results in writing arbitrary data from the kernel stack into POR_EL0. Fix this by adding a valid_fields member to struct user_access_state, and zeroing the struct on allocation. restore_poe_context() then indicates that the por_el0 field is valid by setting the corresponding bit in valid_fields, and restore_user_access_state() only touches POR_EL0 if there is a valid value to set it to. This is in line with how POR_EL0 was originally handled; all frame records are currently optional, except fpsimd_context. restore_user_access_state() is also called if setting up the signal frame fails, so we also initialise valid_fields in that case. For consistency, setup_sigframe() now also checks valid_fields to decide whether to write a poe_context record, avoiding another call to system_supports_poe(). Fixes: 2e8a1acea859 ("arm64: signal: Improve POR_EL0 handling to avoid uacc= ess failures") Reported-by: Will Deacon Signed-off-by: Kevin Brodsky --- arch/arm64/kernel/signal.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c index 08ffc5a5aea4..3f17aed5b4f0 100644 --- a/arch/arm64/kernel/signal.c +++ b/arch/arm64/kernel/signal.c @@ -67,6 +67,8 @@ struct rt_sigframe_user_layout { unsigned long end_offset; }; =20 +#define UA_STATE_HAS_POR_EL0 BIT(0) + /* * Holds any EL0-controlled state that influences unprivileged memory acce= sses. * This includes both accesses done in userspace and uaccess done in the k= ernel. @@ -74,8 +76,12 @@ struct rt_sigframe_user_layout { * This state needs to be carefully managed to ensure that it doesn't cause * uaccess to fail when setting up the signal frame, and the signal handler * itself also expects a well-defined state when entered. + * + * The valid_fields member is a bitfield (see UA_STATE_HAS_*), specifying = which + * of the remaining fields is valid (has been set to a value). */ struct user_access_state { + unsigned int valid_fields; u64 por_el0; }; =20 @@ -95,6 +101,7 @@ static void save_reset_user_access_state(struct user_acc= ess_state *ua_state) por_enable_all |=3D POR_ELx_PERM_PREP(pkey, POE_RWX); =20 ua_state->por_el0 =3D read_sysreg_s(SYS_POR_EL0); + ua_state->valid_fields |=3D UA_STATE_HAS_POR_EL0; write_sysreg_s(por_enable_all, SYS_POR_EL0); /* * No ISB required as we can tolerate spurious Overlay faults - @@ -122,7 +129,7 @@ static void set_handler_user_access_state(void) */ static void restore_user_access_state(const struct user_access_state *ua_s= tate) { - if (system_supports_poe()) + if (ua_state->valid_fields & UA_STATE_HAS_POR_EL0) write_sysreg_s(ua_state->por_el0, SYS_POR_EL0); } =20 @@ -352,8 +359,10 @@ static int restore_poe_context(struct user_ctxs *user, return -EINVAL; =20 __get_user_error(por_el0, &(user->poe->por_el0), err); - if (!err) + if (!err) { ua_state->por_el0 =3D por_el0; + ua_state->valid_fields |=3D UA_STATE_HAS_POR_EL0; + } =20 return err; } @@ -1095,7 +1104,7 @@ SYSCALL_DEFINE0(rt_sigreturn) { struct pt_regs *regs =3D current_pt_regs(); struct rt_sigframe __user *frame; - struct user_access_state ua_state; + struct user_access_state ua_state =3D {0}; =20 /* Always make any pending restarted system calls return -EINTR */ current->restart_block.fn =3D do_no_restart_syscall; @@ -1302,7 +1311,7 @@ static int setup_sigframe(struct rt_sigframe_user_lay= out *user, err |=3D preserve_fpmr_context(fpmr_ctx); } =20 - if (system_supports_poe() && err =3D=3D 0) { + if ((ua_state->valid_fields & UA_STATE_HAS_POR_EL0) && err =3D=3D 0) { struct poe_context __user *poe_ctx =3D apply_user_offset(user, user->poe_offset); =20 @@ -1507,7 +1516,7 @@ static int setup_rt_frame(int usig, struct ksignal *k= sig, sigset_t *set, { struct rt_sigframe_user_layout user; struct rt_sigframe __user *frame; - struct user_access_state ua_state; + struct user_access_state ua_state =3D {0}; int err =3D 0; =20 fpsimd_save_and_flush_current_state(); --=20 2.51.2 From nobody Wed Jun 17 01:42:35 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3A7873D9023; Tue, 21 Apr 2026 14:43:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776782602; cv=none; b=onJlQYolojdpbPXsGQArJTWFzVs6yOUW4W4bkZVYzogHUQ+WPpK9jKdOkAm2oUzPA44T5U3mGrWLCrHZPJmsunpTuAr8cI2PBO02D1VF6PhBcZWRgii4yGvx2CgVDm3O/Oa4b3ECNI1QJte7+/eYYvXx0ziFNBtz74IvEIWAitw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776782602; c=relaxed/simple; bh=99NNtnuLxi2s8quGtXHfvn6Pw2cy8v6tt353X7vUA+c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SQI7naa3Kz1u4WqGVZ7xmD+Ym06PpJQwEXDZjdfVyyREtCbb+rcgXzhW8G+5JE5Jp2gTTZ11BYA5ceKItAeu7WWWYv09lg7P0wM8o1EuWfXWMH5u66NW+bgbN6euMEwlR1RmwoB6cvNhdh+RylEmNUle84LmMPDIflotSY4J76Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=Ig8P47/V; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="Ig8P47/V" 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 14740302D; Tue, 21 Apr 2026 07:43:15 -0700 (PDT) Received: from e123572-lin.arm.com (e123572-lin.cambridge.arm.com [10.1.194.54]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3F2543FAF5; Tue, 21 Apr 2026 07:43:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1776782600; bh=99NNtnuLxi2s8quGtXHfvn6Pw2cy8v6tt353X7vUA+c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ig8P47/VPrUc6cbbK0AOOhF1x2CHw/ZnSTD6dKK4E0oK6LFtGMBmT6xWeQtqr+lM2 mzY7JY+XKA5hupSoLRUGoUDCibnxhVNuzniRs0blD2R2JRT9yo8tnI5XbEkb4oGKlY td3grQ0QQNuq4SjWG30c8HYBhc++7h25IWztbqs4= From: Kevin Brodsky To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Kevin Brodsky , Catalin Marinas , Joey Gouly , Mark Brown , Shuah Khan , Will Deacon , linux-kselftest@vger.kernel.org Subject: [PATCH 2/4] kselftest/arm64: Add POE as a feature in the signal tests Date: Tue, 21 Apr 2026 15:42:50 +0100 Message-ID: <20260421144252.1440365-3-kevin.brodsky@arm.com> X-Mailer: git-send-email 2.51.2 In-Reply-To: <20260421144252.1440365-1-kevin.brodsky@arm.com> References: <20260421144252.1440365-1-kevin.brodsky@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add the POE feature to the signal tests framework, to allow tests to require it. Signed-off-by: Kevin Brodsky Reviewed-by: Mark Brown --- tools/testing/selftests/arm64/signal/test_signals.h | 2 ++ tools/testing/selftests/arm64/signal/test_signals_utils.c | 3 +++ 2 files changed, 5 insertions(+) diff --git a/tools/testing/selftests/arm64/signal/test_signals.h b/tools/te= sting/selftests/arm64/signal/test_signals.h index ee75a2c25ce7..c7c343494cb8 100644 --- a/tools/testing/selftests/arm64/signal/test_signals.h +++ b/tools/testing/selftests/arm64/signal/test_signals.h @@ -36,6 +36,7 @@ enum { FSME_FA64_BIT, FSME2_BIT, FGCS_BIT, + FPOE_BIT, FMAX_END }; =20 @@ -45,6 +46,7 @@ enum { #define FEAT_SME_FA64 (1UL << FSME_FA64_BIT) #define FEAT_SME2 (1UL << FSME2_BIT) #define FEAT_GCS (1UL << FGCS_BIT) +#define FEAT_POE (1UL << FPOE_BIT) =20 /* * A descriptor used to describe and configure a test case. diff --git a/tools/testing/selftests/arm64/signal/test_signals_utils.c b/to= ols/testing/selftests/arm64/signal/test_signals_utils.c index 5d3621921cfe..4b12dbd7669d 100644 --- a/tools/testing/selftests/arm64/signal/test_signals_utils.c +++ b/tools/testing/selftests/arm64/signal/test_signals_utils.c @@ -31,6 +31,7 @@ static char const *const feats_names[FMAX_END] =3D { " FA64 ", " SME2 ", " GCS ", + " POE ", }; =20 #define MAX_FEATS_SZ 128 @@ -341,6 +342,8 @@ int test_init(struct tdescr *td) td->feats_supported |=3D FEAT_SME2; if (getauxval(AT_HWCAP) & HWCAP_GCS) td->feats_supported |=3D FEAT_GCS; + if (getauxval(AT_HWCAP2) & HWCAP2_POE) + td->feats_supported |=3D FEAT_POE; if (feats_ok(td)) { if (td->feats_required & td->feats_supported) fprintf(stderr, --=20 2.51.2 From nobody Wed Jun 17 01:42:35 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B0DB63D902B; Tue, 21 Apr 2026 14:43:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776782604; cv=none; b=gvo9m/9USRO0CypYEB2Mw/SpO5yEuIbMIMSk0MboWaq4RcvJu9h0H1pv8yeOrIg///PfcVdQv7TXvWyGFTNyIfLxdLFIiu1C1F24qvOHzhJex6Ra3NQNEDCvcIhejqCI2yBeNqAGJ3ANZfDcGL+XL8lzu2lEsqqqXuBxf0CMWD8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776782604; c=relaxed/simple; bh=p9bdjlhoG2EqguOOpOu5ObgF3kpj690/lD2+dGUSX94=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gRoQs+Pom51UTTEH07KJeLZgSZ+QA9ofrDndwh7AEx/iVXrjtSRQVGkeTQZZj3Mxo8EQhcNhb0OPf+GP6Tubbsfw9aWGRcj+9vogIiUEr/dT+JzSgU1VvoI3Yu7Z9dxBjx49FwEMjU49d3mTMyTFkEV5dfktQJ173kb/jEopAZ4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=TiIV33xk; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="TiIV33xk" 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 B9A4625DE; Tue, 21 Apr 2026 07:43:16 -0700 (PDT) Received: from e123572-lin.arm.com (e123572-lin.cambridge.arm.com [10.1.194.54]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E88403FAF5; Tue, 21 Apr 2026 07:43:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1776782602; bh=p9bdjlhoG2EqguOOpOu5ObgF3kpj690/lD2+dGUSX94=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TiIV33xkcYjsI3igqSQxQsbZpSAYHDVc87sh2ssX9mBR5iX8ekC58P+/1IlzbVhlZ R4Ry7oJKdhRqFNqJ2EICuy3g96fZVsOoIfTt2VY6Va4jc7NgitwPL7Jb4Cwv7WBpHP C6kws5bOwd6tovUY5A3PnaOVNDy5dSw69cTzSInI= From: Kevin Brodsky To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Kevin Brodsky , Catalin Marinas , Joey Gouly , Mark Brown , Shuah Khan , Will Deacon , linux-kselftest@vger.kernel.org Subject: [PATCH 3/4] kselftest/arm64: Add POE helpers to test_signals_utils.h Date: Tue, 21 Apr 2026 15:42:51 +0100 Message-ID: <20260421144252.1440365-4-kevin.brodsky@arm.com> X-Mailer: git-send-email 2.51.2 In-Reply-To: <20260421144252.1440365-1-kevin.brodsky@arm.com> References: <20260421144252.1440365-1-kevin.brodsky@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In preparation to adding further POE signal tests, move get_por_el0() to test_signals_utils.h and add set_por_el0(). Signed-off-by: Kevin Brodsky Reviewed-by: Mark Brown --- .../selftests/arm64/signal/test_signals_utils.h | 16 ++++++++++++++++ .../arm64/signal/testcases/poe_siginfo.c | 15 --------------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/tools/testing/selftests/arm64/signal/test_signals_utils.h b/to= ols/testing/selftests/arm64/signal/test_signals_utils.h index 36fc12b3cd60..2c7b8c64a35a 100644 --- a/tools/testing/selftests/arm64/signal/test_signals_utils.h +++ b/tools/testing/selftests/arm64/signal/test_signals_utils.h @@ -57,6 +57,22 @@ static inline __attribute__((always_inline)) uint64_t ge= t_gcspr_el0(void) return val; } =20 +#define SYS_POR_EL0 "S3_3_C10_C2_4" + +static inline uint64_t get_por_el0(void) +{ + uint64_t val; + + asm volatile("mrs %0, " SYS_POR_EL0 "\n" : "=3Dr"(val)); + + return val; +} + +static inline void set_por_el0(uint64_t val) +{ + asm volatile("msr " SYS_POR_EL0 ", %0\n" :: "r"(val)); +} + static inline bool feats_ok(struct tdescr *td) { if (td->feats_incompatible & td->feats_supported) diff --git a/tools/testing/selftests/arm64/signal/testcases/poe_siginfo.c b= /tools/testing/selftests/arm64/signal/testcases/poe_siginfo.c index 36bd9940ee05..e15fedf4da6e 100644 --- a/tools/testing/selftests/arm64/signal/testcases/poe_siginfo.c +++ b/tools/testing/selftests/arm64/signal/testcases/poe_siginfo.c @@ -21,21 +21,6 @@ static union { char buf[1024 * 128]; } context; =20 -#define SYS_POR_EL0 "S3_3_C10_C2_4" - -static uint64_t get_por_el0(void) -{ - uint64_t val; - - asm volatile( - "mrs %0, " SYS_POR_EL0 "\n" - : "=3Dr"(val) - : - : ); - - return val; -} - int poe_present(struct tdescr *td, siginfo_t *si, ucontext_t *uc) { struct _aarch64_ctx *head =3D GET_BUF_RESV_HEAD(context); --=20 2.51.2 From nobody Wed Jun 17 01:42:35 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4779E3D47B8; Tue, 21 Apr 2026 14:43:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776782606; cv=none; b=aWRPIbMHrDCvADU3qOfoXfZcfpuvGzkwJl7/raASPUQdmVetTxWT7CaHcdmp7AZPKGI7/xJynltSYz+f3Or1rTB1d1yOu4tyqErdQYdjXMhE4zzA8ILGRB/u1auFcBmvflsm8KK9J4Wgs6jAJpxw4vpFnPR73z41kLPgy93Grxw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776782606; c=relaxed/simple; bh=uE9jQ5/Tb87+KKebRJWQfQzQewWOPhLdHfsan5xetdM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ndr1SZyFdDiSYkt/CdvrIJE40C9P/LTcz+HBUHQDEoGXRdV0ps3z6yg4R0SgpUJ4w9dfTu/1xeSF7bvKZPjGFWOAI2n1imjtuUyHk2hAca4xfqU3XVISen+rygRqm9zBctMdFoPByhsSj2DK6KFpUzZ7FJYZjabDdAeZVTGichU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=qtIUWYBP; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="qtIUWYBP" 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 710D0302C; Tue, 21 Apr 2026 07:43:18 -0700 (PDT) Received: from e123572-lin.arm.com (e123572-lin.cambridge.arm.com [10.1.194.54]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 9D0B33FAF5; Tue, 21 Apr 2026 07:43:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1776782604; bh=uE9jQ5/Tb87+KKebRJWQfQzQewWOPhLdHfsan5xetdM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qtIUWYBPqWf7sC8xIKXk5VB1ZWrtTT315ZiLzg6GMj8nJbfXKYT3L3JFll6h2JxbI 3Ozcg+t0YoLIqWgc1REnoQxGagMc9FSGm4IAUyZ/5ZCxGQcfLAYcljpQqk6raDH1zk J4Mz1EixN1jNaT/o37E6VhSWfHlFayjbJDHMcdJk= From: Kevin Brodsky To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Kevin Brodsky , Catalin Marinas , Joey Gouly , Mark Brown , Shuah Khan , Will Deacon , linux-kselftest@vger.kernel.org Subject: [PATCH 4/4] kselftest/arm64: Add tests for POR_EL0 save/reset/restore Date: Tue, 21 Apr 2026 15:42:52 +0100 Message-ID: <20260421144252.1440365-5-kevin.brodsky@arm.com> X-Mailer: git-send-email 2.51.2 In-Reply-To: <20260421144252.1440365-1-kevin.brodsky@arm.com> References: <20260421144252.1440365-1-kevin.brodsky@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" POR_EL0 is expected to be: - Saved in the poe_context record - Reset to POR_EL0_INIT when invoking the signal handler - Restored from poe_context when returning from the signal handler Add a new test, poe_restore, to check that the save/reset/restore mechanism is working as intended. See commit 2e8a1acea859 ("arm64: signal: Improve POR_EL0 handling to avoid uaccess failures") for more details. This commit did not handle the case where poe_context is missing correctly. This was recently fixed; add a new test, poe_missing_poe_context, to check this case. Note: td->pass is only set to true at the very end, as an unexpected signal may occur in case of failure (especially in poe_missing_poe_context if POR_EL0 is restored to an invalid value). Failures are tracked with a global, failed_check. Signed-off-by: Kevin Brodsky --- .../testcases/poe_missing_poe_context.c | 73 +++++++++++++++++++ .../arm64/signal/testcases/poe_restore.c | 64 ++++++++++++++++ 2 files changed, 137 insertions(+) create mode 100644 tools/testing/selftests/arm64/signal/testcases/poe_miss= ing_poe_context.c create mode 100644 tools/testing/selftests/arm64/signal/testcases/poe_rest= ore.c diff --git a/tools/testing/selftests/arm64/signal/testcases/poe_missing_poe= _context.c b/tools/testing/selftests/arm64/signal/testcases/poe_missing_poe= _context.c new file mode 100644 index 000000000000..abab7400d9df --- /dev/null +++ b/tools/testing/selftests/arm64/signal/testcases/poe_missing_poe_contex= t.c @@ -0,0 +1,73 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2026 Arm Ltd + * + * Verify that the POR_EL0 register is left untouched on sigreturn if the + * POE frame record is missing. + */ + +#include + +#include "test_signals_utils.h" +#include "testcases.h" + +#define POR_EL0_INIT 0x07ul +#define POR_EL0_CUSTOM 0x77ul + +static bool failed_check; + +static bool modify_por_el0(struct tdescr *td) +{ + set_por_el0(POR_EL0_CUSTOM); + + return true; +} + +static int signal_remove_poe_context(struct tdescr *td, siginfo_t *si, + ucontext_t *uc) +{ + struct _aarch64_ctx *ctx =3D GET_UC_RESV_HEAD(uc); + struct _aarch64_ctx *poe_ctx_head; + + poe_ctx_head =3D get_header(ctx, POE_MAGIC, sizeof(uc->uc_mcontext), + NULL); + if (!poe_ctx_head) { + fprintf(stderr, "Missing poe_context record\n"); + failed_check =3D true; + return 0; + } + + /* + * Actually removing the record would require moving down the next + * records. An easier option is to turn it into an ESR record, which is + * ignored by sigreturn(). + */ + poe_ctx_head->magic =3D ESR_MAGIC; + + return 0; +} + +static void check_por_el0_preserved(struct tdescr *td) +{ + uint64_t por_el0 =3D get_por_el0(); + + if (por_el0 =3D=3D POR_EL0_INIT) { + fprintf(stderr, "POR_EL0 preserved\n"); + } else { + fprintf(stderr, "POR_EL0 unexpectedly set to %lx\n", por_el0); + failed_check =3D true; + } + + td->pass =3D !failed_check; +} + +struct tdescr tde =3D { + .name =3D "POR_EL0 missing poe_context", + .descr =3D "Remove poe_context record and check POR_EL0 is preserved", + .feats_required =3D FEAT_POE, + .timeout =3D 3, + .sig_trig =3D SIGUSR1, + .init =3D modify_por_el0, + .run =3D signal_remove_poe_context, + .check_result =3D check_por_el0_preserved, +}; diff --git a/tools/testing/selftests/arm64/signal/testcases/poe_restore.c b= /tools/testing/selftests/arm64/signal/testcases/poe_restore.c new file mode 100644 index 000000000000..9f9a61a4214d --- /dev/null +++ b/tools/testing/selftests/arm64/signal/testcases/poe_restore.c @@ -0,0 +1,64 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2026 Arm Ltd + * + * Verify that the POR_EL0 register is saved and restored as expected on s= ignal + * entry/return. + */ + +#include + +#include "test_signals_utils.h" +#include "testcases.h" + +#define POR_EL0_INIT 0x07ul +#define POR_EL0_CUSTOM 0x77ul + +static bool failed_check; + +static bool modify_por_el0(struct tdescr *td) +{ + set_por_el0(POR_EL0_CUSTOM); + + return true; +} + +static int signal_check_por_el0_reset(struct tdescr *td, siginfo_t *si, + ucontext_t *uc) +{ + uint64_t signal_por_el0 =3D get_por_el0(); + + if (signal_por_el0 !=3D POR_EL0_INIT) { + fprintf(stderr, "POR_EL0 is %lx in signal handler (expected %lx)\n", + signal_por_el0, POR_EL0_INIT); + failed_check =3D true; + } + + return 0; +} + +static void check_por_el0_restored(struct tdescr *td) +{ + uint64_t por_el0 =3D get_por_el0(); + + if (por_el0 =3D=3D POR_EL0_CUSTOM) { + fprintf(stderr, "POR_EL0 restored\n"); + } else { + fprintf(stderr, "POR_EL0 was %lx but is now %lx\n", + POR_EL0_CUSTOM, por_el0); + failed_check =3D true; + } + + td->pass =3D !failed_check; +} + +struct tdescr tde =3D { + .name =3D "POR_EL0 restore", + .descr =3D "Validate that POR_EL0 is saved/restored on signal entry/retur= n", + .feats_required =3D FEAT_POE, + .timeout =3D 3, + .sig_trig =3D SIGUSR1, + .init =3D modify_por_el0, + .run =3D signal_check_por_el0_reset, + .check_result =3D check_por_el0_restored, +}; --=20 2.51.2