Add new PowerPC specific ELF core notes
Subsystems (4)
v4 cover Add new PowerPC specific ELF core notes
This patch series adds five new ELF core note sections which can be
used with existing ptrace request PTRACE_GETREGSET-SETREGSET for accessing various transactional memory and miscellaneous debug register sets on PowerPC platform.
Previous versions:
==================
RFC: https://lkml.org/lkml/2014/4/1/292 V1: https://lkml.org/lkml/2014/4/2/43 V2: https://lkml.org/lkml/2014/5/5/88 V3: https://lkml.org/lkml/2014/5/23/486
Changes in V4:
--------------
- Added one test program into the powerpc selftest bucket in this regard
- Split the 2nd patch in the previous series into four different patches
- Accommodated most of the review comments on the previous patch series
- Added a patch to merge functions __switch_to_tm and tm_reclaim_task
Changes in V3:
--------------
- Added two new error paths in every TM related get/set functions when regset support is not present on the system (ENODEV) or when the process does not have any transaction active (ENODATA) in the context
- Installed the active hooks for all the newly added regset core note types
Changes in V2:
--------------
- Removed all the power specific ptrace requests corresponding to new NT_PPC_* elf core note types. Now all the register sets can be accessed from ptrace through PTRACE_GETREGSET/PTRACE_SETREGSET using the individual NT_PPC* core note type instead
- Fixed couple of attribute values for REGSET_TM_CGPR register set
- Renamed flush_tmreg_to_thread as flush_tmregs_to_thread
- Fixed 32 bit checkpointed GPR support
- Changed commit messages accordingly
Test Result
-----------
The patch series has been verified both in 32 bit and 64 bit compiled mode. Test result for the selftest test (64 bit compiled mode) can be found here.
test: tm_ptrace
tags: git_version:v3.18-rc4-9-g000adb7 =============Testing TM based PTRACE calls============== -------TM Specific SPR------
TFHAR: 10000cc8
TEXASR: de0000018c000001
TFIAR: c0000000000414f0
TM ORIG_MSR: 50000f032
TM CH DSCR: a (PASSED)
TM CH TAR: 14 (PASSED)
TM CH PPR: 8000000000000 (PASSED)
-------TM Checkpointed GPR-----
TM CH NIP: 10000cc8
TM CH LINK: 10000af8
TM CH CCR: 22000422
TM CH GPR[0]: 0 (PASSED)
TM CH GPR[1]: 1 (PASSED)
TM CH GPR[2]: 2 (PASSED)
TM CH GPR[3]: 3 (PASSED)
TM CH GPR[4]: 4 (PASSED)
TM CH GPR[5]: 5 (PASSED)
TM CH GPR[6]: 6 (PASSED)
TM CH GPR[7]: 7 (PASSED)
TM CH GPR[8]: 8 (PASSED)
TM CH GPR[9]: 9 (PASSED)
TM CH GPR[10]: a (PASSED)
TM CH GPR[11]: b (PASSED)
TM CH GPR[12]: c (PASSED)
TM CH GPR[13]: d (PASSED)
TM CH GPR[14]: e (PASSED)
TM CH GPR[15]: f (PASSED)
TM CH GPR[16]: 0 (PASSED)
TM CH GPR[17]: 1 (PASSED)
TM CH GPR[18]: 2 (PASSED)
TM CH GPR[19]: 3 (PASSED)
TM CH GPR[20]: 4 (PASSED)
TM CH GPR[21]: 5 (PASSED)
TM CH GPR[22]: 6 (PASSED)
TM CH GPR[23]: 7 (PASSED)
TM CH GPR[24]: 8 (PASSED)
TM CH GPR[25]: 9 (PASSED)
TM CH GPR[26]: a (PASSED)
TM CH GPR[27]: b (PASSED)
TM CH GPR[28]: c (PASSED)
TM CH GPR[29]: d (PASSED)
TM CH GPR[30]: e (PASSED)
TM CH GPR[31]: f (PASSED)
-------TM Checkpointed FPR-----
TM CH FPSCR: 0
TM CH FPR[0]: 0 (PASSED)
TM CH FPR[1]: 1 (PASSED)
TM CH FPR[2]: 2 (PASSED)
TM CH FPR[3]: 3 (PASSED)
TM CH FPR[4]: 4 (PASSED)
TM CH FPR[5]: 5 (PASSED)
TM CH FPR[6]: 6 (PASSED)
TM CH FPR[7]: 7 (PASSED)
TM CH FPR[8]: 8 (PASSED)
TM CH FPR[9]: 9 (PASSED)
TM CH FPR[10]: a (PASSED)
TM CH FPR[11]: b (PASSED)
TM CH FPR[12]: c (PASSED)
TM CH FPR[13]: d (PASSED)
TM CH FPR[14]: e (PASSED)
TM CH FPR[15]: f (PASSED)
TM CH FPR[16]: 0 (PASSED)
TM CH FPR[17]: 1 (PASSED)
TM CH FPR[18]: 2 (PASSED)
TM CH FPR[19]: 3 (PASSED)
TM CH FPR[20]: 4 (PASSED)
TM CH FPR[21]: 5 (PASSED)
TM CH FPR[22]: 6 (PASSED)
TM CH FPR[23]: 7 (PASSED)
TM CH FPR[24]: 8 (PASSED)
TM CH FPR[25]: 9 (PASSED)
TM CH FPR[26]: a (PASSED)
TM CH FPR[27]: b (PASSED)
TM CH FPR[28]: c (PASSED)
TM CH FPR[29]: d (PASSED)
TM CH FPR[30]: e (PASSED)
TM CH FPR[31]: f (PASSED)
-------TM Running GPR-----
TM RN NIP: 10000de0
TM RN LINK: 10000af8
TM RN CCR: 2000422
TM RN GPR[0]: f (PASSED)
TM RN GPR[1]: e (PASSED)
TM RN GPR[2]: d (PASSED)
TM RN GPR[3]: c (PASSED)
TM RN GPR[4]: b (PASSED)
TM RN GPR[5]: a (PASSED)
TM RN GPR[6]: 9 (PASSED)
TM RN GPR[7]: 8 (PASSED)
TM RN GPR[8]: 7 (PASSED)
TM RN GPR[9]: 6 (PASSED)
TM RN GPR[10]: 5 (PASSED)
TM RN GPR[11]: 4 (PASSED)
TM RN GPR[12]: 3 (PASSED)
TM RN GPR[13]: 2 (PASSED)
TM RN GPR[14]: 1 (PASSED)
TM RN GPR[15]: 0 (PASSED)
TM RN GPR[16]: f (PASSED)
TM RN GPR[17]: e (PASSED)
TM RN GPR[18]: d (PASSED)
TM RN GPR[19]: c (PASSED)
TM RN GPR[20]: b (PASSED)
TM RN GPR[21]: a (PASSED)
TM RN GPR[22]: 9 (PASSED)
TM RN GPR[23]: 8 (PASSED)
TM RN GPR[24]: 7 (PASSED)
TM RN GPR[25]: 6 (PASSED)
TM RN GPR[26]: 5 (PASSED)
TM RN GPR[27]: 4 (PASSED)
TM RN GPR[28]: 3 (PASSED)
TM RN GPR[29]: 2 (PASSED)
TM RN GPR[30]: 1 (PASSED)
TM RN GPR[31]: 0 (PASSED)
-------TM Running FPR-----
TM RN FPSCR: 0
TM RN FPR[0]: f (PASSED)
TM RN FPR[1]: e (PASSED)
TM RN FPR[2]: d (PASSED)
TM RN FPR[3]: c (PASSED)
TM RN FPR[4]: b (PASSED)
TM RN FPR[5]: a (PASSED)
TM RN FPR[6]: 9 (PASSED)
TM RN FPR[7]: 8 (PASSED)
TM RN FPR[8]: 7 (PASSED)
TM RN FPR[9]: 6 (PASSED)
TM RN FPR[10]: 5 (PASSED)
TM RN FPR[11]: 4 (PASSED)
TM RN FPR[12]: 3 (PASSED)
TM RN FPR[13]: 2 (PASSED)
TM RN FPR[14]: 1 (PASSED)
TM RN FPR[15]: 0 (PASSED)
TM RN FPR[16]: f (PASSED)
TM RN FPR[17]: e (PASSED)
TM RN FPR[18]: d (PASSED)
TM RN FPR[19]: c (PASSED)
TM RN FPR[20]: b (PASSED)
TM RN FPR[21]: a (PASSED)
TM RN FPR[22]: 9 (PASSED)
TM RN FPR[23]: 8 (PASSED)
TM RN FPR[24]: 7 (PASSED)
TM RN FPR[25]: 6 (PASSED)
TM RN FPR[26]: 5 (PASSED)
TM RN FPR[27]: 4 (PASSED)
TM RN FPR[28]: 3 (PASSED)
TM RN FPR[29]: 2 (PASSED)
TM RN FPR[30]: 1 (PASSED)
TM RN FPR[31]: 0 (PASSED)
-------TM Running MISC Registers-------
TM RN DSCR: 32 (PASSED)
TM RN TAR: 3c (PASSED)
TM RN PPR: 4000000000000 (PASSED)
success: tm_ptrace
Anshuman Khandual (8):
elf: Add new PowerPC specifc core note sections
powerpc, process: Add functions flush_tm_state, flush_tmregs_to_thread powerpc, process: Merge functions __switch_to_tm and tm_reclaim_task powerpc, ptrace: Enable fpr_(get/set) for transactional memory powerpc, ptrace: Enable vr_(get/set) for transactional memory powerpc, ptrace: Enable support for transactional memory register sets powerpc, ptrace: Enable support for miscellaneous debug registers selftests, powerpc: Add new test case for TM related ptrace interfaces
arch/powerpc/include/asm/switch_to.h | 8 + arch/powerpc/include/uapi/asm/elf.h | 3 + arch/powerpc/kernel/process.c | 65 +- arch/powerpc/kernel/ptrace.c | 965 ++++++++++++++++++++++++- include/uapi/linux/elf.h | 5 + tools/testing/selftests/powerpc/tm/Makefile | 2 +- tools/testing/selftests/powerpc/tm/tm-ptrace.c | 529 ++++++++++++++ 7 files changed, 1533 insertions(+), 44 deletions(-) create mode 100644 tools/testing/selftests/powerpc/tm/tm-ptrace.c
Signature · 1 line
1.9.3
PATCH v4 1/8 elf: Add new PowerPC specifc core note sections
This patch adds four new core note sections for PowerPC transactional memory and one core note section for general miscellaneous debug registers. These addition of new elf core note sections extends the existing elf ABI without affecting it in any manner.
--- include/uapi/linux/elf.h | 5 +++++ 1 file changed, 5 insertions(+)
include/uapi/linux/elf.h +5 -0
@@ -379,6 +379,11 @@ typedef struct elf64_shdr {#define NT_PPC_VMX 0x100/* PowerPC Altivec/VMX registers */ #define NT_PPC_SPE 0x101/* PowerPC SPE/EVR registers */ #define NT_PPC_VSX 0x102/* PowerPC VSX registers */ +#define NT_PPC_TM_SPR 0x103/* PowerPC TM special registers */ +#define NT_PPC_TM_CGPR 0x104/* PowerpC TM checkpointed GPR */ +#define NT_PPC_TM_CFPR 0x105/* PowerPC TM checkpointed FPR */ +#define NT_PPC_TM_CVMX 0x106/* PowerPC TM checkpointed VMX */ +#define NT_PPC_MISC 0x107/* PowerPC miscellaneous registers */ #define NT_386_TLS 0x200/* i386 TLS slots (struct user_desc) */ #define NT_386_IOPERM 0x201/* x86 io permission bitmap (1=deny) */ #define NT_X86_XSTATE 0x202/* x86 extended state using xsave */
Signature · 1 line
1.9.3
Re: [PATCH V4 1/8] elf: Add new PowerPC specifc core note sections
Anshuman Khandual [[email protected]] wrote:
| This patch adds four new core note sections for PowerPC transactional | memory and one core note section for general miscellaneous debug registers. | These addition of new elf core note sections extends the existing elf ABI | without affecting it in any manner. | | Signed-off-by: Anshuman Khandual <[email protected]>
Except for some minor comments to one of the patches, the patchset looks good to me. I was also able to run the included selftest on a PowerVM guest.
| ---
| include/uapi/linux/elf.h | 5 +++++
| 1 file changed, 5 insertions(+)
|
| diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
| index ea9bf25..2260fc0 100644
| --- a/include/uapi/linux/elf.h
| +++ b/include/uapi/linux/elf.h
| @@ -379,6 +379,11 @@ typedef struct elf64_shdr {
| #define NT_PPC_VMX 0x100 /* PowerPC Altivec/VMX registers */
| #define NT_PPC_SPE 0x101 /* PowerPC SPE/EVR registers */
| #define NT_PPC_VSX 0x102 /* PowerPC VSX registers */
| +#define NT_PPC_TM_SPR 0x103 /* PowerPC TM special registers */
| +#define NT_PPC_TM_CGPR 0x104 /* PowerpC TM checkpointed GPR */
| +#define NT_PPC_TM_CFPR 0x105 /* PowerPC TM checkpointed FPR */
| +#define NT_PPC_TM_CVMX 0x106 /* PowerPC TM checkpointed VMX */
| +#define NT_PPC_MISC 0x107 /* PowerPC miscellaneous registers */
| #define NT_386_TLS 0x200 /* i386 TLS slots (struct user_desc) */
| #define NT_386_IOPERM 0x201 /* x86 io permission bitmap (1=deny) */
| #define NT_X86_XSTATE 0x202 /* x86 extended state using xsave */
| --
| 1.9.3Re: [PATCH V4 1/8] elf: Add new PowerPC specifc core note sections
In reply to Anshuman KhandualQuoted 16 lines · On Tue, 11 Nov 2014 10:56:30 +0530 Anshuman Khandual…
This patch adds four new core note sections for PowerPC transactional memory and one core note section for general miscellaneous debug registers. These addition of new elf core note sections extends the existing elf ABI without affecting it in any manner.
Signed-off-by Anshuman Khandual <[email protected]>--- include/uapi/linux/elf.h | 5 +++++ 1 file changed, 5 insertions(+)include/uapi/linux/elf.h +0
-0@@ -379,6 +379,11 @@ typedef struct elf64_shdr {#define NT_PPC_VMX 0x100/* PowerPC Altivec/VMX registers */
include/uapi/linux/elf.h typedef struct elf64_shdr { · line 389
Quoted 10 lines
include/uapi/linux/elf.h +5
-0#define NT_PPC_SPE 0x101/* PowerPC SPE/EVR registers */ #define NT_PPC_VSX 0x102/* PowerPC VSX registers */ +#define NT_PPC_TM_SPR 0x103/* PowerPC TM special registers */ +#define NT_PPC_TM_CGPR 0x104/* PowerpC TM checkpointed GPR */ +#define NT_PPC_TM_CFPR 0x105/* PowerPC TM checkpointed FPR */ +#define NT_PPC_TM_CVMX 0x106/* PowerPC TM checkpointed VMX */ +#define NT_PPC_MISC 0x107/* PowerPC miscellaneous registers */ #define NT_386_TLS 0x200/* i386 TLS slots (struct user_desc) */ #define NT_386_IOPERM 0x201/* x86 io permission bitmap (1=deny) */ #define NT_X86_XSTATE 0x202/* x86 extended state using xsave */
ack from me, if that was at all expected.
Please cc Shuah Khan <[email protected]> on the tools/testing/selftests changes.
Re: [PATCH V4 1/8] elf: Add new PowerPC specifc core note sections
Quoted 22 lines · Andrew Morton
Quoted 20 lines · On Tue, 11 Nov 2014 10:56:30 +0530 Anshuman Khandual…
This patch adds four new core note sections for PowerPC transactional memory and one core note section for general miscellaneous debug registers. These addition of new elf core note sections extends the existing elf ABI without affecting it in any manner.
Signed-off-by Anshuman Khandual <[email protected]>--- include/uapi/linux/elf.h | 5 +++++ 1 file changed, 5 insertions(+)include/uapi/linux/elf.h +2
-0@@ -379,6 +379,11 @@ typedef struct elf64_shdr {#define NT_PPC_VMX 0x100/* PowerPC Altivec/VMX registers */ #define NT_PPC_SPE 0x101/* PowerPC SPE/EVR registers */ #define NT_PPC_VSX 0x102/* PowerPC VSX registers */ +#define NT_PPC_TM_SPR 0x103/* PowerPC TM special registers */ +#define NT_PPC_TM_CGPR 0x104/* PowerpC TM checkpointed GPR */
Quoted 8 lines
include/uapi/linux/elf.h typedef struct elf64_shdr { · line 389
Quoted 6 lines
include/uapi/linux/elf.h +3
-0+#define NT_PPC_TM_CFPR 0x105/* PowerPC TM checkpointed FPR */ +#define NT_PPC_TM_CVMX 0x106/* PowerPC TM checkpointed VMX */ +#define NT_PPC_MISC 0x107/* PowerPC miscellaneous registers */ #define NT_386_TLS 0x200/* i386 TLS slots (struct user_desc) */ #define NT_386_IOPERM 0x201/* x86 io permission bitmap (1=deny) */ #define NT_X86_XSTATE 0x202/* x86 extended state using xsave */ ack from me, if that was at all expected.
Thanks Andrew.
Quoted 3 lines
Please cc Shuah Khan <[email protected]> on the
tools/testing/selftestschanges.
Sure, will do.
PATCH v4 2/8 powerpc, process: Add functions flush_tm_state, flush_tmregs_to_thread
In reply to Anshuman KhandualThis patch creates a new function called flush_tm_state to flush the existing transactional memory state from the thread. It also creates a function called flush_tmregs_to_thread which will then be used on subsequent patches in this series.
--- arch/powerpc/include/asm/switch_to.h | 8 ++++++ arch/powerpc/kernel/process.c | 49 +++++++++++++++++++++++++++++------- 2 files changed, 48 insertions(+), 9 deletions(-)
arch/powerpc/include/asm/switch_to.h +8 -0
@@ -82,6 +82,14 @@ static inline void flush_spe_to_thread(struct task_struct *t) }#endif +#ifdef CONFIG_PPC_TRANSACTIONAL_MEM +extern void flush_tmregs_to_thread (struct task_struct *); +#else +static inline void flush_tmregs_to_thread (struct task_struct *t) +{ +} +#endif +static inline void clear_task_ebb (struct task_struct *t) {#ifdef CONFIG_PPC_BOOK3S_64
arch/powerpc/kernel/process.c +40 -9
61 lines not on this page · raw message
Signature · 1 line
1.9.3
Re: [PATCH V4 2/8] powerpc, process: Add functions flush_tm_state, flush_tmregs_to_thread
Quoted 52 lines · Anshuman Khandual
This patch creates a new function called
flush_tm_stateto flush the existing transactional memory state from the thread. It also creates a function calledflush_tmregs_to_threadwhich will then be used on subsequent patches in this series.Signed-off-by Anshuman Khandual <[email protected]>--- arch/powerpc/include/asm/switch_to.h | 8 ++++++ arch/powerpc/kernel/process.c | 49 +++++++++++++++++++++++++++++------- 2 files changed, 48 insertions(+), 9 deletions(-)arch/powerpc/include/asm/switch_to.h +8
-0@@ -82,6 +82,14 @@ static inline void flush_spe_to_thread(struct task_struct *t) }#endif +#ifdef CONFIG_PPC_TRANSACTIONAL_MEM +extern void flush_tmregs_to_thread (struct task_struct *); +#else +static inline void flush_tmregs_to_thread (struct task_struct *t) +{ +} +#endif +static inline void clear_task_ebb (struct task_struct *t) {#ifdef CONFIG_PPC_BOOK3S_64 arch/powerpc/kernel/process.c +14
-0@@ -745,6 +745,45 @@ void restore_tm_state(struct pt_regs *regs)#define __switch_to_tm (prev)#endif /* CONFIG_PPC_TRANSACTIONAL_MEM */ +/* +* flush_tm_state +* +* Flush TM state out so we can copy it. __switch_to_tm() does this +* flush but it removes the checkpointed state from the current CPU and +* transitions the CPU out of TM mode. Hence we need to call +* tm_recheckpoint_new_task() (on the same task) to restore the +* checkpointed state back and the TM mode. +*/ +static void flush_tm_state (struct task_struct *src) +{ +__switch_to_tm (src); +tm_recheckpoint_new_task (src); +}
arch/powerpc/kernel/process.c void restore_tm_state(struct pt_regs *regs) · line 771
Quoted 10 lines
arch/powerpc/kernel/process.c +10
-0+ +#ifdef CONFIG_PPC_TRANSACTIONAL_MEM +void flush_tmregs_to_thread (struct task_struct *tsk) +{ +/* +* If task is not current, it should have been flushed +* already to it's thread_struct during __switch_to(). +*/ +if (tsk != current) +return ;
As of now, ptrace does not support process self tracing. So here in this function we really dont have to do anything if current and tsk does not match each other. In case they match, we will just post one warning (as ptrace generic code should have prevented this from happening) and move on. Will make this function very simple like the following and remove the next patch as well which was created because of this patch.
#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
void flush_tmregs_to_thread(struct task_struct *tsk)
{
/*
* Self tracing is not yet supported through ptrace
* interface. Warn here if attempted.
*/
WARN_ON(tsk == current);
return;
}#endif
PATCH v4 3/8 powerpc, process: Merge functions __switch_to_tm and tm_reclaim_task
In reply to Anshuman KhandualThe function tm_reclaim_task is only called from the function
__switch_to_tm. This patch merges these two functions to make
it more readable without changing the functionality in any way.
--- arch/powerpc/kernel/process.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-)
arch/powerpc/kernel/process.c +8 -12
@@ -585,6 +585,10 @@ static inline void tm_reclaim_task(struct task_struct *tsk)*/ struct thread_struct *thr = &tsk->thread; +if (!cpu_has_feature (CPU_FTR_TM )) +return ; +tm_enable (); +if (!thr->regs)return ;
@@ -696,14 +700,6 @@ static inline void tm_recheckpoint_new_task(struct task_struct *new) new->pid, mfmsr()); } -static inline void __switch_to_tm (struct task_struct *prev) -{ -if (cpu_has_feature (CPU_FTR_TM )) { -tm_enable (); -tm_reclaim_task (prev); - } -} -/* * This is called if we are on the way out to userspace and the * TIF_RESTORE_TM flag is set. It checks if we need to reload
@@ -742,13 +738,13 @@ void restore_tm_state(struct pt_regs *regs)#else #define tm_recheckpoint_new_task (new) -#define __switch_to_tm (prev) +#define tm_reclaim_task (prev)#endif /* CONFIG_PPC_TRANSACTIONAL_MEM */ /* * flush_tm_state * -* Flush TM state out so we can copy it. __switch_to_tm() does this +* Flush TM state out so we can copy it. tm_reclaim_task() does this * flush but it removes the checkpointed state from the current CPU and * transitions the CPU out of TM mode. Hence we need to call * tm_recheckpoint_new_task() (on the same task) to restore the
@@ -756,7 +752,7 @@ void restore_tm_state(struct pt_regs *regs)*/ static void flush_tm_state (struct task_struct *src) { -__switch_to_tm (src); +tm_reclaim_task (src);tm_recheckpoint_new_task (src); }
@@ -805,7 +801,7 @@ struct task_struct *__switch_to(struct task_struct *prev,*/ save_early_sprs (&prev->thread); -__switch_to_tm (prev); +tm_reclaim_task (prev);#ifdef CONFIG_SMP /* avoid complexity of lazy save/restore of fpu
Signature · 1 line
1.9.3
PATCH v4 4/8 powerpc, ptrace: Enable fpr_(get/set) for transactional memory
In reply to Anshuman KhandualThis patch enables the fpr_get which gets the running value of all the FPR registers and the fpr_set which sets the running value of of all the FPR registers to accommodate in transaction ptrace interface based requests.
--- arch/powerpc/kernel/ptrace.c | 103 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 97 insertions(+), 6 deletions(-)
arch/powerpc/kernel/ptrace.c +97 -6
@@ -357,6 +357,33 @@ static int gpr_set(struct task_struct *target, const struct user_regset *regset,return ret; } + +/* +* fpr_get +* +* When the transaction is active, 'transact_fp' holds the current running +* value of all FPR registers and 'fp_state' holds the last checkpointed +* value of all FPR registers for the current transaction. When transaction +* is not active 'fp_state' holds the current running state of all the FPR +* registers. So this function which returns the current running values of +* all the FPR registers, needs to know whether any transaction is active +* or not. +* +* Userspace interface buffer layout: +* +* struct data { +* u64 fpr[32]; +* u64 fpscr; +* }; +* +* There are two config options CONFIG_VSX and CONFIG_PPC_TRANSACTIONAL_MEM +* which determines the final code in this function. All the combinations of +* these two config options are possible except the one below as transactional +* memory config pulls in CONFIG_VSX automatically. +* +* !defined(CONFIG_VSX) && defined(CONFIG_PPC_TRANSACTIONAL_MEM) +* +*/ static int fpr_get (struct task_struct *target,const struct user_regset *regset,unsigned int pos,unsigned int count,void *kbuf,void __user *ubuf)
@@ -367,22 +394,64 @@ static int fpr_get(struct task_struct *target, const struct user_regset *regset,#endif flush_fp_to_thread (target); -#ifdef CONFIG_VSX +#if defined(CONFIG_VSX ) && defined(CONFIG_PPC_TRANSACTIONAL_MEM ) +/* copy to local buffer then write that out */ +if (MSR_TM_ACTIVE (target->thread.regs->msr)) { +flush_altivec_to_thread (target); +flush_tmregs_to_thread (target); +for (i =0 ; i <32 ; i++) + buf[i] = target->thread.TS_TRANS_FPR (i); + buf[32 ] = target->thread.transact_fp.fpscr; + }else { +for (i =0 ; i <32 ; i++) + buf[i] = target->thread.TS_FPR (i); + buf[32 ] = target->thread.fp_state.fpscr; + } +return user_regset_copyout (&pos, &count, &kbuf, &ubuf, buf,0 ,-1 ); +#endif + +#if defined(CONFIG_VSX ) && !defined(CONFIG_PPC_TRANSACTIONAL_MEM )/* copy to local buffer then write that out */ for (i =0 ; i <32 ; i++) buf[i] = target->thread.TS_FPR (i); buf[32 ] = target->thread.fp_state.fpscr;return user_regset_copyout (&pos, &count, &kbuf, &ubuf, buf,0 ,-1 ); +#endif -#else + +#if !defined(CONFIG_VSX ) && !defined(CONFIG_PPC_TRANSACTIONAL_MEM )BUILD_BUG_ON (offsetof(struct thread_fp_state , fpscr) != offsetof(struct thread_fp_state, fpr[32][0])); -return user_regset_copyout (&pos, &count, &kbuf, &ubuf, &target->thread.fp_state,0 ,-1 );#endif } +/* +* fpr_set +* +* When the transaction is active, 'transact_fp' holds the current running +* value of all FPR registers and 'fp_state' holds the last checkpointed +* value of all FPR registers for the current transaction. When transaction +* is not active 'fp_state' holds the current running state of all the FPR +* registers. So this function which setss the current running values of +* all the FPR registers, needs to know whether any transaction is active +* or not. +* +* Userspace interface buffer layout: +* +* struct data { +* u64 fpr[32]; +* u64 fpscr; +* }; +* +* There are two config options CONFIG_VSX and CONFIG_PPC_TRANSACTIONAL_MEM +* which determines the final code in this function. All the combinations of +* these two config options are possible except the one below as transactional +* memory config pulls in CONFIG_VSX automatically. +* +* !defined(CONFIG_VSX) && defined(CONFIG_PPC_TRANSACTIONAL_MEM) +*/ static int fpr_set (struct task_struct *target,const struct user_regset *regset,unsigned int pos,unsigned int count,const void *kbuf,const void __user *ubuf)
@@ -393,7 +462,27 @@ static int fpr_set(struct task_struct *target, const struct user_regset *regset,#endif flush_fp_to_thread (target); -#ifdef CONFIG_VSX +#if defined(CONFIG_VSX ) && defined(CONFIG_PPC_TRANSACTIONAL_MEM ) +/* copy to local buffer then write that out */ + i =user_regset_copyin (&pos, &count, &kbuf, &ubuf, buf,0 ,-1 ); +if (i) +return i; + +if (MSR_TM_ACTIVE (target->thread.regs->msr)) { +flush_altivec_to_thread (target); +flush_tmregs_to_thread (target); +for (i =0 ; i <32 ; i++) + target->thread.TS_TRANS_FPR (i) = buf[i]; + target->thread.transact_fp.fpscr = buf[32 ]; + }else { +for (i =0 ; i <32 ; i++) + target->thread.TS_FPR (i) = buf[i]; + target->thread.fp_state.fpscr = buf[32 ]; + } +return 0 ; +#endif + +#if defined(CONFIG_VSX ) && !defined(CONFIG_PPC_TRANSACTIONAL_MEM )/* copy to local buffer then write that out */ i =user_regset_copyin (&pos, &count, &kbuf, &ubuf, buf,0 ,-1 );if (i)
@@ -402,12 +491,14 @@ static int fpr_set(struct task_struct *target, const struct user_regset *regset, target->thread.TS_FPR (i) = buf[i]; target->thread.fp_state.fpscr = buf[32 ];return 0 ; -#else +#endif + +#if !defined(CONFIG_VSX ) && !defined(CONFIG_PPC_TRANSACTIONAL_MEM )BUILD_BUG_ON (offsetof(struct thread_fp_state , fpscr) != offsetof(struct thread_fp_state, fpr[32][0])); -return user_regset_copyin (&pos, &count, &kbuf, &ubuf, &target->thread.fp_state,0 ,-1 ); +#endif }
Signature · 1 line
1.9.3
PATCH v4 5/8 powerpc, ptrace: Enable vr_(get/set) for transactional memory
In reply to Anshuman KhandualThis patch enables the vr_get which gets the running value of all the VMX registers and the vr_set which sets the running value of of all the VMX registers to accommodate in transaction ptrace interface based requests.
--- arch/powerpc/kernel/ptrace.c | 94 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 91 insertions(+), 3 deletions(-)
arch/powerpc/kernel/ptrace.c +91 -3
@@ -523,10 +523,30 @@ static int vr_active(struct task_struct *target,return target->thread.used_vr ? regset->n :0 ; } +/* +* vr_get +* +* When the transaction is active, 'transact_vr' holds the current running +* value of all the VMX registers and 'vr_state' holds the last checkpointed +* value of all the VMX registers for the current transaction to fall back +* on in case it aborts. When transaction is not active 'vr_state' holds +* the current running state of all the VMX registers. So this function which +* gets the current running values of all the VMX registers, needs to know +* whether any transaction is active or not. +* +* Userspace interface buffer layout: +* +* struct data { +* vector128 vr[32]; +* vector128 vscr; +* vector128 vrsave; +* }; +*/ static int vr_get (struct task_struct *target,const struct user_regset *regset,unsigned int pos,unsigned int count,void *kbuf,void __user *ubuf) { +struct thread_vr_state *addr;int ret;flush_altivec_to_thread (target);
@@ -534,8 +554,19 @@ static int vr_get(struct task_struct *target, const struct user_regset *regset,BUILD_BUG_ON (offsetof(struct thread_vr_state , vscr) != offsetof(struct thread_vr_state, vr[32])); +#ifdef CONFIG_PPC_TRANSACTIONAL_MEM +if (MSR_TM_ACTIVE (target->thread.regs->msr)) { +flush_fp_to_thread (target); +flush_tmregs_to_thread (target); + addr = &target->thread.transact_vr; + }else { + addr = &target->thread.vr_state; + } +#else + addr = &target->thread.vr_state; +#endif ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, - &target->thread.vr_state,0 , + addr,0 ,33 *sizeof (vector128));if (!ret) {/*
@@ -546,7 +577,16 @@ static int vr_get(struct task_struct *target, const struct user_regset *regset,u32 word; } vrsave;memset (&vrsave,0 ,sizeof (vrsave)); + +#ifdef CONFIG_PPC_TRANSACTIONAL_MEM +if (MSR_TM_ACTIVE (target->thread.regs->msr)) + vrsave.word = target->thread.transact_vrsave; +else + vrsave.word = target->thread.vrsave; +#else vrsave.word = target->thread.vrsave; +#endif + ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, &vrsave,33 *sizeof (vector128),-1 ); }
@@ -554,10 +594,30 @@ static int vr_get(struct task_struct *target, const struct user_regset *regset,return ret; } +/* +* vr_set +* +* When the transaction is active, 'transact_vr' holds the current running +* value of all the VMX registers and 'vr_state' holds the last checkpointed +* value of all the VMX registers for the current transaction to fall back +* on in case it aborts. When transaction is not active 'vr_state' holds +* the current running state of all the VMX registers. So this function which +* sets the current running values of all the VMX registers, needs to know +* whether any transaction is active or not. +* +* Userspace interface buffer layout: +* +* struct data { +* vector128 vr[32]; +* vector128 vscr; +* vector128 vrsave; +* }; +*/ static int vr_set (struct task_struct *target,const struct user_regset *regset,unsigned int pos,unsigned int count,const void *kbuf,const void __user *ubuf) { +struct thread_vr_state *addr;int ret;flush_altivec_to_thread (target);
@@ -565,8 +625,19 @@ static int vr_set(struct task_struct *target, const struct user_regset *regset,BUILD_BUG_ON (offsetof(struct thread_vr_state , vscr) != offsetof(struct thread_vr_state, vr[32])); +#ifdef CONFIG_PPC_TRANSACTIONAL_MEM +if (MSR_TM_ACTIVE (target->thread.regs->msr)) { +flush_fp_to_thread (target); +flush_tmregs_to_thread (target); + addr = &target->thread.transact_vr; + }else { + addr = &target->thread.vr_state; + } +#else + addr = &target->thread.vr_state; +#endif ret =user_regset_copyin (&pos, &count, &kbuf, &ubuf, - &target->thread.vr_state,0 , + addr,0 ,33 *sizeof (vector128));if (!ret && count >0 ) {/*
@@ -577,11 +648,28 @@ static int vr_set(struct task_struct *target, const struct user_regset *regset,u32 word; } vrsave;memset (&vrsave,0 ,sizeof (vrsave)); + +#ifdef CONFIG_PPC_TRANSACTIONAL_MEM +if (MSR_TM_ACTIVE (target->thread.regs->msr)) + vrsave.word = target->thread.transact_vrsave; +else + vrsave.word = target->thread.vrsave; +#else vrsave.word = target->thread.vrsave; +#endif ret =user_regset_copyin (&pos, &count, &kbuf, &ubuf, &vrsave,33 *sizeof (vector128),-1 ); -if (!ret) +if (!ret) { + +#ifdef CONFIG_PPC_TRANSACTIONAL_MEM +if (MSR_TM_ACTIVE (target->thread.regs->msr)) + target->thread.transact_vrsave = vrsave.word; +else + target->thread.vrsave = vrsave.word; +#else target->thread.vrsave = vrsave.word; +#endif + } }return ret;
Signature · 1 line
1.9.3
PATCH v4 6/8 powerpc, ptrace: Enable support for transactional memory register sets
In reply to Anshuman KhandualThis patch enables get and set of transactional memory related register sets through PTRACE_GETREGSET-PTRACE_SETREGSET interface by implementing four new powerpc specific register sets i.e REGSET_TM_SPR, REGSET_TM_CGPR, REGSET_TM_CFPR, REGSET_CVMX support corresponding to these following new ELF core note types added previously in this regard.
(1) NT_PPC_TM_SPR (2) NT_PPC_TM_CGPR (3) NT_PPC_TM_CFPR (4) NT_PPC_TM_CVMX
--- arch/powerpc/include/uapi/asm/elf.h | 2 + arch/powerpc/kernel/ptrace.c | 666 +++++++++++++++++++++++++++++++++++- 2 files changed, 653 insertions(+), 15 deletions(-)
arch/powerpc/include/uapi/asm/elf.h +2 -0
@@ -91,6 +91,8 @@#define ELF_NGREG 48/* includes nip, msr, lr, etc. */ #define ELF_NFPREG 33/* includes fpscr */ +#define ELF_NVMX 34/* includes all vector registers */ +#define ELF_NTMSPRREG 7/* includes TM sprs, org_msr, dscr, tar, ppr */ typedef unsigned long elf_greg_t64 ;typedef elf_greg_t64 elf_gregset_t64 [ELF_NGREG ];
arch/powerpc/kernel/ptrace.c +651 -15
731 lines not on this page · raw message
Signature · 1 line
1.9.3
Re: [PATCH V4 6/8] powerpc, ptrace: Enable support for transactional memory register sets
Anshuman Khandual [[email protected]] wrote:
| This patch enables get and set of transactional memory related register | sets through PTRACE_GETREGSET-PTRACE_SETREGSET interface by implementing | four new powerpc specific register sets i.e REGSET_TM_SPR, REGSET_TM_CGPR, | REGSET_TM_CFPR, REGSET_CVMX support corresponding to these following new | ELF core note types added previously in this regard. | | (1) NT_PPC_TM_SPR | (2) NT_PPC_TM_CGPR | (3) NT_PPC_TM_CFPR | (4) NT_PPC_TM_CVMX | | Signed-off-by: Anshuman Khandual <[email protected]> | --- | arch/powerpc/include/uapi/asm/elf.h | 2 + | arch/powerpc/kernel/ptrace.c | 666 +++++++++++++++++++++++++++++++++++- | 2 files changed, 653 insertions(+), 15 deletions(-) | | diff --git a/arch/powerpc/include/uapi/asm/elf.h b/arch/powerpc/include/uapi/asm/elf.h | index 59dad11..fdc8e2f 100644 | --- a/arch/powerpc/include/uapi/asm/elf.h | +++ b/arch/powerpc/include/uapi/asm/elf.h | @@ -91,6 +91,8 @@ | | #define ELF_NGREG 48 /* includes nip, msr, lr, etc. */ | #define ELF_NFPREG 33 /* includes fpscr */ | +#define ELF_NVMX 34 /* includes all vector registers */ | +#define ELF_NTMSPRREG 7 /* includes TM sprs, org_msr, dscr, tar, ppr */ | | typedef unsigned long elf_greg_t64; | typedef elf_greg_t64 elf_gregset_t64[ELF_NGREG]; | diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c | index 2bbbd10..b279947 100644 | --- a/arch/powerpc/kernel/ptrace.c | +++ b/arch/powerpc/kernel/ptrace.c | @@ -63,6 +63,11 @@ struct pt_regs_offset { | {.name = STR(gpr##num), .offset = offsetof(struct pt_regs, gpr[num])} | #define REG_OFFSET_END {.name = NULL, .offset = 0} | | +/* Some common structure offsets */ | +#define TSO(f) (offsetof(struct thread_struct, f)) | +#define TVSO(f) (offsetof(struct thread_vr_state, f)) | +#define TFSO(f) (offsetof(struct thread_fp_state, f)) | + | static const struct pt_regs_offset regoffset_table[] = { | GPR_OFFSET_NAME(0), | GPR_OFFSET_NAME(1), | @@ -792,6 +797,534 @@ static int evr_set(struct task_struct *target, const struct user_regset *regset, | } | #endif /* CONFIG_SPE */ | | +#ifdef CONFIG_PPC_TRANSACTIONAL_MEM | +/* | + * tm_spr_active | + * | + * This function checks number of available regisers in | + * the transactional memory SPR category. | + */ | +static int tm_spr_active(struct task_struct *target, | + const struct user_regset *regset) | +{ | + if (!cpu_has_feature(CPU_FTR_TM)) | + return -ENODEV; | + | + if (!MSR_TM_ACTIVE(target->thread.regs->msr)) | + return 0; | + | + return regset->n; | +} | + | +/* | + * tm_spr_get | + * | + * This function gets transactional memory related SPR registers | + * | + * Userspace interface buffer layout: | + * | + * struct { | + * u64 tm_tfhar; | + * u64 tm_texasr; | + * u64 tm_tfiar; | + * unsigned long tm_orig_msr; | + * unsigned long tm_tar; | + * unsigned long tm_ppr; | + * unsigned long tm_dscr; | + * }; | + */ | +static int tm_spr_get(struct task_struct *target, | + const struct user_regset *regset, | + unsigned int pos, unsigned int count, | + void *kbuf, void __user *ubuf) | +{ | + int ret; | + | + /* Build tests */ | + BUILD_BUG_ON(TSO(tm_tfhar) + sizeof(u64) != TSO(tm_texasr)); | + BUILD_BUG_ON(TSO(tm_texasr) + sizeof(u64) != TSO(tm_tfiar)); | + BUILD_BUG_ON(TSO(tm_tfiar) + sizeof(u64) != TSO(tm_orig_msr)); | + BUILD_BUG_ON(TSO(tm_orig_msr) + sizeof(unsigned long) + Can we replace TSO(tm_orig_msr) + sizeof(unsigned long) with TSO(ckpt_regs) ? | + sizeof(struct pt_regs) != TSO(tm_tar)); | + BUILD_BUG_ON(TSO(tm_tar) + sizeof(unsigned long) != TSO(tm_ppr)); | + BUILD_BUG_ON(TSO(tm_ppr) + sizeof(unsigned long) != TSO(tm_dscr)); | + | + if (!cpu_has_feature(CPU_FTR_TM)) | + return -ENODEV; | + | + if (!MSR_TM_ACTIVE(target->thread.regs->msr)) | + return -ENODATA; | + | + /* Flush the states */ | + flush_fp_to_thread(target); | + flush_altivec_to_thread(target); | + flush_tmregs_to_thread(target); | + | + /* TFHAR register */ | + ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, | + &target->thread.tm_tfhar, 0, sizeof(u64));
The last two parameters, (start_pos, end_pos) are easy to understand here, but...
| + | + /* TEXASR register */ | + if (!ret) | + ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, | + &target->thread.tm_texasr, sizeof(u64), | + 2 * sizeof(u64));
... gets harder to understand here and subsequent fields below.
Given that you already do the BUILD_BUG_ON() tests above, how about using TSO(tm_texasr) and TSO(tfiar) here for start_pos and end_pos ?
Also, how about just returning if the copyout fails ? If the first copyout fails, we will still check 'if(!ret)' several times below.
| +
| + /* TFIAR register */
| + if (!ret)
| + ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
| + &target->thread.tm_tfiar,
| + 2 * sizeof(u64), 3 * sizeof(u64));
| +
| + /* TM checkpointed original MSR */
| + if (!ret)
| + ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
| + &target->thread.tm_orig_msr, 3 * sizeof(u64),
| + 3 * sizeof(u64) + sizeof(unsigned long));
| +
| + /* TM checkpointed TAR register */
| + if (!ret)
| + ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
| + &target->thread.tm_tar, 3 * sizeof(u64) +
| + sizeof(unsigned long) ,
| + 3 * sizeof(u64) + 2 * sizeof(unsigned long));
| +
| + /* TM checkpointed PPR register */
| + if (!ret)
| + ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
| + &target->thread.tm_ppr, 3 * sizeof(u64) +
| + 2 * sizeof(unsigned long),
| + 3 * sizeof(u64) + 3 * sizeof(unsigned long));
| +
| + /* TM checkpointed DSCR register */
| + if (!ret)
| + ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
| + &target->thread.tm_dscr, 3 * sizeof(u64) +
| + 3 * sizeof(unsigned long),
| + 3 * sizeof(u64) + 4 * sizeof(unsigned long));
| + return ret;
| +}
| +
| +/*
| + * tm_spr_set
| + *
| + * This function sets transactional memory related SPR registers
| + *
| + * Userspace interface buffer layout:
| + *
| + * struct {
| + * u64 tm_tfhar;
| + * u64 tm_texasr;
| + * u64 tm_tfiar;
| + * unsigned long tm_orig_msr;
| + * unsigned long tm_tar;
| + * unsigned long tm_ppr;
| + * unsigned long tm_dscr;
| + * };
| + */
| +static int tm_spr_set(struct task_struct *target,
| + const struct user_regset *regset,
| + unsigned int pos, unsigned int count,
| + const void *kbuf, const void __user *ubuf)
| +{
| + int ret;
| +
| + /* Build tests */
| + BUILD_BUG_ON(TSO(tm_tfhar) + sizeof(u64) != TSO(tm_texasr));
| + BUILD_BUG_ON(TSO(tm_texasr) + sizeof(u64) != TSO(tm_tfiar));
| + BUILD_BUG_ON(TSO(tm_orig_msr) + sizeof(unsigned long)Can we replace TSO(tm_orig_msr) + sizeof(unsigned long) with TSO(ckpt_regs) ?
| + + sizeof(struct pt_regs) != TSO(tm_tar)); | + BUILD_BUG_ON(TSO(tm_tar) + sizeof(unsigned long) != TSO(tm_ppr)); | + BUILD_BUG_ON(TSO(tm_ppr) + sizeof(unsigned long) != TSO(tm_dscr)); | + BUILD_BUG_ON(TSO(tm_tfiar) + sizeof(u64) != TSO(tm_orig_msr));
How about moving this last line up after the check for TSO(tm_tfiar) ?
| + | + if (!cpu_has_feature(CPU_FTR_TM)) | + return -ENODEV; | + | + if (!MSR_TM_ACTIVE(target->thread.regs->msr)) | + return -ENODATA; | + | + /* Flush the states */ | + flush_fp_to_thread(target); | + flush_altivec_to_thread(target); | + flush_tmregs_to_thread(target); | + | + /* TFHAR register */ | + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, | + &target->thread.tm_tfhar, 0, sizeof(u64)); | + | + /* TEXASR register */ | + if (!ret) | + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, | + &target->thread.tm_texasr, sizeof(u64), | + 2 * sizeof(u64));
Return if copyin() fails ?
| +
| + /* TFIAR register */
| + if (!ret)
| + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
| + &target->thread.tm_tfiar,
| + 2 * sizeof(u64), 3 * sizeof(u64));
| +
| +
| + /* TM checkpointed orig MSR */
| + if (!ret)
| + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
| + &target->thread.tm_orig_msr, 3 * sizeof(u64),
| + 3 * sizeof(u64) + sizeof(unsigned long));
| +
| +
| + /* TM checkpointed TAR register */
| + if (!ret)
| + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
| + &target->thread.tm_tar, 3 * sizeof(u64) +
| + sizeof(unsigned long), 3 * sizeof(u64) +
| + 2 * sizeof(unsigned long));
| +
| + /* TM checkpointed PPR register */
| + if (!ret)
| + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
| + &target->thread.tm_ppr, 3 * sizeof(u64) +
| + 2 * sizeof(unsigned long), 3 * sizeof(u64) +
| + 3 * sizeof(unsigned long));
| +
| + /* TM checkpointed DSCR register */
| + if (!ret)
| + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
| + &target->thread.tm_dscr, 3 * sizeof(u64) +
| + 3 * sizeof(unsigned long), 3 * sizeof(u64) +
| + 4 * sizeof(unsigned long));
| + return ret;
| +}
| +
| +/*
| + * tm_cgpr_active
| + *
| + * This function checks the number of available regisers in
| + * transaction checkpointed GPR category.
| + */
| +static int tm_cgpr_active(struct task_struct *target,
| + const struct user_regset *regset)
| +{
| + if (!cpu_has_feature(CPU_FTR_TM))
| + return -ENODEV;
| +
| + if (!MSR_TM_ACTIVE(target->thread.regs->msr))
| + return 0;
| +
| + return regset->n;
| +}
| +
| +/*
| + * tm_cgpr_get
| + *
| + * This function gets transaction checkpointed GPR registers
| + *
| + * When the transaction is active, 'ckpt_regs' holds all the checkpointed
| + * GPR register values for the current transaction to fall back on if it
| + * aborts in between. This function gets those checkpointed GPR registers.
| + *
| + * Userspace interface buffer layout:
| + *
| + * struct data {
| + * struct pt_regs ckpt_regs;
| + * };
| + */
| +static int tm_cgpr_get(struct task_struct *target,
| + const struct user_regset *regset,
| + unsigned int pos, unsigned int count,
| + void *kbuf, void __user *ubuf)
| +{
| + int ret;
| +
| + if (!cpu_has_feature(CPU_FTR_TM))
| + return -ENODEV;
| +
| + if (!MSR_TM_ACTIVE(target->thread.regs->msr))
| + return -ENODATA;
| +
| + flush_fp_to_thread(target);
| + flush_altivec_to_thread(target);
| + flush_tmregs_to_thread(target);
| + ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
| + &target->thread.ckpt_regs, 0,
| + sizeof(struct pt_regs));
| + return ret;
| +}
| +
| +/*
| + * tm_cgpr_set
| + *
| + * This function sets in transaction checkpointed GPR registers
| + *
| + * When the transaction is active, 'ckpt_regs' holds the checkpointed
| + * GPR register values for the current transaction to fall back on if it
| + * aborts in between. This function sets those checkpointed GPR registers.
| + *
| + * Userspace intaerface buffer:
| + *
| + * struct data {
| + * struct pt_regs ckpt_regs;
| + * };
| + */
| +static int tm_cgpr_set(struct task_struct *target,
| + const struct user_regset *regset,
| + unsigned int pos, unsigned int count,
| + const void *kbuf, const void __user *ubuf)
| +{
| + int ret;
| +
| + if (!cpu_has_feature(CPU_FTR_TM))
| + return -ENODEV;
| +
| + if (!MSR_TM_ACTIVE(target->thread.regs->msr))
| + return -ENODATA;
| +
| + flush_fp_to_thread(target);
| + flush_altivec_to_thread(target);
| + flush_tmregs_to_thread(target);
| + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
| + &target->thread.ckpt_regs, 0,
| + sizeof(struct pt_regs));
| + return ret;
| +}
| +
| +/*
| + * tm_cfpr_active
| + *
| + * This function checks number of available regisers in
| + * transaction checkpointed FPR category.
| + */
| +static int tm_cfpr_active(struct task_struct *target,
| + const struct user_regset *regset)
| +{
| + if (!cpu_has_feature(CPU_FTR_TM))
| + return -ENODEV;
| +
| + if (!MSR_TM_ACTIVE(target->thread.regs->msr))
| + return 0;
| +
| + return regset->n;
| +}
| +
| +/*
| + * tm_cfpr_get
| + *
| + * This function gets in transaction checkpointed FPR registers
| + *
| + * When the transaction is active 'fp_state' holds the checkpointed
| + * values for the current transaction to fall back on if it aborts
| + * in between. This function gets those checkpointed FPR registers.
| + *
| + * Userspace interface buffer layout:
| + *
| + * struct data {
| + * u64 fpr[32];
| + * u64 fpscr;
| + *};
| + */
| +static int tm_cfpr_get(struct task_struct *target,
| + const struct user_regset *regset,
| + unsigned int pos, unsigned int count,
| + void *kbuf, void __user *ubuf)
| +{
| + u64 buf[33];
| + int i;
| +
| + if (!cpu_has_feature(CPU_FTR_TM))
| + return -ENODEV;
| +
| + if (!MSR_TM_ACTIVE(target->thread.regs->msr))
| + return -ENODATA;
| +
| + flush_fp_to_thread(target);
| + flush_altivec_to_thread(target);
| + flush_tmregs_to_thread(target);
| +
| + /* copy to local buffer then write that out */
| + for (i = 0; i < 32 ; i++)
| + buf[i] = target->thread.TS_FPR(i);
| + buf[32] = target->thread.fp_state.fpscr;
| + return user_regset_copyout(&pos, &count, &kbuf, &ubuf, buf, 0, -1);
| +}
| +
| +/*
| + * tm_cfpr_set
| + *
| + * This function sets in transaction checkpointed FPR registers
| + *
| + * When the transaction is active 'fp_state' holds the checkpointed
| + * FPR register values for the current transaction to fall back on
| + * if it aborts in between. This function sets these checkpointed
| + * FPR registers.
| + *
| + * Userspace interface buffer layout:
| + *
| + * struct data {
| + * u64 fpr[32];
| + * u64 fpscr;
| + *};
| + */
| +static int tm_cfpr_set(struct task_struct *target,
| + const struct user_regset *regset,
| + unsigned int pos, unsigned int count,
| + const void *kbuf, const void __user *ubuf)
| +{
| + u64 buf[33];
| + int i;
| +
| + if (!cpu_has_feature(CPU_FTR_TM))
| + return -ENODEV;
| +
| + if (!MSR_TM_ACTIVE(target->thread.regs->msr))
| + return -ENODATA;
| +
| + flush_fp_to_thread(target);
| + flush_altivec_to_thread(target);
| + flush_tmregs_to_thread(target);
| +
| + /* copy to local buffer then write that out */
| + i = user_regset_copyin(&pos, &count, &kbuf, &ubuf, buf, 0, -1);
| + if (i)
| + return i;
| + for (i = 0; i < 32 ; i++)
| + target->thread.TS_FPR(i) = buf[i];
| + target->thread.fp_state.fpscr = buf[32];
| + return 0;
| +}
| +
| +/*
| + * tm_cvmx_active
| + *
| + * This function checks the number of available regisers in
| + * checkpointed VMX category.
| + */
| +static int tm_cvmx_active(struct task_struct *target,
| + const struct user_regset *regset)
| +{
| + if (!cpu_has_feature(CPU_FTR_TM))
| + return -ENODEV;
| +
| + if (!MSR_TM_ACTIVE(target->thread.regs->msr))
| + return 0;
| +
| + return regset->n;
| +}
| +
| +/*
| + * tm_cvmx_get
| + *
| + * This function gets in transaction checkpointed VMX registers
| + *
| + * When the transaction is active 'vr_state' and 'vr_save' hold
| + * the checkpointed values for the current transaction to fall
| + * back on if it aborts in between.
| + *
| + * User interface buffer:
| + *
| + * struct data {
| + * vector128 vr[32];
| + * vector128 vscr;
| + * vector128 vrsave;
| + *};
| + */
| +static int tm_cvmx_get(struct task_struct *target,
| + const struct user_regset *regset,
| + unsigned int pos, unsigned int count,
| + void *kbuf, void __user *ubuf)
| +{
| + int ret;
| +
| + BUILD_BUG_ON(TVSO(vscr) != TVSO(vr[32]));
| +
| + if (!cpu_has_feature(CPU_FTR_TM))
| + return -ENODEV;
| +
| + if (!MSR_TM_ACTIVE(target->thread.regs->msr))
| + return -ENODATA;
| +
| + /* Flush the state */
| + flush_fp_to_thread(target);
| + flush_altivec_to_thread(target);
| + flush_tmregs_to_thread(target);
| +
| + ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
| + &target->thread.vr_state, 0,
| + 33 * sizeof(vector128));
| + if (!ret) {
| + /*
| + * Copy out only the low-order word of vrsave.
| + */
| + union {
| + elf_vrreg_t reg;
| + u32 word;
| + } vrsave;
| + memset(&vrsave, 0, sizeof(vrsave));
| + vrsave.word = target->thread.vrsave;
| + ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &vrsave,
| + 33 * sizeof(vector128), -1);
| + }
| +
| + return ret;
| +}
| +
| +/*
| + * tm_cvmx_set
| + *
| + * This function sets in transaction checkpointed VMX registers
| + *
| + * When the transaction is active 'vr_state' and 'vr_save' hold
| + * the checkpointed values for the current transaction to fall
| + * back on if it aborts in between.
| + *
| + * Userspace interface buffer:
| + *
| + * struct data {
| + * vector128 vr[32];
| + * vector128 vscr;
| + * vector128 vrsave;
| + *};
| + */
| +static int tm_cvmx_set(struct task_struct *target,
| + const struct user_regset *regset,
| + unsigned int pos, unsigned int count,
| + const void *kbuf, const void __user *ubuf)
| +{
| + int ret;
| +
| + BUILD_BUG_ON(TVSO(vscr) != TVSO(vr[32]));
| +
| + if (!cpu_has_feature(CPU_FTR_TM))
| + return -ENODEV;
| +
| + if (!MSR_TM_ACTIVE(target->thread.regs->msr))
| + return -ENODATA;
| +
| + flush_fp_to_thread(target);
| + flush_altivec_to_thread(target);
| + flush_tmregs_to_thread(target);
| +
| + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
| + &target->thread.vr_state, 0,
| + 33 * sizeof(vector128));
| + if (!ret && count > 0) {
| + /*
| + * We use only the first word of vrsave.For consistency with the _get() function above, s/first/low-order/ ?
| + */
| + union {
| + elf_vrreg_t reg;
| + u32 word;
| + } vrsave;
| + memset(&vrsave, 0, sizeof(vrsave));
| + vrsave.word = target->thread.vrsave;
| + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &vrsave,
| + 33 * sizeof(vector128), -1);
| + if (!ret)
| + target->thread.vrsave = vrsave.word;
| + }
| +
| + return ret;
| +}
| +#endif /* CONFIG_PPC_TRANSACTIONAL_MEM */
|
| /*
| * These are our native regset flavors.
| @@ -808,6 +1341,12 @@ enum powerpc_regset {
| #ifdef CONFIG_SPE
| REGSET_SPE,
| #endif
| +#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
| + REGSET_TM_SPR, /* TM specific SPR registers */
| + REGSET_TM_CGPR, /* TM checkpointed GPR registers */
| + REGSET_TM_CFPR, /* TM checkpointed FPR registers */
| + REGSET_TM_CVMX, /* TM checkpointed VMX registers */
| +#endif
| };
|
| static const struct user_regset native_regsets[] = {
| @@ -842,6 +1381,28 @@ static const struct user_regset native_regsets[] = {
| .active = evr_active, .get = evr_get, .set = evr_set
| },
| #endif
| +#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
| + [REGSET_TM_SPR] = {
| + .core_note_type = NT_PPC_TM_SPR, .n = ELF_NTMSPRREG,
| + .size = sizeof(u64), .align = sizeof(u64),
| + .active = tm_spr_active, .get = tm_spr_get, .set = tm_spr_set
| + },
| + [REGSET_TM_CGPR] = {
| + .core_note_type = NT_PPC_TM_CGPR, .n = ELF_NGREG,
| + .size = sizeof(long), .align = sizeof(long),
| + .active = tm_cgpr_active, .get = tm_cgpr_get, .set = tm_cgpr_set
| + },
| + [REGSET_TM_CFPR] = {
| + .core_note_type = NT_PPC_TM_CFPR, .n = ELF_NFPREG,
| + .size = sizeof(double), .align = sizeof(double),
| + .active = tm_cfpr_active, .get = tm_cfpr_get, .set = tm_cfpr_set
| + },
| + [REGSET_TM_CVMX] = {
| + .core_note_type = NT_PPC_TM_CVMX, .n = ELF_NVMX,
| + .size = sizeof(vector128), .align = sizeof(vector128),
| + .active = tm_cvmx_active, .get = tm_cvmx_get, .set = tm_cvmx_set
| + },
| +#endif
| };
|
| static const struct user_regset_view user_ppc_native_view = {
| @@ -852,24 +1413,35 @@ static const struct user_regset_view user_ppc_native_view = {
| #ifdef CONFIG_PPC64
| #include <linux/compat.h>
|
| -static int gpr32_get(struct task_struct *target,
| +static int common_gpr32_get(struct task_struct *target,
| const struct user_regset *regset,
| unsigned int pos, unsigned int count,
| - void *kbuf, void __user *ubuf)
| + void *kbuf, void __user *ubuf, bool in_tm)
| {
| - const unsigned long *regs = &target->thread.regs->gpr[0];
| + const unsigned long *regs;
| compat_ulong_t *k = kbuf;
| compat_ulong_t __user *u = ubuf;
| compat_ulong_t reg;
| int i;
|
| - if (target->thread.regs == NULL)
| - return -EIO;
| + if (in_tm) {
| +#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
| + regs = &target->thread.ckpt_regs.gpr[0];
| +#endifregs uninitialized if in_tm is true and CONFIG_PPC_TRANSACTIONAL_MEM is false ? It appears that it cannot/should not happen, how about BUGON() ? or at least regs = NULL to silence compiler warnings ?
| + } else {
| + regs = &target->thread.regs->gpr[0];
|
| - if (!FULL_REGS(target->thread.regs)) {
| - /* We have a partial register set. Fill 14-31 with bogus values */
| - for (i = 14; i < 32; i++)
| - target->thread.regs->gpr[i] = NV_REG_POISON;
| + if (target->thread.regs == NULL)
| + return -EIO;
| +
| + if (!FULL_REGS(target->thread.regs)) {
| + /*
| + * We have a partial register set.
| + * Fill 14-31 with bogus values.
| + */
| + for (i = 14; i < 32; i++)
| + target->thread.regs->gpr[i] = NV_REG_POISON;
| + }
| }
|
| pos /= sizeof(reg);
| @@ -909,20 +1481,28 @@ static int gpr32_get(struct task_struct *target,
| PT_REGS_COUNT * sizeof(reg), -1);
| }
|
| -static int gpr32_set(struct task_struct *target,
| +static int common_gpr32_set(struct task_struct *target,
| const struct user_regset *regset,
| unsigned int pos, unsigned int count,
| - const void *kbuf, const void __user *ubuf)
| + const void *kbuf, const void __user *ubuf, bool in_tm)
| {
| - unsigned long *regs = &target->thread.regs->gpr[0];
| + unsigned long *regs;
| const compat_ulong_t *k = kbuf;
| const compat_ulong_t __user *u = ubuf;
| compat_ulong_t reg;
|
| - if (target->thread.regs == NULL)
| - return -EIO;
| + if (in_tm) {
| +#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
| + regs = &target->thread.ckpt_regs.gpr[0];
| +#endifditto
| + } else {
| + regs = &target->thread.regs->gpr[0];
|
| - CHECK_FULL_REGS(target->thread.regs);
| + if (target->thread.regs == NULL)
| + return -EIO;
| +
| + CHECK_FULL_REGS(target->thread.regs);
| + }
|
| pos /= sizeof(reg);
| count /= sizeof(reg);
| @@ -982,6 +1562,39 @@ static int gpr32_set(struct task_struct *target,
| (PT_TRAP + 1) * sizeof(reg), -1);
| }
|
| +#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
| +static int tm_cgpr32_get(struct task_struct *target,
| + const struct user_regset *regset,
| + unsigned int pos, unsigned int count,
| + void *kbuf, void __user *ubuf)
| +{
| + return common_gpr32_get(target, regset, pos, count, kbuf, ubuf, 1);
| +}
| +
| +static int tm_cgpr32_set(struct task_struct *target,
| + const struct user_regset *regset,
| + unsigned int pos, unsigned int count,
| + const void *kbuf, const void __user *ubuf)
| +{
| + return common_gpr32_set(target, regset, pos, count, kbuf, ubuf, 0);
| +}
| +#endif /* CONFIG_PPC_TRANSACTIONAL_MEM */
| +
| +static int gpr32_get(struct task_struct *target,
| + const struct user_regset *regset,
| + unsigned int pos, unsigned int count,
| + void *kbuf, void __user *ubuf)
| +{
| + return common_gpr32_get(target, regset, pos, count, kbuf, ubuf, 0);
| +}
| +
| +static int gpr32_set(struct task_struct *target,
| + const struct user_regset *regset,
| + unsigned int pos, unsigned int count,
| + const void *kbuf, const void __user *ubuf)
| +{
| + return common_gpr32_set(target, regset, pos, count, kbuf, ubuf, 0);
| +}
| /*
| * These are the regset flavors matching the CONFIG_PPC32 native set.
| */
| @@ -1010,6 +1623,29 @@ static const struct user_regset compat_regsets[] = {
| .active = evr_active, .get = evr_get, .set = evr_set
| },
| #endif
| +#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
| + [REGSET_TM_SPR] = {
| + .core_note_type = NT_PPC_TM_SPR, .n = ELF_NTMSPRREG,
| + .size = sizeof(u64), .align = sizeof(u64),
| + .active = tm_spr_active, .get = tm_spr_get, .set = tm_spr_set
| + },
| + [REGSET_TM_CGPR] = {
| + .core_note_type = NT_PPC_TM_CGPR, .n = ELF_NGREG,
| + .size = sizeof(long), .align = sizeof(long),
| + .active = tm_cgpr_active,
| + .get = tm_cgpr32_get, .set = tm_cgpr32_set
| + },
| + [REGSET_TM_CFPR] = {
| + .core_note_type = NT_PPC_TM_CFPR, .n = ELF_NFPREG,
| + .size = sizeof(double), .align = sizeof(double),
| + .active = tm_cfpr_active, .get = tm_cfpr_get, .set = tm_cfpr_set
| + },
| + [REGSET_TM_CVMX] = {
| + .core_note_type = NT_PPC_TM_CVMX, .n = ELF_NVMX,
| + .size = sizeof(vector128), .align = sizeof(vector128),
| + .active = tm_cvmx_active, .get = tm_cvmx_get, .set = tm_cvmx_set
| + },
| +#endif
| };
|
| static const struct user_regset_view user_ppc_compat_view = {
| --
| 1.9.3Re: [PATCH V4 6/8] powerpc, ptrace: Enable support for transactional memory register sets
Quoted 99 lines · Sukadev Bhattiprolu
Anshuman Khandual [[email protected]] wrote:
| This patch enables get and set of transactional memory related register | sets through PTRACE_GETREGSET-PTRACE_SETREGSET interface by implementing | four new powerpc specific register sets i.e REGSET_TM_SPR, REGSET_TM_CGPR, | REGSET_TM_CFPR, REGSET_CVMX support corresponding to these following new | ELF core note types added previously in this regard. | | (1) NT_PPC_TM_SPR | (2) NT_PPC_TM_CGPR | (3) NT_PPC_TM_CFPR | (4) NT_PPC_TM_CVMX | | Signed-off-by: Anshuman Khandual <[email protected]> | --- | arch/powerpc/include/uapi/asm/elf.h | 2 + | arch/powerpc/kernel/ptrace.c | 666 +++++++++++++++++++++++++++++++++++- | 2 files changed, 653 insertions(+), 15 deletions(-) | | diff --git a/arch/powerpc/include/uapi/asm/elf.h b/arch/powerpc/include/uapi/asm/elf.h | index 59dad11..fdc8e2f 100644 | --- a/arch/powerpc/include/uapi/asm/elf.h | +++ b/arch/powerpc/include/uapi/asm/elf.h | @@ -91,6 +91,8 @@ | | #define ELF_NGREG 48 /* includes nip, msr, lr, etc. */ | #define ELF_NFPREG 33 /* includes fpscr */ | +#define ELF_NVMX 34 /* includes all vector registers */ | +#define ELF_NTMSPRREG 7 /* includes TM sprs, org_msr, dscr, tar, ppr */ | | typedef unsigned long elf_greg_t64; | typedef elf_greg_t64 elf_gregset_t64[ELF_NGREG]; | diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c | index 2bbbd10..b279947 100644 | --- a/arch/powerpc/kernel/ptrace.c | +++ b/arch/powerpc/kernel/ptrace.c | @@ -63,6 +63,11 @@ struct pt_regs_offset { | {.name = STR(gpr##num), .offset = offsetof(struct pt_regs, gpr[num])} | #define REG_OFFSET_END {.name = NULL, .offset = 0} | | +/* Some common structure offsets */ | +#define TSO(f) (offsetof(struct thread_struct, f)) | +#define TVSO(f) (offsetof(struct thread_vr_state, f)) | +#define TFSO(f) (offsetof(struct thread_fp_state, f)) | + | static const struct pt_regs_offset regoffset_table[] = { | GPR_OFFSET_NAME(0), | GPR_OFFSET_NAME(1), | @@ -792,6 +797,534 @@ static int evr_set(struct task_struct *target, const struct user_regset *regset, | } | #endif /* CONFIG_SPE */ | | +#ifdef CONFIG_PPC_TRANSACTIONAL_MEM | +/* | + * tm_spr_active | + * | + * This function checks number of available regisers in | + * the transactional memory SPR category. | + */ | +static int tm_spr_active(struct task_struct *target, | + const struct user_regset *regset) | +{ | + if (!cpu_has_feature(CPU_FTR_TM)) | + return -ENODEV; | + | + if (!MSR_TM_ACTIVE(target->thread.regs->msr)) | + return 0; | + | + return regset->n; | +} | + | +/* | + * tm_spr_get | + * | + * This function gets transactional memory related SPR registers | + * | + * Userspace interface buffer layout: | + * | + * struct { | + * u64 tm_tfhar; | + * u64 tm_texasr; | + * u64 tm_tfiar; | + * unsigned long tm_orig_msr; | + * unsigned long tm_tar; | + * unsigned long tm_ppr; | + * unsigned long tm_dscr; | + * }; | + */ | +static int tm_spr_get(struct task_struct *target, | + const struct user_regset *regset, | + unsigned int pos, unsigned int count, | + void *kbuf, void __user *ubuf) | +{ | + int ret; | + | + /* Build tests */ | + BUILD_BUG_ON(TSO(tm_tfhar) + sizeof(u64) != TSO(tm_texasr)); | + BUILD_BUG_ON(TSO(tm_texasr) + sizeof(u64) != TSO(tm_tfiar)); | + BUILD_BUG_ON(TSO(tm_tfiar) + sizeof(u64) != TSO(tm_orig_msr)); | + BUILD_BUG_ON(TSO(tm_orig_msr) + sizeof(unsigned long) +
Quoted 2 lines
Can we replace
TSO(tm_orig_msr)+ sizeof(unsigned long) withTSO(ckpt_regs)?
Yeah we can.
Quoted 19 lines
| + sizeof(struct pt_regs) != TSO(tm_tar)); | + BUILD_BUG_ON(TSO(tm_tar) + sizeof(unsigned long) != TSO(tm_ppr)); | + BUILD_BUG_ON(TSO(tm_ppr) + sizeof(unsigned long) != TSO(tm_dscr)); | + | + if (!cpu_has_feature(CPU_FTR_TM)) | + return -ENODEV; | + | + if (!MSR_TM_ACTIVE(target->thread.regs->msr)) | + return -ENODATA; | + | + /* Flush the states */ | + flush_fp_to_thread(target); | + flush_altivec_to_thread(target); | + flush_tmregs_to_thread(target); | + | + /* TFHAR register */ | + ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, | + &target->thread.tm_tfhar, 0, sizeof(u64));
Quoted 2 lines
The last two parameters, (
start_pos,end_pos) are easy to understand here, but...
Okay.
Quoted 8 lines
| + | + /* TEXASR register */ | + if (!ret) | + ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, | + &target->thread.tm_texasr, sizeof(u64), | + 2 * sizeof(u64));
Quoted 4 lines
... gets harder to understand here and subsequent fields below.
Given that you already do the
BUILD_BUG_ON()tests above, how about usingTSO(tm_texasr)and TSO(tfiar) here forstart_posandend_pos?
Hmm, I understand that as it looks kind of ugly, but writing to/from the user level buffer is done looking at the user interface buffer structure layout mentioned below.
* struct {
* u64 tm_tfhar; * u64 tm_texasr; * u64 tm_tfiar; * unsigned long tm_orig_msr; * unsigned long tm_tar; * unsigned long tm_ppr; * unsigned long tm_dscr;
* };
Looking at this structure will help some one understand the copy in/out process and it's order better.
Quoted 3 lines
Also, how about just returning if the copyout fails ? If the first copyout fails, we will still check 'if(!ret)' several times below.
Hmm, thats true. But the code flow is very similar to that of gpr_get/ gpr_set functions though it has a BUILD_BUG_ON check in between. The rational is to stop copyout/in when we hit the first error and not to proceed any further. We can return from the first error itself.
Quoted 66 lines
| +
| + /* TFIAR register */
| + if (!ret)
| + ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
| + &target->thread.tm_tfiar,
| + 2 * sizeof(u64), 3 * sizeof(u64));
| +
| + /* TM checkpointed original MSR */
| + if (!ret)
| + ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
| + &target->thread.tm_orig_msr, 3 * sizeof(u64),
| + 3 * sizeof(u64) + sizeof(unsigned long));
| +
| + /* TM checkpointed TAR register */
| + if (!ret)
| + ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
| + &target->thread.tm_tar, 3 * sizeof(u64) +
| + sizeof(unsigned long) ,
| + 3 * sizeof(u64) + 2 * sizeof(unsigned long));
| +
| + /* TM checkpointed PPR register */
| + if (!ret)
| + ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
| + &target->thread.tm_ppr, 3 * sizeof(u64) +
| + 2 * sizeof(unsigned long),
| + 3 * sizeof(u64) + 3 * sizeof(unsigned long));
| +
| + /* TM checkpointed DSCR register */
| + if (!ret)
| + ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
| + &target->thread.tm_dscr, 3 * sizeof(u64) +
| + 3 * sizeof(unsigned long),
| + 3 * sizeof(u64) + 4 * sizeof(unsigned long));
| + return ret;
| +}
| +
| +/*
| + * tm_spr_set
| + *
| + * This function sets transactional memory related SPR registers
| + *
| + * Userspace interface buffer layout:
| + *
| + * struct {
| + * u64 tm_tfhar;
| + * u64 tm_texasr;
| + * u64 tm_tfiar;
| + * unsigned long tm_orig_msr;
| + * unsigned long tm_tar;
| + * unsigned long tm_ppr;
| + * unsigned long tm_dscr;
| + * };
| + */
| +static int tm_spr_set(struct task_struct *target,
| + const struct user_regset *regset,
| + unsigned int pos, unsigned int count,
| + const void *kbuf, const void __user *ubuf)
| +{
| + int ret;
| +
| + /* Build tests */
| + BUILD_BUG_ON(TSO(tm_tfhar) + sizeof(u64) != TSO(tm_texasr));
| + BUILD_BUG_ON(TSO(tm_texasr) + sizeof(u64) != TSO(tm_tfiar));
| + BUILD_BUG_ON(TSO(tm_orig_msr) + sizeof(unsigned long)Quoted 2 lines
Can we replace
TSO(tm_orig_msr)+ sizeof(unsigned long) withTSO(ckpt_regs)?
Yeah we can.
Quoted 7 lines
| + + sizeof(struct pt_regs) != TSO(tm_tar)); | + BUILD_BUG_ON(TSO(tm_tar) + sizeof(unsigned long) != TSO(tm_ppr)); | + BUILD_BUG_ON(TSO(tm_ppr) + sizeof(unsigned long) != TSO(tm_dscr)); | + BUILD_BUG_ON(TSO(tm_tfiar) + sizeof(u64) != TSO(tm_orig_msr));How about moving this last line up after the check for
TSO(tm_tfiar)?
Done.
Quoted 22 lines
| + | + if (!cpu_has_feature(CPU_FTR_TM)) | + return -ENODEV; | + | + if (!MSR_TM_ACTIVE(target->thread.regs->msr)) | + return -ENODATA; | + | + /* Flush the states */ | + flush_fp_to_thread(target); | + flush_altivec_to_thread(target); | + flush_tmregs_to_thread(target); | + | + /* TFHAR register */ | + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, | + &target->thread.tm_tfhar, 0, sizeof(u64)); | + | + /* TEXASR register */ | + if (!ret) | + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, | + &target->thread.tm_texasr, sizeof(u64), | + 2 * sizeof(u64));
Quoted 1 line
Return if
copyin()fails ?
Yeah both the cases are similar.
Quoted 353 lines
| +
| + /* TFIAR register */
| + if (!ret)
| + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
| + &target->thread.tm_tfiar,
| + 2 * sizeof(u64), 3 * sizeof(u64));
| +
| +
| + /* TM checkpointed orig MSR */
| + if (!ret)
| + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
| + &target->thread.tm_orig_msr, 3 * sizeof(u64),
| + 3 * sizeof(u64) + sizeof(unsigned long));
| +
| +
| + /* TM checkpointed TAR register */
| + if (!ret)
| + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
| + &target->thread.tm_tar, 3 * sizeof(u64) +
| + sizeof(unsigned long), 3 * sizeof(u64) +
| + 2 * sizeof(unsigned long));
| +
| + /* TM checkpointed PPR register */
| + if (!ret)
| + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
| + &target->thread.tm_ppr, 3 * sizeof(u64) +
| + 2 * sizeof(unsigned long), 3 * sizeof(u64) +
| + 3 * sizeof(unsigned long));
| +
| + /* TM checkpointed DSCR register */
| + if (!ret)
| + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
| + &target->thread.tm_dscr, 3 * sizeof(u64) +
| + 3 * sizeof(unsigned long), 3 * sizeof(u64) +
| + 4 * sizeof(unsigned long));
| + return ret;
| +}
| +
| +/*
| + * tm_cgpr_active
| + *
| + * This function checks the number of available regisers in
| + * transaction checkpointed GPR category.
| + */
| +static int tm_cgpr_active(struct task_struct *target,
| + const struct user_regset *regset)
| +{
| + if (!cpu_has_feature(CPU_FTR_TM))
| + return -ENODEV;
| +
| + if (!MSR_TM_ACTIVE(target->thread.regs->msr))
| + return 0;
| +
| + return regset->n;
| +}
| +
| +/*
| + * tm_cgpr_get
| + *
| + * This function gets transaction checkpointed GPR registers
| + *
| + * When the transaction is active, 'ckpt_regs' holds all the checkpointed
| + * GPR register values for the current transaction to fall back on if it
| + * aborts in between. This function gets those checkpointed GPR registers.
| + *
| + * Userspace interface buffer layout:
| + *
| + * struct data {
| + * struct pt_regs ckpt_regs;
| + * };
| + */
| +static int tm_cgpr_get(struct task_struct *target,
| + const struct user_regset *regset,
| + unsigned int pos, unsigned int count,
| + void *kbuf, void __user *ubuf)
| +{
| + int ret;
| +
| + if (!cpu_has_feature(CPU_FTR_TM))
| + return -ENODEV;
| +
| + if (!MSR_TM_ACTIVE(target->thread.regs->msr))
| + return -ENODATA;
| +
| + flush_fp_to_thread(target);
| + flush_altivec_to_thread(target);
| + flush_tmregs_to_thread(target);
| + ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
| + &target->thread.ckpt_regs, 0,
| + sizeof(struct pt_regs));
| + return ret;
| +}
| +
| +/*
| + * tm_cgpr_set
| + *
| + * This function sets in transaction checkpointed GPR registers
| + *
| + * When the transaction is active, 'ckpt_regs' holds the checkpointed
| + * GPR register values for the current transaction to fall back on if it
| + * aborts in between. This function sets those checkpointed GPR registers.
| + *
| + * Userspace intaerface buffer:
| + *
| + * struct data {
| + * struct pt_regs ckpt_regs;
| + * };
| + */
| +static int tm_cgpr_set(struct task_struct *target,
| + const struct user_regset *regset,
| + unsigned int pos, unsigned int count,
| + const void *kbuf, const void __user *ubuf)
| +{
| + int ret;
| +
| + if (!cpu_has_feature(CPU_FTR_TM))
| + return -ENODEV;
| +
| + if (!MSR_TM_ACTIVE(target->thread.regs->msr))
| + return -ENODATA;
| +
| + flush_fp_to_thread(target);
| + flush_altivec_to_thread(target);
| + flush_tmregs_to_thread(target);
| + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
| + &target->thread.ckpt_regs, 0,
| + sizeof(struct pt_regs));
| + return ret;
| +}
| +
| +/*
| + * tm_cfpr_active
| + *
| + * This function checks number of available regisers in
| + * transaction checkpointed FPR category.
| + */
| +static int tm_cfpr_active(struct task_struct *target,
| + const struct user_regset *regset)
| +{
| + if (!cpu_has_feature(CPU_FTR_TM))
| + return -ENODEV;
| +
| + if (!MSR_TM_ACTIVE(target->thread.regs->msr))
| + return 0;
| +
| + return regset->n;
| +}
| +
| +/*
| + * tm_cfpr_get
| + *
| + * This function gets in transaction checkpointed FPR registers
| + *
| + * When the transaction is active 'fp_state' holds the checkpointed
| + * values for the current transaction to fall back on if it aborts
| + * in between. This function gets those checkpointed FPR registers.
| + *
| + * Userspace interface buffer layout:
| + *
| + * struct data {
| + * u64 fpr[32];
| + * u64 fpscr;
| + *};
| + */
| +static int tm_cfpr_get(struct task_struct *target,
| + const struct user_regset *regset,
| + unsigned int pos, unsigned int count,
| + void *kbuf, void __user *ubuf)
| +{
| + u64 buf[33];
| + int i;
| +
| + if (!cpu_has_feature(CPU_FTR_TM))
| + return -ENODEV;
| +
| + if (!MSR_TM_ACTIVE(target->thread.regs->msr))
| + return -ENODATA;
| +
| + flush_fp_to_thread(target);
| + flush_altivec_to_thread(target);
| + flush_tmregs_to_thread(target);
| +
| + /* copy to local buffer then write that out */
| + for (i = 0; i < 32 ; i++)
| + buf[i] = target->thread.TS_FPR(i);
| + buf[32] = target->thread.fp_state.fpscr;
| + return user_regset_copyout(&pos, &count, &kbuf, &ubuf, buf, 0, -1);
| +}
| +
| +/*
| + * tm_cfpr_set
| + *
| + * This function sets in transaction checkpointed FPR registers
| + *
| + * When the transaction is active 'fp_state' holds the checkpointed
| + * FPR register values for the current transaction to fall back on
| + * if it aborts in between. This function sets these checkpointed
| + * FPR registers.
| + *
| + * Userspace interface buffer layout:
| + *
| + * struct data {
| + * u64 fpr[32];
| + * u64 fpscr;
| + *};
| + */
| +static int tm_cfpr_set(struct task_struct *target,
| + const struct user_regset *regset,
| + unsigned int pos, unsigned int count,
| + const void *kbuf, const void __user *ubuf)
| +{
| + u64 buf[33];
| + int i;
| +
| + if (!cpu_has_feature(CPU_FTR_TM))
| + return -ENODEV;
| +
| + if (!MSR_TM_ACTIVE(target->thread.regs->msr))
| + return -ENODATA;
| +
| + flush_fp_to_thread(target);
| + flush_altivec_to_thread(target);
| + flush_tmregs_to_thread(target);
| +
| + /* copy to local buffer then write that out */
| + i = user_regset_copyin(&pos, &count, &kbuf, &ubuf, buf, 0, -1);
| + if (i)
| + return i;
| + for (i = 0; i < 32 ; i++)
| + target->thread.TS_FPR(i) = buf[i];
| + target->thread.fp_state.fpscr = buf[32];
| + return 0;
| +}
| +
| +/*
| + * tm_cvmx_active
| + *
| + * This function checks the number of available regisers in
| + * checkpointed VMX category.
| + */
| +static int tm_cvmx_active(struct task_struct *target,
| + const struct user_regset *regset)
| +{
| + if (!cpu_has_feature(CPU_FTR_TM))
| + return -ENODEV;
| +
| + if (!MSR_TM_ACTIVE(target->thread.regs->msr))
| + return 0;
| +
| + return regset->n;
| +}
| +
| +/*
| + * tm_cvmx_get
| + *
| + * This function gets in transaction checkpointed VMX registers
| + *
| + * When the transaction is active 'vr_state' and 'vr_save' hold
| + * the checkpointed values for the current transaction to fall
| + * back on if it aborts in between.
| + *
| + * User interface buffer:
| + *
| + * struct data {
| + * vector128 vr[32];
| + * vector128 vscr;
| + * vector128 vrsave;
| + *};
| + */
| +static int tm_cvmx_get(struct task_struct *target,
| + const struct user_regset *regset,
| + unsigned int pos, unsigned int count,
| + void *kbuf, void __user *ubuf)
| +{
| + int ret;
| +
| + BUILD_BUG_ON(TVSO(vscr) != TVSO(vr[32]));
| +
| + if (!cpu_has_feature(CPU_FTR_TM))
| + return -ENODEV;
| +
| + if (!MSR_TM_ACTIVE(target->thread.regs->msr))
| + return -ENODATA;
| +
| + /* Flush the state */
| + flush_fp_to_thread(target);
| + flush_altivec_to_thread(target);
| + flush_tmregs_to_thread(target);
| +
| + ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
| + &target->thread.vr_state, 0,
| + 33 * sizeof(vector128));
| + if (!ret) {
| + /*
| + * Copy out only the low-order word of vrsave.
| + */
| + union {
| + elf_vrreg_t reg;
| + u32 word;
| + } vrsave;
| + memset(&vrsave, 0, sizeof(vrsave));
| + vrsave.word = target->thread.vrsave;
| + ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &vrsave,
| + 33 * sizeof(vector128), -1);
| + }
| +
| + return ret;
| +}
| +
| +/*
| + * tm_cvmx_set
| + *
| + * This function sets in transaction checkpointed VMX registers
| + *
| + * When the transaction is active 'vr_state' and 'vr_save' hold
| + * the checkpointed values for the current transaction to fall
| + * back on if it aborts in between.
| + *
| + * Userspace interface buffer:
| + *
| + * struct data {
| + * vector128 vr[32];
| + * vector128 vscr;
| + * vector128 vrsave;
| + *};
| + */
| +static int tm_cvmx_set(struct task_struct *target,
| + const struct user_regset *regset,
| + unsigned int pos, unsigned int count,
| + const void *kbuf, const void __user *ubuf)
| +{
| + int ret;
| +
| + BUILD_BUG_ON(TVSO(vscr) != TVSO(vr[32]));
| +
| + if (!cpu_has_feature(CPU_FTR_TM))
| + return -ENODEV;
| +
| + if (!MSR_TM_ACTIVE(target->thread.regs->msr))
| + return -ENODATA;
| +
| + flush_fp_to_thread(target);
| + flush_altivec_to_thread(target);
| + flush_tmregs_to_thread(target);
| +
| + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
| + &target->thread.vr_state, 0,
| + 33 * sizeof(vector128));
| + if (!ret && count > 0) {
| + /*
| + * We use only the first word of vrsave.Quoted 1 line
For consistency with the
_get()function above, s/first/low-order/ ?
Done.
Quoted 86 lines
| + */
| + union {
| + elf_vrreg_t reg;
| + u32 word;
| + } vrsave;
| + memset(&vrsave, 0, sizeof(vrsave));
| + vrsave.word = target->thread.vrsave;
| + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &vrsave,
| + 33 * sizeof(vector128), -1);
| + if (!ret)
| + target->thread.vrsave = vrsave.word;
| + }
| +
| + return ret;
| +}
| +#endif /* CONFIG_PPC_TRANSACTIONAL_MEM */
|
| /*
| * These are our native regset flavors.
| @@ -808,6 +1341,12 @@ enum powerpc_regset {
| #ifdef CONFIG_SPE
| REGSET_SPE,
| #endif
| +#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
| + REGSET_TM_SPR, /* TM specific SPR registers */
| + REGSET_TM_CGPR, /* TM checkpointed GPR registers */
| + REGSET_TM_CFPR, /* TM checkpointed FPR registers */
| + REGSET_TM_CVMX, /* TM checkpointed VMX registers */
| +#endif
| };
|
| static const struct user_regset native_regsets[] = {
| @@ -842,6 +1381,28 @@ static const struct user_regset native_regsets[] = {
| .active = evr_active, .get = evr_get, .set = evr_set
| },
| #endif
| +#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
| + [REGSET_TM_SPR] = {
| + .core_note_type = NT_PPC_TM_SPR, .n = ELF_NTMSPRREG,
| + .size = sizeof(u64), .align = sizeof(u64),
| + .active = tm_spr_active, .get = tm_spr_get, .set = tm_spr_set
| + },
| + [REGSET_TM_CGPR] = {
| + .core_note_type = NT_PPC_TM_CGPR, .n = ELF_NGREG,
| + .size = sizeof(long), .align = sizeof(long),
| + .active = tm_cgpr_active, .get = tm_cgpr_get, .set = tm_cgpr_set
| + },
| + [REGSET_TM_CFPR] = {
| + .core_note_type = NT_PPC_TM_CFPR, .n = ELF_NFPREG,
| + .size = sizeof(double), .align = sizeof(double),
| + .active = tm_cfpr_active, .get = tm_cfpr_get, .set = tm_cfpr_set
| + },
| + [REGSET_TM_CVMX] = {
| + .core_note_type = NT_PPC_TM_CVMX, .n = ELF_NVMX,
| + .size = sizeof(vector128), .align = sizeof(vector128),
| + .active = tm_cvmx_active, .get = tm_cvmx_get, .set = tm_cvmx_set
| + },
| +#endif
| };
|
| static const struct user_regset_view user_ppc_native_view = {
| @@ -852,24 +1413,35 @@ static const struct user_regset_view user_ppc_native_view = {
| #ifdef CONFIG_PPC64
| #include <linux/compat.h>
|
| -static int gpr32_get(struct task_struct *target,
| +static int common_gpr32_get(struct task_struct *target,
| const struct user_regset *regset,
| unsigned int pos, unsigned int count,
| - void *kbuf, void __user *ubuf)
| + void *kbuf, void __user *ubuf, bool in_tm)
| {
| - const unsigned long *regs = &target->thread.regs->gpr[0];
| + const unsigned long *regs;
| compat_ulong_t *k = kbuf;
| compat_ulong_t __user *u = ubuf;
| compat_ulong_t reg;
| int i;
|
| - if (target->thread.regs == NULL)
| - return -EIO;
| + if (in_tm) {
| +#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
| + regs = &target->thread.ckpt_regs.gpr[0];
| +#endifQuoted 3 lines
regs uninitialized if
in_tmis true andCONFIG_PPC_TRANSACTIONAL_MEMis false ? It appears that it cannot/should not happen, how aboutBUGON()? or at least regs = NULL to silence compiler warnings ?
Yeah it cannot happen, seems like compiler is able to figure that out as I dont get any warning because of that. BUG_ON sounds like a good option after the if-else block to verify whether the regs variable got any valid address value to it or not. Also we can start with regs = NULL at the starting of the function as well.
Quoted 47 lines
| + } else {
| + regs = &target->thread.regs->gpr[0];
|
| - if (!FULL_REGS(target->thread.regs)) {
| - /* We have a partial register set. Fill 14-31 with bogus values */
| - for (i = 14; i < 32; i++)
| - target->thread.regs->gpr[i] = NV_REG_POISON;
| + if (target->thread.regs == NULL)
| + return -EIO;
| +
| + if (!FULL_REGS(target->thread.regs)) {
| + /*
| + * We have a partial register set.
| + * Fill 14-31 with bogus values.
| + */
| + for (i = 14; i < 32; i++)
| + target->thread.regs->gpr[i] = NV_REG_POISON;
| + }
| }
|
| pos /= sizeof(reg);
| @@ -909,20 +1481,28 @@ static int gpr32_get(struct task_struct *target,
| PT_REGS_COUNT * sizeof(reg), -1);
| }
|
| -static int gpr32_set(struct task_struct *target,
| +static int common_gpr32_set(struct task_struct *target,
| const struct user_regset *regset,
| unsigned int pos, unsigned int count,
| - const void *kbuf, const void __user *ubuf)
| + const void *kbuf, const void __user *ubuf, bool in_tm)
| {
| - unsigned long *regs = &target->thread.regs->gpr[0];
| + unsigned long *regs;
| const compat_ulong_t *k = kbuf;
| const compat_ulong_t __user *u = ubuf;
| compat_ulong_t reg;
|
| - if (target->thread.regs == NULL)
| - return -EIO;
| + if (in_tm) {
| +#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
| + regs = &target->thread.ckpt_regs.gpr[0];
| +#endifQuoted 1 line
ditto
Done.
Quoted 86 lines
| + } else {
| + regs = &target->thread.regs->gpr[0];
|
| - CHECK_FULL_REGS(target->thread.regs);
| + if (target->thread.regs == NULL)
| + return -EIO;
| +
| + CHECK_FULL_REGS(target->thread.regs);
| + }
|
| pos /= sizeof(reg);
| count /= sizeof(reg);
| @@ -982,6 +1562,39 @@ static int gpr32_set(struct task_struct *target,
| (PT_TRAP + 1) * sizeof(reg), -1);
| }
|
| +#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
| +static int tm_cgpr32_get(struct task_struct *target,
| + const struct user_regset *regset,
| + unsigned int pos, unsigned int count,
| + void *kbuf, void __user *ubuf)
| +{
| + return common_gpr32_get(target, regset, pos, count, kbuf, ubuf, 1);
| +}
| +
| +static int tm_cgpr32_set(struct task_struct *target,
| + const struct user_regset *regset,
| + unsigned int pos, unsigned int count,
| + const void *kbuf, const void __user *ubuf)
| +{
| + return common_gpr32_set(target, regset, pos, count, kbuf, ubuf, 0);
| +}
| +#endif /* CONFIG_PPC_TRANSACTIONAL_MEM */
| +
| +static int gpr32_get(struct task_struct *target,
| + const struct user_regset *regset,
| + unsigned int pos, unsigned int count,
| + void *kbuf, void __user *ubuf)
| +{
| + return common_gpr32_get(target, regset, pos, count, kbuf, ubuf, 0);
| +}
| +
| +static int gpr32_set(struct task_struct *target,
| + const struct user_regset *regset,
| + unsigned int pos, unsigned int count,
| + const void *kbuf, const void __user *ubuf)
| +{
| + return common_gpr32_set(target, regset, pos, count, kbuf, ubuf, 0);
| +}
| /*
| * These are the regset flavors matching the CONFIG_PPC32 native set.
| */
| @@ -1010,6 +1623,29 @@ static const struct user_regset compat_regsets[] = {
| .active = evr_active, .get = evr_get, .set = evr_set
| },
| #endif
| +#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
| + [REGSET_TM_SPR] = {
| + .core_note_type = NT_PPC_TM_SPR, .n = ELF_NTMSPRREG,
| + .size = sizeof(u64), .align = sizeof(u64),
| + .active = tm_spr_active, .get = tm_spr_get, .set = tm_spr_set
| + },
| + [REGSET_TM_CGPR] = {
| + .core_note_type = NT_PPC_TM_CGPR, .n = ELF_NGREG,
| + .size = sizeof(long), .align = sizeof(long),
| + .active = tm_cgpr_active,
| + .get = tm_cgpr32_get, .set = tm_cgpr32_set
| + },
| + [REGSET_TM_CFPR] = {
| + .core_note_type = NT_PPC_TM_CFPR, .n = ELF_NFPREG,
| + .size = sizeof(double), .align = sizeof(double),
| + .active = tm_cfpr_active, .get = tm_cfpr_get, .set = tm_cfpr_set
| + },
| + [REGSET_TM_CVMX] = {
| + .core_note_type = NT_PPC_TM_CVMX, .n = ELF_NVMX,
| + .size = sizeof(vector128), .align = sizeof(vector128),
| + .active = tm_cvmx_active, .get = tm_cvmx_get, .set = tm_cvmx_set
| + },
| +#endif
| };
|
| static const struct user_regset_view user_ppc_compat_view = {
| --
| 1.9.3PATCH v4 7/8 powerpc, ptrace: Enable support for miscellaneous debug registers
In reply to Anshuman KhandualThis patch enables get and set of miscellaneous debug registers through ptrace PTRACE_GETREGSET-PTRACE_SETREGSET interface by implementing new powerpc specific register set REGSET_MISC support corresponding to the new ELF core note NT_PPC_MISC added previously in this regard.
--- arch/powerpc/include/uapi/asm/elf.h | 1 + arch/powerpc/kernel/ptrace.c | 102 ++++++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+)
arch/powerpc/include/uapi/asm/elf.h +1 -0
@@ -93,6 +93,7 @@#define ELF_NFPREG 33/* includes fpscr */ #define ELF_NVMX 34/* includes all vector registers */ #define ELF_NTMSPRREG 7/* includes TM sprs, org_msr, dscr, tar, ppr */ +#define ELF_NMISCREG 3/* includes dscr, tar, ppr */ typedef unsigned long elf_greg_t64 ;typedef elf_greg_t64 elf_gregset_t64 [ELF_NGREG ];
arch/powerpc/kernel/ptrace.c +102 -0
126 lines not on this page · raw message
Signature · 1 line
1.9.3
Re: [PATCH V4 7/8] powerpc, ptrace: Enable support for miscellaneous debug registers
Quoted 4 lines · Anshuman Khandual
This patch enables get and set of miscellaneous debug registers through ptrace PTRACE_GETREGSET-PTRACE_SETREGSET interface by implementing new powerpc specific register set
REGSET_MISCsupport corresponding to the new ELF core noteNT_PPC_MISCadded previously in this regard.
Right now this one does not compile for "ppc64e_defconfig" and "pmac32_defconfig" config options. The patch below will fix it and would be part of next revision.
arch/powerpc/kernel/ptrace.c +22 -1
@@ -1326,6 +1326,7 @@ static int tm_cvmx_set(struct task_struct *target, }#endif /* CONFIG_PPC_TRANSACTIONAL_MEM */ +#ifdef CONFIG_PPC64 /* * get_misc_dbg *
@@ -1339,6 +1340,9 @@ static int tm_cvmx_set(struct task_struct *target,* unsigned long ppr; * unsigned long tar; * }; +* +* The data element 'tar' will be valid only if the +* kernel has CONFIG_PPC_BOOK3S_64 config option enabled. */ static int get_misc_dbg(struct task_struct *target, const struct user_regset *regset, unsigned int pos,
@@ -1348,7 +1352,10 @@ static int get_misc_dbg(struct task_struct *target,/* Build test */ BUILD_BUG_ON (TSO (dscr) +2 *sizeof (unsigned long ) !=TSO (ppr)); + +#ifdef CONFIG_PPC_BOOK3S_64 BUILD_BUG_ON (TSO (ppr) +sizeof (unsigned long ) !=TSO (tar)); +#endif /* DSCR register */ ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
@@ -1362,12 +1369,14 @@ static int get_misc_dbg(struct task_struct *target,sizeof (unsigned long ), 2 * sizeof(unsigned long)); +#ifdef CONFIG_PPC_BOOK3S_64 /* TAR register */ if (!ret) ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, &target->thread.tar,2 *sizeof (unsigned long ),3 *sizeof (unsigned long )); +#endif return ret; }
@@ -1384,6 +1393,9 @@ static int get_misc_dbg(struct task_struct *target,* unsigned long ppr; * unsigned long tar; * }; +* +* The data element 'tar' will be valid only if the +* kernel has CONFIG_PPC_BOOK3S_64 config option enabled. */ static int set_misc_dbg(struct task_struct *target, const struct user_regset *regset, unsigned int pos,
@@ -1394,7 +1406,10 @@ static int set_misc_dbg(struct task_struct *target,/* Build test */ BUILD_BUG_ON (TSO (dscr) +2 *sizeof (unsigned long ) !=TSO (ppr)); + +#ifdef CONFIG_PPC_BOOK3S_64 BUILD_BUG_ON (TSO (ppr) +sizeof (unsigned long ) !=TSO (tar)); +#endif /* DSCR register */ ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
@@ -1407,15 +1422,17 @@ static int set_misc_dbg(struct task_struct *target, &target->thread.ppr,sizeof (unsigned long ), 2 * sizeof(unsigned long)); - +#ifdef CONFIG_PPC_BOOK3S_64 /* TAR register */ if (!ret) ret =user_regset_copyin (&pos, &count, &kbuf, &ubuf, &target->thread.tar,2 *sizeof (unsigned long ),3 *sizeof (unsigned long )); +#endif return ret; } +#endif /* CONFIG_PPC64 */ /* * These are our native regset flavors.
@@ -1438,7 +1455,9 @@ enum powerpc_regset { REGSET_TM_CFPR, /* TM checkpointed FPR registers */ REGSET_TM_CVMX, /* TM checkpointed VMX registers */#endif +#ifdef CONFIG_PPC64 REGSET_MISC /* Miscellaneous debug registers */ +#endif };static const struct user_regset native_regsets[] = {
@@ -1495,11 +1514,13 @@ static const struct user_regset native_regsets[] = { .active = tm_cvmx_active, .get = tm_cvmx_get, .set = tm_cvmx_set },#endif +#ifdef CONFIG_PPC64 [REGSET_MISC] = { .core_note_type = NT_PPC_MISC, .n = ELF_NMISCREG, .size = sizeof(u64), .align = sizeof(u64), .get = get_misc_dbg, .set = set_misc_dbg }, +#endif }; static const struct user_regset_view user_ppc_native_view = {
Re: [PATCH V4 7/8] powerpc, ptrace: Enable support for miscellaneous debug registers
Quoted 9 lines · Anshuman Khandual
Quoted 4 lines · Anshuman Khandual
This patch enables get and set of miscellaneous debug registers through ptrace PTRACE_GETREGSET-PTRACE_SETREGSET interface by implementing new powerpc specific register set
REGSET_MISCsupport corresponding to the new ELF core noteNT_PPC_MISCadded previously in this regard.Right now this one does not compile for "
ppc64e_defconfig" and "pmac32_defconfig" config options. The patch below will fix it and would be part of next revision.
It would be great to have a test tool for that under tools/testing/selftests/ptrace/
Quoted 117 lines
arch/powerpc/kernel/ptrace.c +22
-1@@ -1326,6 +1326,7 @@ static int tm_cvmx_set(struct task_struct *target, }#endif /* CONFIG_PPC_TRANSACTIONAL_MEM */ +#ifdef CONFIG_PPC64 /* * get_misc_dbg * @@ -1339,6 +1340,9 @@ static int tm_cvmx_set(struct task_struct *target,* unsigned long ppr; * unsigned long tar; * }; +* +* The data element 'tar' will be valid only if the +* kernel has CONFIG_PPC_BOOK3S_64 config option enabled. */ static int get_misc_dbg(struct task_struct *target, const struct user_regset *regset, unsigned int pos,@@ -1348,7 +1352,10 @@ static int get_misc_dbg(struct task_struct *target,/* Build test */ BUILD_BUG_ON (TSO (dscr) +2 *sizeof (unsigned long ) !=TSO (ppr)); + +#ifdef CONFIG_PPC_BOOK3S_64 BUILD_BUG_ON (TSO (ppr) +sizeof (unsigned long ) !=TSO (tar)); +#endif /* DSCR register */ ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,@@ -1362,12 +1369,14 @@ static int get_misc_dbg(struct task_struct *target,sizeof (unsigned long ), 2 * sizeof(unsigned long)); +#ifdef CONFIG_PPC_BOOK3S_64 /* TAR register */ if (!ret) ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, &target->thread.tar,2 *sizeof (unsigned long ),3 *sizeof (unsigned long )); +#endif return ret; }@@ -1384,6 +1393,9 @@ static int get_misc_dbg(struct task_struct *target,* unsigned long ppr; * unsigned long tar; * }; +* +* The data element 'tar' will be valid only if the +* kernel has CONFIG_PPC_BOOK3S_64 config option enabled. */ static int set_misc_dbg(struct task_struct *target, const struct user_regset *regset, unsigned int pos,@@ -1394,7 +1406,10 @@ static int set_misc_dbg(struct task_struct *target,/* Build test */ BUILD_BUG_ON (TSO (dscr) +2 *sizeof (unsigned long ) !=TSO (ppr)); + +#ifdef CONFIG_PPC_BOOK3S_64 BUILD_BUG_ON (TSO (ppr) +sizeof (unsigned long ) !=TSO (tar)); +#endif /* DSCR register */ ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,@@ -1407,15 +1422,17 @@ static int set_misc_dbg(struct task_struct *target, &target->thread.ppr,sizeof (unsigned long ), 2 * sizeof(unsigned long)); - +#ifdef CONFIG_PPC_BOOK3S_64 /* TAR register */ if (!ret) ret =user_regset_copyin (&pos, &count, &kbuf, &ubuf, &target->thread.tar,2 *sizeof (unsigned long ),3 *sizeof (unsigned long )); +#endif return ret; } +#endif /* CONFIG_PPC64 */ /* * These are our native regset flavors. @@ -1438,7 +1455,9 @@ enum powerpc_regset { REGSET_TM_CFPR, /* TM checkpointed FPR registers */ REGSET_TM_CVMX, /* TM checkpointed VMX registers */#endif +#ifdef CONFIG_PPC64 REGSET_MISC /* Miscellaneous debug registers */ +#endif };static const struct user_regset native_regsets[] = {@@ -1495,11 +1514,13 @@ static const struct user_regset native_regsets[] = { .active = tm_cvmx_active, .get = tm_cvmx_get, .set = tm_cvmx_set },#endif +#ifdef CONFIG_PPC64 [REGSET_MISC] = { .core_note_type = NT_PPC_MISC, .n = ELF_NMISCREG, .size = sizeof(u64), .align = sizeof(u64), .get = get_misc_dbg, .set = set_misc_dbg }, +#endif }; static const struct user_regset_view user_ppc_native_view = {_______________________________________________
Linuxppc-dev mailing list
[email protected]
https://lists.ozlabs.org/listinfo/linuxppc-dev
Signature · 2 lines
Regards, Denis
Re: [PATCH V4 7/8] powerpc, ptrace: Enable support for miscellaneous debug registers
Quoted 7 lines · Denis Kirjanov
Quoted 6 lines · Anshuman Khandual
Quoted 6 lines · Anshuman Khandual
Quoted 4 lines
Quoted 4 lines
This patch enables get and set of miscellaneous debug registers through ptrace PTRACE_GETREGSET-PTRACE_SETREGSET interface by implementing new powerpc specific register set
REGSET_MISCsupport corresponding to the new ELF core noteNT_PPC_MISCadded previously in this regard.
Quoted 6 lines
Quoted 3 lines
Quoted 3 lines
Right now this one does not compile for "
ppc64e_defconfig" and "pmac32_defconfig" config options. The patch below will fix it and would be part of next revision.It would be great to have a test tool for that under
tools/testing/selftests/ptrace/
Hey Denis,
I have already added one test case under selftests/powerpc/tm/ which will test all the newly added ELF core note based ptrace requests on powerpc. This test case is added as part of the next patch 8/8 in the series. Please let me know if the test case does not cover something you are looking for.
Re: [PATCH V4 7/8] powerpc, ptrace: Enable support for miscellaneous debug registers
Quoted 18 lines · Anshuman Khandual
Quoted 10 lines · Denis Kirjanov
Quoted 9 lines · Anshuman Khandual
Quoted 9 lines · Anshuman Khandual
Quoted 7 lines
Quoted 7 lines
This patch enables get and set of miscellaneous debug registers through
ptrace PTRACE_GETREGSET-PTRACE_SETREGSET interface by implementing new
powerpc specific register setREGSET_MISCsupport corresponding to the
new ELF core noteNT_PPC_MISCadded previously in this regard.Quoted 6 lines
Quoted 3 lines
Quoted 3 lines
Right now this one does not compile for "
ppc64e_defconfig" and "pmac32_defconfig" config options. The patch below will fix it and would be part of next revision.It would be great to have a test tool for that under
tools/testing/selftests/ptrace/
Quoted 7 lines
Hey Denis,
I have already added one test case under selftests/powerpc/tm/ which will test all the newly added ELF core note based ptrace requests on powerpc. This test case is added as part of the next patch 8/8 in the series. Please let me know if the test case does not cover something you are looking for.
Oh, I've missed this one. Anyway, I'll wait the second version to test.
Thanks.
Quoted 5 lines
_______________________________________________
Linuxppc-dev mailing list
[email protected]
https://lists.ozlabs.org/listinfo/linuxppc-dev
PATCH v4 8/8 selftests, powerpc: Add new test case for TM related ptrace interfaces
In reply to Anshuman KhandualThis patch adds one more test case called tm-ptrace targeting TM related ptrace interfaces. This test creates one child process to run some basic transactions and the parent process attaches the child to do some ptrace probing using the recently added regset interfaces. The parent process then compares the received values against the expected values to verify whether it passed the test or not.
--- tools/testing/selftests/powerpc/tm/Makefile | 2 +- tools/testing/selftests/powerpc/tm/tm-ptrace.c | 529 +++++++++++++++++++++++++ 2 files changed, 530 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/powerpc/tm/tm-ptrace.c
tools/testing/selftests/powerpc/tm/Makefile +1 -1
@@ -1,4 +1,4 @@ -PROGS := tm-resched-dscr +PROGS := tm-resched-dscr tm-ptrace all: $(PROGS)
tools/testing/selftests/powerpc/tm/tm-ptrace.c new file +529 -0
529 lines not on this page · raw message
Signature · 1 line
1.9.3