[libvirt] PATCH: recent qemu-kvm requires -enable-kvm flag to activate VT optimization

Hello, Recent qemu releases require command option '-enable-qemu' in order for the kvm functionality be activated. Libvirt needs to pass this flag to qemu when starting a domain. Note that without the option, even if both the kernel and qemu support KVM, KVM will not be activated and VMs will be slow as molasses ;) I added a check in qemu_conf.c to see if `qemu -help` emits the -enable-kvm flag, and if so, use the flag accordingly. There exists a check in src/qemu/qemu_conf.c to check for the -no-kvm flag. This check works the same way. Adding the included code will not break systems where qemu does not have the option. See 'qemu -help': ... -enable-kvm enable KVM full virtualization support ... included patch against src/qemu/qemu_conf.{c,h} -Steve diff -ur libvirt/src/qemu/qemu_conf.c libvirt-qemu-enable-kvm/src/qemu/qemu_conf.c --- libvirt/src/qemu/qemu_conf.c 2009-11-08 20:57:08.438908134 -0800 +++ libvirt-qemu-enable-kvm/src/qemu/qemu_conf.c 2009-11-08 22:36:04.299921427 -0800 @@ -1602,6 +1602,7 @@ struct utsname ut; int disableKQEMU = 0; int disableKVM = 0; + int enableKVM = 0; int qargc = 0, qarga = 0; const char **qargv = NULL; int qenvc = 0, qenva = 0; @@ -1660,6 +1661,15 @@ def->virtType == VIR_DOMAIN_VIRT_QEMU) disableKVM = 1; + /* Should explicitly enable KVM if + * 1. Guest domain is 'qemu' + * 2. The qemu binary has the -enable-kvm flag + * NOTE: user must be responsible to load the kvm modules + */ + if ((qemuCmdFlags & QEMUD_CMD_FLAG_ENABLE_KVM) && + def->virtType == VIR_DOMAIN_VIRT_QEMU) + enableKVM = 1; + /* * Need to force a 32-bit guest CPU type if * @@ -1787,6 +1797,8 @@ ADD_ARG_LIT("-no-kqemu"); if (disableKVM) ADD_ARG_LIT("-no-kvm"); + if (enableKVM) + ADD_ARG_LIT("-enable-kvm"); ADD_ARG_LIT("-m"); ADD_ARG_LIT(memory); if (def->hugepage_backed) { diff -ur libvirt/src/qemu/qemu_conf.h libvirt-qemu-enable-kvm/src/qemu/qemu_conf.h --- libvirt/src/qemu/qemu_conf.h 2009-11-08 20:57:08.438908134 -0800 +++ libvirt-qemu-enable-kvm/src/qemu/qemu_conf.h 2009-11-08 14:57:39.000000000 -0800 @@ -73,6 +73,7 @@ QEMUD_CMD_FLAG_XEN_DOMID = (1 << 20), /* -xen-domid (new style xen integration) */ QEMUD_CMD_FLAG_MIGRATE_QEMU_UNIX = (1 << 21), /* Does qemu support unix domain sockets for migration? */ QEMUD_CMD_FLAG_CHARDEV = (1 << 22), /* Is the new -chardev arg available */ + QEMUD_CMD_FLAG_ENABLE_KVM = (1 << 23), /* Is the -enable-kvm flag available to "enable KVM full virtualization support" */ }; /* Main driver state */

