From dd60d3da956c06cebbd7e1075e9042b22d735c6d Mon Sep 17 00:00:00 2001 From: Marek Marczykowski Date: Sat, 2 Jun 2012 12:32:49 +0200 Subject: [PATCH 1/8] makefile: rename vchan Makefile to not conflict with windows build --- rpm_spec/core-dom0.spec | 2 +- rpm_spec/core-vm.spec | 2 +- vchan/{Makefile => Makefile.linux} | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename vchan/{Makefile => Makefile.linux} (100%) diff --git a/rpm_spec/core-dom0.spec b/rpm_spec/core-dom0.spec index 4de15029..e850371d 100644 --- a/rpm_spec/core-dom0.spec +++ b/rpm_spec/core-dom0.spec @@ -55,7 +55,7 @@ python -O -m compileall qvm-core qmemman make -C restore make -C aux-tools make -C ../qubes_rpc -make -C ../vchan +make -C ../vchan -f Makefile.linux make -C ../u2mfn make -C ../qrexec diff --git a/rpm_spec/core-vm.spec b/rpm_spec/core-vm.spec index 06004ea5..88b26870 100644 --- a/rpm_spec/core-vm.spec +++ b/rpm_spec/core-vm.spec @@ -54,7 +54,7 @@ The Qubes core files for installation inside a Qubes VM. %build make -C u2mfn -make -C vchan +make -C vchan -f Makefile.linux make -C misc make -C qubes_rpc make -C qrexec diff --git a/vchan/Makefile b/vchan/Makefile.linux similarity index 100% rename from vchan/Makefile rename to vchan/Makefile.linux From 1462e36454c93c93023e268a8a70f4801dfe44b3 Mon Sep 17 00:00:00 2001 From: Marek Marczykowski Date: Sat, 2 Jun 2012 12:34:35 +0200 Subject: [PATCH 2/8] win: convert vchan/sources to windows EOL-style --- vchan/sources | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/vchan/sources b/vchan/sources index 1baae972..5d7cff39 100644 --- a/vchan/sources +++ b/vchan/sources @@ -1,24 +1,24 @@ -TARGETNAME=libvchan -TARGETTYPE=LIBRARY -TARGETPATH=..\win\libs - -#BUILD_PASS0_CONSUMES=gntmem evtchn xenstore -#BUILD_PASS0_PRODUCES=vchan - -USE_MSVCRT=1 - -DLLDEF=libvchan.def - -C_DEFINES = $(C_DEFINES) /DCONFIG_STUBDOM - -INCLUDES=$(INCLUDES); \ - ..\win\include;\ - -SOURCES=io.c init.c - -TARGETLIBS=\ - $(SDK_LIB_PATH)\setupapi.lib \ - $(SDK_LIB_PATH)\kernel32.lib - - - +TARGETNAME=libvchan +TARGETTYPE=LIBRARY +TARGETPATH=..\win\libs + +#BUILD_PASS0_CONSUMES=gntmem evtchn xenstore +#BUILD_PASS0_PRODUCES=vchan + +USE_MSVCRT=1 + +DLLDEF=libvchan.def + +C_DEFINES = $(C_DEFINES) /DCONFIG_STUBDOM + +INCLUDES=$(INCLUDES); \ + ..\win\include;\ + +SOURCES=io.c init.c + +TARGETLIBS=\ + $(SDK_LIB_PATH)\setupapi.lib \ + $(SDK_LIB_PATH)\kernel32.lib + + + From 87115716ba1d7f2a643fa13d308a2e0adcd6cb4f Mon Sep 17 00:00:00 2001 From: Marek Marczykowski Date: Sat, 2 Jun 2012 13:25:18 +0200 Subject: [PATCH 3/8] vchan/stubdom: remove temp hack (unneded now) This was needed when stubdom have no write access to device/vchan. --- vchan/init.c | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/vchan/init.c b/vchan/init.c index d870aea2..21d774a8 100644 --- a/vchan/init.c +++ b/vchan/init.c @@ -127,11 +127,6 @@ static int server_interface_init(struct libvchan *ctrl, int devno) struct xs_handle *xs; char buf[64]; char ref[16]; - /* XXX temp hack begin */ - char *domid_s; - int domid = 0; - unsigned int len; - /* XXX temp hack end */ #ifdef XENCTRL_HAS_XC_INTERFACE xc_evtchn *evfd; #else @@ -163,11 +158,6 @@ static int server_interface_init(struct libvchan *ctrl, int devno) ctrl->evport = port; ctrl->devno = devno; - // stubdom debug HACK XXX - domid_s = xs_read(xs, 0, "domid", &len); - if (domid_s) - domid = atoi(domid_s); - snprintf(buf, sizeof buf, "device/vchan/%d/version", devno); if (!xs_write(xs, 0, buf, "2", strlen("2"))) goto fail2; @@ -175,21 +165,11 @@ static int server_interface_init(struct libvchan *ctrl, int devno) snprintf(ref, sizeof ref, "%d", ctrl->ring_ref); snprintf(buf, sizeof buf, "device/vchan/%d/ring-ref", devno); if (!xs_write(xs, 0, buf, ref, strlen(ref))) -#ifdef CONFIG_STUBDOM - // TEMP HACK XXX FIXME goto fail2; - fprintf(stderr, "xenstore-write /local/domain/%d/%s %s\n", domid, buf, ref); -#else goto fail2; -#endif snprintf(ref, sizeof ref, "%d", ctrl->evport); snprintf(buf, sizeof buf, "device/vchan/%d/event-channel", devno); if (!xs_write(xs, 0, buf, ref, strlen(ref))) -#ifdef CONFIG_STUBDOM - // TEMP HACK XXX FIXME goto fail2; - fprintf(stderr, "xenstore-write /local/domain/%d/%s %s\n", domid, buf, ref); -#else goto fail2; -#endif // do not block in stubdom - libvchan_server_handle_connected will be // called on first input #ifndef CONFIG_STUBDOM @@ -449,4 +429,4 @@ struct libvchan *libvchan_client_init(int domain, int devno) return NULL; } -#endif \ No newline at end of file +#endif From a2a21c046738fde689bd28cb766d103043b25aba Mon Sep 17 00:00:00 2001 From: Marek Marczykowski Date: Sun, 3 Jun 2012 16:32:46 +0200 Subject: [PATCH 4/8] vchan: unify calls to xc_evtchn_close Calls to this function can be the same on all systems and xen versions, so simplify code. --- vchan/init.c | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/vchan/init.c b/vchan/init.c index 21d774a8..0f7756f5 100644 --- a/vchan/init.c +++ b/vchan/init.c @@ -184,15 +184,7 @@ static int server_interface_init(struct libvchan *ctrl, int devno) ret = 0; fail2: if (ret) -#ifdef XENCTRL_HAS_XC_INTERFACE xc_evtchn_close(evfd); -#else -#ifdef WINNT - xc_evtchn_close(evfd); -#else - close(evfd); -#endif -#endif fail: xs_daemon_close(xs); return ret; @@ -268,11 +260,7 @@ int libvchan_server_handle_connected(struct libvchan *ctrl) #if 0 fail2: if (ret) -#ifdef XENCTRL_HAS_XC_INTERFACE xc_evtchn_close(ctrl->evfd); -#else - close(ctrl->evfd); -#endif #endif xs_daemon_close(xs); return ret; @@ -357,11 +345,7 @@ static int client_interface_init(struct libvchan *ctrl, int domain, int devno) ctrl->ring = (struct vchan_interface *) xc_map_foreign_range(xcfd, domain, 4096, PROT_READ | PROT_WRITE, ctrl->ring_ref); -#ifdef XENCTRL_HAS_XC_INTERFACE xc_interface_close(xcfd); -#else - close(xcfd); -#endif break; case 2: xcg = xc_gnttab_open(); @@ -390,11 +374,7 @@ static int client_interface_init(struct libvchan *ctrl, int domain, int devno) ctrl->evport = xc_evtchn_bind_interdomain(evfd, domain, remote_port); if (ctrl->evport < 0 || xc_evtchn_notify(evfd, ctrl->evport)) -#ifdef XENCTRL_HAS_XC_INTERFACE xc_evtchn_close(evfd); -#else - close(evfd); -#endif else ret = 0; fail: From edf1ecfcfd9a72a6140033a176fa4abc25ac8226 Mon Sep 17 00:00:00 2001 From: Marek Marczykowski Date: Sun, 3 Jun 2012 16:37:34 +0200 Subject: [PATCH 5/8] vchan: remove unused variables --- vchan/init.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/vchan/init.c b/vchan/init.c index 0f7756f5..e93d5148 100644 --- a/vchan/init.c +++ b/vchan/init.c @@ -235,8 +235,6 @@ int libvchan_server_handle_connected(struct libvchan *ctrl) struct xs_handle *xs; char buf[64]; int ret = -1; - int libvchan_fd; -// fd_set rfds; #ifdef WINNT xs = xs_domain_open(); From f01b1b40ac9080d17f5db2514861c407bdfc0869 Mon Sep 17 00:00:00 2001 From: Marek Marczykowski Date: Sun, 3 Jun 2012 16:38:00 +0200 Subject: [PATCH 6/8] vchan: fix xc_gnttab_open call --- vchan/init.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/vchan/init.c b/vchan/init.c index e93d5148..de2991a6 100644 --- a/vchan/init.c +++ b/vchan/init.c @@ -278,10 +278,11 @@ static int client_interface_init(struct libvchan *ctrl, int domain, int devno) struct xs_handle *xs; #ifdef XENCTRL_HAS_XC_INTERFACE xc_interface *xcfd; + xc_gnttab *xcg; #else int xcfd; -#endif int xcg; +#endif char buf[64]; char *ref; int version; @@ -346,7 +347,7 @@ static int client_interface_init(struct libvchan *ctrl, int domain, int devno) xc_interface_close(xcfd); break; case 2: - xcg = xc_gnttab_open(); + xcg = xc_gnttab_open(NULL, 0); if (xcg < 0) goto fail; ctrl->ring = (struct vchan_interface *) From 22207ddf75b610e589aede548d64fa1e40b49004 Mon Sep 17 00:00:00 2001 From: Marek Marczykowski Date: Sun, 3 Jun 2012 16:38:30 +0200 Subject: [PATCH 7/8] vchan: introduce features macros Use features macros (QREXEC_RING_V2 and ASYNC_INIT) instead of directly depending on building environment. The macros are turned on (when required) in libvchan.h based on target system. --- vchan/init.c | 12 +++++++----- vchan/libvchan.h | 12 ++++++++++-- vchan/sources | 2 -- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/vchan/init.c b/vchan/init.c index de2991a6..93d6fb09 100644 --- a/vchan/init.c +++ b/vchan/init.c @@ -62,7 +62,7 @@ static int fill_ctrl(struct libvchan *ctrl, struct vchan_interface *ring, int ri return 0; } -#ifdef WINNT +#ifdef QREXEC_RING_V2 static int ring_init(struct libvchan *ctrl) { struct gntmem_handle* h; @@ -158,9 +158,11 @@ static int server_interface_init(struct libvchan *ctrl, int devno) ctrl->evport = port; ctrl->devno = devno; +#ifdef QREXEC_RING_V2 snprintf(buf, sizeof buf, "device/vchan/%d/version", devno); if (!xs_write(xs, 0, buf, "2", strlen("2"))) goto fail2; +#endif snprintf(ref, sizeof ref, "%d", ctrl->ring_ref); snprintf(buf, sizeof buf, "device/vchan/%d/ring-ref", devno); @@ -170,10 +172,10 @@ static int server_interface_init(struct libvchan *ctrl, int devno) snprintf(buf, sizeof buf, "device/vchan/%d/event-channel", devno); if (!xs_write(xs, 0, buf, ref, strlen(ref))) goto fail2; - // do not block in stubdom - libvchan_server_handle_connected will be - // called on first input -#ifndef CONFIG_STUBDOM - // wait for the peer to arrive + // do not block in stubdom and windows - libvchan_server_handle_connected will be + // called on first input +#ifdef ASYNC_INIT + // wait for the peer to arrive if (xc_evtchn_pending(evfd) == -1) goto fail2; xc_evtchn_unmask(ctrl->evfd, ctrl->evport); diff --git a/vchan/libvchan.h b/vchan/libvchan.h index 63ab6e9f..6b19b2fa 100644 --- a/vchan/libvchan.h +++ b/vchan/libvchan.h @@ -28,11 +28,19 @@ #include typedef HANDLE EVTCHN; #define snprintf _snprintf -#else +#else /* WINNT */ #include typedef int EVTCHN; -#endif +#endif /* WINNT */ +/* config vchan features */ +#ifdef WINNT +#define QREXEC_RING_V2 +#define ASYNC_INIT +#endif /* WINNT */ +#ifdef CONFIG_STUBDOM +#define ASYNC_INIT +#endif /* CONFIG_STUBDOM */ #include typedef uint32_t VCHAN_RING_IDX; diff --git a/vchan/sources b/vchan/sources index 5d7cff39..5aea3939 100644 --- a/vchan/sources +++ b/vchan/sources @@ -9,8 +9,6 @@ USE_MSVCRT=1 DLLDEF=libvchan.def -C_DEFINES = $(C_DEFINES) /DCONFIG_STUBDOM - INCLUDES=$(INCLUDES); \ ..\win\include;\ From 01c9fdfe59c59546f6c703f986018c8f67b56c10 Mon Sep 17 00:00:00 2001 From: Marek Marczykowski Date: Mon, 4 Jun 2012 14:59:11 +0200 Subject: [PATCH 8/8] vchan: fix ASYNC_INIT macro --- vchan/init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vchan/init.c b/vchan/init.c index 93d6fb09..09e05ff9 100644 --- a/vchan/init.c +++ b/vchan/init.c @@ -174,7 +174,7 @@ static int server_interface_init(struct libvchan *ctrl, int devno) goto fail2; // do not block in stubdom and windows - libvchan_server_handle_connected will be // called on first input -#ifdef ASYNC_INIT +#ifndef ASYNC_INIT // wait for the peer to arrive if (xc_evtchn_pending(evfd) == -1) goto fail2;