All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 0/4] arm64/signal: Support TPIDR2
@ 2022-10-28 18:50 Mark Brown
  2022-10-28 18:50 ` [PATCH v1 1/4] arm64/sme: Document ABI for TPIDR2 signal information Mark Brown
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Mark Brown @ 2022-10-28 18:50 UTC (permalink / raw)
  To: Catalin Marinas, Will Deacon, Shuah Khan, Shuah Khan
  Cc: Szabolcs Nagy, linux-arm-kernel, Mark Brown

When SME support was merged support for TPIDR2 in signal frames was
omitted, meaning that it was not possible for signal handers to inspect
or modify it. This will present an issue for programs using signals to
implement lightweight threads so let's provide access to TPIDR2 in
signal handlers.

Implement a new record type for TPIDR2 using the same format as we use
for ESR and add coverage to make sure that this appears in the signal
context as expected.  Due to TPIDR2 being reserved for libc we only
validate that the value is unchanged, meaning we're likely to just be
validating the default value of 0 on current systems. I have tested with
a modified version that sets an explicit value.

Mark Brown (4):
  arm64/sme: Document ABI for TPIDR2 signal information
  arm64/signal: Include TPIDR2 in the signal context
  kselftest/arm64: Add TPIDR2 to the set of known signal context records
  kselftest/arm64: Add test case for TPIDR2 signal frame records

 Documentation/arm64/sme.rst                   |  3 +
 arch/arm64/include/uapi/asm/sigcontext.h      |  8 ++
 arch/arm64/kernel/signal.c                    | 59 ++++++++++++
 .../testing/selftests/arm64/signal/.gitignore |  1 +
 .../arm64/signal/testcases/testcases.c        |  4 +
 .../arm64/signal/testcases/tpidr2_siginfo.c   | 90 +++++++++++++++++++
 6 files changed, 165 insertions(+)
 create mode 100644 tools/testing/selftests/arm64/signal/testcases/tpidr2_siginfo.c


base-commit: 9abf2313adc1ca1b6180c508c25f22f9395cc780
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v1 1/4] arm64/sme: Document ABI for TPIDR2 signal information
  2022-10-28 18:50 [PATCH v1 0/4] arm64/signal: Support TPIDR2 Mark Brown
@ 2022-10-28 18:50 ` Mark Brown
  2022-10-28 18:50 ` [PATCH v1 2/4] arm64/signal: Include TPIDR2 in the signal context Mark Brown
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 9+ messages in thread
From: Mark Brown @ 2022-10-28 18:50 UTC (permalink / raw)
  To: Catalin Marinas, Will Deacon, Shuah Khan, Shuah Khan
  Cc: Szabolcs Nagy, linux-arm-kernel, Mark Brown

In order to allow access to TPIDR2 from signal handlers we need to add it
to the signal context, document that we are doing so.

Signed-off-by: Mark Brown <broonie@kernel.org>
---
 Documentation/arm64/sme.rst | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/Documentation/arm64/sme.rst b/Documentation/arm64/sme.rst
index 16d2db4c2e2e..36b08a105dd1 100644
--- a/Documentation/arm64/sme.rst
+++ b/Documentation/arm64/sme.rst
@@ -111,6 +111,9 @@ be zeroed.
 
 * Signal handlers are invoked with streaming mode and ZA disabled.
 
+* A new signal frame record TPIDR2_MAGIC is added formatted as a struct
+  tpidr2_context to allow access to TPIDR2_EL0 from signal handlers.
+
 * A new signal frame record za_context encodes the ZA register contents on
   signal delivery. [1]
 
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v1 2/4] arm64/signal: Include TPIDR2 in the signal context
  2022-10-28 18:50 [PATCH v1 0/4] arm64/signal: Support TPIDR2 Mark Brown
  2022-10-28 18:50 ` [PATCH v1 1/4] arm64/sme: Document ABI for TPIDR2 signal information Mark Brown
@ 2022-10-28 18:50 ` Mark Brown
  2022-10-31 15:05   ` Szabolcs Nagy
  2022-10-28 18:50 ` [PATCH v1 3/4] kselftest/arm64: Add TPIDR2 to the set of known signal context records Mark Brown
  2022-10-28 18:50 ` [PATCH v1 4/4] kselftest/arm64: Add test case for TPIDR2 signal frame records Mark Brown
  3 siblings, 1 reply; 9+ messages in thread
