Skip to contentSkip to conversation

arm64: Preserve the user r/w register tpidr_el0 on context switch and fork in compat mode

PATCH In review André Hentschel 2 participants 3 messages May 20, 2015 – May 28, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 arm64: Preserve the user r/w register tpidr_el0 on context switch and fork in compat mode

From: André Hentschel <[email protected]>

Since commit a4780adeefd042482f624f5e0d577bf9cdcbb760 the user writeable TLS register on ARM is preserved per thread.

This patch does it analogous to the ARM patch, but for compat mode on ARM64.

Cc Will Deacon <[email protected]>
Cc Catalin Marinas <[email protected]>

---
This patch is against Linux 4.1-rc1 (b787f68c36d49bb1d9236f403813641efa74a031)

v2: Trying to address suggestions by Will Deacon

@Will Deacon: The macro you suggested is not helpful it seems, instead i introduced
static functions. They also could be macros i guess, but it seems much cleaner to me to use functions as it only affects one file.
Should the final version be send to rmk's patchtracker or will someone else pick it up?

 arch/arm64/include/asm/processor.h |  3 +++
 arch/arm64/kernel/process.c        | 41 +++++++++++++++++++++++++++++---------
 2 files changed, 35 insertions(+), 9 deletions(-)
arch/arm64/include/asm/processor.h +3 -0
index d2c37a1..466a851 100644
@@ -79,6 +79,9 @@ struct cpu_context {
 struct thread_struct {
 	struct cpu_context	cpu_context;	/* cpu context */
 	unsigned long		tp_value;
+#ifdef CONFIG_COMPAT
+	unsigned long		tp_compat;
+#endif
 	struct fpsimd_state	fpsimd_state;
 	unsigned long		fault_address;	/* fault info */
 	unsigned long		fault_code;	/* ESR_EL1 value */
arch/arm64/kernel/process.c +32 -9

74 lines not on this page · raw message

#1 lore raw

Hi André,

Quoted 11 lines · André Hentschel

From: André Hentschel <[email protected]>

Since commit a4780adeefd042482f624f5e0d577bf9cdcbb760 the user writeable TLS register on ARM is preserved per thread.

This patch does it analogous to the ARM patch, but for compat mode on ARM64.

Cc Will Deacon <[email protected]>
Cc Catalin Marinas <[email protected]>
Quoted 8 lines

---
This patch is against Linux 4.1-rc1 (b787f68c36d49bb1d9236f403813641efa74a031)

v2: Trying to address suggestions by Will Deacon

@Will Deacon: The macro you suggested is not helpful it seems, instead i introduced
static functions. They also could be macros i guess, but it seems much cleaner to me to use functions as it only affects one file.

I wanted to understand in more detail why the macro didn't work out for you, so I trued hacking together my own version of the patch (see below). It seems to hold up to light testing, so it would be good to know where you ran into problems.

Quoted 2 lines

Should the final version be send to rmk's patchtracker or will someone else pick it up?

This is an arm64 patch, so either Catalin or me will pick it up directly when it's ready to be merged.

Will

--->8

arch/arm64/include/asm/processor.h +18 -1
index d2c37a1df0eb..e4c893e54f01 100644
@@ -78,13 +78,30 @@ struct cpu_context {
 
 struct thread_struct {
 	struct cpu_context	cpu_context;	/* cpu context */
-	unsigned long		tp_value;
+	unsigned long		tp_value;	/* TLS register */
+#ifdef CONFIG_COMPAT
+	unsigned long		tp2_value;
+#endif
 	struct fpsimd_state	fpsimd_state;
 	unsigned long		fault_address;	/* fault info */
 	unsigned long		fault_code;	/* ESR_EL1 value */
 	struct debug_info	debug;		/* debugging */
 };
 
+#ifdef CONFIG_COMPAT
+#define task_user_tls(t)						\
+({									\
+	unsigned long *__tls;						\
+	if (is_compat_thread(task_thread_info(t)))			\
+		__tls = &(t)->thread.tp2_value;				\
+	else								\
+		__tls = &(t)->thread.tp_value;				\
+	__tls;								\
+ })
+#else
+#define task_user_tls(t)	(&(t)->thread.tp_value)
+#endif
+
 #define INIT_THREAD  {	}
 
 static inline void start_thread_common(struct pt_regs *regs, unsigned long pc)
arch/arm64/kernel/process.c +20 -27

80 lines not on this page · raw message

#2 lore raw

Am 27.05.2015 um 16:36 schrieb Will Deacon:

Quoted 28 lines

Hi André,

Quoted 11 lines · André Hentschel

From: André Hentschel <[email protected]>

Since commit a4780adeefd042482f624f5e0d577bf9cdcbb760 the user writeable TLS register on ARM is preserved per thread.

This patch does it analogous to the ARM patch, but for compat mode on ARM64.

Cc Will Deacon <[email protected]>
Cc Catalin Marinas <[email protected]>
Quoted 8 lines

---
This patch is against Linux 4.1-rc1 (b787f68c36d49bb1d9236f403813641efa74a031)

v2: Trying to address suggestions by Will Deacon

@Will Deacon: The macro you suggested is not helpful it seems, instead i introduced
static functions. They also could be macros i guess, but it seems much cleaner to me to use functions as it only affects one file.

I wanted to understand in more detail why the macro didn't work out for you, so I trued hacking together my own version of the patch (see below). It seems to hold up to light testing, so it would be good to know where you ran into problems.

Quoted 7 lines
Quoted 2 lines

Should the final version be send to rmk's patchtracker or will someone else pick it up?

This is an arm64 patch, so either Catalin or me will pick it up directly when it's ready to be merged.

Will

Your patch works, you can add me as Tested-by. :)
My bad was that i didn't know that macro style (returning a variable conditionally with c code) Sadly no new commit by me :(