]> xenbits.xensource.com Git - xentesttools/bootstrap.git/commitdiff
xen_diag: Add diagnostic module that causes 'xl debug-keys 0dreg'
authorKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Fri, 19 Jul 2013 18:47:29 +0000 (14:47 -0400)
committerKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Fri, 19 Jul 2013 18:47:29 +0000 (14:47 -0400)
This is a debug facility that can be handy at some point.

Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
root_image/drivers/Makefile
root_image/drivers/xen_diag/Makefile [new file with mode: 0644]
root_image/drivers/xen_diag/xen_diag.c [new file with mode: 0644]

index 782655fbf0947c74bca3ac223225966635a9fa3c..22c40005111997cd2cfadfd030e9ef9135ba2008 100644 (file)
@@ -1,5 +1,6 @@
 obj-m += dma_test/
 obj-m += wb_to_wc/
+obj-m += xen_diag/
 
 .PHONY:        distclean
 distclean:     clean
diff --git a/root_image/drivers/xen_diag/Makefile b/root_image/drivers/xen_diag/Makefile
new file mode 100644 (file)
index 0000000..2c396e2
--- /dev/null
@@ -0,0 +1,37 @@
+# Comment/uncomment the following line to disable/enable debugging
+#DEBUG = y
+
+# Add your debugging flag (or not) to CFLAGS
+ifeq ($(DEBUG),y)
+  DEBFLAGS = -O -g # "-O" is needed to expand inlines
+else
+  DEBFLAGS = -O2
+endif
+
+EXTRA_CFLAGS += $(DEBFLAGS) -I$(LDDINCDIR)
+
+ifneq ($(KERNELRELEASE),)
+# call from kernel build system
+
+obj-m  := xen_diag.o
+
+else
+
+KERNELDIR ?= /lib/modules/$(shell uname -r)/build
+PWD       := $(shell pwd)
+
+default:
+       $(MAKE) -C $(KERNELDIR) M=$(PWD) LDDINCDIR=$(PWD)/../include modules
+
+endif
+
+clean:
+       rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions
+
+depend .depend dep:
+       $(CC) $(CFLAGS) -M *.c > .depend
+
+
+ifeq (.depend,$(wildcard .depend))
+include .depend
+endif
diff --git a/root_image/drivers/xen_diag/xen_diag.c b/root_image/drivers/xen_diag/xen_diag.c
new file mode 100644 (file)
index 0000000..a45a0e1
--- /dev/null
@@ -0,0 +1,76 @@
+#include <linux/module.h>
+#include <linux/init.h>
+#include <xen/xen.h>
+#include <xen/interface/platform.h>
+#include <asm/xen/hypercall.h>
+#include <asm/xen/interface.h>
+
+MODULE_AUTHOR("Konrad Rzeszutek Wilk<konrad.wilk@oracle.com>");
+MODULE_DESCRIPTION("xen_diag");
+MODULE_LICENSE("GPL");
+MODULE_VERSION("0.1");
+
+static char *key = "0dreg";
+module_param(key, charp , 0644);
+MODULE_PARM_DESC(key, "keys to send");
+
+#define __HYPERVISOR_sysctl_op               35
+
+/* XEN_SYSCTL_debug_keys */
+struct xen_sysctl_debug_keys {
+    /* IN variables. */
+    GUEST_HANDLE(char) keys;
+    uint32_t nr_keys;
+};
+
+DEFINE_GUEST_HANDLE_STRUCT(xen_sysctl_debug_keys);
+
+struct xen_sysctl {
+#define XEN_SYSCTL_debug_keys                     7
+       uint32_t cmd;
+/* 4.1 has 9, 4.2 and 4.3 are A */
+#define XEN_SYSCTL_INTERFACE_VERSION_4_1 0x00000008
+#define XEN_SYSCTL_INTERFACE_VERSION_4_2 0x00000009
+#define XEN_SYSCTL_INTERFACE_VERSION_4_3 0x0000000A
+       uint32_t interface_version; /* XEN_SYSCTL_INTERFACE_VERSION */
+       union {
+               struct xen_sysctl_debug_keys        debug_keys;
+       } u;
+};
+DEFINE_GUEST_HANDLE_STRUCT(xen_sysctl);
+
+static int __init do_sysctl(int ver, char  *key)
+{
+       struct xen_sysctl op = {
+               .cmd = XEN_SYSCTL_debug_keys,
+               .interface_version = ver,
+               .u.debug_keys.nr_keys = strlen(key),
+       };
+
+       printk(KERN_INFO "Sending [%s]\n", key);
+       set_xen_guest_handle(op.u.debug_keys.keys, key);
+       return  _hypercall1(int, sysctl_op, &op);
+}
+static int __init xen_diag_init(void)
+{
+       int i;
+
+       int ver[3] = {XEN_SYSCTL_INTERFACE_VERSION_4_1,
+                     XEN_SYSCTL_INTERFACE_VERSION_4_2,
+                     XEN_SYSCTL_INTERFACE_VERSION_4_3};
+
+       for (i = 0; i < ARRAY_SIZE(ver); i++) {
+               int rc = do_sysctl(ver[i], key);
+
+               if (rc  == -EACCES)
+                       continue;
+               else if (rc < 0)
+                       return rc;
+       }
+       return 0;
+}
+static void __exit xen_diag_exit(void)
+{
+}
+module_init(xen_diag_init);
+module_exit(xen_diag_exit);