From: Mark Brown @ 2022-10-28 18:50 UTC (permalink / raw)
  To: Catalin Marinas, Will Deacon, Shuah Khan, Shuah Khan
  Cc: Szabolcs Nagy, linux-arm-kernel, Mark Brown

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 <broonie@kernel.org>
---
 arch/arm64/include/uapi/asm/sigcontext.h |  8 ++++
 arch/arm64/kernel/signal.c               | 59 ++++++++++++++++++++++++
 2 files changed, 67 insertions(+)

diff --git a/arch/arm64/include/uapi/asm/sigcontext.h b/arch/arm64/include/uapi/asm/sigcontext.h
index 4aaf31e3bf16..6315e1b8e2c4 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	0x45a4209c
+
+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..ac4fb42a9613 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,32 @@ 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;
+
+	current->thread.tpidr2_el0 = read_sysreg_s(SYS_TPIDR2_EL0);
+
+	__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 deciding to call this function */
+	__get_user_error(tpidr2_el0, &user->tpidr2->tpidr2, err);
+	if (!err)
+		current->thread.tpidr2_el0 = tpidr2_el0;
+
+	return err;
+}
+
 static int preserve_za_context(struct za_context __user *ctx)
 {
 	int err = 0;
@@ -447,6 +475,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 +495,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 +562,19 @@ static int parse_user_sigframe(struct user_ctxs *user,
 			user->sve = (struct sve_context __user *)head;
 			break;
 
+		case TPIDR2_MAGIC:
+			if (!system_supports_sme())
+				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 +707,9 @@ static int restore_sigframe(struct pt_regs *regs,
 			err = restore_fpsimd_context(user.fpsimd);
 	}
 
+	if (err == 0 && system_supports_sme() && user.tpidr2)
+		err = restore_tpidr2_context(&user);
+
 	if (err == 0 && system_supports_sme() && user.za)
 		err = restore_za_context(&user);
 
@@ -757,6 +804,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(&current->thread))
 			vq = sve_vq_from_vl(vl);
 
@@ -814,6 +866,13 @@ static int setup_sigframe(struct rt_sigframe_user_layout *user,
 		err |= preserve_sve_context(sve_ctx);
 	}
 
+	/* TPIDR2 if supported */
+	if (system_supports_sme() && 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

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v1 3/4] kselftest/arm64: Add TPIDR2 to the set of known signal context records
  2022-10-28 18:50 [PATCH v1 0/4] arm64/signal: Support TPIDR2 Mark Brown
  2022-10-28 18:50 ` [PATCH v1 1/4] arm64/sme: Document ABI for TPIDR2 signal information Mark Brown
  2022-10-28 18:50 ` [PATCH v1 2/4] arm64/signal: Include TPIDR2 in the signal context Mark Brown
@ 2022-10-28 18:50 ` Mark Brown
  2022-10-28 18:50 ` [PATCH v1 4/4] kselftest/arm64: Add test case for TPIDR2 signal frame records Mark Brown
  3 siblings, 0 replies; 9+ messages in thread
From: Mark Brown @ 2022-10-28 18:50 UTC (permalink / raw)
  To: Catalin Marinas, Will Deacon, Shuah Khan, Shuah Khan
  Cc: Szabolcs Nagy, linux-arm-kernel, Mark Brown

When validating the set of signal context records check that any TPIDR2
record has the correct size, also suppressing warnings due to seeing an
unknown record type.

Signed-off-by: Mark Brown <broonie@kernel.org>
---
 tools/testing/selftests/arm64/signal/testcases/testcases.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/tools/testing/selftests/arm64/signal/testcases/testcases.c b/tools/testing/selftests/arm64/signal/testcases/testcases.c
index e1c625b20ac4..f98cc081aa95 100644
--- a/tools/testing/selftests/arm64/signal/testcases/testcases.c
+++ b/tools/testing/selftests/arm64/signal/testcases/testcases.c
@@ -158,6 +158,10 @@ bool validate_reserved(ucontext_t *uc, size_t resv_sz, char **err)
 			if (head->size != sizeof(struct esr_context))
 				*err = "Bad size for esr_context";
 			break;
+		case TPIDR2_MAGIC:
+			if (head->size != sizeof(struct tpidr2_context))
+				*err = "Bad size for tpidr2_context";
+			break;
 		case SVE_MAGIC:
 			if (flags & SVE_CTX)
 				*err = "Multiple SVE_MAGIC";
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v1 4/4] kselftest/arm64: Add test case for TPIDR2 signal frame records
  2022-10-28 18:50 [PATCH v1 0/4] arm64/signal: Support TPIDR2 Mark Brown
                   ` (2 preceding siblings ...)
  2022-10-28 18:50 ` [PATCH v1 3/4] kselftest/arm64: Add TPIDR2 to the set of known signal context records Mark Brown
