Skip to contentSkip to conversation

Consistent TM structures

PATCH Superseded Cyril Bur 3 participants 26 messages Aug 11, 2016 – Aug 15, 2016

Subsystems (3)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Cyril Bur

author
#0 lore raw

v2 cover Consistent TM structures

Hello,

This series has grown considerably from v1.

Similarities with v1 include:
- Selftests are all the same, they have simply been split into several patches with comments from MPE and Daniel Axtens incorporated. It is possible some things slipped through the cracks selftest wise as the focus has been on the final three patches.
- The final three patches have been reworked following extra testing and from review by Simon Guo.

Differences include:
- Patches 2-5 are fixes for existing problems found in the course of verifying the final three patches. In the case of "powerpc: Never giveup a reclaimed thread when enabling kernel {fp, altivec, vsx}" it has proven difficult to narrow down when the bug was introduced. It does not exist in 3.8 when TM was introduced but does exist in 4.4. I was unable to boot 3.13 (or 3.12) in an attempt to further bisect.
- As ptrace code was merged between v1 and v2, work was needed there to make it fit in with the final three patches.

The overall aim of this series may have gotten lost here. The final three patches are the goal here.

Cyril Bur (20):
selftests/powerpc: Compile selftests against headers without AT_HWCAP2
powerpc: Always restore FPU/VEC/VSX if hardware transactional memory
in use
powerpc: Add check_if_tm_restore_required() to giveup_all()
powerpc: Return the new MSR from msr_check_and_set()
powerpc: Never giveup a reclaimed thread when enabling kernel {fp,

    altivec, vsx}

selftests/powerpc: Check for VSX preservation across userspace
preemption
selftests/powerpc: Rework FPU stack placement macros and move to
header file
selftests/powerpc: Move VMX stack frame macros to header file selftests/powerpc: Introduce GPR asm helper header file selftests/powerpc: Add transactional memory defines selftests/powerpc: Allow tests to extend their kill timeout selftests/powerpc: Add TM tcheck helpers in C selftests/powerpc: Check that signals always get delivered selftests/powerpc: Add checks for transactional GPRs in signal
contexts
selftests/powerpc: Add checks for transactional FPUs in signal
contexts
selftests/powerpc: Add checks for transactional VMXs in signal
contexts
selftests/powerpc: Add checks for transactional VSXs in signal
contexts
powerpc: tm: Always use fp_state and vr_state to store live registers
powerpc: tm: Rename transct_(*) to ck(\1)_state
powerpc: Remove do_load_up_transact_{fpu,altivec}

 arch/powerpc/include/asm/processor.h               |  15 +-
 arch/powerpc/include/asm/reg.h                     |   2 +-
 arch/powerpc/include/asm/tm.h                      |   5 -
 arch/powerpc/kernel/asm-offsets.c                  |  12 +-
 arch/powerpc/kernel/fpu.S                          |  26 --
 arch/powerpc/kernel/process.c                      | 119 +++++----
 arch/powerpc/kernel/ptrace.c                       | 278 +++++----------------
 arch/powerpc/kernel/signal.h                       |   8 +-
 arch/powerpc/kernel/signal_32.c                    |  84 +++----
 arch/powerpc/kernel/signal_64.c                    |  59 ++---
 arch/powerpc/kernel/tm.S                           |  94 +++----
 arch/powerpc/kernel/traps.c                        |  12 +-
 arch/powerpc/kernel/vector.S                       |  25 --
 tools/testing/selftests/powerpc/Makefile           |   1 +
 tools/testing/selftests/powerpc/basic_asm.h        |   4 +
 tools/testing/selftests/powerpc/fpu_asm.h          |  81 ++++++
 tools/testing/selftests/powerpc/gpr_asm.h          |  96 +++++++
 tools/testing/selftests/powerpc/harness.c          |   9 +-
 tools/testing/selftests/powerpc/math/Makefile      |   4 +-
 tools/testing/selftests/powerpc/math/fpu_asm.S     |  73 +-----
 tools/testing/selftests/powerpc/math/vmx_asm.S     |  85 +------
 tools/testing/selftests/powerpc/math/vsx_asm.S     |  61 +++++
 tools/testing/selftests/powerpc/math/vsx_preempt.c | 147 +++++++++++
 tools/testing/selftests/powerpc/signal/Makefile    |  12 +
 tools/testing/selftests/powerpc/signal/signal.S    |  50 ++++
 tools/testing/selftests/powerpc/signal/signal.c    | 111 ++++++++
 tools/testing/selftests/powerpc/signal/signal_tm.c | 110 ++++++++
 tools/testing/selftests/powerpc/tm/Makefile        |   8 +-
 .../powerpc/tm/tm-signal-context-chk-fpu.c         |  92 +++++++
 .../powerpc/tm/tm-signal-context-chk-gpr.c         |  90 +++++++
 .../powerpc/tm/tm-signal-context-chk-vmx.c         | 110 ++++++++
 .../powerpc/tm/tm-signal-context-chk-vsx.c         | 125 +++++++++
 tools/testing/selftests/powerpc/tm/tm-signal.S     | 114 +++++++++
 tools/testing/selftests/powerpc/tm/tm.h            |  27 ++
 tools/testing/selftests/powerpc/utils.h            |   9 +-
 tools/testing/selftests/powerpc/vmx_asm.h          |  98 ++++++++
 tools/testing/selftests/powerpc/vsx_asm.h          |  71 ++++++
 37 files changed, 1709 insertions(+), 618 deletions(-)
 create mode 100644 tools/testing/selftests/powerpc/fpu_asm.h
 create mode 100644 tools/testing/selftests/powerpc/gpr_asm.h
 create mode 100644 tools/testing/selftests/powerpc/math/vsx_asm.S
 create mode 100644 tools/testing/selftests/powerpc/math/vsx_preempt.c
 create mode 100644 tools/testing/selftests/powerpc/signal/Makefile
 create mode 100644 tools/testing/selftests/powerpc/signal/signal.S
 create mode 100644 tools/testing/selftests/powerpc/signal/signal.c
 create mode 100644 tools/testing/selftests/powerpc/signal/signal_tm.c
 create mode 100644 tools/testing/selftests/powerpc/tm/tm-signal-context-chk-fpu.c
 create mode 100644 tools/testing/selftests/powerpc/tm/tm-signal-context-chk-gpr.c
 create mode 100644 tools/testing/selftests/powerpc/tm/tm-signal-context-chk-vmx.c
 create mode 100644 tools/testing/selftests/powerpc/tm/tm-signal-context-chk-vsx.c
 create mode 100644 tools/testing/selftests/powerpc/tm/tm-signal.S
 create mode 100644 tools/testing/selftests/powerpc/vmx_asm.h
 create mode 100644 tools/testing/selftests/powerpc/vsx_asm.h
Signature · 1 line
2.9.2
author
#1 lore raw

PATCH v2 1/20 selftests/powerpc: Compile selftests against headers without AT_HWCAP2

It might be nice to compile selftests against older kernels and headers but which may not have HWCAP2.

---
 tools/testing/selftests/powerpc/utils.h | 7 +++++++
 1 file changed, 7 insertions(+)
tools/testing/selftests/powerpc/utils.h +7 -0
index fbd33e5..ecd11b5 100644
@@ -32,10 +32,17 @@ static inline bool have_hwcap(unsigned long ftr)
 	return ((unsigned long)get_auxv_entry(AT_HWCAP) & ftr) == ftr;
 }
 
+#ifdef AT_HWCAP2
 static inline bool have_hwcap2(unsigned long ftr2)
 {
 	return ((unsigned long)get_auxv_entry(AT_HWCAP2) & ftr2) == ftr2;
 }
+#else
+static inline bool have_hwcap2(unsigned long ftr2)
+{
+	return false;
+}
+#endif
 
 /* Yes, this is evil */
 #define FAIL_IF(x)						\
Signature · 1 line
2.9.2
author
#2 lore raw

PATCH v2 2/20 powerpc: Always restore FPU/VEC/VSX if hardware transactional memory in use

In reply to Cyril Bur

Comment from arch/powerpc/kernel/process.c:967:
If userspace is inside a transaction (whether active or suspended) and FP/VMX/VSX instructions have ever been enabled inside that transaction, then we have to keep them enabled and keep the FP/VMX/VSX state loaded while ever the transaction continues. The reason is that if we didn't, and subsequently got a FP/VMX/VSX unavailable interrupt inside a transaction, we don't know whether it's the same transaction, and thus we don't know which of the checkpointed state and the ransactional state to use.

restore_math() restore_fp() and restore_altivec() currently may not restore the registers. It doesn't appear that this is more serious than a performance penalty. If the math registers aren't restored the userspace thread will still be run with the facility disabled. Userspace will not be able to read invalid values. On the first access it will take an facility unavailable exception and the kernel will detected an active transaction, at which point it will abort the transaction. There is the possibility for a pathological case preventing any progress by transactions, however, transactions are never guaranteed to make progress.

Fixes 70fe3d9 ("powerpc: Restore FPU/VEC/VSX if previously used")
---
 arch/powerpc/kernel/process.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
