From: Roland McGrath <roland@redhat.com>
To: Andrew Morton <akpm@linux-foundation.org>,
Linus Torvalds <torvalds@linux-foundation.org>
Cc: linux-arch@vger.kernel.org, linuxppc-dev@ozlabs.org,
Paul Mackerras <paulus@samba.org>,
linux-kernel@vger.kernel.org
Subject: [PATCH -mm 11/43] powerpc user_regset altivec
Date: Thu, 20 Dec 2007 03:57:39 -0800 (PST) [thread overview]
Message-ID: <20071220115739.4978126F98A@magilla.localdomain> (raw)
In-Reply-To: Roland McGrath's message of Thursday, 20 December 2007 03:52:00 -0800 <20071220115200.C767E26F98A@magilla.localdomain>
This implements user_regset-style accessors for the powerpc Altivec data,
and rewrites the existing ptrace code in terms of those calls.
Signed-off-by: Roland McGrath <roland@redhat.com>
---
arch/powerpc/kernel/ptrace.c | 112 +++++++++++++++++++++++++++++-------------
1 files changed, 78 insertions(+), 34 deletions(-)
diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
index f1ce646..7cdf35a 100644
--- a/arch/powerpc/kernel/ptrace.c
+++ b/arch/powerpc/kernel/ptrace.c
@@ -22,6 +22,7 @@
#include <linux/errno.h>
#include <linux/ptrace.h>
#include <linux/regset.h>
+#include <linux/elf.h>
#include <linux/user.h>
#include <linux/security.h>
#include <linux/signal.h>
@@ -163,30 +164,87 @@ static int set_fpregs(void __user *data, struct task_struct *task,
* (combined (32- and 64-bit) gdb.
*/
+static int vr_active(struct task_struct *target,
+ const struct user_regset *regset)
+{
+ flush_altivec_to_thread(target);
+ return target->thread.used_vr ? regset->n : 0;
+}
+
+static int vr_get(struct task_struct *target, const struct user_regset *regset,
+ unsigned int pos, unsigned int count,
+ void *kbuf, void __user *ubuf)
+{
+ int ret;
+
+ flush_altivec_to_thread(target);
+
+ BUILD_BUG_ON(offsetof(struct thread_struct, vscr) !=
+ offsetof(struct thread_struct, vr[32]));
+
+ ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
+ &target->thread.vr, 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;
+}
+
+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)
+{
+ int ret;
+
+ flush_altivec_to_thread(target);
+
+ BUILD_BUG_ON(offsetof(struct thread_struct, vscr) !=
+ offsetof(struct thread_struct, vr[32]));
+
+ ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
+ &target->thread.vr, 0, 33 * sizeof(vector128));
+ if (!ret && count > 0) {
+ /*
+ * We use only the first word of vrsave.
+ */
+ 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;
+}
+
/*
* Get contents of AltiVec register state in task TASK
*/
static int get_vrregs(unsigned long __user *data, struct task_struct *task)
{
- unsigned long regsize;
-
- /* copy AltiVec registers VR[0] .. VR[31] */
- regsize = 32 * sizeof(vector128);
- if (copy_to_user(data, task->thread.vr, regsize))
- return -EFAULT;
- data += (regsize / sizeof(unsigned long));
-
- /* copy VSCR */
- regsize = 1 * sizeof(vector128);
- if (copy_to_user(data, &task->thread.vscr, regsize))
+ if (!access_ok(VERIFY_WRITE, data,
+ 33 * sizeof(vector128) + sizeof(u32)))
return -EFAULT;
- data += (regsize / sizeof(unsigned long));
- /* copy VRSAVE */
- if (put_user(task->thread.vrsave, (u32 __user *)data))
- return -EFAULT;
-
- return 0;
+ return vr_get(task, NULL, 0, 33 * sizeof(vector128) + sizeof(u32),
+ NULL, data);
}
/*
@@ -194,25 +252,11 @@ static int get_vrregs(unsigned long __user *data, struct task_struct *task)
*/
static int set_vrregs(struct task_struct *task, unsigned long __user *data)
{
- unsigned long regsize;
-
- /* copy AltiVec registers VR[0] .. VR[31] */
- regsize = 32 * sizeof(vector128);
- if (copy_from_user(task->thread.vr, data, regsize))
- return -EFAULT;
- data += (regsize / sizeof(unsigned long));
-
- /* copy VSCR */
- regsize = 1 * sizeof(vector128);
- if (copy_from_user(&task->thread.vscr, data, regsize))
- return -EFAULT;
- data += (regsize / sizeof(unsigned long));
-
- /* copy VRSAVE */
- if (get_user(task->thread.vrsave, (u32 __user *)data))
+ if (!access_ok(VERIFY_READ, data, 33 * sizeof(vector128) + sizeof(u32)))
return -EFAULT;
- return 0;
+ return vr_set(task, NULL, 0, 33 * sizeof(vector128) + sizeof(u32),
+ NULL, data);
}
#endif /* CONFIG_ALTIVEC */
--
1.5.3.6
next prev parent reply other threads:[~2007-12-20 13:02 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20071220115200.C767E26F98A@magilla.localdomain>
2007-12-20 11:57 ` [PATCH -mm 10/43] powerpc user_regset fpregs Roland McGrath
2007-12-20 11:57 ` Roland McGrath [this message]
2007-12-20 11:57 ` [PATCH -mm 12/43] powerpc user_regset spe Roland McGrath
2007-12-20 11:57 ` [PATCH -mm 13/43] powerpc ptrace special regs Roland McGrath
2007-12-20 11:57 ` [PATCH -mm 14/43] powerpc user_regset gpr Roland McGrath
2007-12-20 11:58 ` [PATCH -mm 15/43] powerpc user_regset_view Roland McGrath
2007-12-20 11:58 ` [PATCH -mm 16/43] powerpc user_regset compat Roland McGrath
2008-01-07 5:40 ` [PATCH update " Roland McGrath
2007-12-20 11:58 ` [PATCH -mm 17/43] powerpc CORE_DUMP_USE_REGSET Roland McGrath
2007-12-20 11:58 ` [PATCH -mm 18/43] powerpc compat_binfmt_elf Roland McGrath
2007-12-21 7:12 ` Christoph Hellwig
2007-12-21 8:56 ` Roland McGrath
2007-12-21 17:51 ` Kyle McMartin
2007-12-21 19:36 ` Arnd Bergmann
2007-12-21 20:00 ` Sam Ravnborg
2007-12-20 11:58 ` [PATCH -mm 19/43] powerpc core dump cleanup Roland McGrath
2007-12-20 11:58 ` [PATCH -mm 20/43] powerpc SPE core dump Roland McGrath
2007-12-20 11:58 ` [PATCH -mm 21/43] powerpc ptrace user_regset Roland McGrath
2007-12-20 11:58 ` [PATCH -mm 22/43] powerpc ptrace generic peekdata/pokedata Roland McGrath
2007-12-20 11:58 ` [PATCH -mm 23/43] powerpc compat_ptrace_request Roland McGrath
2007-12-20 11:58 ` [PATCH -mm 24/43] powerpc compat_sys_ptrace Roland McGrath
2007-12-20 11:59 ` [PATCH -mm 25/43] powerpc ptrace32 user_regset Roland McGrath
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20071220115739.4978126F98A@magilla.localdomain \
--to=roland@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@ozlabs.org \
--cc=paulus@samba.org \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).