From patchwork Wed Feb 6 22:43:10 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andr=C3=A9_Hentschel?= X-Patchwork-Id: 2108751 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork1.kernel.org (Postfix) with ESMTP id 0A79D3FDF1 for ; Wed, 6 Feb 2013 22:46:31 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1U3Di8-0002jj-Q0; Wed, 06 Feb 2013 22:43:24 +0000 Received: from moutng.kundenserver.de ([212.227.126.187]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1U3Di4-0002i8-AE for linux-arm-kernel@lists.infradead.org; Wed, 06 Feb 2013 22:43:21 +0000 Received: from [192.168.178.20] (pD95310AE.dip0.t-ipconnect.de [217.83.16.174]) by mrelayeu.kundenserver.de (node=mreu3) with ESMTP (Nemesis) id 0MZs0w-1UNUNV2OSs-00LXIf; Wed, 06 Feb 2013 23:43:12 +0100 Message-ID: <5112DC7E.4020108@dawncrow.de> Date: Wed, 06 Feb 2013 23:43:10 +0100 From: =?ISO-8859-15?Q?Andr=E9_Hentschel?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121011 Thunderbird/16.0.1 MIME-Version: 1.0 To: linux-arch@vger.kernel.org, will.deacon@arm.com, linux@arm.linux.org.uk, linux-arm-kernel@lists.infradead.org Subject: [PATCH] arm: Preserve TPIDRURW on context switch X-Provags-ID: V02:K0:vr3nRphOD1eJJjDkGbseUstybllQfcBtjEtrRsTS26i 5ZcCNRHsf8e2loE77sPc/ZIb71h4Hmpu6Mw3J1+1lfXFNDXjmn bxhLqQpPPd0LsP5hXj4pLEHjdISluKMYbMxHoDeWoLiw26q9l5 20M7MNTAl+RbYpvqDdkIGEHEvhlQN8X5tDQ4+52j0r2+4nWVxf Ty8W0Qt88HApsvHlVsKi9DseG3G55EdBMRMPEiQMRloSfQ0iWU EL0OE+dZlcbL5WK1a2G103gzB+CoVjkX+kqU0gDmV3TROkRpeY 4/TObUTq5dc0gVCMv5eKuNFNIrLi1QowMPvLe/A4tHWmUF5u83 QUsWzPXgClipnpyLXNeM= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130206_174320_560026_7CB0BFBA X-CRM114-Status: GOOD ( 10.95 ) X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-1.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [212.227.126.187 listed in list.dnswl.org] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Greg KH , linux-kernel@vger.kernel.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org There are more and more applications coming to WinRT, Wine could support them, but mostly they expect to have the thread environment block (TEB) in TPIDRURW. This register must be preserved per thread instead of being cleared. This patch is against 0944c0a03465718909ba8e800a5230528aeabafb I could only test it with kernel 3.4.6 Signed-off-by: André Hentschel From: =?UTF-8?q?Andr=C3=A9=20Hentschel?= Date: Wed, 6 Feb 2013 23:24:54 +0100 Subject: [PATCH] arm: Preserve TPIDRURW on context switch --- arch/arm/include/asm/thread_info.h | 1 + arch/arm/include/asm/tls.h | 43 ++++++++++++++++++++++++++++++++++---- arch/arm/kernel/asm-offsets.c | 1 + arch/arm/kernel/entry-armv.S | 7 +++++++ 4 files changed, 48 insertions(+), 4 deletions(-) diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h index cddda1f..948525c 100644 --- a/arch/arm/include/asm/thread_info.h +++ b/arch/arm/include/asm/thread_info.h @@ -59,6 +59,7 @@ struct thread_info { __u32 syscall; /* syscall number */ __u8 used_cp[16]; /* thread used copro */ unsigned long tp_value; + unsigned long tp2_value; /* userspace read/write thread id register (2) */ #ifdef CONFIG_CRUNCH struct crunch_state crunchstate; #endif diff --git a/arch/arm/include/asm/tls.h b/arch/arm/include/asm/tls.h index 73409e6..3230cf2 100644 --- a/arch/arm/include/asm/tls.h +++ b/arch/arm/include/asm/tls.h @@ -7,8 +7,6 @@ .macro set_tls_v6k, tp, tmp1, tmp2 mcr p15, 0, \tp, c13, c0, 3 @ set TLS register - mov \tmp1, #0 - mcr p15, 0, \tmp1, c13, c0, 2 @ clear user r/w TLS register .endm .macro set_tls_v6, tp, tmp1, tmp2 @@ -17,8 +15,6 @@ mov \tmp2, #0xffff0fff tst \tmp1, #HWCAP_TLS @ hardware TLS available? mcrne p15, 0, \tp, c13, c0, 3 @ yes, set TLS register - movne \tmp1, #0 - mcrne p15, 0, \tmp1, c13, c0, 2 @ clear user r/w TLS register streq \tp, [\tmp2, #-15] @ set TLS value at 0xffff0ff0 .endm @@ -26,24 +22,63 @@ mov \tmp1, #0xffff0fff str \tp, [\tmp1, #-15] @ set TLS value at 0xffff0ff0 .endm + + .macro set_tls2_none, tp2, tmp1, tmp2 + .endm + + .macro set_tls2_v6k, tp2, tmp1, tmp2 + mcr p15, 0, \tp2, c13, c0, 2 @ set TPIDRURW register + .endm + + .macro set_tls2_v6, tp2, tmp1, tmp2 + ldr \tmp1, =elf_hwcap + ldr \tmp1, [\tmp1, #0] + mov \tmp2, #0xffff0fff + tst \tmp1, #HWCAP_TLS @ hardware TLS available? + mcrne p15, 0, \tp2, c13, c0, 2 @ yes, set TPIDRURW register + .endm + + .macro get_tls2_none, tp2, tmp1, tmp2 + .endm + + .macro get_tls2_v6k, tp2, tmp1, tmp2 + mrc p15, 0, \tp2, c13, c0, 2 @ get TPIDRURW register + .endm + + .macro get_tls2_v6, tp2, tmp1, tmp2 + ldr \tmp1, =elf_hwcap + ldr \tmp1, [\tmp1, #0] + mov \tmp2, #0xffff0fff + tst \tmp1, #HWCAP_TLS @ hardware TLS available? + mrcne p15, 0, \tp2, c13, c0, 2 @ yes, get TPIDRURW register + .endm + #endif #ifdef CONFIG_TLS_REG_EMUL #define tls_emu 1 #define has_tls_reg 1 #define set_tls set_tls_none +#define set_tls2 set_tls2_none +#define get_tls2 get_tls2_none #elif defined(CONFIG_CPU_V6) #define tls_emu 0 #define has_tls_reg (elf_hwcap & HWCAP_TLS) #define set_tls set_tls_v6 +#define set_tls2 set_tls2_v6 +#define get_tls2 get_tls2_v6 #elif defined(CONFIG_CPU_32v6K) #define tls_emu 0 #define has_tls_reg 1 #define set_tls set_tls_v6k +#define set_tls2 set_tls2_v6k +#define get_tls2 get_tls2_v6k #else #define tls_emu 0 #define has_tls_reg 0 #define set_tls set_tls_software +#define set_tls2 set_tls2_none +#define get_tls2 get_tls2_none #endif #endif /* __ASMARM_TLS_H */ diff --git a/arch/arm/kernel/asm-offsets.c b/arch/arm/kernel/asm-offsets.c index c985b48..2563f29 100644 --- a/arch/arm/kernel/asm-offsets.c +++ b/arch/arm/kernel/asm-offsets.c @@ -58,6 +58,7 @@ int main(void) DEFINE(TI_CPU_SAVE, offsetof(struct thread_info, cpu_context)); DEFINE(TI_USED_CP, offsetof(struct thread_info, used_cp)); DEFINE(TI_TP_VALUE, offsetof(struct thread_info, tp_value)); + DEFINE(TI_TP2_VALUE, offsetof(struct thread_info, tp2_value)); DEFINE(TI_FPSTATE, offsetof(struct thread_info, fpstate)); #ifdef CONFIG_VFP DEFINE(TI_VFPSTATE, offsetof(struct thread_info, vfpstate)); diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S index 0f82098..39de843 100644 --- a/arch/arm/kernel/entry-armv.S +++ b/arch/arm/kernel/entry-armv.S @@ -737,6 +737,13 @@ ENTRY(__switch_to) ldr r6, [r2, #TI_CPU_DOMAIN] #endif set_tls r3, r4, r5 + + @ preserve TPIDRURW register state + get_tls2 r3, r4, r5 + str r3, [r1, #TI_TP2_VALUE] + ldr r3, [r2, #TI_TP2_VALUE] + set_tls2 r3, r4, r5 + #if defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_SMP) ldr r7, [r2, #TI_TASK] ldr r8, =__stack_chk_guard