提交 c686f67f 编写于 作者: M Marek Marczykowski-Górecki 提交者: Jim Fehlig

libxl: do not enable nested HVM unless global nested_hvm option enabled

Introduce global libxl option for enabling nested HVM feature, similar
to kvm module parameter. This will prevent enabling experimental feature
by mere presence of <cpu mode='host-passthrough'> element in domain
config, unless explicitly enabled. <cpu mode='host-passthrough'> element
may be used to configure other features, like NUMA, or CPUID.
Signed-off-by: NMarek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
Reviewed-by: NDaniel P. Berrangé <berrange@redhat.com>
Reviewed-by: NJim Fehlig <jfehlig@suse.com>
上级 8c49e04e
...@@ -28,12 +28,14 @@ module Libvirtd_libxl = ...@@ -28,12 +28,14 @@ module Libvirtd_libxl =
let lock_entry = str_entry "lock_manager" let lock_entry = str_entry "lock_manager"
let keepalive_interval_entry = int_entry "keepalive_interval" let keepalive_interval_entry = int_entry "keepalive_interval"
let keepalive_count_entry = int_entry "keepalive_count" let keepalive_count_entry = int_entry "keepalive_count"
let nested_hvm_entry = bool_entry "nested_hvm"
(* Each entry in the config is one of the following ... *) (* Each entry in the config is one of the following ... *)
let entry = autoballoon_entry let entry = autoballoon_entry
| lock_entry | lock_entry
| keepalive_interval_entry | keepalive_interval_entry
| keepalive_count_entry | keepalive_count_entry
| nested_hvm_entry
let comment = [ label "#comment" . del /#[ \t]*/ "# " . store /([^ \t\n][^\n]*)?/ . del /\n/ "\n" ] let comment = [ label "#comment" . del /#[ \t]*/ "# " . store /([^ \t\n][^\n]*)?/ . del /\n/ "\n" ]
let empty = [ label "#empty" . eol ] let empty = [ label "#empty" . eol ]
......
...@@ -41,3 +41,11 @@ ...@@ -41,3 +41,11 @@
# #
#keepalive_interval = 5 #keepalive_interval = 5
#keepalive_count = 5 #keepalive_count = 5
# Nested HVM default control. In order to use nested HVM feature, this option
# needs to be enabled, in addition to specifying <cpu mode='host-passthrough'>
# in domain configuration. This can be overridden in domain configuration by
# explicitly setting <feature policy='require' name='vmx'/> inside <cpu/>
# element.
# By default it is disabled.
#nested_hvm = 0
...@@ -395,10 +395,12 @@ libxlMakeDomBuildInfo(virDomainDefPtr def, ...@@ -395,10 +395,12 @@ libxlMakeDomBuildInfo(virDomainDefPtr def,
bool hasHwVirt = false; bool hasHwVirt = false;
bool svm = false, vmx = false; bool svm = false, vmx = false;
/* enable nested HVM only if global nested_hvm option enable it and
* host support it*/
if (ARCH_IS_X86(def->os.arch)) { if (ARCH_IS_X86(def->os.arch)) {
vmx = virCPUCheckFeature(caps->host.arch, caps->host.cpu, "vmx"); vmx = virCPUCheckFeature(caps->host.arch, caps->host.cpu, "vmx");
svm = virCPUCheckFeature(caps->host.arch, caps->host.cpu, "svm"); svm = virCPUCheckFeature(caps->host.arch, caps->host.cpu, "svm");
hasHwVirt = vmx | svm; hasHwVirt = cfg->nested_hvm && (vmx | svm);
} }
if (def->cpu->nfeatures) { if (def->cpu->nfeatures) {
...@@ -415,6 +417,11 @@ libxlMakeDomBuildInfo(virDomainDefPtr def, ...@@ -415,6 +417,11 @@ libxlMakeDomBuildInfo(virDomainDefPtr def,
case VIR_CPU_FEATURE_FORCE: case VIR_CPU_FEATURE_FORCE:
case VIR_CPU_FEATURE_REQUIRE: case VIR_CPU_FEATURE_REQUIRE:
if ((vmx && STREQ(def->cpu->features[i].name, "vmx")) ||
(svm && STREQ(def->cpu->features[i].name, "svm")))
hasHwVirt = true;
break;
case VIR_CPU_FEATURE_OPTIONAL: case VIR_CPU_FEATURE_OPTIONAL:
case VIR_CPU_FEATURE_LAST: case VIR_CPU_FEATURE_LAST:
break; break;
...@@ -1758,6 +1765,9 @@ int libxlDriverConfigLoadFile(libxlDriverConfigPtr cfg, ...@@ -1758,6 +1765,9 @@ int libxlDriverConfigLoadFile(libxlDriverConfigPtr cfg,
if (virConfGetValueUInt(conf, "keepalive_count", &cfg->keepAliveCount) < 0) if (virConfGetValueUInt(conf, "keepalive_count", &cfg->keepAliveCount) < 0)
goto cleanup; goto cleanup;
if (virConfGetValueBool(conf, "nested_hvm", &cfg->nested_hvm) < 0)
goto cleanup;
ret = 0; ret = 0;
cleanup: cleanup:
......
...@@ -88,6 +88,8 @@ struct _libxlDriverConfig { ...@@ -88,6 +88,8 @@ struct _libxlDriverConfig {
int keepAliveInterval; int keepAliveInterval;
unsigned int keepAliveCount; unsigned int keepAliveCount;
bool nested_hvm;
/* Once created, caps are immutable */ /* Once created, caps are immutable */
virCapsPtr caps; virCapsPtr caps;
......
...@@ -6,3 +6,4 @@ module Test_libvirtd_libxl = ...@@ -6,3 +6,4 @@ module Test_libvirtd_libxl =
{ "lock_manager" = "lockd" } { "lock_manager" = "lockd" }
{ "keepalive_interval" = "5" } { "keepalive_interval" = "5" }
{ "keepalive_count" = "5" } { "keepalive_count" = "5" }
{ "nested_hvm" = "0" }
...@@ -76,6 +76,9 @@ testCompareXMLToDomConfig(const char *xmlfile, ...@@ -76,6 +76,9 @@ testCompareXMLToDomConfig(const char *xmlfile,
if (!(log = (xentoollog_logger *)xtl_createlogger_stdiostream(stderr, XTL_DEBUG, 0))) if (!(log = (xentoollog_logger *)xtl_createlogger_stdiostream(stderr, XTL_DEBUG, 0)))
goto cleanup; goto cleanup;
/* for testing nested HVM */
cfg->nested_hvm = true;
/* replace logger with stderr one */ /* replace logger with stderr one */
libxl_ctx_free(cfg->ctx); libxl_ctx_free(cfg->ctx);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册