From: Peter Dinda Date: Fri, 13 Apr 2012 22:00:18 +0000 (-0500) Subject: linux userspace hypercall addition utility + Makefile updates X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?p=palacios.git;a=commitdiff_plain;h=67f99136a8d412f865f68b16f6875fe3969ce900 linux userspace hypercall addition utility + Makefile updates --- diff --git a/linux_usr/Makefile b/linux_usr/Makefile index 4f2aa2c..6b60433 100644 --- a/linux_usr/Makefile +++ b/linux_usr/Makefile @@ -24,6 +24,7 @@ BASE_EXECS = v3_mem \ v3_cons_sc \ v3_stream \ v3_monitor \ + v3_hypercall # # Examples @@ -31,13 +32,18 @@ BASE_EXECS = v3_mem \ EXAMPLE_EXECS = v3_user_host_dev_example \ v3_os_debug \ v3_user_keyed_stream_example \ - v3_user_keyed_stream_file \ + v3_user_keyed_stream_file # # Currently experimental things # EXPERIMENTAL_EXECS = v3_simulate \ - v3_inject_ecc_scrubber_mce + v3_inject_ecc_scrubber_mce \ + v3_top_inject \ + v3_env_inject + + + # # Things that have been built elsewhere - just for reference here @@ -61,6 +67,8 @@ ifeq ($(STATIC),1) CFLAGS += -static endif +CFLAGS += -I../linux_module + CC = gcc AR = ar diff --git a/linux_usr/v3_hypercall.c b/linux_usr/v3_hypercall.c new file mode 100644 index 0000000..1cc53b4 --- /dev/null +++ b/linux_usr/v3_hypercall.c @@ -0,0 +1,85 @@ +/* + * V3 Hypercall Add Utility + * Allows hypercalls to be added to Palacios at run-time + * + * (c) Kyle C. Hale, 2011 + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../linux_module/iface-host-hypercall.h" + +static void usage (char * bin) { + fprintf(stderr, "%s /dev/v3-vm add|remove [function]\n", bin); + fprintf(stderr, " = hypercall number\n" + "[function] = kernel symbol to bind to\n" + " (defaults to a nop if not given)\n"); +} + +int main (int argc, char ** argv) { + char * vm_dev = NULL; + int vm_fd, err; + struct hcall_data hd; + enum {ADD,REMOVE} task; + + + if (argc < 4 || argc>5) { + usage(argv[0]); + return -1; + } + + vm_dev = argv[1]; + + hd.hcall_nr = strtol(argv[3], NULL, 0); + + + if (!strcasecmp(argv[2],"add")) { + task=ADD; + if (argc==4) { + hd.fn[0]=0; // blank + } else { + strcpy(hd.fn,argv[4]); + } + } else if (!strcasecmp(argv[2],"remove")) { + task=REMOVE; + } else { + usage(argv[0]); + return -1; + } + + printf("%s hypercall %d (0x%x) -> '%s' on %s\n", + task==ADD ? "Adding" : "Removing", + hd.hcall_nr, hd.hcall_nr, + task==REMOVE ? "(unimportant)" + : strcmp(hd.fn,"") ? hd.fn : "(default nop)", vm_dev); + + vm_fd = open(vm_dev, O_RDONLY); + if (vm_fd == -1) { + perror("Cannot open VM device"); + return -1; + } + + if (ioctl(vm_fd, + task==ADD ? V3_VM_HYPERCALL_ADD : V3_VM_HYPERCALL_REMOVE, + &hd) < 0) { + perror("Cannot complete task due ioctl failure"); + close(vm_fd); + return -1; + } + + close(vm_fd); + + printf("Done.\n"); + + return 0; +} + +