arm64/signal: Support TPIDR2
Subsystems (3)
v3 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.
v3:
- Load restored TPIDR2 value into the register to ensure that any changes requested by userspace are reflected in the case where we don't context switch before we return to userspace.
- Use tls_preserve_current_state() to sync TPIDR2 state to the task struct.
- Use system_supports_tpidr2().
- Fix mangled comment.
- Update comment on prototype for tls_preserve_current_state().
v2:
- Rebase onto v6.1-rc3.
- Change the signal frame magic to 0x54504902 (TPI).
Mark Brown (5):
arm64/processor: Update documentation for tls_preserve_current_state() 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/asm/processor.h | 2 +- arch/arm64/include/uapi/asm/sigcontext.h | 8 ++ arch/arm64/kernel/signal.c | 61 +++++++++++++ .../testing/selftests/arm64/signal/.gitignore | 1 + .../arm64/signal/testcases/testcases.c | 4 + .../arm64/signal/testcases/tpidr2_siginfo.c | 90 +++++++++++++++++++ 7 files changed, 168 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/arm64/signal/testcases/tpidr2_siginfo.c
base-commit: 30a0b95b1335e12efef89dd78518ed3e4a71a763
Signature · 7 lines
2.30.2 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v3 1/5 arm64/processor: Update documentation for tls_preserve_current_state()
tls_preserve_current_state() has been extended to sync TPIDR2_EL0 as well as TPIDR_EL0, update the comment in the header to reflect this.
--- arch/arm64/include/asm/processor.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/include/asm/processor.h +1 -1
@@ -263,7 +263,7 @@ static inline void arch_thread_struct_whitelist(unsigned long *offset,#define task_user_tls (t) (&(t)->thread.uw.tp_value)#endif -/* Sync TPIDR_EL0 back to thread_struct for current */ +/* Sync TPIDR_EL0 and TPIDR2_EL0 back to thread_struct for current */ void tls_preserve_current_state (void );#define INIT_THREAD { \
Signature · 7 lines
2.30.2 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v3 2/5 arm64/sme: Document ABI for TPIDR2 signal information
In reply to Mark BrownIn 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 v3 3/5 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 | 61 ++++++++++++++++++++++++ 2 files changed, 69 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 0x54504902 + +struct tpidr2_context { +struct _aarch64_ctx head; +__u64 tpidr2; +}; +#define ZA_MAGIC 0x54366345struct za_context {
arch/arm64/kernel/signal.c +61 -0
115 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 v3 4/5 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 v3 5/5 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