From: Konrad Rzeszutek Wilk Date: Fri, 19 Jul 2013 18:47:29 +0000 (-0400) Subject: xen_diag: Add diagnostic module that causes 'xl debug-keys 0dreg' X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=bee4cd39d56a4203e4936238f3b6f60b5c393d59;p=xentesttools%2Fbootstrap.git xen_diag: Add diagnostic module that causes 'xl debug-keys 0dreg' This is a debug facility that can be handy at some point. Signed-off-by: Konrad Rzeszutek Wilk --- diff --git a/root_image/drivers/Makefile b/root_image/drivers/Makefile index 782655f..22c4000 100644 --- a/root_image/drivers/Makefile +++ b/root_image/drivers/Makefile @@ -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 index 0000000..2c396e2 --- /dev/null +++ b/root_image/drivers/xen_diag/Makefile @@ -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 index 0000000..a45a0e1 --- /dev/null +++ b/root_image/drivers/xen_diag/xen_diag.c @@ -0,0 +1,76 @@ +#include +#include +#include +#include +#include +#include + +MODULE_AUTHOR("Konrad Rzeszutek Wilk"); +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);