Skip to contentSkip to conversation

Fix runqemu startup failure

PATCH New Chen Qi 1 participant 3 messages Aug 18, 2017

lore
Share & tools
lore

Chen Qi

author
#0 lore raw

cover Fix runqemu startup failure

The following changes since commit 55bf88603927469de9aa9f6fd4d449230d2e61e3:

poky: Add nios2 to list of qemu targets (2017-08-17 00:21:35 +0100)

are available in the git repository at:

git://git.pokylinux.org/poky-contrib ChenQi/runqemu_boot_error
http://git.pokylinux.org/cgit.cgi/poky-contrib/log/?h=ChenQi/runqemu_boot_error

Chen Qi (2):
qemu: backport patches to fix boot failure qemu conf: replace deprecated option with new option

 meta/conf/machine/include/qemuboot-mips.inc        |   2 +-
 meta/conf/machine/include/qemuboot-x86.inc         |   2 +-
 meta/conf/machine/qemuarm.conf                     |   2 +-
 meta/conf/machine/qemuppc.conf                     |   2 +-
 ...0001-osdep-Add-runtime-OFD-lock-detection.patch | 141 +++++++++++++++++++++
 ...e-posix-Do-runtime-check-for-ofd-lock-API.patch |  71 +++++++++++
 meta/recipes-devtools/qemu/qemu_2.10.0-rc2.bb      |   2 +
 7 files changed, 218 insertions(+), 4 deletions(-)
 create mode 100644 meta/recipes-devtools/qemu/qemu/0001-osdep-Add-runtime-OFD-lock-detection.patch
 create mode 100644 meta/recipes-devtools/qemu/qemu/0002-file-posix-Do-runtime-check-for-ofd-lock-API.patch
Signature · 1 line
1.9.1
author
#1 lore raw

PATCH 1/2 qemu: backport patches to fix boot failure

Backport two patches to fix the following error when booting qemu.

Failed to unlock byte 100

---
 ...0001-osdep-Add-runtime-OFD-lock-detection.patch | 141 +++++++++++++++++++++
 ...e-posix-Do-runtime-check-for-ofd-lock-API.patch |  71 +++++++++++
 meta/recipes-devtools/qemu/qemu_2.10.0-rc2.bb      |   2 +
 3 files changed, 214 insertions(+)
 create mode 100644 meta/recipes-devtools/qemu/qemu/0001-osdep-Add-runtime-OFD-lock-detection.patch
 create mode 100644 meta/recipes-devtools/qemu/qemu/0002-file-posix-Do-runtime-check-for-ofd-lock-API.patch