@ 2022-10-28 18:50 ` Mark Brown
  3 siblings, 0 replies; 9+ messages in thread
From: Mark Brown @ 2022-10-28 18:50 UTC (permalink / raw)
  To: Catalin Marinas, Will Deacon, Shuah Khan, Shuah Khan
  Cc: Szabolcs Nagy, linux-arm-kernel, Mark Brown

Ensure that we get signal context for TPIDR2 if and only if SME is present
on the system. Since TPIDR2 is owned by libc we merely validate that the
value is whatever it was set to, this isn't ideal since it's likely to
just be the default of 0 with current systems but it avoids future false
positives.

Signed-off-by: Mark Brown <broonie@kernel.org>
---
 .../testing/selftests/arm64/signal/.gitignore |  1 +
 .../arm64/signal/testcases/tpidr2_siginfo.c   | 90 +++++++++++++++++++
 2 files changed, 91 insertions(+)
 create mode 100644 tools/testing/selftests/arm64/signal/testcases/tpidr2_siginfo.c

diff --git a/tools/testing/selftests/arm64/signal/.gitignore b/tools/testing/selftests/arm64/signal/.gitignore
index e8d2b57f73ec..e1b6c4d961b5 100644
--- a/tools/testing/selftests/arm64/signal/.gitignore
+++ b/tools/testing/selftests/arm64/signal/.gitignore
@@ -4,5 +4,6 @@ fake_sigreturn_*
 sme_*
 ssve_*
 sve_*
+tpidr2_siginfo
 za_*
 !*.[ch]
diff --git a/tools/testing/selftests/arm64/signal/testcases/tpidr2_siginfo.c b/tools/testing/selftests/arm64/signal/testcases/tpidr2_siginfo.c
new file mode 100644
index 000000000000..6a2c82bf7ead
--- /dev/null
+++ b/tools/testing/selftests/arm64/signal/testcases/tpidr2_siginfo.c
@@ -0,0 +1,90 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2022 ARM Limited
+ *
+ * Verify that the TPIDR2 register context in signal frames is set up as
+ * expected.
+ */
+
+#include <signal.h>
+#include <ucontext.h>
+#include <sys/auxv.h>
+#include <sys/prctl.h>
+#include <unistd.h>
+#include <asm/sigcontext.h>
+
+#include "test_signals_utils.h"
+#include "testcases.h"
+
+static union {
+	ucontext_t uc;
+	char buf[1024 * 128];
+} context;
+
+#define SYS_TPIDR2 "S3_3_C13_C0_5"
+
+static uint64_t get_tpidr2(void)
+{
+	uint64_t val;
+
+	asm volatile (
+		"mrs	%0, " SYS_TPIDR2 "\n"
+		: "=r"(val)
+		:
+		: "cc");
+
+	return val;
+}
+
+int tpidr2_present(struct tdescr *td, siginfo_t *si, ucontext_t *uc)
+{
+	struct _aarch64_ctx *head = GET_BUF_RESV_HEAD(context);
+	struct tpidr2_context *tpidr2_ctx;
+	size_t offset;
+	bool in_sigframe;
+	bool have_sme;
+	__u64 orig_tpidr2;
+
+	have_sme = getauxval(AT_HWCAP2) & HWCAP2_SME;
+	if (have_sme)
+		orig_tpidr2 = get_tpidr2();
+
+	if (!get_current_context(td, &context.uc, sizeof(context)))
+		return 1;
+
+	tpidr2_ctx = (struct tpidr2_context *)
+		get_header(head, TPIDR2_MAGIC, td->live_sz, &offset);
+
+	in_sigframe = tpidr2_ctx != NULL;
+
+	fprintf(stderr, "TPIDR2 sigframe %s on system %s SME\n",
+		in_sigframe ? "present" : "absent",
+		have_sme ? "with" : "without");
+
+	td->pass = (in_sigframe == have_sme);
+
+	/*
+	 * Check that the value we read back was the one present at
+	 * the time that the signal was triggered.  TPIDR2 is owned by
+	 * libc so we can't safely choose the value and it is possible
+	 * that we may need to revisit this in future if something
+	 * starts deciding to set a new TPIDR2 between us reading and
+	 * the signal.
+	 */
+	if (have_sme && tpidr2_ctx) {
+		if (tpidr2_ctx->tpidr2 != orig_tpidr2) {
+			fprintf(stderr, "TPIDR2 in frame is %llx, was %llx\n",
+				tpidr2_ctx->tpidr2, orig_tpidr2);
+			td->pass = false;
+		}
+	}
+
+	return 0;
+}
+
+struct tdescr tde = {
+	.name = "TPIDR2",
+	.descr = "Validate that TPIDR2 is present as expected",
+	.timeout = 3,
+	.run = tpidr2_present,
+};
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v1 2/4] arm64/signal: Include TPIDR2 in the signal context
  2022-10-28 18:50 ` [PATCH v1 2/4] arm64/signal: Include TPIDR2 in the signal context Mark Brown
