arm64/signal: Support TPIDR2
Subsystems (3)
cover arm64/signal: Support TPIDR2
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
Signature · 7 lines
2.30.2 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH 1/4 arm64/sme: Document ABI for TPIDR2 signal information
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.
--- Documentation/arm64/sme.rst | 3 +++ 1 file changed, 3 insertions(+)
Documentation/arm64/sme.rst +3 -0
@@ -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]
Signature · 7 lines
2.30.2 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH 2/4 arm64/signal: Include TPIDR2 in the signal context
In reply to Mark BrownAdd 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.
--- arch/arm64/include/uapi/asm/sigcontext.h | 8 ++++ arch/arm64/kernel/signal.c | 59 ++++++++++++++++++++++++ 2 files changed, 67 insertions(+)
arch/arm64/include/uapi/asm/sigcontext.h +8 -0
@@ -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 0x54366345struct za_context {
arch/arm64/kernel/signal.c +59 -0
113 lines not on this page · raw message
Signature · 7 lines
2.30.2 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH 3/4 kselftest/arm64: Add TPIDR2 to the set of known signal context records
In reply to Mark BrownWhen 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.
--- tools/testing/selftests/arm64/signal/testcases/testcases.c | 4 ++++ 1 file changed, 4 insertions(+)
tools/testing/selftests/arm64/signal/testcases/testcases.c +4 -0
@@ -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" ;
Signature · 7 lines
2.30.2 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH 4/4 kselftest/arm64: Add test case for TPIDR2 signal frame records
In reply to Mark BrownEnsure 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.
--- .../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
tools/testing/selftests/arm64/signal/.gitignore +1 -0
@@ -4,5 +4,6 @@ fake_sigreturn_* sme_* ssve_* sve_* +tpidr2_siginfo za_* !*.[ch]
tools/testing/selftests/arm64/signal/testcases/tpidr2_siginfo.c new file +90 -0
90 lines not on this page · raw message
Signature · 7 lines
2.30.2 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v1 2/4] arm64/signal: Include TPIDR2 in the signal context
In reply to Mark BrownQuoted 6 lines · 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 <[email protected]>
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.
Quoted 153 lines
--- arch/arm64/include/uapi/asm/sigcontext.h | 8 ++++ arch/arm64/kernel/signal.c | 59 ++++++++++++++++++++++++ 2 files changed, 67 insertions(+)arch/arm64/include/uapi/asm/sigcontext.h +8
-0@@ -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 0x54366345struct za_context {arch/arm64/kernel/signal.c +59
-0@@ -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 (¤t->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 =Signature · 1 line
2.30.2
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v1 2/4] arm64/signal: Include TPIDR2 in the signal context
Quoted 5 lines · Szabolcs Nagy
this looks good from userspace point of view.
originally the magic numbers made some sense, e.g. esr used
0x45535201which 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.
Quoted 1 line
Reviewed-by Szabolcs Nagy <[email protected]>
Thanks, if I just change the constant I'll preserve the tag if that's OK?
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v1 2/4] arm64/signal: Include TPIDR2 in the signal context
Quoted 15 lines · Mark Brown
Quoted 5 lines · Szabolcs Nagy
this looks good from userspace point of view.
originally the magic numbers made some sense, e.g. esr used
0x45535201which 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.
Quoted 3 lines
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.
Quoted 5 lines
Quoted 2 lines
Reviewed-by Szabolcs Nagy <[email protected]>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
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v1 2/4] arm64/signal: Include TPIDR2 in the signal context
Quoted 10 lines · Szabolcs Nagy
Quoted 3 lines · Mark Brown
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.
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel