Skip to contentSkip to conversation

Misc vhost-user fixes

PATCH In review Marc-André Lureau 5 participants 15 messages Jun 5, 2019 – Jun 26, 2019

lore
Share & tools
lore
#0 lore raw

cover Misc vhost-user fixes

Hi,

Here is a few fixes spotted by Coverity in the recently landed vhost-user-{input,gpu}.

Marc-André Lureau (5):
vhost-user-gpu: do not send scanout update if no GPU socket
vhost-user: check unix_listen() return value
vhost-user: improve error report
vhost-user-input: check ioctl(EVIOCGNAME) return value
vhost-user-gpu: initialize msghdr & iov at declaration

 contrib/vhost-user-gpu/main.c   | 29 ++++++++++++++---------------
 contrib/vhost-user-input/main.c | 12 ++++++++++--
 2 files changed, 24 insertions(+), 17 deletions(-)
Signature · 1 line
2.22.0.rc2.384.g1a9a72ea1d
#1 lore raw

PATCH 1/5 vhost-user-gpu: do not send scanout update if no GPU socket

Should fix coverity CID 1401760.

---
 contrib/vhost-user-gpu/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
contrib/vhost-user-gpu/main.c +1 -1
index f9e2146b69..9614c9422c 100644
@@ -354,7 +354,7 @@ vg_disable_scanout(VuGpu *g, int scanout_id)
     scanout->width = 0;
     scanout->height = 0;
 
