linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Suresh Siddha <suresh.b.siddha@intel.com>
To: Roland McGrath <roland@redhat.com>,
	Oleg Nesterov <oleg@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
	Ingo Molnar <mingo@elte.hu>, Thomas Gleixner <tglx@linutronix.de>
Cc: LKML <linux-kernel@vger.kernel.org>,
	hjl.tools@gmail.com, peter.lachner@intel.com,
	suresh.b.siddha@intel.com
Subject: [patch v3 2/2] ptrace: Add support for generic PTRACE_GETREGSET/PTRACE_SETREGSET
Date: Thu, 11 Feb 2010 11:51:00 -0800	[thread overview]
Message-ID: <20100211195614.886724710@sbs-t61.sc.intel.com> (raw)
In-Reply-To: 20100211195058.071883111@sbs-t61.sc.intel.com

[-- Attachment #1: ptrace_support_for_xstate.patch --]
[-- Type: text/plain, Size: 5623 bytes --]

Generic support for PTRACE_GETREGSET/PTRACE_SETREGSET commands which
export the regsets supported by each architecture using the correponding
NT_* types. These NT_* types are already part of the userland ABI, used
in representing the architecture specific register sets as different NOTES
in an ELF core file.

'addr' parameter for the ptrace system call encode the REGSET type (using
the corresppnding NT_* type) and the 'data' parameter points to the
struct iovec having the user buffer and the length of that buffer.

	struct iovec iov = { buf, len};
	ret = ptrace(PTRACE_GETREGSET/PTRACE_SETREGSET, pid, NT_XXX_TYPE, &iov);

On successful completion, iov.len will be updated by the kernel specifying
how much the kernel has written/read to/from the user's iov.buf.

x86 extended state registers are primarily exported using this interface.

Signed-off-by: Suresh Siddha <suresh.b.siddha@intel.com>
Acked-by: Hongjiu Lu <hjl.tools@gmail.com>
---
 include/linux/elf.h    |    6 ++-
 include/linux/ptrace.h |   15 ++++++++
 kernel/ptrace.c        |   88 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 108 insertions(+), 1 deletion(-)

Index: tip/include/linux/ptrace.h
===================================================================
--- tip.orig/include/linux/ptrace.h
+++ tip/include/linux/ptrace.h
@@ -27,6 +27,21 @@
 #define PTRACE_GETSIGINFO	0x4202
 #define PTRACE_SETSIGINFO	0x4203
 
+/*
+ * Generic ptrace interface that exports the architecture specific regsets
+ * using the corresponding NT_* types (which are also used in the core dump).
+ *
+ * This interface usage is as follows:
+ * 	struct iovec iov = { buf, len};
+ *
+ * 	ret = ptrace(PTRACE_GETREGSET/PTRACE_SETREGSET, pid, NT_XXX_TYPE, &iov);
+ *
+ * On the successful completion, iov.len will be updated by the kernel,
+ * specifying how much the kernel has written/read to/from the user's iov.buf.
+ */
+#define PTRACE_GETREGSET	0x4204
+#define PTRACE_SETREGSET	0x4205
+
 /* options set using PTRACE_SETOPTIONS */
 #define PTRACE_O_TRACESYSGOOD	0x00000001
 #define PTRACE_O_TRACEFORK	0x00000002
Index: tip/kernel/ptrace.c
===================================================================
--- tip.orig/kernel/ptrace.c
+++ tip/kernel/ptrace.c
@@ -22,6 +22,7 @@
 #include <linux/pid_namespace.h>
 #include <linux/syscalls.h>
 #include <linux/uaccess.h>
+#include <linux/regset.h>
 
 
 /*
@@ -511,6 +512,47 @@ static int ptrace_resume(struct task_str
 	return 0;
 }
 
+#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
+
+static const struct user_regset *
+find_regset(const struct user_regset_view *view, unsigned int type)
+{
+	const struct user_regset *regset;
+	int n;
+
+	for (n = 0; n < view->n; ++n) {
+		regset = view->regsets + n;
+		if (regset->core_note_type == type)
+			return regset;
+	}
+
+	return NULL;
+}
+
+static int ptrace_regset(struct task_struct *task, int req, unsigned int type,
+			 struct iovec *kiov)
+{
+	const struct user_regset_view *view = task_user_regset_view(task);
+	const struct user_regset *regset = find_regset(view, type);
+	int regset_no;
+
+	if (!regset || (kiov->iov_len % regset->size) != 0)
+		return -EIO;
+
+	regset_no = regset - view->regsets;
+	kiov->iov_len = min(kiov->iov_len,
+			    (__kernel_size_t) (regset->n * regset->size));
+
+	if (req == PTRACE_GETREGSET)
+		return copy_regset_to_user(task, view, regset_no, 0,
+					   kiov->iov_len, kiov->iov_base);
+	else
+		return copy_regset_from_user(task, view, regset_no, 0,
+					     kiov->iov_len, kiov->iov_base);
+}
+
+#endif
+
 int ptrace_request(struct task_struct *child, long request,
 		   long addr, long data)
 {
@@ -573,6 +615,26 @@ int ptrace_request(struct task_struct *c
 			return 0;
 		return ptrace_resume(child, request, SIGKILL);
 
+#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
+	case PTRACE_GETREGSET:
+	case PTRACE_SETREGSET:
+	{
+		struct iovec kiov;
+		struct iovec __user *uiov = (struct iovec __user *) data;
+
+		if (!access_ok(VERIFY_WRITE, uiov, sizeof(*uiov)))
+			return -EFAULT;
+
+		if (__get_user(kiov.iov_base, &uiov->iov_base) ||
+		    __get_user(kiov.iov_len, &uiov->iov_len))
+			return -EFAULT;
+
+		ret = ptrace_regset(child, request, addr, &kiov);
+		if (!ret)
+			ret = __put_user(kiov.iov_len, &uiov->iov_len);
+		break;
+	}
+#endif
 	default:
 		break;
 	}
@@ -711,6 +773,32 @@ int compat_ptrace_request(struct task_st
 		else
 			ret = ptrace_setsiginfo(child, &siginfo);
 		break;
+#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
+	case PTRACE_GETREGSET:
+	case PTRACE_SETREGSET:
+	{
+		struct iovec kiov;
+		struct compat_iovec __user *uiov =
+			(struct compat_iovec __user *) datap;
+		compat_uptr_t ptr;
+		compat_size_t len;
+
+		if (!access_ok(VERIFY_WRITE, uiov, sizeof(*uiov)))
+			return -EFAULT;
+
+		if (__get_user(ptr, &uiov->iov_base) ||
+		    __get_user(len, &uiov->iov_len))
+			return -EFAULT;
+
+		kiov.iov_base = compat_ptr(ptr);
+		kiov.iov_len = len;
+
+		ret = ptrace_regset(child, request, addr, &kiov);
+		if (!ret)
+			ret = __put_user(kiov.iov_len, &uiov->iov_len);
+		break;
+	}
+#endif
 
 	default:
 		ret = ptrace_request(child, request, addr, data);
Index: tip/include/linux/elf.h
===================================================================
--- tip.orig/include/linux/elf.h
+++ tip/include/linux/elf.h
@@ -349,7 +349,11 @@ typedef struct elf64_shdr {
 #define ELF_OSABI ELFOSABI_NONE
 #endif
 
-/* Notes used in ET_CORE */
+/*
+ * Notes used in ET_CORE. Architectures export some of the arch register sets
+ * using the corresponding note types via the PTRACE_GETREGSET and
+ * PTRACE_SETREGSET requests.
+ */
 #define NT_PRSTATUS	1
 #define NT_PRFPREG	2
 #define NT_PRPSINFO	3



  parent reply	other threads:[~2010-02-11 20:00 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-11 19:50 [patch v3 0/2] updated ptrace/core-dump patches for supporting xstate - v3 Suresh Siddha
2010-02-11 19:50 ` [patch v3 1/2] x86, ptrace: regset extensions to support xstate Suresh Siddha
2010-02-11 23:18   ` [tip:x86/ptrace] " tip-bot for Suresh Siddha
2010-02-12  3:45   ` [patch v3 1/2] " Roland McGrath
2010-02-12 17:31   ` Oleg Nesterov
2010-02-11 19:51 ` Suresh Siddha [this message]
2010-02-11 23:19   ` [tip:x86/ptrace] ptrace: Add support for generic PTRACE_GETREGSET/PTRACE_SETREGSET tip-bot for Suresh Siddha
2010-02-22  9:07     ` Ingo Molnar
2010-02-22  9:33       ` linux-next requiements (Was: Re: [tip:x86/ptrace] ptrace: Add support for generic PTRACE_GETREGSET/PTRACE_SETREGSET) Stephen Rothwell
2010-02-22 10:27         ` Ingo Molnar
2010-02-22 11:47           ` linux-next requirements " Stephen Rothwell
2010-02-22 22:57             ` H. Peter Anvin
2010-02-22 23:59               ` Stephen Rothwell
2010-02-23 20:20                 ` Roland McGrath
2010-02-23 20:49                   ` H. Peter Anvin
2010-02-23 22:54                     ` Stephen Rothwell
2010-02-23  8:45             ` Ingo Molnar
2010-02-23 19:52               ` Al Viro
2010-02-23 19:57                 ` Al Viro
2010-02-24  7:25               ` linux-next requirements Stephen Rothwell
2010-02-27  1:53                 ` Grant Likely
2010-02-27  8:53                   ` Geert Uytterhoeven
2010-02-27  9:09                 ` Jaswinder Singh Rajput
2010-02-27  9:39                 ` Ingo Molnar
2010-02-27 12:23                   ` Rafael J. Wysocki
2010-02-27 12:47                     ` Ingo Molnar
2010-02-27 19:07                       ` Rafael J. Wysocki
2010-02-27 21:50                         ` Geert Uytterhoeven
2010-02-27 22:31                           ` Rafael J. Wysocki
2010-02-28  7:06                         ` Ingo Molnar
2010-02-28 12:22                           ` Rafael J. Wysocki
2010-02-28  7:14                         ` Ingo Molnar
2010-02-28  7:37                           ` Stephen Rothwell
2010-02-28  7:51                             ` Ingo Molnar
2010-02-28  8:19                               ` Al Viro
2010-02-28  8:53                                 ` Ingo Molnar
2010-02-28 10:26                                 ` Stephen Rothwell
2010-02-28  7:23                         ` Ingo Molnar
2010-03-01 15:13                           ` Nick Bowler
2010-03-03 21:53                           ` Pavel Machek
2010-03-04  0:35                             ` Thomas Gleixner
2010-03-04  0:42                               ` Andrew Morton
2010-03-04  1:17                                 ` Thomas Gleixner
2010-03-04  2:48                                   ` Ingo Molnar
2010-02-22 18:37       ` [tip:x86/ptrace] ptrace: Add support for generic PTRACE_GETREGSET/PTRACE_SETREGSET Roland McGrath
2010-02-23 18:36         ` [tip:x86/ptrace] parisc: Disable CONFIG_HAVE_ARCH_TRACEHOOK tip-bot for Roland McGrath
2010-02-12  3:56   ` [patch v3 2/2] ptrace: Add support for generic PTRACE_GETREGSET/PTRACE_SETREGSET Roland McGrath
2010-02-12 15:59     ` Oleg Nesterov

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=20100211195614.886724710@sbs-t61.sc.intel.com \
    --to=suresh.b.siddha@intel.com \
    --cc=hjl.tools@gmail.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=oleg@redhat.com \
    --cc=peter.lachner@intel.com \
    --cc=roland@redhat.com \
    --cc=tglx@linutronix.de \
    /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).