libxl_conf: Implement hyperv domain flags for Xen

Adds support for configuring <hyperv/> flags for domains
running under Xen.

The following flags, making use of QEMU's existing flags, are now
configurable for Xen: vapic, synic, stimer, frequencies, tlbflush and
ipi.

Tests have been added validating translation to libxl's viridian flags

Updated docs section on <hyperv/> flags to note support and to specify
which flags work with Xen.

Signed-off-by: Will <tcosprojects@gmail.com>
Reviewed-by: Jim Fehlig <jfehlig@suse.com>
This commit is contained in:
Will authored and Jim Fehlig committed 2025-04-03 15:47:52 -06:00
1 parent 312088d9b6
commit 410dfde9bb
9 files changed
+601 -11

No files matched your search

+13 -11
View File
@@ -2132,32 +2132,34 @@ are:
based virtualization drivers, such as LXC.
``hyperv``
Enable various features improving behavior of guests running Microsoft
Windows.
Windows. :since:`Since 11.3.0` some of these flags are also available for
Xen domains running Microsoft Windows.
=============== ====================================================================== ============================================ ========================================================================
Feature Description Value Since
=============== ====================================================================== ============================================ ========================================================================
relaxed Relax constraints on timers on, off :since:`1.0.0 (QEMU 2.0)`
vapic Enable virtual APIC on, off :since:`1.1.0 (QEMU 2.0)`
relaxed Relax constraints on timers on, off :since:`1.0.0 (QEMU 2.0), 11.3.0 (Xen, always on)`
vapic Enable virtual APIC on, off :since:`1.1.0 (QEMU 2.0), 11.3.0 (Xen)`
spinlocks Enable spinlock support on, off; retries - at least 4095 :since:`1.1.0 (QEMU 2.0)`
vpindex Virtual processor index on, off :since:`1.3.3 (QEMU 2.5)`
vpindex Virtual processor index on, off :since:`1.3.3 (QEMU 2.5), 11.3.0 (Xen, always on)`
runtime Processor time spent on running guest code and on behalf of guest code on, off :since:`1.3.3 (QEMU 2.5)`
synic Enable Synthetic Interrupt Controller (SynIC) on, off :since:`1.3.3 (QEMU 2.6)`
stimer Enable SynIC timers, optionally with Direct Mode support on, off; direct - on,off :since:`1.3.3 (QEMU 2.6), direct mode 5.7.0 (QEMU 4.1)`
synic Enable Synthetic Interrupt Controller (SynIC) on, off :since:`1.3.3 (QEMU 2.6), 11.3.0 (Xen)`
stimer Enable SynIC timers, optionally with Direct Mode support on, off; direct - on,off :since:`1.3.3 (QEMU 2.6), direct mode 5.7.0 (QEMU 4.1), 11.3.0 (Xen, on/off only)`
reset Enable hypervisor reset on, off :since:`1.3.3 (QEMU 2.5)`
vendor_id Set hypervisor vendor id on, off; value - string, up to 12 characters :since:`1.3.3 (QEMU 2.5)`
frequencies Expose frequency MSRs on, off :since:`4.7.0 (QEMU 2.12)`
frequencies Expose frequency MSRs on, off :since:`4.7.0 (QEMU 2.12), 11.3.0 (Xen)`
reenlightenment Enable re-enlightenment notification on migration on, off :since:`4.7.0 (QEMU 3.0)`
tlbflush Enable PV TLB flush support on, off; direct - on,off; extended - on,off :since:`4.7.0 (QEMU 3.0), direct and extended modes 11.0.0 (QEMU 7.1.0)`
ipi Enable PV IPI support on, off :since:`4.10.0 (QEMU 3.1)`
tlbflush Enable PV TLB flush support on, off; direct - on,off; extended - on,off :since:`4.7.0 (QEMU 3.0), direct and extended modes 11.0.0 (QEMU 7.1.0), 11.3.0 (Xen, on/off only)`
ipi Enable PV IPI support on, off :since:`4.10.0 (QEMU 3.1), 11.3.0 (Xen)`
evmcs Enable Enlightened VMCS on, off :since:`4.10.0 (QEMU 3.1)`
avic Enable use Hyper-V SynIC with hardware APICv/AVIC on, off :since:`8.10.0 (QEMU 6.2)`
emsr_bitmap Avoid unnecessary updates to L2 MSR Bitmap upon vmexits. on, off :since:`10.7.0 (QEMU 7.1)`
xmm_input Enable XMM Fast Hypercall Input on, off :since:`10.7.0 (QEMU 7.1)`
=============== ====================================================================== ============================================ ========================================================================
:since:`Since 8.0.0`, the hypervisor can be configured further by setting
the ``mode`` attribute to one of the following values:
:since:`Since 8.0.0 (QEMU) Since 11.3.0 (Xen)`, the hypervisor can be
configured further by setting the ``mode`` attribute to one of the following
values:
``custom``
Set exactly the specified features.
+101
View File
@@ -582,6 +582,107 @@ libxlMakeDomBuildInfo(virDomainDef *def,
VIR_TRISTATE_SWITCH_ON);
#endif
#ifdef LIBXL_HAVE_BUILDINFO_HVM_VIRIDIAN_ENABLE_DISABLE
if (def->features[VIR_DOMAIN_FEATURE_HYPERV] != VIR_DOMAIN_HYPERV_MODE_NONE) {
libxl_bitmap_alloc(ctx, &b_info->u.hvm.viridian_enable,
LIBXL_BUILDINFO_HVM_VIRIDIAN_ENABLE_DISABLE_WIDTH);
switch ((virDomainHyperVMode) def->features[VIR_DOMAIN_FEATURE_HYPERV]) {
case VIR_DOMAIN_HYPERV_MODE_CUSTOM:
/* Base is required by Xen to enable any other flag */
libxl_bitmap_set(&b_info->u.hvm.viridian_enable,
LIBXL_VIRIDIAN_ENLIGHTENMENT_BASE);
/* Enable crash ctl register by default to allow guest logs to reach Xen */
libxl_bitmap_set(&b_info->u.hvm.viridian_enable,
LIBXL_VIRIDIAN_ENLIGHTENMENT_CRASH_CTL);
break;
case VIR_DOMAIN_HYPERV_MODE_PASSTHROUGH:
libxl_bitmap_set_any(&b_info->u.hvm.viridian_enable);
break;
case VIR_DOMAIN_HYPERV_MODE_NONE:
case VIR_DOMAIN_HYPERV_MODE_LAST:
default:
virReportEnumRangeError(virDomainHyperVMode,
def->features[VIR_DOMAIN_FEATURE_HYPERV]);
return -1;
}
for (i = 0; i < VIR_DOMAIN_HYPERV_LAST; i++) {
switch ((virDomainHyperv) i) {
case VIR_DOMAIN_HYPERV_VPINDEX:
case VIR_DOMAIN_HYPERV_RELAXED:
/* Already set by base flag */
break;
case VIR_DOMAIN_HYPERV_SYNIC:
if (def->hyperv_features[i] == VIR_TRISTATE_SWITCH_ON) {
libxl_bitmap_set(&b_info->u.hvm.viridian_enable,
LIBXL_VIRIDIAN_ENLIGHTENMENT_SYNIC);
}
break;
case VIR_DOMAIN_HYPERV_STIMER:
if (def->hyperv_features[i] == VIR_TRISTATE_SWITCH_ON) {
/* STIMER implies synic and clock features */
libxl_bitmap_set(&b_info->u.hvm.viridian_enable,
LIBXL_VIRIDIAN_ENLIGHTENMENT_STIMER);
libxl_bitmap_set(&b_info->u.hvm.viridian_enable,
LIBXL_VIRIDIAN_ENLIGHTENMENT_SYNIC);
libxl_bitmap_set(&b_info->u.hvm.viridian_enable,
LIBXL_VIRIDIAN_ENLIGHTENMENT_TIME_REF_COUNT);
libxl_bitmap_set(&b_info->u.hvm.viridian_enable,
LIBXL_VIRIDIAN_ENLIGHTENMENT_REFERENCE_TSC);
}
break;
case VIR_DOMAIN_HYPERV_VAPIC:
if (def->hyperv_features[i] == VIR_TRISTATE_SWITCH_ON) {
libxl_bitmap_set(&b_info->u.hvm.viridian_enable,
LIBXL_VIRIDIAN_ENLIGHTENMENT_APIC_ASSIST);
}
break;
case VIR_DOMAIN_HYPERV_FREQUENCIES:
if (def->hyperv_features[i] == VIR_TRISTATE_SWITCH_ON) {
libxl_bitmap_set(&b_info->u.hvm.viridian_enable,
LIBXL_VIRIDIAN_ENLIGHTENMENT_FREQ);
}
break;
case VIR_DOMAIN_HYPERV_TLBFLUSH:
if (def->hyperv_features[i] == VIR_TRISTATE_SWITCH_ON) {
libxl_bitmap_set(&b_info->u.hvm.viridian_enable,
LIBXL_VIRIDIAN_ENLIGHTENMENT_HCALL_REMOTE_TLB_FLUSH);
}
break;
case VIR_DOMAIN_HYPERV_IPI:
if (def->hyperv_features[i] == VIR_TRISTATE_SWITCH_ON) {
libxl_bitmap_set(&b_info->u.hvm.viridian_enable,
LIBXL_VIRIDIAN_ENLIGHTENMENT_HCALL_IPI);
}
break;
case VIR_DOMAIN_HYPERV_SPINLOCKS:
case VIR_DOMAIN_HYPERV_VENDOR_ID:
if (def->hyperv_features[i] == VIR_TRISTATE_SWITCH_ON) {
const char *name = virDomainHypervTypeToString(i);
VIR_WARN("Hyper-v flag '%s' specified per-domain but is a global Xen setting and will be ignored.", name);
}
break;
case VIR_DOMAIN_HYPERV_RUNTIME:
case VIR_DOMAIN_HYPERV_RESET:
case VIR_DOMAIN_HYPERV_REENLIGHTENMENT:
case VIR_DOMAIN_HYPERV_EVMCS:
case VIR_DOMAIN_HYPERV_AVIC:
case VIR_DOMAIN_HYPERV_EMSR_BITMAP:
case VIR_DOMAIN_HYPERV_XMM_INPUT:
if (def->hyperv_features[i] == VIR_TRISTATE_SWITCH_ON) {
const char *name = virDomainHypervTypeToString(i);
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Hyper-v enlightenment feature '%1$s' is not supported for Xen domains."), name);
}
break;
case VIR_DOMAIN_HYPERV_LAST:
break;
}
}
}
#endif
/* copy the table path to acpi_firmware */
if (def->os.nacpiTables)
b_info->u.hvm.acpi_firmware = g_strdup(def->os.acpiTables[0]->path);
@@ -0,0 +1,101 @@
{
"c_info": {
"type": "hvm",
"name": "test-hvm",
"uuid": "2147d599-9cc6-c0dc-92ab-4064b5446e9b"
},
"b_info": {
"max_vcpus": 4,
"avail_vcpus": [
0,
1,
2,
3
],
"max_memkb": 1048576,
"target_memkb": 1048576,
"video_memkb": 8192,
"shadow_memkb": 1234,
"device_model_version": "qemu_xen",
"device_model": "/bin/true",
"sched_params": {
},
"apic": "True",
"acpi": "True",
"type.hvm": {
"pae": "True",
"viridian_enable": [
0,
1,
2,
3,
4,
5,
6,
7,
8,
9
],
"vga": {
"kind": "cirrus"
},
"vnc": {
"enable": "True",
"listen": "0.0.0.0",
"findunused": "False"
},
"sdl": {
"enable": "False"
},
"spice": {
},
"boot": "c",
"rdm": {
}
},
"arch_arm": {
}
},
"disks": [
{
"pdev_path": "/var/lib/xen/images/test-hvm.img",
"vdev": "hda",
"backend": "qdisk",
"format": "raw",
"removable": 1,
"readwrite": 1
}
],
"nics": [
{
"devid": 0,
"mac": "00:16:3e:66:12:b4",
"bridge": "br0",
"script": "/etc/xen/scripts/vif-bridge",
"nictype": "vif_ioemu"
}
],
"vfbs": [
{
"devid": -1,
"vnc": {
"enable": "True",
"listen": "0.0.0.0",
"findunused": "False"
},
"sdl": {
"enable": "False"
}
}
],
"vkbs": [
{
"devid": -1
}
],
"on_reboot": "restart"
}
@@ -0,0 +1,45 @@
<domain type='xen'>
<name>test-hvm</name>
<description>None</description>
<uuid>2147d599-9cc6-c0dc-92ab-4064b5446e9b</uuid>
<memory>1048576</memory>
<currentMemory>1048576</currentMemory>
<vcpu>4</vcpu>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<clock offset='utc'/>
<os>
<type>hvm</type>
<loader>/usr/lib/xen/boot/hvmloader</loader>
<boot dev='hd'/>
</os>
<features>
<apic/>
<acpi/>
<pae/>
<hyperv>
<vapic state='on'/>
<vpindex state='on'/>
<synic state='on'/>
<stimer state='on'/>
<frequencies state='on'/>
<tlbflush state='on'/>
<ipi state='on'/>
</hyperv>
</features>
<devices>
<emulator>/bin/true</emulator>
<disk type='file' device='disk'>
<driver name='qemu'/>
<source file='/var/lib/xen/images/test-hvm.img'/>
<target dev='hda'/>
</disk>
<interface type='bridge'>
<source bridge='br0'/>
<mac address='00:16:3e:66:12:b4'/>
<script path='/etc/xen/scripts/vif-bridge'/>
</interface>
<graphics type='vnc' port='-1' autoport='yes' listen='0.0.0.0'/>
</devices>
</domain>
@@ -0,0 +1,99 @@
{
"c_info": {
"type": "hvm",
"name": "test-hvm",
"uuid": "2147d599-9cc6-c0dc-92ab-4064b5446e9b"
},
"b_info": {
"max_vcpus": 4,
"avail_vcpus": [
0,
1,
2,
3
],
"max_memkb": 1048576,
"target_memkb": 1048576,
"video_memkb": 8192,
"shadow_memkb": 1234,
"device_model_version": "qemu_xen",
"device_model": "/bin/true",
"sched_params": {
},
"apic": "True",
"acpi": "True",
"type.hvm": {
"pae": "True",
"viridian_enable": [
0,
2,
3,
4,
6,
7,
8,
9
],
"vga": {
"kind": "cirrus"
},
"vnc": {
"enable": "True",
"listen": "0.0.0.0",
"findunused": "False"
},
"sdl": {
"enable": "False"
},
"spice": {
},
"boot": "c",
"rdm": {
}
},
"arch_arm": {
}
},
"disks": [
{
"pdev_path": "/var/lib/xen/images/test-hvm.img",
"vdev": "hda",
"backend": "qdisk",
"format": "raw",
"removable": 1,
"readwrite": 1
}
],
"nics": [
{
"devid": 0,
"mac": "00:16:3e:66:12:b4",
"bridge": "br0",
"script": "/etc/xen/scripts/vif-bridge",
"nictype": "vif_ioemu"
}
],
"vfbs": [
{
"devid": -1,
"vnc": {
"enable": "True",
"listen": "0.0.0.0",
"findunused": "False"
},
"sdl": {
"enable": "False"
}
}
],
"vkbs": [
{
"devid": -1
}
],
"on_reboot": "restart"
}
@@ -0,0 +1,42 @@
<domain type='xen'>
<name>test-hvm</name>
<description>None</description>
<uuid>2147d599-9cc6-c0dc-92ab-4064b5446e9b</uuid>
<memory>1048576</memory>
<currentMemory>1048576</currentMemory>
<vcpu>4</vcpu>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<clock offset='utc'/>
<os>
<type>hvm</type>
<loader>/usr/lib/xen/boot/hvmloader</loader>
<boot dev='hd'/>
</os>
<features>
<apic/>
<acpi/>
<pae/>
<hyperv mode="custom">
<synic state='on'/>
<stimer state='on'/>
<tlbflush state='on'/>
<ipi state='on'/>
</hyperv>
</features>
<devices>
<emulator>/bin/true</emulator>
<disk type='file' device='disk'>
<driver name='qemu'/>
<source file='/var/lib/xen/images/test-hvm.img'/>
<target dev='hda'/>
</disk>
<interface type='bridge'>
<source bridge='br0'/>
<mac address='00:16:3e:66:12:b4'/>
<script path='/etc/xen/scripts/vif-bridge'/>
</interface>
<graphics type='vnc' port='-1' autoport='yes' listen='0.0.0.0'/>
</devices>
</domain>
@@ -0,0 +1,155 @@
{
"c_info": {
"type": "hvm",
"name": "test-hvm",
"uuid": "2147d599-9cc6-c0dc-92ab-4064b5446e9b"
},
"b_info": {
"max_vcpus": 4,
"avail_vcpus": [
0,
1,
2,
3
],
"max_memkb": 1048576,
"target_memkb": 1048576,
"video_memkb": 8192,
"shadow_memkb": 1234,
"device_model_version": "qemu_xen",
"device_model": "/bin/true",
"sched_params": {
},
"apic": "True",
"acpi": "True",
"type.hvm": {
"pae": "True",
"viridian_enable": [
0,
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
],
"vga": {
"kind": "cirrus"
},
"vnc": {
"enable": "True",
"listen": "0.0.0.0",
"findunused": "False"
},
"sdl": {
"enable": "False"
},
"spice": {
},
"boot": "c",
"rdm": {
}
},
"arch_arm": {
}
},
"disks": [
{
"pdev_path": "/var/lib/xen/images/test-hvm.img",
"vdev": "hda",
"backend": "qdisk",
"format": "raw",
"removable": 1,
"readwrite": 1
}
],
"nics": [
{
"devid": 0,
"mac": "00:16:3e:66:12:b4",
"bridge": "br0",
"script": "/etc/xen/scripts/vif-bridge",
"nictype": "vif_ioemu"
}
],
"vfbs": [
{
"devid": -1,
"vnc": {
"enable": "True",
"listen": "0.0.0.0",
"findunused": "False"
},
"sdl": {
"enable": "False"
}
}
],
"vkbs": [
{
"devid": -1
}
],
"on_reboot": "restart"
}
@@ -0,0 +1,37 @@
<domain type='xen'>
<name>test-hvm</name>
<description>None</description>
<uuid>2147d599-9cc6-c0dc-92ab-4064b5446e9b</uuid>
<memory>1048576</memory>
<currentMemory>1048576</currentMemory>
<vcpu>4</vcpu>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<clock offset='utc'/>
<os>
<type>hvm</type>
<loader>/usr/lib/xen/boot/hvmloader</loader>
<boot dev='hd'/>
</os>
<features>
<apic/>
<acpi/>
<pae/>
<hyperv mode="passthrough"/>
</features>
<devices>
<emulator>/bin/true</emulator>
<disk type='file' device='disk'>
<driver name='qemu'/>
<source file='/var/lib/xen/images/test-hvm.img'/>
<target dev='hda'/>
</disk>
<interface type='bridge'>
<source bridge='br0'/>
<mac address='00:16:3e:66:12:b4'/>
<script path='/etc/xen/scripts/vif-bridge'/>
</interface>
<graphics type='vnc' port='-1' autoport='yes' listen='0.0.0.0'/>
</devices>
</domain>
+8
View File
@@ -211,6 +211,14 @@ mymain(void)
DO_TEST("single-serial");
DO_TEST("multiple-serial");
# ifdef LIBXL_HAVE_BUILDINFO_HVM_VIRIDIAN_ENABLE_DISABLE
DO_TEST("viridian-hvm");
DO_TEST("viridian-hvm-full");
# if LIBXL_BUILDINFO_HVM_VIRIDIAN_ENABLE_DISABLE_WIDTH == 64
DO_TEST("viridian-passthrough");
# endif
# endif
unlink("libxl-driver.log");
testXLFreeDriver(driver);