On Sun, Nov 15, 2009 at 07:03:51PM -0800, Steve Yarmie wrote:
Hello,
Recent qemu releases require command option '-enable-qemu' in order for the kvm functionality be activated. Libvirt needs to pass this flag to qemu when starting a domain. Note that without the option, even if both the kernel and qemu support KVM, KVM will not be activated and VMs will be slow as molasses ;)
I added a check in qemu_conf.c to see if `qemu -help` emits the -enable-kvm flag, and if so, use the flag accordingly.
There exists a check in src/qemu/qemu_conf.c to check for the -no-kvm flag. This check works the same way.
Adding the included code will not break systems where qemu does not have the option.
See 'qemu -help': ... -enable-kvm enable KVM full virtualization support ...
included patch against src/qemu/qemu_conf.{c,h}
-Steve
diff -ur libvirt/src/qemu/qemu_conf.c libvirt-qemu-enable-kvm/src/qemu/qemu_conf.c --- libvirt/src/qemu/qemu_conf.c 2009-11-08 20:57:08.438908134 -0800 +++ libvirt-qemu-enable-kvm/src/qemu/qemu_conf.c 2009-11-08 22:36:04.299921427 -0800 @@ -1602,6 +1602,7 @@ struct utsname ut; int disableKQEMU = 0; int disableKVM = 0; + int enableKVM = 0; int qargc = 0, qarga = 0; const char **qargv = NULL; int qenvc = 0, qenva = 0; @@ -1660,6 +1661,15 @@ def->virtType == VIR_DOMAIN_VIRT_QEMU) disableKVM = 1;
+ /* Should explicitly enable KVM if + * 1. Guest domain is 'qemu' + * 2. The qemu binary has the -enable-kvm flag + * NOTE: user must be responsible to load the kvm modules + */ + if ((qemuCmdFlags & QEMUD_CMD_FLAG_ENABLE_KVM) && + def->virtType == VIR_DOMAIN_VIRT_QEMU) + enableKVM = 1; + /* * Need to force a 32-bit guest CPU type if * @@ -1787,6 +1797,8 @@ ADD_ARG_LIT("-no-kqemu"); if (disableKVM) ADD_ARG_LIT("-no-kvm"); + if (enableKVM) + ADD_ARG_LIT("-enable-kvm"); ADD_ARG_LIT("-m"); ADD_ARG_LIT(memory); if (def->hugepage_backed) { diff -ur libvirt/src/qemu/qemu_conf.h libvirt-qemu-enable-kvm/src/qemu/qemu_conf.h --- libvirt/src/qemu/qemu_conf.h 2009-11-08 20:57:08.438908134 -0800 +++ libvirt-qemu-enable-kvm/src/qemu/qemu_conf.h 2009-11-08 14:57:39.000000000 -0800 @@ -73,6 +73,7 @@ QEMUD_CMD_FLAG_XEN_DOMID = (1 << 20), /* -xen-domid (new style xen integration) */ QEMUD_CMD_FLAG_MIGRATE_QEMU_UNIX = (1 << 21), /* Does qemu support unix domain sockets for migration? */ QEMUD_CMD_FLAG_CHARDEV = (1 << 22), /* Is the new -chardev arg available */ + QEMUD_CMD_FLAG_ENABLE_KVM = (1 << 23), /* Is the -enable-kvm flag available to "enable KVM full virtualization support" */ };
/* Main driver state */
Patch seems incomplete as I don't see any detection code setting up QEMUD_CMD_FLAG_ENABLE_KVM in qemuCmdFlags Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/