meta/recipes-devtools/qemu/qemu/0001-osdep-Add-runtime-OFD-lock-detection.patch new file +141 -0
new file mode 100644
index 0000000..f83f0d2
@@ -0,0 +1,141 @@
+From ca749954b09b89e22cd69c4949fb7e689b057963 Mon Sep 17 00:00:00 2001
+From: Fam Zheng <[email protected]>
+Date: Fri, 11 Aug 2017 19:44:46 +0800
+Subject: [PATCH 1/2] osdep: Add runtime OFD lock detection
+
+Build time check of OFD lock is not sufficient and can cause image open
+errors when the runtime environment doesn't support it.
+
+Add a helper function to probe it at runtime, additionally. Also provide
+a qemu_has_ofd_lock() for callers to check the status.
+
+Signed-off-by: Fam Zheng <[email protected]>
+Signed-off-by: Kevin Wolf <[email protected]>
+
+Upstream-Status: Backport
+Signed-off-by: Chen Qi <[email protected]>
+---
+ include/qemu/osdep.h |  1 +
+ util/osdep.c         | 66 ++++++++++++++++++++++++++++++++++++++++++++--------
+ 2 files changed, 57 insertions(+), 10 deletions(-)
+
+diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
+index 3b74f6fcb2..6855b94bbf 100644
+--- a/include/qemu/osdep.h
++++ b/include/qemu/osdep.h
+@@ -357,6 +357,7 @@ int qemu_dup(int fd);
+ int qemu_lock_fd(int fd, int64_t start, int64_t len, bool exclusive);
+ int qemu_unlock_fd(int fd, int64_t start, int64_t len);
+ int qemu_lock_fd_test(int fd, int64_t start, int64_t len, bool exclusive);
++bool qemu_has_ofd_lock(void);
+ 
+ #if defined(__HAIKU__) && defined(__i386__)
+ #define FMT_pid "%ld"
+diff --git a/util/osdep.c b/util/osdep.c
+index a2863c8e53..a479fedc4a 100644
+--- a/util/osdep.c
++++ b/util/osdep.c
+@@ -38,14 +38,6 @@ extern int madvise(caddr_t, size_t, int);
+ #include "qemu/error-report.h"
+ #include "monitor/monitor.h"
+ 
+-#ifdef F_OFD_SETLK
+-#define QEMU_SETLK F_OFD_SETLK
+-#define QEMU_GETLK F_OFD_GETLK
+-#else
+-#define QEMU_SETLK F_SETLK
+-#define QEMU_GETLK F_GETLK
+-#endif
+-
+ static bool fips_enabled = false;
+ 
+ static const char *hw_version = QEMU_HW_VERSION;
+@@ -82,6 +74,10 @@ int qemu_madvise(void *addr, size_t len, int advice)
+ }
+ 
+ #ifndef _WIN32
++
++static int fcntl_op_setlk = -1;
++static int fcntl_op_getlk = -1;
++
+ /*
+  * Dups an fd and sets the flags
+  */
+@@ -149,6 +145,54 @@ static int qemu_parse_fdset(const char *param)
+     return qemu_parse_fd(param);
+ }
+ 
++static void qemu_probe_lock_ops(void)
++{
++    if (fcntl_op_setlk == -1) {
++#ifdef F_OFD_SETLK
++        int fd;
++        int ret;
++        struct flock fl = {
++            .l_whence = SEEK_SET,
++            .l_start  = 0,
++            .l_len    = 0,
++            .l_type   = F_WRLCK,
++        };
++
++        fd = open("/dev/null", O_RDWR);
++        if (fd < 0) {
++            fprintf(stderr,
++                    "Failed to open /dev/null for OFD lock probing: %s\n",
++                    strerror(errno));
++            fcntl_op_setlk = F_SETLK;
++            fcntl_op_getlk = F_GETLK;
++            return;
++        }
++        ret = fcntl(fd, F_OFD_GETLK, &fl);
++        close(fd);
++        if (!ret) {
++            fcntl_op_setlk = F_OFD_SETLK;
++            fcntl_op_getlk = F_OFD_GETLK;
++        } else {
++            fcntl_op_setlk = F_SETLK;
++            fcntl_op_getlk = F_GETLK;
++        }
++#else
++        fcntl_op_setlk = F_SETLK;
++        fcntl_op_getlk = F_GETLK;
++#endif
++    }
++}
++
++bool qemu_has_ofd_lock(void)
++{
++    qemu_probe_lock_ops();
++#ifdef F_OFD_SETLK
++    return fcntl_op_setlk == F_OFD_SETLK;
++#else
++    return false;
++#endif
++}
++
+ static int qemu_lock_fcntl(int fd, int64_t start, int64_t len, int fl_type)
+ {
+     int ret;
+@@ -158,7 +202,8 @@ static int qemu_lock_fcntl(int fd, int64_t start, int64_t len, int fl_type)
+         .l_len    = len,
+         .l_type   = fl_type,
+     };
+-    ret = fcntl(fd, QEMU_SETLK, &fl);
++    qemu_probe_lock_ops();
++    ret = fcntl(fd, fcntl_op_setlk, &fl);
+     return ret == -1 ? -errno : 0;
+ }
+ 
+@@ -181,7 +226,8 @@ int qemu_lock_fd_test(int fd, int64_t start, int64_t len, bool exclusive)
+         .l_len    = len,
+         .l_type   = exclusive ? F_WRLCK : F_RDLCK,
+     };
+-    ret = fcntl(fd, QEMU_GETLK, &fl);
++    qemu_probe_lock_ops();
++    ret = fcntl(fd, fcntl_op_getlk, &fl);
+     if (ret == -1) {
+         return -errno;
+     } else {
+-- 
+2.11.0
+
meta/recipes-devtools/qemu/qemu/0002-file-posix-Do-runtime-check-for-ofd-lock-API.patch new file +71 -0

71 lines not on this page · raw message

meta/recipes-devtools/qemu/qemu_2.10.0-rc2.bb +2 -0
index 04d656b..08eaf19 100644
@@ -24,6 +24,8 @@ SRC_URI = "http://wiki.qemu-project.org/download/${BP}.tar.bz2 \
            file://0003-Introduce-condition-in-TPM-backend-for-notification.patch \
            file://0004-Add-support-for-VM-suspend-resume-for-TPM-TIS-v2.9.patch \
            file://apic-fixup-fallthrough-to-PIC.patch \
+           file://0001-osdep-Add-runtime-OFD-lock-detection.patch \
+           file://0002-file-posix-Do-runtime-check-for-ofd-lock-API.patch \
            "
 
 SRC_URI_append_class-native = " \
Signature · 1 line
1.9.1
author
#2 lore raw

PATCH 2/2 qemu conf: replace deprecated option with new option

In reply to Chen Qi

Replace the deprecated '-usbdevice' option with '-device usb-xx' option. This would fix runqemu boot error like below.

'-usbdevice' is deprecated, please use '-device usb-...' instead

---
 meta/conf/machine/include/qemuboot-mips.inc | 2 +-
 meta/conf/machine/include/qemuboot-x86.inc  | 2 +-
 meta/conf/machine/qemuarm.conf              | 2 +-
 meta/conf/machine/qemuppc.conf              | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)
