-
Notifications
You must be signed in to change notification settings - Fork 2
/
1000-libvirt-pci-qubes.patch
71 lines (66 loc) · 3.09 KB
/
1000-libvirt-pci-qubes.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
diff --git a/libkvmchan/Makefile b/libkvmchan/Makefile
index 3a02ef6..4656602 100644
--- a/libkvmchan/Makefile
+++ b/libkvmchan/Makefile
@@ -5,6 +5,7 @@ LIBS=-lrt -pthread
DEBUG:=true
SYSTEMD ?= 0
+BACKEND_VMM ?=
DAEMON_SRCS:=daemon/daemon.c daemon/libvirt.c daemon/util.c daemon/ivshmem.c daemon/vfio.c \
daemon/ipc.c daemon/connections.c daemon/localhandler.c
@@ -16,6 +17,10 @@ ifeq ($(SYSTEMD),1)
DAEMON_CFLAGS += -DHAVE_SYSTEMD
DAEMON_LIBS += `pkg-config --libs libsystemd || pkg-config --libs libsystemd-daemon`
endif
+ifeq ($(BACKEND_VMM),kvm)
+DAEMON_CFLAGS += -DHAVE_QUBES
+endif
+
TEST_SRCS:=test.c
TEST_DEPS:=$(TEST_SRCS:.c=.o)
diff --git a/libkvmchan/daemon/libvirt.c b/libkvmchan/daemon/libvirt.c
index c061736..12b589a 100644
--- a/libkvmchan/daemon/libvirt.c
+++ b/libkvmchan/daemon/libvirt.c
@@ -268,6 +268,7 @@ static bool attach_ivshmem_device(virDomainPtr dom, const char *path, uint32_t i
* about dedicated pci host bridges.
*/
+#ifdef HAVE_QUBES
// A QMP command to add a new chardev with formats %d %s (index, path)
const char qmp_new_chardev_format[] = "{\"execute\":\"chardev-add\", \"arguments\": {\"id\":"
"\"charshmem%"PRIu32"\", \"backend\":{ \"type\": \"socket\", \"data\": "
@@ -282,6 +283,35 @@ static bool attach_ivshmem_device(virDomainPtr dom, const char *path, uint32_t i
char ivshmem_buf[sizeof(qmp_new_ivshmem_format) + 255 /* enough for pci bus? */];
snprintf(chardev_buf, sizeof(chardev_buf), qmp_new_chardev_format, index, path);
snprintf(ivshmem_buf, sizeof(ivshmem_buf), qmp_new_ivshmem_format, index);
+#else
+ /* QUBES TEST CODE */
+
+ // A QMP command to add a new chardev with formats %d %s (index, path)
+ const char qmp_new_chardev_format[] = "{\"execute\":\"chardev-add\", \"arguments\": {\"id\":"
+ "\"charshmem%"PRIu32"\", \"backend\":{ \"type\": \"socket\", \"data\": "
+ "{\"server\": false, \"addr\": {\"type\": \"unix\", \"data\": {\"path\": \"%s\"} } } } } }";
+
+ // A QMP command to add a new ivshmem device with format %d (index)
+ const char qmp_new_ivshmem_format[] = "{\"execute\":\"device_add\", \"arguments\": {\"driver\": "
+ "\"ivshmem-doorbell\", \"id\":\"shmem%1$"PRIu32"\", \"chardev\":\"charshmem%1$"PRIu32"\", \"vectors\": 2,"
+ "\"bus\": \"%2$s\", \"addr\": \"%3$s\"}}";
+
+ // Fill in arguments for chardev and ivshmem commands
+ char chardev_buf[sizeof(qmp_new_chardev_format) + 255];
+ char ivshmem_buf[sizeof(qmp_new_ivshmem_format) + 255];
+ snprintf(chardev_buf, sizeof(chardev_buf), qmp_new_chardev_format, index, path);
+
+ // TODO: CONVERT TO HEX
+ const char pci_bus_format[] = "pci.%1$"PRIu32"";
+ const char pci_slot_format[] = "0x%1$"PRIu32"";
+ char pci_bus[10 /* pcie.ff.ff */];
+ char pci_slot[4 /* 0xff */];
+
+ // XXX: TEMP: Manually setting PCI bus to 2
+ snprintf(pci_bus, sizeof(pci_bus), pci_bus_format, 2);
+ snprintf(pci_slot, sizeof(pci_slot), pci_slot_format, index+1);
+ snprintf(ivshmem_buf, sizeof(ivshmem_buf), qmp_new_ivshmem_format, index, pci_bus, pci_slot);
+#endif
#elif defined(USE_VFIO_SPAPR)
/**