xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Boris Ostrovsky <boris.ostrovsky@oracle.com>
To: david.vrabel@citrix.com, konrad.wilk@oracle.com
Cc: boris.ostrovsky@oracle.com, kevin.tian@intel.com,
	dietmar.hahn@ts.fujitsu.com, JBeulich@suse.com,
	xen-devel@lists.xen.org
Subject: [PATCH v2 1/6] xen: xensyms support
Date: Fri,  6 Jun 2014 13:44:41 -0400	[thread overview]
Message-ID: <1402076686-26586-2-git-send-email-boris.ostrovsky@oracle.com> (raw)
In-Reply-To: <1402076686-26586-1-git-send-email-boris.ostrovsky@oracle.com>

Export Xen symbols to dom0 via /proc/xen/xensyms (similar to /proc/kallsyms).

Signed-off-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
---
 drivers/xen/Kconfig              |   5 ++
 drivers/xen/xenfs/Makefile       |   1 +
 drivers/xen/xenfs/super.c        |   3 +
 drivers/xen/xenfs/xenfs.h        |   1 +
 drivers/xen/xenfs/xensyms.c      | 124 +++++++++++++++++++++++++++++++++++++++
 include/xen/interface/platform.h |  19 ++++++
 6 files changed, 153 insertions(+)
 create mode 100644 drivers/xen/xenfs/xensyms.c

diff --git a/drivers/xen/Kconfig b/drivers/xen/Kconfig
index 38fb36e..b3d1da7 100644
--- a/drivers/xen/Kconfig
+++ b/drivers/xen/Kconfig
@@ -240,4 +240,9 @@ config XEN_MCE_LOG
 config XEN_HAVE_PVMMU
        bool
 
+config XEN_SYMS
+       bool "Xen symbols"
+       depends on XEN_DOM0 && XENFS
+       default y if KALLSYMS
+
 endmenu
diff --git a/drivers/xen/xenfs/Makefile b/drivers/xen/xenfs/Makefile
index b019865..1a83010 100644
--- a/drivers/xen/xenfs/Makefile
+++ b/drivers/xen/xenfs/Makefile
@@ -2,3 +2,4 @@ obj-$(CONFIG_XENFS) += xenfs.o
 
 xenfs-y			  = super.o
 xenfs-$(CONFIG_XEN_DOM0) += xenstored.o
+xenfs-$(CONFIG_XEN_SYMS) += xensyms.o
diff --git a/drivers/xen/xenfs/super.c b/drivers/xen/xenfs/super.c
index 06092e0..8559a71 100644
--- a/drivers/xen/xenfs/super.c
+++ b/drivers/xen/xenfs/super.c
@@ -57,6 +57,9 @@ static int xenfs_fill_super(struct super_block *sb, void *data, int silent)
 		{ "privcmd", &xen_privcmd_fops, S_IRUSR|S_IWUSR },
 		{ "xsd_kva", &xsd_kva_file_ops, S_IRUSR|S_IWUSR},
 		{ "xsd_port", &xsd_port_file_ops, S_IRUSR|S_IWUSR},
+#ifdef CONFIG_XEN_SYMS
+		{ "xensyms", &xensyms_ops, S_IRUSR},
+#endif
 		{""},
 	};
 
diff --git a/drivers/xen/xenfs/xenfs.h b/drivers/xen/xenfs/xenfs.h
index 6b80c77..2c5934e 100644
--- a/drivers/xen/xenfs/xenfs.h
+++ b/drivers/xen/xenfs/xenfs.h
@@ -3,5 +3,6 @@
 
 extern const struct file_operations xsd_kva_file_ops;
 extern const struct file_operations xsd_port_file_ops;
+extern const struct file_operations xensyms_ops;
 
 #endif	/* _XENFS_XENBUS_H */