meta/conf/machine/include/qemuboot-mips.inc +1 -1
index 0c60cf2..7d9fa52 100644
@@ -4,5 +4,5 @@ QB_MEM = "-m 256"
 QB_MACHINE = "-machine malta"
 QB_KERNEL_CMDLINE_APPEND = "console=ttyS0 console=tty"
 # Add the 'virtio-rng-pci' device otherwise the guest may run out of entropy
-QB_OPT_APPEND = "-vga cirrus -show-cursor -usb -usbdevice tablet -device virtio-rng-pci"
+QB_OPT_APPEND = "-vga cirrus -show-cursor -usb -device usb-tablet -device virtio-rng-pci"
 QB_SYSTEM_NAME = "qemu-system-${TUNE_ARCH}"
meta/conf/machine/include/qemuboot-x86.inc +1 -1
index acf9d55..0596e2e 100644
@@ -12,7 +12,7 @@ QB_AUDIO_DRV = "alsa"
 QB_AUDIO_OPT = "-soundhw ac97,es1370"
 QB_KERNEL_CMDLINE_APPEND = "vga=0 uvesafb.mode_option=${UVESA_MODE} oprofile.timer=1 uvesafb.task_timeout=-1"
 # Add the 'virtio-rng-pci' device otherwise the guest may run out of entropy
-QB_OPT_APPEND = "-vga vmware -show-cursor -usb -usbdevice tablet -device virtio-rng-pci"
+QB_OPT_APPEND = "-vga vmware -show-cursor -usb -device usb-tablet -device virtio-rng-pci"
 
 KERNEL_MODULE_AUTOLOAD += "uvesafb"
 KERNEL_MODULE_PROBECONF += "uvesafb"
meta/conf/machine/qemuarm.conf +1 -1
index 6b875e4..1f0a65f 100644
@@ -15,6 +15,6 @@ QB_SYSTEM_NAME = "qemu-system-arm"
 QB_MACHINE = "-machine versatilepb"
 QB_KERNEL_CMDLINE_APPEND = "console=ttyAMA0,115200 console=tty"
 # Add the 'virtio-rng-pci' device otherwise the guest may run out of entropy
-QB_OPT_APPEND = "-show-cursor -usb -usbdevice tablet -device virtio-rng-pci"
+QB_OPT_APPEND = "-show-cursor -usb -device usb-tablet -device virtio-rng-pci"
 PREFERRED_VERSION_linux-yocto ??= "4.10%"
 QB_DTB = "${@base_version_less_or_equal('PREFERRED_VERSION_linux-yocto', '4.7', '', 'zImage-versatile-pb.dtb', d)}"
meta/conf/machine/qemuppc.conf +1 -1
index a9ef64b..537b2f6 100644
@@ -17,5 +17,5 @@ QB_MACHINE = "-machine mac99"
 QB_CPU = "-cpu G4"
 QB_KERNEL_CMDLINE_APPEND = "console=tty console=ttyS0"
 # Add the 'virtio-rng-pci' device otherwise the guest may run out of entropy
-QB_OPT_APPEND = "-show-cursor -usb -usbdevice tablet -device virtio-rng-pci"
+QB_OPT_APPEND = "-show-cursor -usb -device usb-tablet -device virtio-rng-pci"
 QB_TAP_OPT = "-netdev tap,id=net0,ifname=@TAP@,script=no,downscript=no"
Signature · 1 line
1.9.1