Right - I left it out of the patch by mistake. New attachment has the needed test: + if (strstr(help, "-enable-kvm")) + flags |= QEMUD_CMD_FLAG_ENABLEKVM; -Steve Daniel Veillard wrote:
On Sun, Nov 15, 2009 at 07:03:51PM -0800, Steve Yarmie wrote:
Hello,
Recent qemu releases require command option '-enable-qemu' in order for the kvm functionality be activated. Libvirt needs to pass this flag to qemu when starting a domain. Note that without the option, even if both the kernel and qemu support KVM, KVM will not be activated and VMs will be slow as molasses ;)
I added a check in qemu_conf.c to see if `qemu -help` emits the -enable-kvm flag, and if so, use the flag accordingly.
There exists a check in src/qemu/qemu_conf.c to check for the -no-kvm flag. This check works the same way.
Adding the included code will not break systems where qemu does not have the option.
See 'qemu -help': ... -enable-kvm enable KVM full virtualization support ...
included patch against src/qemu/qemu_conf.{c,h}
-Steve
diff -ur libvirt/src/qemu/qemu_conf.c libvirt-qemu-enable-kvm/src/qemu/qemu_conf.c --- libvirt/src/qemu/qemu_conf.c 2009-11-08 20:57:08.438908134 -0800 +++ libvirt-qemu-enable-kvm/src/qemu/qemu_conf.c 2009-11-08 22:36:04.299921427 -0800 @@ -1602,6 +1602,7 @@ struct utsname ut; int disableKQEMU = 0; int disableKVM = 0; + int enableKVM = 0; int qargc = 0, qarga = 0; const char **qargv = NULL; int qenvc = 0, qenva = 0; @@ -1660,6 +1661,15 @@ def->virtType == VIR_DOMAIN_VIRT_QEMU) disableKVM = 1;
+ /* Should explicitly enable KVM if + * 1. Guest domain is 'qemu' + * 2. The qemu binary has the -enable-kvm flag + * NOTE: user must be responsible to load the kvm modules + */ + if ((qemuCmdFlags & QEMUD_CMD_FLAG_ENABLE_KVM) && + def->virtType == VIR_DOMAIN_VIRT_QEMU) + enableKVM = 1; + /* * Need to force a 32-bit guest CPU type if * @@ -1787,6 +1797,8 @@ ADD_ARG_LIT("-no-kqemu"); if (disableKVM) ADD_ARG_LIT("-no-kvm"); + if (enableKVM) + ADD_ARG_LIT("-enable-kvm"); ADD_ARG_LIT("-m"); ADD_ARG_LIT(memory); if (def->hugepage_backed) { diff -ur libvirt/src/qemu/qemu_conf.h libvirt-qemu-enable-kvm/src/qemu/qemu_conf.h --- libvirt/src/qemu/qemu_conf.h 2009-11-08 20:57:08.438908134 -0800 +++ libvirt-qemu-enable-kvm/src/qemu/qemu_conf.h 2009-11-08 14:57:39.000000000 -0800 @@ -73,6 +73,7 @@ QEMUD_CMD_FLAG_XEN_DOMID = (1 << 20), /* -xen-domid (new style xen integration) */ QEMUD_CMD_FLAG_MIGRATE_QEMU_UNIX = (1 << 21), /* Does qemu support unix domain sockets for migration? */ QEMUD_CMD_FLAG_CHARDEV = (1 << 22), /* Is the new -chardev arg available */ + QEMUD_CMD_FLAG_ENABLE_KVM = (1 << 23), /* Is the -enable-kvm flag available to "enable KVM full virtualization support" */ };
/* Main driver state */
Patch seems incomplete as I don't see any detection code setting up QEMUD_CMD_FLAG_ENABLE_KVM in qemuCmdFlags
Daniel
diff -upr libvirt/src/qemu/qemu_conf.c libvirt-enableKVM/src/qemu/qemu_conf.c --- libvirt/src/qemu/qemu_conf.c 2009-11-15 18:23:34.132206179 -0800 +++ libvirt-enableKVM/src/qemu/qemu_conf.c 2009-11-16 01:56:08.519182637 -0800 @@ -878,6 +878,8 @@ static unsigned int qemudComputeCmdFlags flags |= QEMUD_CMD_FLAG_KQEMU; if (strstr(help, "-no-kvm")) flags |= QEMUD_CMD_FLAG_KVM; + if (strstr(help, "-enable-kvm")) + flags |= QEMUD_CMD_FLAG_ENABLEKVM; if (strstr(help, "-no-reboot")) flags |= QEMUD_CMD_FLAG_NO_REBOOT; if (strstr(help, "-name")) @@ -1595,6 +1597,7 @@ int qemudBuildCommandLine(virConnectPtr struct utsname ut; int disableKQEMU = 0; int disableKVM = 0; + int enableKVM = 0; int qargc = 0, qarga = 0; const char **qargv = NULL; int qenvc = 0, qenva = 0; @@ -1653,6 +1656,15 @@ int qemudBuildCommandLine(virConnectPtr def->virtType == VIR_DOMAIN_VIRT_QEMU) disableKVM = 1; + /* Should explicitly enable KVM if + * 1. Guest domain is 'qemu' + * 2. The qemu binary has the -enable-kvm flag + * NOTE: user must be responsible to load the kvm modules + */ + if ((qemuCmdFlags & QEMUD_CMD_FLAG_ENABLE_KVM) && + def->virtType == VIR_DOMAIN_VIRT_QEMU) + enableKVM = 1; + /* * Need to force a 32-bit guest CPU type if * @@ -1780,6 +1792,8 @@ int qemudBuildCommandLine(virConnectPtr ADD_ARG_LIT("-no-kqemu"); if (disableKVM) ADD_ARG_LIT("-no-kvm"); + if (enableKVM) + ADD_ARG_LIT("-enable-kvm"); ADD_ARG_LIT("-m"); ADD_ARG_LIT(memory); if (def->hugepage_backed) { diff -upr libvirt/src/qemu/qemu_conf.h libvirt-enableKVM/src/qemu/qemu_conf.h --- libvirt/src/qemu/qemu_conf.h 2009-11-15 18:23:34.136206610 -0800 +++ libvirt-enableKVM/src/qemu/qemu_conf.h 2009-11-16 01:50:54.830156632 -0800 @@ -73,6 +73,7 @@ enum qemud_cmd_flags { QEMUD_CMD_FLAG_XEN_DOMID = (1 << 20), /* -xen-domid (new style xen integration) */ QEMUD_CMD_FLAG_MIGRATE_QEMU_UNIX = (1 << 21), /* Does qemu support unix domain sockets for migration? */ QEMUD_CMD_FLAG_CHARDEV = (1 << 22), /* Is the new -chardev arg available */ + QEMUD_CMD_FLAG_ENABLE_KVM = (1 << 23), /* Is the -enable-kvm flag available to "enable KVM full virtualization support" */ }; /* Main driver state */

