[PATCH 2/2] powerpc: Use helper function to flush TM state in ptrace
Pedro Franco de Carvalho
pedromfc at linux.vnet.ibm.com
Wed Jun 20 05:54:29 AEST 2018
This patch updates the get/set regset functions that flush tm, fpu and
altvec state when TM is available and active to use a helper function.
Signed-off-by: Pedro Franco de Carvalho <pedromfc at linux.vnet.ibm.com>
---
arch/powerpc/kernel/ptrace.c | 104 ++++++++++++-------------------------------
1 file changed, 28 insertions(+), 76 deletions(-)
diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
index 0d56857e1e89..84fa97587850 100644
--- a/arch/powerpc/kernel/ptrace.c
+++ b/arch/powerpc/kernel/ptrace.c
@@ -845,17 +845,10 @@ static int tm_cgpr_get(struct task_struct *target,
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;
+ int ret = tm_flush_if_active(target);
- flush_tmregs_to_thread(target);
- flush_fp_to_thread(target);
- flush_altivec_to_thread(target);
+ if (ret)
+ return ret;
ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
&target->thread.ckpt_regs,
@@ -910,17 +903,11 @@ static int tm_cgpr_set(struct task_struct *target,
const void *kbuf, const void __user *ubuf)
{
unsigned long reg;
- int ret;
-
- if (!cpu_has_feature(CPU_FTR_TM))
- return -ENODEV;
- if (!MSR_TM_ACTIVE(target->thread.regs->msr))
- return -ENODATA;
+ int ret = tm_flush_if_active(target);
- flush_tmregs_to_thread(target);
- flush_fp_to_thread(target);
- flush_altivec_to_thread(target);
+ if (ret)
+ return ret;
ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
&target->thread.ckpt_regs,
@@ -1014,15 +1001,10 @@ static int tm_cfpr_get(struct task_struct *target,
u64 buf[33];
int i;
- if (!cpu_has_feature(CPU_FTR_TM))
- return -ENODEV;
-
- if (!MSR_TM_ACTIVE(target->thread.regs->msr))
- return -ENODATA;
+ int ret = tm_flush_if_active(target);
- flush_tmregs_to_thread(target);
- flush_fp_to_thread(target);
- flush_altivec_to_thread(target);
+ if (ret)
+ return ret;
/* copy to local buffer then write that out */
for (i = 0; i < 32 ; i++)
@@ -1060,15 +1042,10 @@ static int tm_cfpr_set(struct task_struct *target,
u64 buf[33];
int i;
- if (!cpu_has_feature(CPU_FTR_TM))
- return -ENODEV;
-
- if (!MSR_TM_ACTIVE(target->thread.regs->msr))
- return -ENODATA;
+ int ret = tm_flush_if_active(target);
- flush_tmregs_to_thread(target);
- flush_fp_to_thread(target);
- flush_altivec_to_thread(target);
+ if (ret)
+ return ret;
for (i = 0; i < 32; i++)
buf[i] = target->thread.TS_CKFPR(i);
@@ -1131,20 +1108,12 @@ static int tm_cvmx_get(struct task_struct *target,
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;
+ int ret = tm_flush_if_active(target);
- if (!MSR_TM_ACTIVE(target->thread.regs->msr))
- return -ENODATA;
+ if (ret)
+ return ret;
- /* Flush the state */
- flush_tmregs_to_thread(target);
- flush_fp_to_thread(target);
- flush_altivec_to_thread(target);
+ BUILD_BUG_ON(TVSO(vscr) != TVSO(vr[32]));
ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
&target->thread.ckvr_state, 0,
@@ -1193,19 +1162,12 @@ static int tm_cvmx_set(struct task_struct *target,
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;
+ int ret = tm_flush_if_active(target);
- if (!MSR_TM_ACTIVE(target->thread.regs->msr))
- return -ENODATA;
+ if (ret)
+ return ret;
- flush_tmregs_to_thread(target);
- flush_fp_to_thread(target);
- flush_altivec_to_thread(target);
+ BUILD_BUG_ON(TVSO(vscr) != TVSO(vr[32]));
ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
&target->thread.ckvr_state, 0,
@@ -1276,18 +1238,13 @@ static int tm_cvsx_get(struct task_struct *target,
void *kbuf, void __user *ubuf)
{
u64 buf[32];
- int ret, i;
+ int i;
- if (!cpu_has_feature(CPU_FTR_TM))
- return -ENODEV;
+ int ret = tm_flush_if_active(target);
- if (!MSR_TM_ACTIVE(target->thread.regs->msr))
- return -ENODATA;
+ if (ret)
+ return ret;
- /* Flush the state */
- flush_tmregs_to_thread(target);
- flush_fp_to_thread(target);
- flush_altivec_to_thread(target);
flush_vsx_to_thread(target);
for (i = 0; i < 32 ; i++)
@@ -1324,18 +1281,13 @@ static int tm_cvsx_set(struct task_struct *target,
const void *kbuf, const void __user *ubuf)
{
u64 buf[32];
- int ret, i;
+ int i;
- if (!cpu_has_feature(CPU_FTR_TM))
- return -ENODEV;
+ int ret = tm_flush_if_active(target);
- if (!MSR_TM_ACTIVE(target->thread.regs->msr))
- return -ENODATA;
+ if (ret)
+ return ret;
- /* Flush the state */
- flush_tmregs_to_thread(target);
- flush_fp_to_thread(target);
- flush_altivec_to_thread(target);
flush_vsx_to_thread(target);
for (i = 0; i < 32 ; i++)
--
2.13.6
More information about the Linuxppc-dev
mailing list