@ 2022-10-31 15:05   ` Szabolcs Nagy
  2022-10-31 15:34     ` Mark Brown
  0 siblings, 1 reply; 9+ messages in thread
From: Szabolcs Nagy @ 2022-10-31 15:05 UTC (permalink / raw)
  To: Mark Brown
  Cc: Catalin Marinas, Will Deacon, Shuah Khan, Shuah Khan, linux-arm-kernel

The 10/28/2022 19:50, Mark Brown wrote:
> 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 <broonie@kernel.org>

this looks good from userspace point of view.

originally the magic numbers made some sense, e.g.
esr used 0x45535201 which is ascii encoded "ESR\01",
the new ones seem random. probably does not matter.

Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>

> ---
>  arch/arm64/include/uapi/asm/sigcontext.h |  8 ++++
>  arch/arm64/kernel/signal.c               | 59 ++++++++++++++++++++++++
>  2 files changed, 67 insertions(+)
> 
> diff --git a/arch/arm64/include/uapi/asm/sigcontext.h b/arch/arm64/include/uapi/asm/sigcontext.h
> index 4aaf31e3bf16..6315e1b8e2c4 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	0x45a4209c
> +
> +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..ac4fb42a9613 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,32 @@ 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;
> +
> +	current->thread.tpidr2_el0 = read_sysreg_s(SYS_TPIDR2_EL0);
> +
> +	__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 deciding to call this function */
> +	__get_user_error(tpidr2_el0, &user->tpidr2->tpidr2, err);
> +	if (!err)
> +		current->thread.tpidr2_el0 = tpidr2_el0;
> +
> +	return err;
> +}
> +
>  static int preserve_za_context(struct za_context __user *ctx)
>  {
>  	int err = 0;
> @@ -447,6 +475,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 +495,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 +562,19 @@ static int parse_user_sigframe(struct user_ctxs *user,
>  			user->sve = (struct sve_context __user *)head;
>  			break;
>  
> +		case TPIDR2_MAGIC:
> +			if (!system_supports_sme())
> +				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 +707,9 @@ static int restore_sigframe(struct pt_regs *regs,
>  			err = restore_fpsimd_context(user.fpsimd);
>  	}
>  
> +	if (err == 0 && system_supports_sme() && user.tpidr2)
> +		err = restore_tpidr2_context(&user);
> +
>  	if (err == 0 && system_supports_sme() && user.za)
>  		err = restore_za_context(&user);
>  
> @@ -757,6 +804,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(&current->thread))
>  			vq = sve_vq_from_vl(vl);
>  
> @@ -814,6 +866,13 @@ static int setup_sigframe(struct rt_sigframe_user_layout *user,
>  		err |= preserve_sve_context(sve_ctx);
>  	}
>  
> +	/* TPIDR2 if supported */
> +	if (system_supports_sme() && 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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v1 2/4] arm64/signal: Include TPIDR2 in the signal context
  2022-10-31 15:05   ` Szabolcs Nagy
@ 2022-10-31 15:34     ` Mark Brown
  2022-10-31 15:47       ` Szabolcs Nagy
  0 siblings, 1 reply; 9+ messages in thread
From: Mark Brown @ 2022-10-31 15:34 UTC (permalink / raw)
  To: Szabolcs Nagy
  Cc: Catalin Marinas, Will Deacon, Shuah Khan, Shuah Khan, linux-arm-kernel


[-- Attachment #1.1: Type: text/plain, Size: 1033 bytes --]

On Mon, Oct 31, 2022 at 03:05:06PM +0000, Szabolcs Nagy wrote:

> this looks good from userspace point of view.

> originally the magic numbers made some sense, e.g.
> esr used 0x45535201 which is ascii encoded "ESR\01",
> the new ones seem random. probably does not matter.

Ah!  That looks like it was just the one I added for ZA that doesn't
follow the convention, plus this and the ZT one that are on the list.
The fact that there wasn't anything in the code mentioning this meant
that when I was adding new values I had no idea that the numbers were
anything other than random.  Nobody said anything in the many, many
months the SME patches were on the list.  

We could start trying to follow that again and make this something like
0x54504902 (TPI\02 for TPIDR2)?  We should definitely at least add a
comment about this if we're hoping to have people follow the convention.

> Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>

Thanks, if I just change the constant I'll preserve the tag if that's
OK?

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

[-- Attachment #2: Type: text/plain, Size: 176 bytes --]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v1 2/4] arm64/signal: Include TPIDR2 in the signal context
  2022-10-31 15:34     ` Mark Brown
@ 2022-10-31 15:47       ` Szabolcs Nagy
  2022-10-31 15:52         ` Mark Brown
  0 siblings, 1 reply; 9+ messages in thread
From: Szabolcs Nagy @ 2022-10-31 15:47 UTC (permalink / raw)
  To: Mark Brown
  Cc: Catalin Marinas, Will Deacon, Shuah Khan, Shuah Khan, linux-arm-kernel

The 10/31/2022 15:34, Mark Brown wrote:
> On Mon, Oct 31, 2022 at 03:05:06PM +0000, Szabolcs Nagy wrote:
> 
> > this looks good from userspace point of view.
> 
> > originally the magic numbers made some sense, e.g.
> > esr used 0x45535201 which is ascii encoded "ESR\01",
> > the new ones seem random. probably does not matter.
> 
> Ah!  That looks like it was just the one I added for ZA that doesn't
> follow the convention, plus this and the ZT one that are on the list.
> The fact that there wasn't anything in the code mentioning this meant
> that when I was adding new values I had no idea that the numbers were
> anything other than random.  Nobody said anything in the many, many
> months the SME patches were on the list.  
> 
> We could start trying to follow that again and make this something like
> 0x54504902 (TPI\02 for TPIDR2)?  We should definitely at least add a
> comment about this if we're hoping to have people follow the convention.

i think this is not super important, but may help
when somebody is debugging a signal frame and does
not have to look up the magic value if it's self
documenting.

> 
> > Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>
> 
> Thanks, if I just change the constant I'll preserve the tag if that's
> OK?

that's fine by me.



_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v1 2/4] arm64/signal: Include TPIDR2 in the signal context
  2022-10-31 15:47       ` Szabolcs Nagy
@ 2022-10-31 15:52         ` Mark Brown
  0 siblings, 0 replies; 9+ messages in thread