d*mn! I missed the underscore - sorry - corrected in this attachment - ugh QEMUD_CMD_FLAG_ENABLE_KVM Steve Yarmie wrote:
Right - I left it out of the patch by mistake. New attachment has the needed test:
+ if (strstr(help, "-enable-kvm"))
+ flags |= QEMUD_CMD_FLAG_ENABLEKVM;
-Steve
Daniel Veillard wrote:
On Sun, Nov 15, 2009 at 07:03:51PM -0800, Steve Yarmie wrote:
Hello,
Recent qemu releases require command option '-enable-qemu' in order for the kvm functionality be activated. Libvirt needs to pass this flag to qemu when starting a domain. Note that without the option, even if both the kernel and qemu support KVM, KVM will not be activated and VMs will be slow as molasses ;)
I added a check in qemu_conf.c to see if `qemu -help` emits the -enable-kvm flag, and if so, use the flag accordingly.
There exists a check in src/qemu/qemu_conf.c to check for the -no-kvm flag. This check works the same way.
Adding the included code will not break systems where qemu does not have the option.
See 'qemu -help': ... -enable-kvm enable KVM full virtualization support ...
included patch against src/qemu/qemu_conf.{c,h}
-Steve
diff -ur libvirt/src/qemu/qemu_conf.c libvirt-qemu-enable-kvm/src/qemu/qemu_conf.c --- libvirt/src/qemu/qemu_conf.c 2009-11-08 20:57:08.438908134 -0800 +++ libvirt-qemu-enable-kvm/src/qemu/qemu_conf.c 2009-11-08 22:36:04.299921427 -0800 @@ -1602,6 +1602,7 @@ struct utsname ut; int disableKQEMU = 0; int disableKVM = 0; + int enableKVM = 0; int qargc = 0, qarga = 0; const char **qargv = NULL; int qenvc = 0, qenva = 0; @@ -1660,6 +1661,15 @@ def->virtType == VIR_DOMAIN_VIRT_QEMU) disableKVM = 1;
+ /* Should explicitly enable KVM if + * 1. Guest domain is 'qemu' + * 2. The qemu binary has the -enable-kvm flag + * NOTE: user must be responsible to load the kvm modules + */ + if ((qemuCmdFlags & QEMUD_CMD_FLAG_ENABLE_KVM) && + def->virtType == VIR_DOMAIN_VIRT_QEMU) + enableKVM = 1; + /* * Need to force a 32-bit guest CPU type if * @@ -1787,6 +1797,8 @@ ADD_ARG_LIT("-no-kqemu"); if (disableKVM) ADD_ARG_LIT("-no-kvm"); + if (enableKVM) + ADD_ARG_LIT("-enable-kvm"); ADD_ARG_LIT("-m"); ADD_ARG_LIT(memory); if (def->hugepage_backed) { diff -ur libvirt/src/qemu/qemu_conf.h libvirt-qemu-enable-kvm/src/qemu/qemu_conf.h --- libvirt/src/qemu/qemu_conf.h 2009-11-08 20:57:08.438908134 -0800 +++ libvirt-qemu-enable-kvm/src/qemu/qemu_conf.h 2009-11-08 14:57:39.000000000 -0800 @@ -73,6 +73,7 @@ QEMUD_CMD_FLAG_XEN_DOMID = (1 << 20), /* -xen-domid (new style xen integration) */ QEMUD_CMD_FLAG_MIGRATE_QEMU_UNIX = (1 << 21), /* Does qemu support unix domain sockets for migration? */ QEMUD_CMD_FLAG_CHARDEV = (1 << 22), /* Is the new -chardev arg available */ + QEMUD_CMD_FLAG_ENABLE_KVM = (1 << 23), /* Is the -enable-kvm flag available to "enable KVM full virtualization support" */ };
/* Main driver state */
Patch seems incomplete as I don't see any detection code setting up QEMUD_CMD_FLAG_ENABLE_KVM in qemuCmdFlags
Daniel
diff -upr libvirt/src/qemu/qemu_conf.c libvirt-enableKVM/src/qemu/qemu_conf.c --- libvirt/src/qemu/qemu_conf.c 2009-11-15 18:23:34.132206179 -0800 +++ libvirt-enableKVM/src/qemu/qemu_conf.c 2009-11-16 02:13:08.060515632 -0800 @@ -878,6 +878,8 @@ static unsigned int qemudComputeCmdFlags flags |= QEMUD_CMD_FLAG_KQEMU; if (strstr(help, "-no-kvm")) flags |= QEMUD_CMD_FLAG_KVM; + if (strstr(help, "-enable-kvm")) + flags |= QEMUD_CMD_FLAG_ENABLE_KVM; if (strstr(help, "-no-reboot")) flags |= QEMUD_CMD_FLAG_NO_REBOOT; if (strstr(help, "-name")) @@ -1595,6 +1597,7 @@ int qemudBuildCommandLine(virConnectPtr struct utsname ut; int disableKQEMU = 0; int disableKVM = 0; + int enableKVM = 0; int qargc = 0, qarga = 0; const char **qargv = NULL; int qenvc = 0, qenva = 0; @@ -1653,6 +1656,15 @@ int qemudBuildCommandLine(virConnectPtr def->virtType == VIR_DOMAIN_VIRT_QEMU) disableKVM = 1; + /* Should explicitly enable KVM if + * 1. Guest domain is 'qemu' + * 2. The qemu binary has the -enable-kvm flag + * NOTE: user must be responsible to load the kvm modules + */ + if ((qemuCmdFlags & QEMUD_CMD_FLAG_ENABLE_KVM) && + def->virtType == VIR_DOMAIN_VIRT_QEMU) + enableKVM = 1; + /* * Need to force a 32-bit guest CPU type if * @@ -1780,6 +1792,8 @@ int qemudBuildCommandLine(virConnectPtr ADD_ARG_LIT("-no-kqemu"); if (disableKVM) ADD_ARG_LIT("-no-kvm"); + if (enableKVM) + ADD_ARG_LIT("-enable-kvm"); ADD_ARG_LIT("-m"); ADD_ARG_LIT(memory); if (def->hugepage_backed) { diff -upr libvirt/src/qemu/qemu_conf.h libvirt-enableKVM/src/qemu/qemu_conf.h --- libvirt/src/qemu/qemu_conf.h 2009-11-15 18:23:34.136206610 -0800 +++ libvirt-enableKVM/src/qemu/qemu_conf.h 2009-11-16 01:50:54.830156632 -0800 @@ -73,6 +73,7 @@ enum qemud_cmd_flags { QEMUD_CMD_FLAG_XEN_DOMID = (1 << 20), /* -xen-domid (new style xen integration) */ QEMUD_CMD_FLAG_MIGRATE_QEMU_UNIX = (1 << 21), /* Does qemu support unix domain sockets for migration? */ QEMUD_CMD_FLAG_CHARDEV = (1 << 22), /* Is the new -chardev arg available */ + QEMUD_CMD_FLAG_ENABLE_KVM = (1 << 23), /* Is the -enable-kvm flag available to "enable KVM full virtualization support" */ }; /* Main driver state */