diff --git a/drivers/xen/xenfs/xensyms.c b/drivers/xen/xenfs/xensyms.c
new file mode 100644
index 0000000..748948c
--- /dev/null
+++ b/drivers/xen/xenfs/xensyms.c
@@ -0,0 +1,124 @@
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/seq_file.h>
+#include <linux/fs.h>
+#include <linux/mm.h>
+#include <linux/proc_fs.h>
+#include <linux/slab.h>
+#include <xen/interface/platform.h>
+#include <asm/xen/hypercall.h>
+#include <xen/xen-ops.h>
+#include "xenfs.h"
+
+
+#define XEN_KSYM_NAME_LEN 127 /* Hypervisor may have different name length */
+
+
+/* Grab next output page from the hypervisor */
+static int xensyms_next_sym(struct xen_platform_op *op)
+{
+	int ret;
+	uint64_t symnum = op->u.symdata.symnum;
+
+	memset(op->u.symdata.name, 0, XEN_KSYM_NAME_LEN + 1);
+
+	ret = HYPERVISOR_dom0_op(op);
+	if (ret < 0)
+		return ret;
+
+	if (op->u.symdata.symnum == symnum)
+		/* End of symbols */
+		return 1;
+
+	return 0;
+}
+
+static void *xensyms_start(struct seq_file *m, loff_t *pos)
+{
+	struct xen_platform_op *op = (struct xen_platform_op *)m->private;
+
+	if (op->u.symdata.symnum != *pos)
+		op->u.symdata.symnum = *pos;
+
+	if (xensyms_next_sym(op))
+		return NULL;
+
+	return m->private;
+}
+
+static void *xensyms_next(struct seq_file *m, void *p, loff_t *pos)
+{
+	struct xen_platform_op *op = (struct xen_platform_op *)m->private;
+
+	(*pos)++;
+
+	if (op->u.symdata.symnum != *pos)
+		op->u.symdata.symnum = *pos;
+
+	if (xensyms_next_sym(op))
+		return NULL;
+
+	return p;
+}
+
+static int xensyms_show(struct seq_file *m, void *p)
+{
+	struct xen_platform_op *op = (struct xen_platform_op *)m->private;
+
+	seq_printf(m, "%016llx %c %s\n", op->u.symdata.address,
+		   op->u.symdata.type, op->u.symdata.name);
+
+	return 0;
+}
+
+static void xensyms_stop(struct seq_file *m, void *p)
+{
+}
+
+static const struct seq_operations xensyms_seq_ops = {
+	.start = xensyms_start,
+	.next = xensyms_next,
+	.show = xensyms_show,
+	.stop = xensyms_stop,
+};
+
+static int xensyms_open(struct inode *inode, struct file *file)
+{
+	struct seq_file *m;
+	struct xen_platform_op *op;
+	char *buf;
+	int ret;
+
+	buf = kzalloc(XEN_KSYM_NAME_LEN + 1, GFP_KERNEL);
+	if (!buf)
+		return -ENOMEM;
+
+	ret = seq_open_private(file, &xensyms_seq_ops,
+		sizeof(struct xen_platform_op));
+	if (ret)
+		return ret;
+
+	m = file->private_data;
+	op = (struct xen_platform_op *)m->private;
+	set_xen_guest_handle(op->u.symdata.name, buf);
+	op->cmd = XENPF_get_symbol;
+	op->u.symdata.namelen = XEN_KSYM_NAME_LEN + 1;
+
+	return 0;
+}
+
+static int xensyms_release(struct inode *inode, struct file *file)
+{
+	struct seq_file *m = file->private_data;
+	struct xen_platform_op *op = (struct xen_platform_op *)m->private;
+
+	kfree(op->u.symdata.name);
+	return seq_release_private(inode, file);
+}
+
+const struct file_operations xensyms_ops = {
+	.open = xensyms_open,
+	.read = seq_read,
+	.llseek = seq_lseek,
+	.release = xensyms_release
+};
diff --git a/include/xen/interface/platform.h b/include/xen/interface/platform.h
index f1331e3..792e29a 100644
--- a/include/xen/interface/platform.h
+++ b/include/xen/interface/platform.h
@@ -352,6 +352,24 @@ struct xenpf_core_parking {
 };
 DEFINE_GUEST_HANDLE_STRUCT(xenpf_core_parking);
 
