--- /dev/null
+# 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
--- /dev/null
+#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);