forked from QubesOS/qubes-vmm-xen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
1202-libxl-Add-partially-Intel-GVT-g-support-xengt-device.patch
165 lines (153 loc) · 6.45 KB
/
1202-libxl-Add-partially-Intel-GVT-g-support-xengt-device.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
From 1b0acc68addd4fe6c2e9928e65904b1110d9ea47 Mon Sep 17 00:00:00 2001
From: Ivan Kardykov <[email protected]>
Date: Wed, 16 Nov 2022 02:40:06 +0100
Subject: [PATCH] libxl: Add partially Intel GVT-g support (xengt device)
This requires to add minimal support Intel GVT-g mediated passtrough
to Qubes OS. This patches based on Intel XenGT preview, XCP-NG
Project.
---
tools/libs/light/libxl_create.c | 34 ++++++++++++++++++++++++++++++++
tools/libs/light/libxl_dm.c | 3 +++
tools/libs/light/libxl_domain.c | 26 ++++++++++++++++++++++++
tools/libs/light/libxl_types.idl | 5 +++++
4 files changed, 68 insertions(+)
diff --git a/tools/libs/light/libxl_create.c b/tools/libs/light/libxl_create.c
index d89515b8693e..a3a1e99ace44 100644
--- a/tools/libs/light/libxl_create.c
+++ b/tools/libs/light/libxl_create.c
@@ -26,6 +26,36 @@
#include <xen-xsm/flask/flask.h>
+/* The format of the string is:
+ * domid,aperture_size,gm_size,fence_size. This means we want the vgt
+ * driver to create a vgt instance for Domain domid with the required
+ * parameters. NOTE: aperture_size and gm_size are in MB.
+ */
+static void domcreate_vgt_instance(libxl__gc *gc, uint32_t domid,
+ libxl_domain_build_info *b_info)
+{
+ const char *path = "/sys/kernel/vgt/control/create_vgt_instance";
+ FILE *vgt_file;
+ int low_gm = b_info->u.hvm.vgt_low_gm_sz ?: 64;
+ int high_gm = b_info->u.hvm.vgt_high_gm_sz ?: 448;
+ int fence = b_info->u.hvm.vgt_fence_sz ?: 4;
+
+ if ((vgt_file = fopen(path, "w")) == NULL) {
+ LOGD(ERROR, domid, "vGT: fopen failed\n");
+ return;
+ }
+
+ LOGD(INFO, domid, "vGT: fprintf %u,%u,%u,%u,-1,0\n",
+ domid, low_gm, high_gm, fence);
+
+ if (fprintf(vgt_file, "%u,%u,%u,%u,-1,0\n",
+ domid, low_gm, high_gm, fence) < 0)
+ LOGD(ERROR, domid, "vGT: fprintf failed %d\n", errno);
+
+ fclose(vgt_file);
+ return;
+}
+
int libxl__domain_create_info_setdefault(libxl__gc *gc,
libxl_domain_create_info *c_info,
const libxl_physinfo *info)
@@ -334,6 +364,7 @@ int libxl__domain_build_info_setdefault(libxl__gc *gc,
return ERROR_INVAL;
}
break;
+ case LIBXL_VGA_INTERFACE_TYPE_XENGT:
case LIBXL_VGA_INTERFACE_TYPE_CIRRUS:
default:
if (b_info->video_memkb == LIBXL_MEMKB_DEFAULT)
@@ -1877,6 +1908,9 @@ static void domcreate_launch_dm(libxl__egc *egc, libxl__multidev *multidev,
if ( ret )
goto error_out;
+ if (d_config->b_info.u.hvm.vga.kind == LIBXL_VGA_INTERFACE_TYPE_XENGT)
+ domcreate_vgt_instance(gc, domid, &d_config->b_info);
+
return;
}
case LIBXL_DOMAIN_TYPE_PV:
diff --git a/tools/libs/light/libxl_dm.c b/tools/libs/light/libxl_dm.c
index 4710ded5deec..af96dcae5ffd 100644
--- a/tools/libs/light/libxl_dm.c
+++ b/tools/libs/light/libxl_dm.c
@@ -1446,6 +1446,9 @@ static int libxl__build_device_model_args_new(libxl__gc *gc,
GCSPRINTF("qxl-vga,vram_size_mb=%"PRIu64",ram_size_mb=%"PRIu64,
(b_info->video_memkb/2/1024), (b_info->video_memkb/2/1024) ) );
break;
+ case LIBXL_VGA_INTERFACE_TYPE_XENGT:
+ flexarray_vappend(dm_args, "-vga", "xengt", NULL);
+ break;
default:
LOGD(ERROR, guest_domid, "Invalid emulated video card specified");
return ERROR_INVAL;
diff --git a/tools/libs/light/libxl_domain.c b/tools/libs/light/libxl_domain.c
index f4bcb0b198cb..db257d45ebb7 100644
--- a/tools/libs/light/libxl_domain.c
+++ b/tools/libs/light/libxl_domain.c
@@ -1110,6 +1110,30 @@ static void domain_destroy_callback(libxl__egc *egc,
static void destroy_finish_check(libxl__egc *egc,
libxl__domain_destroy_state *dds);
+/* We don't care the return value:
+ * 1) the guest may not be a VGT guest;
+ * 2) normally when a VGT guest shutdown, the ioemu has already tried to
+ * destroy the vgt instance and we shouldn't come here by "xl dest dom_id".
+ * 3) we come here because the ioemu didn't destroy the vgt instance
+ * successfully(e.g., ioemu exits abnormally) or we want to kill the guest by
+ * force while it's running. In this case, we still try our best to destroy
+ * the vgt instance.
+ */
+static void destroy_vgt_instance(int domid)
+{
+ const char *path = "/sys/kernel/vgt/control/create_vgt_instance";
+ FILE *vgt_file;
+
+ if (domid <= 0)
+ return;
+
+ if ((vgt_file = fopen(path, "w")) == NULL)
+ return;
+
+ (void)fprintf(vgt_file, "%d\n", -domid);
+ (void)fclose(vgt_file);
+}
+
void libxl__domain_destroy(libxl__egc *egc, libxl__domain_destroy_state *dds)
{
STATE_AO_GC(dds->ao);
@@ -1583,6 +1607,8 @@ static void devices_destroy_cb(libxl__egc *egc,
}
libxl__userdata_destroyall(gc, domid);
+ destroy_vgt_instance(domid);
+
libxl__unlock_file(lock);
/* Clean up qemu-save and qemu-resume files. They are
diff --git a/tools/libs/light/libxl_types.idl b/tools/libs/light/libxl_types.idl
index 1ad4d8dd1d3f..ba362dc43e61 100644
--- a/tools/libs/light/libxl_types.idl
+++ b/tools/libs/light/libxl_types.idl
@@ -38,6 +38,7 @@ libxl_ms_vm_genid = Builtin("ms_vm_genid", passby=PASS_BY_REFERENCE, check_defau
#
MemKB = UInt(64, init_val = "LIBXL_MEMKB_DEFAULT", json_gen_fn = "libxl__uint64_gen_json")
+VgtInt = UInt(32, init_val = "0UL")
#
# Constants / Enumerations
@@ -238,6 +239,7 @@ libxl_vga_interface_type = Enumeration("vga_interface_type", [
(2, "STD"),
(3, "NONE"),
(4, "QXL"),
+ (5, "XENGT"),
], init_val = "LIBXL_VGA_INTERFACE_TYPE_UNKNOWN")
libxl_vendor_device = Enumeration("vendor_device", [
@@ -677,6 +679,9 @@ libxl_domain_build_info = Struct("domain_build_info",[
("hdtype", libxl_hdtype),
("nographic", libxl_defbool),
("vga", libxl_vga_interface_info),
+ ("vgt_low_gm_sz", VgtInt),
+ ("vgt_high_gm_sz", VgtInt),
+ ("vgt_fence_sz", VgtInt),
("vnc", libxl_vnc_info),
# keyboard layout, default is en-us keyboard
("keymap", string),
--
2.44.0