+#define XENPF_get_symbol      61
+struct xenpf_symdata {
+	/* IN/OUT variables */
+	uint32_t namelen; /* size of 'name' buffer */
+
+	/* IN/OUT variables */
+	uint32_t symnum;  /* IN:  Symbol to read                            */
+			  /* OUT: Next available symbol. If same as IN then */
+			  /*      we reached the end                        */
+
+	/* OUT variables */
+	char type;
+	uint64_t address;
+	GUEST_HANDLE(char) name;
+};
+DEFINE_GUEST_HANDLE_STRUCT(xenpf_symdata);
+
+
 struct xen_platform_op {
 	uint32_t cmd;
 	uint32_t interface_version; /* XENPF_INTERFACE_VERSION */
@@ -372,6 +390,7 @@ struct xen_platform_op {
 		struct xenpf_cpu_hotadd        cpu_add;
 		struct xenpf_mem_hotadd        mem_add;
 		struct xenpf_core_parking      core_parking;
+		struct xenpf_symdata           symdata;
 		uint8_t                        pad[128];
 	} u;
 };
-- 
1.8.1.4

  reply	other threads:[~2014-06-06 17:44 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-06 17:44 [PATCH v2 0/6] xen/PMU: PMU support for Xen PV guests Boris Ostrovsky
2014-06-06 17:44 ` Boris Ostrovsky [this message]
2014-06-10 13:31   ` [PATCH v2 1/6] xen: xensyms support David Vrabel
2014-06-10 14:49     ` Boris Ostrovsky
2014-06-10 14:51       ` Jan Beulich
2014-06-10 15:03         ` Boris Ostrovsky
2014-06-10 15:21           ` Jan Beulich
2014-06-10 15:45             ` Boris Ostrovsky
2014-06-10 16:13               ` Jan Beulich
2014-06-11  9:37   ` Dietmar Hahn
2014-06-06 17:44 ` [PATCH v2 2/6] xen/PMU: Sysfs interface for setting Xen PMU mode Boris Ostrovsky
2014-06-06 20:19   ` Konrad Rzeszutek Wilk
2014-06-10 13:33     ` David Vrabel
2014-06-10 13:48   ` David Vrabel
2014-06-10 14:52     ` Boris Ostrovsky
2014-06-11 10:13   ` Dietmar Hahn
2014-06-11 12:53     ` Boris Ostrovsky
2014-06-11 13:12       ` Dietmar Hahn
2014-06-06 17:44 ` [PATCH v2 3/6] xen/PMU: Initialization code for Xen PMU Boris Ostrovsky
2014-06-06 18:57   ` Andrew Cooper
2014-06-06 19:51     ` Boris Ostrovsky
2014-06-06 17:44 ` [PATCH v2 4/6] xen/PMU: Describe vendor-specific PMU registers Boris Ostrovsky
2014-06-10 14:11   ` David Vrabel
2014-06-10 15:29     ` Boris Ostrovsky
2014-06-06 17:44 ` [PATCH v2 5/6] xen/PMU: Intercept PMU-related MSR and APIC accesses Boris Ostrovsky
2014-06-12  6:56   ` Dietmar Hahn
2014-06-12 14:50     ` Boris Ostrovsky
2014-06-06 17:44 ` [PATCH v2 6/6] xen/PMU: PMU emulation code Boris Ostrovsky
2014-06-10 13:57 ` [PATCH v2 0/6] xen/PMU: PMU support for Xen PV guests David Vrabel
2014-06-10 15:27   ` Boris Ostrovsky

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=1402076686-26586-2-git-send-email-boris.ostrovsky@oracle.com \
    --to=boris.ostrovsky@oracle.com \
    --cc=JBeulich@suse.com \
    --cc=david.vrabel@citrix.com \
    --cc=dietmar.hahn@ts.fujitsu.com \
    --cc=kevin.tian@intel.com \
    --cc=konrad.wilk@oracle.com \
    --cc=xen-devel@lists.xen.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).