From: Mark Brown @ 2022-10-31 15:52 UTC (permalink / raw)
  To: Szabolcs Nagy
  Cc: Catalin Marinas, Will Deacon, Shuah Khan, Shuah Khan, linux-arm-kernel


[-- Attachment #1.1: Type: text/plain, Size: 645 bytes --]

On Mon, Oct 31, 2022 at 03:47:11PM +0000, Szabolcs Nagy wrote:
> The 10/31/2022 15:34, Mark Brown wrote:

> > We could start trying to follow that again and make this something like
> > 0x54504902 (TPI\02 for TPIDR2)?  We should definitely at least add a
> > comment about this if we're hoping to have people follow the convention.

> i think this is not super important, but may help
> when somebody is debugging a signal frame and does
> not have to look up the magic value if it's self
> documenting.

Yeah, it's not the end of the world but like you say it might help
someone out if we pick the magic numbers this way so I'll do the respin.

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

[-- Attachment #2: Type: text/plain, Size: 176 bytes --]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-10-31 15:53 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-28 18:50 [PATCH v1 0/4] arm64/signal: Support TPIDR2 Mark Brown
2022-10-28 18:50 ` [PATCH v1 1/4] arm64/sme: Document ABI for TPIDR2 signal information Mark Brown
2022-10-28 18:50 ` [PATCH v1 2/4] arm64/signal: Include TPIDR2 in the signal context Mark Brown
2022-10-31 15:05   ` Szabolcs Nagy
2022-10-31 15:34     ` Mark Brown
2022-10-31 15:47       ` Szabolcs Nagy
2022-10-31 15:52         ` Mark Brown
2022-10-28 18:50 ` [PATCH v1 3/4] kselftest/arm64: Add TPIDR2 to the set of known signal context records Mark Brown
2022-10-28 18:50 ` [PATCH v1 4/4] kselftest/arm64: Add test case for TPIDR2 signal frame records Mark Brown

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.