[PATCH 4.4 06/87] MIPS: Factor out NT_PRFPREG regset access helpers

2018-01-15 Thread Greg Kroah-Hartman
4.4-stable review patch.  If anyone has any objections, please let me know.

--

From: Maciej W. Rozycki 

commit a03fe72572c12e98f4173f8a535f32468e48b6ec upstream.

In preparation to fix a commit 72b22bbad1e7 ("MIPS: Don't assume 64-bit
FP registers for FP regset") FCSR access regression factor out
NT_PRFPREG regset access helpers for the non-MSA and the MSA variants
respectively, to avoid having to deal with excessive indentation in the
actual fix.

No functional change, however use `target->thread.fpu.fpr[0]' rather
than `target->thread.fpu.fpr[i]' for FGR holding type size determination
as there's no `i' variable to refer to anymore, and for the factored out
`i' variable declaration use `unsigned int' rather than `unsigned' as
its type, following the common style.

Signed-off-by: Maciej W. Rozycki 
Fixes: 72b22bbad1e7 ("MIPS: Don't assume 64-bit FP registers for FP regset")
Cc: James Hogan 
Cc: Paul Burton 
Cc: Alex Smith 
Cc: Dave Martin 
Cc: linux-m...@linux-mips.org
Cc: linux-kernel@vger.kernel.org
Patchwork: https://patchwork.linux-mips.org/patch/17925/
Signed-off-by: Ralf Baechle 
Signed-off-by: Greg Kroah-Hartman 

---
 arch/mips/kernel/ptrace.c |  108 +++---
 1 file changed, 83 insertions(+), 25 deletions(-)

--- a/arch/mips/kernel/ptrace.c
+++ b/arch/mips/kernel/ptrace.c
@@ -439,25 +439,36 @@ static int gpr64_set(struct task_struct
 
 #endif /* CONFIG_64BIT */
 
-static int fpr_get(struct task_struct *target,
-  const struct user_regset *regset,
-  unsigned int pos, unsigned int count,
-  void *kbuf, void __user *ubuf)
+/*
+ * Copy the floating-point context to the supplied NT_PRFPREG buffer,
+ * !CONFIG_CPU_HAS_MSA variant.  FP context's general register slots
+ * correspond 1:1 to buffer slots.
+ */
+static int fpr_get_fpa(struct task_struct *target,
+  unsigned int *pos, unsigned int *count,
+  void **kbuf, void __user **ubuf)
 {
-   unsigned i;
-   int err;
-   u64 fpr_val;
-
-   /* XXX fcr31  */
+   return user_regset_copyout(pos, count, kbuf, ubuf,
+  >thread.fpu,
+  0, sizeof(elf_fpregset_t));
+}
 
-   if (sizeof(target->thread.fpu.fpr[i]) == sizeof(elf_fpreg_t))
-   return user_regset_copyout(, , , ,
-  >thread.fpu,
-  0, sizeof(elf_fpregset_t));
+/*
+ * Copy the floating-point context to the supplied NT_PRFPREG buffer,
+ * CONFIG_CPU_HAS_MSA variant.  Only lower 64 bits of FP context's
+ * general register slots are copied to buffer slots.
+ */
+static int fpr_get_msa(struct task_struct *target,
+  unsigned int *pos, unsigned int *count,
+  void **kbuf, void __user **ubuf)
+{
+   unsigned int i;
+   u64 fpr_val;
+   int err;
 
for (i = 0; i < NUM_FPU_REGS; i++) {
fpr_val = get_fpr64(>thread.fpu.fpr[i], 0);
-   err = user_regset_copyout(, , , ,
+   err = user_regset_copyout(pos, count, kbuf, ubuf,
  _val, i * sizeof(elf_fpreg_t),
  (i + 1) * sizeof(elf_fpreg_t));
if (err)
@@ -467,27 +478,54 @@ static int fpr_get(struct task_struct *t
return 0;
 }
 
-static int fpr_set(struct task_struct *target,
+/* Copy the floating-point context to the supplied NT_PRFPREG buffer.  */
+static int fpr_get(struct task_struct *target,
   const struct user_regset *regset,
   unsigned int pos, unsigned int count,
-  const void *kbuf, const void __user *ubuf)
+  void *kbuf, void __user *ubuf)
 {
-   unsigned i;
int err;
-   u64 fpr_val;
 
/* XXX fcr31  */
 
-   init_fp_ctx(target);
+   if (sizeof(target->thread.fpu.fpr[0]) == sizeof(elf_fpreg_t))
+   err = fpr_get_fpa(target, , , , );
+   else
+   err = fpr_get_msa(target, , , , );
+
+   return err;
+}
 
-   if (sizeof(target->thread.fpu.fpr[i]) == sizeof(elf_fpreg_t))
-   return user_regset_copyin(, , , ,
- >thread.fpu,
- 0, sizeof(elf_fpregset_t));
+/*
+ * Copy the supplied NT_PRFPREG buffer to the floating-point context,
+ * !CONFIG_CPU_HAS_MSA variant.   Buffer slots correspond 1:1 to FP
+ * context's general register slots.
+ */
+static int fpr_set_fpa(struct task_struct *target,
+  unsigned int *pos, unsigned int *count,
+  const void **kbuf, const void __user **ubuf)
+{
+   return user_regset_copyin(pos, 

[PATCH 4.4 06/87] MIPS: Factor out NT_PRFPREG regset access helpers

2018-01-15 Thread Greg Kroah-Hartman
4.4-stable review patch.  If anyone has any objections, please let me know.

--

From: Maciej W. Rozycki 

commit a03fe72572c12e98f4173f8a535f32468e48b6ec upstream.

In preparation to fix a commit 72b22bbad1e7 ("MIPS: Don't assume 64-bit
FP registers for FP regset") FCSR access regression factor out
NT_PRFPREG regset access helpers for the non-MSA and the MSA variants
respectively, to avoid having to deal with excessive indentation in the
actual fix.

No functional change, however use `target->thread.fpu.fpr[0]' rather
than `target->thread.fpu.fpr[i]' for FGR holding type size determination
as there's no `i' variable to refer to anymore, and for the factored out
`i' variable declaration use `unsigned int' rather than `unsigned' as
its type, following the common style.

Signed-off-by: Maciej W. Rozycki 
Fixes: 72b22bbad1e7 ("MIPS: Don't assume 64-bit FP registers for FP regset")
Cc: James Hogan 
Cc: Paul Burton 
Cc: Alex Smith 
Cc: Dave Martin 
Cc: linux-m...@linux-mips.org
Cc: linux-kernel@vger.kernel.org
Patchwork: https://patchwork.linux-mips.org/patch/17925/
Signed-off-by: Ralf Baechle 
Signed-off-by: Greg Kroah-Hartman 

---
 arch/mips/kernel/ptrace.c |  108 +++---
 1 file changed, 83 insertions(+), 25 deletions(-)

--- a/arch/mips/kernel/ptrace.c
+++ b/arch/mips/kernel/ptrace.c
@@ -439,25 +439,36 @@ static int gpr64_set(struct task_struct
 
 #endif /* CONFIG_64BIT */
 
-static int fpr_get(struct task_struct *target,
-  const struct user_regset *regset,
-  unsigned int pos, unsigned int count,
-  void *kbuf, void __user *ubuf)
+/*
+ * Copy the floating-point context to the supplied NT_PRFPREG buffer,
+ * !CONFIG_CPU_HAS_MSA variant.  FP context's general register slots
+ * correspond 1:1 to buffer slots.
+ */
+static int fpr_get_fpa(struct task_struct *target,
+  unsigned int *pos, unsigned int *count,
+  void **kbuf, void __user **ubuf)
 {
-   unsigned i;
-   int err;
-   u64 fpr_val;
-
-   /* XXX fcr31  */
+   return user_regset_copyout(pos, count, kbuf, ubuf,
+  >thread.fpu,
+  0, sizeof(elf_fpregset_t));
+}
 
-   if (sizeof(target->thread.fpu.fpr[i]) == sizeof(elf_fpreg_t))
-   return user_regset_copyout(, , , ,
-  >thread.fpu,
-  0, sizeof(elf_fpregset_t));
+/*
+ * Copy the floating-point context to the supplied NT_PRFPREG buffer,
+ * CONFIG_CPU_HAS_MSA variant.  Only lower 64 bits of FP context's
+ * general register slots are copied to buffer slots.
+ */
+static int fpr_get_msa(struct task_struct *target,
+  unsigned int *pos, unsigned int *count,
+  void **kbuf, void __user **ubuf)
+{
+   unsigned int i;
+   u64 fpr_val;
+   int err;
 
for (i = 0; i < NUM_FPU_REGS; i++) {
fpr_val = get_fpr64(>thread.fpu.fpr[i], 0);
-   err = user_regset_copyout(, , , ,
+   err = user_regset_copyout(pos, count, kbuf, ubuf,
  _val, i * sizeof(elf_fpreg_t),
  (i + 1) * sizeof(elf_fpreg_t));
if (err)
@@ -467,27 +478,54 @@ static int fpr_get(struct task_struct *t
return 0;
 }
 
-static int fpr_set(struct task_struct *target,
+/* Copy the floating-point context to the supplied NT_PRFPREG buffer.  */
+static int fpr_get(struct task_struct *target,
   const struct user_regset *regset,
   unsigned int pos, unsigned int count,
-  const void *kbuf, const void __user *ubuf)
+  void *kbuf, void __user *ubuf)
 {
-   unsigned i;
int err;
-   u64 fpr_val;
 
/* XXX fcr31  */
 
-   init_fp_ctx(target);
+   if (sizeof(target->thread.fpu.fpr[0]) == sizeof(elf_fpreg_t))
+   err = fpr_get_fpa(target, , , , );
+   else
+   err = fpr_get_msa(target, , , , );
+
+   return err;
+}
 
-   if (sizeof(target->thread.fpu.fpr[i]) == sizeof(elf_fpreg_t))
-   return user_regset_copyin(, , , ,
- >thread.fpu,
- 0, sizeof(elf_fpregset_t));
+/*
+ * Copy the supplied NT_PRFPREG buffer to the floating-point context,
+ * !CONFIG_CPU_HAS_MSA variant.   Buffer slots correspond 1:1 to FP
+ * context's general register slots.
+ */
+static int fpr_set_fpa(struct task_struct *target,
+  unsigned int *pos, unsigned int *count,
+  const void **kbuf, const void __user **ubuf)
+{
+   return user_regset_copyin(pos, count, kbuf, ubuf,
+ >thread.fpu,
+ 0, sizeof(elf_fpregset_t));
+}
+
+/*
+ * Copy the supplied