From: Michal Privoznik Date: Wed, 3 Nov 2021 12:15:41 +0000 (+0100) Subject: conf: Introduce TCG domain features X-Git-Tag: v8.0.0-rc1~246 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f106788069359f19e225647a4699ccd0d44838db;p=thirdparty%2Flibvirt.git conf: Introduce TCG domain features It may come handy to be able to tweak TCG options, in this specific case the size of translation block cache size (tb-size). Since we can expect more knobs to tweak let's put them under common element, like this: 128 Signed-off-by: Michal Privoznik Tested-by: Kashyap Chamarthy Reviewed-by: Peter Krempa --- diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst index eb8c973cf1..041dfc699d 100644 --- a/docs/formatdomain.rst +++ b/docs/formatdomain.rst @@ -1864,6 +1864,9 @@ Hypervisors may allow certain CPU / machine features to be toggled on/off. + + 128 + ... @@ -2065,6 +2068,14 @@ are: ``fixed-na (fixed in hardware - no longer applicable)``. If the attribute is not defined, the hypervisor default will be used. :since:`Since 6.3.0` (QEMU/KVM only) +``tcg`` + Various features to change the behavior of the TCG accelerator. + + =========== ============================================== =================================================== ============== + Feature Description Value Since + =========== ============================================== =================================================== ============== + tb-cache The size of translation block cache size an integer :since:`8.0.0` + =========== ============================================== =================================================== ============== :anchor:`` diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index f01b7a6470..ce51e95895 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -6092,7 +6092,7 @@ @@ -6232,6 +6232,9 @@ + + + @@ -6520,6 +6523,16 @@ + + + + + + + + + + diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index c634e7dd41..b6249aa76f 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -172,6 +172,7 @@ VIR_ENUM_IMPL(virDomainFeature, "cfpc", "sbbc", "ibs", + "tcg", ); VIR_ENUM_IMPL(virDomainCapabilitiesPolicy, @@ -3713,6 +3714,7 @@ void virDomainDefFree(virDomainDef *def) g_free(def->description); g_free(def->title); g_free(def->hyperv_vendor_id); + g_free(def->tcg_features); virBlkioDeviceArrayClear(def->blkio.devices, def->blkio.ndevices); @@ -17648,6 +17650,30 @@ virDomainFeaturesCapabilitiesDefParse(virDomainDef *def, } +static int +virDomainFeaturesTCGDefParse(virDomainDef *def, + xmlXPathContextPtr ctxt, + xmlNodePtr node) +{ + g_autofree virDomainFeatureTCG *tcg = NULL; + VIR_XPATH_NODE_AUTORESTORE(ctxt); + + tcg = g_new0(virDomainFeatureTCG, 1); + ctxt->node = node; + + if (virDomainParseMemory("./tb-cache", "./tb-cache/@unit", + ctxt, &tcg->tb_cache, false, false) < 0) + return -1; + + if (tcg->tb_cache == 0) + return 0; + + def->features[VIR_DOMAIN_FEATURE_TCG] = VIR_TRISTATE_SWITCH_ON; + def->tcg_features = g_steal_pointer(&tcg); + return 0; +} + + static int virDomainFeaturesDefParse(virDomainDef *def, xmlXPathContextPtr ctxt) @@ -17856,6 +17882,11 @@ virDomainFeaturesDefParse(virDomainDef *def, break; } + case VIR_DOMAIN_FEATURE_TCG: + if (virDomainFeaturesTCGDefParse(def, ctxt, nodes[i]) < 0) + return -1; + break; + case VIR_DOMAIN_FEATURE_LAST: break; } @@ -21656,8 +21687,7 @@ virDomainDefFeaturesCheckABIStability(virDomainDef *src, break; case VIR_DOMAIN_FEATURE_MSRS: - break; - + case VIR_DOMAIN_FEATURE_TCG: case VIR_DOMAIN_FEATURE_LAST: break; } @@ -27644,6 +27674,26 @@ virDomainDefFormatBlkiotune(virBuffer *buf, } +static void +virDomainFeatureTCGFormat(virBuffer *buf, + const virDomainDef *def) +{ + g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf); + + if (!def->tcg_features || + def->features[VIR_DOMAIN_FEATURE_TCG] != VIR_TRISTATE_SWITCH_ON) + return; + + if (def->tcg_features->tb_cache > 0) { + virBufferAsprintf(&childBuf, + "%lld\n", + def->tcg_features->tb_cache); + } + + virXMLFormatElement(buf, "tcg", NULL, &childBuf); +} + + static int virDomainDefFormatFeatures(virBuffer *buf, virDomainDef *def) @@ -27964,6 +28014,10 @@ virDomainDefFormatFeatures(virBuffer *buf, virDomainIBSTypeToString(def->features[i])); break; + case VIR_DOMAIN_FEATURE_TCG: + virDomainFeatureTCGFormat(&childBuf, def); + break; + case VIR_DOMAIN_FEATURE_LAST: break; } diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index c0c07ea6ba..b410922f68 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2054,6 +2054,7 @@ typedef enum { VIR_DOMAIN_FEATURE_CFPC, VIR_DOMAIN_FEATURE_SBBC, VIR_DOMAIN_FEATURE_IBS, + VIR_DOMAIN_FEATURE_TCG, VIR_DOMAIN_FEATURE_LAST } virDomainFeature; @@ -2262,6 +2263,11 @@ typedef enum { VIR_ENUM_DECL(virDomainIBS); +typedef struct _virDomainFeatureTCG virDomainFeatureTCG; +struct _virDomainFeatureTCG { + unsigned long long tb_cache; /* Stored in KiB */ +}; + /* Operating system configuration data & machine / arch */ struct _virDomainOSEnv { char *name; @@ -2824,6 +2830,7 @@ struct _virDomainDef { unsigned long long hpt_maxpagesize; /* Stored in KiB */ char *hyperv_vendor_id; virTristateSwitch apic_eoi; + virDomainFeatureTCG *tcg_features; bool tseg_specified; unsigned long long tseg_size; diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index 29b01495ad..2c9ccbd4fd 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -294,6 +294,7 @@ qemuValidateDomainDefFeatures(const virDomainDef *def, } break; + case VIR_DOMAIN_FEATURE_TCG: case VIR_DOMAIN_FEATURE_SMM: case VIR_DOMAIN_FEATURE_KVM: case VIR_DOMAIN_FEATURE_XEN: diff --git a/tests/qemuxml2argvdata/x86_64-default-cpu-tcg-features.xml b/tests/qemuxml2argvdata/x86_64-default-cpu-tcg-features.xml new file mode 100644 index 0000000000..808e31752c --- /dev/null +++ b/tests/qemuxml2argvdata/x86_64-default-cpu-tcg-features.xml @@ -0,0 +1,56 @@ + + guest + 1ccfd97d-5eb4-478a-bbe6-88d254c16db7 + 4194304 + 4194304 + 4 + + hvm + + + + + + + 102400 + + + + qemu64 + + + destroy + restart + destroy + + /usr/bin/qemu-system-x86_64 + +
+ + +
+ + + + + +
+ + + + +
+ + + + +
+ + + +