-    {
+    if (g->sock_fd >= 0) {
         VhostUserGpuMsg msg = {
             .request = VHOST_USER_GPU_SCANOUT,
             .size = sizeof(VhostUserGpuScanout),
Signature · 1 line
2.22.0.rc2.384.g1a9a72ea1d
#2 lore raw

PATCH 2/5 vhost-user: check unix_listen() return value

In reply to Marc-André Lureau

This check shouldn't be necessary, since &error_fatal is given as argument and will exit() on failure. However, this change should silence coverity CID 1401761 & 1401705.

---
 contrib/vhost-user-gpu/main.c   | 4 ++++
 contrib/vhost-user-input/main.c | 4 ++++
 2 files changed, 8 insertions(+)
contrib/vhost-user-gpu/main.c +4 -0
index 9614c9422c..e0b6df5b4d 100644
@@ -1160,6 +1160,10 @@ main(int argc, char *argv[])
 
     if (opt_socket_path) {
         int lsock = unix_listen(opt_socket_path, &error_fatal);
+        if (lsock < 0) {
+            g_printerr("Failed to listen on %s.\n", opt_socket_path);
+            exit(EXIT_FAILURE);
+        }
         fd = accept(lsock, NULL, NULL);
         close(lsock);
     } else {
contrib/vhost-user-input/main.c +4 -0
index 8d493f598e..8b854117f5 100644
@@ -367,6 +367,10 @@ main(int argc, char *argv[])
 
     if (opt_socket_path) {
         int lsock = unix_listen(opt_socket_path, &error_fatal);
+        if (lsock < 0) {
+            g_printerr("Failed to listen on %s.\n", opt_socket_path);
+            exit(EXIT_FAILURE);
+        }
         fd = accept(lsock, NULL, NULL);
         close(lsock);
     } else {
Signature · 1 line
2.22.0.rc2.384.g1a9a72ea1d
#3 lore raw

Re: [Qemu-devel] [PATCH 2/5] vhost-user: check unix_listen() return value

Quoted 42 lines · Marc-André Lureau

This check shouldn't be necessary, since &error_fatal is given as argument and will exit() on failure. However, this change should silence coverity CID 1401761 & 1401705.

---
 contrib/vhost-user-gpu/main.c   | 4 ++++
 contrib/vhost-user-input/main.c | 4 ++++
 2 files changed, 8 insertions(+)
contrib/vhost-user-gpu/main.c +4 -0
index 9614c9422c..e0b6df5b4d 100644
@@ -1160,6 +1160,10 @@ main(int argc, char *argv[])
 
     if (opt_socket_path) {
         int lsock = unix_listen(opt_socket_path, &error_fatal);
+        if (lsock < 0) {
+            g_printerr("Failed to listen on %s.\n", opt_socket_path);
+            exit(EXIT_FAILURE);
+        }
         fd = accept(lsock, NULL, NULL);
         close(lsock);
     } else {
contrib/vhost-user-input/main.c +4 -1
index 8d493f598e..8b854117f5 100644
@@ -367,6 +367,10 @@ main(int argc, char *argv[])
 
     if (opt_socket_path) {
         int lsock = unix_listen(opt_socket_path, &error_fatal);
+        if (lsock < 0) {
+            g_printerr("Failed to listen on %s.\n", opt_socket_path);
+            exit(EXIT_FAILURE);
+        }
         fd = accept(lsock, NULL, NULL);
         close(lsock);
     } else {
--
Quoted 2 lines

2.22.0.rc2.384.g1a9a72ea1d

Maybe better to just assert(lsock >= 0) ?
(I hadn't noticed the &error_fatal -- it means this new code is unreachable.)

thanks
-- PMM

#4 lore raw

Re: [Qemu-devel] [PULL 02/11] vhost-user: check unix_listen() return value

In reply to Marc-André Lureau
Quoted 20 lines · Michael S. Tsirkin

From: Marc-André Lureau <[email protected]>

This check shouldn't be necessary, since &error_fatal is given as argument and will exit() on failure. However, this change should silence coverity CID 1401761 & 1401705.

Message-Id: <[email protected]>

---
 contrib/vhost-user-gpu/main.c   | 4 ++++
 contrib/vhost-user-input/main.c | 4 ++++
 2 files changed, 8 insertions(+)
contrib/vhost-user-gpu/main.c +0 -0
index 9614c9422c..e0b6df5b4d 100644

contrib/vhost-user-gpu/main.c main(int argc, char *argv[]) · line 1166

Quoted 7 lines
contrib/vhost-user-gpu/main.c +4 -0
@@ -1160,6 +1160,10 @@ main(int argc, char *argv[])
 
     if (opt_socket_path) {
         int lsock = unix_listen(opt_socket_path, &error_fatal);
+        if (lsock < 0) {
+            g_printerr("Failed to listen on %s.\n", opt_socket_path);
+            exit(EXIT_FAILURE);
+        }

4 lines to appease Coverity; wouldn't the following one-liner also do the trick?

int lsock = unix_listen(opt_socket_path, &error_fatal); assert (lsock >= 0);

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
#5 lore raw

Re: [Qemu-devel] [PULL 02/11] vhost-user: check unix_listen() return value

Hi

Quoted 33 lines · Eric Blake
Quoted 20 lines · Michael S. Tsirkin

From: Marc-André Lureau <[email protected]>

This check shouldn't be necessary, since &error_fatal is given as argument and will exit() on failure. However, this change should silence coverity CID 1401761 & 1401705.

Message-Id: <[email protected]>

---
 contrib/vhost-user-gpu/main.c   | 4 ++++
 contrib/vhost-user-input/main.c | 4 ++++
 2 files changed, 8 insertions(+)
contrib/vhost-user-gpu/main.c +0 -0
index 9614c9422c..e0b6df5b4d 100644

contrib/vhost-user-gpu/main.c main(int argc, char *argv[]) · line 1166

Quoted 7 lines
contrib/vhost-user-gpu/main.c +4 -0
@@ -1160,6 +1160,10 @@ main(int argc, char *argv[])
 
     if (opt_socket_path) {
         int lsock = unix_listen(opt_socket_path, &error_fatal);
+        if (lsock < 0) {
+            g_printerr("Failed to listen on %s.\n", opt_socket_path);
+            exit(EXIT_FAILURE);
+        }

4 lines to appease Coverity; wouldn't the following one-liner also do the trick?

Quoted 2 lines

int lsock = unix_listen(opt_socket_path, &error_fatal); assert (lsock >= 0);

Probably, I didn't think too much about it. However looking at it now, it would be worthwhile to report the error to the user in a friendlier way than what error_fatal do. So I guess a follow-up patch should introduce a local Error.

Quoted 6 lines

--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization: qemu.org | libvirt.org

Signature · 1 line
Marc-André Lureau
#6 lore raw

PATCH 3/5 vhost-user: improve error report

In reply to Marc-André Lureau

g_printerr() needs a trailing \n

---
 contrib/vhost-user-gpu/main.c   | 2 +-
 contrib/vhost-user-input/main.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
contrib/vhost-user-gpu/main.c +1 -1
index e0b6df5b4d..0ef649ffaa 100644
@@ -1170,7 +1170,7 @@ main(int argc, char *argv[])
         fd = opt_fdnum;
     }
     if (fd == -1) {
-        g_printerr("Invalid socket");
+        g_printerr("Invalid vhost-user socket.\n");
         exit(EXIT_FAILURE);
     }
 
contrib/vhost-user-input/main.c +1 -1
index 8b854117f5..54f882602a 100644
@@ -377,7 +377,7 @@ main(int argc, char *argv[])
         fd = opt_fdnum;
     }
     if (fd == -1) {
-        g_printerr("Invalid socket");
+        g_printerr("Invalid vhost-user socket.\n");
         exit(EXIT_FAILURE);
     }
     vug_init(&vi.dev, fd, vi_panic, &vuiface);
Signature · 1 line
2.22.0.rc2.384.g1a9a72ea1d
#7 lore raw

PATCH 4/5 vhost-user-input: check ioctl(EVIOCGNAME) return value

In reply to Marc-André Lureau

This should fix coverity CID 1401704.

---
 contrib/vhost-user-input/main.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
contrib/vhost-user-input/main.c +5 -1
index 54f882602a..8b4e7d2536 100644
@@ -342,7 +342,11 @@ main(int argc, char *argv[])
 
     vi.config = g_array_new(false, false, sizeof(virtio_input_config));
     memset(&id, 0, sizeof(id));
-    ioctl(vi.evdevfd, EVIOCGNAME(sizeof(id.u.string) - 1), id.u.string);
+    if (ioctl(vi.evdevfd, EVIOCGNAME(sizeof(id.u.string) - 1),
+              id.u.string) < 0) {
+        g_printerr("Failed to get evdev name: %s\n", g_strerror(errno));
+        exit(EXIT_FAILURE);
+    }
     id.select = VIRTIO_INPUT_CFG_ID_NAME;
     id.size = strlen(id.u.string);
     g_array_append_val(vi.config, id);
Signature · 1 line
2.22.0.rc2.384.g1a9a72ea1d
Reviewed-by on v1 4/5
#8 lore raw

Re: [Qemu-devel] [PATCH 4/5] vhost-user-input: check ioctl(EVIOCGNAME) return value

Quoted 13 lines · Marc-André Lureau

This should fix coverity CID 1401704.

---
 contrib/vhost-user-input/main.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
contrib/vhost-user-input/main.c +0 -0
index 54f882602a..8b4e7d2536 100644

contrib/vhost-user-input/main.c main(int argc, char *argv[]) · line 349

Quoted 9 lines
contrib/vhost-user-input/main.c +5 -1
@@ -342,7 +342,11 @@ main(int argc, char *argv[])
 
     vi.config = g_array_new(false, false, sizeof(virtio_input_config));
     memset(&id, 0, sizeof(id));
-    ioctl(vi.evdevfd, EVIOCGNAME(sizeof(id.u.string) - 1), id.u.string);
+    if (ioctl(vi.evdevfd, EVIOCGNAME(sizeof(id.u.string) - 1),
+              id.u.string) < 0) {
+        g_printerr("Failed to get evdev name: %s\n", g_strerror(errno));
+        exit(EXIT_FAILURE);
+    }

thanks
-- PMM

#9 lore raw

PATCH 5/5 vhost-user-gpu: initialize msghdr & iov at declaration

In reply to Marc-André Lureau

This should fix uninitialized fields found by coverity CID 1401762.

---
 contrib/vhost-user-gpu/main.c | 21 ++++++++-------------
 1 file changed, 8 insertions(+), 13 deletions(-)
contrib/vhost-user-gpu/main.c +8 -13
index 0ef649ffaa..04b753046f 100644
@@ -138,22 +138,20 @@ static int
 vg_sock_fd_write(int sock, const void *buf, ssize_t buflen, int fd)
 {
     ssize_t ret;
-    struct msghdr msg;
-    struct iovec iov;
+    struct iovec iov = {
+        .iov_base = (void *)buf,
+        .iov_len = buflen,
+    };
+    struct msghdr msg = {
+        .msg_iov = &iov,
+        .msg_iovlen = 1,
+    };
     union {
         struct cmsghdr cmsghdr;
         char control[CMSG_SPACE(sizeof(int))];
     } cmsgu;
     struct cmsghdr *cmsg;
 
-    iov.iov_base = (void *)buf;
-    iov.iov_len = buflen;
-
-    msg.msg_name = NULL;
-    msg.msg_namelen = 0;
-    msg.msg_iov = &iov;
-    msg.msg_iovlen = 1;
-
     if (fd != -1) {
         msg.msg_control = cmsgu.control;
         msg.msg_controllen = sizeof(cmsgu.control);
@@ -164,9 +162,6 @@ vg_sock_fd_write(int sock, const void *buf, ssize_t buflen, int fd)
         cmsg->cmsg_type = SCM_RIGHTS;
 
         *((int *)CMSG_DATA(cmsg)) = fd;
-    } else {
-        msg.msg_control = NULL;
-        msg.msg_controllen = 0;
     }
 
     do {
Signature · 1 line
2.22.0.rc2.384.g1a9a72ea1d
Reviewed-by on v1 5/5
#10 lore raw

Re: [Qemu-devel] [PATCH 5/5] vhost-user-gpu: initialize msghdr & iov at declaration

Quoted 8 lines · Marc-André Lureau

This should fix uninitialized fields found by coverity CID 1401762.

---
 contrib/vhost-user-gpu/main.c | 21 ++++++++-------------
 1 file changed, 8 insertions(+), 13 deletions(-)

thanks
-- PMM

#11 lore raw

[Qemu-devel] [PULL 00/11] virtio, acpi: fixes, cleanups

The following changes since commit f3d0bec9f80e4ed7796fffa834ba0a53f2094f7f:

Merge remote-tracking branch 'remotes/maxreitz/tags/pull-block-2019-06-14' into staging (2019-06-14 14:46:13 +0100)

are available in the Git repository at:

git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git tags/for_upstream

for you to fetch changes up to 5f6b3561bf58395fd6c906d7064a1a5693a2e426:

tests/rebuild-expected-aml.sh: blow out difflist (2019-06-16 16:44:44 -0400)

----------------------------------------------------------------
virtio, acpi: fixes, cleanups

A bunch of minor fixes all over the place.

----------------------------------------------------------------
Gerd Hoffmann (1):
q35: fix mmconfig and PCI0._CRS

Li Hangjing (1):
vhost: fix vhost_log size overflow during migration

Marc-André Lureau (6):
vhost-user-gpu: do not send scanout update if no GPU socket
vhost-user: check unix_listen() return value
vhost-user: improve error report
vhost-user-input: check ioctl(EVIOCGNAME) return value
vhost-user-gpu: initialize msghdr & iov at declaration docs/vhost-user.json: some firmware.json copy leftovers

Michael S. Tsirkin (2):
q35: update DSDT tests/rebuild-expected-aml.sh: blow out difflist

Wei Yang (1):
hw/acpi: extract acpi_add_rom_blob()

 docs/interop/vhost-user.json            |   6 ++---
 include/hw/acpi/utils.h                 |   9 +++++++
 contrib/vhost-user-gpu/main.c           |  29 +++++++++++------------
 contrib/vhost-user-input/main.c         |  12 ++++++++--
 hw/acpi/utils.c                         |  35 ++++++++++++++++++++++++++++
 hw/arm/virt-acpi-build.c                |  26 ++++++++-------------
 hw/i386/acpi-build.c                    |  40 +++++++++++++++++++-------------
 hw/pci-host/q35.c                       |  31 +++++++------------------
 hw/virtio/vhost.c                       |  10 ++++++++
 hw/acpi/Makefile.objs                   |   2 +-
 tests/data/acpi/q35/DSDT                | Bin 7815 -> 7841 bytes
 tests/data/acpi/q35/DSDT.bridge         | Bin 7832 -> 7858 bytes
 tests/data/acpi/q35/DSDT.cphp           | Bin 8278 -> 8304 bytes
 tests/data/acpi/q35/DSDT.dimmpxm        | Bin 9468 -> 9494 bytes
 tests/data/acpi/q35/DSDT.ipmibt         | Bin 7890 -> 7916 bytes
 tests/data/acpi/q35/DSDT.memhp          | Bin 9174 -> 9200 bytes
 tests/data/acpi/q35/DSDT.mmio64         | Bin 8945 -> 8971 bytes
 tests/data/acpi/q35/DSDT.numamem        | Bin 7821 -> 7847 bytes
 tests/data/acpi/rebuild-expected-aml.sh |   3 +++
 19 files changed, 127 insertions(+), 76 deletions(-)
 create mode 100644 include/hw/acpi/utils.h
 create mode 100644 hw/acpi/utils.c
#12 lore raw

[Qemu-devel] [PULL 10/11] q35: update DSDT

update expected files and drop them from allowed diff list.

Fixes 4a4418369d6 ("q35: fix mmconfig and PCI0._CRS")
---
 tests/bios-tables-test-allowed-diff.h |   8 --------
 tests/data/acpi/q35/DSDT              | Bin 7815 -> 7841 bytes
 tests/data/acpi/q35/DSDT.bridge       | Bin 7832 -> 7858 bytes
 tests/data/acpi/q35/DSDT.cphp         | Bin 8278 -> 8304 bytes
 tests/data/acpi/q35/DSDT.dimmpxm      | Bin 9468 -> 9494 bytes
 tests/data/acpi/q35/DSDT.ipmibt       | Bin 7890 -> 7916 bytes
 tests/data/acpi/q35/DSDT.memhp        | Bin 9174 -> 9200 bytes
 tests/data/acpi/q35/DSDT.mmio64       | Bin 8945 -> 8971 bytes
 tests/data/acpi/q35/DSDT.numamem      | Bin 7821 -> 7847 bytes
 9 files changed, 8 deletions(-)
tests/bios-tables-test-allowed-diff.h +0 -8
index 3bbd22c62a..dfb8523c8b 100644
@@ -1,9 +1 @@
 /* List of comma-separated changed AML files to ignore */
-"tests/data/acpi/q35/DSDT",
-"tests/data/acpi/q35/DSDT.bridge",
-"tests/data/acpi/q35/DSDT.mmio64",
-"tests/data/acpi/q35/DSDT.ipmibt",
-"tests/data/acpi/q35/DSDT.cphp",
-"tests/data/acpi/q35/DSDT.memhp",
-"tests/data/acpi/q35/DSDT.numamem",
-"tests/data/acpi/q35/DSDT.dimmpxm",
tests/data/acpi/q35/DSDT binary +0 -0
index 7576ffcd05991ad5a3901c0f7698a52fffc6d6e2..f9f36d1645c9b57aea38350d67dfaa143845697d 100644
GIT binary patch
tests/data/acpi/q35/DSDT.bridge binary +0 -0
index c623cc5d72a2e346793fa9128e7e88b6781241b2..29176832ca9842c6654273ae1246321aa38b2821 100644
GIT binary patch
tests/data/acpi/q35/DSDT.cphp binary +0 -0
index 7ac526e4669fd84048b2d8ec6af8661503e1a9fa..19bdb5d21050f24aaacbafb1f84d6e1d541876c6 100644
GIT binary patch
tests/data/acpi/q35/DSDT.dimmpxm binary +0 -0
index 7177116a21969fa3649053ec83a8704b0d84b9c5..727fe489b4c8cdd39476ff61e7d7664c816f5291 100644
GIT binary patch
tests/data/acpi/q35/DSDT.ipmibt binary +0 -0
index c7f431f058bcb54e364be4edfd9d4609bc9bb602..9634930e6125de4375d87a56a353f636985599d4 100644
GIT binary patch
tests/data/acpi/q35/DSDT.memhp binary +0 -0
index 0235461391c90d577c3d533c2fd29ce50f1e2981..dad5dc8db2f13bdb0de001da42c13b18286c3061 100644
GIT binary patch
tests/data/acpi/q35/DSDT.mmio64 binary +0 -0
index f60ee77fb4d655e77c7ef1e8c205d741cc288939..20f627ed08a0cae4e144f3e4dd7dd5f1d8d0318c 100644
GIT binary patch
tests/data/acpi/q35/DSDT.numamem binary +0 -0
index 6c0d4f2bcb384cc3f3919b7472021ed51b93cbf5..7b96a972804e95e191d9d3bf9a965e90f6f7e555 100644
GIT binary patch
Signature · 1 line
MST
#13 lore raw

[Qemu-devel] [PULL 11/11] tests/rebuild-expected-aml.sh: blow out difflist

In reply to Michael S. Tsirkin

As expected files have been updated, make sure we
do not forget to remove them from the allowed
diff list.

---
 tests/data/acpi/rebuild-expected-aml.sh | 3 +++
 1 file changed, 3 insertions(+)
tests/data/acpi/rebuild-expected-aml.sh +3 -0
index d2853218dd..f89d4624bc 100755
@@ -29,5 +29,8 @@ for qemu in $qemu_bins; do
     TEST_ACPI_REBUILD_AML=y QTEST_QEMU_BINARY=$qemu tests/bios-tables-test
 done
 
+eval `grep SRC_PATH= config-host.mak`
+
+echo '/* List of comma-separated changed AML files to ignore */' > ${SRC_PATH}/tests/bios-tables-test-allowed-diff.h
 
 echo "The files were rebuilt and can be added to git."
Signature · 1 line
MST
#14 lore raw

Re: [Qemu-devel] [PULL 00/11] virtio, acpi: fixes, cleanups

In reply to Michael S. Tsirkin
Quoted 11 lines · Michael S. Tsirkin

The following changes since commit f3d0bec9f80e4ed7796fffa834ba0a53f2094f7f:

Merge remote-tracking branch 'remotes/maxreitz/tags/pull-block-2019-06-14' into staging (2019-06-14 14:46:13 +0100)

are available in the Git repository at:

git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git tags/for_upstream

for you to fetch changes up to 5f6b3561bf58395fd6c906d7064a1a5693a2e426:

Quoted 8 lines

tests/rebuild-expected-aml.sh: blow out difflist (2019-06-16 16:44:44 -0400)

----------------------------------------------------------------
virtio, acpi: fixes, cleanups

A bunch of minor fixes all over the place.

Applied, thanks.

Please update the changelog at https://wiki.qemu.org/ChangeLog/4.1
for any user-visible changes.

-- PMM