xen: xensyms support
authorBoris Ostrovsky <boris.ostrovsky@oracle.com>
Mon, 10 Aug 2015 20:34:32 +0000 (16:34 -0400)
committerDavid Vrabel <david.vrabel@citrix.com>
Thu, 20 Aug 2015 11:24:25 +0000 (12:24 +0100)
Export Xen symbols to dom0 via /proc/xen/xensyms (similar to
/proc/kallsyms).

Signed-off-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Reviewed-by: David Vrabel <david.vrabel@citrix.com>
Signed-off-by: David Vrabel <david.vrabel@citrix.com>
drivers/xen/Kconfig
drivers/xen/xenfs/Makefile
drivers/xen/xenfs/super.c
drivers/xen/xenfs/xenfs.h
drivers/xen/xenfs/xensyms.c [new file with mode: 0644]
include/xen/interface/platform.h

index 7cd226da15fea2d6985b6203d696a6fe8e0c400f..936760455dd5a49810576d5dc503a1e0aa059285 100644 (file)
@@ -280,4 +280,12 @@ config XEN_ACPI
        def_bool y
        depends on X86 && ACPI
 
+config XEN_SYMS
+       bool "Xen symbols"
+       depends on X86 && XEN_DOM0 && XENFS
+       default y if KALLSYMS
+       help
+          Exports hypervisor symbols (along with their types and addresses) via
+          /proc/xen/xensyms file, similar to /proc/kallsyms
+
 endmenu
index b019865fcc56b779098c792bc7653cdc2537f2bc..1a83010ddffafc0f6fe816d021732129814c2d00 100644 (file)
@@ -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
index 06092e0fe8cea4d3a5dfddac4df0e9bb531c5a60..8559a71f36b1a7d6fe2bd2b57b588321ad92f26c 100644 (file)
@@ -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
                {""},
        };
 
index 6b80c7779c0217bdddca45d977e5d823df150b5a..2c5934ea9b1e5498c4f92ff2b74a40f11a973a6d 100644 (file)
@@ -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 (file)
index 0000000..f8b1285
--- /dev/null
@@ -0,0 +1,152 @@
+#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 */
+
+struct xensyms {
+       struct xen_platform_op op;
+       char *name;
+       uint32_t namelen;
+};
+
+/* Grab next output page from the hypervisor */
+static int xensyms_next_sym(struct xensyms *xs)
+{
+       int ret;
+       struct xenpf_symdata *symdata = &xs->op.u.symdata;
+       uint64_t symnum;
+
+       memset(xs->name, 0, xs->namelen);
+       symdata->namelen = xs->namelen;
+
+       symnum = symdata->symnum;
+
+       ret = HYPERVISOR_dom0_op(&xs->op);
+       if (ret < 0)
+               return ret;
+
+       /*
+        * If hypervisor's symbol didn't fit into the buffer then allocate
+        * a larger buffer and try again.
+        */
+       if (unlikely(symdata->namelen > xs->namelen)) {
+               kfree(xs->name);
+
+               xs->namelen = symdata->namelen;
+               xs->name = kzalloc(xs->namelen, GFP_KERNEL);
+               if (!xs->name)
+                       return -ENOMEM;
+
+               set_xen_guest_handle(symdata->name, xs->name);
+               symdata->symnum--; /* Rewind */
+
+               ret = HYPERVISOR_dom0_op(&xs->op);
+               if (ret < 0)
+                       return ret;
+       }
+
+       if (symdata->symnum == symnum)
+               /* End of symbols */
+               return 1;
+
+       return 0;
+}
+
+static void *xensyms_start(struct seq_file *m, loff_t *pos)
+{
+       struct xensyms *xs = (struct xensyms *)m->private;
+
+       xs->op.u.symdata.symnum = *pos;
+
+       if (xensyms_next_sym(xs))
+               return NULL;
+
+       return m->private;
+}
+
+static void *xensyms_next(struct seq_file *m, void *p, loff_t *pos)
+{
+       struct xensyms *xs = (struct xensyms *)m->private;
+
+       xs->op.u.symdata.symnum = ++(*pos);
+
+       if (xensyms_next_sym(xs))
+               return NULL;
+
+       return p;
+}
+
+static int xensyms_show(struct seq_file *m, void *p)
+{
+       struct xensyms *xs = (struct xensyms *)m->private;
+       struct xenpf_symdata *symdata = &xs->op.u.symdata;
+
+       seq_printf(m, "%016llx %c %s\n", symdata->address,
+                  symdata->type, xs->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 xensyms *xs;
+       int ret;
+
+       ret = seq_open_private(file, &xensyms_seq_ops,
+                              sizeof(struct xensyms));
+       if (ret)
+               return ret;
+
+       m = file->private_data;
+       xs = (struct xensyms *)m->private;
+
+       xs->namelen = XEN_KSYM_NAME_LEN + 1;
+       xs->name = kzalloc(xs->namelen, GFP_KERNEL);
+       if (!xs->name) {
+               seq_release_private(inode, file);
+               return -ENOMEM;
+       }
+       set_xen_guest_handle(xs->op.u.symdata.name, xs->name);
+       xs->op.cmd = XENPF_get_symbol;
+       xs->op.u.symdata.namelen = xs->namelen;
+
+       return 0;
+}
+
+static int xensyms_release(struct inode *inode, struct file *file)
+{
+       struct seq_file *m = file->private_data;
+       struct xensyms *xs = (struct xensyms *)m->private;
+
+       kfree(xs->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
+};
index 5cc49ea8d8406f1fec09609828e0b47d1c22f196..8e035871360e15e0593a026d151088a8d7482347 100644 (file)
@@ -474,6 +474,23 @@ struct xenpf_core_parking {
 };
 DEFINE_GUEST_HANDLE_STRUCT(xenpf_core_parking);
 
+#define XENPF_get_symbol      63
+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 */
+       GUEST_HANDLE(char) name;
+       uint64_t        address;
+       char            type;
+};
+DEFINE_GUEST_HANDLE_STRUCT(xenpf_symdata);
+
 struct xen_platform_op {
        uint32_t cmd;
        uint32_t interface_version; /* XENPF_INTERFACE_VERSION */
@@ -495,6 +512,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;
 };