arch/powerpc/kernel/process.c +5 -3
index 58ccf86..a5cdef9 100644
@@ -208,7 +208,7 @@ void enable_kernel_fp(void)
 EXPORT_SYMBOL(enable_kernel_fp);
 
 static int restore_fp(struct task_struct *tsk) {
-	if (tsk->thread.load_fp) {
+	if (tsk->thread.load_fp || MSR_TM_ACTIVE(tsk->thread.regs->msr)) {
 		load_fp_state(&current->thread.fp_state);
 		current->thread.load_fp++;
 		return 1;
@@ -278,7 +278,8 @@ EXPORT_SYMBOL_GPL(flush_altivec_to_thread);
 
 static int restore_altivec(struct task_struct *tsk)
 {
-	if (cpu_has_feature(CPU_FTR_ALTIVEC) && tsk->thread.load_vec) {
+	if (cpu_has_feature(CPU_FTR_ALTIVEC) &&
+		(tsk->thread.load_vec || MSR_TM_ACTIVE(tsk->thread.regs->msr))) {
 		load_vr_state(&tsk->thread.vr_state);
 		tsk->thread.used_vr = 1;
 		tsk->thread.load_vec++;
@@ -464,7 +465,8 @@ void restore_math(struct pt_regs *regs)
 {
 	unsigned long msr;
 
-	if (!current->thread.load_fp && !loadvec(current->thread))
+	if (!MSR_TM_ACTIVE(regs->msr) &&
+		!current->thread.load_fp && !loadvec(current->thread))
 		return;
 
 	msr = regs->msr;
Signature · 1 line
2.9.2
#3 lore raw

Re: [PATCH v2 02/20] powerpc: Always restore FPU/VEC/VSX if hardware transactional memory in use

reproduce: wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # save the attached .config to linux build tree…

Hi Cyril,

[auto build test ERROR on powerpc/next]
[also build test ERROR on v4.8-rc1 next-20160811]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Cyril-Bur/Consistent-TM-structures/20160812-075557
base:   https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git next
config: powerpc-sbc834x_defconfig (attached as .config)
compiler: powerpc-linux-gnu-gcc (Debian 5.4.0-6) 5.4.0 20160609

reproduce:
wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=powerpc

All error/warnings (new ones prefixed by >>):

In file included from arch/powerpc/include/asm/processor.h:13:0,
from arch/powerpc/include/asm/thread_info.h:33, from include/linux/thread_info.h:54,
from include/asm-generic/preempt.h:4,
from ./arch/powerpc/include/generated/asm/preempt.h:1, from include/linux/preempt.h:59,
from include/linux/spinlock.h:50,
from include/linux/seqlock.h:35,
from include/linux/time.h:5,
from include/uapi/linux/timex.h:56,
from include/linux/timex.h:56,
from include/linux/sched.h:19,
from arch/powerpc/kernel/process.c:18:
arch/powerpc/kernel/process.c: In function 'restore_fp':

>> arch/powerpc/include/asm/reg.h:64:23: error: left shift count >= width of type [-Werror=shift-count-overflow]
    #define __MASK(X) (1UL<<(X))
                          ^
>> arch/powerpc/include/asm/reg.h:116:18: note: in expansion of macro '__MASK'
    #define MSR_TS_T __MASK(MSR_TS_T_LG) /*  Transaction Transactional */
                     ^
>> arch/powerpc/include/asm/reg.h:117:22: note: in expansion of macro 'MSR_TS_T'
    #define MSR_TS_MASK (MSR_TS_T | MSR_TS_S)   /* Transaction State bits */
                         ^
>> arch/powerpc/include/asm/reg.h:118:34: note: in expansion of macro 'MSR_TS_MASK'
    #define MSR_TM_ACTIVE(x) (((x) & MSR_TS_MASK) != 0) /* Transaction active? */
                                     ^
>> arch/powerpc/kernel/process.c:211:29: note: in expansion of macro 'MSR_TM_ACTIVE'
     if (tsk->thread.load_fp || MSR_TM_ACTIVE(tsk->thread.regs->msr)) {
                                ^
>> arch/powerpc/include/asm/reg.h:64:23: error: left shift count >= width of type [-Werror=shift-count-overflow]
    #define __MASK(X) (1UL<<(X))
                          ^
   arch/powerpc/include/asm/reg.h:115:18: note: in expansion of macro '__MASK'
    #define MSR_TS_S __MASK(MSR_TS_S_LG) /*  Transaction Suspended */
                     ^
>> arch/powerpc/include/asm/reg.h:117:33: note: in expansion of macro 'MSR_TS_S'
    #define MSR_TS_MASK (MSR_TS_T | MSR_TS_S)   /* Transaction State bits */
                                    ^
>> arch/powerpc/include/asm/reg.h:118:34: note: in expansion of macro 'MSR_TS_MASK'
    #define MSR_TM_ACTIVE(x) (((x) & MSR_TS_MASK) != 0) /* Transaction active? */
                                     ^
>> arch/powerpc/kernel/process.c:211:29: note: in expansion of macro 'MSR_TM_ACTIVE'
     if (tsk->thread.load_fp || MSR_TM_ACTIVE(tsk->thread.regs->msr)) {
                                ^
   arch/powerpc/kernel/process.c: In function 'restore_math':
>> arch/powerpc/include/asm/reg.h:64:23: error: left shift count >= width of type [-Werror=shift-count-overflow]
    #define __MASK(X) (1UL<<(X))
                          ^
>> arch/powerpc/include/asm/reg.h:116:18: note: in expansion of macro '__MASK'
    #define MSR_TS_T __MASK(MSR_TS_T_LG) /*  Transaction Transactional */
                     ^
>> arch/powerpc/include/asm/reg.h:117:22: note: in expansion of macro 'MSR_TS_T'
    #define MSR_TS_MASK (MSR_TS_T | MSR_TS_S)   /* Transaction State bits */
                         ^
>> arch/powerpc/include/asm/reg.h:118:34: note: in expansion of macro 'MSR_TS_MASK'
    #define MSR_TM_ACTIVE(x) (((x) & MSR_TS_MASK) != 0) /* Transaction active? */
                                     ^
   arch/powerpc/kernel/process.c:468:7: note: in expansion of macro 'MSR_TM_ACTIVE'
     if (!MSR_TM_ACTIVE(regs->msr) &&
          ^
>> arch/powerpc/include/asm/reg.h:64:23: error: left shift count >= width of type [-Werror=shift-count-overflow]
    #define __MASK(X) (1UL<<(X))
                          ^
   arch/powerpc/include/asm/reg.h:115:18: note: in expansion of macro '__MASK'
    #define MSR_TS_S __MASK(MSR_TS_S_LG) /*  Transaction Suspended */
                     ^
>> arch/powerpc/include/asm/reg.h:117:33: note: in expansion of macro 'MSR_TS_S'
    #define MSR_TS_MASK (MSR_TS_T | MSR_TS_S)   /* Transaction State bits */
                                    ^
>> arch/powerpc/include/asm/reg.h:118:34: note: in expansion of macro 'MSR_TS_MASK'
    #define MSR_TM_ACTIVE(x) (((x) & MSR_TS_MASK) != 0) /* Transaction active? */
                                     ^
   arch/powerpc/kernel/process.c:468:7: note: in expansion of macro 'MSR_TM_ACTIVE'
     if (!MSR_TM_ACTIVE(regs->msr) &&
          ^

cc1: all warnings being treated as errors

vim +/MSR_TM_ACTIVE +211 arch/powerpc/kernel/process.c

195 EXPORT_SYMBOL_GPL(flush_fp_to_thread);
196
197 void enable_kernel_fp(void)
198 {
199 WARN_ON(preemptible());
200
201 msr_check_and_set(MSR_FP);
202
203 if (current->thread.regs && (current->thread.regs->msr & MSR_FP)) {
204 check_if_tm_restore_required(current);
205 __giveup_fpu(current);
206 }
207 }
208 EXPORT_SYMBOL(enable_kernel_fp);
209
210 static int restore_fp(struct task_struct *tsk) {

 > 211		if (tsk->thread.load_fp || MSR_TM_ACTIVE(tsk->thread.regs->msr)) {

212 load_fp_state(&current->thread.fp_state);
213 current->thread.load_fp++;
214 return 1;
215 }
216 return 0;
217 }
218 #else
219 static int restore_fp(struct task_struct *tsk) { return 0; }

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

author
#4 lore raw

PATCH v2 3/20 powerpc: Add check_if_tm_restore_required() to giveup_all()

In reply to Cyril Bur

giveup_all() causes FPU/VMX/VSX facilitities to be disabled in a threads MSR. If this thread was transactional this should be recorded as reclaiming/recheckpointing code will need to know.

Fixes c208505 ("powerpc: create giveup_all()")
---
 arch/powerpc/kernel/process.c | 1 +
 1 file changed, 1 insertion(+)
arch/powerpc/kernel/process.c +1 -0
index a5cdef9..79f0615 100644
@@ -439,6 +439,7 @@ void giveup_all(struct task_struct *tsk)
 		return;
 
 	msr_check_and_set(msr_all_available);
+	check_if_tm_restore_required(tsk);
 
 #ifdef CONFIG_PPC_FPU
 	if (usermsr & MSR_FP)
Signature · 1 line
2.9.2
author
#5 lore raw

PATCH v2 4/20 powerpc: Return the new MSR from msr_check_and_set()

In reply to Cyril Bur

mfmsr() is a fairly expensive call and callers of msr_check_and_set() may want to make decisions bits in the MSR that it did not change but may not know the value of.

This patch would avoid a two calls to mfmsr().

---
 arch/powerpc/include/asm/reg.h | 2 +-
 arch/powerpc/kernel/process.c  | 4 +++-
 2 files changed, 4 insertions(+), 2 deletions(-)
arch/powerpc/include/asm/reg.h +1 -1
index f69f40f..0a3dde9 100644
@@ -1247,7 +1247,7 @@ static inline void mtmsr_isync(unsigned long val)
 				     : "memory")
 #endif
 
-extern void msr_check_and_set(unsigned long bits);
+extern unsigned long msr_check_and_set(unsigned long bits);
 extern bool strict_msr_control;
 extern void __msr_check_and_clear(unsigned long bits);
 static inline void msr_check_and_clear(unsigned long bits)
arch/powerpc/kernel/process.c +3 -1
index 79f0615..216cf05 100644
@@ -104,7 +104,7 @@ static int __init enable_strict_msr_control(char *str)
 }
 early_param("ppc_strict_facility_enable", enable_strict_msr_control);
 
-void msr_check_and_set(unsigned long bits)
+unsigned long msr_check_and_set(unsigned long bits)
 {
 	unsigned long oldmsr = mfmsr();
 	unsigned long newmsr;
@@ -118,6 +118,8 @@ void msr_check_and_set(unsigned long bits)
 
 	if (oldmsr != newmsr)
 		mtmsr_isync(newmsr);
+
+	return newmsr;
 }
 
 void __msr_check_and_clear(unsigned long bits)
Signature · 1 line
2.9.2
author
#6 lore raw

PATCH v2 5/20 powerpc: Never giveup a reclaimed thread when enabling kernel {fp, altivec, vsx}

In reply to Cyril Bur

After a thread is reclaimed from its active or suspended transactional state the checkpointed state exists on CPU, this state (along with the live/transactional state) has been saved in its entirety by the reclaiming process.

There exists a sequence of events that would cause the kernel to call one of enable_kernel_fp(), enable_kernel_altivec() or enable_kernel_vsx() after a thread has been reclaimed. These functions save away any user state on the CPU so that the kernel can use the registers. Not only is this saving away unnecessary at this point, it is actually incorrect. It causes a save of the checkpointed state to the live structures within the thread struct thus destroying the true live state for that thread.

---
 arch/powerpc/kernel/process.c | 39 ++++++++++++++++++++++++++++++++++++---
 1 file changed, 36 insertions(+), 3 deletions(-)
arch/powerpc/kernel/process.c +36 -3
index 216cf05..0cfbc89 100644
@@ -198,12 +198,23 @@ EXPORT_SYMBOL_GPL(flush_fp_to_thread);
 
 void enable_kernel_fp(void)
 {
+	unsigned long cpumsr;
+
 	WARN_ON(preemptible());
 
-	msr_check_and_set(MSR_FP);
+	cpumsr = msr_check_and_set(MSR_FP);
 
 	if (current->thread.regs && (current->thread.regs->msr & MSR_FP)) {
 		check_if_tm_restore_required(current);
+		/*
+		 * If a thread has already been reclaimed then the
+		 * checkpointed registers are on the CPU but have definitely
+		 * been saved by the reclaim code. Don't need to and *cannot*
+		 * giveup as this would save  to the 'live' structure not the
+		 * checkpointed structure.
+		 */
+		if(!MSR_TM_ACTIVE(cpumsr) && MSR_TM_ACTIVE(current->thread.regs->msr))
+			return;
 		__giveup_fpu(current);
 	}
 }
@@ -250,12 +261,23 @@ EXPORT_SYMBOL(giveup_altivec);
 
 void enable_kernel_altivec(void)
 {
+	unsigned long cpumsr;
+
 	WARN_ON(preemptible());
 
-	msr_check_and_set(MSR_VEC);
+	cpumsr = msr_check_and_set(MSR_VEC);
 
 	if (current->thread.regs && (current->thread.regs->msr & MSR_VEC)) {
 		check_if_tm_restore_required(current);
+		/*
+		 * If a thread has already been reclaimed then the
+		 * checkpointed registers are on the CPU but have definitely
+		 * been saved by the reclaim code. Don't need to and *cannot*
+		 * giveup as this would save  to the 'live' structure not the
+		 * checkpointed structure.
+		 */
+		if(!MSR_TM_ACTIVE(cpumsr) && MSR_TM_ACTIVE(current->thread.regs->msr))
+			return;
 		__giveup_altivec(current);
 	}
 }
@@ -324,12 +346,23 @@ static void save_vsx(struct task_struct *tsk)
 
 void enable_kernel_vsx(void)
 {
+	unsigned long cpumsr;
+
 	WARN_ON(preemptible());
 
-	msr_check_and_set(MSR_FP|MSR_VEC|MSR_VSX);
+	cpumsr = msr_check_and_set(MSR_FP|MSR_VEC|MSR_VSX);
 
 	if (current->thread.regs && (current->thread.regs->msr & MSR_VSX)) {
 		check_if_tm_restore_required(current);
+		/*
+		 * If a thread has already been reclaimed then the
+		 * checkpointed registers are on the CPU but have definitely
+		 * been saved by the reclaim code. Don't need to and *cannot*
+		 * giveup as this would save  to the 'live' structure not the
+		 * checkpointed structure.
+		 */
+		if(!MSR_TM_ACTIVE(cpumsr) && MSR_TM_ACTIVE(current->thread.regs->msr))
+			return;
 		if (current->thread.regs->msr & MSR_FP)
 			__giveup_fpu(current);
 		if (current->thread.regs->msr & MSR_VEC)
Signature · 1 line
2.9.2
author
#7 lore raw

PATCH v2 6/20 selftests/powerpc: Check for VSX preservation across userspace preemption

In reply to Cyril Bur

Ensure the kernel correctly switches VSX registers correctly. VSX registers are all volatile, and despite the kernel preserving VSX across syscalls, it doesn't have to. Test that during interrupts and timeslices ending the VSX regs remain the same.

---
 tools/testing/selftests/powerpc/math/Makefile      |   4 +-
 tools/testing/selftests/powerpc/math/vsx_asm.S     |  61 +++++++++
 tools/testing/selftests/powerpc/math/vsx_preempt.c | 147 +++++++++++++++++++++
 tools/testing/selftests/powerpc/vsx_asm.h          |  71 ++++++++++
 4 files changed, 282 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/powerpc/math/vsx_asm.S
 create mode 100644 tools/testing/selftests/powerpc/math/vsx_preempt.c
 create mode 100644 tools/testing/selftests/powerpc/vsx_asm.h
tools/testing/selftests/powerpc/math/Makefile +3 -1
index 5b88875..aa6598b 100644
@@ -1,4 +1,4 @@
-TEST_PROGS := fpu_syscall fpu_preempt fpu_signal vmx_syscall vmx_preempt vmx_signal
+TEST_PROGS := fpu_syscall fpu_preempt fpu_signal vmx_syscall vmx_preempt vmx_signal vsx_preempt
 
 all: $(TEST_PROGS)
 
@@ -13,6 +13,8 @@ vmx_syscall: vmx_asm.S
 vmx_preempt: vmx_asm.S
 vmx_signal: vmx_asm.S
 
+vsx_preempt: vsx_asm.S
+
 include ../../lib.mk
 
 clean:
tools/testing/selftests/powerpc/math/vsx_asm.S new file +61 -0

61 lines not on this page · raw message

tools/testing/selftests/powerpc/math/vsx_preempt.c new file +147 -0

147 lines not on this page · raw message

tools/testing/selftests/powerpc/vsx_asm.h new file +71 -0

71 lines not on this page · raw message

Signature · 1 line
2.9.2
author
#8 lore raw

PATCH v2 7/20 selftests/powerpc: Rework FPU stack placement macros and move to header file

In reply to Cyril Bur

The FPU regs are placed at the top of the stack frame. Currently the position expected to be passed to the macro. The macros now should be passed the stack frame size and from there they can calculate where to put the regs, this makes the use simpler.

Also move them to a header file to be used in an different area of the powerpc selftests

---
 tools/testing/selftests/powerpc/fpu_asm.h      | 81 ++++++++++++++++++++++++++
 tools/testing/selftests/powerpc/math/fpu_asm.S | 73 ++---------------------
 2 files changed, 86 insertions(+), 68 deletions(-)
 create mode 100644 tools/testing/selftests/powerpc/fpu_asm.h
tools/testing/selftests/powerpc/fpu_asm.h new file +81 -0
new file mode 100644
index 0000000..24061b8
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2016, Cyril Bur, IBM Corp.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#ifndef _SELFTESTS_POWERPC_FPU_ASM_H
+#define _SELFTESTS_POWERPC_FPU_ASM_H
+#include "basic_asm.h"
+
+#define PUSH_FPU(stack_size) \
+	stfd	f31,(stack_size + STACK_FRAME_MIN_SIZE)(%r1); \
+	stfd	f30,(stack_size + STACK_FRAME_MIN_SIZE - 8)(%r1); \
+	stfd	f29,(stack_size + STACK_FRAME_MIN_SIZE - 16)(%r1); \
+	stfd	f28,(stack_size + STACK_FRAME_MIN_SIZE - 24)(%r1); \
+	stfd	f27,(stack_size + STACK_FRAME_MIN_SIZE - 32)(%r1); \
+	stfd	f26,(stack_size + STACK_FRAME_MIN_SIZE - 40)(%r1); \
+	stfd	f25,(stack_size + STACK_FRAME_MIN_SIZE - 48)(%r1); \
+	stfd	f24,(stack_size + STACK_FRAME_MIN_SIZE - 56)(%r1); \
+	stfd	f23,(stack_size + STACK_FRAME_MIN_SIZE - 64)(%r1); \
+	stfd	f22,(stack_size + STACK_FRAME_MIN_SIZE - 72)(%r1); \
+	stfd	f21,(stack_size + STACK_FRAME_MIN_SIZE - 80)(%r1); \
+	stfd	f20,(stack_size + STACK_FRAME_MIN_SIZE - 88)(%r1); \
+	stfd	f19,(stack_size + STACK_FRAME_MIN_SIZE - 96)(%r1); \
+	stfd	f18,(stack_size + STACK_FRAME_MIN_SIZE - 104)(%r1); \
+	stfd	f17,(stack_size + STACK_FRAME_MIN_SIZE - 112)(%r1); \
+	stfd	f16,(stack_size + STACK_FRAME_MIN_SIZE - 120)(%r1); \
+	stfd	f15,(stack_size + STACK_FRAME_MIN_SIZE - 128)(%r1); \
+	stfd	f14,(stack_size + STACK_FRAME_MIN_SIZE - 136)(%r1);
+
+#define POP_FPU(stack_size) \
+	lfd	f31,(stack_size + STACK_FRAME_MIN_SIZE)(%r1); \
+	lfd	f30,(stack_size + STACK_FRAME_MIN_SIZE - 8)(%r1); \
+	lfd	f29,(stack_size + STACK_FRAME_MIN_SIZE - 16)(%r1); \
+	lfd	f28,(stack_size + STACK_FRAME_MIN_SIZE - 24)(%r1); \
+	lfd	f27,(stack_size + STACK_FRAME_MIN_SIZE - 32)(%r1); \
+	lfd	f26,(stack_size + STACK_FRAME_MIN_SIZE - 40)(%r1); \
+	lfd	f25,(stack_size + STACK_FRAME_MIN_SIZE - 48)(%r1); \
+	lfd	f24,(stack_size + STACK_FRAME_MIN_SIZE - 56)(%r1); \
+	lfd	f23,(stack_size + STACK_FRAME_MIN_SIZE - 64)(%r1); \
+	lfd	f22,(stack_size + STACK_FRAME_MIN_SIZE - 72)(%r1); \
+	lfd	f21,(stack_size + STACK_FRAME_MIN_SIZE - 80)(%r1); \
+	lfd	f20,(stack_size + STACK_FRAME_MIN_SIZE - 88)(%r1); \
+	lfd	f19,(stack_size + STACK_FRAME_MIN_SIZE - 96)(%r1); \
+	lfd	f18,(stack_size + STACK_FRAME_MIN_SIZE - 104)(%r1); \
+	lfd	f17,(stack_size + STACK_FRAME_MIN_SIZE - 112)(%r1); \
+	lfd	f16,(stack_size + STACK_FRAME_MIN_SIZE - 120)(%r1); \
+	lfd	f15,(stack_size + STACK_FRAME_MIN_SIZE - 128)(%r1); \
+	lfd	f14,(stack_size + STACK_FRAME_MIN_SIZE - 136)(%r1);
+
+/*
+ * Careful calling this, it will 'clobber' fpu (by design)
+ * Don't call this from C
+ */
+FUNC_START(load_fpu)
+	lfd	f14,0(r3)
+	lfd	f15,8(r3)
+	lfd	f16,16(r3)
+	lfd	f17,24(r3)
+	lfd	f18,32(r3)
+	lfd	f19,40(r3)
+	lfd	f20,48(r3)
+	lfd	f21,56(r3)
+	lfd	f22,64(r3)
+	lfd	f23,72(r3)
+	lfd	f24,80(r3)
+	lfd	f25,88(r3)
+	lfd	f26,96(r3)
+	lfd	f27,104(r3)
+	lfd	f28,112(r3)
+	lfd	f29,120(r3)
+	lfd	f30,128(r3)
+	lfd	f31,136(r3)
+	blr
+FUNC_END(load_fpu)
+
+#endif /* _SELFTESTS_POWERPC_FPU_ASM_H */
+
tools/testing/selftests/powerpc/math/fpu_asm.S +5 -68

108 lines not on this page · raw message

Signature · 1 line
2.9.2
author
#9 lore raw

PATCH v2 8/20 selftests/powerpc: Move VMX stack frame macros to header file

In reply to Cyril Bur
---
 tools/testing/selftests/powerpc/math/vmx_asm.S | 85 +---------------------
 tools/testing/selftests/powerpc/vmx_asm.h      | 98 ++++++++++++++++++++++++++
 2 files changed, 99 insertions(+), 84 deletions(-)
 create mode 100644 tools/testing/selftests/powerpc/vmx_asm.h
tools/testing/selftests/powerpc/math/vmx_asm.S +1 -84
index 1b8c248..fd74da4 100644
@@ -8,90 +8,7 @@
  */
 
 #include "../basic_asm.h"
-
-# POS MUST BE 16 ALIGNED!
-#define PUSH_VMX(pos,reg) \
-	li	reg,pos; \
-	stvx	v20,reg,sp; \
-	addi	reg,reg,16; \
-	stvx	v21,reg,sp; \
-	addi	reg,reg,16; \
-	stvx	v22,reg,sp; \
-	addi	reg,reg,16; \
-	stvx	v23,reg,sp; \
-	addi	reg,reg,16; \
-	stvx	v24,reg,sp; \
-	addi	reg,reg,16; \
-	stvx	v25,reg,sp; \
-	addi	reg,reg,16; \
-	stvx	v26,reg,sp; \
-	addi	reg,reg,16; \
-	stvx	v27,reg,sp; \
-	addi	reg,reg,16; \
-	stvx	v28,reg,sp; \
-	addi	reg,reg,16; \
-	stvx	v29,reg,sp; \
-	addi	reg,reg,16; \
-	stvx	v30,reg,sp; \
-	addi	reg,reg,16; \
-	stvx	v31,reg,sp;
-
-# POS MUST BE 16 ALIGNED!
-#define POP_VMX(pos,reg) \
-	li	reg,pos; \
-	lvx	v20,reg,sp; \
-	addi	reg,reg,16; \
-	lvx	v21,reg,sp; \
-	addi	reg,reg,16; \
-	lvx	v22,reg,sp; \
-	addi	reg,reg,16; \
-	lvx	v23,reg,sp; \
-	addi	reg,reg,16; \
-	lvx	v24,reg,sp; \
-	addi	reg,reg,16; \
-	lvx	v25,reg,sp; \
-	addi	reg,reg,16; \
-	lvx	v26,reg,sp; \
-	addi	reg,reg,16; \
-	lvx	v27,reg,sp; \
-	addi	reg,reg,16; \
-	lvx	v28,reg,sp; \
-	addi	reg,reg,16; \
-	lvx	v29,reg,sp; \
-	addi	reg,reg,16; \
-	lvx	v30,reg,sp; \
-	addi	reg,reg,16; \
-	lvx	v31,reg,sp;
-
-# Carefull this will 'clobber' vmx (by design)
-# Don't call this from C
-FUNC_START(load_vmx)
-	li	r5,0
-	lvx	v20,r5,r3
-	addi	r5,r5,16
-	lvx	v21,r5,r3
-	addi	r5,r5,16
-	lvx	v22,r5,r3
-	addi	r5,r5,16
-	lvx	v23,r5,r3
-	addi	r5,r5,16
-	lvx	v24,r5,r3
-	addi	r5,r5,16
-	lvx	v25,r5,r3
-	addi	r5,r5,16
-	lvx	v26,r5,r3
-	addi	r5,r5,16
-	lvx	v27,r5,r3
-	addi	r5,r5,16
-	lvx	v28,r5,r3
-	addi	r5,r5,16
-	lvx	v29,r5,r3
-	addi	r5,r5,16
-	lvx	v30,r5,r3
-	addi	r5,r5,16
-	lvx	v31,r5,r3
-	blr
-FUNC_END(load_vmx)
+#include "../vmx_asm.h"
 
 # Should be safe from C, only touches r4, r5 and v0,v1,v2
 FUNC_START(check_vmx)
tools/testing/selftests/powerpc/vmx_asm.h new file +98 -0

98 lines not on this page · raw message

Signature · 1 line
2.9.2
author
#10 lore raw

PATCH v2 9/20 selftests/powerpc: Introduce GPR asm helper header file

In reply to Cyril Bur
---
 tools/testing/selftests/powerpc/gpr_asm.h | 96 +++++++++++++++++++++++++++++++
 1 file changed, 96 insertions(+)
 create mode 100644 tools/testing/selftests/powerpc/gpr_asm.h
tools/testing/selftests/powerpc/gpr_asm.h new file +96 -0
new file mode 100644
index 0000000..f6f3885
@@ -0,0 +1,96 @@
+/*
+ * Copyright 2016, Cyril Bur, IBM Corp.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#ifndef _SELFTESTS_POWERPC_GPR_ASM_H
+#define _SELFTESTS_POWERPC_GPR_ASM_H
+
+#include "basic_asm.h"
+
+#define __PUSH_NVREGS(top_pos); \
+	std r31,(top_pos)(%r1); \
+	std r30,(top_pos - 8)(%r1); \
+	std r29,(top_pos - 16)(%r1); \
+	std r28,(top_pos - 24)(%r1); \
+	std r27,(top_pos - 32)(%r1); \
+	std r26,(top_pos - 40)(%r1); \
+	std r25,(top_pos - 48)(%r1); \
+	std r24,(top_pos - 56)(%r1); \
+	std r23,(top_pos - 64)(%r1); \
+	std r22,(top_pos - 72)(%r1); \
+	std r21,(top_pos - 80)(%r1); \
+	std r20,(top_pos - 88)(%r1); \
+	std r19,(top_pos - 96)(%r1); \
+	std r18,(top_pos - 104)(%r1); \
+	std r17,(top_pos - 112)(%r1); \
+	std r16,(top_pos - 120)(%r1); \
+	std r15,(top_pos - 128)(%r1); \
+	std r14,(top_pos - 136)(%r1)
+
+#define __POP_NVREGS(top_pos); \
+	ld r31,(top_pos)(%r1); \
+	ld r30,(top_pos - 8)(%r1); \
+	ld r29,(top_pos - 16)(%r1); \
+	ld r28,(top_pos - 24)(%r1); \
+	ld r27,(top_pos - 32)(%r1); \
+	ld r26,(top_pos - 40)(%r1); \
+	ld r25,(top_pos - 48)(%r1); \
+	ld r24,(top_pos - 56)(%r1); \
+	ld r23,(top_pos - 64)(%r1); \
+	ld r22,(top_pos - 72)(%r1); \
+	ld r21,(top_pos - 80)(%r1); \
+	ld r20,(top_pos - 88)(%r1); \
+	ld r19,(top_pos - 96)(%r1); \
+	ld r18,(top_pos - 104)(%r1); \
+	ld r17,(top_pos - 112)(%r1); \
+	ld r16,(top_pos - 120)(%r1); \
+	ld r15,(top_pos - 128)(%r1); \
+	ld r14,(top_pos - 136)(%r1)
+
+#define PUSH_NVREGS(stack_size) \
+	__PUSH_NVREGS(stack_size + STACK_FRAME_MIN_SIZE)
+
+/* 18 NV FPU REGS */
+#define PUSH_NVREGS_BELOW_FPU(stack_size) \
+	__PUSH_NVREGS(stack_size + STACK_FRAME_MIN_SIZE - (18 * 8))
+
+#define POP_NVREGS(stack_size) \
+	__POP_NVREGS(stack_size + STACK_FRAME_MIN_SIZE)
+
+/* 18 NV FPU REGS */
+#define POP_NVREGS_BELOW_FPU(stack_size) \
+	__POP_NVREGS(stack_size + STACK_FRAME_MIN_SIZE - (18 * 8))
+
+/*
+ * Careful calling this, it will 'clobber' NVGPRs (by design)
+ * Don't call this from C
+ */
+FUNC_START(load_gpr)
+	ld	r14,0(r3)
+	ld	r15,8(r3)
+	ld	r16,16(r3)
+	ld	r17,24(r3)
+	ld	r18,32(r3)
+	ld	r19,40(r3)
+	ld	r20,48(r3)
+	ld	r21,56(r3)
+	ld	r22,64(r3)
+	ld	r23,72(r3)
+	ld	r24,80(r3)
+	ld	r25,88(r3)
+	ld	r26,96(r3)
+	ld	r27,104(r3)
+	ld	r28,112(r3)
+	ld	r29,120(r3)
+	ld	r30,128(r3)
+	ld	r31,136(r3)
+	blr
+FUNC_END(load_gpr)
+
+
+#endif /* _SELFTESTS_POWERPC_GPR_ASM_H */
Signature · 1 line
2.9.2
author
#11 lore raw

PATCH v2 10/20 selftests/powerpc: Add transactional memory defines

In reply to Cyril Bur
---
 tools/testing/selftests/powerpc/basic_asm.h | 4 ++++
 1 file changed, 4 insertions(+)
tools/testing/selftests/powerpc/basic_asm.h +4 -0
index 3349a07..5131059 100644
@@ -4,6 +4,10 @@
 #include <ppc-asm.h>
 #include <asm/unistd.h>
 
+#define TBEGIN .long 0x7C00051D
+#define TSUSPEND .long 0x7C0005DD
+#define TRESUME .long 0x7C2005DD
+
 #define LOAD_REG_IMMEDIATE(reg,expr) \
 	lis	reg,(expr)@highest;	\
 	ori	reg,reg,(expr)@higher;	\
Signature · 1 line
2.9.2
author
#12 lore raw

PATCH v2 11/20 selftests/powerpc: Allow tests to extend their kill timeout

In reply to Cyril Bur
---
 tools/testing/selftests/powerpc/harness.c | 9 +++++++--
 tools/testing/selftests/powerpc/utils.h   | 2 +-
 2 files changed, 8 insertions(+), 3 deletions(-)
tools/testing/selftests/powerpc/harness.c +7 -2
index 52f9be7..248a820 100644
@@ -19,9 +19,9 @@
 #include "subunit.h"
 #include "utils.h"
 
-#define TIMEOUT		120
 #define KILL_TIMEOUT	5
 
+static uint64_t timeout = 120;
 
 int run_test(int (test_function)(void), char *name)
 {
@@ -44,7 +44,7 @@ int run_test(int (test_function)(void), char *name)
 	setpgid(pid, pid);
 
 	/* Wake us up in timeout seconds */
-	alarm(TIMEOUT);
+	alarm(timeout);
 	terminated = false;
 
 wait:
@@ -94,6 +94,11 @@ static struct sigaction alarm_action = {
 	.sa_handler = alarm_handler,
 };
 
+void test_harness_set_timeout(uint64_t time)
+{
+	timeout = time;
+}
+
 int test_harness(int (test_function)(void), char *name)
 {
 	int rc;
tools/testing/selftests/powerpc/utils.h +1 -1
index ecd11b5..53405e8 100644
@@ -22,7 +22,7 @@ typedef uint32_t u32;
 typedef uint16_t u16;
 typedef uint8_t u8;
 
-
+void test_harness_set_timeout(uint64_t time);
 int test_harness(int (test_function)(void), char *name);
 extern void *get_auxv_entry(int type);
 int pick_online_cpu(void);
Signature · 1 line
2.9.2
author
#13 lore raw

PATCH v2 12/20 selftests/powerpc: Add TM tcheck helpers in C

In reply to Cyril Bur
---
 tools/testing/selftests/powerpc/tm/tm.h | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
tools/testing/selftests/powerpc/tm/tm.h +27 -0
index 60318ba..2c8da74 100644
@@ -52,4 +52,31 @@ static inline bool failure_is_nesting(void)
 	return (__builtin_get_texasru() & 0x400000);
 }
 
+static inline int tcheck(void)
+{
+	long cr;
+	asm volatile ("tcheck 0" : "=r"(cr) : : "cr0");
+	return (cr >> 28) & 4;
+}
+
+static inline bool tcheck_doomed(void)
+{
+	return tcheck() & 8;
+}
+
+static inline bool tcheck_active(void)
+{
+	return tcheck() & 4;
+}
+
+static inline bool tcheck_suspended(void)
+{
+	return tcheck() & 2;
+}
+
+static inline bool tcheck_transactional(void)
+{
+	return tcheck() & 6;
+}
+
 #endif /* _SELFTESTS_POWERPC_TM_TM_H */
Signature · 1 line
2.9.2
author
#14 lore raw

PATCH v2 13/20 selftests/powerpc: Check that signals always get delivered

In reply to Cyril Bur
---
 tools/testing/selftests/powerpc/Makefile           |   1 +
 tools/testing/selftests/powerpc/signal/Makefile    |  12 +++
 tools/testing/selftests/powerpc/signal/signal.S    |  50 ++++++++++
 tools/testing/selftests/powerpc/signal/signal.c    | 111 +++++++++++++++++++++
 tools/testing/selftests/powerpc/signal/signal_tm.c | 110 ++++++++++++++++++++
 5 files changed, 284 insertions(+)
 create mode 100644 tools/testing/selftests/powerpc/signal/Makefile
 create mode 100644 tools/testing/selftests/powerpc/signal/signal.S
 create mode 100644 tools/testing/selftests/powerpc/signal/signal.c
 create mode 100644 tools/testing/selftests/powerpc/signal/signal_tm.c
tools/testing/selftests/powerpc/Makefile +1 -0
index 3c40c9d..96a8593 100644
@@ -19,6 +19,7 @@ SUB_DIRS = alignment		\
 	   dscr			\
 	   mm			\
 	   pmu			\
+	   signal		\
 	   primitives		\
 	   stringloops		\
 	   switch_endian	\
tools/testing/selftests/powerpc/signal/Makefile new file +12 -0
new file mode 100644
index 0000000..97944cf
@@ -0,0 +1,12 @@
+TEST_PROGS := signal signal_tm
+
+all: $(TEST_PROGS)
+
+$(TEST_PROGS): ../harness.c ../utils.c signal.S
+
+signal_tm: CFLAGS += -mhtm
+
+include ../../lib.mk
+
+clean:
+	rm -f $(TEST_PROGS) *.o
tools/testing/selftests/powerpc/signal/signal.S new file +50 -0

50 lines not on this page · raw message

tools/testing/selftests/powerpc/signal/signal.c new file +111 -0

111 lines not on this page · raw message

tools/testing/selftests/powerpc/signal/signal_tm.c new file +110 -0

110 lines not on this page · raw message

Signature · 1 line
2.9.2
author
#15 lore raw

PATCH v2 14/20 selftests/powerpc: Add checks for transactional GPRs in signal contexts

In reply to Cyril Bur

If a thread receives a signal while transactional the kernel creates a second context to show the transactional state of the process. This test loads some known values and waits for a signal and confirms that the expected values are in the signal context.

---
 tools/testing/selftests/powerpc/tm/Makefile        |   7 +-
 .../powerpc/tm/tm-signal-context-chk-gpr.c         |  90 ++++++++++++++++
 tools/testing/selftests/powerpc/tm/tm-signal.S     | 114 +++++++++++++++++++++
 3 files changed, 210 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/powerpc/tm/tm-signal-context-chk-gpr.c
 create mode 100644 tools/testing/selftests/powerpc/tm/tm-signal.S
tools/testing/selftests/powerpc/tm/Makefile +6 -1
index 9d301d7..2b6fe8f 100644
@@ -1,5 +1,7 @@
+SIGNAL_CONTEXT_CHK_TESTS := tm-signal-context-chk-gpr
+
 TEST_PROGS := tm-resched-dscr tm-syscall tm-signal-msr-resv tm-signal-stack \
-	tm-vmxcopy tm-fork tm-tar tm-tmspr tm-exec tm-execed
+	tm-vmxcopy tm-fork tm-tar tm-tmspr $(SIGNAL_CONTEXT_CHK_TESTS)
 
 all: $(TEST_PROGS)
 
@@ -11,6 +13,9 @@ tm-syscall: tm-syscall-asm.S
 tm-syscall: CFLAGS += -I../../../../../usr/include
 tm-tmspr: CFLAGS += -pthread
 
+$(SIGNAL_CONTEXT_CHK_TESTS): tm-signal.S
+$(SIGNAL_CONTEXT_CHK_TESTS): CFLAGS += -mhtm -m64
+
 include ../../lib.mk
 
 clean:
tools/testing/selftests/powerpc/tm/tm-signal-context-chk-gpr.c new file +90 -0

90 lines not on this page · raw message

tools/testing/selftests/powerpc/tm/tm-signal.S new file +114 -0

114 lines not on this page · raw message

Signature · 1 line
2.9.2
author
#16 lore raw

PATCH v2 15/20 selftests/powerpc: Add checks for transactional FPUs in signal contexts

In reply to Cyril Bur

If a thread receives a signal while transactional the kernel creates a second context to show the transactional state of the process. This test loads some known values and waits for a signal and confirms that the expected values are in the signal context.

---
 tools/testing/selftests/powerpc/tm/Makefile        |  2 +-
 .../powerpc/tm/tm-signal-context-chk-fpu.c         | 92 ++++++++++++++++++++++
 2 files changed, 93 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/powerpc/tm/tm-signal-context-chk-fpu.c
tools/testing/selftests/powerpc/tm/Makefile +1 -1
index 2b6fe8f..103648f 100644
@@ -1,4 +1,4 @@
-SIGNAL_CONTEXT_CHK_TESTS := tm-signal-context-chk-gpr
+SIGNAL_CONTEXT_CHK_TESTS := tm-signal-context-chk-gpr tm-signal-context-chk-fpu
 
 TEST_PROGS := tm-resched-dscr tm-syscall tm-signal-msr-resv tm-signal-stack \
 	tm-vmxcopy tm-fork tm-tar tm-tmspr $(SIGNAL_CONTEXT_CHK_TESTS)
tools/testing/selftests/powerpc/tm/tm-signal-context-chk-fpu.c new file +92 -0

92 lines not on this page · raw message

Signature · 1 line
2.9.2
author
#17 lore raw

PATCH v2 16/20 selftests/powerpc: Add checks for transactional VMXs in signal contexts

In reply to Cyril Bur

If a thread receives a signal while transactional the kernel creates a second context to show the transactional state of the process. This test loads some known values and waits for a signal and confirms that the expected values are in the signal context.

---
 tools/testing/selftests/powerpc/tm/Makefile        |   3 +-
 .../powerpc/tm/tm-signal-context-chk-vmx.c         | 110 +++++++++++++++++++++
 2 files changed, 112 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/powerpc/tm/tm-signal-context-chk-vmx.c
tools/testing/selftests/powerpc/tm/Makefile +2 -1
index 103648f..06c44aa 100644
@@ -1,4 +1,5 @@
-SIGNAL_CONTEXT_CHK_TESTS := tm-signal-context-chk-gpr tm-signal-context-chk-fpu
+SIGNAL_CONTEXT_CHK_TESTS := tm-signal-context-chk-gpr tm-signal-context-chk-fpu \
+	tm-signal-context-chk-vmx
 
 TEST_PROGS := tm-resched-dscr tm-syscall tm-signal-msr-resv tm-signal-stack \
 	tm-vmxcopy tm-fork tm-tar tm-tmspr $(SIGNAL_CONTEXT_CHK_TESTS)
tools/testing/selftests/powerpc/tm/tm-signal-context-chk-vmx.c new file +110 -0

110 lines not on this page · raw message

Signature · 1 line
2.9.2
author
#18 lore raw

PATCH v2 17/20 selftests/powerpc: Add checks for transactional VSXs in signal contexts

In reply to Cyril Bur

If a thread receives a signal while transactional the kernel creates a second context to show the transactional state of the process. This test loads some known values and waits for a signal and confirms that the expected values are in the signal context.

---
 tools/testing/selftests/powerpc/tm/Makefile        |   2 +-
 .../powerpc/tm/tm-signal-context-chk-vsx.c         | 125 +++++++++++++++++++++
 2 files changed, 126 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/powerpc/tm/tm-signal-context-chk-vsx.c
tools/testing/selftests/powerpc/tm/Makefile +1 -1
index 06c44aa..9d53f8b 100644
@@ -1,5 +1,5 @@
 SIGNAL_CONTEXT_CHK_TESTS := tm-signal-context-chk-gpr tm-signal-context-chk-fpu \
-	tm-signal-context-chk-vmx
+	tm-signal-context-chk-vmx tm-signal-context-chk-vsx
 
 TEST_PROGS := tm-resched-dscr tm-syscall tm-signal-msr-resv tm-signal-stack \
 	tm-vmxcopy tm-fork tm-tar tm-tmspr $(SIGNAL_CONTEXT_CHK_TESTS)
tools/testing/selftests/powerpc/tm/tm-signal-context-chk-vsx.c new file +125 -0

125 lines not on this page · raw message

Signature · 1 line
2.9.2
author
#19 lore raw

PATCH v2 18/20 powerpc: tm: Always use fp_state and vr_state to store live registers

In reply to Cyril Bur

There is currently an inconsistency as to how the entire CPU register state is saved and restored when a thread uses transactional memory (TM).

Using transactional memory results in the CPU having duplicated (almost all) of its register state. This duplication results in a set of registers which can be considered 'live', those being currently modified by the instructions being executed and another set that is frozen at a point in time.

On context switch, both sets of state have to be saved and (later) restored. These two states are often called a variety of different things. Common terms for the state which only exists after has entered a transaction (performed a TBEGIN instruction) in hardware is the 'transactional' or 'speculative'.

Between a TBEGIN and a TEND or TABORT (or an event that causes the hardware to abort), regardless of the use of TSUSPEND the transactional state can be referred to as the live state.

The second state is often to referred to as the 'checkpointed' state and is a duplication of the live state when the TBEGIN instruction is executed. This state is kept in the hardware and will be rolled back to on transaction failure.

Currently all the registers stored in pt_regs are ALWAYS the live registers, that is, when a thread has transactional registers their values are stored in pt_regs and the checkpointed state is in ckpt_regs. A strange opposite is true for fp_state. When a thread is non transactional fp_state holds the live registers. When a thread has initiated a transaction fp_state holds the checkpointed state and transact_fp becomes the structure which holds the live state (at this point it is a transactional state). The same is true for vr_state

This method creates confusion as to where the live state is, in some circumstances it requires extra work to determine where to put the live state and prevents the use of common functions designed (probably before TM) to save the live state.

With this patch pt_regs, fp_state and vr_state all represent the same thing and the other structures [pending rename] are for checkpointed state.

---
 arch/powerpc/include/asm/processor.h |   7 +-
 arch/powerpc/kernel/process.c        |  63 +++-----
 arch/powerpc/kernel/ptrace.c         | 278 +++++++++--------------------------
 arch/powerpc/kernel/signal_32.c      |  50 +++----
 arch/powerpc/kernel/signal_64.c      |  53 +++----
 arch/powerpc/kernel/tm.S             |  94 ++++++------
 arch/powerpc/kernel/traps.c          |  12 +-
 7 files changed, 196 insertions(+), 361 deletions(-)
arch/powerpc/include/asm/processor.h +2 -5
index 68e3bf5..feab2ce 100644
@@ -267,16 +267,13 @@ struct thread_struct {
 	unsigned long	tm_dscr;
 
 	/*
-	 * Transactional FP and VSX 0-31 register set.
-	 * NOTE: the sense of these is the opposite of the integer ckpt_regs!
+	 * Checkpointed FP and VSX 0-31 register set.
 	 *
 	 * When a transaction is active/signalled/scheduled etc., *regs is the
 	 * most recent set of/speculated GPRs with ckpt_regs being the older
 	 * checkpointed regs to which we roll back if transaction aborts.
 	 *
-	 * However, fpr[] is the checkpointed 'base state' of FP regs, and
-	 * transact_fpr[] is the new set of transactional values.
-	 * VRs work the same way.
+	 * These are analogous to how ckpt_regs and pt_regs work
 	 */
 	struct thread_fp_state transact_fp;
 	struct thread_vr_state transact_vr;
arch/powerpc/kernel/process.c +21 -42

130 lines not on this page · raw message

arch/powerpc/kernel/ptrace.c +68 -210

581 lines not on this page · raw message

arch/powerpc/kernel/signal_32.c +23 -27

136 lines not on this page · raw message

arch/powerpc/kernel/signal_64.c +24 -29

142 lines not on this page · raw message

arch/powerpc/kernel/tm.S +50 -44

145 lines not on this page · raw message

arch/powerpc/kernel/traps.c +8 -4
index f7e2f2e..8e2304c9 100644
@@ -1498,7 +1498,8 @@ void fp_unavailable_tm(struct pt_regs *regs)
 
 	/* If VMX is in use, get the transactional values back */
 	if (regs->msr & MSR_VEC) {
-		do_load_up_transact_altivec(&current->thread);
+		msr_check_and_set(MSR_VEC);
+		load_vr_state(&current->thread.vr_state);
 		/* At this point all the VSX state is loaded, so enable it */
 		regs->msr |= MSR_VSX;
 	}
@@ -1519,7 +1520,8 @@ void altivec_unavailable_tm(struct pt_regs *regs)
 	current->thread.used_vr = 1;
 
 	if (regs->msr & MSR_FP) {
-		do_load_up_transact_fpu(&current->thread);
+		msr_check_and_set(MSR_FP);
+		load_fp_state(&current->thread.fp_state);
 		regs->msr |= MSR_VSX;
 	}
 }
@@ -1558,10 +1560,12 @@ void vsx_unavailable_tm(struct pt_regs *regs)
 	 */
 	tm_recheckpoint(&current->thread, regs->msr & ~orig_msr);
 
+	msr_check_and_set(orig_msr & (MSR_FP | MSR_VEC));
+
 	if (orig_msr & MSR_FP)
-		do_load_up_transact_fpu(&current->thread);
+		load_fp_state(&current->thread.fp_state);
 	if (orig_msr & MSR_VEC)
-		do_load_up_transact_altivec(&current->thread);
+		load_vr_state(&current->thread.vr_state);
 }
 #endif /* CONFIG_PPC_TRANSACTIONAL_MEM */
 
Signature · 1 line
2.9.2
#20 lore raw

Re: [PATCH v2 18/20] powerpc: tm: Always use fp_state and vr_state to store live registers

Quoted 16 lines · Cyril Bur
arch/powerpc/kernel/process.c +3 -1
@@ -846,7 +834,9 @@ static void tm_reclaim_thread(struct thread_struct *thr,
 	if (!MSR_TM_SUSPENDED(mfmsr()))
 		return;
 
-	tm_reclaim(thr, thr->regs->msr, cause);
+	giveup_all(container_of(thr, struct task_struct, thread));
+
+	tm_reclaim(thr, msr_diff, cause);
 
 	/* Having done the reclaim, we now have the checkpointed
 	 * FP/VSX values in the registers.  These might be valid
@@ -1189,11 +1171,11 @@ struct task_struct *__switch_to(struct task_struct *prev,
 	 */
 	save_sprs(&prev->thread);
 

arch/powerpc/kernel/process.c struct task_struct *__switch_to(struct task_struct *prev, · line 1181

Quoted 10 lines
arch/powerpc/kernel/process.c +2 -2
-	__switch_to_tm(prev);
-
 	/* Save FPU, Altivec, VSX and SPE state */
 	giveup_all(prev);
 
+	__switch_to_tm(prev, new);
+
 	/*
 	 * We can't take a PMU exception inside _switch() since there is a
 	 * window where the kernel stack SLB and the kernel stack are out

There are 2 "giveall_all()" in above path:
__switch_to()

        giveup_all()  // first time
        __switch_to_tm()
                tm_reclaim_task()
                        tm_reclaim_thread()
                                giveup_all()  // again????

We should remove the one in __switch_to().

And another question, for following code in tm_reclaim_thread():
/* Having done the reclaim, we now have the checkpointed
* FP/VSX values in the registers. These might be valid
* even if we have previously called enable_kernel_fp() or
* flush_fp_to_thread(), so update thr->regs->msr to
* indicate their current validity.
*/
thr->regs->msr |= msr_diff;

Does it imply the task being switched out of CPU, with TIF_RESTORE_TM bit set, might end with MSR_FP enabled? (I thought MSR_FP should not be enabled for a switched out task, as specified in flush_fp_to_thread())

Thanks,
- Simon

author
#21 lore raw

Re: [PATCH v2 18/20] powerpc: tm: Always use fp_state and vr_state to store live registers

Quoted 35 lines · Simon Guo
Quoted 27 lines · Cyril Bur
arch/powerpc/kernel/process.c +0 -0
@@ -846,7 +834,9 @@ static void tm_reclaim_thread(struct
 thread_struct *thr,
  	if (!MSR_TM_SUSPENDED(mfmsr()))
  		return;

arch/powerpc/kernel/process.c +3 -1
-	tm_reclaim(thr, thr->regs->msr, cause);
+	giveup_all(container_of(thr, struct task_struct, thread));
+
+	tm_reclaim(thr, msr_diff, cause);


  /* Having done the reclaim, we now have the checkpointed
   * FP/VSX values in the registers.  These might be valid

arch/powerpc/kernel/process.c +0 -0
@@ -1189,11 +1171,11 @@ struct task_struct *__switch_to(struct
 task_struct *prev,
  	 */
  	save_sprs(&prev->thread);

arch/powerpc/kernel/process.c +0 -2
-	__switch_to_tm(prev);
-

  /* Save FPU, Altivec, VSX and SPE state */ giveup_all(prev);

arch/powerpc/kernel/process.c +2 -0
+	__switch_to_tm(prev, new);
+
Quoted 5 lines

  /*
   * We can't take a PMU exception inside _switch() since there is a
   * window where the kernel stack SLB and the kernel stack are out

Quoted 8 lines

There are 2 "giveall_all()" in above path:
__switch_to()
        giveup_all()  // first time __switch_to_tm()
                tm_reclaim_task() tm_reclaim_thread() giveup_all()  // again???? We should remove the one in __switch_to().

I don't think that will be possible, if a thread is not transactional the second giveup_all() won't get called so we'll need to preserve the one in __switch_to().
I don't think removing the second is a good idea as we can enter tm_reclaim_thread() from other means than __switch_to_tm(). I did think that perhaps __switch_to_tm() could call giveup_all() in the non transactional case but on reflection, doing nothing on the non transactional case is cleaner.
The two calls are annoying but in the case where two calls are made, the second should realise that nothing needs to be done and exit quickly.

Quoted 9 lines

And another question, for following code in tm_reclaim_thread():
        /* Having done the reclaim, we now have the checkpointed
         * FP/VSX values in the registers.  These might be valid
         * even if we have previously called enable_kernel_fp() or
         * flush_fp_to_thread(), so update thr->regs->msr to
         * indicate their current validity.
         */
        thr->regs->msr |= msr_diff;

Quoted 5 lines

Does it imply the task being switched out of CPU, with TIF_RESTORE_TM bit set,  might end with MSR_FP enabled? (I thought MSR_FP should not
be enabled for a switched out task, as specified in flush_fp_to_thread())

Correct! I mistakenly thought it was solving a problem but you're right. What you say is correct but it breaks signals, I've been hesitating on how to get signals to work with the correct solution here, I wasn't happy with my ideas but looks like it's pretty much the only way to go unfortunately.

Thanks,
Cyril

Quoted 3 lines

Thanks,
- Simon

#22 lore raw

Re: [PATCH v2 18/20] powerpc: tm: Always use fp_state and vr_state to store live registers

Hi Cyril,

Quoted 9 lines · Cyril Bur
Quoted 8 lines

There are 2 "giveall_all()" in above path:
__switch_to()
        giveup_all()  // first time __switch_to_tm()
                tm_reclaim_task() tm_reclaim_thread() giveup_all()  // again???? We should remove the one in __switch_to().

Quoted 11 lines

I don't think that will be possible, if a thread is not transactional the second giveup_all() won't get called so we'll need to preserve the one in __switch_to().
I don't think removing the second is a good idea as we can enter tm_reclaim_thread() from other means than __switch_to_tm(). I did think that perhaps __switch_to_tm() could call giveup_all() in the non transactional case but on reflection, doing nothing on the non transactional case is cleaner.
The two calls are annoying but in the case where two calls are made, the second should realise that nothing needs to be done and exit quickly.

Ah, yes. I somehow ignored non-transactional case....

Quoted 16 lines
Quoted 10 lines

And another question, for following code in tm_reclaim_thread():
        /* Having done the reclaim, we now have the checkpointed
         * FP/VSX values in the registers.  These might be valid
         * even if we have previously called enable_kernel_fp() or
         * flush_fp_to_thread(), so update thr->regs->msr to
         * indicate their current validity.
         */
        thr->regs->msr |= msr_diff;

Quoted 5 lines

Does it imply the task being switched out of CPU, with TIF_RESTORE_TM bit set,  might end with MSR_FP enabled? (I thought MSR_FP should not
be enabled for a switched out task, as specified in flush_fp_to_thread())

Quoted 5 lines

Correct! I mistakenly thought it was solving a problem but you're right. What you say is correct but it breaks signals, I've been hesitating on how to get signals to work with the correct solution here, I wasn't happy with my ideas but looks like it's pretty much the only way to go unfortunately.

Currently there will be an oops on flush_fp_to_thread() with this patch, when ptrace a transaction application.

I think originally there is no giveup_all() call before tm_reclaim_thread(), so TIF_RESTORE_TM bit is not set. And finally thr->regs->msr is not marked with MSR_FP enabled.

[  363.473851] kernel BUG at arch/powerpc/kernel/process.c:191!
[  363.474242] Oops: Exception in kernel mode, sig: 5 [#1]
[  363.474595] SMP NR_CPUS=2048 NUMA pSeries
[  363.474956] Modules linked in: isofs sg virtio_balloon ip_tables xfs libcrc32c sr_mod cdrom sd_mod virtio_net ibmvscsi scsi_transport_srp virtio_pci virtio_ring virtio
[  363.476021] CPU: 0 PID: 3018 Comm: ptrace-tm-gpr Not tainted 4.8.0-rc1+ #5
[  363.476547] task: c000000072c66b80 task.stack: c00000007e64c000
[  363.476949] NIP: c000000000017650 LR: c00000000000dc10 CTR: c000000000011538
[  363.477428] REGS: c00000007e64f960 TRAP: 0700   Not tainted (4.8.0-rc1+)
[  363.477948] MSR: 8000000000029033 <SF,EE,ME,IR,DR,RI,LE>  CR: 42000088  XER: 20000000
[  363.478488] CFAR: c000000000017620 SOFTE: 1 

GPR00: c00000000000dc10 c00000007e64fbe0 c000000000f3d800 c000000072c65600
GPR04: c0000000008706a8 0000000000000000 0000000000000108 0000000000000000
GPR08: 0000010008410180 0000000000000001 0000000000000001 c000000000870f18
GPR12: 0000000000000000 c00000000fe80000 0000000000000000 0000000000000000
GPR16: 0000000000000000 0000000000000000 0000000000000000 0000000000000000
GPR20: 0000000000000000 0000000000000000 0000000000000000 0000000000000000
GPR24: 0000000000000000 0000000000000000 0000000000000000 0000010008410180
GPR28: 0000000000000000 0000000000000000 0000000000000108 c000000072c65600

[  363.482451] NIP [c000000000017650] flush_fp_to_thread+0x50/0x70
[  363.482855] LR [c00000000000dc10] fpr_get+0x40/0x120
[  363.483194] Call Trace:
[  363.483362] [c00000007e64fbe0] [c00000007e64fcf0] 0xc00000007e64fcf0 (unreliable)
[  363.483872] [c00000007e64fc00] [c00000000000dc10] fpr_get+0x40/0x120
[  363.484304] [c00000007e64fd60] [c000000000011578] arch_ptrace+0x628/0x7e0
[  363.485811] [c00000007e64fde0] [c0000000000c3340] SyS_ptrace+0xa0/0x180
[  363.486276] [c00000007e64fe30] [c000000000009404] system_call+0x38/0xec
[  363.486725] Instruction dump:
[  363.486927] 40820010 4e800020 60000000 60420000 7c0802a6 f8010010 f821ffe1 e92d0210 
[  363.487459] 7c694a78 7d290074 7929d182 69290001 <0b090000> 4bffff25 38210020 e8010010 
[  363.488005] ---[ end trace 58650a99c675b48c ]---
[  363.490137] 
[  365.490279] Kernel panic - not syncing: Fatal exception

Thanks,
- Simon

author
#23 lore raw

Re: [PATCH v2 18/20] powerpc: tm: Always use fp_state and vr_state to store live registers

Quoted 110 lines · Simon Guo

Hi Cyril,

Quoted 11 lines · Cyril Bur
Quoted 10 lines

There are 2 "giveall_all()" in above path:
__switch_to()
        giveup_all()  // first time __switch_to_tm()
                tm_reclaim_task() tm_reclaim_thread() giveup_all()  // again???? We should remove the one in __switch_to().

Quoted 16 lines

I don't think that will be possible, if a thread is not transactional
the second giveup_all() won't get called so we'll need to preserve the
one in __switch_to().
I don't think removing the second is a good idea as we can enter tm_reclaim_thread() from other means than __switch_to_tm(). I did think that perhaps __switch_to_tm() could call giveup_all() in
the non transactional case but on reflection, doing nothing on the non
transactional case is cleaner.
The two calls are annoying but in the case where two calls are made,
the second should realise that nothing needs to be done and exit quickly.

Ah, yes. I somehow ignored non-transactional case....

Quoted 20 lines
Quoted 13 lines

And another question, for following code in tm_reclaim_thread():
        /* Having done the reclaim, we now have the checkpointed
         * FP/VSX values in the registers.  These might be valid
         * even if we have previously called enable_kernel_fp() or
         * flush_fp_to_thread(), so update thr->regs->msr to
         * indicate their current validity.
         */
        thr->regs->msr |= msr_diff;

Quoted 6 lines

Does it imply the task being switched out of CPU, with TIF_RESTORE_TM
bit set,  might end with MSR_FP enabled? (I thought MSR_FP should not
be enabled for a switched out task, as specified in flush_fp_to_thread())

Quoted 6 lines

Correct! I mistakenly thought it was solving a problem but you're right. What you say is correct but it breaks signals, I've been hesitating on how to get signals to work with the correct solution here, I wasn't happy with my ideas but looks like it's pretty much the
only way to go unfortunately.

Currently there will be an oops on flush_fp_to_thread() with this patch, when ptrace a transaction application.

I think originally there is no giveup_all() call before tm_reclaim_thread(),
so TIF_RESTORE_TM bit is not set. And finally thr->regs->msr is not marked with MSR_FP enabled.

[  363.473851] kernel BUG at arch/powerpc/kernel/process.c:191! [  363.474242] Oops: Exception in kernel mode, sig: 5 [#1] [  363.474595] SMP NR_CPUS=2048 NUMA pSeries
[  363.474956] Modules linked in: isofs sg virtio_balloon ip_tables xfs libcrc32c sr_mod cdrom sd_mod virtio_net ibmvscsi scsi_transport_srp virtio_pci virtio_ring virtio
[  363.476021] CPU: 0 PID: 3018 Comm: ptrace-tm-gpr Not tainted 4.8.0-rc1+ #5
[  363.476547] task: c000000072c66b80 task.stack: c00000007e64c000 [  363.476949] NIP: c000000000017650 LR: c00000000000dc10 CTR:
c000000000011538
[  363.477428] REGS: c00000007e64f960 TRAP: 0700   Not tainted (4.8.0-rc1+)
[  363.477948] MSR: 8000000000029033 <SF,EE,ME,IR,DR,RI,LE>  CR:
42000088  XER: 20000000
[  363.478488] CFAR: c000000000017620 SOFTE: 1
GPR00: c00000000000dc10 c00000007e64fbe0 c000000000f3d800 c000000072c65600
GPR04: c0000000008706a8 0000000000000000 0000000000000108 0000000000000000
GPR08: 0000010008410180 0000000000000001 0000000000000001 c000000000870f18
GPR12: 0000000000000000 c00000000fe80000 0000000000000000 0000000000000000
GPR16: 0000000000000000 0000000000000000 0000000000000000 0000000000000000
GPR20: 0000000000000000 0000000000000000 0000000000000000 0000000000000000
GPR24: 0000000000000000 0000000000000000 0000000000000000 0000010008410180
GPR28: 0000000000000000 0000000000000000 0000000000000108 c000000072c65600
[  363.482451] NIP [c000000000017650] flush_fp_to_thread+0x50/0x70 [  363.482855] LR [c00000000000dc10] fpr_get+0x40/0x120 [  363.483194] Call Trace:
[  363.483362] [c00000007e64fbe0] [c00000007e64fcf0] 0xc00000007e64fcf0 (unreliable)
[  363.483872] [c00000007e64fc00] [c00000000000dc10] fpr_get+0x40/0x120
[  363.484304] [c00000007e64fd60] [c000000000011578] arch_ptrace+0x628/0x7e0
[  363.485811] [c00000007e64fde0] [c0000000000c3340] SyS_ptrace+0xa0/0x180
[  363.486276] [c00000007e64fe30] [c000000000009404] system_call+0x38/0xec

Quoted 9 lines

[  363.486725] Instruction dump:
[  363.486927] 40820010 4e800020 60000000 60420000 7c0802a6 f8010010 f821ffe1 e92d0210
[  363.487459] 7c694a78 7d290074 7929d182 69290001 <0b090000> 4bffff25 38210020 e8010010
[  363.488005] ---[ end trace 58650a99c675b48c ]---
[  363.490137]
[  365.490279] Kernel panic - not syncing: Fatal exception

Yeah so that is to do with the problem you found, TM code shouldn't be leaving MSR_{FP,VEC,VSX} on after a switch. I sort of found myself cleaning up a bit of the signal code to solve this nicely.

Hopefully v3 today!

Quoted 2 lines

Thanks,
- Simon

author
#24 lore raw

PATCH v2 19/20 powerpc: tm: Rename transct_(*) to ck(\1)_state

In reply to Cyril Bur

Make the structures being used for checkpointed state named consistently with the pt_regs/ckpt_regs.

---
 arch/powerpc/include/asm/processor.h |  8 ++---
 arch/powerpc/kernel/asm-offsets.c    | 12 ++++----
 arch/powerpc/kernel/fpu.S            |  2 +-
 arch/powerpc/kernel/process.c        |  4 +--
 arch/powerpc/kernel/ptrace.c         | 46 +++++++++++++--------------
 arch/powerpc/kernel/signal.h         |  8 ++---
 arch/powerpc/kernel/signal_32.c      | 60 ++++++++++++++++++------------------
 arch/powerpc/kernel/signal_64.c      | 32 +++++++++----------
 arch/powerpc/kernel/tm.S             | 12 ++++----
 arch/powerpc/kernel/vector.S         |  4 +--
 10 files changed, 94 insertions(+), 94 deletions(-)
arch/powerpc/include/asm/processor.h +4 -4
index feab2ce..b3e0cfc 100644
@@ -147,7 +147,7 @@ typedef struct {
 } mm_segment_t;
 
 #define TS_FPR(i) fp_state.fpr[i][TS_FPROFFSET]
-#define TS_TRANS_FPR(i) transact_fp.fpr[i][TS_FPROFFSET]
+#define TS_CKFPR(i) ckfp_state.fpr[i][TS_FPROFFSET]
 
 /* FP and VSX 0-31 register set */
 struct thread_fp_state {
@@ -275,9 +275,9 @@ struct thread_struct {
 	 *
 	 * These are analogous to how ckpt_regs and pt_regs work
 	 */
-	struct thread_fp_state transact_fp;
-	struct thread_vr_state transact_vr;
-	unsigned long	transact_vrsave;
+	struct thread_fp_state ckfp_state; /* Checkpointed FP state */
+	struct thread_vr_state ckvr_state; /* Checkpointed VR state */
+	unsigned long	ckvrsave; /* Checkpointed VRSAVE */
 #endif /* CONFIG_PPC_TRANSACTIONAL_MEM */
 #ifdef CONFIG_KVM_BOOK3S_32_HANDLER
 	void*		kvm_shadow_vcpu; /* KVM internal data */
arch/powerpc/kernel/asm-offsets.c +6 -6
index b89d14c..dd0fc33 100644
@@ -142,12 +142,12 @@ int main(void)
 	DEFINE(THREAD_TM_PPR, offsetof(struct thread_struct, tm_ppr));
 	DEFINE(THREAD_TM_DSCR, offsetof(struct thread_struct, tm_dscr));
 	DEFINE(PT_CKPT_REGS, offsetof(struct thread_struct, ckpt_regs));
-	DEFINE(THREAD_TRANSACT_VRSTATE, offsetof(struct thread_struct,
-						 transact_vr));
-	DEFINE(THREAD_TRANSACT_VRSAVE, offsetof(struct thread_struct,
-					    transact_vrsave));
-	DEFINE(THREAD_TRANSACT_FPSTATE, offsetof(struct thread_struct,
-						 transact_fp));
+	DEFINE(THREAD_CKVRSTATE, offsetof(struct thread_struct,
+						 ckvr_state));
+	DEFINE(THREAD_CKVRSAVE, offsetof(struct thread_struct,
+					    ckvrsave));
+	DEFINE(THREAD_CKFPSTATE, offsetof(struct thread_struct,
+						 ckfp_state));
 	/* Local pt_regs on stack for Transactional Memory funcs. */
 	DEFINE(TM_FRAME_SIZE, STACK_FRAME_OVERHEAD +
 	       sizeof(struct pt_regs) + 16);
arch/powerpc/kernel/fpu.S +1 -1
index 15da2b5..181c187 100644
@@ -68,7 +68,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_VSX)
 	SYNC
 	MTMSRD(r5)
 
-	addi	r7,r3,THREAD_TRANSACT_FPSTATE
+	addi	r7,r3,THREAD_CKFPSTATE
 	lfd	fr0,FPSTATE_FPSCR(r7)
 	MTFSF_L(fr0)
 	REST_32FPVSRS(0, R4, R7)
arch/powerpc/kernel/process.c +2 -2
index 6836570..5216e04 100644
@@ -860,8 +860,8 @@ static inline void tm_reclaim_task(struct task_struct *tsk)
 	 *
 	 * In switching we need to maintain a 2nd register state as
 	 * oldtask->thread.ckpt_regs.  We tm_reclaim(oldproc); this saves the
-	 * checkpointed (tbegin) state in ckpt_regs and saves the transactional
-	 * (current) FPRs into oldtask->thread.transact_fpr[].
+	 * checkpointed (tbegin) state in ckpt_regs, ckfp_state and
+	 * ckvr_state
 	 *
 	 * We also context switch (save) TFHAR/TEXASR/TFIAR in here.
 	 */
arch/powerpc/kernel/ptrace.c +23 -23

169 lines not on this page · raw message

arch/powerpc/kernel/signal.h +4 -4
index be305c8..b1cebf66 100644
@@ -23,20 +23,20 @@ extern int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset,
 
 extern unsigned long copy_fpr_to_user(void __user *to,
 				      struct task_struct *task);
-extern unsigned long copy_transact_fpr_to_user(void __user *to,
+extern unsigned long copy_ckfpr_to_user(void __user *to,
 					       struct task_struct *task);
 extern unsigned long copy_fpr_from_user(struct task_struct *task,
 					void __user *from);
-extern unsigned long copy_transact_fpr_from_user(struct task_struct *task,
+extern unsigned long copy_ckfpr_from_user(struct task_struct *task,
 						 void __user *from);
 #ifdef CONFIG_VSX
 extern unsigned long copy_vsx_to_user(void __user *to,
 				      struct task_struct *task);
-extern unsigned long copy_transact_vsx_to_user(void __user *to,
+extern unsigned long copy_ckvsx_to_user(void __user *to,
 					       struct task_struct *task);
 extern unsigned long copy_vsx_from_user(struct task_struct *task,
 					void __user *from);
-extern unsigned long copy_transact_vsx_from_user(struct task_struct *task,
+extern unsigned long copy_ckvsx_from_user(struct task_struct *task,
 						 void __user *from);
 #endif
 
arch/powerpc/kernel/signal_32.c +30 -30

195 lines not on this page · raw message

arch/powerpc/kernel/signal_64.c +16 -16
index 53db2b3..45ae2e7 100644
@@ -222,7 +222,7 @@ static long setup_tm_sigcontexts(struct sigcontext __user *sc,
 	/* save altivec registers */
 	if (current->thread.used_vr) {
 		/* Copy 33 vec registers (vr0..31 and vscr) to the stack */
-		err |= __copy_to_user(v_regs, &current->thread.transact_vr,
+		err |= __copy_to_user(v_regs, &current->thread.ckvr_state,
 				      33 * sizeof(vector128));
 		/* If VEC was enabled there are transactional VRs valid too,
 		 * else they're a copy of the checkpointed VRs.
@@ -233,7 +233,7 @@ static long setup_tm_sigcontexts(struct sigcontext __user *sc,
 					      33 * sizeof(vector128));
 		else
 			err |= __copy_to_user(tm_v_regs,
-					      &current->thread.transact_vr,
+					      &current->thread.ckvr_state,
 					      33 * sizeof(vector128));
 
 		/* set MSR_VEC in the MSR value in the frame to indicate
@@ -245,13 +245,13 @@ static long setup_tm_sigcontexts(struct sigcontext __user *sc,
 	 * use altivec.
 	 */
 	if (cpu_has_feature(CPU_FTR_ALTIVEC))
-		current->thread.transact_vrsave = mfspr(SPRN_VRSAVE);
-	err |= __put_user(current->thread.transact_vrsave, (u32 __user *)&v_regs[33]);
+		current->thread.ckvrsave = mfspr(SPRN_VRSAVE);
+	err |= __put_user(current->thread.ckvrsave, (u32 __user *)&v_regs[33]);
 	if (msr & MSR_VEC)
 		err |= __put_user(current->thread.vrsave,
 				  (u32 __user *)&tm_v_regs[33]);
 	else
-		err |= __put_user(current->thread.transact_vrsave,
+		err |= __put_user(current->thread.ckvrsave,
 				  (u32 __user *)&tm_v_regs[33]);
 
 #else /* CONFIG_ALTIVEC */
@@ -260,11 +260,11 @@ static long setup_tm_sigcontexts(struct sigcontext __user *sc,
 #endif /* CONFIG_ALTIVEC */
 
 	/* copy fpr regs and fpscr */
-	err |= copy_transact_fpr_to_user(&sc->fp_regs, current);
+	err |= copy_ckfpr_to_user(&sc->fp_regs, current);
 	if (msr & MSR_FP)
 		err |= copy_fpr_to_user(&tm_sc->fp_regs, current);
 	else
-		err |= copy_transact_fpr_to_user(&tm_sc->fp_regs, current);
+		err |= copy_ckfpr_to_user(&tm_sc->fp_regs, current);
 
 #ifdef CONFIG_VSX
 	/*
@@ -276,12 +276,12 @@ static long setup_tm_sigcontexts(struct sigcontext __user *sc,
 		v_regs += ELF_NVRREG;
 		tm_v_regs += ELF_NVRREG;
 
-		err |= copy_transact_vsx_to_user(v_regs, current);
+		err |= copy_ckvsx_to_user(v_regs, current);
 
 		if (msr & MSR_VSX)
 			err |= copy_vsx_to_user(tm_v_regs, current);
 		else
-			err |= copy_transact_vsx_to_user(tm_v_regs, current);
+			err |= copy_ckvsx_to_user(tm_v_regs, current);
 
 		/* set MSR_VSX in the MSR value in the frame to
 		 * indicate that sc->vs_reg) contains valid data.
@@ -480,32 +480,32 @@ static long restore_tm_sigcontexts(struct pt_regs *regs,
 		return -EFAULT;
 	/* Copy 33 vec registers (vr0..31 and vscr) from the stack */
 	if (v_regs != NULL && tm_v_regs != NULL && (msr & MSR_VEC) != 0) {
-		err |= __copy_from_user(&current->thread.transact_vr, v_regs,
+		err |= __copy_from_user(&current->thread.ckvr_state, v_regs,
 					33 * sizeof(vector128));
 		err |= __copy_from_user(&current->thread.vr_state, tm_v_regs,
 					33 * sizeof(vector128));
 	}
 	else if (current->thread.used_vr) {
 		memset(&current->thread.vr_state, 0, 33 * sizeof(vector128));
-		memset(&current->thread.transact_vr, 0, 33 * sizeof(vector128));
+		memset(&current->thread.ckvr_state, 0, 33 * sizeof(vector128));
 	}
 	/* Always get VRSAVE back */
 	if (v_regs != NULL && tm_v_regs != NULL) {
-		err |= __get_user(current->thread.transact_vrsave,
+		err |= __get_user(current->thread.ckvrsave,
 				  (u32 __user *)&v_regs[33]);
 		err |= __get_user(current->thread.vrsave,
 				  (u32 __user *)&tm_v_regs[33]);
 	}
 	else {
 		current->thread.vrsave = 0;
-		current->thread.transact_vrsave = 0;
+		current->thread.ckvrsave = 0;
 	}
 	if (cpu_has_feature(CPU_FTR_ALTIVEC))
 		mtspr(SPRN_VRSAVE, current->thread.vrsave);
 #endif /* CONFIG_ALTIVEC */
 	/* restore floating point */
 	err |= copy_fpr_from_user(current, &tm_sc->fp_regs);
-	err |= copy_transact_fpr_from_user(current, &sc->fp_regs);
+	err |= copy_ckfpr_from_user(current, &sc->fp_regs);
 #ifdef CONFIG_VSX
 	/*
 	 * Get additional VSX data. Update v_regs to point after the
@@ -516,11 +516,11 @@ static long restore_tm_sigcontexts(struct pt_regs *regs,
 		v_regs += ELF_NVRREG;
 		tm_v_regs += ELF_NVRREG;
 		err |= copy_vsx_from_user(current, tm_v_regs);
-		err |= copy_transact_vsx_from_user(current, v_regs);
+		err |= copy_ckvsx_from_user(current, v_regs);
 	} else {
 		for (i = 0; i < 32 ; i++) {
 			current->thread.fp_state.fpr[i][TS_VSRLOWOFFSET] = 0;
-			current->thread.transact_fp.fpr[i][TS_VSRLOWOFFSET] = 0;
+			current->thread.ckfp_state.fpr[i][TS_VSRLOWOFFSET] = 0;
 		}
 	}
 #endif
arch/powerpc/kernel/tm.S +6 -6
index 7b7088d..3a2d041 100644
@@ -257,19 +257,19 @@ _GLOBAL(tm_reclaim)
 	andis.		r0, r4, MSR_VEC@h
 	beq	dont_backup_vec
 
-	addi	r7, r3, THREAD_TRANSACT_VRSTATE
+	addi	r7, r3, THREAD_CKVRSTATE
 	SAVE_32VRS(0, r6, r7)	/* r6 scratch, r7 transact vr state */
 	mfvscr	v0
 	li	r6, VRSTATE_VSCR
 	stvx	v0, r7, r6
 dont_backup_vec:
 	mfspr	r0, SPRN_VRSAVE
-	std	r0, THREAD_TRANSACT_VRSAVE(r3)
+	std	r0, THREAD_CKVRSAVE(r3)
 
 	andi.	r0, r4, MSR_FP
 	beq	dont_backup_fp
 
-	addi	r7, r3, THREAD_TRANSACT_FPSTATE
+	addi	r7, r3, THREAD_CKFPSTATE
 	SAVE_32FPRS_VSRS(0, R6, R7)	/* r6 scratch, r7 transact fp state */
 
 	mffs    fr0
@@ -370,20 +370,20 @@ _GLOBAL(__tm_recheckpoint)
 	andis.	r0, r4, MSR_VEC@h
 	beq	dont_restore_vec
 
-	addi	r8, r3, THREAD_TRANSACT_VRSTATE
+	addi	r8, r3, THREAD_CKVRSTATE
 	li	r5, VRSTATE_VSCR
 	lvx	v0, r8, r5
 	mtvscr	v0
 	REST_32VRS(0, r5, r8)			/* r5 scratch, r8 ptr */
 dont_restore_vec:
-	ld	r5, THREAD_TRANSACT_VRSAVE(r3)
+	ld	r5, THREAD_CKVRSAVE(r3)
 	mtspr	SPRN_VRSAVE, r5
 #endif
 
 	andi.	r0, r4, MSR_FP
 	beq	dont_restore_fp
 
-	addi	r8, r3, THREAD_TRANSACT_FPSTATE
+	addi	r8, r3, THREAD_CKFPSTATE
 	lfd	fr0, FPSTATE_FPSCR(r8)
 	MTFSF_L(fr0)
 	REST_32FPRS_VSRS(0, R4, R8)
arch/powerpc/kernel/vector.S +2 -2
index 616a6d8..7dc4021 100644
@@ -23,10 +23,10 @@ _GLOBAL(do_load_up_transact_altivec)
 	li	r4,1
 	stw	r4,THREAD_USED_VR(r3)
 
-	li	r10,THREAD_TRANSACT_VRSTATE+VRSTATE_VSCR
+	li	r10,THREAD_CKVRSTATE+VRSTATE_VSCR
 	lvx	v0,r10,r3
 	mtvscr	v0
-	addi	r10,r3,THREAD_TRANSACT_VRSTATE
+	addi	r10,r3,THREAD_CKVRSTATE
 	REST_32VRS(0,r4,r10)
 
 	blr
Signature · 1 line
2.9.2
author
#25 lore raw

PATCH v2 20/20 powerpc: Remove do_load_up_transact_{fpu,altivec}

In reply to Cyril Bur

Previous rework of TM code leaves these functions unused

---
 arch/powerpc/include/asm/tm.h |  5 -----
 arch/powerpc/kernel/fpu.S     | 26 --------------------------
 arch/powerpc/kernel/vector.S  | 25 -------------------------
 3 files changed, 56 deletions(-)
arch/powerpc/include/asm/tm.h +0 -5
index c22d704..82e06ca 100644
@@ -9,11 +9,6 @@
 
 #ifndef __ASSEMBLY__
 
-#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
-extern void do_load_up_transact_fpu(struct thread_struct *thread);
-extern void do_load_up_transact_altivec(struct thread_struct *thread);
-#endif
-
 extern void tm_enable(void);
 extern void tm_reclaim(struct thread_struct *thread,
 		       unsigned long orig_msr, uint8_t cause);
arch/powerpc/kernel/fpu.S +0 -26
index 181c187..08d14b0 100644
@@ -50,32 +50,6 @@ END_FTR_SECTION_IFSET(CPU_FTR_VSX);					\
 #define REST_32FPVSRS(n,c,base) __REST_32FPVSRS(n,__REG_##c,__REG_##base)
 #define SAVE_32FPVSRS(n,c,base) __SAVE_32FPVSRS(n,__REG_##c,__REG_##base)
 
-#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
-/* void do_load_up_transact_fpu(struct thread_struct *thread)
- *
- * This is similar to load_up_fpu but for the transactional version of the FP
- * register set.  It doesn't mess with the task MSR or valid flags.
- * Furthermore, we don't do lazy FP with TM currently.
- */
-_GLOBAL(do_load_up_transact_fpu)
-	mfmsr	r6
-	ori	r5,r6,MSR_FP
-#ifdef CONFIG_VSX
-BEGIN_FTR_SECTION
-	oris	r5,r5,MSR_VSX@h
-END_FTR_SECTION_IFSET(CPU_FTR_VSX)
-#endif
-	SYNC
-	MTMSRD(r5)
-
-	addi	r7,r3,THREAD_CKFPSTATE
-	lfd	fr0,FPSTATE_FPSCR(r7)
-	MTFSF_L(fr0)
-	REST_32FPVSRS(0, R4, R7)
-
-	blr
-#endif /* CONFIG_PPC_TRANSACTIONAL_MEM */
-
 /*
  * Load state from memory into FP registers including FPSCR.
  * Assumes the caller has enabled FP in the MSR.
arch/powerpc/kernel/vector.S +0 -25
index 7dc4021..bc85bdf 100644
@@ -7,31 +7,6 @@
 #include <asm/page.h>
 #include <asm/ptrace.h>
 
-#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
-/* void do_load_up_transact_altivec(struct thread_struct *thread)
- *
- * This is similar to load_up_altivec but for the transactional version of the
- * vector regs.  It doesn't mess with the task MSR or valid flags.
- * Furthermore, VEC laziness is not supported with TM currently.
- */
-_GLOBAL(do_load_up_transact_altivec)
-	mfmsr	r6
-	oris	r5,r6,MSR_VEC@h
-	MTMSRD(r5)
-	isync
-
-	li	r4,1
-	stw	r4,THREAD_USED_VR(r3)
-
-	li	r10,THREAD_CKVRSTATE+VRSTATE_VSCR
-	lvx	v0,r10,r3
-	mtvscr	v0
-	addi	r10,r3,THREAD_CKVRSTATE
-	REST_32VRS(0,r4,r10)
-
-	blr
-#endif
-
 /*
  * Load state from memory into VMX registers including VSCR.
  * Assumes the caller has enabled VMX in the MSR.
Signature · 1 line
2.9.2