Skip to contentSkip to conversation

scripts/runqemu: when qemu fails to start with kvm retry with kvm disabled

PATCH In review Joshua Lock 3 participants 3 messages Nov 3, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scripts/runqemu: when qemu fails to start with kvm retry with kvm disabled

On the Yocto Project Autobuilder we occasionally see qemu fail to start, most frequently on Fedora 25, because kvm fails to allocate memory. See:

https://bugzilla.yoctoproject.org/show_bug.cgi?id=12058

This patch introduces a fallback path where if the inital qemu command fails and kvm is enabled we retry running qemu with the kvm related options removed from the qemu command line.

---
 scripts/runqemu | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
scripts/runqemu +19 -1
index df762709043..b7f8b3c4d55 100755
@@ -1168,7 +1168,25 @@ class BaseConfig(object):
         logger.info('Running %s\n' % cmd)
         process = subprocess.Popen(cmd, shell=True, stderr=subprocess.PIPE)
         if process.wait():
-            logger.error("Failed to run qemu: %s", process.stderr.read().decode())
+            # If starting qemu failed and kvm is enabled we try again, with the
+            # kvm related options removed. This is because we have observed
+            # failures where kvm is unable to allocate memory (particularly on
+            # Fedora 25) but where a run withou kvm may be successful.
+            if self.kvm_enabled:
+                logger.info("Failed to run qemu: %s\nRetrying without kvm...",
+                            process.stderr.read().decode())
+                nokvm_cmd = cmd
+                nokvm_cmd = nokvm_cmd.replace(' -enable-kvm', '')
+                nokvm_cmd = nokvm_cmd.replace(',vhost=on', '')
+                logger.info('Running %s\n' % nokvm_cmd)
+                process = subprocess.Popen(nokvm_cmd, shell=True,
+                                           stderr=subprocess.PIPE)
+                if process.wait():
+                    logger.error("Failed to run qemu (with kvm disabled): %s",
+                                 process.stderr.read().decode())
+            else:
+                logger.error("Failed to run qemu: %s",
+                             process.stderr.read().decode())
 
     def cleanup(self):
         if self.cleantap:
Signature · 1 line
2.13.6
#1 lore raw

Joshua,

Quoted 8 lines · Joshua Lock

On the Yocto Project Autobuilder we occasionally see qemu fail to start, most frequently on Fedora 25, because kvm fails to allocate memory. See:

https://bugzilla.yoctoproject.org/show_bug.cgi?id=12058

This patch introduces a fallback path where if the inital qemu command fails and kvm is enabled we retry running qemu with the kvm related options removed from the qemu command line.

I will backport once this lands in master.
thanks,
 - armin

Quoted 36 lines
---
 scripts/runqemu | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
scripts/runqemu +19 -1
index df762709043..b7f8b3c4d55 100755
@@ -1168,7 +1168,25 @@ class BaseConfig(object):
         logger.info('Running %s\n' % cmd)
         process = subprocess.Popen(cmd, shell=True, stderr=subprocess.PIPE)
         if process.wait():
-            logger.error("Failed to run qemu: %s", process.stderr.read().decode())
+            # If starting qemu failed and kvm is enabled we try again, with the
+            # kvm related options removed. This is because we have observed
+            # failures where kvm is unable to allocate memory (particularly on
+            # Fedora 25) but where a run withou kvm may be successful.
+            if self.kvm_enabled:
+                logger.info("Failed to run qemu: %s\nRetrying without kvm...",
+                            process.stderr.read().decode())
+                nokvm_cmd = cmd
+                nokvm_cmd = nokvm_cmd.replace(' -enable-kvm', '')
+                nokvm_cmd = nokvm_cmd.replace(',vhost=on', '')
+                logger.info('Running %s\n' % nokvm_cmd)
+                process = subprocess.Popen(nokvm_cmd, shell=True,
+                                           stderr=subprocess.PIPE)
+                if process.wait():
+                    logger.error("Failed to run qemu (with kvm disabled): %s",
+                                 process.stderr.read().decode())
+            else:
+                logger.error("Failed to run qemu: %s",
+                             process.stderr.read().decode())
 
     def cleanup(self):
         if self.cleantap:
#2 lore raw
Quoted 7 lines · On 03/11/17 15:18, akuster808 wrote:

Joshua,

Quoted 3 lines · Joshua Lock

On the Yocto Project Autobuilder we occasionally see qemu fail to start, most frequently on Fedora 25, because kvm fails to allocate memory. See:

Quoted 8 lines
Quoted 5 lines

https://bugzilla.yoctoproject.org/show_bug.cgi?id=12058

This patch introduces a fallback path where if the inital qemu command fails and kvm is enabled we retry running qemu with the kvm related options removed from the qemu command line.

I will backport once this lands in master.
thanks,

I don't think it will make it. It complicates the code for a relatively rare edge case.

To avoid this on Yocto Autobuilder we're going to drop Fedora 25 from the clusters.

Joshua