On Mon, Nov 16, 2009 at 02:15:28AM -0800, Steve Yarmie wrote:
diff -upr libvirt/src/qemu/qemu_conf.c libvirt-enableKVM/src/qemu/qemu_conf.c --- libvirt/src/qemu/qemu_conf.c 2009-11-15 18:23:34.132206179 -0800 +++ libvirt-enableKVM/src/qemu/qemu_conf.c 2009-11-16 02:13:08.060515632 -0800 @@ -878,6 +878,8 @@ static unsigned int qemudComputeCmdFlags flags |= QEMUD_CMD_FLAG_KQEMU; if (strstr(help, "-no-kvm")) flags |= QEMUD_CMD_FLAG_KVM; + if (strstr(help, "-enable-kvm")) + flags |= QEMUD_CMD_FLAG_ENABLE_KVM; if (strstr(help, "-no-reboot")) flags |= QEMUD_CMD_FLAG_NO_REBOOT; if (strstr(help, "-name")) @@ -1595,6 +1597,7 @@ int qemudBuildCommandLine(virConnectPtr struct utsname ut; int disableKQEMU = 0; int disableKVM = 0; + int enableKVM = 0; int qargc = 0, qarga = 0; const char **qargv = NULL; int qenvc = 0, qenva = 0; @@ -1653,6 +1656,15 @@ int qemudBuildCommandLine(virConnectPtr def->virtType == VIR_DOMAIN_VIRT_QEMU) disableKVM = 1;
+ /* Should explicitly enable KVM if + * 1. Guest domain is 'qemu'
Surely 'kvm' here
+ * 2. The qemu binary has the -enable-kvm flag + * NOTE: user must be responsible to load the kvm modules + */ + if ((qemuCmdFlags & QEMUD_CMD_FLAG_ENABLE_KVM) && + def->virtType == VIR_DOMAIN_VIRT_QEMU)
Again, this should be VIR_DOMAIN_VIRT_KVM here - 'qemu' is intended to be pure emulation only
+ enableKVM = 1; + /* * Need to force a 32-bit guest CPU type if * @@ -1780,6 +1792,8 @@ int qemudBuildCommandLine(virConnectPtr ADD_ARG_LIT("-no-kqemu"); if (disableKVM) ADD_ARG_LIT("-no-kvm"); + if (enableKVM) + ADD_ARG_LIT("-enable-kvm"); ADD_ARG_LIT("-m"); ADD_ARG_LIT(memory); if (def->hugepage_backed) {
Regards, Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

Thanks for pointing that out. I made the changes you suggested. An updated patch is attached. btw - I'm using qemu-kvm-0.11.0, but this patch would be relevant when running any version of qemu/qemu-kvm that was released after the upstream merge of the kvm userspace.. -Steve Daniel P. Berrange wrote:
On Mon, Nov 16, 2009 at 02:15:28AM -0800, Steve Yarmie wrote
+ /* Should explicitly enable KVM if + * 1. Guest domain is 'qemu' Surely 'kvm' here
+ * 2. The qemu binary has the -enable-kvm flag + * NOTE: user must be responsible to load the kvm modules + */ + if ((qemuCmdFlags & QEMUD_CMD_FLAG_ENABLE_KVM) && + def->virtType == VIR_DOMAIN_VIRT_QEMU)
Again, this should be VIR_DOMAIN_VIRT_KVM here - 'qemu' is intended to be pure emulation only
Regards, Daniel
diff -upr libvirt/src/qemu/qemu_conf.c libvirt-enableKVM/src/qemu/qemu_conf.c --- libvirt/src/qemu/qemu_conf.c 2009-11-17 05:37:23.973599362 -0800 +++ libvirt-enableKVM/src/qemu/qemu_conf.c 2009-11-17 05:41:40.755832169 -0800 @@ -878,6 +878,8 @@ static unsigned int qemudComputeCmdFlags flags |= QEMUD_CMD_FLAG_KQEMU; if (strstr(help, "-no-kvm")) flags |= QEMUD_CMD_FLAG_KVM; + if (strstr(help, "-enable-kvm")) + flags |= QEMUD_CMD_FLAG_ENABLE_KVM; if (strstr(help, "-no-reboot")) flags |= QEMUD_CMD_FLAG_NO_REBOOT; if (strstr(help, "-name")) @@ -1595,6 +1597,7 @@ int qemudBuildCommandLine(virConnectPtr struct utsname ut; int disableKQEMU = 0; int disableKVM = 0; + int enableKVM = 0; int qargc = 0, qarga = 0; const char **qargv = NULL; int qenvc = 0, qenva = 0; @@ -1653,6 +1656,15 @@ int qemudBuildCommandLine(virConnectPtr def->virtType == VIR_DOMAIN_VIRT_QEMU) disableKVM = 1; + /* Should explicitly enable KVM if + * 1. Guest domain is 'kvm' + * 2. The qemu binary has the -enable-kvm flag + * NOTE: user must be responsible for loading the kvm modules + */ + if ((qemuCmdFlags & QEMUD_CMD_FLAG_ENABLE_KVM) && + def->virtType == VIR_DOMAIN_VIRT_KVM) + enableKVM = 1; + /* * Need to force a 32-bit guest CPU type if * @@ -1780,6 +1792,8 @@ int qemudBuildCommandLine(virConnectPtr ADD_ARG_LIT("-no-kqemu"); if (disableKVM) ADD_ARG_LIT("-no-kvm"); + if (enableKVM) + ADD_ARG_LIT("-enable-kvm"); ADD_ARG_LIT("-m"); ADD_ARG_LIT(memory); if (def->hugepage_backed) { diff -upr libvirt/src/qemu/qemu_conf.h libvirt-enableKVM/src/qemu/qemu_conf.h --- libvirt/src/qemu/qemu_conf.h 2009-11-17 05:37:23.973599362 -0800 +++ libvirt-enableKVM/src/qemu/qemu_conf.h 2009-11-17 05:41:40.755832169 -0800 @@ -73,6 +73,7 @@ enum qemud_cmd_flags { QEMUD_CMD_FLAG_XEN_DOMID = (1 << 20), /* -xen-domid (new style xen integration) */ QEMUD_CMD_FLAG_MIGRATE_QEMU_UNIX = (1 << 21), /* Does qemu support unix domain sockets for migration? */ QEMUD_CMD_FLAG_CHARDEV = (1 << 22), /* Is the new -chardev arg available */ + QEMUD_CMD_FLAG_ENABLE_KVM = (1 << 23), /* Is the -enable-kvm flag available to "enable KVM full virtualization support" */ }; /* Main driver state */

On Tue, Nov 17, 2009 at 06:02:56AM -0800, Steve Yarmie wrote:
diff -upr libvirt/src/qemu/qemu_conf.c libvirt-enableKVM/src/qemu/qemu_conf.c --- libvirt/src/qemu/qemu_conf.c 2009-11-17 05:37:23.973599362 -0800 +++ libvirt-enableKVM/src/qemu/qemu_conf.c 2009-11-17 05:41:40.755832169 -0800 @@ -878,6 +878,8 @@ static unsigned int qemudComputeCmdFlags flags |= QEMUD_CMD_FLAG_KQEMU; if (strstr(help, "-no-kvm")) flags |= QEMUD_CMD_FLAG_KVM; + if (strstr(help, "-enable-kvm")) + flags |= QEMUD_CMD_FLAG_ENABLE_KVM; if (strstr(help, "-no-reboot")) flags |= QEMUD_CMD_FLAG_NO_REBOOT; if (strstr(help, "-name")) @@ -1595,6 +1597,7 @@ int qemudBuildCommandLine(virConnectPtr struct utsname ut; int disableKQEMU = 0; int disableKVM = 0; + int enableKVM = 0; int qargc = 0, qarga = 0; const char **qargv = NULL; int qenvc = 0, qenva = 0; @@ -1653,6 +1656,15 @@ int qemudBuildCommandLine(virConnectPtr def->virtType == VIR_DOMAIN_VIRT_QEMU) disableKVM = 1;
+ /* Should explicitly enable KVM if + * 1. Guest domain is 'kvm' + * 2. The qemu binary has the -enable-kvm flag + * NOTE: user must be responsible for loading the kvm modules + */ + if ((qemuCmdFlags & QEMUD_CMD_FLAG_ENABLE_KVM) && + def->virtType == VIR_DOMAIN_VIRT_KVM) + enableKVM = 1; + /* * Need to force a 32-bit guest CPU type if * @@ -1780,6 +1792,8 @@ int qemudBuildCommandLine(virConnectPtr ADD_ARG_LIT("-no-kqemu"); if (disableKVM) ADD_ARG_LIT("-no-kvm"); + if (enableKVM) + ADD_ARG_LIT("-enable-kvm"); ADD_ARG_LIT("-m"); ADD_ARG_LIT(memory); if (def->hugepage_backed) { diff -upr libvirt/src/qemu/qemu_conf.h libvirt-enableKVM/src/qemu/qemu_conf.h --- libvirt/src/qemu/qemu_conf.h 2009-11-17 05:37:23.973599362 -0800 +++ libvirt-enableKVM/src/qemu/qemu_conf.h 2009-11-17 05:41:40.755832169 -0800 @@ -73,6 +73,7 @@ enum qemud_cmd_flags { QEMUD_CMD_FLAG_XEN_DOMID = (1 << 20), /* -xen-domid (new style xen integration) */ QEMUD_CMD_FLAG_MIGRATE_QEMU_UNIX = (1 << 21), /* Does qemu support unix domain sockets for migration? */ QEMUD_CMD_FLAG_CHARDEV = (1 << 22), /* Is the new -chardev arg available */ + QEMUD_CMD_FLAG_ENABLE_KVM = (1 << 23), /* Is the -enable-kvm flag available to "enable KVM full virtualization support" */ };
/* Main driver state */
ACK, this looks good now Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

On Tue, Nov 17, 2009 at 06:02:56AM -0800, Steve Yarmie wrote:
Thanks for pointing that out. I made the changes you suggested. An updated patch is attached.
btw - I'm using qemu-kvm-0.11.0, but this patch would be relevant when running any version of qemu/qemu-kvm that was released after the upstream merge of the kvm userspace..
Okay looks fine, I applied it but I also had to modify tests/qemuhelptest.c since the computed flags for qemu-0.10.5 and qemu-kvm-0.11.0-rc2 have the new flag added and this was breaking make check, thanks ! Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/
participants (3)
-
Daniel P. Berrange
-
Daniel Veillard
-
Steve Yarmie