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
165
166
167
168
<!--
libvirt VM XML snippet for GPU passthrough (KVM/QEMU + VFIO + OVMF)
Placeholders to replace:
- @DOMAIN_NAME@ : the VM's name
- @MEM_MB@ : memory in MiB (e.g. 16384)
- @VCPU@ : vCPU count (e.g. 8)
- @OVMF_CODE@/@OVMF_VARS@: paths to OVMF firmware for your distro
- GPU PCI addresses: domain/bus/slot/function (0x0000 / 0x01 / 0x00 / 0x0)
- AUDIO PCI address: usually bus same as GPU, function 0x1 (replace as needed)
- vendor_id value: a random 8-char hex string (avoid NVIDIA vendor detection)
Notes:
- Keep this snippet as a template. Always replace placeholders before using.
- Use `host-passthrough` CPU mode and hide kvm to reduce the chance of NVIDIA Error 43.
- Confirm IOMMU groups and ensure the GPU is isolated in its own group or groups that can be passed together.
- This XML is intended as an example; adapt to your environment and libvirt/QEMU version.
-->
@DOMAIN_NAME@
@MEM_MB@
@MEM_MB@
@VCPU@
<!-- Use host CPU attributes for maximum compatibility with GPU drivers -->
<!-- Optional: restrict topology if needed
<topology sockets='1' cores='@VCPU@' threads='1'/>
-->
<!-- Hide KVM presence from guest and set Hyper-V vendor id to avoid NVidia Error 43 -->
<!-- Replace the vendor_id value with a random 8-character hex string -->
<!-- Optional Hyper-V feature toggles (tune depending on guest OS) -->
<!-- Use OVMF (UEFI) firmware; replace paths with your system's OVMF code / vars images -->
hvm
@OVMF_CODE@
@OVMF_VARS@
<!-- Memory backing: hugepages can improve performance for LLM inference -->
<!-- Uncomment and adapt if you have hugepages configured on the host -->
<!--
<memoryBacking>
<hugepages>
<page size='2048' unit='KiB'/>
</hugepages>
<locked/>
</memoryBacking>
-->
destroy
restart
restart
<!-- Example disk: use virtio-blk or virtio-scsi for best perf -->
<!-- Network: default NAT network; replace or configure bridge if you need LAN access -->
<!-- Serial / Console -->
<!-- Input / Display -->
<!-- No emulated GPU is provided; if you need a virtual display add a simple cirrus or qxl device.
For headless inference VMs it's common to omit a paravirtual video device. -->
<!-- RNG device: improves entropy in guests -->
/dev/urandom
<!-- Memory ballooning disabled for predictable memory sizing in inference workloads -->
<!--
Hostdev entries for GPU passthrough.
IMPORTANT:
- Replace the address values with the exact domain/bus/slot/function from `lspci`.
- Include both the GPU PCI function (commonly .0) and the associated audio/function (.1).
- `managed='yes'` allows libvirt to unbind/bind drivers as needed.
- If your GPU spans multiple IOMMU groups you may need to pass all devices in those groups.
-->
<!-- NVIDIA GPU (VGA) -->
<!-- Optional: give the guest a friendly name for the device -->
<!-- NVIDIA GPU Audio (replace addresses accordingly) -->
<!-- Optional USB controller passthrough (useful for USB dongles / peripherals) -->
<!--
<hostdev mode='subsystem' type='pci' managed='yes'>
<source>
<address domain='0x0000' bus='0x00' slot='0x14' function='0x0'/>
</source>
</hostdev>
-->
<!-- If you require a virtual display for the guest (for testing), add a simple video device:
<video>
<model type='virtio' heads='1'/>
</video>
-->
<!-- QEMU commandline additions (namespace qemu) can be used for fine-grained tuning.
Example: expose host CPU features, or attach a nvram workaround.
Be cautious: incorrect qemu:commandline entries may break the domain. -->
<!-- Example: set a random vendor id (match hyperv vendor_id above) -->
<!--
<qemu:arg value='-cpu'/>
<qemu:arg value='host,policy=prefer'/>
-->
<!-- Example: set hugepage backing on a specific memory device (requires matching host config)
<qemu:arg value='-object'/>
<qemu:arg value='memory-backend-file,id=mem0,mem-path=/dev/hugepages,share=on,size=@MEM_MB@M'/>
<qemu:arg value='-numa'/>
<qemu:arg value='node,memdev=mem0'/>
-->