-
-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy path0605-libxl-automatically-enable-gfx_passthru-if-IGD-is-as.patch
139 lines (124 loc) · 5.43 KB
/
0605-libxl-automatically-enable-gfx_passthru-if-IGD-is-as.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
From 573919b6c6903ddb920963a10cf5becd398d5d35 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?=
<marmarek@invisiblethingslab.com>
Date: Sat, 6 Jun 2020 05:02:33 +0200
Subject: [PATCH] libxl: automatically enable gfx_passthru if IGD is assigned
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
The gfx_passthru option needs to be enabled whenever IGD is assigned,
otherwise qemu refuses to start. Similarly, if gfx_passthru is enabled,
IGD needs to be assigned, otherwise libxl refuses to start the guest.
This means the gfx_passthru is fully redundant to assigning IGD (besides
enabling various non-bootable configurations).
Change the default value to follow IGD assignment state. For that, use
existing libxl__detect_gfx_passthru_kind (move from libxl_dm.c to
libxl_create.c).
While the option is designed with various GFX in mind, only IGD ever got
a special treatment. PCI passthrough of other GFX devices (some AMD and
Nvidia at least) works just fine without setting gfx_passthru at all.
This change simplifies configuration, but also fixes IGD passthrough
when using libvirt (which doesn't expose gfx_passthru option).
Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
---
docs/man/xl.cfg.5.pod.in | 3 +++
tools/libs/light/libxl_create.c | 27 ++++++++++++++++++++++++++-
tools/libs/light/libxl_dm.c | 20 +-------------------
3 files changed, 30 insertions(+), 20 deletions(-)
diff --git a/docs/man/xl.cfg.5.pod.in b/docs/man/xl.cfg.5.pod.in
index ac3f88fd5718..bce4b2979881 100644
--- a/docs/man/xl.cfg.5.pod.in
+++ b/docs/man/xl.cfg.5.pod.in
@@ -1247,6 +1247,9 @@ Intel Graphics Device.
=back
+By default, this option is enabled if Intel Graphics Device is assigned to the
+VM.
+
Note that some graphics cards (AMD/ATI cards, for example) do not
necessarily require the B<gfx_passthru> option, so you can use the normal Xen
PCI passthrough to assign the graphics card as a secondary graphics
diff --git a/tools/libs/light/libxl_create.c b/tools/libs/light/libxl_create.c
index 48c625992149..ac8d3c395163 100644
--- a/tools/libs/light/libxl_create.c
+++ b/tools/libs/light/libxl_create.c
@@ -71,6 +71,22 @@ void libxl__rdm_setdefault(libxl__gc *gc, libxl_domain_build_info *b_info)
LIBXL_RDM_MEM_BOUNDARY_MEMKB_DEFAULT;
}
+static enum libxl_gfx_passthru_kind
+libxl__detect_gfx_passthru_kind(libxl__gc *gc,
+ const libxl_domain_config *guest_config)
+{
+ const libxl_domain_build_info *b_info = &guest_config->b_info;
+
+ if (b_info->u.hvm.gfx_passthru_kind != LIBXL_GFX_PASSTHRU_KIND_DEFAULT)
+ return b_info->u.hvm.gfx_passthru_kind;
+
+ if (libxl__is_igd_vga_passthru(gc, guest_config)) {
+ return LIBXL_GFX_PASSTHRU_KIND_IGD;
+ }
+
+ return LIBXL_GFX_PASSTHRU_KIND_DEFAULT;
+}
+
int libxl__domain_build_info_setdefault(libxl__gc *gc,
libxl_domain_build_info *b_info)
{
@@ -423,7 +439,8 @@ int libxl__domain_build_info_setdefault(libxl__gc *gc,
libxl_defbool_setdefault(&b_info->u.hvm.nographic, false);
- libxl_defbool_setdefault(&b_info->u.hvm.gfx_passthru, false);
+ libxl_defbool_setdefault(&b_info->u.hvm.gfx_passthru,
+ b_info->u.hvm.gfx_passthru_kind != LIBXL_GFX_PASSTHRU_KIND_DEFAULT);
libxl__rdm_setdefault(gc, b_info);
break;
@@ -1265,6 +1282,14 @@ int libxl__domain_config_setdefault(libxl__gc *gc,
? libxl__get_required_iommu_memory(d_config->b_info.max_memkb)
: 0;
+ if (d_config->b_info.type == LIBXL_DOMAIN_TYPE_HVM) {
+ if (d_config->b_info.u.hvm.gfx_passthru_kind == LIBXL_GFX_PASSTHRU_KIND_DEFAULT) {
+ /* this may also keep LIBXL_GFX_PASSTHRU_KIND_DEFAULT */
+ d_config->b_info.u.hvm.gfx_passthru_kind =
+ libxl__detect_gfx_passthru_kind(gc, d_config);
+ }
+ }
+
ret = libxl__domain_build_info_setdefault(gc, &d_config->b_info);
if (ret) {
LOGD(ERROR, domid, "Unable to set domain build info defaults");
diff --git a/tools/libs/light/libxl_dm.c b/tools/libs/light/libxl_dm.c
index ff8ddeec9a37..bcbaac8d8f1d 100644
--- a/tools/libs/light/libxl_dm.c
+++ b/tools/libs/light/libxl_dm.c
@@ -996,22 +996,6 @@ static char *dm_spice_options(libxl__gc *gc,
return opt;
}
-static enum libxl_gfx_passthru_kind
-libxl__detect_gfx_passthru_kind(libxl__gc *gc,
- const libxl_domain_config *guest_config)
-{
- const libxl_domain_build_info *b_info = &guest_config->b_info;
-
- if (b_info->u.hvm.gfx_passthru_kind != LIBXL_GFX_PASSTHRU_KIND_DEFAULT)
- return b_info->u.hvm.gfx_passthru_kind;
-
- if (libxl__is_igd_vga_passthru(gc, guest_config)) {
- return LIBXL_GFX_PASSTHRU_KIND_IGD;
- }
-
- return LIBXL_GFX_PASSTHRU_KIND_DEFAULT;
-}
-
/* colo mode */
enum {
LIBXL__COLO_NONE = 0,
@@ -1832,9 +1816,7 @@ static int libxl__build_device_model_args_new(libxl__gc *gc,
}
if (libxl_defbool_val(b_info->u.hvm.gfx_passthru)) {
- enum libxl_gfx_passthru_kind gfx_passthru_kind =
- libxl__detect_gfx_passthru_kind(gc, guest_config);
- switch (gfx_passthru_kind) {
+ switch (b_info->u.hvm.gfx_passthru_kind) {
case LIBXL_GFX_PASSTHRU_KIND_IGD:
machinearg = GCSPRINTF("%s,igd-passthru=on", machinearg);
break;
--
2.44.0